~drizzle-trunk/drizzle/development

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
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
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
2241.4.5 by Stewart Smith
remove two #includes from heap_priv.h - include error_t.h only where needed
22
#include <drizzled/error_t.h>
1130.3.28 by Monty Taylor
Moved heapdef.h and myisamdef.h to *_priv.h for easier filtering for include guard check.
23
#include "heap_priv.h"
1 by brian
clean slate
24
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
25
using namespace drizzled;
26
1165.1.159 by Stewart Smith
make hp_clear_keys() static to hp_clear.cc
27
static void hp_clear_keys(HP_SHARE *info);
28
1 by brian
clean slate
29
void heap_clear(HP_INFO *info)
30
{
1697.2.1 by Brian Aker
Encapsulate the internal share for HEAP.
31
  hp_clear(info->getShare());
1 by brian
clean slate
32
}
33
34
void hp_clear(HP_SHARE *info)
35
{
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
36
  hp_clear_dataspace(&info->recordspace);
1 by brian
clean slate
37
  hp_clear_keys(info);
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
38
  info->records= 0;
1 by brian
clean slate
39
  info->blength=1;
40
  info->changed=0;
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
41
  return;
1 by brian
clean slate
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
1165.1.159 by Stewart Smith
make hp_clear_keys() static to hp_clear.cc
58
static void hp_clear_keys(HP_SHARE *info)
1 by brian
clean slate
59
{
1707.1.7 by Brian Aker
Style updates.
60
  for (uint32_t key=0 ; key < info->keys ; key++)
1 by brian
clean slate
61
  {
62
    HP_KEYDEF *keyinfo = info->keydef + key;
63
    {
64
      HP_BLOCK *block= &keyinfo->block;
65
      if (block->levels)
481 by Brian Aker
Remove all of uchar.
66
        hp_free_level(block,block->levels,block->root,(unsigned char*) 0);
1 by brian
clean slate
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
90
int heap_disable_indexes(HP_INFO *info)
91
{
1697.2.1 by Brian Aker
Encapsulate the internal share for HEAP.
92
  HP_SHARE *share= info->getShare();
1 by brian
clean slate
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
123
int heap_enable_indexes(HP_INFO *info)
124
{
125
  int error= 0;
1697.2.1 by Brian Aker
Encapsulate the internal share for HEAP.
126
  HP_SHARE *share= info->getShare();
1 by brian
clean slate
127
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
128
  if (share->recordspace.total_data_length || share->index_length)
1 by brian
clean slate
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
156
int heap_indexes_are_disabled(HP_INFO *info)
157
{
1697.2.1 by Brian Aker
Encapsulate the internal share for HEAP.
158
  HP_SHARE *share= info->getShare();
1 by brian
clean slate
159
160
  return (! share->keys && share->currently_disabled_keys);
161
}