~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/heap/hp_clear.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-13 01:03:01 UTC
  • mto: (1126.9.2 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090913010301-tcvvezipx1124acy
Added calls to the dtrace delete begin/end probes.

Show diffs side-by-side

added added

removed removed

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