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
25void heap_clear(HP_INFO *info)
26{
27 hp_clear(info->s);
28}
29
30void 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 info->key_version++;
45 info->file_version++;
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
64void 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
84void 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, 0);
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
125int 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
158int heap_enable_indexes(HP_INFO *info)
159{
160 int error= 0;
161 HP_SHARE *share= info->s;
162
163 if (share->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
191int 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