drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
hp_clear.cc
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 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 <drizzled/error_t.h>
23#include "heap_priv.h"
24
25using namespace drizzled;
26
27static void hp_clear_keys(HP_SHARE *info);
28
29void heap_clear(HP_INFO *info)
30{
31 hp_clear(info->getShare());
32}
33
34void hp_clear(HP_SHARE *info)
35{
36 hp_clear_dataspace(&info->recordspace);
37 hp_clear_keys(info);
38 info->records= 0;
39 info->blength=1;
40 info->changed=0;
41 return;
42}
43
44/*
45 Clear all keys.
46
47 SYNOPSIS
48 hp_clear_keys()
49 info A pointer to the heap storage engine HP_SHARE struct.
50
51 DESCRIPTION
52 Delete all trees of all indexes and leave them empty.
53
54 RETURN
55 void
56*/
57
58static void hp_clear_keys(HP_SHARE *info)
59{
60 for (uint32_t key=0 ; key < info->keys ; key++)
61 {
62 HP_KEYDEF *keyinfo = info->keydef + key;
63 {
64 HP_BLOCK *block= &keyinfo->block;
65 if (block->levels)
66 hp_free_level(block,block->levels,block->root,(unsigned char*) 0);
67 block->levels=0;
68 block->last_allocated=0;
69 keyinfo->hash_buckets= 0;
70 }
71 }
72 info->index_length=0;
73}
74
75
76/*
77 Disable all indexes.
78
79 SYNOPSIS
80 heap_disable_indexes()
81 info A pointer to the heap storage engine HP_INFO struct.
82
83 DESCRIPTION
84 Disable and clear (remove contents of) all indexes.
85
86 RETURN
87 0 ok
88*/
89
90int heap_disable_indexes(HP_INFO *info)
91{
92 HP_SHARE *share= info->getShare();
93
94 if (share->keys)
95 {
96 hp_clear_keys(share);
97 share->currently_disabled_keys= share->keys;
98 share->keys= 0;
99 }
100 return 0;
101}
102
103
104/*
105 Enable all indexes
106
107 SYNOPSIS
108 heap_enable_indexes()
109 info A pointer to the heap storage engine HP_INFO struct.
110
111 DESCRIPTION
112 Enable all indexes. The indexes might have been disabled
113 by heap_disable_index() before.
114 The function works only if both data and indexes are empty,
115 since the heap storage engine cannot repair the indexes.
116 To be sure, call handler::delete_all_rows() before.
117
118 RETURN
119 0 ok
120 HA_ERR_CRASHED data or index is non-empty.
121*/
122
123int heap_enable_indexes(HP_INFO *info)
124{
125 int error= 0;
126 HP_SHARE *share= info->getShare();
127
128 if (share->recordspace.total_data_length || share->index_length)
129 error= HA_ERR_CRASHED;
130 else
131 if (share->currently_disabled_keys)
132 {
133 share->keys= share->currently_disabled_keys;
134 share->currently_disabled_keys= 0;
135 }
136 return error;
137}
138
139
140/*
141 Test if indexes are disabled.
142
143 SYNOPSIS
144 heap_indexes_are_disabled()
145 info A pointer to the heap storage engine HP_INFO struct.
146
147 DESCRIPTION
148 Test if indexes are disabled.
149
150 RETURN
151 0 indexes are not disabled
152 1 all indexes are disabled
153 [2 non-unique indexes are disabled - NOT YET IMPLEMENTED]
154*/
155
156int heap_indexes_are_disabled(HP_INFO *info)
157{
158 HP_SHARE *share= info->getShare();
159
160 return (! share->keys && share->currently_disabled_keys);
161}
TODO: Rename this file - func.h is stupid.