~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/memory/ha_heap.cc

  • Committer: lbieber
  • Date: 2010-10-02 14:36:07 UTC
  • mfrom: (1799.7.7 drizzle-bug-649844)
  • mto: This revision was merged to the branch mainline in revision 1809.
  • Revision ID: lbieber@orisndriz08-20101002143607-fffgvc6l4gw9drmm
Merge Andrew - fix bug 649844 - Clean up and fix some drizzledump options along with some documentation fixes

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
  }
104
104
  bool doDoesTableExist(Session& session, const TableIdentifier &identifier);
105
105
  void doGetTableIdentifiers(CachedDirectory &directory,
106
106
                             const SchemaIdentifier &schema_identifier,
107
 
                             TableIdentifier::vector &set_of_identifiers);
 
107
                             TableIdentifiers &set_of_identifiers);
108
108
};
109
109
 
110
110
void HeapEngine::doGetTableIdentifiers(CachedDirectory&,
111
111
                                       const SchemaIdentifier&,
112
 
                                       TableIdentifier::vector&)
 
112
                                       TableIdentifiers&)
113
113
{
114
114
}
115
115
 
116
116
bool HeapEngine::doDoesTableExist(Session& session, const TableIdentifier &identifier)
117
117
{
118
 
  return session.getMessageCache().doesTableMessageExist(identifier);
 
118
  return session.doesTableMessageExist(identifier);
119
119
}
120
120
 
121
121
int HeapEngine::doGetTableDefinition(Session &session,
122
122
                                     const TableIdentifier &identifier,
123
123
                                     message::Table &table_proto)
