Drizzled Public API Documentation

hp_clear.cc
00001 /* Copyright (C) 2000-2002, 2004, 2006 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00015 
00016 /*
00017   remove all records from database
00018   Identical as hp_create() and hp_open() but used HP_SHARE* instead of name and
00019   database remains open.
00020 */
00021 
00022 #include <drizzled/error_t.h>
00023 #include "heap_priv.h"
00024 
00025 using namespace drizzled;
00026 
00027 static void hp_clear_keys(HP_SHARE *info);
00028 
00029 void heap_clear(HP_INFO *info)
00030 {
00031   hp_clear(info->getShare());
00032 }
00033 
00034 void hp_clear(HP_SHARE *info)
00035 {
00036   hp_clear_dataspace(&info->recordspace);
00037   hp_clear_keys(info);
00038   info->records= 0;
00039   info->blength=1;
00040   info->changed=0;
00041   return;
00042 }
00043 
00044 /*
00045   Clear all keys.
00046 
00047   SYNOPSIS
00048     hp_clear_keys()
00049     info      A pointer to the heap storage engine HP_SHARE struct.
00050 
00051   DESCRIPTION
00052     Delete all trees of all indexes and leave them empty.
00053 
00054   RETURN
00055     void
00056 */
00057 
00058 static void hp_clear_keys(HP_SHARE *info)
00059 {
00060   for (uint32_t key=0 ; key < info->keys ; key++)
00061   {
00062     HP_KEYDEF *keyinfo = info->keydef + key;
00063     {
00064       HP_BLOCK *block= &keyinfo->block;
00065       if (block->levels)
00066         hp_free_level(block,block->levels,block->root,(unsigned char*) 0);
00067       block->levels=0;
00068       block->last_allocated=0;
00069       keyinfo->hash_buckets= 0;
00070     }
00071   }
00072   info->index_length=0;
00073 }
00074 
00075 
00076 /*
00077   Disable all indexes.
00078 
00079   SYNOPSIS
00080     heap_disable_indexes()
00081     info      A pointer to the heap storage engine HP_INFO struct.
00082 
00083   DESCRIPTION
00084     Disable and clear (remove contents of) all indexes.
00085 
00086   RETURN
00087     0  ok
00088 */
00089 
00090 int heap_disable_indexes(HP_INFO *info)
00091 {
00092   HP_SHARE *share= info->getShare();
00093 
00094   if (share->keys)
00095   {
00096     hp_clear_keys(share);
00097     share->currently_disabled_keys= share->keys;
00098     share->keys= 0;
00099   }
00100   return 0;
00101 }
00102 
00103 
00104 /*
00105   Enable all indexes
00106 
00107   SYNOPSIS
00108     heap_enable_indexes()
00109     info      A pointer to the heap storage engine HP_INFO struct.
00110 
00111   DESCRIPTION
00112     Enable all indexes. The indexes might have been disabled
00113     by heap_disable_index() before.
00114     The function works only if both data and indexes are empty,
00115     since the heap storage engine cannot repair the indexes.
00116     To be sure, call handler::delete_all_rows() before.
00117 
00118   RETURN
00119     0  ok
00120     HA_ERR_CRASHED data or index is non-empty.
00121 */
00122 
00123 int heap_enable_indexes(HP_INFO *info)
00124 {
00125   int error= 0;
00126   HP_SHARE *share= info->getShare();
00127 
00128   if (share->recordspace.total_data_length || share->index_length)
00129     error= HA_ERR_CRASHED;
00130   else
00131     if (share->currently_disabled_keys)
00132     {
00133       share->keys= share->currently_disabled_keys;
00134       share->currently_disabled_keys= 0;
00135     }
00136   return error;
00137 }
00138 
00139 
00140 /*
00141   Test if indexes are disabled.
00142 
00143   SYNOPSIS
00144     heap_indexes_are_disabled()
00145     info      A pointer to the heap storage engine HP_INFO struct.
00146 
00147   DESCRIPTION
00148     Test if indexes are disabled.
00149 
00150   RETURN
00151     0  indexes are not disabled
00152     1  all indexes are disabled
00153    [2  non-unique indexes are disabled - NOT YET IMPLEMENTED]
00154 */
00155 
00156 int heap_indexes_are_disabled(HP_INFO *info)
00157 {
00158   HP_SHARE *share= info->getShare();
00159 
00160   return (! share->keys && share->currently_disabled_keys);
00161 }