~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/heap/ha_heap.cc

  • Committer: Brian Aker
  • Date: 2010-09-09 21:45:53 UTC
  • mto: (1756.1.2 build) (1768.2.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 1757.
  • Revision ID: brian@tangent.org-20100909214553-e687rmf5zk9478on
Force unique to just use memory and let the OS handle paging.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
#include "heap_priv.h"
17
17
#include <drizzled/error.h>
60
60
    hp_panic(HA_PANIC_CLOSE);
61
61
  }
62
62
 
63
 
  virtual Cursor *create(Table &table)
 
63
  virtual Cursor *create(TableShare &table)
64
64
  {
65
65
    return new ha_heap(*this, table);
66
66
  }
93
93
                           const TableIdentifier &identifier,
94
94
                           message::Table &table_message);
95
95
 
 
96
  /* Temp only engine, so do not return values. */
 
97
  void doGetTableNames(CachedDirectory &, const SchemaIdentifier& , set<string>&) { };
 
98
 
96
99
  uint32_t max_supported_keys()          const { return MAX_KEY; }
97
100
  uint32_t max_supported_key_part_length() const { return MAX_KEY_LENGTH; }
98
101
 
104
107
  bool doDoesTableExist(Session& session, const TableIdentifier &identifier);
105
108
  void doGetTableIdentifiers(CachedDirectory &directory,
106
109
                             const SchemaIdentifier &schema_identifier,
107
 
                             TableIdentifier::vector &set_of_identifiers);
 
110
                             TableIdentifiers &set_of_identifiers);
108
111
};
109
112
 
110
113
void HeapEngine::doGetTableIdentifiers(CachedDirectory&,
111
114
                                       const SchemaIdentifier&,
112
 
                                       TableIdentifier::vector&)
 
115
                                       TableIdentifiers&)
113
116
{
114
117
}
115
118
 
116
119
bool HeapEngine::doDoesTableExist(Session& session, const TableIdentifier &identifier)
117
120
{
118
 
  return session.getMessageCache().doesTableMessageExist(identifier);
 
121
  return session.doesTableMessageExist(identifier);
119
122
}
120
123
 
121
124
int HeapEngine::doGetTableDefinition(Session &session,
122
125
                                     const TableIdentifier &identifier,
123
126
                                     message::Table &table_proto)
