~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/heap/ha_heap.cc

  • Committer: Eric Day
  • Date: 2009-10-31 21:53:33 UTC
  • mfrom: (1200 staging)
  • mto: This revision was merged to the branch mainline in revision 1202.
  • Revision ID: eday@oddments.org-20091031215333-j94bjoanwmi68p6f
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#include <drizzled/server_includes.h>
 
16
#include "heap_priv.h"
17
17
#include <drizzled/error.h>
18
18
#include <drizzled/table.h>
19
19
#include <drizzled/session.h>
23
23
 
24
24
#include "heap.h"
25
25
#include "ha_heap.h"
26
 
#include "heapdef.h"
27
26
 
28
27
#include <string>
29
28
 
47
46
    addAlias("HEAP");
48
47
  }
49
48
 
50
 
  virtual handler *create(TableShare *table,
 
49
  virtual Cursor *create(TableShare *table,
51
50
                          MEM_ROOT *mem_root)
52
51
  {
53
52
    return new (mem_root) ha_heap(this, table);
57
56
    return ha_heap_exts;
58
57
  }
59
58
 
60
 
  int createTableImplementation(Session *session, const char *table_name,
61
 
                                Table *table_arg, HA_CREATE_INFO *create_info,
62
 
                                drizzled::message::Table*);
 
59
  int doCreateTable(Session *session, 
 
60
                    const char *table_name,
 
61
                    Table& table_arg, 
 
62
                    HA_CREATE_INFO& create_info,
 
63
                    drizzled::message::Table&);
63
64
 
64
 
  /* For whatever reason, internal tables can be created by handler::open()
 
65
  /* For whatever reason, internal tables can be created by Cursor::open()
65
66
     for HEAP.
66
67
     Instead of diving down a rat hole, let's just cry ourselves to sleep
67
68
     at night with this odd hackish workaround.
68
69
   */
69
70
  int heap_create_table(Session *session, const char *table_name,
70
 
                        Table *table_arg, HA_CREATE_INFO *create_info,
 
71
                        Table *table_arg, HA_CREATE_INFO& create_info,
71
72
                        bool internal_table,
72
73
                        HP_SHARE **internal_share);
73
74
 
74
 
  int renameTableImplementation(Session*, const char * from, const char * to);
75
 
 
76
 
  int deleteTableImplementation(Session *, const string table_path);
 
75
  int doRenameTable(Session*, const char * from, const char * to);
 
76
 
 
77
  int doDropTable(Session&, const string table_path);
 
78
 
 
79
  int doGetTableDefinition(Session& session,
 
80
                           const char* path,
 
81
                           const char *db,
 
82
                           const char *table_name,
 
83
                           const bool is_tmp,
 
84
                           drizzled::message::Table *table_proto);
 
85
 
 
86
  /* Temp only engine, so do not return values. */
 
87
  void doGetTableNames(CachedDirectory &, string& , set<string>&) { };
 
88
 
77
89
};
78
90
 
 
91
int HeapEngine::doGetTableDefinition(Session&,
 
92
                                     const char* path,
 
93
                                     const char *,
 
94
                                     const char *,
 
95
                                     const bool,
 
96
                                     drizzled::message::Table *table_proto)
 
97
{
 
98
  int error= 1;
 
99
  ProtoCache::iterator iter;
 
100
 
 
101
  pthread_mutex_lock(&proto_cache_mutex);
 
102
  iter= proto_cache.find(path);
 
103
 
 
104
  if (iter!= proto_cache.end())
 
105
  {
 
106
    if (table_proto)
 
107
      table_proto->CopyFrom(((*iter).second));
 
108
    error= EEXIST;
 
109
  }
 
110
  pthread_mutex_unlock(&proto_cache_mutex);
 
111
 
 
112
  return error;
 
113
}
79
114
/*
80
115
  We have to ignore ENOENT entries as the HEAP table is created on open and
81
116
  not when doing a CREATE on the table.
82
117
*/
83
 
int HeapEngine::deleteTableImplementation(Session*, const string table_path)
 
118
int HeapEngine::doDropTable(Session&, const string table_path)
84
119
{
 
120
  ProtoCache::iterator iter;
 
121
 
 
122
  pthread_mutex_lock(&proto_cache_mutex);
 
123
  iter= proto_cache.find(table_path.c_str());
 
124
 
 
125
  if (iter!= proto_cache.end())
 
126
    proto_cache.erase(iter);
 
127
  pthread_mutex_unlock(&proto_cache_mutex);
 
128
 
85
129
  return heap_delete_table(table_path.c_str());
86
130
}
87
131
 
115
159
 
116
160
ha_heap::ha_heap(drizzled::plugin::StorageEngine *engine_arg,
117
161
                 TableShare *table_arg)
