19
19
Handler-calling-functions
22
#ifdef USE_PRAGMA_IMPLEMENTATION
23
#pragma implementation // gcc: Class implementation
26
22
#include <drizzled/server_includes.h>
27
#include "rpl_filter.h"
28
#include <drizzled/drizzled_error_messages.h>
23
#include <drizzled/rpl_filter.h>
24
#include <drizzled/error.h>
25
#include <drizzled/gettext.h>
26
#include <drizzled/data_home.h>
27
#include <drizzled/probes.h>
28
#include <drizzled/sql_parse.h>
31
31
While we have legacy_db_type, we have this array to
72
static plugin_ref ha_default_plugin(THD *thd)
70
static plugin_ref ha_default_plugin(Session *session)
74
if (thd->variables.table_plugin)
75
return thd->variables.table_plugin;
76
return my_plugin_lock(thd, &global_system_variables.table_plugin);
72
if (session->variables.table_plugin)
73
return session->variables.table_plugin;
74
return my_plugin_lock(session, &global_system_variables.table_plugin);
81
79
Return the default storage engine handlerton for thread
83
@param ha_default_handlerton(thd)
84
@param thd current thread
81
@param ha_default_handlerton(session)
82
@param session current thread
87
85
pointer to handlerton
89
handlerton *ha_default_handlerton(THD *thd)
87
handlerton *ha_default_handlerton(Session *session)
91
plugin_ref plugin= ha_default_plugin(thd);
89
plugin_ref plugin= ha_default_plugin(session);
93
91
handlerton *hton= plugin_data(plugin, handlerton*);
100
98
Return the storage engine handlerton for the supplied name
102
@param thd current thread
100
@param session current thread
103
101
@param name name of storage engine
106
104
pointer to storage engine plugin handle
108
plugin_ref ha_resolve_by_name(THD *thd, const LEX_STRING *name)
106
plugin_ref ha_resolve_by_name(Session *session, const LEX_STRING *name)
110
108
const LEX_STRING *table_alias;
111
109
plugin_ref plugin;
114
112
/* my_strnncoll is a macro and gcc doesn't do early expansion of macro */
115
if (thd && !my_charset_utf8_general_ci.coll->strnncoll(&my_charset_utf8_general_ci,
113
if (session && !my_charset_utf8_general_ci.coll->strnncoll(&my_charset_utf8_general_ci,
116
114
(const unsigned char *)name->str, name->length,
117
115
(const unsigned char *)STRING_WITH_LEN("DEFAULT"), 0))
118
return ha_default_plugin(thd);
116
return ha_default_plugin(session);
120
if ((plugin= my_plugin_lock_by_name(thd, name, DRIZZLE_STORAGE_ENGINE_PLUGIN)))
118
if ((plugin= my_plugin_lock_by_name(session, name, DRIZZLE_STORAGE_ENGINE_PLUGIN)))
122
120
handlerton *hton= plugin_data(plugin, handlerton *);
123
121
if (!(hton->flags & HTON_NOT_USER_SELECTABLE))
150
plugin_ref ha_lock_engine(THD *thd, handlerton *hton)
148
plugin_ref ha_lock_engine(Session *session, handlerton *hton)
154
152
st_plugin_int **plugin= hton2plugin + hton->slot;
156
return my_plugin_lock(thd, &plugin);
154
return my_plugin_lock(session, &plugin);
162
handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type)
160
handlerton *ha_resolve_by_legacy_type(Session *session, enum legacy_db_type db_type)
164
162
plugin_ref plugin;
165
163
switch (db_type) {
166
164
case DB_TYPE_DEFAULT:
167
return ha_default_handlerton(thd);
165
return ha_default_handlerton(session);
169
167
if (db_type > DB_TYPE_UNKNOWN && db_type < DB_TYPE_DEFAULT &&
170
(plugin= ha_lock_engine(thd, installed_htons[db_type])))
168
(plugin= ha_lock_engine(session, installed_htons[db_type])))
171
169
return plugin_data(plugin, handlerton*);
172
170
/* fall through */
173
171
case DB_TYPE_UNKNOWN:
180
178
Use other database handler if databasehandler is not compiled in.
182
handlerton *ha_checktype(THD *thd, enum legacy_db_type database_type,
180
handlerton *ha_checktype(Session *session, enum legacy_db_type database_type,
183
181
bool no_substitute, bool report_error)
185
handlerton *hton= ha_resolve_by_legacy_type(thd, database_type);
183
handlerton *hton= ha_resolve_by_legacy_type(session, database_type);
186
184
if (ha_storage_engine_is_enabled(hton))
215
213
Try the default table type
216
Here the call to current_thd() is ok as we call this function a lot of
214
Here the call to current_session() is ok as we call this function a lot of
217
215
times but we enter this branch very seldom.
219
return(get_new_handler(share, alloc, ha_default_handlerton(current_thd)));
217
return(get_new_handler(share, alloc, ha_default_handlerton(current_session)));
487
485
don't bother to rollback here, it's done already
489
void ha_close_connection(THD* thd)
487
void ha_close_connection(Session* session)
491
plugin_foreach(thd, closecon_handlerton, DRIZZLE_STORAGE_ENGINE_PLUGIN, 0);
489
plugin_foreach(session, closecon_handlerton, DRIZZLE_STORAGE_ENGINE_PLUGIN, 0);
494
492
/* ========================================================================
595
593
The server stores its transaction-related data in
596
thd->transaction. This structure has two members of type
597
THD_TRANS. These members correspond to the statement and
594
session->transaction. This structure has two members of type
595
Session_TRANS. These members correspond to the statement and
598
596
normal transactions respectively:
600
- thd->transaction.stmt contains a list of engines
598
- session->transaction.stmt contains a list of engines
601
599
that are participating in the given statement
602
- thd->transaction.all contains a list of engines that
600
- session->transaction.all contains a list of engines that
603
601
have participated in any of the statement transactions started
604
602
within the context of the normal transaction.
605
603
Each element of the list contains a pointer to the storage
606
604
engine, engine-specific transactional data, and engine-specific
607
605
transaction flags.
609
In autocommit mode thd->transaction.all is empty.
610
Instead, data of thd->transaction.stmt is
607
In autocommit mode session->transaction.all is empty.
608
Instead, data of session->transaction.stmt is
611
609
used to commit/rollback the normal transaction.
613
611
The list of registered engines has a few important properties:
644
642
- if the user has requested so, by issuing ROLLBACK SQL
646
644
- if one of the storage engines requested a rollback
647
by setting thd->transaction_rollback_request. This may
645
by setting session->transaction_rollback_request. This may
648
646
happen in case, e.g., when the transaction in the engine was
649
647
chosen a victim of the internal deadlock resolution algorithm
650
648
and rolled back internally. When such a situation happens, there
750
748
---------------------------------------------------
752
750
DDLs and operations with non-transactional engines
753
do not "register" in thd->transaction lists, and thus do not
751
do not "register" in session->transaction lists, and thus do not
754
752
modify the transaction state. Besides, each DDL in
755
753
MySQL is prefixed with an implicit normal transaction commit
756
754
(a call to end_active_trans()), and thus leaves nothing
797
795
times per transaction.
800
void trans_register_ha(THD *thd, bool all, handlerton *ht_arg)
798
void trans_register_ha(Session *session, bool all, handlerton *ht_arg)
800
Session_TRANS *trans;
803
801
Ha_trx_info *ha_info;
807
trans= &thd->transaction.all;
808
thd->server_status|= SERVER_STATUS_IN_TRANS;
805
trans= &session->transaction.all;
806
session->server_status|= SERVER_STATUS_IN_TRANS;
811
trans= &thd->transaction.stmt;
809
trans= &session->transaction.stmt;
813
ha_info= thd->ha_data[ht_arg->slot].ha_info + static_cast<unsigned>(all);
811
ha_info= session->ha_data[ht_arg->slot].ha_info + static_cast<unsigned>(all);
815
813
if (ha_info->is_started())
816
814
return; /* already registered, return */
843
841
handlerton *ht= ha_info->ht();
844
status_var_increment(thd->status_var.ha_prepare_count);
842
status_var_increment(session->status_var.ha_prepare_count);
847
if ((err= ht->prepare(ht, thd, all)))
845
if ((err= ht->prepare(ht, session, all)))
849
847
my_error(ER_ERROR_DURING_COMMIT, MYF(0), err);
850
ha_rollback_trans(thd, all);
848
ha_rollback_trans(session, all);
857
push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
855
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
858
856
ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
859
857
ha_resolve_storage_engine_name(ht));
896
Ha_trx_info *ha_info_all= &thd->ha_data[ha_info->ht()->slot].ha_info[1];
894
Ha_trx_info *ha_info_all= &session->ha_data[ha_info->ht()->slot].ha_info[1];
897
895
assert(ha_info != ha_info_all);
899
897
Merge read-only/read-write information about statement
900
898
transaction to its enclosing normal transaction. Do this
901
899
only if in a real transaction -- that is, if we know
902
that ha_info_all is registered in thd->transaction.all.
900
that ha_info_all is registered in session->transaction.all.
903
901
Since otherwise we only clutter the normal transaction flags.
905
903
if (ha_info_all->is_started()) /* false if autocommit. */
933
931
stored functions or triggers. So we simply do nothing now.
934
932
TODO: This should be fixed in later ( >= 5.1) releases.
936
int ha_commit_trans(THD *thd, bool all)
934
int ha_commit_trans(Session *session, bool all)
938
936
int error= 0, cookie= 0;
940
938
'all' means that this is either an explicit commit issued by
941
939
user, or an implicit commit issued by a DDL.
943
THD_TRANS *trans= all ? &thd->transaction.all : &thd->transaction.stmt;
944
bool is_real_trans= all || thd->transaction.all.ha_list == 0;
941
Session_TRANS *trans= all ? &session->transaction.all : &session->transaction.stmt;
942
bool is_real_trans= all || session->transaction.all.ha_list == 0;
945
943
Ha_trx_info *ha_info= trans->ha_list;
946
my_xid xid= thd->transaction.xid_state.xid.get_my_xid();
944
my_xid xid= session->transaction.xid_state.xid.get_my_xid();
949
947
We must not commit the normal transaction if a statement
951
949
flags will not get propagated to its normal transaction's
954
assert(thd->transaction.stmt.ha_list == NULL ||
955
trans == &thd->transaction.stmt);
952
assert(session->transaction.stmt.ha_list == NULL ||
953
trans == &session->transaction.stmt);
957
if (thd->in_sub_stmt)
960
Since we don't support nested statement transactions in 5.0,
961
we can't commit or rollback stmt transactions while we are inside
962
stored functions or triggers. So we simply do nothing now.
963
TODO: This should be fixed in later ( >= 5.1) releases.
968
We assume that all statements which commit or rollback main transaction
969
are prohibited inside of stored functions or triggers. So they should
970
bail out with error even before ha_commit_trans() call. To be 100% safe
971
let us throw error in non-debug builds.
974
my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
981
if (is_real_trans && wait_if_global_read_lock(thd, 0, 0))
959
if (is_real_trans && wait_if_global_read_lock(session, 0, 0))
983
ha_rollback_trans(thd, all);
961
ha_rollback_trans(session, all);
987
965
if ( is_real_trans
989
&& ! thd->slave_thread
967
&& ! session->slave_thread
992
970
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only");
993
ha_rollback_trans(thd, all);
971
ha_rollback_trans(session, all);
998
must_2pc= ha_check_and_coalesce_trx_read_only(thd, ha_info, all);
976
must_2pc= ha_check_and_coalesce_trx_read_only(session, ha_info, all);
1000
978
if (!trans->no_2pc && must_2pc)
1014
992
Sic: we know that prepare() is not NULL since otherwise
1015
993
trans->no_2pc would have been set.
1017
if ((err= ht->prepare(ht, thd, all)))
995
if ((err= ht->prepare(ht, session, all)))
1019
997
my_error(ER_ERROR_DURING_COMMIT, MYF(0), err);
1022
status_var_increment(thd->status_var.ha_prepare_count);
1000
status_var_increment(session->status_var.ha_prepare_count);
1024
1002
if (error || (is_real_trans && xid &&
1025
(error= !(cookie= tc_log->log_xid(thd, xid)))))
1003
(error= !(cookie= tc_log->log_xid(session, xid)))))
1027
ha_rollback_trans(thd, all);
1005
ha_rollback_trans(session, all);
1032
error=ha_commit_one_phase(thd, all) ? (cookie ? 2 : 1) : 0;
1010
error=ha_commit_one_phase(session, all) ? (cookie ? 2 : 1) : 0;
1034
1012
tc_log->unlog(cookie, xid);
1036
1014
if (is_real_trans)
1037
start_waiting_global_read_lock(thd);
1015
start_waiting_global_read_lock(session);
1044
1022
This function does not care about global read lock. A caller should.
1046
int ha_commit_one_phase(THD *thd, bool all)
1024
int ha_commit_one_phase(Session *session, bool all)
1049
THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt;
1050
bool is_real_trans=all || thd->transaction.all.ha_list == 0;
1027
Session_TRANS *trans=all ? &session->transaction.all : &session->transaction.stmt;
1028
bool is_real_trans=all || session->transaction.all.ha_list == 0;
1051
1029
Ha_trx_info *ha_info= trans->ha_list, *ha_info_next;
1057
1035
handlerton *ht= ha_info->ht();
1058
if ((err= ht->commit(ht, thd, all)))
1036
if ((err= ht->commit(ht, session, all)))
1060
1038
my_error(ER_ERROR_DURING_COMMIT, MYF(0), err);
1063
status_var_increment(thd->status_var.ha_commit_count);
1041
status_var_increment(session->status_var.ha_commit_count);
1064
1042
ha_info_next= ha_info->next();
1065
1043
ha_info->reset(); /* keep it conveniently zero-filled */
1067
1045
trans->ha_list= 0;
1068
1046
trans->no_2pc=0;
1069
1047
if (is_real_trans)
1070
thd->transaction.xid_state.xid.null();
1048
session->transaction.xid_state.xid.null();
1073
thd->variables.tx_isolation=thd->session_tx_isolation;
1074
thd->transaction.cleanup();
1051
session->variables.tx_isolation=session->session_tx_isolation;
1052
session->transaction.cleanup();
1081
int ha_rollback_trans(THD *thd, bool all)
1059
int ha_rollback_trans(Session *session, bool all)
1084
THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt;
1062
Session_TRANS *trans=all ? &session->transaction.all : &session->transaction.stmt;
1085
1063
Ha_trx_info *ha_info= trans->ha_list, *ha_info_next;
1086
bool is_real_trans=all || thd->transaction.all.ha_list == 0;
1064
bool is_real_trans=all || session->transaction.all.ha_list == 0;
1089
1067
We must not rollback the normal transaction if a statement
1090
1068
transaction is pending.
1092
assert(thd->transaction.stmt.ha_list == NULL ||
1093
trans == &thd->transaction.stmt);
1070
assert(session->transaction.stmt.ha_list == NULL ||
1071
trans == &session->transaction.stmt);
1095
if (thd->in_sub_stmt)
1098
If we are inside stored function or trigger we should not commit or
1099
rollback current statement transaction. See comment in ha_commit_trans()
1100
call for more information.
1105
my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
1110
1075
for (; ha_info; ha_info= ha_info_next)
1113
1078
handlerton *ht= ha_info->ht();
1114
if ((err= ht->rollback(ht, thd, all)))
1079
if ((err= ht->rollback(ht, session, all)))
1115
1080
{ // cannot happen
1116
1081
my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
1119
status_var_increment(thd->status_var.ha_rollback_count);
1084
status_var_increment(session->status_var.ha_rollback_count);
1120
1085
ha_info_next= ha_info->next();
1121
1086
ha_info->reset(); /* keep it conveniently zero-filled */
1123
1088
trans->ha_list= 0;
1124
1089
trans->no_2pc=0;
1125
1090
if (is_real_trans)
1126
thd->transaction.xid_state.xid.null();
1091
session->transaction.xid_state.xid.null();
1129
thd->variables.tx_isolation=thd->session_tx_isolation;
1130
thd->transaction.cleanup();
1094
session->variables.tx_isolation=session->session_tx_isolation;
1095
session->transaction.cleanup();
1134
thd->transaction_rollback_request= false;
1099
session->transaction_rollback_request= false;
1137
1102
If a non-transactional table was updated, warn; don't warn if this is a
1142
1107
the error log; but we don't want users to wonder why they have this
1143
1108
message in the error log, so we don't send it.
1145
if (is_real_trans && thd->transaction.all.modified_non_trans_table &&
1146
!thd->slave_thread && thd->killed != THD::KILL_CONNECTION)
1147
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1110
if (is_real_trans && session->transaction.all.modified_non_trans_table &&
1111
!session->slave_thread && session->killed != Session::KILL_CONNECTION)
1112
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1148
1113
ER_WARNING_NOT_COMPLETE_ROLLBACK,
1149
1114
ER(ER_WARNING_NOT_COMPLETE_ROLLBACK));
1161
1126
the user has used LOCK TABLES then that mechanism does not know to do the
1164
int ha_autocommit_or_rollback(THD *thd, int error)
1129
int ha_autocommit_or_rollback(Session *session, int error)
1166
if (thd->transaction.stmt.ha_list)
1131
if (session->transaction.stmt.ha_list)
1170
if (ha_commit_trans(thd, 0))
1135
if (ha_commit_trans(session, 0))
1175
(void) ha_rollback_trans(thd, 0);
1176
if (thd->transaction_rollback_request && !thd->in_sub_stmt)
1177
(void) ha_rollback(thd);
1140
(void) ha_rollback_trans(session, 0);
1141
if (session->transaction_rollback_request)
1142
(void) ha_rollback(session);
1180
thd->variables.tx_isolation=thd->session_tx_isolation;
1145
session->variables.tx_isolation=session->session_tx_isolation;
1418
1383
This function should be called when MySQL sends rows of a SELECT result set
1419
1384
or the EOF mark to the client. It releases a possible adaptive hash index
1420
S-latch held by thd in InnoDB and also releases a possible InnoDB query
1421
FIFO ticket to enter InnoDB. To save CPU time, InnoDB allows a thd to
1385
S-latch held by session in InnoDB and also releases a possible InnoDB query
1386
FIFO ticket to enter InnoDB. To save CPU time, InnoDB allows a session to
1422
1387
keep them over several calls of the InnoDB handler interface when a join
1423
1388
is executed. But when we let the control to pass to the client they have
1424
1389
to be released because if the application program uses mysql_use_result(),
1426
1391
performs another SQL query. In MySQL-4.1 this is even more important because
1427
1392
there a connection can have several SELECT queries open at the same time.
1429
@param thd the thread handle of the current connection
1394
@param session the thread handle of the current connection
1434
static bool release_temporary_latches(THD *thd, plugin_ref plugin,
1399
static bool release_temporary_latches(Session *session, plugin_ref plugin,
1435
1400
void *unused __attribute__((unused)))
1437
1402
handlerton *hton= plugin_data(plugin, handlerton *);
1439
1404
if (hton->state == SHOW_OPTION_YES && hton->release_temporary_latches)
1440
hton->release_temporary_latches(hton, thd);
1405
hton->release_temporary_latches(hton, session);
1446
int ha_release_temporary_latches(THD *thd)
1411
int ha_release_temporary_latches(Session *session)
1448
plugin_foreach(thd, release_temporary_latches, DRIZZLE_STORAGE_ENGINE_PLUGIN,
1413
plugin_foreach(session, release_temporary_latches, DRIZZLE_STORAGE_ENGINE_PLUGIN,
1454
int ha_rollback_to_savepoint(THD *thd, SAVEPOINT *sv)
1419
int ha_rollback_to_savepoint(Session *session, SAVEPOINT *sv)
1457
THD_TRANS *trans= (thd->in_sub_stmt ? &thd->transaction.stmt :
1458
&thd->transaction.all);
1422
Session_TRANS *trans= &session->transaction.all;
1459
1423
Ha_trx_info *ha_info, *ha_info_next;
1461
1425
trans->no_2pc=0;
1469
1433
handlerton *ht= ha_info->ht();
1471
1435
assert(ht->savepoint_set != 0);
1472
if ((err= ht->savepoint_rollback(ht, thd,
1436
if ((err= ht->savepoint_rollback(ht, session,
1473
1437
(unsigned char *)(sv+1)+ht->savepoint_offset)))
1474
1438
{ // cannot happen
1475
1439
my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
1478
status_var_increment(thd->status_var.ha_savepoint_rollback_count);
1442
status_var_increment(session->status_var.ha_savepoint_rollback_count);
1479
1443
trans->no_2pc|= ht->prepare == 0;
1489
1453
handlerton *ht= ha_info->ht();
1490
if ((err= ht->rollback(ht, thd, !thd->in_sub_stmt)))
1454
if ((err= ht->rollback(ht, session, !(0))))
1491
1455
{ // cannot happen
1492
1456
my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
1495
status_var_increment(thd->status_var.ha_rollback_count);
1459
status_var_increment(session->status_var.ha_rollback_count);
1496
1460
ha_info_next= ha_info->next();
1497
1461
ha_info->reset(); /* keep it conveniently zero-filled */
1506
1470
section "4.33.4 SQL-statements and transaction states",
1507
1471
SAVEPOINT is *not* transaction-initiating SQL-statement
1509
int ha_savepoint(THD *thd, SAVEPOINT *sv)
1473
int ha_savepoint(Session *session, SAVEPOINT *sv)
1512
THD_TRANS *trans= (thd->in_sub_stmt ? &thd->transaction.stmt :
1513
&thd->transaction.all);
1476
Session_TRANS *trans= &session->transaction.all;
1514
1477
Ha_trx_info *ha_info= trans->ha_list;
1515
1478
for (; ha_info; ha_info= ha_info->next())
1526
if ((err= ht->savepoint_set(ht, thd, (unsigned char *)(sv+1)+ht->savepoint_offset)))
1489
if ((err= ht->savepoint_set(ht, session, (unsigned char *)(sv+1)+ht->savepoint_offset)))
1527
1490
{ // cannot happen
1528
1491
my_error(ER_GET_ERRNO, MYF(0), err);
1531
status_var_increment(thd->status_var.ha_savepoint_count);
1494
status_var_increment(session->status_var.ha_savepoint_count);
1534
1497
Remember the list of registered storage engines. All new
1565
static bool snapshot_handlerton(THD *thd, plugin_ref plugin, void *arg)
1528
static bool snapshot_handlerton(Session *session, plugin_ref plugin, void *arg)
1567
1530
handlerton *hton= plugin_data(plugin, handlerton *);
1568
1531
if (hton->state == SHOW_OPTION_YES &&
1569
1532
hton->start_consistent_snapshot)
1571
hton->start_consistent_snapshot(hton, thd);
1534
hton->start_consistent_snapshot(hton, session);
1572
1535
*((bool *)arg)= false;
1577
int ha_start_consistent_snapshot(THD *thd)
1540
int ha_start_consistent_snapshot(Session *session)
1579
1542
bool warn= true;
1581
plugin_foreach(thd, snapshot_handlerton, DRIZZLE_STORAGE_ENGINE_PLUGIN, &warn);
1544
plugin_foreach(session, snapshot_handlerton, DRIZZLE_STORAGE_ENGINE_PLUGIN, &warn);
1584
1547
Same idea as when one wants to CREATE TABLE in one engine which does not
1588
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
1551
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
1589
1552
"This MySQL server does not support any "
1590
1553
"consistent-read capable storage engine");
1595
static bool flush_handlerton(THD *thd __attribute__((unused)),
1558
static bool flush_handlerton(Session *session __attribute__((unused)),
1596
1559
plugin_ref plugin,
1597
1560
void *arg __attribute__((unused)))
1674
1637
This should return ENOENT if the file doesn't exists.
1675
1638
The .frm file will be deleted only if we return 0 or ENOENT
1677
int ha_delete_table(THD *thd, handlerton *table_type, const char *path,
1640
int ha_delete_table(Session *session, handlerton *table_type, const char *path,
1678
1641
const char *db, const char *alias, bool generate_warning)
1715
1678
file->change_table_ptr(&dummy_table, &dummy_share);
1717
thd->push_internal_handler(&ha_delete_table_error_handler);
1680
session->push_internal_handler(&ha_delete_table_error_handler);
1718
1681
file->print_error(error, 0);
1720
thd->pop_internal_handler();
1683
session->pop_internal_handler();
1723
1686
XXX: should we convert *all* errors to warnings here?
1724
1687
What if the error is fatal?
1726
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR, error,
1689
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, error,
1727
1690
ha_delete_table_error_handler.buff);
1758
1721
status_var_increment(table->in_use->status_var.*offset);
1761
void **handler::ha_data(THD *thd) const
1724
void **handler::ha_data(Session *session) const
1763
return thd_ha_data(thd, ht);
1726
return session_ha_data(session, ht);
1766
THD *handler::ha_thd(void) const
1729
Session *handler::ha_session(void) const
1768
assert(!table || !table->in_use || table->in_use == current_thd);
1769
return (table && table->in_use) ? table->in_use : current_thd;
1731
assert(!table || !table->in_use || table->in_use == current_session);
1732
return (table && table->in_use) ? table->in_use : current_session;
1898
1861
void handler::adjust_next_insert_id_after_explicit_value(uint64_t nr)
1901
If we have set THD::next_insert_id previously and plan to insert an
1864
If we have set Session::next_insert_id previously and plan to insert an
1902
1865
explicitely-specified value larger than this, we need to increase
1903
THD::next_insert_id to be greater than the explicit value.
1866
Session::next_insert_id to be greater than the explicit value.
1905
1868
if ((next_insert_id > 0) && (nr >= next_insert_id))
1906
1869
set_next_insert_id(compute_next_insert_id(nr, &table->in_use->variables));
1990
1953
start counting from the inserted value.
1992
1955
This function's "outputs" are: the table's auto_increment field is filled
1993
with a value, thd->next_insert_id is filled with the value to use for the
1956
with a value, session->next_insert_id is filled with the value to use for the
1994
1957
next row, if a value was autogenerated for the current row it is stored in
1995
thd->insert_id_for_cur_row, if get_auto_increment() was called
1996
thd->auto_inc_interval_for_cur_row is modified, if that interval is not
1997
present in thd->auto_inc_intervals_in_cur_stmt_for_binlog it is added to
1958
session->insert_id_for_cur_row, if get_auto_increment() was called
1959
session->auto_inc_interval_for_cur_row is modified, if that interval is not
1960
present in session->auto_inc_intervals_in_cur_stmt_for_binlog it is added to
2139
2102
auto_inc_interval_for_cur_row.replace(nr, nb_reserved_values,
2140
2103
variables->auto_increment_increment);
2141
2104
/* Row-based replication does not need to store intervals in binlog */
2142
if (!thd->current_stmt_binlog_row_based)
2143
thd->auto_inc_intervals_in_cur_stmt_for_binlog.append(auto_inc_interval_for_cur_row.minimum(),
2105
if (!session->current_stmt_binlog_row_based)
2106
session->auto_inc_intervals_in_cur_stmt_for_binlog.append(auto_inc_interval_for_cur_row.minimum(),
2144
2107
auto_inc_interval_for_cur_row.values(),
2145
2108
variables->auto_increment_increment);
2560
2523
strxmov(path, table->s->normalized_path.str, reg_ext, NULL);
2562
if ((file= my_open(path, O_RDWR|O_BINARY, MYF(MY_WME))) >= 0)
2525
if ((file= my_open(path, O_RDWR, MYF(MY_WME))) >= 0)
2564
2527
unsigned char version[4];
2565
2528
char *key= table->s->table_cache_key.str;
2999
2962
is an optimization hint that storage engine is free to ignore.
3000
2963
So, let's commit an open transaction (if any) now.
3002
if (!(error= ha_commit_trans(thd, 0)))
3003
error= end_trans(thd, COMMIT);
2965
if (!(error= ha_commit_trans(session, 0)))
2966
error= end_trans(session, COMMIT);
3079
3042
const char *name;
3080
3043
TABLE_SHARE share;
3082
init_tmp_table_share(thd, &share, db, 0, table_name, path);
3083
if (open_table_def(thd, &share, 0) ||
3084
open_table_from_share(thd, &share, "", 0, (uint) READ_ALL, 0, &table,
3045
init_tmp_table_share(session, &share, db, 0, table_name, path);
3046
if (open_table_def(session, &share, 0) ||
3047
open_table_from_share(session, &share, "", 0, (uint) READ_ALL, 0, &table,
3126
3089
TABLE_SHARE share;
3128
3091
memset(&create_info, 0, sizeof(create_info));
3129
if ((error= ha_discover(thd, db, name, &frmblob, &frmlen)))
3092
if ((error= ha_discover(session, db, name, &frmblob, &frmlen)))
3131
3094
/* Table could not be discovered and thus not created */
3147
init_tmp_table_share(thd, &share, db, 0, name, path);
3148
if (open_table_def(thd, &share, 0))
3110
init_tmp_table_share(session, &share, db, 0, name, path);
3111
if (open_table_def(session, &share, 0))
3152
if (open_table_from_share(thd, &share, "" ,0, 0, 0, &table, OTM_OPEN))
3115
if (open_table_from_share(session, &share, "" ,0, 0, 0, &table, OTM_OPEN))
3154
3117
free_table_share(&share);
3280
3243
size_t *frmlen;
3283
static bool discover_handlerton(THD *thd, plugin_ref plugin,
3246
static bool discover_handlerton(Session *session, plugin_ref plugin,
3286
3249
st_discover_args *vargs= (st_discover_args *)arg;
3287
3250
handlerton *hton= plugin_data(plugin, handlerton *);
3288
3251
if (hton->state == SHOW_OPTION_YES && hton->discover &&
3289
(!(hton->discover(hton, thd, vargs->db, vargs->name,
3252
(!(hton->discover(hton, session, vargs->db, vargs->name,
3290
3253
vargs->frmblob,
3291
3254
vargs->frmlen))))
3303
3266
if (is_prefix(name,tmp_file_prefix)) /* skip temporary tables */
3306
if (plugin_foreach(thd, discover_handlerton,
3269
if (plugin_foreach(session, discover_handlerton,
3307
3270
DRIZZLE_STORAGE_ENGINE_PLUGIN, &args))
3311
status_var_increment(thd->status_var.ha_discover_count);
3274
status_var_increment(session->status_var.ha_discover_count);
3364
int ha_table_exists_in_engine(THD* thd, const char* db, const char* name)
3327
int ha_table_exists_in_engine(Session* session, const char* db, const char* name)
3366
3329
st_table_exists_in_engine_args args= {db, name, HA_ERR_NO_SUCH_TABLE};
3367
plugin_foreach(thd, table_exists_in_engine_handlerton,
3330
plugin_foreach(session, table_exists_in_engine_handlerton,
3368
3331
DRIZZLE_STORAGE_ENGINE_PLUGIN, &args);
3369
3332
return(args.err);
4401
4364
handlerton *hton= plugin_data(plugin, handlerton *);
4403
4366
if (hton->state == SHOW_OPTION_YES && hton->create &&
4404
(file= hton->create(hton, (TABLE_SHARE*) 0, current_thd->mem_root)))
4367
(file= hton->create(hton, (TABLE_SHARE*) 0, current_session->mem_root)))
4406
4369
List_iterator_fast<char> it(*found_exts);
4407
4370
const char **ext, *old_ext;
4455
static bool stat_print(THD *thd, const char *type, uint32_t type_len,
4418
static bool stat_print(Session *session, const char *type, uint32_t type_len,
4456
4419
const char *file, uint32_t file_len,
4457
4420
const char *status, uint32_t status_len)
4459
Protocol *protocol= thd->protocol;
4422
Protocol *protocol= session->protocol;
4460
4423
protocol->prepare_for_resend();
4461
4424
protocol->store(type, type_len, system_charset_info);
4462
4425
protocol->store(file, file_len, system_charset_info);
4513
4476
assert(table->s->cached_row_logging_check == 0 ||
4514
4477
table->s->cached_row_logging_check == 1);
4516
return (thd->current_stmt_binlog_row_based &&
4479
return (session->current_stmt_binlog_row_based &&
4517
4480
table->s->cached_row_logging_check &&
4518
(thd->options & OPTION_BIN_LOG) &&
4481
(session->options & OPTION_BIN_LOG) &&
4519
4482
mysql_bin_log.is_open());
4525
4488
to the binary log.
4527
4490
This function will generate and write table maps for all tables
4528
that are locked by the thread 'thd'. Either manually locked
4529
(stored in THD::locked_tables) and automatically locked (stored
4530
in THD::lock) are considered.
4491
that are locked by the thread 'session'. Either manually locked
4492
(stored in Session::locked_tables) and automatically locked (stored
4493
in Session::lock) are considered.
4532
@param thd Pointer to THD structure
4495
@param session Pointer to Session structure
4534
4497
@retval 0 All OK
4535
4498
@retval 1 Failed to write all table maps
4502
Session::locked_tables
4542
static int write_locked_table_maps(THD *thd)
4505
static int write_locked_table_maps(Session *session)
4544
if (thd->get_binlog_table_maps() == 0)
4507
if (session->get_binlog_table_maps() == 0)
4546
4509
DRIZZLE_LOCK *locks[3];
4547
locks[0]= thd->extra_lock;
4548
locks[1]= thd->lock;
4549
locks[2]= thd->locked_tables;
4510
locks[0]= session->extra_lock;
4511
locks[1]= session->lock;
4512
locks[2]= session->locked_tables;
4550
4513
for (uint32_t i= 0 ; i < sizeof(locks)/sizeof(*locks) ; ++i )
4552
4515
DRIZZLE_LOCK const *const lock= locks[i];
4561
4524
Table *const table= *table_ptr;
4562
4525
if (table->current_lock == F_WRLCK &&
4563
check_table_binlog_row_based(thd, table))
4526
check_table_binlog_row_based(session, table))
4565
4528
int const has_trans= table->file->has_transactions();
4566
int const error= thd->binlog_write_table_map(table, has_trans);
4529
int const error= session->binlog_write_table_map(table, has_trans);
4568
4531
If an error occurs, it is the responsibility of the caller to
4569
4532
roll back the transaction.
4581
typedef bool Log_func(THD*, Table*, bool, const unsigned char*, const unsigned char*);
4544
typedef bool Log_func(Session*, Table*, bool, const unsigned char*, const unsigned char*);
4583
4546
static int binlog_log_row(Table* table,
4584
4547
const unsigned char *before_record,
4588
4551
if (table->no_replicate)
4591
THD *const thd= table->in_use;
4554
Session *const session= table->in_use;
4593
if (check_table_binlog_row_based(thd, table))
4556
if (check_table_binlog_row_based(session, table))
4596
4559
If there are no table maps written to the binary log, this is
4597
4560
the first row handled in this statement. In that case, we need
4598
4561
to write table maps for all locked tables to the binary log.
4600
if (likely(!(error= write_locked_table_maps(thd))))
4563
if (likely(!(error= write_locked_table_maps(session))))
4602
4565
bool const has_trans= table->file->has_transactions();
4603
error= (*log_func)(thd, table, has_trans, before_record, after_record);
4566
error= (*log_func)(session, table, has_trans, before_record, after_record);
4606
4569
return error ? HA_ERR_RBR_LOGGING_FAILED : 0;
4609
int handler::ha_external_lock(THD *thd, int lock_type)
4572
int handler::ha_external_lock(Session *session, int lock_type)
4612
4575
Whether this is lock or unlock, this should be true, and is to verify that
4713
4676
/* fallback to use all columns in the table to identify row */
4714
4677
table->use_all_columns();
4680
void table_case_convert(char * name, uint32_t length)
4682
if (lower_case_table_names)
4683
files_charset_info->cset->casedn(files_charset_info,
4684
name, length, name, length);
4687
const char *table_case_name(HA_CREATE_INFO *info, const char *name)
4689
return ((lower_case_table_names == 2 && info->alias) ? info->alias : name);