~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/cursor.cc

Merge of Keycache gutting code. (this is a test).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
23
23
  Handler-calling-functions
24
24
*/
25
25
 
26
 
#include <config.h>
 
26
#include "config.h"
27
27
 
28
28
#include <fcntl.h>
29
29
 
30
 
#include <drizzled/error.h>
31
 
#include <drizzled/field/epoch.h>
32
 
#include <drizzled/gettext.h>
33
 
#include <drizzled/internal/my_sys.h>
34
 
#include <drizzled/item/empty_string.h>
35
 
#include <drizzled/item/int.h>
36
 
#include <drizzled/lock.h>
37
 
#include <drizzled/message/table.h>
38
 
#include <drizzled/my_hash.h>
39
 
#include <drizzled/optimizer/cost_vector.h>
40
 
#include <drizzled/plugin/client.h>
41
 
#include <drizzled/plugin/event_observer.h>
42
 
#include <drizzled/plugin/storage_engine.h>
43
 
#include <drizzled/probes.h>
44
 
#include <drizzled/session.h>
45
 
#include <drizzled/sql_base.h>
46
 
#include <drizzled/sql_parse.h>
47
 
#include <drizzled/transaction_services.h>
 
30
#include "drizzled/my_hash.h"
 
31
#include "drizzled/error.h"
 
32
#include "drizzled/gettext.h"
 
33
#include "drizzled/probes.h"
 
34
#include "drizzled/sql_parse.h"
 
35
#include "drizzled/optimizer/cost_vector.h"
 
36
#include "drizzled/session.h"
 
37
#include "drizzled/sql_base.h"
 
38
#include "drizzled/transaction_services.h"
 
39
#include "drizzled/lock.h"
 
40
#include "drizzled/item/int.h"
 
41
#include "drizzled/item/empty_string.h"
 
42
#include "drizzled/field/timestamp.h"
 
43
#include "drizzled/message/table.pb.h"
 
44
#include "drizzled/plugin/client.h"
 
45
#include "drizzled/internal/my_sys.h"
 
46
#include "drizzled/plugin/event_observer.h"
48
47
 
49
48
using namespace std;
50
49
 
55
54
** General Cursor functions
56
55
****************************************************************************/
57
56
Cursor::Cursor(plugin::StorageEngine &engine_arg,
58
 
               Table &arg)
59
 
  : table(arg),
60
 
    engine(engine_arg),
61
 
    estimation_rows_to_insert(0),
 
57
               TableShare &share_arg)
 
58
  : table_share(&share_arg), table(0),
 
59
    estimation_rows_to_insert(0), engine(&engine_arg),
62
60
    ref(0),
63
61
    key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
64
62
    ref_length(sizeof(internal::my_off_t)),
81
79
 */
82
80
Cursor *Cursor::clone(memory::Root *mem_root)
83
81
{
84
 
  Cursor *new_handler= getTable()->getMutableShare()->db_type()->getCursor(*getTable());
 
82
  Cursor *new_handler= table->getMutableShare()->db_type()->getCursor(*table->getMutableShare());
85
83
 
86
84
  /*
87
85
    Allocate Cursor->ref here because otherwise ha_open will allocate it
91
89
  if (!(new_handler->ref= (unsigned char*) mem_root->alloc_root(ALIGN_SIZE(ref_length)*2)))
92
90
    return NULL;
93
91
 
94
 
  identifier::Table identifier(getTable()->getShare()->getSchemaName(),
95
 
                             getTable()->getShare()->getTableName(),
96
 
                             getTable()->getShare()->getType());
 
92
  TableIdentifier identifier(table->getShare()->getSchemaName(),
 
93
                             table->getShare()->getTableName(),
 
94
                             table->getShare()->getType());
97
95
 
98
96
  if (new_handler && !new_handler->ha_open(identifier,
99
 
                                           getTable()->getDBStat(),
 
97
                                           table,
 
98
                                           table->getMutableShare()->getNormalizedPath(),
 
99
                                           table->getDBStat(),
100
100
                                           HA_OPEN_IGNORE_IF_LOCKED))
101
101
    return new_handler;
102
102
  return NULL;
112
112
  /* works only with key prefixes */
113
113
  assert(((keypart_map_arg + 1) & keypart_map_arg) == 0);
114
114
 
115
 
  const KeyPartInfo *key_part_found= getTable()->getShare()->getKeyInfo(key_position).key_part;
116
 
  const KeyPartInfo *end_key_part_found= key_part_found + getTable()->getShare()->getKeyInfo(key_position).key_parts;
 
115
  const KeyPartInfo *key_part_found= table->getShare()->getKeyInfo(key_position).key_part;
 
116
  const KeyPartInfo *end_key_part_found= key_part_found + table->getShare()->getKeyInfo(key_position).key_parts;
117
117
  uint32_t length= 0;
118
118
 
119
119
  while (key_part_found < end_key_part_found && keypart_map_arg)
176
176
  return end_bulk_insert();
177
177
}
178
178
 
 
179
void Cursor::change_table_ptr(Table *table_arg, TableShare *share)
 
