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