1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1
/* Copyright (C) 2000-2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
21
17
/* Classes in mysql */
22
#include <drizzled/global.h>
19
#ifdef USE_PRAGMA_INTERFACE
20
#pragma interface /* gcc class implementation */
23
#include <mysql/plugin_audit.h>
24
25
#include "rpl_tblmap.h"
53
54
#define TC_HEURISTIC_RECOVER_COMMIT 1
54
55
#define TC_HEURISTIC_RECOVER_ROLLBACK 2
55
extern uint32_t tc_heuristic_recover;
56
extern uint tc_heuristic_recover;
57
58
typedef struct st_user_var_events
98
99
class Key_part_spec :public Sql_alloc {
100
101
LEX_STRING field_name;
102
Key_part_spec(const LEX_STRING &name, uint32_t len)
103
Key_part_spec(const LEX_STRING &name, uint len)
103
104
: field_name(name), length(len)
105
Key_part_spec(const char *name, const size_t name_len, uint32_t len)
106
Key_part_spec(const char *name, const size_t name_len, uint len)
107
108
{ field_name.str= (char *)name; field_name.length= name_len; }
108
109
bool operator==(const Key_part_spec& other) const;
199
200
Table_ident *ref_table;
200
201
List<Key_part_spec> ref_columns;
201
uint32_t delete_opt, update_opt, match_opt;
202
uint delete_opt, update_opt, match_opt;
202
203
Foreign_key(const LEX_STRING &name_arg, List<Key_part_spec> &cols,
203
204
Table_ident *table, List<Key_part_spec> &ref_cols,
204
uint32_t delete_opt_arg, uint32_t update_opt_arg, uint32_t match_opt_arg)
205
uint delete_opt_arg, uint update_opt_arg, uint match_opt_arg)
205
206
:Key(FOREIGN_KEY, name_arg, &default_key_create_info, 0, cols),
206
207
ref_table(table), ref_columns(ref_cols),
207
208
delete_opt(delete_opt_arg), update_opt(update_opt_arg),
215
216
virtual Key *clone(MEM_ROOT *mem_root) const
216
217
{ return new (mem_root) Foreign_key(*this, mem_root); }
217
/* Used to validate foreign key options */
218
bool validate(List<Create_field> &table_fields);
221
220
typedef struct st_mysql_lock
224
uint32_t table_count,lock_count;
223
uint table_count,lock_count;
225
224
THR_LOCK_DATA **locks;
229
228
class LEX_COLUMN : public Sql_alloc
234
233
LEX_COLUMN (const String& x,const uint& y ): column (x),rights (y) {}
237
Query_cache_tls -- query cache thread local data.
240
struct Query_cache_block;
242
struct Query_cache_tls
245
'first_query_block' should be accessed only via query cache
246
functions and methods to maintain proper locking.
248
Query_cache_block *first_query_block;
249
void set_first_query_block(Query_cache_block *first_query_block_arg)
251
first_query_block= first_query_block_arg;
254
Query_cache_tls() :first_query_block(NULL) {}
257
#include "sql_lex.h" /* Must be here */
237
259
class select_result;
240
262
#define THD_SENTRY_MAGIC 0xfeedd1ff
241
263
#define THD_SENTRY_GONE 0xdeadbeef
243
#define THD_CHECK_SENTRY(thd) assert(thd->dbug_sentry == THD_SENTRY_MAGIC)
265
#define THD_CHECK_SENTRY(thd) DBUG_ASSERT(thd->dbug_sentry == THD_SENTRY_MAGIC)
245
267
struct system_variables
256
278
ulong dynamic_variables_version;
257
279
char* dynamic_variables_ptr;
258
uint32_t dynamic_variables_head; /* largest valid variable offset */
259
uint32_t dynamic_variables_size; /* how many bytes are in use */
280
uint dynamic_variables_head; /* largest valid variable offset */
281
uint dynamic_variables_size; /* how many bytes are in use */
261
uint64_t myisam_max_extra_sort_file_size;
262
uint64_t myisam_max_sort_file_size;
263
uint64_t max_heap_table_size;
264
uint64_t tmp_table_size;
265
uint64_t long_query_time;
283
ulonglong myisam_max_extra_sort_file_size;
284
ulonglong myisam_max_sort_file_size;
285
ulonglong max_heap_table_size;
286
ulonglong tmp_table_size;
287
ulonglong long_query_time;
266
288
ha_rows select_limit;
267
289
ha_rows max_join_size;
268
290
ulong auto_increment_increment, auto_increment_offset;
323
345
my_thread_id pseudo_thread_id;
325
bool low_priority_updates;
347
my_bool low_priority_updates;
328
350
compatibility option:
329
351
- index usage hints (USE INDEX without a FOR clause) behave as in 5.0
332
bool engine_condition_pushdown;
333
bool keep_files_on_create;
354
my_bool query_cache_wlock_invalidate;
355
my_bool engine_condition_pushdown;
356
my_bool keep_files_on_create;
335
bool old_alter_table;
358
my_bool old_alter_table;
359
my_bool old_passwords;
337
361
plugin_ref table_plugin;
339
363
/* Only charset part of these variables is sensible */
340
const CHARSET_INFO *character_set_filesystem;
341
const CHARSET_INFO *character_set_client;
342
const CHARSET_INFO *character_set_results;
364
CHARSET_INFO *character_set_filesystem;
365
CHARSET_INFO *character_set_client;
366
CHARSET_INFO *character_set_results;
344
368
/* Both charset and collation parts of these variables are important */
345
const CHARSET_INFO *collation_server;
346
const CHARSET_INFO *collation_database;
347
const CHARSET_INFO *collation_connection;
369
CHARSET_INFO *collation_server;
370
CHARSET_INFO *collation_database;
371
CHARSET_INFO *collation_connection;
349
373
/* Locale Support */
350
374
MY_LOCALE *lc_time_names;
352
376
Time_zone *time_zone;
354
/* DATE, DATETIME and DRIZZLE_TIME formats */
378
/* DATE, DATETIME and MYSQL_TIME formats */
355
379
DATE_TIME_FORMAT *date_format;
356
380
DATE_TIME_FORMAT *datetime_format;
357
381
DATE_TIME_FORMAT *time_format;
382
my_bool sysdate_is_now;
362
#include "sql_lex.h" /* only for SQLCOM_END */
364
387
/* per thread status variables */
366
389
typedef struct system_status_var
368
uint64_t bytes_received;
391
ulonglong bytes_received;
392
ulonglong bytes_sent;
371
394
ulong com_stat[(uint) SQLCOM_END];
372
395
ulong created_tmp_disk_tables;
445
468
void mark_transaction_to_rollback(THD *thd, bool all);
447
#ifdef DRIZZLE_SERVER
472
void free_tmp_table(THD *thd, TABLE *entry);
475
/* The following macro is to make init of Query_arena simpler */
477
#define INIT_ARENA_DBUG_INFO is_backup_arena= 0
479
#define INIT_ARENA_DBUG_INFO
449
482
class Query_arena
457
490
MEM_ROOT *mem_root; // Pointer to current memroot
459
Query_arena(MEM_ROOT *mem_root_arg) :
460
free_list(0), mem_root(mem_root_arg)
492
bool is_backup_arena; /* True if this arena is used for backup. */
495
The states relfects three diffrent life cycles for three
496
different types of statements:
497
Prepared statement: INITIALIZED -> PREPARED -> EXECUTED.
498
Stored procedure: INITIALIZED_FOR_SP -> EXECUTED.
499
Other statements: CONVENTIONAL_EXECUTION never changes.
503
INITIALIZED= 0, INITIALIZED_FOR_SP= 1, PREPARED= 2,
504
CONVENTIONAL_EXECUTION= 3, EXECUTED= 4, ERROR= -1
509
/* We build without RTTI, so dynamic_cast can't be used. */
512
STATEMENT, PREPARED_STATEMENT, STORED_PROCEDURE
515
Query_arena(MEM_ROOT *mem_root_arg, enum enum_state state_arg) :
516
free_list(0), mem_root(mem_root_arg), state(state_arg)
517
{ INIT_ARENA_DBUG_INFO; }
463
519
This constructor is used only when Query_arena is created as
464
520
backup storage for another instance of Query_arena.
522
Query_arena() { INIT_ARENA_DBUG_INFO; }
468
524
virtual ~Query_arena() {};
526
inline bool is_conventional() const
527
{ assert(state == CONVENTIONAL_EXECUTION); return state == CONVENTIONAL_EXECUTION; }
470
529
inline void* alloc(size_t size) { return alloc_root(mem_root,size); }
471
530
inline void* calloc(size_t size)
474
533
if ((ptr=alloc_root(mem_root,size)))
475
memset(ptr, 0, size);
478
537
inline char *strdup(const char *str)
481
540
{ return strmake_root(mem_root,str,size); }
482
541
inline void *memdup(const void *str, size_t size)
483
542
{ return memdup_root(mem_root,str,size); }
484
inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
543
inline void *memdup_w_gap(const void *str, size_t size, uint gap)
487
546
if ((ptr= alloc_root(mem_root,size+gap)))
577
641
/* This constructor is called for backup statements */
580
Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg, ulong id_arg);
644
Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg,
645
enum enum_state state_arg, ulong id_arg);
648
/* Assign execution context (note: not all members) of given stmt to self */
649
void set_statement(Statement *stmt);
650
void set_n_backup_statement(Statement *stmt, Statement *backup);
651
void restore_backup_statement(Statement *stmt, Statement *backup);
584
654
struct st_savepoint {
585
655
struct st_savepoint *prev;
588
658
Ha_trx_info *ha_list;
622
692
priv_user - The user privilege we are using. May be "" for anonymous user.
695
char *host, *user, *priv_user, *ip;
696
/* The host privilege we are using */
697
char priv_host[MAX_HOSTNAME];
698
/* points to host if host is available, otherwise points to ip */
699
const char *host_or_ip;
700
ulong db_access; /* Privileges for current db */
630
704
void skip_grants();
631
705
inline char *priv_host_name()
633
return (ip ? ip : (char *)"%");
707
return (*priv_host ? priv_host : (char *)"%");
659
733
List of regular tables in use by this thread. Contains temporary and
660
734
base tables that were opened with @see open_tables().
664
738
List of temporary tables used by this thread. Contains user-level
665
739
temporary tables, created with CREATE TEMPORARY TABLE, and
667
741
or for an intermediate table used in ALTER.
668
742
XXX Why are internal temporary tables added to this list?
670
Table *temporary_tables;
744
TABLE *temporary_tables;
672
746
List of tables that were opened with HANDLER OPEN and are
673
747
still in use by this thread.
675
Table *handler_tables;
676
Table *derived_tables;
749
TABLE *handler_tables;
750
TABLE *derived_tables;
678
752
During a MySQL session, one can lock tables in two modes: automatic
679
753
or manual. In automatic mode all necessary tables are locked just before
687
761
the 'LOCK_TABLES' chapter of the MySQL manual.
688
762
See also lock_tables() for details.
692
766
Tables that were locked with explicit or implicit LOCK TABLES.
693
767
(Implicit LOCK TABLES happens when we are prelocking tables for
694
768
execution of statement which uses stored routines. See description
695
769
THD::prelocked_mode for more info.)
697
DRIZZLE_LOCK *locked_tables;
771
MYSQL_LOCK *locked_tables;
700
774
CREATE-SELECT keeps an extra lock for the table being
701
775
created. This field is used to keep the extra lock available for
702
776
lower level routines, which would otherwise miss that lock.
704
DRIZZLE_LOCK *extra_lock;
778
MYSQL_LOCK *extra_lock;
707
uint32_t current_tablenr;
781
uint current_tablenr;
709
783
enum enum_flags {
710
784
BACKUPS_AVAIL = (1U << 0) /* There are backups available */
814
@class Sub_statement_state
815
@brief Used to save context when executing a function or trigger
818
/* Defines used for Sub_statement_state::in_sub_stmt */
820
#define SUB_STMT_TRIGGER 1
821
#define SUB_STMT_FUNCTION 2
824
class Sub_statement_state
828
ulonglong first_successful_insert_id_in_prev_stmt;
829
ulonglong first_successful_insert_id_in_cur_stmt, insert_id_for_cur_row;
830
Discrete_interval auto_inc_interval_for_cur_row;
831
Discrete_intervals_list auto_inc_intervals_forced;
832
ulonglong limit_found_rows;
833
ha_rows cuted_fields, sent_row_count, examined_row_count;
834
ulong client_capabilities;
836
bool enable_slow_log;
837
bool last_insert_id_used;
838
SAVEPOINT *savepoints;
740
842
/* Flags for the THD::system_thread variable */
741
843
enum enum_thread_type
744
SYSTEM_THREAD_SLAVE_IO,
745
SYSTEM_THREAD_SLAVE_SQL
845
NON_SYSTEM_THREAD= 0,
846
SYSTEM_THREAD_DELAYED_INSERT= 1,
847
SYSTEM_THREAD_SLAVE_IO= 2,
848
SYSTEM_THREAD_SLAVE_SQL= 4,
849
SYSTEM_THREAD_NDBCLUSTER_BINLOG= 8,
850
SYSTEM_THREAD_EVENT_SCHEDULER= 16,
851
SYSTEM_THREAD_EVENT_WORKER= 32,
852
SYSTEM_THREAD_BACKUP= 64
783
890
@param thd the calling thread
784
891
@return true if the error is handled
786
virtual bool handle_error(uint32_t sql_errno,
893
virtual bool handle_error(uint sql_errno,
787
894
const char *message,
788
DRIZZLE_ERROR::enum_warning_level level,
895
MYSQL_ERROR::enum_warning_level level,
819
926
bool can_overwrite_status;
821
928
void set_ok_status(THD *thd, ha_rows affected_rows_arg,
822
uint64_t last_insert_id_arg,
929
ulonglong last_insert_id_arg,
823
930
const char *message);
824
931
void set_eof_status(THD *thd);
825
void set_error_status(THD *thd, uint32_t sql_errno_arg, const char *message_arg);
932
void set_error_status(THD *thd, uint sql_errno_arg, const char *message_arg);
827
934
void disable_status();
836
943
enum_diagnostics_status status() const { return m_status; }
838
945
const char *message() const
839
{ assert(m_status == DA_ERROR || m_status == DA_OK); return m_message; }
841
uint32_t sql_errno() const
842
{ assert(m_status == DA_ERROR); return m_sql_errno; }
844
uint32_t server_status() const
946
{ DBUG_ASSERT(m_status == DA_ERROR || m_status == DA_OK); return m_message; }
948
uint sql_errno() const
949
{ DBUG_ASSERT(m_status == DA_ERROR); return m_sql_errno; }
951
uint server_status() const
846
assert(m_status == DA_OK || m_status == DA_EOF);
953
DBUG_ASSERT(m_status == DA_OK || m_status == DA_EOF);
847
954
return m_server_status;
850
957
ha_rows affected_rows() const
851
{ assert(m_status == DA_OK); return m_affected_rows; }
853
uint64_t last_insert_id() const
854
{ assert(m_status == DA_OK); return m_last_insert_id; }
856
uint32_t total_warn_count() const
958
{ DBUG_ASSERT(m_status == DA_OK); return m_affected_rows; }
960
ulonglong last_insert_id() const
961
{ DBUG_ASSERT(m_status == DA_OK); return m_last_insert_id; }
963
uint total_warn_count() const
858
assert(m_status == DA_OK || m_status == DA_EOF);
965
DBUG_ASSERT(m_status == DA_OK || m_status == DA_EOF);
859
966
return m_total_warn_count;
865
972
/** Message buffer. Can be used by OK or ERROR status. */
866
char m_message[DRIZZLE_ERRMSG_SIZE];
973
char m_message[MYSQL_ERRMSG_SIZE];
868
975
SQL error number. One of ER_ codes from share/errmsg.txt.
869
976
Set by set_error_status.
871
uint32_t m_sql_errno;
874
981
Copied from thd->server_status when the diagnostics area is assigned.
878
985
thd->server_status&= ~...
879
986
Assigned by OK, EOF or ERROR.
881
uint32_t m_server_status;
988
uint m_server_status;
883
990
The number of rows affected by the last statement. This is
884
991
semantically close to thd->row_count_func, but has a different
896
1003
thd->first_successful_insert_id_in_prev_stmt, which is used
897
1004
to implement LAST_INSERT_ID().
899
uint64_t m_last_insert_id;
1006
ulonglong m_last_insert_id;
900
1007
/** The total number of warnings. */
901
1008
uint m_total_warn_count;
902
1009
enum_diagnostics_status m_status;
1006
1113
Set it using the thd_proc_info(THD *thread, const char *message)
1007
1114
macro/function.
1009
void set_proc_info(const char *info) { proc_info= info; }
1010
const char* get_proc_info() const { return proc_info; }
1117
#define THD_SET_PROC_INFO(thd, info) \
1118
(thd)->set_proc_info(__FILE__, __LINE__, (info))
1120
void set_proc_info(const char* file, int line, const char* info);
1122
#define THD_SET_PROC_INFO(thd, info) \
1123
(thd)->proc_info= (info)
1126
inline const char* get_proc_info() { return proc_info;}
1128
/* left public for the the storage engines, please avoid direct use */
1129
const char *proc_info;
1013
1132
Used in error messages to tell user in what part of MySQL we found an
1026
1145
points to a lock object if the lock is present. See item_func.cc and
1027
1146
chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK.
1029
uint32_t dbug_sentry; // watch out for memory corruption
1149
uint dbug_sentry; // watch out for memory corruption
1030
1151
struct st_my_thread_var *mysys_var;
1032
1153
Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
1033
1154
first byte of the packet in do_command()
1035
1156
enum enum_server_command command;
1037
uint32_t file_id; // for LOAD DATA INFILE
1158
uint32 file_id; // for LOAD DATA INFILE
1038
1159
/* remote (peer) port */
1040
1161
time_t start_time, user_time;
1041
uint64_t connect_utime, thr_create_utime; // track down slow pthread_create
1042
uint64_t start_utime, utime_after_lock;
1162
ulonglong connect_utime, thr_create_utime; // track down slow pthread_create
1163
ulonglong start_utime, utime_after_lock;
1044
1165
thr_lock_type update_lock_default;
1167
/* <> 0 if we are inside of trigger or stored function. */
1046
1170
/* container for handler's private per-connection data */
1047
1171
Ha_data ha_data[MAX_HA];
1049
1173
/* Place to store various things */
1050
1174
void *thd_marker;
1175
#ifndef MYSQL_CLIENT
1051
1176
int binlog_setup_trx_data();
1056
1181
void binlog_start_trans_and_stmt();
1057
1182
void binlog_set_stmt_begin();
1058
int binlog_write_table_map(Table *table, bool is_transactional);
1059
int binlog_write_row(Table* table, bool is_transactional,
1060
const unsigned char *new_data);
1061
int binlog_delete_row(Table* table, bool is_transactional,
1062
const unsigned char *old_data);
1063
int binlog_update_row(Table* table, bool is_transactional,
1064
const unsigned char *old_data, const unsigned char *new_data);
1183
int binlog_write_table_map(TABLE *table, bool is_transactional);
1184
int binlog_write_row(TABLE* table, bool is_transactional,
1185
const uchar *new_data);
1186
int binlog_delete_row(TABLE* table, bool is_transactional,
1187
const uchar *old_data);
1188
int binlog_update_row(TABLE* table, bool is_transactional,
1189
const uchar *old_data, const uchar *new_data);
1066
void set_server_id(uint32_t sid) { server_id = sid; }
1191
void set_server_id(uint32 sid) { server_id = sid; }
1069
1194
Member functions to handle pending event for row-level logging.
1071
1196
template <class RowsEventT> Rows_log_event*
1072
binlog_prepare_pending_rows_event(Table* table, uint32_t serv_id,
1197
binlog_prepare_pending_rows_event(TABLE* table, uint32 serv_id,
1074
1199
bool is_transactional,
1075
1200
RowsEventT* hint);
1089
1214
Flags with per-thread information regarding the status of the
1092
uint32_t binlog_flags;
1217
uint32 binlog_flags;
1094
uint32_t get_binlog_table_maps() const {
1219
uint get_binlog_table_maps() const {
1095
1220
return binlog_table_maps;
1097
1222
void clear_binlog_table_maps() {
1098
1223
binlog_table_maps= 0;
1225
#endif /* MYSQL_CLIENT */
1113
1239
List contain only transactional tables, that not invalidated in query
1114
1240
cache (instead of full list of changed in transaction tables).
1116
CHANGED_TableList* changed_tables;
1242
CHANGED_TABLE_LIST* changed_tables;
1117
1243
MEM_ROOT mem_root; // Transaction-life memory allocation pool
1124
1250
st_transactions()
1126
memset(this, 0, sizeof(*this));
1252
bzero((char*)this, sizeof(*this));
1127
1253
xid_state.xid.null();
1128
1254
init_sql_alloc(&mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
1131
1257
Field *dup_field;
1132
1258
sigset_t signals;
1259
#ifdef SIGNAL_WITH_VIO_CLOSE
1134
1263
This is to track items changed during execution of a prepared
1135
1264
statement/stored procedure. It's created by
1140
1269
Item_change_list change_list;
1272
A permanent memory area of the statement. For conventional
1273
execution, the parsed tree and execution runtime reside in the same
1274
memory root. In this case stmt_arena points to THD. In case of
1275
a prepared statement or a stored procedure statement, thd->mem_root
1276
conventionally points to runtime memory, and thd->stmt_arena
1277
points to the memory of the PS/SP, where the parsed tree of the
1278
statement resides. Whenever you need to perform a permanent
1279
transformation of a parsed tree, you should allocate new memory in
1280
stmt_arena, to allow correct re-execution of PS/SP.
1281
Note: in the parser, stmt_arena == thd, even for PS/SP.
1283
Query_arena *stmt_arena;
1142
1284
/* Tells if LAST_INSERT_ID(#) was called for the current statement */
1143
1285
bool arg_of_last_insert_id_function;
1153
1295
It can also be set by SET LAST_INSERT_ID=# or SELECT LAST_INSERT_ID(#).
1154
1296
It is returned by LAST_INSERT_ID().
1156
uint64_t first_successful_insert_id_in_prev_stmt;
1298
ulonglong first_successful_insert_id_in_prev_stmt;
1158
1300
Variant of the above, used for storing in statement-based binlog. The
1159
1301
difference is that the one above can change as the execution of a stored
1160
1302
function progresses, while the one below is set once and then does not
1161
1303
change (which is the value which statement-based binlog needs).
1163
uint64_t first_successful_insert_id_in_prev_stmt_for_binlog;
1305
ulonglong first_successful_insert_id_in_prev_stmt_for_binlog;
1165
1307
This is the first autogenerated insert id which was *successfully*
1166
1308
inserted by the current statement. It is maintained only to set
1167
1309
first_successful_insert_id_in_prev_stmt when statement ends.
1169
uint64_t first_successful_insert_id_in_cur_stmt;
1311
ulonglong first_successful_insert_id_in_cur_stmt;
1171
1313
We follow this logic:
1172
1314
- when stmt starts, first_successful_insert_id_in_prev_stmt contains the
1246
1388
mode, row-based binlogging is used for such cases where two
1247
1389
auto_increment columns are inserted.
1249
inline void record_first_successful_insert_id_in_cur_stmt(uint64_t id_arg)
1391
inline void record_first_successful_insert_id_in_cur_stmt(ulonglong id_arg)
1251
1393
if (first_successful_insert_id_in_cur_stmt == 0)
1252
1394
first_successful_insert_id_in_cur_stmt= id_arg;
1254
inline uint64_t read_first_successful_insert_id_in_prev_stmt(void)
1396
inline ulonglong read_first_successful_insert_id_in_prev_stmt(void)
1256
1398
if (!stmt_depends_on_first_successful_insert_id_in_prev_stmt)
1267
1409
(mysqlbinlog). We'll soon add a variant which can take many intervals in
1270
inline void force_one_auto_inc_interval(uint64_t next_id)
1412
inline void force_one_auto_inc_interval(ulonglong next_id)
1272
1414
auto_inc_intervals_forced.empty(); // in case of multiple SET INSERT_ID
1273
auto_inc_intervals_forced.append(next_id, UINT64_MAX, 0);
1415
auto_inc_intervals_forced.append(next_id, ULONGLONG_MAX, 0);
1276
uint64_t limit_found_rows;
1277
uint64_t options; /* Bitmap of states */
1278
int64_t row_count_func; /* For the ROW_COUNT() function */
1418
ulonglong limit_found_rows;
1419
ulonglong options; /* Bitmap of states */
1420
longlong row_count_func; /* For the ROW_COUNT() function */
1279
1421
ha_rows cuted_fields;
1298
1440
table_map used_tables;
1299
1441
USER_CONN *user_connect;
1300
const CHARSET_INFO *db_charset;
1442
CHARSET_INFO *db_charset;
1302
1444
FIXME: this, and some other variables like 'count_cuted_fields'
1303
1445
maybe should be statement/cursor local, that is, moved to Statement
1304
1446
class. With current implementation warnings produced in each prepared
1305
1447
statement/cursor settle here.
1307
List <DRIZZLE_ERROR> warn_list;
1308
uint warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_END];
1449
List <MYSQL_ERROR> warn_list;
1450
uint warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_END];
1309
1451
uint total_warn_count;
1310
1452
Diagnostics_area main_da;
1336
1478
uint tmp_table, global_read_lock;
1337
1479
uint server_status,open_options;
1338
1480
enum enum_thread_type system_thread;
1339
uint32_t select_number; //number of select (used for EXPLAIN)
1481
uint select_number; //number of select (used for EXPLAIN)
1340
1482
/* variables.transaction_isolation is reset to this after each commit */
1341
1483
enum_tx_isolation session_tx_isolation;
1342
1484
enum_check_fields count_cuted_fields;
1364
1506
bool last_cuted_field;
1365
1507
bool no_errors, password;
1367
Set to true if execution of the current compound statement
1509
Set to TRUE if execution of the current compound statement
1368
1510
can not continue. In particular, disables activation of
1369
1511
CONTINUE or EXIT handlers of stored routines.
1370
1512
Reset in the end of processing of the current user request, in
1379
1521
bool transaction_rollback_request;
1381
true if we are in a sub-statement and the current error can
1523
TRUE if we are in a sub-statement and the current error can
1382
1524
not be safely recovered until we left the sub-statement mode.
1383
1525
In particular, disables activation of CONTINUE and EXIT
1384
1526
handlers inside sub-statements. E.g. if it is a deadlock
1386
1528
raised (traditionally, MySQL first has to close all the reads
1387
1529
via @see handler::ha_index_or_rnd_end() and only then perform
1389
Reset to false when we leave the sub-statement mode.
1531
Reset to FALSE when we leave the sub-statement mode.
1391
1533
bool is_fatal_sub_stmt_error;
1392
1534
bool query_start_used, rand_used, time_zone_used;
1400
1542
it returned an error on master, and this is OK on the slave.
1402
1544
bool is_slave_error;
1545
bool bootstrap, cleanup_done;
1405
1547
/** is set if some thread specific value(s) used in a statement. */
1406
1548
bool thread_specific_used;
1407
1549
bool charset_is_system_charset, charset_is_collation_connection;
1408
1550
bool charset_is_character_set_filesystem;
1551
bool enable_slow_log; /* enable slow log for current statement */
1409
1552
bool abort_on_warning;
1410
1553
bool got_warning; /* Set on call to push_warning() */
1411
1554
bool no_warnings_for_error; /* no warnings on call to my_error() */
1412
1555
/* set during loop of derived table processing */
1413
1556
bool derived_tables_processing;
1414
bool tablespace_op; /* This is true in DISCARD/IMPORT TABLESPACE */
1557
my_bool tablespace_op; /* This is TRUE in DISCARD/IMPORT TABLESPACE */
1417
1560
If we do a purge of binary logs, log index info of the threads
1440
If true, at least one mysql_bin_log::write(Log_event) call has been
1583
If TRUE, at least one mysql_bin_log::write(Log_event) call has been
1441
1584
made after last mysql_bin_log.start_union_events() call.
1443
1586
bool unioned_events;
1445
If true, at least one mysql_bin_log::write(Log_event e), where
1446
e.cache_stmt == true call has been made after last
1588
If TRUE, at least one mysql_bin_log::write(Log_event e), where
1589
e.cache_stmt == TRUE call has been made after last
1447
1590
mysql_bin_log.start_union_events() call.
1449
1592
bool unioned_events_trans;
1465
1608
Lex_input_stream *m_lip;
1611
@todo The following is a work around for online backup and the DDL blocker.
1612
It should be removed when the generalized solution is in place.
1613
This is needed to ensure the restore (which uses DDL) is not blocked
1614
when the DDL blocker is engaged.
1616
my_bool DDL_exception; // Allow some DDL if there is an exception
1482
1633
void cleanup(void);
1483
1634
void cleanup_after_query();
1484
1635
bool store_globals();
1636
#ifdef SIGNAL_WITH_VIO_CLOSE
1637
inline void set_active_vio(Vio* vio)
1639
pthread_mutex_lock(&LOCK_delete);
1641
pthread_mutex_unlock(&LOCK_delete);
1643
inline void clear_active_vio()
1645
pthread_mutex_lock(&LOCK_delete);
1647
pthread_mutex_unlock(&LOCK_delete);
1649
void close_active_vio();
1485
1651
void awake(THD::killed_state state_to_set);
1653
#ifndef MYSQL_CLIENT
1487
1654
enum enum_binlog_query_type {
1489
1656
The query can be logged row-based or statement-based
1507
1674
char const *query, ulong query_len,
1508
1675
bool is_trans, bool suppress_use,
1509
1676
THD::killed_state killed_err_arg= THD::KILLED_NO_VALUE);
1512
1680
For enter_cond() / exit_cond() to work the mutex must be got before
1520
1688
safe_mutex_assert_owner(mutex);
1521
1689
mysys_var->current_mutex = mutex;
1522
1690
mysys_var->current_cond = cond;
1523
this->set_proc_info(msg);
1691
thd_proc_info(this, msg);
1524
1692
return old_msg;
1526
1694
inline void exit_cond(const char* old_msg)
1535
1703
pthread_mutex_lock(&mysys_var->mutex);
1536
1704
mysys_var->current_mutex = 0;
1537
1705
mysys_var->current_cond = 0;
1538
this->set_proc_info(old_msg);
1706
thd_proc_info(this, old_msg);
1539
1707
pthread_mutex_unlock(&mysys_var->mutex);
1541
1709
inline time_t query_start() { query_start_used=1; return start_time; }
1556
1724
start_utime= utime_after_lock= my_micro_time();
1558
1726
void set_time_after_lock() { utime_after_lock= my_micro_time(); }
1559
uint64_t current_utime() { return my_micro_time(); }
1560
inline uint64_t found_rows(void)
1727
ulonglong current_utime() { return my_micro_time(); }
1728
inline ulonglong found_rows(void)
1562
1730
return limit_found_rows;
1577
1745
LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1578
const char* str, uint32_t length,
1746
const char* str, uint length,
1579
1747
bool allocate_lex_string);
1581
bool convert_string(LEX_STRING *to, const CHARSET_INFO * const to_cs,
1582
const char *from, uint32_t from_length,
1583
const CHARSET_INFO * const from_cs);
1585
bool convert_string(String *s, const CHARSET_INFO * const from_cs, const CHARSET_INFO * const to_cs);
1587
void add_changed_table(Table *table);
1749
bool convert_string(LEX_STRING *to, CHARSET_INFO *to_cs,
1750
const char *from, uint from_length,
1751
CHARSET_INFO *from_cs);
1753
bool convert_string(String *s, CHARSET_INFO *from_cs, CHARSET_INFO *to_cs);
1755
void add_changed_table(TABLE *table);
1588
1756
void add_changed_table(const char *key, long key_length);
1589
CHANGED_TableList * changed_table_dup(const char *key, long key_length);
1757
CHANGED_TABLE_LIST * changed_table_dup(const char *key, long key_length);
1590
1758
int send_explain_fields(select_result *result);
1592
1760
Clear the current error, if any.
1598
1766
inline void clear_error()
1768
DBUG_ENTER("clear_error");
1600
1769
if (main_da.is_error())
1601
1770
main_da.reset_diagnostics_area();
1602
1771
is_slave_error= 0;
1605
1774
inline bool vio_ok() const { return net.vio != 0; }
1775
/** Return FALSE if connection to client is broken. */
1776
bool vio_is_connected();
1608
1778
Mark the current error as fatal. Warning: this does not
1609
1779
set any error, it sets a property of the error, so must be
1612
1782
inline void fatal_error()
1614
assert(main_da.is_error());
1784
DBUG_ASSERT(main_da.is_error());
1615
1785
is_fatal_error= 1;
1786
DBUG_PRINT("error",("Fatal error set"));
1618
true if there is an error in the error stack.
1789
TRUE if there is an error in the error stack.
1620
1791
Please use this method instead of direct access to
1621
1792
net.report_error.
1623
If true, the current (sub)-statement should be aborted.
1794
If TRUE, the current (sub)-statement should be aborted.
1624
1795
The main difference between this member and is_fatal_error
1625
1796
is that a fatal error can not be handled by a stored
1626
1797
procedure continue handler, whereas a normal error can.
1628
1799
To raise this flag, use my_error().
1630
1801
inline bool is_error() const { return main_da.is_error(); }
1631
inline const CHARSET_INFO *charset() { return variables.character_set_client; }
1802
inline CHARSET_INFO *charset() { return variables.character_set_client; }
1632
1803
void update_charset();
1634
1805
void change_item_tree(Item **place, Item *new_value)
1807
/* TODO: check for OOM condition here */
1808
if (!stmt_arena->is_conventional())
1809
nocheck_register_item_tree_change(place, *place, mem_root);
1636
1810
*place= new_value;
1638
1812
void nocheck_register_item_tree_change(Item **place, Item *old_value,
1649
1823
killed_state killed_val; /* to cache the volatile 'killed' */
1650
1824
return (killed_val= killed) != KILL_BAD_DATA ? killed_val : 0;
1652
void send_kill_message() const;
1653
/* return true if we will abort query if we make a warning now */
1826
inline void send_kill_message() const
1828
int err= killed_errno();
1830
my_message(err, ER(err), MYF(0));
1832
/* return TRUE if we will abort query if we make a warning now */
1654
1833
inline bool really_abort_on_warning()
1656
1835
return (abort_on_warning);
1658
1837
void set_status_var_init();
1838
bool is_context_analysis_only()
1839
{ return lex->view_prepare_mode; }
1659
1840
void reset_n_backup_open_tables_state(Open_tables_state *backup);
1660
1841
void restore_backup_open_tables_state(Open_tables_state *backup);
1842
void restore_sub_statement_state(Sub_statement_state *backup);
1843
void set_n_backup_active_arena(Query_arena *set, Query_arena *backup);
1844
void restore_active_arena(Query_arena *set, Query_arena *backup);
1662
1846
inline void set_current_stmt_binlog_row_based_if_mixed()
1664
if (variables.binlog_format == BINLOG_FORMAT_MIXED)
1665
current_stmt_binlog_row_based= true;
1849
If in a stored/function trigger, the caller should already have done the
1850
change. We test in_sub_stmt to prevent introducing bugs where people
1851
wouldn't ensure that, and would switch to row-based mode in the middle
1852
of executing a stored function/trigger (which is too late, see also
1853
reset_current_stmt_binlog_row_based()); this condition will make their
1854
tests fail and so force them to propagate the
1855
lex->binlog_row_based_if_mixed upwards to the caller.
1857
if ((variables.binlog_format == BINLOG_FORMAT_MIXED) &&
1859
current_stmt_binlog_row_based= TRUE;
1667
1861
inline void set_current_stmt_binlog_row_based()
1669
current_stmt_binlog_row_based= true;
1863
current_stmt_binlog_row_based= TRUE;
1671
1865
inline void clear_current_stmt_binlog_row_based()
1673
current_stmt_binlog_row_based= false;
1867
current_stmt_binlog_row_based= FALSE;
1675
1869
inline void reset_current_stmt_binlog_row_based()
1680
1874
CREATE TEMPORARY TABLE t SELECT UUID(); # row-based
1681
1875
# and row-based does not store updates to temp tables
1682
1876
# in the binlog.
1877
INSERT INTO u SELECT * FROM t; # stmt-based
1878
and then the INSERT will fail as data inserted into t was not logged.
1879
So we continue with row-based until the temp table is dropped.
1880
If we are in a stored function or trigger, we mustn't reset in the
1881
middle of its execution (as the binary logging way of a stored function
1882
or trigger is decided when it starts executing, depending for example on
1883
the caller (for a stored function: if caller is SELECT or
1884
INSERT/UPDATE/DELETE...).
1684
1886
Don't reset binlog format for NDB binlog injector thread.
1686
if (temporary_tables == NULL)
1888
if ((temporary_tables == NULL) && (in_sub_stmt == 0) &&
1889
(system_thread != SYSTEM_THREAD_NDBCLUSTER_BINLOG))
1688
1891
current_stmt_binlog_row_based=
1689
1892
test(variables.binlog_format == BINLOG_FORMAT_ROW);
1699
1902
Initialize the current database from a NULL-terminated string with
1700
1903
length. If we run out of memory, we free the current database and
1701
return true. This way the user will notice the error as there will be
1904
return TRUE. This way the user will notice the error as there will be
1702
1905
no current database selected (in addition to the error message set by
1750
1952
allocate memory for a deep copy: current database may be freed after
1751
1953
a statement is parsed but before it's executed.
1753
bool copy_db_to(char **p_db, size_t *p_db_length);
1955
bool copy_db_to(char **p_db, size_t *p_db_length)
1959
my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
1962
*p_db= strmake(db, db_length);
1963
*p_db_length= db_length;
1754
1966
thd_scheduler scheduler;
1766
1978
@param level the error level
1767
1979
@return true if the error is handled
1769
virtual bool handle_error(uint32_t sql_errno, const char *message,
1770
DRIZZLE_ERROR::enum_warning_level level);
1981
virtual bool handle_error(uint sql_errno, const char *message,
1982
MYSQL_ERROR::enum_warning_level level);
1773
1985
Remove the error handler last pushed.
1801
2011
/** A short cut for thd->main_da.set_ok_status(). */
1804
my_ok(THD *thd, ha_rows affected_rows= 0, uint64_t id= 0,
2014
my_ok(THD *thd, ha_rows affected_rows= 0, ulonglong id= 0,
1805
2015
const char *message= NULL)
1807
2017
thd->main_da.set_ok_status(thd, affected_rows, id, message);
1819
2029
#define tmp_disable_binlog(A) \
1820
{uint64_t tmp_disable_binlog__save_options= (A)->options; \
2030
{ulonglong tmp_disable_binlog__save_options= (A)->options; \
1821
2031
(A)->options&= ~OPTION_BIN_LOG
1823
2033
#define reenable_binlog(A) (A)->options= tmp_disable_binlog__save_options;}
1870
2079
we need to know number of columns in the result set (if
1871
2080
there is a result set) apart from sending columns metadata.
1873
virtual uint32_t field_count(List<Item> &fields) const
2082
virtual uint field_count(List<Item> &fields) const
1874
2083
{ return fields.elements; }
1875
virtual bool send_fields(List<Item> &list, uint32_t flags)=0;
2084
virtual bool send_fields(List<Item> &list, uint flags)=0;
1876
2085
virtual bool send_data(List<Item> &items)=0;
1877
virtual bool initialize_tables (JOIN __attribute__((unused)) *join=0)
1879
virtual void send_error(uint32_t errcode,const char *err);
2086
virtual bool initialize_tables (JOIN *join=0) { return 0; }
2087
virtual void send_error(uint errcode,const char *err);
1880
2088
virtual bool send_eof()=0;
1882
2090
Check if this query returns a result set and therefore is allowed in
1883
2091
cursors and set an error message if it is not the case.
1885
@retval false success
1886
@retval true error, an error message is set
2093
@retval FALSE success
2094
@retval TRUE error, an error message is set
1888
2096
virtual bool check_simple_select() const;
1889
2097
virtual void abort() {}
1909
2117
select_result_interceptor() {} /* Remove gcc warning */
1910
uint32_t field_count(List<Item> &fields __attribute__((unused))) const
1912
bool send_fields(List<Item> &fields __attribute__((unused)),
1913
uint32_t flag __attribute__((unused))) { return false; }
2118
uint field_count(List<Item> &fields) const { return 0; }
2119
bool send_fields(List<Item> &fields, uint flag) { return FALSE; }
1923
2129
bool is_result_set_started;
1925
select_send() :is_result_set_started(false) {}
1926
bool send_fields(List<Item> &list, uint32_t flags);
2131
select_send() :is_result_set_started(FALSE) {}
2132
bool send_fields(List<Item> &list, uint flags);
1927
2133
bool send_data(List<Item> &items);
1928
2134
bool send_eof();
1929
virtual bool check_simple_select() const { return false; }
2135
virtual bool check_simple_select() const { return FALSE; }
1931
2137
virtual void cleanup();
1944
2150
select_to_file(sql_exchange *ex) :exchange(ex), file(-1),row_count(0L)
1946
2152
~select_to_file();
1947
void send_error(uint32_t errcode,const char *err);
2153
void send_error(uint errcode,const char *err);
1948
2154
bool send_eof();
1949
2155
void cleanup();
1962
2168
class select_export :public select_to_file {
1963
uint32_t field_term_length;
2169
uint field_term_length;
1964
2170
int field_sep_char,escape_char,line_sep_char;
1965
2171
int field_term_char; // first char of FIELDS TERMINATED BY or MAX_INT
2001
2207
class select_insert :public select_result_interceptor {
2003
TableList *table_list;
2209
TABLE_LIST *table_list;
2005
2211
List<Item> *fields;
2006
uint64_t autoinc_value_of_last_inserted_row; // autogenerated or not
2212
ulonglong autoinc_value_of_last_inserted_row; // autogenerated or not
2007
2213
COPY_INFO info;
2008
2214
bool insert_into_view;
2009
select_insert(TableList *table_list_par,
2010
Table *table_par, List<Item> *fields_par,
2215
select_insert(TABLE_LIST *table_list_par,
2216
TABLE *table_par, List<Item> *fields_par,
2011
2217
List<Item> *update_fields, List<Item> *update_values,
2012
2218
enum_duplicates duplic, bool ignore);
2013
2219
~select_insert();
2016
2222
bool send_data(List<Item> &items);
2017
2223
virtual void store_values(List<Item> &values);
2018
2224
virtual bool can_rollback_data() { return 0; }
2019
void send_error(uint32_t errcode,const char *err);
2225
void send_error(uint errcode,const char *err);
2020
2226
bool send_eof();
2022
2228
/* not implemented: select_insert is never re-used in prepared statements */
2027
2233
class select_create: public select_insert {
2029
TableList *create_table;
2235
TABLE_LIST *create_table;
2030
2236
HA_CREATE_INFO *create_info;
2031
TableList *select_tables;
2237
TABLE_LIST *select_tables;
2032
2238
Alter_info *alter_info;
2034
2240
/* lock data for tmp table */
2035
DRIZZLE_LOCK *m_lock;
2036
2242
/* m_lock or thd->extra_lock */
2037
DRIZZLE_LOCK **m_plock;
2243
MYSQL_LOCK **m_plock;
2039
select_create (TableList *table_arg,
2245
select_create (TABLE_LIST *table_arg,
2040
2246
HA_CREATE_INFO *create_info_par,
2041
2247
Alter_info *alter_info_arg,
2042
2248
List<Item> &select_fields,enum_duplicates duplic, bool ignore,
2043
TableList *select_tables_arg)
2249
TABLE_LIST *select_tables_arg)
2044
2250
:select_insert (NULL, NULL, &select_fields, 0, 0, duplic, ignore),
2045
2251
create_table(table_arg),
2046
2252
create_info(create_info_par),
2051
2257
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2053
void binlog_show_create_table(Table **tables, uint32_t count);
2259
void binlog_show_create_table(TABLE **tables, uint count);
2054
2260
void store_values(List<Item> &values);
2055
void send_error(uint32_t errcode,const char *err);
2261
void send_error(uint errcode,const char *err);
2056
2262
bool send_eof();
2058
2264
virtual bool can_rollback_data() { return 1; }
2083
2289
List<Item> save_copy_funcs;
2084
2290
Copy_field *copy_field, *copy_field_end;
2085
2291
Copy_field *save_copy_field, *save_copy_field_end;
2086
unsigned char *group_buff;
2087
2293
Item **items_to_copy; /* Fields in tmp table */
2088
2294
MI_COLUMNDEF *recinfo,*start_recinfo;
2090
2296
ha_rows end_write_records;
2091
2297
uint field_count,sum_func_count,func_count;
2092
uint32_t hidden_field_count;
2298
uint hidden_field_count;
2093
2299
uint group_parts,group_length,group_null_parts;
2094
2300
uint quick_group;
2095
2301
bool using_indirect_summary_function;
2096
2302
/* If >0 convert all blob fields to varchar(convert_blob_length) */
2097
uint32_t convert_blob_length;
2098
const CHARSET_INFO *table_charset;
2303
uint convert_blob_length;
2304
CHARSET_INFO *table_charset;
2099
2305
bool schema_table;
2101
2307
True if GROUP BY and its aggregate functions are already computed
2106
2312
bool precomputed_group_by;
2107
2313
bool force_copy_fields;
2109
If true, create_tmp_field called from create_tmp_table will convert
2315
If TRUE, create_tmp_field called from create_tmp_table will convert
2110
2316
all BIT fields to 64-bit longs. This is a workaround the limitation
2111
2317
that MEMORY tables cannot index BIT columns.
2147
2353
void cleanup();
2148
2354
bool create_result_table(THD *thd, List<Item> *column_types,
2149
bool is_distinct, uint64_t options,
2355
bool is_distinct, ulonglong options,
2150
2356
const char *alias, bool bit_fields_as_long);
2204
2410
Field *field; /* Field to sort */
2205
2411
Item *item; /* Item if not sorting fields */
2206
2412
uint length; /* Length of sort field */
2207
uint32_t suffix_length; /* Length suffix (0-4) */
2413
uint suffix_length; /* Length suffix (0-4) */
2208
2414
Item_result result_type; /* Type of item */
2209
2415
bool reverse; /* if descending sort */
2210
2416
bool need_strxnfrm; /* If we have to use strxnfrm() */
2274
2480
Item_result type;
2275
2481
bool unsigned_flag;
2277
double val_real(bool *null_value);
2278
int64_t val_int(bool *null_value) const;
2279
String *val_str(bool *null_value, String *str, uint32_t decimals);
2280
my_decimal *val_decimal(bool *null_value, my_decimal *result);
2483
double val_real(my_bool *null_value);
2484
longlong val_int(my_bool *null_value) const;
2485
String *val_str(my_bool *null_value, String *str, uint decimals);
2486
my_decimal *val_decimal(my_bool *null_value, my_decimal *result);
2281
2487
DTCollation collation;
2294
2500
DYNAMIC_ARRAY file_ptrs;
2295
2501
ulong max_elements;
2296
uint64_t max_in_memory_size;
2502
ulonglong max_in_memory_size;
2299
unsigned char *record_pointers;
2505
uchar *record_pointers;
2304
2510
ulong elements;
2305
2511
Unique(qsort_cmp2 comp_func, void *comp_func_fixed_arg,
2306
uint32_t size_arg, uint64_t max_in_memory_size_arg);
2512
uint size_arg, ulonglong max_in_memory_size_arg);
2308
2514
ulong elements_in_tree() { return tree.elements_in_tree; }
2309
2515
inline bool unique_add(void *ptr)
2517
DBUG_ENTER("unique_add");
2518
DBUG_PRINT("info", ("tree %u - %lu", tree.elements_in_tree, max_elements));
2311
2519
if (tree.elements_in_tree > max_elements && flush())
2313
return(!tree_insert(&tree, ptr, 0, tree.custom_arg));
2521
DBUG_RETURN(!tree_insert(&tree, ptr, 0, tree.custom_arg));
2316
bool get(Table *table);
2317
static double get_use_cost(uint32_t *buffer, uint32_t nkeys, uint32_t key_size,
2318
uint64_t max_in_memory_size);
2319
inline static int get_cost_calc_buff_size(ulong nkeys, uint32_t key_size,
2320
uint64_t max_in_memory_size)
2524
bool get(TABLE *table);
2525
static double get_use_cost(uint *buffer, uint nkeys, uint key_size,
2526
ulonglong max_in_memory_size);
2527
inline static int get_cost_calc_buff_size(ulong nkeys, uint key_size,
2528
ulonglong max_in_memory_size)
2322
register uint64_t max_elems_in_tree=
2530
register ulonglong max_elems_in_tree=
2323
2531
(1 + max_in_memory_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size));
2324
2532
return (int) (sizeof(uint)*(1 + nkeys/max_elems_in_tree));
2328
2536
bool walk(tree_walk_action action, void *walk_action_arg);
2330
friend int unique_write_to_file(unsigned char* key, element_count count, Unique *unique);
2331
friend int unique_write_to_ptrs(unsigned char* key, element_count count, Unique *unique);
2538
friend int unique_write_to_file(uchar* key, element_count count, Unique *unique);
2539
friend int unique_write_to_ptrs(uchar* key, element_count count, Unique *unique);
2335
2543
class multi_delete :public select_result_interceptor
2337
TableList *delete_tables, *table_being_deleted;
2545
TABLE_LIST *delete_tables, *table_being_deleted;
2338
2546
Unique **tempfiles;
2339
2547
ha_rows deleted, found;
2340
uint32_t num_of_tables;
2342
2550
bool do_delete;
2343
2551
/* True if at least one table we delete from is transactional */
2352
2560
bool error_handled;
2355
multi_delete(TableList *dt, uint32_t num_of_tables);
2563
multi_delete(TABLE_LIST *dt, uint num_of_tables);
2356
2564
~multi_delete();
2357
2565
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2358
2566
bool send_data(List<Item> &items);
2359
2567
bool initialize_tables (JOIN *join);
2360
void send_error(uint32_t errcode,const char *err);
2568
void send_error(uint errcode,const char *err);
2361
2569
int do_deletes();
2362
2570
bool send_eof();
2363
2571
virtual void abort();
2367
2575
class multi_update :public select_result_interceptor
2369
TableList *all_tables; /* query/update command tables */
2370
TableList *leaves; /* list of leves of join table tree */
2371
TableList *update_tables, *table_being_updated;
2372
Table **tmp_tables, *main_table, *table_to_update;
2577
TABLE_LIST *all_tables; /* query/update command tables */
2578
TABLE_LIST *leaves; /* list of leves of join table tree */
2579
TABLE_LIST *update_tables, *table_being_updated;
2580
TABLE **tmp_tables, *main_table, *table_to_update;
2373
2581
TMP_TABLE_PARAM *tmp_table_param;
2374
2582
ha_rows updated, found;
2375
2583
List <Item> *fields, *values;
2376
2584
List <Item> **fields_for_table, **values_for_table;
2377
uint32_t table_count;
2379
2587
List of tables referenced in the CHECK OPTION condition of
2380
2588
the updated view excluding the updated table.
2382
List <Table> unupdated_check_opt_tables;
2590
List <TABLE> unupdated_check_opt_tables;
2383
2591
Copy_field *copy_field;
2384
2592
enum enum_duplicates handle_duplicates;
2385
2593
bool do_update, trans_safe;
2393
2601
bool error_handled;
2396
multi_update(TableList *ut, TableList *leaves_list,
2604
multi_update(TABLE_LIST *ut, TABLE_LIST *leaves_list,
2397
2605
List<Item> *fields, List<Item> *values,
2398
2606
enum_duplicates handle_duplicates, bool ignore);
2399
2607
~multi_update();
2400
2608
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2401
2609
bool send_data(List<Item> &items);
2402
2610
bool initialize_tables (JOIN *join);
2403
void send_error(uint32_t errcode,const char *err);
2611
void send_error(uint errcode,const char *err);
2404
2612
int do_updates();
2405
2613
bool send_eof();
2406
2614
virtual void abort();
2414
2622
enum_field_types type;
2415
my_var (LEX_STRING& j, bool i, uint32_t o, enum_field_types t)
2623
my_var (LEX_STRING& j, bool i, uint o, enum_field_types t)
2416
2624
:s(j), local(i), offset(o), type(t)
2446
2654
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
2447
2655
STATUS_VAR *dec_var);
2656
void mark_transaction_to_rollback(THD *thd, bool all);
2449
#endif /* DRIZZLE_SERVER */
2658
#endif /* MYSQL_SERVER */