124
127
{
125
 
  if (session.getMessageCache().getTableMessage(identifier, table_proto))
 
128
  if (session.getTableMessage(identifier, table_proto))
126
129
    return EEXIST;
127
130
 
128
131
  return ENOENT;
133
136
*/
134
137
int HeapEngine::doDropTable(Session &session, const TableIdentifier &identifier)
135
138
{
136
 
  session.getMessageCache().removeTableMessage(identifier);
 
139
  session.removeTableMessage(identifier);
137
140
 
138
141
  int error= heap_delete_table(identifier.getPath().c_str());
139
142
 
158
161
*****************************************************************************/
159
162
 
160
163
ha_heap::ha_heap(plugin::StorageEngine &engine_arg,
161
 
                 Table &table_arg)
 
164
                 TableShare &table_arg)
162
165
  :Cursor(engine_arg, table_arg), file(0), records_changed(0), key_stat_version(0),
163
166
  internal_table(0)
164
167
{}
176
179
*/
177
180
#define MEMORY_STATS_UPDATE_THRESHOLD 10
178
181
 
179
 
int ha_heap::doOpen(const drizzled::TableIdentifier &identifier, int mode, uint32_t test_if_locked)
 
182
int ha_heap::open(const char *name, int mode, uint32_t test_if_locked)
180
183
{
181
 
  if ((test_if_locked & HA_OPEN_INTERNAL_TABLE) || (!(file= heap_open(identifier.getPath().c_str(), mode)) && errno == ENOENT))
 
184
  if ((test_if_locked & HA_OPEN_INTERNAL_TABLE) || (!(file= heap_open(name, mode)) && errno == ENOENT))
182
185
  {
183
186
    internal_table= test(test_if_locked & HA_OPEN_INTERNAL_TABLE);
184
187
    file= 0;
185
188
    HP_SHARE *internal_share= NULL;
186
189
    message::Table create_proto;
187
190
 
188
 
    if (not heap_storage_engine->heap_create_table(getTable()->in_use,
189
 
                                                   identifier.getPath().c_str(),
190
 
                                                   getTable(),
191
 
                                                   internal_table,
192
 
                                                   create_proto,
193
 
                                                   &internal_share))
 
191
    if (!heap_storage_engine->heap_create_table(table->in_use, name, table,
 
192
                                                internal_table,
 
193
                                                create_proto,
 
194
                                                &internal_share))
194
195
    {
195
196
        file= internal_table ?
196
197
          heap_open_from_share(internal_share, mode) :
240
241
 
241
242
Cursor *ha_heap::clone(memory::Root *)
242
243
{
243
 
  Cursor *new_handler= getTable()->getMutableShare()->db_type()->getCursor(*getTable());
244
 
  TableIdentifier identifier(getTable()->getShare()->getSchemaName(),
245
 
                             getTable()->getShare()->getTableName(),
246
 
                             getTable()->getShare()->getPath());
 
244
  Cursor *new_handler= table->getMutableShare()->db_type()->getCursor(*(table->getMutableShare()));
 
245
  TableIdentifier identifier(table->getShare()->getSchemaName(),
 
246
                             table->getShare()->getTableName(),
 
247
                             table->getShare()->getPath());
247
248
 
248
 
  if (new_handler && !new_handler->ha_open(identifier, getTable()->db_stat,
 
249
  if (new_handler && !new_handler->ha_open(identifier, table, table->db_stat,
249
250
                                           HA_OPEN_IGNORE_IF_LOCKED))
250
251
    return new_handler;
251
252
  return NULL;
281
282
 
282
283
void ha_heap::update_key_stats()
283
284
{
284
 
  for (uint32_t i= 0; i < getTable()->getShare()->sizeKeys(); i++)
 
285
  for (uint32_t i= 0; i < table->getShare()->sizeKeys(); i++)
285
286
  {
286
 
    KeyInfo *key= &getTable()->key_info[i];
 
287
    KeyInfo *key= &table->key_info[i];
287
288
 
288
289
    if (!key->rec_per_key)
289
290
      continue;
310
311
int ha_heap::doInsertRecord(unsigned char * buf)
311
312
{
312
313
  int res;
313
 
  if (getTable()->next_number_field && buf == getTable()->getInsertRecord())
 
314
  if (table->next_number_field && buf == table->getInsertRecord())
314
315
  {
315
316
    if ((res= update_auto_increment()))
316
317
      return res;
350
351
  int res;
351
352
 
352
353
  res= heap_delete(file,buf);
353
 
  if (!res && getTable()->getShare()->getType() == message::Table::STANDARD &&
 
354
  if (!res && table->getShare()->getType() == message::Table::STANDARD &&
354
355
      ++records_changed*MEMORY_STATS_UPDATE_THRESHOLD > file->getShare()->records)
355
356
  {
356
357
    /*
369
370
  assert(inited==INDEX);
370
371
  ha_statistic_increment(&system_status_var::ha_read_key_count);
371
372
  int error = heap_rkey(file,buf,active_index, key, keypart_map, find_flag);
372
 
  getTable()->status = error ? STATUS_NOT_FOUND : 0;
 
373
  table->status = error ? STATUS_NOT_FOUND : 0;
373
374
  return error;
374
375
}
375
376
 
380
381
  ha_statistic_increment(&system_status_var::ha_read_key_count);
381
382
  int error= heap_rkey(file, buf, active_index, key, keypart_map,
382
383
                       HA_READ_PREFIX_LAST);
383
 
  getTable()->status= error ? STATUS_NOT_FOUND : 0;
 
384
  table->status= error ? STATUS_NOT_FOUND : 0;
384
385
  return error;
385
386
}
386
387
 
390
391
{
391
392
  ha_statistic_increment(&system_status_var::ha_read_key_count);
392
393
  int error = heap_rkey(file, buf, index, key, keypart_map, find_flag);
393
 
  getTable()->status = error ? STATUS_NOT_FOUND : 0;
 
394
  table->status = error ? STATUS_NOT_FOUND : 0;
394
395
  return error;
395
396
}
396
397
 
399
400
  assert(inited==INDEX);
400
401
  ha_statistic_increment(&system_status_var::ha_read_next_count);
401
402
  int error=heap_rnext(file,buf);
402
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
403
  table->status=error ? STATUS_NOT_FOUND: 0;
403
404
  return error;
404
405
}
405
406
 
408
409
  assert(inited==INDEX);
409
410
  ha_statistic_increment(&system_status_var::ha_read_prev_count);
410
411
  int error=heap_rprev(file,buf);
411
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
412
  table->status=error ? STATUS_NOT_FOUND: 0;
412
413
  return error;
413
414
}
414
415
 
417
418
  assert(inited==INDEX);
418
419
  ha_statistic_increment(&system_status_var::ha_read_first_count);
419
420
  int error=heap_rfirst(file, buf, active_index);
420
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
421
  table->status=error ? STATUS_NOT_FOUND: 0;
421
422
  return error;
422
423
}
423
424
 
426
427
  assert(inited==INDEX);
427
428
  ha_statistic_increment(&system_status_var::ha_read_last_count);
428
429
  int error=heap_rlast(file, buf, active_index);
429
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
430
  table->status=error ? STATUS_NOT_FOUND: 0;
430
431
  return error;
431
432
}
432
433
 
439
440
{
440
441
  ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
441
442
  int error=heap_scan(file, buf);
442
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
443
  table->status=error ? STATUS_NOT_FOUND: 0;
443
444
  return error;
444
445
}
445
446
 
450
451
  ha_statistic_increment(&system_status_var::ha_read_rnd_count);
451
452
  memcpy(&heap_position, pos, sizeof(HEAP_PTR));
452
453
  error=heap_rrnd(file, buf, heap_position);
453
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
454
  table->status=error ? STATUS_NOT_FOUND: 0;
454
455
  return error;
455
456
}
456
457
 
499
500
int ha_heap::delete_all_rows()
500
501
{
501
502
  heap_clear(file);
502
 
  if (getTable()->getShare()->getType() == message::Table::STANDARD)
 
503
  if (table->getShare()->getType() == message::Table::STANDARD)
503
504
  {
504
505
    /*
505
506
       We can perform this safely since only one writer at the time is
626
627
 
627
628
int HeapEngine::doRenameTable(Session &session, const TableIdentifier &from, const TableIdentifier &to)
628
629
{
629
 
  session.getMessageCache().renameTableMessage(from, to);
 
630
  session.renameTableMessage(from, to);
630
631
  return heap_rename(from.getPath().c_str(), to.getPath().c_str());
631
632
}
632
633
 
634
635
ha_rows ha_heap::records_in_range(uint32_t inx, key_range *min_key,
635
636
                                  key_range *max_key)
636
637
{
637
 
  KeyInfo *key= &getTable()->key_info[inx];
 
638
  KeyInfo *key= &table->key_info[inx];
638
639
 
639
640
  if (!min_key || !max_key ||
640
641
      min_key->length != max_key->length ||
667
668
 
668
669
  if (error == 0)
669
670
  {
670
 
    session.getMessageCache().storeTableMessage(identifier, create_proto);
 
671
    session.storeTableMessage(identifier, create_proto);
671
672
  }
672
673
 
673
674
  return error;
686
687
  uint32_t max_key_fieldnr = 0, key_part_size = 0, next_field_pos = 0;
687
688
  uint32_t column_count= table_arg->getShare()->sizeFields();
688
689
  std::vector<HP_KEYDEF> keydef;
 
690
  char buff[FN_REFLEN];
689
691
  int error;
690
692
  bool found_real_auto_increment= 0;
691
693
 
738
740
      next_field_pos= seg->start + seg->length;
739
741
      if (field->type() == DRIZZLE_TYPE_VARCHAR)
740
742
      {
741
 
        next_field_pos+= (uint8_t)(((Field_varstring*)field)->pack_length_no_ptr());
 
743
        next_field_pos+= (uint8_t)(((Field_varstring*)field)->length_bytes);
742
744
      }
743
745
 
744
746
      if (next_field_pos > key_part_size) {
770
772
        auto_key= key+ 1;
771
773
        auto_key_type= field->key_type();
772
774
      }
773
 
      if ((uint)field->position() + 1 > max_key_fieldnr)
 
775
      if ((uint)field->field_index + 1 > max_key_fieldnr)
774
776
      {
775
777
        /* Do not use seg->fieldnr as it's not reliable in case of temp tables */
776
 
        max_key_fieldnr= field->position() + 1;
 
778
        max_key_fieldnr= field->field_index + 1;
777
779
      }
778
780
    }
779
781
  }
801
803
  hp_create_info.internal_table= internal_table;
802
804
  hp_create_info.max_chunk_size= table_arg->getShare()->block_size;
803
805
 
804
 
  error= heap_create(table_name,
805
 
                     keys, &keydef[0],
806
 
                     column_count,
807
 
                     key_part_size,
808
 
                     table_arg->getShare()->getRecordLength(), mem_per_row_keys,
809
 
                     static_cast<uint32_t>(num_rows), /* We check for overflow above, so cast is fine here. */
810
 
                     0, // Factor out MIN
811
 
                     &hp_create_info, internal_share);
 
806
  error= heap_create(internal::fn_format(buff,table_name,"","",
 
807
                              MY_REPLACE_EXT|MY_UNPACK_FILENAME),
 
808
                    keys, &keydef[0],
 
809
                    column_count,
 
810
                    key_part_size,
 
811
                    table_arg->getShare()->getRecordLength(), mem_per_row_keys,
 
812
                    static_cast<uint32_t>(num_rows), /* We check for overflow above, so cast is fine here. */
 
813
                    0, // Factor out MIN
 
814
                    &hp_create_info, internal_share);
812
815
 
813
816
  return (error);
814
817
}