1 /* Copyright (c) 2000, 2021, Oracle and/or its affiliates.
2 Use is subject to license terms.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24 /*
25 remove all records from database
26 Identical as hp_create() and hp_open() but used HP_SHARE* instead of name and
27 database remains open.
28 */
29
30 #include "heapdef.h"
31
heap_clear(HP_INFO * info)32 void heap_clear(HP_INFO *info)
33 {
34 hp_clear(info->s);
35 }
36
hp_clear(HP_SHARE * info)37 void hp_clear(HP_SHARE *info)
38 {
39 DBUG_ENTER("hp_clear");
40
41 hp_clear_dataspace(&info->recordspace);
42 hp_clear_keys(info);
43 info->records= 0;
44 info->blength=1;
45 info->changed=0;
46 DBUG_VOID_RETURN;
47 }
48
49
50 /*
51 Clear all keys.
52
53 SYNOPSIS
54 heap_clear_keys()
55 info A pointer to the heap storage engine HP_INFO struct.
56
57 DESCRIPTION
58 Delete all trees of all indexes and leave them empty.
59
60 RETURN
61 void
62 */
63
heap_clear_keys(HP_INFO * info)64 void heap_clear_keys(HP_INFO *info)
65 {
66 hp_clear(info->s);
67 }
68
69
70 /*
71 Clear all keys.
72
73 SYNOPSIS
74 hp_clear_keys()
75 info A pointer to the heap storage engine HP_SHARE struct.
76
77 DESCRIPTION
78 Delete all trees of all indexes and leave them empty.
79
80 RETURN
81 void
82 */
83
hp_clear_keys(HP_SHARE * info)84 void hp_clear_keys(HP_SHARE *info)
85 {
86 uint key;
87 DBUG_ENTER("hp_clear_keys");
88
89 for (key=0 ; key < info->keys ; key++)
90 {
91 HP_KEYDEF *keyinfo = info->keydef + key;
92 if (keyinfo->algorithm == HA_KEY_ALG_BTREE)
93 {
94 delete_tree(&keyinfo->rb_tree);
95 }
96 else
97 {
98 HP_BLOCK *block= &keyinfo->block;
99 if (block->levels)
100 (void) hp_free_level(block,block->levels,block->root,(uchar*) 0);
101 block->levels=0;
102 block->last_allocated=0;
103 keyinfo->hash_buckets= 0;
104 }
105 }
106 info->index_length=0;
107 DBUG_VOID_RETURN;
108 }
109
110
111 /*
112 Disable all indexes.
113
114 SYNOPSIS
115 heap_disable_indexes()
116 info A pointer to the heap storage engine HP_INFO struct.
117
118 DESCRIPTION
119 Disable and clear (remove contents of) all indexes.
120
121 RETURN
122 0 ok
123 */
124
heap_disable_indexes(HP_INFO * info)125 int heap_disable_indexes(HP_INFO *info)
126 {
127 HP_SHARE *share= info->s;
128
129 if (share->keys)
130 {
131 hp_clear_keys(share);
132 share->currently_disabled_keys= share->keys;
133 share->keys= 0;
134 }
135 return 0;
136 }
137
138
139 /*
140 Enable all indexes
141
142 SYNOPSIS
143 heap_enable_indexes()
144 info A pointer to the heap storage engine HP_INFO struct.
145
146 DESCRIPTION
147 Enable all indexes. The indexes might have been disabled
148 by heap_disable_index() before.
149 The function works only if both data and indexes are empty,
150 since the heap storage engine cannot repair the indexes.
151 To be sure, call handler::delete_all_rows() before.
152
153 RETURN
154 0 ok
155 HA_ERR_CRASHED data or index is non-empty.
156 */
157
heap_enable_indexes(HP_INFO * info)158 int heap_enable_indexes(HP_INFO *info)
159 {
160 int error= 0;
161 HP_SHARE *share= info->s;
162
163 if (share->recordspace.total_data_length || share->index_length)
164 error= HA_ERR_CRASHED;
165 else
166 if (share->currently_disabled_keys)
167 {
168 share->keys= share->currently_disabled_keys;
169 share->currently_disabled_keys= 0;
170 }
171 return error;
172 }
173
174
175 /*
176 Test if indexes are disabled.
177
178 SYNOPSIS
179 heap_indexes_are_disabled()
180 info A pointer to the heap storage engine HP_INFO struct.
181
182 DESCRIPTION
183 Test if indexes are disabled.
184
185 RETURN
186 0 indexes are not disabled
187 1 all indexes are disabled
188 [2 non-unique indexes are disabled - NOT YET IMPLEMENTED]
189 */
190
heap_indexes_are_disabled(HP_INFO * info)191 int heap_indexes_are_disabled(HP_INFO *info)
192 {
193 HP_SHARE *share= info->s;
194
195 return (! share->keys && share->currently_disabled_keys);
196 }
197
198