180
{
 
181
  table= table_arg;
 
182
  table_share= share;
 
183
}
 
184
 
179
185
const key_map *Cursor::keys_to_use_for_scanning()
180
186
{
181
187
  return &key_map_empty;
183
189
 
184
190
bool Cursor::has_transactions()
185
191
{
186
 
  return (getTable()->getShare()->db_type()->check_flag(HTON_BIT_DOES_TRANSACTIONS));
 
192
  return (table->getShare()->db_type()->check_flag(HTON_BIT_DOES_TRANSACTIONS));
187
193
}
188
194
 
189
195
void Cursor::ha_statistic_increment(uint64_t system_status_var::*offset) const
190
196
{
191
 
  (getTable()->in_use->status_var.*offset)++;
 
197
  status_var_increment(table->in_use->status_var.*offset);
192
198
}
193
199
 
194
200
void **Cursor::ha_data(Session *session) const
195
201
{
196
 
  return session->getEngineData(getEngine());
 
202
  return session->getEngineData(engine);
197
203
}
198
204
 
199
205
bool Cursor::is_fatal_error(int error, uint32_t flags)
209
215
 
210
216
ha_rows Cursor::records() { return stats.records; }
211
217
uint64_t Cursor::tableSize() { return stats.index_file_length + stats.data_file_length; }
212
 
uint64_t Cursor::rowSize() { return getTable()->getRecordLength() + getTable()->sizeFields(); }
 
218
uint64_t Cursor::rowSize() { return table->getRecordLength() + table->sizeFields(); }
213
219
 
214
 
int Cursor::doOpen(const identifier::Table &identifier, int mode, uint32_t test_if_locked)
 
220
int Cursor::doOpen(const TableIdentifier &identifier, int mode, uint32_t test_if_locked)
215
221
{
216
222
  return open(identifier.getPath().c_str(), mode, test_if_locked);
217
223
}
222
228
  Try O_RDONLY if cannot open as O_RDWR
223
229
  Don't wait for locks if not HA_OPEN_WAIT_IF_LOCKED is set
224
230
*/
225
 
int Cursor::ha_open(const identifier::Table &identifier,
226
 
                    int mode,
 
231
int Cursor::ha_open(const TableIdentifier &identifier,
 
232
                    Table *table_arg, const char *name, int mode,
227
233
                    int test_if_locked)
228
234
{
229
235
  int error;
230
236
 
 
237
  table= table_arg;
 
238
  assert(table->getShare() == table_share);
 
239
 
 
240
  assert(identifier.getPath().compare(name) == 0);
231
241
  if ((error= doOpen(identifier, mode, test_if_locked)))
232
242
  {
233
243
    if ((error == EACCES || error == EROFS) && mode == O_RDWR &&
234
 
        (getTable()->db_stat & HA_TRY_READ_ONLY))
 
244
        (table->db_stat & HA_TRY_READ_ONLY))
235
245
    {
236
 
      getTable()->db_stat|=HA_READ_ONLY;
 
246
      table->db_stat|=HA_READ_ONLY;
237
247
      error= doOpen(identifier, O_RDONLY,test_if_locked);
238
248
    }
239
249
  }
243
253
  }
244
254
  else
245
255
  {
246
 
    if (getTable()->getShare()->db_options_in_use & HA_OPTION_READ_ONLY_DATA)
247
 
      getTable()->db_stat|=HA_READ_ONLY;
 
256
    if (table->getShare()->db_options_in_use & HA_OPTION_READ_ONLY_DATA)
 
257
      table->db_stat|=HA_READ_ONLY;
248
258
    (void) extra(HA_EXTRA_NO_READCHECK);        // Not needed in SQL
249
259
 
250
260
    /* ref is already allocated for us if we're called from Cursor::clone() */
251
 
    if (!ref && !(ref= (unsigned char*) getTable()->alloc_root(ALIGN_SIZE(ref_length)*2)))
 
261
    if (!ref && !(ref= (unsigned char*) table->alloc_root(ALIGN_SIZE(ref_length)*2)))
252
262
    {
253
263
      close();
254
264
      error=HA_ERR_OUT_OF_MEM;
267
277
*/
268
278
int Cursor::read_first_row(unsigned char * buf, uint32_t primary_key)
269
279
{
270
 
  int error;
 
280
  register int error;
271
281
 
272
282
  ha_statistic_increment(&system_status_var::ha_read_first_count);
273
283
 
274
284
  /*
275
285
    If there is very few deleted rows in the table, find the first row by
276
286
    scanning the table.
277
 
    @todo remove the test for HA_READ_ORDER
 
287
    TODO remove the test for HA_READ_ORDER
278
288
  */
279
289
  if (stats.deleted < 10 || primary_key >= MAX_KEY ||
280
 
      !(getTable()->index_flags(primary_key) & HA_READ_ORDER))
 
290
      !(table->index_flags(primary_key) & HA_READ_ORDER))
281
291
  {
282
 
    error= startTableScan(1);
283
 
    if (error == 0)
284
 
    {
285
 
      while ((error= rnd_next(buf)) == HA_ERR_RECORD_DELETED) ;
286
 
      (void) endTableScan();
287
 
    }
 
292
    (void) startTableScan(1);
 
293
    while ((error= rnd_next(buf)) == HA_ERR_RECORD_DELETED) ;
 
294
    (void) endTableScan();
288
295
  }
289
296
  else
290
297
  {
291
298
    /* Find the first row through the primary key */
292
 
    error= startIndexScan(primary_key, 0);
293
 
    if (error == 0)
294
 
    {
295
 
      error=index_first(buf);
296
 
      (void) endIndexScan();
297
 
    }
 
299
    (void) startIndexScan(primary_key, 0);
 
300
    error=index_first(buf);
 
301
    (void) endIndexScan();
298
302
  }
299
303
  return error;
300
304
}
311
315
  @verbatim 1,5,15,25,35,... @endverbatim
312
316
*/
313
317
inline uint64_t
314
 
compute_next_insert_id(uint64_t nr, drizzle_system_variables *variables)
 
318
compute_next_insert_id(uint64_t nr,struct system_variables *variables)
315
319
{
316
320
  if (variables->auto_increment_increment == 1)
317
321
    return (nr+1); // optimization of the formula below
331
335
    Session::next_insert_id to be greater than the explicit value.
332
336
  */
333
337
  if ((next_insert_id > 0) && (nr >= next_insert_id))
334
 
    set_next_insert_id(compute_next_insert_id(nr, &getTable()->in_use->variables));
 
338
    set_next_insert_id(compute_next_insert_id(nr, &table->in_use->variables));
335
339
}
336
340
 
337
341
 
351
355
    The number X if it exists, "nr" otherwise.
352
356
*/
353
357
inline uint64_t
354
 
prev_insert_id(uint64_t nr, drizzle_system_variables *variables)
 
358
prev_insert_id(uint64_t nr, struct system_variables *variables)
355
359
{
356
360
  if (unlikely(nr < variables->auto_increment_offset))
357
361
  {
448
452
{
449
453
  uint64_t nr, nb_reserved_values;
450
454
  bool append= false;
451
 
  Session *session= getTable()->in_use;
452
 
  drizzle_system_variables *variables= &session->variables;
 
455
  Session *session= table->in_use;
 
456
  struct system_variables *variables= &session->variables;
453
457
 
454
458
  /*
455
459
    next_insert_id is a "cursor" into the reserved interval, it may go greater
461
465
     for an auto increment column, not a magic value like NULL is.
462
466
     same as sql_mode=NO_AUTO_VALUE_ON_ZERO */
463
467
 
464
 
  if ((nr= getTable()->next_number_field->val_int()) != 0
465
 
      || getTable()->auto_increment_field_not_null)
 
468
  if ((nr= table->next_number_field->val_int()) != 0
 
469
      || table->auto_increment_field_not_null)
466
470
  {
467
471
    /*
468
472
      Update next_insert_id if we had already generated a value in this
540
544
      nr= compute_next_insert_id(nr-1, variables);
541
545
    }
542
546
 
543
 
    if (getTable()->getShare()->next_number_keypart == 0)
 
547
    if (table->getShare()->next_number_keypart == 0)
544
548
    {
545
549
      /* We must defer the appending until "nr" has been possibly truncated */
546
550
      append= true;
547
551
    }
548
552
  }
549
553
 
550
 
  if (unlikely(getTable()->next_number_field->store((int64_t) nr, true)))
 
554
  if (unlikely(table->next_number_field->store((int64_t) nr, true)))
551
555
  {
552
556
    /*
553
557
      first test if the query was aborted due to strict mode constraints
554
558
    */
555
 
    if (session->getKilled() == Session::KILL_BAD_DATA)
 
559
    if (session->killed == Session::KILL_BAD_DATA)
556
560
      return HA_ERR_AUTOINC_ERANGE;
557
561
 
558
562
    /*
563
567
      bother shifting the right bound (anyway any other value from this
564
568
      interval will cause a duplicate key).
565
569
    */
566
 
    nr= prev_insert_id(getTable()->next_number_field->val_int(), variables);
567
 
    if (unlikely(getTable()->next_number_field->store((int64_t) nr, true)))
568
 
      nr= getTable()->next_number_field->val_int();
 
570
    nr= prev_insert_id(table->next_number_field->val_int(), variables);
 
571
    if (unlikely(table->next_number_field->store((int64_t) nr, true)))
 
572
      nr= table->next_number_field->val_int();
569
573
  }
570
574
  if (append)
571
575
  {
619
623
      this statement used forced auto_increment values if there were some,
620
624
      wipe them away for other statements.
621
625
    */
622
 
    getTable()->in_use->auto_inc_intervals_forced.empty();
 
626
    table->in_use->auto_inc_intervals_forced.empty();
623
627
  }
624
628
}
625
629
 
665
669
   * possible resource to gain (and if there is... then there is a bug such
666
670
   * that in_use should have been set.
667
671
 */
668
 
  if (not getTable()->in_use)
 
672
  if (not table || not table->in_use)
669
673
    return;
670
674
 
671
 
  resource_context= getTable()->in_use->getResourceContext(getEngine());
 
675
  resource_context= table->in_use->getResourceContext(engine);
672
676
  /*
673
677
    When a storage engine method is called, the transaction must
674
678
    have been started, unless it's a DDL call, for which the
709
713
     * @todo Make TransactionServices generic to AfterTriggerServices
710
714
     * or similar...
711
715
     */
712
 
    Session *const session= getTable()->in_use;
 
716
    Session *const session= table->in_use;
713
717
    TransactionServices &transaction_services= TransactionServices::singleton();
714
 
    transaction_services.truncateTable(*session, *getTable());
 
718
    transaction_services.truncateTable(session, table);
715
719
  }
716
720
 
717
721
  return result;
810
814
  int error;
811
815
  if (!(error=index_next(buf)))
812
816
  {
813
 
    ptrdiff_t ptrdiff= buf - getTable()->getInsertRecord();
 
817
    ptrdiff_t ptrdiff= buf - table->getInsertRecord();
814
818
    unsigned char *save_record_0= NULL;
815
819
    KeyInfo *key_info= NULL;
816
820
    KeyPartInfo *key_part;
826
830
    */
827
831
    if (ptrdiff)
828
832
    {
829
 
      save_record_0= getTable()->getInsertRecord();
830
 
      getTable()->record[0]= buf;
831
 
      key_info= getTable()->key_info + active_index;
 
833
      save_record_0= table->getInsertRecord();
 
834
      table->record[0]= buf;
 
835
      key_info= table->key_info + active_index;
832
836
      key_part= key_info->key_part;
833
837
      key_part_end= key_part + key_info->key_parts;
834
838
      for (; key_part < key_part_end; key_part++)
838
842
      }
839
843
    }
840
844
 
841
 
    if (key_cmp_if_same(getTable(), key, active_index, keylen))
 
845
    if (key_cmp_if_same(table, key, active_index, keylen))
842
846
    {
843
 
      getTable()->status=STATUS_NOT_FOUND;
 
847
      table->status=STATUS_NOT_FOUND;
844
848
      error=HA_ERR_END_OF_FILE;
845
849
    }
846
850
 
847
851
    /* Move back if necessary. */
848
852
    if (ptrdiff)
849
853
    {
850
 
      getTable()->record[0]= save_record_0;
 
854
      table->record[0]= save_record_0;
851
855
      for (key_part= key_info->key_part; key_part < key_part_end; key_part++)
852
856
        key_part->field->move_field_offset(-ptrdiff);
853
857
    }
884
888
double Cursor::index_only_read_time(uint32_t keynr, double key_records)
885
889
{
886
890
  uint32_t keys_per_block= (stats.block_size/2/
887
 
                        (getTable()->key_info[keynr].key_length + ref_length) + 1);
 
891
                        (table->key_info[keynr].key_length + ref_length) + 1);
888
892
  return ((double) (key_records + keys_per_block-1) /
889
893
          (double) keys_per_block);
890
894
}
913
917
 
914
918
  @note
915
919
    This method (or an overriding one in a derived class) must check for
916
 
    session->getKilled() and return HA_POS_ERROR if it is not zero. This is required
 
920
    session->killed and return HA_POS_ERROR if it is not zero. This is required
917
921
    for a user to be able to interrupt the calculation by killing the
918
922
    connection/query.
919
923
 
1191
1195
    key_compare_result_on_equal= ((end_key->flag == HA_READ_BEFORE_KEY) ? 1 :
1192
1196
                                  (end_key->flag == HA_READ_AFTER_KEY) ? -1 : 0);
1193
1197
  }
1194
 
  range_key_part= getTable()->key_info[active_index].key_part;
 
1198
  range_key_part= table->key_info[active_index].key_part;
1195
1199
 
1196
1200
  if (!start_key)                       // Read first record
1197
 
    result= index_first(getTable()->getInsertRecord());
 
1201
    result= index_first(table->getInsertRecord());
1198
1202
  else
1199
 
    result= index_read_map(getTable()->getInsertRecord(),
 
1203
    result= index_read_map(table->getInsertRecord(),
1200
1204
                           start_key->key,
1201
1205
                           start_key->keypart_map,
1202
1206
                           start_key->flag);
1229
1233
  if (eq_range)
1230
1234
  {
1231
1235
    /* We trust that index_next_same always gives a row in range */
1232
 
    return(index_next_same(getTable()->getInsertRecord(),
 
1236
    return(index_next_same(table->getInsertRecord(),
1233
1237
                                end_range->key,
1234
1238
                                end_range->length));
1235
1239
  }
1236
 
  result= index_next(getTable()->getInsertRecord());
 
1240
  result= index_next(table->getInsertRecord());
1237
1241
  if (result)
1238
1242
    return result;
1239
1243
  return(compare_key(end_range) <= 0 ? 0 : HA_ERR_END_OF_FILE);
1300
1304
 
1301
1305
  bool result= false;
1302
1306
 
1303
 
  switch (session->getLex()->sql_command)
 
1307
  switch (session->lex->sql_command)
1304
1308
  {
1305
1309
  case SQLCOM_CREATE_TABLE:
1306
1310
    /*
1312
1316
     * CREATE TABLE will commit the transaction containing
1313
1317
     * it).
1314
1318
     */
1315
 
    result= transaction_services.insertRecord(*session, *table);
 
1319
    result= transaction_services.insertRecord(session, table);
1316
1320
    break;
1317
1321
  case SQLCOM_REPLACE:
1318
1322
  case SQLCOM_REPLACE_SELECT:
1323
1327
     * called.  If it fails, then a call to deleteRecord()
1324
1328
     * is called, followed by a repeat of the original
1325
1329
     * call to insertRecord().  So, log_row_for_replication
1326
 
     * could be called multiple times for a REPLACE
 
1330
     * could be called either once or twice for a REPLACE
1327
1331
     * statement.  The below looks at the values of before_record
1328
1332
     * and after_record to determine which call to this
1329
1333
     * function is for the delete or the insert, since NULL
1336
1340
     */
1337
1341
    if (after_record == NULL)
1338
1342
    {
1339
 
      /*
1340
 
       * The storage engine is passed the record in table->record[1]
1341
 
       * as the row to delete (this is the conflicting row), so
1342
 
       * we need to notify TransactionService to use that row.
1343
 
       */
1344
 
      transaction_services.deleteRecord(*session, *table, true);
 
1343
      transaction_services.deleteRecord(session, table);
1345
1344
      /* 
1346
1345
       * We set the "current" statement message to NULL.  This triggers
1347
1346
       * the replication services component to generate a new statement
1348
1347
       * message for the inserted record which will come next.
1349
1348
       */
1350
 
      transaction_services.finalizeStatementMessage(*session->getStatementMessage(), *session);
 
1349
      transaction_services.finalizeStatementMessage(*session->getStatementMessage(), session);
1351
1350
    }
1352
1351
    else
1353
1352
    {
1354
1353
      if (before_record == NULL)
1355
 
        result= transaction_services.insertRecord(*session, *table);
 
1354
        result= transaction_services.insertRecord(session, table);
1356
1355
      else
1357
 
        transaction_services.updateRecord(*session, *table, before_record, after_record);
 
1356
        transaction_services.updateRecord(session, table, before_record, after_record);
1358
1357
    }
1359
1358
    break;
1360
1359
  case SQLCOM_INSERT:
1361
1360
  case SQLCOM_INSERT_SELECT:
1362
 
  case SQLCOM_LOAD:
1363
1361
    /*
1364
1362
     * The else block below represents an 
1365
1363
     * INSERT ... ON DUPLICATE KEY UPDATE that
1367
1365
     * an update.
1368
1366
     */
1369
1367
    if (before_record == NULL)
1370
 
      result= transaction_services.insertRecord(*session, *table);
 
1368
      result= transaction_services.insertRecord(session, table);
1371
1369
    else
1372
 
      transaction_services.updateRecord(*session, *table, before_record, after_record);
 
1370
      transaction_services.updateRecord(session, table, before_record, after_record);
1373
1371
    break;
1374
1372
 
1375
1373
  case SQLCOM_UPDATE:
1376
 
    transaction_services.updateRecord(*session, *table, before_record, after_record);
 
1374
    transaction_services.updateRecord(session, table, before_record, after_record);
1377
1375
    break;
1378
1376
 
1379
1377
  case SQLCOM_DELETE:
1380
 
    transaction_services.deleteRecord(*session, *table);
 
1378
    transaction_services.deleteRecord(session, table);
1381
1379
    break;
1382
1380
  default:
1383
1381
    break;
1401
1399
  {
1402
1400
    if (lock_type == F_RDLCK)
1403
1401
    {
1404
 
      DRIZZLE_CURSOR_RDLOCK_START(getTable()->getShare()->getSchemaName(),
1405
 
                                  getTable()->getShare()->getTableName());
 
1402
      DRIZZLE_CURSOR_RDLOCK_START(table_share->getSchemaName(),
 
1403
                                  table_share->getTableName());
1406
1404
    }
1407
1405
    else if (lock_type == F_WRLCK)
1408
1406
    {
1409
 
      DRIZZLE_CURSOR_WRLOCK_START(getTable()->getShare()->getSchemaName(),
1410
 
                                  getTable()->getShare()->getTableName());
 
1407
      DRIZZLE_CURSOR_WRLOCK_START(table_share->getSchemaName(),
 
1408
                                  table_share->getTableName());
1411
1409
    }
1412
1410
    else if (lock_type == F_UNLCK)
1413
1411
    {
1414
 
      DRIZZLE_CURSOR_UNLOCK_START(getTable()->getShare()->getSchemaName(),
1415
 
                                  getTable()->getShare()->getTableName());
 
1412
      DRIZZLE_CURSOR_UNLOCK_START(table_share->getSchemaName(),
 
1413
                                  table_share->getTableName());
1416
1414
    }
1417
1415
  }
1418
1416
 
1451
1449
int Cursor::ha_reset()
1452
1450
{
1453
1451
  /* Check that we have called all proper deallocation functions */
1454
 
  assert(! getTable()->getShare()->all_set.none());
1455
 
  assert(getTable()->key_read == 0);
 
1452
  assert((unsigned char*) table->def_read_set.getBitmap() +
 
1453
              table->getShare()->column_bitmap_size ==
 
1454
              (unsigned char*) table->def_write_set.getBitmap());
 
1455
  assert(table->getShare()->all_set.isSetAll());
 
1456
  assert(table->key_read == 0);
1456
1457
  /* ensure that ha_index_end / endTableScan has been called */
1457
1458
  assert(inited == NONE);
1458
1459
  /* Free cache used by filesort */
1459
 
  getTable()->free_io_cache();
 
1460
  table->free_io_cache();
1460
1461
  /* reset the bitmaps to point to defaults */
1461
 
  getTable()->default_column_bitmaps();
 
1462
  table->default_column_bitmaps();
1462
1463
  return(reset());
1463
1464
}
1464
1465
 
1473
1474
   * @TODO Technically, the below two lines can be take even further out of the
1474
1475
   * Cursor interface and into the fill_record() method.
1475
1476
   */
1476
 
  if (getTable()->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
 
1477
  if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
1477
1478
  {
1478
 
    getTable()->timestamp_field->set_time();
 
1479
    table->timestamp_field->set_time();
1479
1480
  }
1480
1481
 
1481
 
  DRIZZLE_INSERT_ROW_START(getTable()->getShare()->getSchemaName(), getTable()->getShare()->getTableName());
 
1482
  DRIZZLE_INSERT_ROW_START(table_share->getSchemaName(), table_share->getTableName());
1482
1483
  setTransactionReadWrite();
1483
1484
  
1484
 
  if (unlikely(plugin::EventObserver::beforeInsertRecord(*getTable(), buf)))
 
1485
  if (unlikely(plugin::EventObserver::beforeInsertRecord(*table, buf)))
1485
1486
  {
1486
1487
    error= ER_EVENT_OBSERVER_PLUGIN;
1487
1488
  }
1488
1489
  else
1489
1490
  {
1490
1491
    error= doInsertRecord(buf);
1491
 
    if (unlikely(plugin::EventObserver::afterInsertRecord(*getTable(), buf, error))) 
 
1492
    if (unlikely(plugin::EventObserver::afterInsertRecord(*table, buf, error))) 
1492
1493
    {
1493
1494
      error= ER_EVENT_OBSERVER_PLUGIN;
1494
1495
    }
1503
1504
    return error;
1504
1505
  }
1505
1506
 
1506
 
  if (unlikely(log_row_for_replication(getTable(), NULL, buf)))
 
1507
  if (unlikely(log_row_for_replication(table, NULL, buf)))
1507
1508
    return HA_ERR_RBR_LOGGING_FAILED;
1508
1509
 
1509
1510
  return 0;
1518
1519
    Some storage engines require that the new record is in getInsertRecord()
1519
1520
    (and the old record is in getUpdateRecord()).
1520
1521
   */
1521
 
  assert(new_data == getTable()->getInsertRecord());
 
1522
  assert(new_data == table->getInsertRecord());
1522
1523
 
1523
 
  DRIZZLE_UPDATE_ROW_START(getTable()->getShare()->getSchemaName(), getTable()->getShare()->getTableName());
 
1524
  DRIZZLE_UPDATE_ROW_START(table_share->getSchemaName(), table_share->getTableName());
1524
1525
  setTransactionReadWrite();
1525
 
  if (unlikely(plugin::EventObserver::beforeUpdateRecord(*getTable(), old_data, new_data)))
 
1526
  if (unlikely(plugin::EventObserver::beforeUpdateRecord(*table, old_data, new_data)))
1526
1527
  {
1527
1528
    error= ER_EVENT_OBSERVER_PLUGIN;
1528
1529
  }
1529
1530
  else
1530
1531
  {
1531
 
    if (getTable()->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
 
1532
    if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
1532
1533
    {
1533
 
      getTable()->timestamp_field->set_time();
 
1534
      table->timestamp_field->set_time();
1534
1535
    }
1535
1536
 
1536
1537
    error= doUpdateRecord(old_data, new_data);
1537
 
    if (unlikely(plugin::EventObserver::afterUpdateRecord(*getTable(), old_data, new_data, error)))
 
1538
    if (unlikely(plugin::EventObserver::afterUpdateRecord(*table, old_data, new_data, error)))
1538
1539
    {
1539
1540
      error= ER_EVENT_OBSERVER_PLUGIN;
1540
1541
    }
1549
1550
    return error;
1550
1551
  }
1551
1552
 
1552
 
  if (unlikely(log_row_for_replication(getTable(), old_data, new_data)))
 
1553
  if (unlikely(log_row_for_replication(table, old_data, new_data)))
1553
1554
    return HA_ERR_RBR_LOGGING_FAILED;
1554
1555
 
1555
1556
  return 0;
1556
1557
}
1557
 
TableShare *Cursor::getShare()
1558
 
{
1559
 
  return getTable()->getMutableShare();
1560
 
}
1561
1558
 
1562
1559
int Cursor::deleteRecord(const unsigned char *buf)
1563
1560
{
1564
1561
  int error;
1565
1562
 
1566
 
  DRIZZLE_DELETE_ROW_START(getTable()->getShare()->getSchemaName(), getTable()->getShare()->getTableName());
 
1563
  DRIZZLE_DELETE_ROW_START(table_share->getSchemaName(), table_share->getTableName());
1567
1564
  setTransactionReadWrite();
1568
 
  if (unlikely(plugin::EventObserver::beforeDeleteRecord(*getTable(), buf)))
 
1565
  if (unlikely(plugin::EventObserver::beforeDeleteRecord(*table, buf)))
1569
1566
  {
1570
1567
    error= ER_EVENT_OBSERVER_PLUGIN;
1571
1568
  }
1572
1569
  else
1573
1570
  {
1574
1571
    error= doDeleteRecord(buf);
1575
 
    if (unlikely(plugin::EventObserver::afterDeleteRecord(*getTable(), buf, error)))
 
1572
    if (unlikely(plugin::EventObserver::afterDeleteRecord(*table, buf, error)))
1576
1573
    {
1577
1574
      error= ER_EVENT_OBSERVER_PLUGIN;
1578
1575
    }
1585
1582
  if (unlikely(error))
1586
1583
    return error;
1587
1584
 
1588
 
  if (unlikely(log_row_for_replication(getTable(), buf, NULL)))
 
1585
  if (unlikely(log_row_for_replication(table, buf, NULL)))
1589
1586
    return HA_ERR_RBR_LOGGING_FAILED;
1590
1587
 
1591
1588
  return 0;