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) {}
236
#include "sql_lex.h" /* Must be here */
237
238
class select_result;
256
257
ulong dynamic_variables_version;
257
258
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 */
259
uint dynamic_variables_head; /* largest valid variable offset */
260
uint dynamic_variables_size; /* how many bytes are in use */
261
262
uint64_t myisam_max_extra_sort_file_size;
262
263
uint64_t myisam_max_sort_file_size;
323
324
my_thread_id pseudo_thread_id;
325
bool low_priority_updates;
326
my_bool low_priority_updates;
328
329
compatibility option:
329
330
- 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;
333
my_bool engine_condition_pushdown;
334
my_bool keep_files_on_create;
335
bool old_alter_table;
336
my_bool old_alter_table;
337
338
plugin_ref table_plugin;
339
340
/* 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;
341
CHARSET_INFO *character_set_filesystem;
342
CHARSET_INFO *character_set_client;
343
CHARSET_INFO *character_set_results;
344
345
/* 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;
346
CHARSET_INFO *collation_server;
347
CHARSET_INFO *collation_database;
348
CHARSET_INFO *collation_connection;
349
350
/* Locale Support */
350
351
MY_LOCALE *lc_time_names;
352
353
Time_zone *time_zone;
354
/* DATE, DATETIME and DRIZZLE_TIME formats */
355
/* DATE, DATETIME and MYSQL_TIME formats */
355
356
DATE_TIME_FORMAT *date_format;
356
357
DATE_TIME_FORMAT *datetime_format;
357
358
DATE_TIME_FORMAT *time_format;
359
my_bool sysdate_is_now;
362
#include "sql_lex.h" /* only for SQLCOM_END */
364
364
/* per thread status variables */
457
459
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)
460
bool is_backup_arena; /* True if this arena is used for backup. */
463
The states relfects three diffrent life cycles for three
464
different types of statements:
465
Prepared statement: INITIALIZED -> PREPARED -> EXECUTED.
466
Stored procedure: INITIALIZED_FOR_SP -> EXECUTED.
467
Other statements: CONVENTIONAL_EXECUTION never changes.
471
INITIALIZED= 0, INITIALIZED_FOR_SP= 1, PREPARED= 2,
472
CONVENTIONAL_EXECUTION= 3, EXECUTED= 4, ERROR= -1
477
/* We build without RTTI, so dynamic_cast can't be used. */
480
STATEMENT, PREPARED_STATEMENT, STORED_PROCEDURE
483
Query_arena(MEM_ROOT *mem_root_arg, enum enum_state state_arg) :
484
free_list(0), mem_root(mem_root_arg), state(state_arg)
485
{ INIT_ARENA_DBUG_INFO; }
463
487
This constructor is used only when Query_arena is created as
464
488
backup storage for another instance of Query_arena.
490
Query_arena() { INIT_ARENA_DBUG_INFO; }
468
492
virtual ~Query_arena() {};
494
inline bool is_conventional() const
495
{ assert(state == CONVENTIONAL_EXECUTION); return state == CONVENTIONAL_EXECUTION; }
470
497
inline void* alloc(size_t size) { return alloc_root(mem_root,size); }
471
498
inline void* calloc(size_t size)
474
501
if ((ptr=alloc_root(mem_root,size)))
475
memset(ptr, 0, size);
478
505
inline char *strdup(const char *str)
481
508
{ return strmake_root(mem_root,str,size); }
482
509
inline void *memdup(const void *str, size_t size)
483
510
{ return memdup_root(mem_root,str,size); }
484
inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
511
inline void *memdup_w_gap(const void *str, size_t size, uint gap)
487
514
if ((ptr= alloc_root(mem_root,size+gap)))
531
562
enum enum_mark_columns mark_used_columns;
564
LEX_STRING name; /* name for named prepared statements */
533
565
LEX *lex; // parse tree descriptor
535
567
Points to the query associated with this statement. It's const, but
577
609
/* This constructor is called for backup statements */
580
Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg, ulong id_arg);
612
Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg,
613
enum enum_state state_arg, ulong id_arg);
616
/* Assign execution context (note: not all members) of given stmt to self */
617
void set_statement(Statement *stmt);
618
void set_n_backup_statement(Statement *stmt, Statement *backup);
619
void restore_backup_statement(Statement *stmt, Statement *backup);
584
622
struct st_savepoint {
585
623
struct st_savepoint *prev;
588
626
Ha_trx_info *ha_list;
622
660
priv_user - The user privilege we are using. May be "" for anonymous user.
663
char *host, *user, *priv_user, *ip;
664
/* The host privilege we are using */
665
char priv_host[MAX_HOSTNAME];
666
/* points to host if host is available, otherwise points to ip */
667
const char *host_or_ip;
668
ulong db_access; /* Privileges for current db */
630
672
void skip_grants();
631
673
inline char *priv_host_name()
633
return (ip ? ip : (char *)"%");
675
return (*priv_host ? priv_host : (char *)"%");
659
701
List of regular tables in use by this thread. Contains temporary and
660
702
base tables that were opened with @see open_tables().
664
706
List of temporary tables used by this thread. Contains user-level
665
707
temporary tables, created with CREATE TEMPORARY TABLE, and
667
709
or for an intermediate table used in ALTER.
668
710
XXX Why are internal temporary tables added to this list?
670
Table *temporary_tables;
712
TABLE *temporary_tables;
672
714
List of tables that were opened with HANDLER OPEN and are
673
715
still in use by this thread.
675
Table *handler_tables;
676
Table *derived_tables;
717
TABLE *handler_tables;
718
TABLE *derived_tables;
678
720
During a MySQL session, one can lock tables in two modes: automatic
679
721
or manual. In automatic mode all necessary tables are locked just before
687
729
the 'LOCK_TABLES' chapter of the MySQL manual.
688
730
See also lock_tables() for details.
692
734
Tables that were locked with explicit or implicit LOCK TABLES.
693
735
(Implicit LOCK TABLES happens when we are prelocking tables for
694
736
execution of statement which uses stored routines. See description
695
737
THD::prelocked_mode for more info.)
697
DRIZZLE_LOCK *locked_tables;
739
MYSQL_LOCK *locked_tables;
700
742
CREATE-SELECT keeps an extra lock for the table being
701
743
created. This field is used to keep the extra lock available for
702
744
lower level routines, which would otherwise miss that lock.
704
DRIZZLE_LOCK *extra_lock;
746
MYSQL_LOCK *extra_lock;
707
uint32_t current_tablenr;
749
uint current_tablenr;
709
751
enum enum_flags {
710
752
BACKUPS_AVAIL = (1U << 0) /* There are backups available */
782
@class Sub_statement_state
783
@brief Used to save context when executing a function or trigger
786
/* Defines used for Sub_statement_state::in_sub_stmt */
788
#define SUB_STMT_TRIGGER 1
789
#define SUB_STMT_FUNCTION 2
792
class Sub_statement_state
796
uint64_t first_successful_insert_id_in_prev_stmt;
797
uint64_t first_successful_insert_id_in_cur_stmt, insert_id_for_cur_row;
798
Discrete_interval auto_inc_interval_for_cur_row;
799
Discrete_intervals_list auto_inc_intervals_forced;
800
uint64_t limit_found_rows;
801
ha_rows cuted_fields, sent_row_count, examined_row_count;
802
ulong client_capabilities;
804
bool enable_slow_log;
805
bool last_insert_id_used;
806
SAVEPOINT *savepoints;
740
810
/* Flags for the THD::system_thread variable */
741
811
enum enum_thread_type
783
853
@param thd the calling thread
784
854
@return true if the error is handled
786
virtual bool handle_error(uint32_t sql_errno,
856
virtual bool handle_error(uint sql_errno,
787
857
const char *message,
788
DRIZZLE_ERROR::enum_warning_level level,
858
MYSQL_ERROR::enum_warning_level level,
822
892
uint64_t last_insert_id_arg,
823
893
const char *message);
824
894
void set_eof_status(THD *thd);
825
void set_error_status(THD *thd, uint32_t sql_errno_arg, const char *message_arg);
895
void set_error_status(THD *thd, uint sql_errno_arg, const char *message_arg);
827
897
void disable_status();
838
908
const char *message() const
839
909
{ assert(m_status == DA_ERROR || m_status == DA_OK); return m_message; }
841
uint32_t sql_errno() const
911
uint sql_errno() const
842
912
{ assert(m_status == DA_ERROR); return m_sql_errno; }
844
uint32_t server_status() const
914
uint server_status() const
846
916
assert(m_status == DA_OK || m_status == DA_EOF);
847
917
return m_server_status;
853
923
uint64_t last_insert_id() const
854
924
{ assert(m_status == DA_OK); return m_last_insert_id; }
856
uint32_t total_warn_count() const
926
uint total_warn_count() const
858
928
assert(m_status == DA_OK || m_status == DA_EOF);
859
929
return m_total_warn_count;
865
935
/** Message buffer. Can be used by OK or ERROR status. */
866
char m_message[DRIZZLE_ERRMSG_SIZE];
936
char m_message[MYSQL_ERRMSG_SIZE];
868
938
SQL error number. One of ER_ codes from share/errmsg.txt.
869
939
Set by set_error_status.
871
uint32_t m_sql_errno;
874
944
Copied from thd->server_status when the diagnostics area is assigned.
878
948
thd->server_status&= ~...
879
949
Assigned by OK, EOF or ERROR.
881
uint32_t m_server_status;
951
uint m_server_status;
883
953
The number of rows affected by the last statement. This is
884
954
semantically close to thd->row_count_func, but has a different
1006
1076
Set it using the thd_proc_info(THD *thread, const char *message)
1007
1077
macro/function.
1009
void set_proc_info(const char *info) { proc_info= info; }
1010
const char* get_proc_info() const { return proc_info; }
1079
#define THD_SET_PROC_INFO(thd, info) \
1080
(thd)->proc_info= (info)
1082
inline const char* get_proc_info() { return proc_info;}
1084
/* left public for the the storage engines, please avoid direct use */
1085
const char *proc_info;
1013
1088
Used in error messages to tell user in what part of MySQL we found an
1026
1101
points to a lock object if the lock is present. See item_func.cc and
1027
1102
chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK.
1029
uint32_t dbug_sentry; // watch out for memory corruption
1104
uint dbug_sentry; // watch out for memory corruption
1030
1105
struct st_my_thread_var *mysys_var;
1032
1107
Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
1033
1108
first byte of the packet in do_command()
1035
1110
enum enum_server_command command;
1037
uint32_t file_id; // for LOAD DATA INFILE
1112
uint32 file_id; // for LOAD DATA INFILE
1038
1113
/* remote (peer) port */
1040
1115
time_t start_time, user_time;
1041
1116
uint64_t connect_utime, thr_create_utime; // track down slow pthread_create
1042
1117
uint64_t start_utime, utime_after_lock;
1044
1119
thr_lock_type update_lock_default;
1121
/* <> 0 if we are inside of trigger or stored function. */
1046
1124
/* container for handler's private per-connection data */
1047
1125
Ha_data ha_data[MAX_HA];
1049
1127
/* Place to store various things */
1050
1128
void *thd_marker;
1129
#ifndef MYSQL_CLIENT
1051
1130
int binlog_setup_trx_data();
1056
1135
void binlog_start_trans_and_stmt();
1057
1136
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);
1137
int binlog_write_table_map(TABLE *table, bool is_transactional);
1138
int binlog_write_row(TABLE* table, bool is_transactional,
1139
const uchar *new_data);
1140
int binlog_delete_row(TABLE* table, bool is_transactional,
1141
const uchar *old_data);
1142
int binlog_update_row(TABLE* table, bool is_transactional,
1143
const uchar *old_data, const uchar *new_data);
1066
void set_server_id(uint32_t sid) { server_id = sid; }
1145
void set_server_id(uint32 sid) { server_id = sid; }
1069
1148
Member functions to handle pending event for row-level logging.
1071
1150
template <class RowsEventT> Rows_log_event*
1072
binlog_prepare_pending_rows_event(Table* table, uint32_t serv_id,
1151
binlog_prepare_pending_rows_event(TABLE* table, uint32 serv_id,
1074
1153
bool is_transactional,
1075
1154
RowsEventT* hint);
1078
1157
int binlog_flush_pending_rows_event(bool stmt_end);
1081
uint32_t binlog_table_maps; // Number of table maps currently in the binlog
1160
uint binlog_table_maps; // Number of table maps currently in the binlog
1083
1162
enum enum_binlog_flag {
1084
1163
BINLOG_FLAG_UNSAFE_STMT_PRINTED,
1089
1168
Flags with per-thread information regarding the status of the
1092
uint32_t binlog_flags;
1171
uint32 binlog_flags;
1094
uint32_t get_binlog_table_maps() const {
1173
uint get_binlog_table_maps() const {
1095
1174
return binlog_table_maps;
1097
1176
void clear_binlog_table_maps() {
1098
1177
binlog_table_maps= 0;
1179
#endif /* MYSQL_CLIENT */
1113
1193
List contain only transactional tables, that not invalidated in query
1114
1194
cache (instead of full list of changed in transaction tables).
1116
CHANGED_TableList* changed_tables;
1196
CHANGED_TABLE_LIST* changed_tables;
1117
1197
MEM_ROOT mem_root; // Transaction-life memory allocation pool
1124
1204
st_transactions()
1126
memset(this, 0, sizeof(*this));
1206
bzero((char*)this, sizeof(*this));
1127
1207
xid_state.xid.null();
1128
1208
init_sql_alloc(&mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
1131
1211
Field *dup_field;
1132
1212
sigset_t signals;
1213
#ifdef SIGNAL_WITH_VIO_CLOSE
1134
1217
This is to track items changed during execution of a prepared
1135
1218
statement/stored procedure. It's created by
1140
1223
Item_change_list change_list;
1226
A permanent memory area of the statement. For conventional
1227
execution, the parsed tree and execution runtime reside in the same
1228
memory root. In this case stmt_arena points to THD. In case of
1229
a prepared statement or a stored procedure statement, thd->mem_root
1230
conventionally points to runtime memory, and thd->stmt_arena
1231
points to the memory of the PS/SP, where the parsed tree of the
1232
statement resides. Whenever you need to perform a permanent
1233
transformation of a parsed tree, you should allocate new memory in
1234
stmt_arena, to allow correct re-execution of PS/SP.
1235
Note: in the parser, stmt_arena == thd, even for PS/SP.
1237
Query_arena *stmt_arena;
1142
1238
/* Tells if LAST_INSERT_ID(#) was called for the current statement */
1143
1239
bool arg_of_last_insert_id_function;
1298
1394
table_map used_tables;
1299
1395
USER_CONN *user_connect;
1300
const CHARSET_INFO *db_charset;
1396
CHARSET_INFO *db_charset;
1302
1398
FIXME: this, and some other variables like 'count_cuted_fields'
1303
1399
maybe should be statement/cursor local, that is, moved to Statement
1304
1400
class. With current implementation warnings produced in each prepared
1305
1401
statement/cursor settle here.
1307
List <DRIZZLE_ERROR> warn_list;
1308
uint warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_END];
1403
List <MYSQL_ERROR> warn_list;
1404
uint warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_END];
1309
1405
uint total_warn_count;
1310
1406
Diagnostics_area main_da;
1336
1432
uint tmp_table, global_read_lock;
1337
1433
uint server_status,open_options;
1338
1434
enum enum_thread_type system_thread;
1339
uint32_t select_number; //number of select (used for EXPLAIN)
1435
uint select_number; //number of select (used for EXPLAIN)
1340
1436
/* variables.transaction_isolation is reset to this after each commit */
1341
1437
enum_tx_isolation session_tx_isolation;
1342
1438
enum_check_fields count_cuted_fields;
1400
1496
it returned an error on master, and this is OK on the slave.
1402
1498
bool is_slave_error;
1499
bool bootstrap, cleanup_done;
1405
1501
/** is set if some thread specific value(s) used in a statement. */
1406
1502
bool thread_specific_used;
1407
1503
bool charset_is_system_charset, charset_is_collation_connection;
1408
1504
bool charset_is_character_set_filesystem;
1505
bool enable_slow_log; /* enable slow log for current statement */
1409
1506
bool abort_on_warning;
1410
1507
bool got_warning; /* Set on call to push_warning() */
1411
1508
bool no_warnings_for_error; /* no warnings on call to my_error() */
1465
1562
Lex_input_stream *m_lip;
1565
@todo The following is a work around for online backup and the DDL blocker.
1566
It should be removed when the generalized solution is in place.
1567
This is needed to ensure the restore (which uses DDL) is not blocked
1568
when the DDL blocker is engaged.
1570
my_bool DDL_exception; // Allow some DDL if there is an exception
1482
1587
void cleanup(void);
1483
1588
void cleanup_after_query();
1484
1589
bool store_globals();
1590
#ifdef SIGNAL_WITH_VIO_CLOSE
1591
inline void set_active_vio(Vio* vio)
1593
pthread_mutex_lock(&LOCK_delete);
1595
pthread_mutex_unlock(&LOCK_delete);
1597
inline void clear_active_vio()
1599
pthread_mutex_lock(&LOCK_delete);
1601
pthread_mutex_unlock(&LOCK_delete);
1603
void close_active_vio();
1485
1605
void awake(THD::killed_state state_to_set);
1607
#ifndef MYSQL_CLIENT
1487
1608
enum enum_binlog_query_type {
1489
1610
The query can be logged row-based or statement-based
1507
1628
char const *query, ulong query_len,
1508
1629
bool is_trans, bool suppress_use,
1509
1630
THD::killed_state killed_err_arg= THD::KILLED_NO_VALUE);
1512
1634
For enter_cond() / exit_cond() to work the mutex must be got before
1520
1642
safe_mutex_assert_owner(mutex);
1521
1643
mysys_var->current_mutex = mutex;
1522
1644
mysys_var->current_cond = cond;
1523
this->set_proc_info(msg);
1645
thd_proc_info(this, msg);
1524
1646
return old_msg;
1526
1648
inline void exit_cond(const char* old_msg)
1535
1657
pthread_mutex_lock(&mysys_var->mutex);
1536
1658
mysys_var->current_mutex = 0;
1537
1659
mysys_var->current_cond = 0;
1538
this->set_proc_info(old_msg);
1660
thd_proc_info(this, old_msg);
1539
1661
pthread_mutex_unlock(&mysys_var->mutex);
1541
1663
inline time_t query_start() { query_start_used=1; return start_time; }
1577
1699
LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1578
const char* str, uint32_t length,
1700
const char* str, uint length,
1579
1701
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);
1703
bool convert_string(LEX_STRING *to, CHARSET_INFO *to_cs,
1704
const char *from, uint from_length,
1705
CHARSET_INFO *from_cs);
1707
bool convert_string(String *s, CHARSET_INFO *from_cs, CHARSET_INFO *to_cs);
1709
void add_changed_table(TABLE *table);
1588
1710
void add_changed_table(const char *key, long key_length);
1589
CHANGED_TableList * changed_table_dup(const char *key, long key_length);
1711
CHANGED_TABLE_LIST * changed_table_dup(const char *key, long key_length);
1590
1712
int send_explain_fields(select_result *result);
1592
1714
Clear the current error, if any.
1605
1727
inline bool vio_ok() const { return net.vio != 0; }
1728
/** Return false if connection to client is broken. */
1729
bool vio_is_connected();
1608
1731
Mark the current error as fatal. Warning: this does not
1609
1732
set any error, it sets a property of the error, so must be
1628
1751
To raise this flag, use my_error().
1630
1753
inline bool is_error() const { return main_da.is_error(); }
1631
inline const CHARSET_INFO *charset() { return variables.character_set_client; }
1754
inline CHARSET_INFO *charset() { return variables.character_set_client; }
1632
1755
void update_charset();
1634
1757
void change_item_tree(Item **place, Item *new_value)
1759
/* TODO: check for OOM condition here */
1760
if (!stmt_arena->is_conventional())
1761
nocheck_register_item_tree_change(place, *place, mem_root);
1636
1762
*place= new_value;
1638
1764
void nocheck_register_item_tree_change(Item **place, Item *old_value,
1649
1775
killed_state killed_val; /* to cache the volatile 'killed' */
1650
1776
return (killed_val= killed) != KILL_BAD_DATA ? killed_val : 0;
1652
void send_kill_message() const;
1778
inline void send_kill_message() const
1780
int err= killed_errno();
1782
my_message(err, ER(err), MYF(0));
1653
1784
/* return true if we will abort query if we make a warning now */
1654
1785
inline bool really_abort_on_warning()
1658
1789
void set_status_var_init();
1659
1790
void reset_n_backup_open_tables_state(Open_tables_state *backup);
1660
1791
void restore_backup_open_tables_state(Open_tables_state *backup);
1792
void restore_sub_statement_state(Sub_statement_state *backup);
1793
void set_n_backup_active_arena(Query_arena *set, Query_arena *backup);
1794
void restore_active_arena(Query_arena *set, Query_arena *backup);
1662
1796
inline void set_current_stmt_binlog_row_based_if_mixed()
1664
if (variables.binlog_format == BINLOG_FORMAT_MIXED)
1799
If in a stored/function trigger, the caller should already have done the
1800
change. We test in_sub_stmt to prevent introducing bugs where people
1801
wouldn't ensure that, and would switch to row-based mode in the middle
1802
of executing a stored function/trigger (which is too late, see also
1803
reset_current_stmt_binlog_row_based()); this condition will make their
1804
tests fail and so force them to propagate the
1805
lex->binlog_row_based_if_mixed upwards to the caller.
1807
if ((variables.binlog_format == BINLOG_FORMAT_MIXED) &&
1665
1809
current_stmt_binlog_row_based= true;
1667
1811
inline void set_current_stmt_binlog_row_based()
1680
1824
CREATE TEMPORARY TABLE t SELECT UUID(); # row-based
1681
1825
# and row-based does not store updates to temp tables
1682
1826
# in the binlog.
1827
INSERT INTO u SELECT * FROM t; # stmt-based
1828
and then the INSERT will fail as data inserted into t was not logged.
1829
So we continue with row-based until the temp table is dropped.
1830
If we are in a stored function or trigger, we mustn't reset in the
1831
middle of its execution (as the binary logging way of a stored function
1832
or trigger is decided when it starts executing, depending for example on
1833
the caller (for a stored function: if caller is SELECT or
1834
INSERT/UPDATE/DELETE...).
1684
1836
Don't reset binlog format for NDB binlog injector thread.
1686
if (temporary_tables == NULL)
1838
if ((temporary_tables == NULL) && (in_sub_stmt == 0))
1688
1840
current_stmt_binlog_row_based=
1689
1841
test(variables.binlog_format == BINLOG_FORMAT_ROW);
1750
1901
allocate memory for a deep copy: current database may be freed after
1751
1902
a statement is parsed but before it's executed.
1753
bool copy_db_to(char **p_db, size_t *p_db_length);
1904
bool copy_db_to(char **p_db, size_t *p_db_length)
1908
my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
1911
*p_db= strmake(db, db_length);
1912
*p_db_length= db_length;
1754
1915
thd_scheduler scheduler;
1766
1927
@param level the error level
1767
1928
@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);
1930
virtual bool handle_error(uint sql_errno, const char *message,
1931
MYSQL_ERROR::enum_warning_level level);
1773
1934
Remove the error handler last pushed.
1870
2029
we need to know number of columns in the result set (if
1871
2030
there is a result set) apart from sending columns metadata.
1873
virtual uint32_t field_count(List<Item> &fields) const
2032
virtual uint field_count(List<Item> &fields) const
1874
2033
{ return fields.elements; }
1875
virtual bool send_fields(List<Item> &list, uint32_t flags)=0;
2034
virtual bool send_fields(List<Item> &list, uint flags)=0;
1876
2035
virtual bool send_data(List<Item> &items)=0;
1877
virtual bool initialize_tables (JOIN __attribute__((unused)) *join=0)
2036
virtual bool initialize_tables (JOIN __attribute__((__unused__)) *join=0)
1879
virtual void send_error(uint32_t errcode,const char *err);
2038
virtual void send_error(uint errcode,const char *err);
1880
2039
virtual bool send_eof()=0;
1882
2041
Check if this query returns a result set and therefore is allowed in
1909
2068
select_result_interceptor() {} /* Remove gcc warning */
1910
uint32_t field_count(List<Item> &fields __attribute__((unused))) const
2069
uint 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; }
2071
bool send_fields(List<Item> &fields __attribute__((__unused__)),
2072
uint flag __attribute__((__unused__))) { return false; }
1923
2082
bool is_result_set_started;
1925
2084
select_send() :is_result_set_started(false) {}
1926
bool send_fields(List<Item> &list, uint32_t flags);
2085
bool send_fields(List<Item> &list, uint flags);
1927
2086
bool send_data(List<Item> &items);
1928
2087
bool send_eof();
1929
2088
virtual bool check_simple_select() const { return false; }
1944
2103
select_to_file(sql_exchange *ex) :exchange(ex), file(-1),row_count(0L)
1946
2105
~select_to_file();
1947
void send_error(uint32_t errcode,const char *err);
2106
void send_error(uint errcode,const char *err);
1948
2107
bool send_eof();
1949
2108
void cleanup();
1962
2121
class select_export :public select_to_file {
1963
uint32_t field_term_length;
2122
uint field_term_length;
1964
2123
int field_sep_char,escape_char,line_sep_char;
1965
2124
int field_term_char; // first char of FIELDS TERMINATED BY or MAX_INT
2001
2160
class select_insert :public select_result_interceptor {
2003
TableList *table_list;
2162
TABLE_LIST *table_list;
2005
2164
List<Item> *fields;
2006
2165
uint64_t autoinc_value_of_last_inserted_row; // autogenerated or not
2007
2166
COPY_INFO info;
2008
2167
bool insert_into_view;
2009
select_insert(TableList *table_list_par,
2010
Table *table_par, List<Item> *fields_par,
2168
select_insert(TABLE_LIST *table_list_par,
2169
TABLE *table_par, List<Item> *fields_par,
2011
2170
List<Item> *update_fields, List<Item> *update_values,
2012
2171
enum_duplicates duplic, bool ignore);
2013
2172
~select_insert();
2016
2175
bool send_data(List<Item> &items);
2017
2176
virtual void store_values(List<Item> &values);
2018
2177
virtual bool can_rollback_data() { return 0; }
2019
void send_error(uint32_t errcode,const char *err);
2178
void send_error(uint errcode,const char *err);
2020
2179
bool send_eof();
2022
2181
/* not implemented: select_insert is never re-used in prepared statements */
2027
2186
class select_create: public select_insert {
2029
TableList *create_table;
2188
TABLE_LIST *create_table;
2030
2189
HA_CREATE_INFO *create_info;
2031
TableList *select_tables;
2190
TABLE_LIST *select_tables;
2032
2191
Alter_info *alter_info;
2034
2193
/* lock data for tmp table */
2035
DRIZZLE_LOCK *m_lock;
2036
2195
/* m_lock or thd->extra_lock */
2037
DRIZZLE_LOCK **m_plock;
2196
MYSQL_LOCK **m_plock;
2039
select_create (TableList *table_arg,
2198
select_create (TABLE_LIST *table_arg,
2040
2199
HA_CREATE_INFO *create_info_par,
2041
2200
Alter_info *alter_info_arg,
2042
2201
List<Item> &select_fields,enum_duplicates duplic, bool ignore,
2043
TableList *select_tables_arg)
2202
TABLE_LIST *select_tables_arg)
2044
2203
:select_insert (NULL, NULL, &select_fields, 0, 0, duplic, ignore),
2045
2204
create_table(table_arg),
2046
2205
create_info(create_info_par),
2051
2210
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2053
void binlog_show_create_table(Table **tables, uint32_t count);
2212
void binlog_show_create_table(TABLE **tables, uint count);
2054
2213
void store_values(List<Item> &values);
2055
void send_error(uint32_t errcode,const char *err);
2214
void send_error(uint errcode,const char *err);
2056
2215
bool send_eof();
2058
2217
virtual bool can_rollback_data() { return 1; }
2083
2242
List<Item> save_copy_funcs;
2084
2243
Copy_field *copy_field, *copy_field_end;
2085
2244
Copy_field *save_copy_field, *save_copy_field_end;
2086
unsigned char *group_buff;
2087
2246
Item **items_to_copy; /* Fields in tmp table */
2088
2247
MI_COLUMNDEF *recinfo,*start_recinfo;
2090
2249
ha_rows end_write_records;
2091
2250
uint field_count,sum_func_count,func_count;
2092
uint32_t hidden_field_count;
2251
uint hidden_field_count;
2093
2252
uint group_parts,group_length,group_null_parts;
2094
2253
uint quick_group;
2095
2254
bool using_indirect_summary_function;
2096
2255
/* If >0 convert all blob fields to varchar(convert_blob_length) */
2097
uint32_t convert_blob_length;
2098
const CHARSET_INFO *table_charset;
2256
uint convert_blob_length;
2257
CHARSET_INFO *table_charset;
2099
2258
bool schema_table;
2101
2260
True if GROUP BY and its aggregate functions are already computed
2204
2363
Field *field; /* Field to sort */
2205
2364
Item *item; /* Item if not sorting fields */
2206
2365
uint length; /* Length of sort field */
2207
uint32_t suffix_length; /* Length suffix (0-4) */
2366
uint suffix_length; /* Length suffix (0-4) */
2208
2367
Item_result result_type; /* Type of item */
2209
2368
bool reverse; /* if descending sort */
2210
2369
bool need_strxnfrm; /* If we have to use strxnfrm() */
2274
2433
Item_result type;
2275
2434
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);
2436
double val_real(my_bool *null_value);
2437
int64_t val_int(my_bool *null_value) const;
2438
String *val_str(my_bool *null_value, String *str, uint decimals);
2439
my_decimal *val_decimal(my_bool *null_value, my_decimal *result);
2281
2440
DTCollation collation;
2296
2455
uint64_t max_in_memory_size;
2299
unsigned char *record_pointers;
2458
uchar *record_pointers;
2304
2463
ulong elements;
2305
2464
Unique(qsort_cmp2 comp_func, void *comp_func_fixed_arg,
2306
uint32_t size_arg, uint64_t max_in_memory_size_arg);
2465
uint size_arg, uint64_t max_in_memory_size_arg);
2308
2467
ulong elements_in_tree() { return tree.elements_in_tree; }
2309
2468
inline bool unique_add(void *ptr)
2313
2472
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,
2475
bool get(TABLE *table);
2476
static double get_use_cost(uint *buffer, uint nkeys, uint key_size,
2318
2477
uint64_t max_in_memory_size);
2319
inline static int get_cost_calc_buff_size(ulong nkeys, uint32_t key_size,
2478
inline static int get_cost_calc_buff_size(ulong nkeys, uint key_size,
2320
2479
uint64_t max_in_memory_size)
2322
2481
register uint64_t max_elems_in_tree=
2328
2487
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);
2489
friend int unique_write_to_file(uchar* key, element_count count, Unique *unique);
2490
friend int unique_write_to_ptrs(uchar* key, element_count count, Unique *unique);
2335
2494
class multi_delete :public select_result_interceptor
2337
TableList *delete_tables, *table_being_deleted;
2496
TABLE_LIST *delete_tables, *table_being_deleted;
2338
2497
Unique **tempfiles;
2339
2498
ha_rows deleted, found;
2340
uint32_t num_of_tables;
2342
2501
bool do_delete;
2343
2502
/* True if at least one table we delete from is transactional */
2352
2511
bool error_handled;
2355
multi_delete(TableList *dt, uint32_t num_of_tables);
2514
multi_delete(TABLE_LIST *dt, uint num_of_tables);
2356
2515
~multi_delete();
2357
2516
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2358
2517
bool send_data(List<Item> &items);
2359
2518
bool initialize_tables (JOIN *join);
2360
void send_error(uint32_t errcode,const char *err);
2519
void send_error(uint errcode,const char *err);
2361
2520
int do_deletes();
2362
2521
bool send_eof();
2363
2522
virtual void abort();
2367
2526
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;
2528
TABLE_LIST *all_tables; /* query/update command tables */
2529
TABLE_LIST *leaves; /* list of leves of join table tree */
2530
TABLE_LIST *update_tables, *table_being_updated;
2531
TABLE **tmp_tables, *main_table, *table_to_update;
2373
2532
TMP_TABLE_PARAM *tmp_table_param;
2374
2533
ha_rows updated, found;
2375
2534
List <Item> *fields, *values;
2376
2535
List <Item> **fields_for_table, **values_for_table;
2377
uint32_t table_count;
2379
2538
List of tables referenced in the CHECK OPTION condition of
2380
2539
the updated view excluding the updated table.
2382
List <Table> unupdated_check_opt_tables;
2541
List <TABLE> unupdated_check_opt_tables;
2383
2542
Copy_field *copy_field;
2384
2543
enum enum_duplicates handle_duplicates;
2385
2544
bool do_update, trans_safe;
2393
2552
bool error_handled;
2396
multi_update(TableList *ut, TableList *leaves_list,
2555
multi_update(TABLE_LIST *ut, TABLE_LIST *leaves_list,
2397
2556
List<Item> *fields, List<Item> *values,
2398
2557
enum_duplicates handle_duplicates, bool ignore);
2399
2558
~multi_update();
2400
2559
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2401
2560
bool send_data(List<Item> &items);
2402
2561
bool initialize_tables (JOIN *join);
2403
void send_error(uint32_t errcode,const char *err);
2562
void send_error(uint errcode,const char *err);
2404
2563
int do_updates();
2405
2564
bool send_eof();
2406
2565
virtual void abort();
2414
2573
enum_field_types type;
2415
my_var (LEX_STRING& j, bool i, uint32_t o, enum_field_types t)
2574
my_var (LEX_STRING& j, bool i, uint o, enum_field_types t)
2416
2575
:s(j), local(i), offset(o), type(t)