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