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 "heap_priv.h"
00023 
00024 using namespace drizzled;
00025 
00026 static void hp_clear_keys(HP_SHARE *info);
00027 
00028 void heap_clear(HP_INFO *info)
00029 {
00030   hp_clear(info->getShare());
00031 }
00032 
00033 void hp_clear(HP_SHARE *info)
00034 {
00035   hp_clear_dataspace(&info->recordspace);
00036   hp_clear_keys(info);
00037   info->records= 0;
00038   info->blength=1;
00039   info->changed=0;
00040   return;
00041 }
00042 
00043 /*
00044   Clear all keys.
00045 
00046   SYNOPSIS
00047     hp_clear_keys()
00048     info      A pointer to the heap storage engine HP_SHARE struct.
00049 
00050   DESCRIPTION
00051     Delete all trees of all indexes and leave them empty.
00052 
00053   RETURN
00054     void
00055 */
00056 
00057 static void hp_clear_keys(HP_SHARE *info)
00058 {
00059   for (uint32_t key=0 ; key < info->keys ; key++)
00060   {
00061     HP_KEYDEF *keyinfo = info->keydef + key;
00062     {
00063       HP_BLOCK *block= &keyinfo->block;
00064       if (block->levels)
00065         hp_free_level(block,block->levels,block->root,(unsigned char*) 0);
00066       block->levels=0;
00067       block->last_allocated=0;
00068       keyinfo->hash_buckets= 0;
00069     }
00070   }
00071   info->index_length=0;
00072 }
00073 
00074 
00075 /*
00076   Disable all indexes.
00077 
00078   SYNOPSIS
00079     heap_disable_indexes()
00080     info      A pointer to the heap storage engine HP_INFO struct.
00081 
00082   DESCRIPTION
00083     Disable and clear (remove contents of) all indexes.
00084 
00085   RETURN
00086     0  ok
00087 */
00088 
00089 int heap_disable_indexes(HP_INFO *info)
00090 {
00091   HP_SHARE *share= info->getShare();
00092 
00093   if (share->keys)
00094   {
00095     hp_clear_keys(share);
00096     share->currently_disabled_keys= share->keys;
00097     share->keys= 0;
00098   }
00099   return 0;
00100 }
00101 
00102 
00103 /*
00104   Enable all indexes
00105 
00106   SYNOPSIS
00107     heap_enable_indexes()
00108     info      A pointer to the heap storage engine HP_INFO struct.
00109 
00110   DESCRIPTION
00111     Enable all indexes. The indexes might have been disabled
00112     by heap_disable_index() before.
00113     The function works only if both data and indexes are empty,
00114     since the heap storage engine cannot repair the indexes.
00115     To be sure, call handler::delete_all_rows() before.
00116 
00117   RETURN
00118     0  ok
00119     HA_ERR_CRASHED data or index is non-empty.
00120 */
00121 
00122 int heap_enable_indexes(HP_INFO *info)
00123 {
00124   int error= 0;
00125   HP_SHARE *share= info->getShare();
00126 
00127   if (share->recordspace.total_data_length || share->index_length)
00128     error= HA_ERR_CRASHED;
00129   else
00130     if (share->currently_disabled_keys)
00131     {
00132       share->keys= share->currently_disabled_keys;
00133       share->currently_disabled_keys= 0;
00134     }
00135   return error;
00136 }
00137 
00138 
00139 /*
00140   Test if indexes are disabled.
00141 
00142   SYNOPSIS
00143     heap_indexes_are_disabled()
00144     info      A pointer to the heap storage engine HP_INFO struct.
00145 
00146   DESCRIPTION
00147     Test if indexes are disabled.
00148 
00149   RETURN
00150     0  indexes are not disabled
00151     1  all indexes are disabled
00152    [2  non-unique indexes are disabled - NOT YET IMPLEMENTED]
00153 */
00154 
00155 int heap_indexes_are_disabled(HP_INFO *info)
00156 {
00157   HP_SHARE *share= info->getShare();
00158 
00159   return (! share->keys && share->currently_disabled_keys);
00160 }