118
 
  :handler(engine_arg, table_arg), file(0), records_changed(0), key_stat_version(0),
 
162
  :Cursor(engine_arg, table_arg), file(0), records_changed(0), key_stat_version(0),
119
163
  internal_table(0)
120
164
{}
121
165
 
142
186
    file= 0;
143
187
    HP_SHARE *internal_share= NULL;
144
188
    if (!heap_storage_engine->heap_create_table(ha_session(), name, table,
145
 
                                                &create_info,
 
189
                                                create_info,
146
190
                                                internal_table,&internal_share))
147
191
    {
148
192
        file= internal_table ?
192
236
    with '\'-delimited path.
193
237
*/
194
238
 
195
 
handler *ha_heap::clone(MEM_ROOT *mem_root)
 
239
Cursor *ha_heap::clone(MEM_ROOT *mem_root)
196
240
{
197
 
  handler *new_handler= get_new_handler(table->s, mem_root, table->s->db_type());
 
241
  Cursor *new_handler= table->s->db_type()->getCursor(table->s, mem_root);
 
242
 
198
243
  if (new_handler && !new_handler->ha_open(table, file->s->name, table->db_stat,
199
244
                                           HA_OPEN_IGNORE_IF_LOCKED))
200
245
    return new_handler;
486
531
  return 0;
487
532
}
488
533
 
489
 
int ha_heap::external_lock(Session *, int)
490
 
{
491
 
  return 0;                                     // No external locking
492
 
}
493
 
 
494
 
 
495
534
/*
496
535
  Disable indexes.
497
536
 
550
589
    The indexes might have been disabled by disable_index() before.
551
590
    The function works only if both data and indexes are empty,
552
591
    since the heap storage engine cannot repair the indexes.
553
 
    To be sure, call handler::delete_all_rows() before.
 
592
    To be sure, call Cursor::delete_all_rows() before.
554
593
 
555
594
  IMPLEMENTATION
556
595
    HA_KEY_SWITCH_NONUNIQ       is not implemented.
616
655
}
617
656
 
618
657
 
619
 
int HeapEngine::renameTableImplementation(Session*,
620
 
                                          const char *from, const char *to)
 
658
int HeapEngine::doRenameTable(Session*,
 
659
                              const char *from, const char *to)
621
660
{
622
661
  return heap_rename(from,to);
623
662
}
645
684
  return key->rec_per_key[key->key_parts-1];
646
685
}
647
686
 
648
 
int HeapEngine::createTableImplementation(Session *session,
649
 
                                          const char *table_name,
650
 
                                          Table *table_arg,
651
 
                                          HA_CREATE_INFO *create_info,
652
 
                                          drizzled::message::Table*)
 
687
int HeapEngine::doCreateTable(Session *session,
 
688
                              const char *table_name,
 
689
                              Table& table_arg,
 
690
                              HA_CREATE_INFO& create_info,
 
691
                              drizzled::message::Table& create_proto)
653
692
{
 
693
  int error;
654
694
  HP_SHARE *internal_share;
655
 
  return heap_create_table(session, table_name, table_arg, create_info,
 
695
 
 
696
  error= heap_create_table(session, table_name, &table_arg, create_info,
656
697
                           false, &internal_share);
 
698
 
 
699
  if (error == 0)
 
700
  {
 
701
    pthread_mutex_lock(&proto_cache_mutex);
 
702
    proto_cache.insert(make_pair(table_name, create_proto));
 
703
    pthread_mutex_unlock(&proto_cache_mutex);
 
704
  }
 
705
 
 
706
  return error;
657
707
}
658
708
 
659
709
 
660
710
int HeapEngine::heap_create_table(Session *session, const char *table_name,
661
 
                             Table *table_arg, HA_CREATE_INFO *create_info,
 
711
                             Table *table_arg, HA_CREATE_INFO& create_info,
662
712
                             bool internal_table, HP_SHARE **internal_share)
663
713
{
664
714
  uint32_t key, parts, mem_per_row_keys= 0, keys= table_arg->s->keys;
828
878
  HP_CREATE_INFO hp_create_info;
829
879
  hp_create_info.auto_key= auto_key;
830
880
  hp_create_info.auto_key_type= auto_key_type;
831
 
  hp_create_info.auto_increment= (create_info->auto_increment_value ?
832
 
                                  create_info->auto_increment_value - 1 : 0);
 
881
  hp_create_info.auto_increment= (create_info.auto_increment_value ?
 
882
                                  create_info.auto_increment_value - 1 : 0);
833
883
  hp_create_info.max_table_size=session->variables.max_heap_table_size;
834
884
  hp_create_info.with_auto_increment= found_real_auto_increment;
835
885
  hp_create_info.internal_table= internal_table;