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 |
{
|
|
244.1.1
by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns. |
31 |
hp_clear_dataspace(&info->recordspace); |
1
by brian
clean slate |
32 |
hp_clear_keys(info); |
244.1.1
by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns. |
33 |
info->records= 0; |
1
by brian
clean slate |
34 |
info->blength=1; |
35 |
info->changed=0; |
|
51.3.1
by Jay Pipes
Removed all DBUG symbols from heap storage engine |
36 |
return; |
1
by brian
clean slate |
37 |
}
|
38 |
||
39 |
||
40 |
/*
|
|
41 |
Clear all keys.
|
|
42 |
||
43 |
SYNOPSIS
|
|
44 |
heap_clear_keys()
|
|
45 |
info A pointer to the heap storage engine HP_INFO struct.
|
|
46 |
||
47 |
DESCRIPTION
|
|
48 |
Delete all trees of all indexes and leave them empty.
|
|
49 |
||
50 |
RETURN
|
|
51 |
void
|
|
52 |
*/
|
|
53 |
||
54 |
void heap_clear_keys(HP_INFO *info) |
|
55 |
{
|
|
56 |
hp_clear(info->s); |
|
57 |
}
|
|
58 |
||
59 |
||
60 |
/*
|
|
61 |
Clear all keys.
|
|
62 |
||
63 |
SYNOPSIS
|
|
64 |
hp_clear_keys()
|
|
65 |
info A pointer to the heap storage engine HP_SHARE struct.
|
|
66 |
||
67 |
DESCRIPTION
|
|
68 |
Delete all trees of all indexes and leave them empty.
|
|
69 |
||
70 |
RETURN
|
|
71 |
void
|
|
72 |
*/
|
|
73 |
||
74 |
void hp_clear_keys(HP_SHARE *info) |
|
75 |
{
|
|
76 |
uint key; |
|
77 |
||
78 |
for (key=0 ; key < info->keys ; key++) |
|
79 |
{
|
|
80 |
HP_KEYDEF *keyinfo = info->keydef + key; |
|
81 |
if (keyinfo->algorithm == HA_KEY_ALG_BTREE) |
|
82 |
{
|
|
83 |
delete_tree(&keyinfo->rb_tree); |
|
84 |
}
|
|
85 |
else
|
|
86 |
{
|
|
87 |
HP_BLOCK *block= &keyinfo->block; |
|
88 |
if (block->levels) |
|
89 |
VOID(hp_free_level(block,block->levels,block->root,(uchar*) 0)); |
|
90 |
block->levels=0; |
|
91 |
block->last_allocated=0; |
|
92 |
keyinfo->hash_buckets= 0; |
|
93 |
}
|
|
94 |
}
|
|
95 |
info->index_length=0; |
|
51.3.1
by Jay Pipes
Removed all DBUG symbols from heap storage engine |
96 |
return; |
1
by brian
clean slate |
97 |
}
|
98 |
||
99 |
||
100 |
/*
|
|
101 |
Disable all indexes.
|
|
102 |
||
103 |
SYNOPSIS
|
|
104 |
heap_disable_indexes()
|
|
105 |
info A pointer to the heap storage engine HP_INFO struct.
|
|
106 |
||
107 |
DESCRIPTION
|
|
108 |
Disable and clear (remove contents of) all indexes.
|
|
109 |
||
110 |
RETURN
|
|
111 |
0 ok
|
|
112 |
*/
|
|
113 |
||
114 |
int heap_disable_indexes(HP_INFO *info) |
|
115 |
{
|
|
116 |
HP_SHARE *share= info->s; |
|
117 |
||
118 |
if (share->keys) |
|
119 |
{
|
|
120 |
hp_clear_keys(share); |
|
121 |
share->currently_disabled_keys= share->keys; |
|
122 |
share->keys= 0; |
|
123 |
}
|
|
124 |
return 0; |
|
125 |
}
|
|
126 |
||
127 |
||
128 |
/*
|
|
129 |
Enable all indexes
|
|
130 |
||
131 |
SYNOPSIS
|
|
132 |
heap_enable_indexes()
|
|
133 |
info A pointer to the heap storage engine HP_INFO struct.
|
|
134 |
||
135 |
DESCRIPTION
|
|
136 |
Enable all indexes. The indexes might have been disabled
|
|
137 |
by heap_disable_index() before.
|
|
138 |
The function works only if both data and indexes are empty,
|
|
139 |
since the heap storage engine cannot repair the indexes.
|
|
140 |
To be sure, call handler::delete_all_rows() before.
|
|
141 |
||
142 |
RETURN
|
|
143 |
0 ok
|
|
144 |
HA_ERR_CRASHED data or index is non-empty.
|
|
145 |
*/
|
|
146 |
||
147 |
int heap_enable_indexes(HP_INFO *info) |
|
148 |
{
|
|
149 |
int error= 0; |
|
150 |
HP_SHARE *share= info->s; |
|
151 |
||
244.1.1
by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns. |
152 |
if (share->recordspace.total_data_length || share->index_length) |
1
by brian
clean slate |
153 |
error= HA_ERR_CRASHED; |
154 |
else
|
|
155 |
if (share->currently_disabled_keys) |
|
156 |
{
|
|
157 |
share->keys= share->currently_disabled_keys; |
|
158 |
share->currently_disabled_keys= 0; |
|
159 |
}
|
|
160 |
return error; |
|
161 |
}
|
|
162 |
||
163 |
||
164 |
/*
|
|
165 |
Test if indexes are disabled.
|
|
166 |
||
167 |
SYNOPSIS
|
|
168 |
heap_indexes_are_disabled()
|
|
169 |
info A pointer to the heap storage engine HP_INFO struct.
|
|
170 |
||
171 |
DESCRIPTION
|
|
172 |
Test if indexes are disabled.
|
|
173 |
||
174 |
RETURN
|
|
175 |
0 indexes are not disabled
|
|
176 |
1 all indexes are disabled
|
|
177 |
[2 non-unique indexes are disabled - NOT YET IMPLEMENTED]
|
|
178 |
*/
|
|
179 |
||
180 |
int heap_indexes_are_disabled(HP_INFO *info) |
|
181 |
{
|
|
182 |
HP_SHARE *share= info->s; |
|
183 |
||
184 |
return (! share->keys && share->currently_disabled_keys); |
|
185 |
}
|