124
124
{
125
 
  if (session.getMessageCache().getTableMessage(identifier, table_proto))
 
125
  if (session.getTableMessage(identifier, table_proto))
126
126
    return EEXIST;
127
127
 
128
128
  return ENOENT;
133
133
*/
134
134
int HeapEngine::doDropTable(Session &session, const TableIdentifier &identifier)
135
135
{
136
 
  session.getMessageCache().removeTableMessage(identifier);
 
136
  session.removeTableMessage(identifier);
137
137
 
138
138
  int error= heap_delete_table(identifier.getPath().c_str());
139
139
 
158
158
*****************************************************************************/
159
159
 
160
160
ha_heap::ha_heap(plugin::StorageEngine &engine_arg,
161
 
                 Table &table_arg)
 
161
                 TableShare &table_arg)
162
162
  :Cursor(engine_arg, table_arg), file(0), records_changed(0), key_stat_version(0),
163
163
  internal_table(0)
164
164
{}
185
185
    HP_SHARE *internal_share= NULL;
186
186
    message::Table create_proto;
187
187
 
188
 
    if (not heap_storage_engine->heap_create_table(getTable()->in_use,
 
188
    if (not heap_storage_engine->heap_create_table(table->in_use,
189
189
                                                   identifier.getPath().c_str(),
190
 
                                                   getTable(),
 
190
                                                   table,
191
191
                                                   internal_table,
192
192
                                                   create_proto,
193
193
                                                   &internal_share))
240
240
 
241
241
Cursor *ha_heap::clone(memory::Root *)
242
242
{
243
 
  Cursor *new_handler= getTable()->getMutableShare()->db_type()->getCursor(*getTable());
244
 
  TableIdentifier identifier(getTable()->getShare()->getSchemaName(),
245
 
                             getTable()->getShare()->getTableName(),
246
 
                             getTable()->getShare()->getPath());
 
243
  Cursor *new_handler= table->getMutableShare()->db_type()->getCursor(*(table->getMutableShare()));
 
244
  TableIdentifier identifier(table->getShare()->getSchemaName(),
 
245
                             table->getShare()->getTableName(),
 
246
                             table->getShare()->getPath());
247
247
 
248
 
  if (new_handler && !new_handler->ha_open(identifier, getTable()->db_stat,
 
248
  if (new_handler && !new_handler->ha_open(identifier, table, table->db_stat,
249
249
                                           HA_OPEN_IGNORE_IF_LOCKED))
250
250
    return new_handler;
251
251
  return NULL;
281
281
 
282
282
void ha_heap::update_key_stats()
283
283
{
284
 
  for (uint32_t i= 0; i < getTable()->getShare()->sizeKeys(); i++)
 
284
  for (uint32_t i= 0; i < table->getShare()->sizeKeys(); i++)
285
285
  {
286
 
    KeyInfo *key= &getTable()->key_info[i];
 
286
    KeyInfo *key= &table->key_info[i];
287
287
 
288
288
    if (!key->rec_per_key)
289
289
      continue;
310
310
int ha_heap::doInsertRecord(unsigned char * buf)
311
311
{
312
312
  int res;
313
 
  if (getTable()->next_number_field && buf == getTable()->getInsertRecord())
 
313
  if (table->next_number_field && buf == table->getInsertRecord())
314
314
  {
315
315
    if ((res= update_auto_increment()))
316
316
      return res;
350
350
  int res;
351
351
 
352
352
  res= heap_delete(file,buf);
353
 
  if (!res && getTable()->getShare()->getType() == message::Table::STANDARD &&
 
353
  if (!res && table->getShare()->getType() == message::Table::STANDARD &&
354
354
      ++records_changed*MEMORY_STATS_UPDATE_THRESHOLD > file->getShare()->records)
355
355
  {
356
356
    /*
369
369
  assert(inited==INDEX);
370
370
  ha_statistic_increment(&system_status_var::ha_read_key_count);
371
371
  int error = heap_rkey(file,buf,active_index, key, keypart_map, find_flag);
372
 
  getTable()->status = error ? STATUS_NOT_FOUND : 0;
 
372
  table->status = error ? STATUS_NOT_FOUND : 0;
373
373
  return error;
374
374
}
375
375
 
380
380
  ha_statistic_increment(&system_status_var::ha_read_key_count);
381
381
  int error= heap_rkey(file, buf, active_index, key, keypart_map,
382
382
                       HA_READ_PREFIX_LAST);
383
 
  getTable()->status= error ? STATUS_NOT_FOUND : 0;
 
383
  table->status= error ? STATUS_NOT_FOUND : 0;
384
384
  return error;
385
385
}
386
386
 
390
390
{
391
391
  ha_statistic_increment(&system_status_var::ha_read_key_count);
392
392
  int error = heap_rkey(file, buf, index, key, keypart_map, find_flag);
393
 
  getTable()->status = error ? STATUS_NOT_FOUND : 0;
 
393
  table->status = error ? STATUS_NOT_FOUND : 0;
394
394
  return error;
395
395
}
396
396
 
399
399
  assert(inited==INDEX);
400
400
  ha_statistic_increment(&system_status_var::ha_read_next_count);
401
401
  int error=heap_rnext(file,buf);
402
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
402
  table->status=error ? STATUS_NOT_FOUND: 0;
403
403
  return error;
404
404
}
405
405
 
408
408
  assert(inited==INDEX);
409
409
  ha_statistic_increment(&system_status_var::ha_read_prev_count);
410
410
  int error=heap_rprev(file,buf);
411
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
411
  table->status=error ? STATUS_NOT_FOUND: 0;
412
412
  return error;
413
413
}
414
414
 
417
417
  assert(inited==INDEX);
418
418
  ha_statistic_increment(&system_status_var::ha_read_first_count);
419
419
  int error=heap_rfirst(file, buf, active_index);
420
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
420
  table->status=error ? STATUS_NOT_FOUND: 0;
421
421
  return error;
422
422
}
423
423
 
426
426
  assert(inited==INDEX);
427
427
  ha_statistic_increment(&system_status_var::ha_read_last_count);
428
428
  int error=heap_rlast(file, buf, active_index);
429
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
429
  table->status=error ? STATUS_NOT_FOUND: 0;
430
430
  return error;
431
431
}
432
432
 
439
439
{
440
440
  ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
441
441
  int error=heap_scan(file, buf);
442
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
442
  table->status=error ? STATUS_NOT_FOUND: 0;
443
443
  return error;
444
444
}
445
445
 
450
450
  ha_statistic_increment(&system_status_var::ha_read_rnd_count);
451
451
  memcpy(&heap_position, pos, sizeof(HEAP_PTR));
452
452
  error=heap_rrnd(file, buf, heap_position);
453
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
453
  table->status=error ? STATUS_NOT_FOUND: 0;
454
454
  return error;
455
455
}
456
456
 
499
499
int ha_heap::delete_all_rows()
500
500
{
501
501
  heap_clear(file);
502
 
  if (getTable()->getShare()->getType() == message::Table::STANDARD)
 
502
  if (table->getShare()->getType() == message::Table::STANDARD)
503
503
  {
504
504
    /*
505
505
       We can perform this safely since only one writer at the time is
626
626
 
627
627
int HeapEngine::doRenameTable(Session &session, const TableIdentifier &from, const TableIdentifier &to)
628
628
{
629
 
  session.getMessageCache().renameTableMessage(from, to);
 
629
  session.renameTableMessage(from, to);
630
630
  return heap_rename(from.getPath().c_str(), to.getPath().c_str());
631
631
}
632
632
 
634
634
ha_rows ha_heap::records_in_range(uint32_t inx, key_range *min_key,
635
635
                                  key_range *max_key)
636
636
{
637
 
  KeyInfo *key= &getTable()->key_info[inx];
 
637
  KeyInfo *key= &table->key_info[inx];
638
638
 
639
639
  if (!min_key || !max_key ||
640
640
      min_key->length != max_key->length ||
667
667
 
668
668
  if (error == 0)
669
669
  {
670
 
    session.getMessageCache().storeTableMessage(identifier, create_proto);
 
670
    session.storeTableMessage(identifier, create_proto);
671
671
  }
672
672
 
673
673
  return error;
770
770
        auto_key= key+ 1;
771
771
        auto_key_type= field->key_type();
772
772
      }
773
 
      if ((uint)field->position() + 1 > max_key_fieldnr)
 
773
      if ((uint)field->field_index + 1 > max_key_fieldnr)
774
774
      {
775
775
        /* Do not use seg->fieldnr as it's not reliable in case of temp tables */
776
 
        max_key_fieldnr= field->position() + 1;
 
776
        max_key_fieldnr= field->field_index + 1;
777
777
      }
778
778
    }
779
779
  }