80
83
Cursor *Cursor::clone(memory::Root *mem_root)
82
85
Cursor *new_handler= getTable()->getMutableShare()->db_type()->getCursor(*getTable());
85
87
Allocate Cursor->ref here because otherwise ha_open will allocate it
86
88
on this->table->mem_root and we will not be able to reclaim that memory
87
89
when the clone Cursor object is destroyed.
89
if (!(new_handler->ref= (unsigned char*) mem_root->alloc_root(ALIGN_SIZE(ref_length)*2)))
92
identifier::Table identifier(getTable()->getShare()->getSchemaName(),
93
getTable()->getShare()->getTableName(),
94
getTable()->getShare()->getType());
96
if (new_handler && !new_handler->ha_open(identifier,
97
getTable()->getDBStat(),
98
HA_OPEN_IGNORE_IF_LOCKED))
91
new_handler->ref= mem_root->alloc(ALIGN_SIZE(ref_length)*2);
92
identifier::Table identifier(getTable()->getShare()->getSchemaName(), getTable()->getShare()->getTableName(), getTable()->getShare()->getType());
93
return new_handler->ha_open(identifier, getTable()->getDBStat(), HA_OPEN_IGNORE_IF_LOCKED) ? NULL : new_handler;
400
385
we either take the next provided interval or call get_auto_increment()
401
386
again to reserve a new interval.
403
- In both cases, the reserved intervals are remembered in
404
session->auto_inc_intervals_in_cur_stmt_for_binlog if statement-based
405
binlogging; the last reserved interval is remembered in
388
- the last reserved interval is remembered in
406
389
auto_inc_interval_for_cur_row.
408
391
The idea is that generated auto_increment values are predictable and
418
401
with a value, session->next_insert_id is filled with the value to use for the
419
402
next row, if a value was autogenerated for the current row it is stored in
420
403
session->insert_id_for_cur_row, if get_auto_increment() was called
421
session->auto_inc_interval_for_cur_row is modified, if that interval is not
422
present in session->auto_inc_intervals_in_cur_stmt_for_binlog it is added to
404
session->auto_inc_interval_for_cur_row is modified.
426
407
Replace all references to "next number" or NEXT_NUMBER to
477
458
if ((nr= next_insert_id) >= auto_inc_interval_for_cur_row.maximum())
479
/* next_insert_id is beyond what is reserved, so we reserve more. */
480
const Discrete_interval *forced=
481
session->auto_inc_intervals_forced.get_next();
484
nr= forced->minimum();
485
nb_reserved_values= forced->values();
490
462
Cursor::estimation_rows_to_insert was set by
491
463
Cursor::ha_start_bulk_insert(); if 0 it means "unknown".
493
uint32_t nb_already_reserved_intervals=
494
session->auto_inc_intervals_in_cur_stmt_for_binlog.nb_elements();
465
uint32_t nb_already_reserved_intervals= 0;
495
466
uint64_t nb_desired_values;
497
468
If an estimation was given to the engine:
610
578
release_auto_increment();
611
579
insert_id_for_cur_row= 0;
612
580
auto_inc_interval_for_cur_row.replace(0, 0, 0);
613
if (next_insert_id > 0)
617
this statement used forced auto_increment values if there were some,
618
wipe them away for other statements.
620
getTable()->in_use->auto_inc_intervals_forced.empty();
624
void Cursor::drop_table(const char *)
584
void Cursor::drop_table()
631
Performs checks upon the table.
633
@param session thread doing CHECK Table operation
634
@param check_opt options from the parser
637
HA_ADMIN_OK Successful upgrade
639
HA_ADMIN_NEEDS_UPGRADE Table has structures requiring upgrade
641
HA_ADMIN_NEEDS_ALTER Table has structures requiring ALTER Table
643
HA_ADMIN_NOT_IMPLEMENTED
645
int Cursor::ha_check(Session *, HA_CHECK_OPT *)
589
int Cursor::ha_check(Session*)
647
591
return HA_ADMIN_OK;
795
732
@sa Cursor::drop_table()
799
Cursor::closeMarkForDelete(const char *name)
735
void Cursor::closeMarkForDelete()
801
737
setTransactionReadWrite();
803
return drop_table(name);
806
741
int Cursor::index_next_same(unsigned char *buf, const unsigned char *key, uint32_t keylen)
809
if (!(error=index_next(buf)))
811
ptrdiff_t ptrdiff= buf - getTable()->getInsertRecord();
812
unsigned char *save_record_0= NULL;
813
KeyInfo *key_info= NULL;
814
KeyPartInfo *key_part;
815
KeyPartInfo *key_part_end= NULL;
818
key_cmp_if_same() compares table->getInsertRecord() against 'key'.
819
In parts it uses table->getInsertRecord() directly, in parts it uses
820
field objects with their local pointers into table->getInsertRecord().
821
If 'buf' is distinct from table->getInsertRecord(), we need to move
822
all record references. This is table->getInsertRecord() itself and
823
the field pointers of the fields used in this key.
827
save_record_0= getTable()->getInsertRecord();
828
getTable()->record[0]= buf;
829
key_info= getTable()->key_info + active_index;
830
key_part= key_info->key_part;
831
key_part_end= key_part + key_info->key_parts;
832
for (; key_part < key_part_end; key_part++)
834
assert(key_part->field);
835
key_part->field->move_field_offset(ptrdiff);
839
if (key_cmp_if_same(getTable(), key, active_index, keylen))
841
getTable()->status=STATUS_NOT_FOUND;
842
error=HA_ERR_END_OF_FILE;
845
/* Move back if necessary. */
848
getTable()->record[0]= save_record_0;
849
for (key_part= key_info->key_part; key_part < key_part_end; key_part++)
850
key_part->field->move_field_offset(-ptrdiff);
743
int error= index_next(buf);
747
ptrdiff_t ptrdiff= buf - getTable()->getInsertRecord();
748
unsigned char *save_record_0= NULL;
749
KeyInfo *key_info= NULL;
750
KeyPartInfo *key_part;
751
KeyPartInfo *key_part_end= NULL;
754
key_cmp_if_same() compares table->getInsertRecord() against 'key'.
755
In parts it uses table->getInsertRecord() directly, in parts it uses
756
field objects with their local pointers into table->getInsertRecord().
757
If 'buf' is distinct from table->getInsertRecord(), we need to move
758
all record references. This is table->getInsertRecord() itself and
759
the field pointers of the fields used in this key.
763
save_record_0= getTable()->getInsertRecord();
764
getTable()->record[0]= buf;
765
key_info= getTable()->key_info + active_index;
766
key_part= key_info->key_part;
767
key_part_end= key_part + key_info->key_parts;
768
for (; key_part < key_part_end; key_part++)
770
assert(key_part->field);
771
key_part->field->move_field_offset(ptrdiff);
775
if (key_cmp_if_same(getTable(), key, active_index, keylen))
777
getTable()->status=STATUS_NOT_FOUND;
778
error= HA_ERR_END_OF_FILE;
781
/* Move back if necessary. */
784
getTable()->record[0]= save_record_0;
785
for (key_part= key_info->key_part; key_part < key_part_end; key_part++)
786
key_part->field->move_field_offset(-ptrdiff);
1279
1214
return error ? error : error1;
1283
Check if the conditions for row-based binlogging is correct for the table.
1285
A row in the given table should be replicated if:
1286
- It is not a temporary table
1289
1217
static bool log_row_for_replication(Table* table,
1290
1218
const unsigned char *before_record,
1291
1219
const unsigned char *after_record)
1293
TransactionServices &transaction_services= TransactionServices::singleton();
1294
1221
Session *const session= table->in_use;
1296
if (table->getShare()->getType() || not transaction_services.shouldConstructMessages())
1223
if (table->getShare()->getType() || not TransactionServices::shouldConstructMessages())
1299
1226
bool result= false;
1339
1266
* as the row to delete (this is the conflicting row), so
1340
1267
* we need to notify TransactionService to use that row.
1342
transaction_services.deleteRecord(*session, *table, true);
1269
TransactionServices::deleteRecord(*session, *table, true);
1344
1271
* We set the "current" statement message to NULL. This triggers
1345
1272
* the replication services component to generate a new statement
1346
1273
* message for the inserted record which will come next.
1348
transaction_services.finalizeStatementMessage(*session->getStatementMessage(), *session);
1275
TransactionServices::finalizeStatementMessage(*session->getStatementMessage(), *session);
1352
1279
if (before_record == NULL)
1353
result= transaction_services.insertRecord(*session, *table);
1280
result= TransactionServices::insertRecord(*session, *table);
1355
transaction_services.updateRecord(*session, *table, before_record, after_record);
1282
TransactionServices::updateRecord(*session, *table, before_record, after_record);
1358
1285
case SQLCOM_INSERT:
1367
1294
if (before_record == NULL)
1368
result= transaction_services.insertRecord(*session, *table);
1295
result= TransactionServices::insertRecord(*session, *table);
1370
transaction_services.updateRecord(*session, *table, before_record, after_record);
1297
TransactionServices::updateRecord(*session, *table, before_record, after_record);
1373
1300
case SQLCOM_UPDATE:
1374
transaction_services.updateRecord(*session, *table, before_record, after_record);
1301
TransactionServices::updateRecord(*session, *table, before_record, after_record);
1377
1304
case SQLCOM_DELETE:
1378
transaction_services.deleteRecord(*session, *table);
1305
TransactionServices::deleteRecord(*session, *table);