23
23
Handler-calling-functions
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"
28
#include <drizzled/error.h>
29
#include <drizzled/field/epoch.h>
30
#include <drizzled/gettext.h>
31
#include <drizzled/internal/my_sys.h>
32
#include <drizzled/item/empty_string.h>
33
#include <drizzled/item/int.h>
34
#include <drizzled/lock.h>
35
#include <drizzled/message/table.h>
36
#include <drizzled/optimizer/cost_vector.h>
37
#include <drizzled/plugin/client.h>
38
#include <drizzled/plugin/event_observer.h>
39
#include <drizzled/plugin/storage_engine.h>
40
#include <drizzled/probes.h>
41
#include <drizzled/session.h>
42
#include <drizzled/sql_base.h>
43
#include <drizzled/sql_parse.h>
44
#include <drizzled/transaction_services.h>
45
#include <drizzled/key.h>
46
#include <drizzled/sql_lex.h>
47
#include <drizzled/resource_context.h>
48
#include <drizzled/statistics_variables.h>
49
#include <drizzled/system_variables.h>
48
51
using namespace std;
53
55
/****************************************************************************
54
56
** General Cursor functions
90
92
if (!(new_handler->ref= (unsigned char*) mem_root->alloc_root(ALIGN_SIZE(ref_length)*2)))
93
TableIdentifier identifier(getTable()->getShare()->getSchemaName(),
95
identifier::Table identifier(getTable()->getShare()->getSchemaName(),
94
96
getTable()->getShare()->getTableName(),
95
97
getTable()->getShare()->getType());
210
212
uint64_t Cursor::tableSize() { return stats.index_file_length + stats.data_file_length; }
211
213
uint64_t Cursor::rowSize() { return getTable()->getRecordLength() + getTable()->sizeFields(); }
213
int Cursor::doOpen(const TableIdentifier &identifier, int mode, uint32_t test_if_locked)
215
int Cursor::doOpen(const identifier::Table &identifier, int mode, uint32_t test_if_locked)
215
217
return open(identifier.getPath().c_str(), mode, test_if_locked);
221
223
Try O_RDONLY if cannot open as O_RDWR
222
224
Don't wait for locks if not HA_OPEN_WAIT_IF_LOCKED is set
224
int Cursor::ha_open(const TableIdentifier &identifier,
226
int Cursor::ha_open(const identifier::Table &identifier,
226
228
int test_if_locked)
267
269
int Cursor::read_first_row(unsigned char * buf, uint32_t primary_key)
271
273
ha_statistic_increment(&system_status_var::ha_read_first_count);
274
276
If there is very few deleted rows in the table, find the first row by
275
277
scanning the table.
276
TODO remove the test for HA_READ_ORDER
278
@todo remove the test for HA_READ_ORDER
278
280
if (stats.deleted < 10 || primary_key >= MAX_KEY ||
279
281
!(getTable()->index_flags(primary_key) & HA_READ_ORDER))
281
(void) startTableScan(1);
282
while ((error= rnd_next(buf)) == HA_ERR_RECORD_DELETED) ;
283
(void) endTableScan();
283
error= startTableScan(1);
286
while ((error= rnd_next(buf)) == HA_ERR_RECORD_DELETED) ;
287
(void) endTableScan();
287
292
/* Find the first row through the primary key */
288
(void) startIndexScan(primary_key, 0);
289
error=index_first(buf);
290
(void) endIndexScan();
293
error= startIndexScan(primary_key, 0);
296
error=index_first(buf);
297
(void) endIndexScan();
472
480
if ((nr= next_insert_id) >= auto_inc_interval_for_cur_row.maximum())
474
/* next_insert_id is beyond what is reserved, so we reserve more. */
475
const Discrete_interval *forced=
476
session->auto_inc_intervals_forced.get_next();
479
nr= forced->minimum();
480
nb_reserved_values= forced->values();
485
484
Cursor::estimation_rows_to_insert was set by
486
485
Cursor::ha_start_bulk_insert(); if 0 it means "unknown".
488
uint32_t nb_already_reserved_intervals=
489
session->auto_inc_intervals_in_cur_stmt_for_binlog.nb_elements();
487
uint32_t nb_already_reserved_intervals= 0;
490
488
uint64_t nb_desired_values;
492
490
If an estimation was given to the engine:
561
559
nr= getTable()->next_number_field->val_int();
565
auto_inc_interval_for_cur_row.replace(nr, nb_reserved_values,
566
variables->auto_increment_increment);
562
auto_inc_interval_for_cur_row.replace(nr, nb_reserved_values, variables->auto_increment_increment);
570
565
Record this autogenerated value. If the caller then
605
600
release_auto_increment();
606
601
insert_id_for_cur_row= 0;
607
602
auto_inc_interval_for_cur_row.replace(0, 0, 0);
608
if (next_insert_id > 0)
612
this statement used forced auto_increment values if there were some,
613
wipe them away for other statements.
615
getTable()->in_use->auto_inc_intervals_forced.empty();
619
606
void Cursor::drop_table(const char *)
661
646
if (not getTable()->in_use)
664
resource_context= getTable()->in_use->getResourceContext(getEngine());
666
650
When a storage engine method is called, the transaction must
667
651
have been started, unless it's a DDL call, for which the
670
654
Unfortunately here we can't know know for sure if the engine
671
655
has registered the transaction or not, so we must check.
673
if (resource_context->isStarted())
675
resource_context->markModifiedData();
657
ResourceContext& resource_context= getTable()->in_use->getResourceContext(*getEngine());
658
if (resource_context.isStarted())
659
resource_context.markModifiedData();
705
688
Session *const session= getTable()->in_use;
706
689
TransactionServices &transaction_services= TransactionServices::singleton();
707
transaction_services.truncateTable(session, getTable());
690
transaction_services.truncateTable(*session, *getTable());
1305
1288
* CREATE TABLE will commit the transaction containing
1308
result= transaction_services.insertRecord(session, table);
1291
result= transaction_services.insertRecord(*session, *table);
1310
1293
case SQLCOM_REPLACE:
1311
1294
case SQLCOM_REPLACE_SELECT:
1334
1317
* as the row to delete (this is the conflicting row), so
1335
1318
* we need to notify TransactionService to use that row.
1337
transaction_services.deleteRecord(session, table, true);
1320
transaction_services.deleteRecord(*session, *table, true);
1339
1322
* We set the "current" statement message to NULL. This triggers
1340
1323
* the replication services component to generate a new statement
1341
1324
* message for the inserted record which will come next.
1343
transaction_services.finalizeStatementMessage(*session->getStatementMessage(), session);
1326
transaction_services.finalizeStatementMessage(*session->getStatementMessage(), *session);
1347
1330
if (before_record == NULL)
1348
result= transaction_services.insertRecord(session, table);
1331
result= transaction_services.insertRecord(*session, *table);
1350
transaction_services.updateRecord(session, table, before_record, after_record);
1333
transaction_services.updateRecord(*session, *table, before_record, after_record);
1353
1336
case SQLCOM_INSERT:
1362
1345
if (before_record == NULL)
1363
result= transaction_services.insertRecord(session, table);
1346
result= transaction_services.insertRecord(*session, *table);
1365
transaction_services.updateRecord(session, table, before_record, after_record);
1348
transaction_services.updateRecord(*session, *table, before_record, after_record);
1368
1351
case SQLCOM_UPDATE:
1369
transaction_services.updateRecord(session, table, before_record, after_record);
1352
transaction_services.updateRecord(*session, *table, before_record, after_record);
1372
1355
case SQLCOM_DELETE:
1373
transaction_services.deleteRecord(session, table);
1356
transaction_services.deleteRecord(*session, *table);