94
93
/* for VIEW ... WITH CHECK OPTION */
98
class Key_part_spec :public Sql_alloc {
100
LEX_STRING field_name;
102
Key_part_spec(const LEX_STRING &name, uint32_t len)
103
: field_name(name), length(len)
105
Key_part_spec(const char *name, const size_t name_len, uint32_t len)
107
{ field_name.str= (char *)name; field_name.length= name_len; }
108
bool operator==(const Key_part_spec& other) const;
110
Construct a copy of this Key_part_spec. field_name is copied
111
by-pointer as it is known to never change. At the same time
112
'length' may be reset in mysql_prepare_create_table, and this
113
is why we supply it with a copy.
115
@return If out of memory, 0 is returned and an error is set in
118
Key_part_spec *clone(MEM_ROOT *mem_root) const
119
{ return new (mem_root) Key_part_spec(*this); }
123
class Alter_drop :public Sql_alloc {
125
enum drop_type {KEY, COLUMN };
128
Alter_drop(enum drop_type par_type,const char *par_name)
129
:name(par_name), type(par_type) {}
131
Used to make a clone of this object for ALTER/CREATE TABLE
132
@sa comment for Key_part_spec::clone
134
Alter_drop *clone(MEM_ROOT *mem_root) const
135
{ return new (mem_root) Alter_drop(*this); }
139
class Alter_column :public Sql_alloc {
143
Alter_column(const char *par_name,Item *literal)
144
:name(par_name), def(literal) {}
146
Used to make a clone of this object for ALTER/CREATE TABLE
147
@sa comment for Key_part_spec::clone
149
Alter_column *clone(MEM_ROOT *mem_root) const
150
{ return new (mem_root) Alter_column(*this); }
154
class Key :public Sql_alloc {
156
enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FOREIGN_KEY};
158
KEY_CREATE_INFO key_create_info;
159
List<Key_part_spec> columns;
163
Key(enum Keytype type_par, const LEX_STRING &name_arg,
164
KEY_CREATE_INFO *key_info_arg,
165
bool generated_arg, List<Key_part_spec> &cols)
166
:type(type_par), key_create_info(*key_info_arg), columns(cols),
167
name(name_arg), generated(generated_arg)
169
Key(enum Keytype type_par, const char *name_arg, size_t name_len_arg,
170
KEY_CREATE_INFO *key_info_arg, bool generated_arg,
171
List<Key_part_spec> &cols)
172
:type(type_par), key_create_info(*key_info_arg), columns(cols),
173
generated(generated_arg)
175
name.str= (char *)name_arg;
176
name.length= name_len_arg;
178
Key(const Key &rhs, MEM_ROOT *mem_root);
180
/* Equality comparison of keys (ignoring name) */
181
friend bool foreign_key_prefix(Key *a, Key *b);
183
Used to make a clone of this object for ALTER/CREATE TABLE
184
@sa comment for Key_part_spec::clone
186
virtual Key *clone(MEM_ROOT *mem_root) const
187
{ return new (mem_root) Key(*this, mem_root); }
192
class Foreign_key: public Key {
194
enum fk_match_opt { FK_MATCH_UNDEF, FK_MATCH_FULL,
195
FK_MATCH_PARTIAL, FK_MATCH_SIMPLE};
196
enum fk_option { FK_OPTION_UNDEF, FK_OPTION_RESTRICT, FK_OPTION_CASCADE,
197
FK_OPTION_SET_NULL, FK_OPTION_NO_ACTION, FK_OPTION_DEFAULT};
199
Table_ident *ref_table;
200
List<Key_part_spec> ref_columns;
201
uint32_t delete_opt, update_opt, match_opt;
202
Foreign_key(const LEX_STRING &name_arg, List<Key_part_spec> &cols,
203
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
:Key(FOREIGN_KEY, name_arg, &default_key_create_info, 0, cols),
206
ref_table(table), ref_columns(ref_cols),
207
delete_opt(delete_opt_arg), update_opt(update_opt_arg),
208
match_opt(match_opt_arg)
210
Foreign_key(const Foreign_key &rhs, MEM_ROOT *mem_root);
212
Used to make a clone of this object for ALTER/CREATE TABLE
213
@sa comment for Key_part_spec::clone
215
virtual Key *clone(MEM_ROOT *mem_root) const
216
{ return new (mem_root) Foreign_key(*this, mem_root); }
219
typedef struct st_mysql_lock
96
typedef struct drizzled_lock_st
222
uint32_t table_count,lock_count;
223
101
THR_LOCK_DATA **locks;
227
class LEX_COLUMN : public Sql_alloc
232
LEX_COLUMN (const String& x,const uint& y ): column (x),rights (y) {}
104
#include <drizzled/lex_column.h>
235
106
class select_result;
238
#define THD_SENTRY_MAGIC 0xfeedd1ff
239
#define THD_SENTRY_GONE 0xdeadbeef
109
#define Session_SENTRY_MAGIC 0xfeedd1ff
110
#define Session_SENTRY_GONE 0xdeadbeef
241
#define THD_CHECK_SENTRY(thd) assert(thd->dbug_sentry == THD_SENTRY_MAGIC)
112
#define Session_CHECK_SENTRY(session) assert(session->dbug_sentry == Session_SENTRY_MAGIC)
243
114
struct system_variables
116
system_variables() {};
246
118
How dynamically allocated system variables are handled:
248
120
The global_system_variables and max_system_variables are "authoritative"
249
121
They both should have the same 'version' and 'size'.
250
122
When attempting to access a dynamic variable, if the session version
251
123
is out of date, then the session version is updated and realloced if
252
124
neccessary and bytes copied from global to make up for missing data.
254
126
ulong dynamic_variables_version;
255
char* dynamic_variables_ptr;
127
char * dynamic_variables_ptr;
256
128
uint32_t dynamic_variables_head; /* largest valid variable offset */
257
129
uint32_t dynamic_variables_size; /* how many bytes are in use */
259
131
uint64_t myisam_max_extra_sort_file_size;
260
uint64_t myisam_max_sort_file_size;
261
132
uint64_t max_heap_table_size;
262
133
uint64_t tmp_table_size;
263
uint64_t long_query_time;
264
134
ha_rows select_limit;
265
135
ha_rows max_join_size;
266
ulong auto_increment_increment, auto_increment_offset;
267
ulong bulk_insert_buff_size;
268
ulong join_buff_size;
269
ulong max_allowed_packet;
270
ulong max_error_count;
271
ulong max_length_for_sort_data;
272
ulong max_sort_length;
273
ulong max_tmp_tables;
274
ulong min_examined_row_limit;
275
ulong myisam_repair_threads;
276
ulong myisam_sort_buff_size;
277
ulong myisam_stats_method;
278
ulong net_buffer_length;
279
ulong net_interactive_timeout;
280
ulong net_read_timeout;
281
ulong net_retry_count;
282
ulong net_wait_timeout;
283
ulong net_write_timeout;
284
ulong optimizer_prune_level;
285
ulong optimizer_search_depth;
287
Controls use of Engine-MRR:
288
0 - auto, based on cost
289
1 - force MRR when the storage engine is capable of doing it
292
ulong optimizer_use_mrr;
136
uint64_t auto_increment_increment;
137
uint64_t auto_increment_offset;
138
uint64_t bulk_insert_buff_size;
139
uint64_t join_buff_size;
140
uint32_t max_allowed_packet;
141
uint32_t myisam_stats_method;
142
uint64_t max_error_count;
143
uint64_t max_length_for_sort_data;
144
size_t max_sort_length;
145
uint64_t min_examined_row_limit;
146
uint32_t net_buffer_length;
147
bool optimizer_prune_level;
149
bool engine_condition_pushdown;
151
uint32_t optimizer_search_depth;
293
152
/* A bitmap for switching optimizations on/off */
294
ulong optimizer_switch;
295
ulong preload_buff_size;
296
ulong profiling_history_size;
297
ulong query_cache_type;
298
ulong read_buff_size;
299
ulong read_rnd_buff_size;
300
ulong div_precincrement;
302
ulong thread_handling;
304
ulong completion_type;
153
uint32_t optimizer_switch;
154
uint32_t div_precincrement;
155
uint64_t preload_buff_size;
156
uint32_t read_buff_size;
157
uint32_t read_rnd_buff_size;
158
size_t sortbuff_size;
159
uint32_t thread_handling;
160
uint32_t tx_isolation;
161
uint32_t completion_type;
305
162
/* Determines which non-standard SQL behaviour should be enabled */
307
ulong default_week_format;
308
ulong max_seeks_for_key;
309
ulong range_alloc_block_size;
310
ulong query_alloc_block_size;
311
ulong query_prealloc_size;
312
ulong trans_alloc_block_size;
313
ulong trans_prealloc_size;
315
ulong group_concat_max_len;
316
ulong binlog_format; // binlog format for this thd (see enum_binlog_format)
318
In slave thread we need to know in behalf of which
319
thread the query is being run to replicate temp tables properly
321
my_thread_id pseudo_thread_id;
323
bool low_priority_updates;
326
compatibility option:
327
- index usage hints (USE INDEX without a FOR clause) behave as in 5.0
330
bool engine_condition_pushdown;
331
bool keep_files_on_create;
333
bool old_alter_table;
335
plugin_ref table_plugin;
164
uint64_t max_seeks_for_key;
165
size_t range_alloc_block_size;
166
uint32_t query_alloc_block_size;
167
uint32_t query_prealloc_size;
168
uint32_t trans_alloc_block_size;
169
uint32_t trans_prealloc_size;
170
uint64_t group_concat_max_len;
171
/* TODO: change this to my_thread_id - but have to fix set_var first */
172
uint64_t pseudo_thread_id;
174
StorageEngine *storage_engine;
337
176
/* Only charset part of these variables is sensible */
338
177
const CHARSET_INFO *character_set_filesystem;
339
const CHARSET_INFO *character_set_client;
340
const CHARSET_INFO *character_set_results;
342
179
/* Both charset and collation parts of these variables are important */
343
180
const CHARSET_INFO *collation_server;
344
const CHARSET_INFO *collation_database;
345
const CHARSET_INFO *collation_connection;
182
inline const CHARSET_INFO *getCollation(void)
184
return collation_server;
347
187
/* Locale Support */
348
188
MY_LOCALE *lc_time_names;
350
190
Time_zone *time_zone;
352
/* DATE, DATETIME and DRIZZLE_TIME formats */
353
DATE_TIME_FORMAT *date_format;
354
DATE_TIME_FORMAT *datetime_format;
355
DATE_TIME_FORMAT *time_format;
360
#include "sql_lex.h" /* only for SQLCOM_END */
362
/* per thread status variables */
193
extern struct system_variables global_system_variables;
198
* Per-session local status counters
364
200
typedef struct system_status_var
366
202
uint64_t bytes_received;
367
203
uint64_t bytes_sent;
369
ulong com_stat[(uint) SQLCOM_END];
205
ulong com_stat[(uint32_t) SQLCOM_END];
370
206
ulong created_tmp_disk_tables;
371
207
ulong created_tmp_tables;
372
208
ulong ha_commit_count;
563
353
valid database name.
565
355
@note this attribute is set and alloced by the slave SQL thread (for
566
the THD of that thread); that thread is (and must remain, for now) the
356
the Session of that thread); that thread is (and must remain, for now) the
567
357
only responsible for freeing this member.
360
uint32_t db_length; /**< Length of current schema name */
575
364
/* This constructor is called for backup statements */
578
Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg, ulong id_arg);
367
Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg, uint32_t id_arg)
370
mem_root(mem_root_arg),
372
mark_used_columns(MARK_COLUMNS_READ),
379
virtual ~Statement() {}
380
inline void* alloc(size_t size)
382
return alloc_root(mem_root,size);
384
inline void* calloc(size_t size)
387
if ((ptr= alloc_root(mem_root,size)))
388
memset(ptr, 0, size);
391
inline char *strdup(const char *str)
393
return strdup_root(mem_root,str);
395
inline char *strmake(const char *str, size_t size)
397
return strmake_root(mem_root,str,size);
399
inline void *memdup(const void *str, size_t size)
401
return memdup_root(mem_root,str,size);
403
inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
406
if ((ptr= alloc_root(mem_root,size+gap)))
407
memcpy(ptr,str,size);
410
/** Frees all items attached to this Statement */
582
struct st_savepoint {
583
416
struct st_savepoint *prev;
586
Ha_trx_info *ha_list;
419
Ha_trx_info *ha_list;
589
enum xa_states {XA_NOTR=0, XA_ACTIVE, XA_IDLE, XA_PREPARED};
590
extern const char *xa_state_names[];
592
typedef struct st_xid_state {
593
/* For now, this is only used to catch duplicated external xids */
594
XID xid; // transaction identifier
595
enum xa_states xa_state; // used by external XA only
599
422
extern pthread_mutex_t LOCK_xid_cache;
600
423
extern HASH xid_cache;
601
bool xid_cache_init(void);
602
void xid_cache_free(void);
603
XID_STATE *xid_cache_search(XID *xid);
604
bool xid_cache_insert(XID *xid, enum xa_states xa_state);
605
bool xid_cache_insert(XID_STATE *xid_state);
606
void xid_cache_delete(XID_STATE *xid_state);
609
@class Security_context
610
@brief A set of THD members describing the current authenticated user.
613
class Security_context {
615
Security_context() {} /* Remove gcc warning */
617
host - host of the client
618
user - user of the client, set to NULL until the user has been read from
620
priv_user - The user privilege we are using. May be "" for anonymous user.
629
inline char *priv_host_name()
631
return (ip ? ip : (char *)"%");
637
A registry for item tree transformations performed during
638
query optimization. We register only those changes which require
639
a rollback to re-execute a prepared statement or stored procedure
643
struct Item_change_record;
644
typedef I_List<Item_change_record> Item_change_list;
648
Class that holds information about tables which were opened and locked
649
by the thread. It is also used to save/restore this information in
650
push_open_tables_state()/pop_open_tables_state().
653
class Open_tables_state
657
List of regular tables in use by this thread. Contains temporary and
658
base tables that were opened with @see open_tables().
662
List of temporary tables used by this thread. Contains user-level
663
temporary tables, created with CREATE TEMPORARY TABLE, and
664
internal temporary tables, created, e.g., to resolve a SELECT,
665
or for an intermediate table used in ALTER.
666
XXX Why are internal temporary tables added to this list?
668
Table *temporary_tables;
670
List of tables that were opened with HANDLER OPEN and are
671
still in use by this thread.
673
Table *handler_tables;
674
Table *derived_tables;
676
During a MySQL session, one can lock tables in two modes: automatic
677
or manual. In automatic mode all necessary tables are locked just before
678
statement execution, and all acquired locks are stored in 'lock'
679
member. Unlocking takes place automatically as well, when the
681
Manual mode comes into play when a user issues a 'LOCK TABLES'
682
statement. In this mode the user can only use the locked tables.
683
Trying to use any other tables will give an error. The locked tables are
684
stored in 'locked_tables' member. Manual locking is described in
685
the 'LOCK_TABLES' chapter of the MySQL manual.
686
See also lock_tables() for details.
690
Tables that were locked with explicit or implicit LOCK TABLES.
691
(Implicit LOCK TABLES happens when we are prelocking tables for
692
execution of statement which uses stored routines. See description
693
THD::prelocked_mode for more info.)
695
DRIZZLE_LOCK *locked_tables;
698
CREATE-SELECT keeps an extra lock for the table being
699
created. This field is used to keep the extra lock available for
700
lower level routines, which would otherwise miss that lock.
702
DRIZZLE_LOCK *extra_lock;
705
uint32_t current_tablenr;
708
BACKUPS_AVAIL = (1U << 0) /* There are backups available */
712
Flags with information about the open tables state.
714
uint32_t state_flags;
717
This constructor serves for creation of Open_tables_state instances
718
which are used as backup storage.
720
Open_tables_state() : state_flags(0U) { }
722
Open_tables_state(ulong version_arg);
724
void set_open_tables_state(Open_tables_state *state)
729
void reset_open_tables_state()
731
open_tables= temporary_tables= handler_tables= derived_tables= 0;
732
extra_lock= lock= locked_tables= 0;
738
/* Flags for the THD::system_thread variable */
739
enum enum_thread_type
742
SYSTEM_THREAD_SLAVE_IO,
743
SYSTEM_THREAD_SLAVE_SQL
748
This class represents the interface for internal error handlers.
749
Internal error handlers are exception handlers used by the server
752
class Internal_error_handler
755
Internal_error_handler() {}
756
virtual ~Internal_error_handler() {}
760
Handle an error condition.
761
This method can be implemented by a subclass to achieve any of the
763
- mask an error internally, prevent exposing it to the user,
764
- mask an error and throw another one instead.
765
When this method returns true, the error condition is considered
766
'handled', and will not be propagated to upper layers.
767
It is the responsability of the code installing an internal handler
768
to then check for trapped conditions, and implement logic to recover
769
from the anticipated conditions trapped during runtime.
771
This mechanism is similar to C++ try/throw/catch:
772
- 'try' correspond to <code>THD::push_internal_handler()</code>,
773
- 'throw' correspond to <code>my_error()</code>,
774
which invokes <code>my_message_sql()</code>,
775
- 'catch' correspond to checking how/if an internal handler was invoked,
776
before removing it from the exception stack with
777
<code>THD::pop_internal_handler()</code>.
779
@param sql_errno the error number
780
@param level the error level
781
@param thd the calling thread
782
@return true if the error is handled
784
virtual bool handle_error(uint32_t sql_errno,
786
DRIZZLE_ERROR::enum_warning_level level,
792
Stores status of the currently executed statement.
793
Cleared at the beginning of the statement, and then
794
can hold either OK, ERROR, or EOF status.
795
Can not be assigned twice per statement.
798
class Diagnostics_area
801
enum enum_diagnostics_status
803
/** The area is cleared at start of a statement. */
805
/** Set whenever one calls my_ok(). */
807
/** Set whenever one calls my_eof(). */
809
/** Set whenever one calls my_error() or my_message(). */
811
/** Set in case of a custom response, such as one from COM_STMT_PREPARE. */
814
/** True if status information is sent to the client. */
816
/** Set to make set_error_status after set_{ok,eof}_status possible. */
817
bool can_overwrite_status;
819
void set_ok_status(THD *thd, ha_rows affected_rows_arg,
820
uint64_t last_insert_id_arg,
821
const char *message);
822
void set_eof_status(THD *thd);
823
void set_error_status(THD *thd, uint32_t sql_errno_arg, const char *message_arg);
825
void disable_status();
827
void reset_diagnostics_area();
829
bool is_set() const { return m_status != DA_EMPTY; }
830
bool is_error() const { return m_status == DA_ERROR; }
831
bool is_eof() const { return m_status == DA_EOF; }
832
bool is_ok() const { return m_status == DA_OK; }
833
bool is_disabled() const { return m_status == DA_DISABLED; }
834
enum_diagnostics_status status() const { return m_status; }
836
const char *message() const
837
{ assert(m_status == DA_ERROR || m_status == DA_OK); return m_message; }
839
uint32_t sql_errno() const
840
{ assert(m_status == DA_ERROR); return m_sql_errno; }
842
uint32_t server_status() const
844
assert(m_status == DA_OK || m_status == DA_EOF);
845
return m_server_status;
848
ha_rows affected_rows() const
849
{ assert(m_status == DA_OK); return m_affected_rows; }
851
uint64_t last_insert_id() const
852
{ assert(m_status == DA_OK); return m_last_insert_id; }
854
uint32_t total_warn_count() const
856
assert(m_status == DA_OK || m_status == DA_EOF);
857
return m_total_warn_count;
860
Diagnostics_area() { reset_diagnostics_area(); }
863
/** Message buffer. Can be used by OK or ERROR status. */
864
char m_message[DRIZZLE_ERRMSG_SIZE];
866
SQL error number. One of ER_ codes from share/errmsg.txt.
867
Set by set_error_status.
869
uint32_t m_sql_errno;
872
Copied from thd->server_status when the diagnostics area is assigned.
873
We need this member as some places in the code use the following pattern:
874
thd->server_status|= ...
876
thd->server_status&= ~...
877
Assigned by OK, EOF or ERROR.
879
uint32_t m_server_status;
881
The number of rows affected by the last statement. This is
882
semantically close to thd->row_count_func, but has a different
883
life cycle. thd->row_count_func stores the value returned by
884
function ROW_COUNT() and is cleared only by statements that
885
update its value, such as INSERT, UPDATE, DELETE and few others.
886
This member is cleared at the beginning of the next statement.
888
We could possibly merge the two, but life cycle of thd->row_count_func
891
ha_rows m_affected_rows;
893
Similarly to the previous member, this is a replacement of
894
thd->first_successful_insert_id_in_prev_stmt, which is used
895
to implement LAST_INSERT_ID().
897
uint64_t m_last_insert_id;
898
/** The total number of warnings. */
899
uint m_total_warn_count;
900
enum_diagnostics_status m_status;
902
@todo: the following THD members belong here:
903
- warn_list, warn_count,
425
#include <drizzled/security_context.h>
426
#include <drizzled/open_tables_state.h>
428
#include <drizzled/internal_error_handler.h>
429
#include <drizzled/diagnostics_area.h>
909
432
Storage engine specific thread local data.
1209
644
in the binlog is still needed; the list's minimum will contain 3.
1211
646
Discrete_intervals_list auto_inc_intervals_in_cur_stmt_for_binlog;
1212
/* Used by replication and SET INSERT_ID */
647
/** Used by replication and SET INSERT_ID */
1213
648
Discrete_intervals_list auto_inc_intervals_forced;
1215
There is BUG#19630 where statement-based replication of stored
1216
functions/triggers with two auto_increment columns breaks.
1217
We however ensure that it works when there is 0 or 1 auto_increment
1218
column; our rules are
1219
a) on master, while executing a top statement involving substatements,
1220
first top- or sub- statement to generate auto_increment values wins the
1221
exclusive right to see its values be written to binlog (the write
1222
will be done by the statement or its caller), and the losers won't see
1223
their values be written to binlog.
1224
b) on slave, while replicating a top statement involving substatements,
1225
first top- or sub- statement to need to read auto_increment values from
1226
the master's binlog wins the exclusive right to read them (so the losers
1227
won't read their values from binlog but instead generate on their own).
1228
a) implies that we mustn't backup/restore
1229
auto_inc_intervals_in_cur_stmt_for_binlog.
1230
b) implies that we mustn't backup/restore auto_inc_intervals_forced.
1232
If there are more than 1 auto_increment columns, then intervals for
1233
different columns may mix into the
1234
auto_inc_intervals_in_cur_stmt_for_binlog list, which is logically wrong,
1235
but there is no point in preventing this mixing by preventing intervals
1236
from the secondly inserted column to come into the list, as such
1237
prevention would be wrong too.
1238
What will happen in the case of
1239
INSERT INTO t1 (auto_inc) VALUES(NULL);
1240
where t1 has a trigger which inserts into an auto_inc column of t2, is
1241
that in binlog we'll store the interval of t1 and the interval of t2 (when
1242
we store intervals, soon), then in slave, t1 will use both intervals, t2
1243
will use none; if t1 inserts the same number of rows as on master,
1244
normally the 2nd interval will not be used by t1, which is fine. t2's
1245
values will be wrong if t2's internal auto_increment counter is different
1246
from what it was on master (which is likely). In 5.1, in mixed binlogging
1247
mode, row-based binlogging is used for such cases where two
1248
auto_increment columns are inserted.
1250
inline void record_first_successful_insert_id_in_cur_stmt(uint64_t id_arg)
1252
if (first_successful_insert_id_in_cur_stmt == 0)
1253
first_successful_insert_id_in_cur_stmt= id_arg;
1255
inline uint64_t read_first_successful_insert_id_in_prev_stmt(void)
1257
if (!stmt_depends_on_first_successful_insert_id_in_prev_stmt)
1259
/* It's the first time we read it */
1260
first_successful_insert_id_in_prev_stmt_for_binlog=
1261
first_successful_insert_id_in_prev_stmt;
1262
stmt_depends_on_first_successful_insert_id_in_prev_stmt= 1;
1264
return first_successful_insert_id_in_prev_stmt;
1267
Used by Intvar_log_event::do_apply_event() and by "SET INSERT_ID=#"
1268
(mysqlbinlog). We'll soon add a variant which can take many intervals in
1271
inline void force_one_auto_inc_interval(uint64_t next_id)
1273
auto_inc_intervals_forced.empty(); // in case of multiple SET INSERT_ID
1274
auto_inc_intervals_forced.append(next_id, UINT64_MAX, 0);
1277
uint64_t limit_found_rows;
1278
uint64_t options; /* Bitmap of states */
1279
int64_t row_count_func; /* For the ROW_COUNT() function */
1280
ha_rows cuted_fields;
1283
number of rows we actually sent to the client, including "synthetic"
1286
ha_rows sent_row_count;
1289
number of rows we read, sent or not, including in create_sort_index()
1291
ha_rows examined_row_count;
1294
The set of those tables whose fields are referenced in all subqueries
1296
TODO: possibly this it is incorrect to have used tables in THD because
1297
with more than one subquery, it is not clear what does the field mean.
1299
table_map used_tables;
1300
USER_CONN *user_connect;
1301
const CHARSET_INFO *db_charset;
1303
FIXME: this, and some other variables like 'count_cuted_fields'
650
uint64_t limit_found_rows;
651
uint64_t options; /**< Bitmap of options */
652
int64_t row_count_func; /**< For the ROW_COUNT() function */
653
ha_rows cuted_fields; /**< Count of "cut" or truncated fields. @todo Kill this friggin thing. */
656
* Number of rows we actually sent to the client, including "synthetic"
657
* rows in ROLLUP etc.
659
ha_rows sent_row_count;
662
* Number of rows we read, sent or not, including in create_sort_index()
664
ha_rows examined_row_count;
667
* The set of those tables whose fields are referenced in all subqueries
672
* Possibly this it is incorrect to have used tables in Session because
673
* with more than one subquery, it is not clear what does the field mean.
675
table_map used_tables;
680
This, and some other variables like 'count_cuted_fields'
1304
681
maybe should be statement/cursor local, that is, moved to Statement
1305
682
class. With current implementation warnings produced in each prepared
1306
683
statement/cursor settle here.
1308
List <DRIZZLE_ERROR> warn_list;
1309
uint warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_END];
1310
uint total_warn_count;
685
List<DRIZZLE_ERROR> warn_list;
686
uint32_t warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_END];
687
uint32_t total_warn_count;
1311
688
Diagnostics_area main_da;
1465
789
and may point to invalid memory after that.
1467
791
Lex_input_stream *m_lip;
1474
Initialize memory roots necessary for query processing and (!)
1475
pre-allocate memory for it. We can't do that in THD constructor because
1476
there are use cases (acl_init, watcher threads,
1477
killing mysqld) where it's vital to not allocate excessive and not used
1478
memory. Note, that we still don't return error from init_for_queries():
1479
if preallocation fails, we should notice that at the first call to
1482
void init_for_queries();
1483
void change_user(void);
793
/** Place to store various things */
794
void *session_marker;
795
/** Keeps a copy of the previous table around in case we are just slamming on particular table */
799
Points to info-string that we show in SHOW PROCESSLIST
800
You are supposed to call Session_SET_PROC_INFO only if you have coded
801
a time-consuming piece that MySQL can get stuck in for a long time.
803
Set it using the session_proc_info(Session *thread, const char *message)
806
inline void set_proc_info(const char *info)
810
inline const char* get_proc_info() const
815
inline void setReplicationData (void *data)
817
replication_data= data;
819
inline void *getReplicationData () const
821
return replication_data;
824
/** Returns the current query ID */
825
inline query_id_t getQueryId() const
830
/** Returns the current query text */
831
inline const char *getQueryString() const
836
/** Returns the length of the current query text */
837
inline size_t getQueryLength() const
839
return strlen(query);
842
/** Accessor method returning the server's ID. */
843
inline uint32_t getServerId() const
845
/* We return the global server ID. */
849
/** Returns the current transaction ID for the session's current statement */
850
inline my_xid getTransactionId()
852
return transaction.xid_state.xid.quick_get_my_xid();
855
There is BUG#19630 where statement-based replication of stored
856
functions/triggers with two auto_increment columns breaks.
857
We however ensure that it works when there is 0 or 1 auto_increment
858
column; our rules are
859
a) on master, while executing a top statement involving substatements,
860
first top- or sub- statement to generate auto_increment values wins the
861
exclusive right to see its values be written to binlog (the write
862
will be done by the statement or its caller), and the losers won't see
863
their values be written to binlog.
864
b) on slave, while replicating a top statement involving substatements,
865
first top- or sub- statement to need to read auto_increment values from
866
the master's binlog wins the exclusive right to read them (so the losers
867
won't read their values from binlog but instead generate on their own).
868
a) implies that we mustn't backup/restore
869
auto_inc_intervals_in_cur_stmt_for_binlog.
870
b) implies that we mustn't backup/restore auto_inc_intervals_forced.
872
If there are more than 1 auto_increment columns, then intervals for
873
different columns may mix into the
874
auto_inc_intervals_in_cur_stmt_for_binlog list, which is logically wrong,
875
but there is no point in preventing this mixing by preventing intervals
876
from the secondly inserted column to come into the list, as such
877
prevention would be wrong too.
878
What will happen in the case of
879
INSERT INTO t1 (auto_inc) VALUES(NULL);
880
where t1 has a trigger which inserts into an auto_inc column of t2, is
881
that in binlog we'll store the interval of t1 and the interval of t2 (when
882
we store intervals, soon), then in slave, t1 will use both intervals, t2
883
will use none; if t1 inserts the same number of rows as on master,
884
normally the 2nd interval will not be used by t1, which is fine. t2's
885
values will be wrong if t2's internal auto_increment counter is different
886
from what it was on master (which is likely). In 5.1, in mixed binlogging
887
mode, row-based binlogging is used for such cases where two
888
auto_increment columns are inserted.
890
inline void record_first_successful_insert_id_in_cur_stmt(uint64_t id_arg)
892
if (first_successful_insert_id_in_cur_stmt == 0)
893
first_successful_insert_id_in_cur_stmt= id_arg;
895
inline uint64_t read_first_successful_insert_id_in_prev_stmt(void)
897
return first_successful_insert_id_in_prev_stmt;
900
Used by Intvar_log_event::do_apply_event() and by "SET INSERT_ID=#"
901
(mysqlbinlog). We'll soon add a variant which can take many intervals in
904
inline void force_one_auto_inc_interval(uint64_t next_id)
906
auto_inc_intervals_forced.empty(); // in case of multiple SET INSERT_ID
907
auto_inc_intervals_forced.append(next_id, UINT64_MAX, 0);
910
Session(drizzled::plugin::Client *client_arg);
1484
913
void cleanup(void);
915
* Cleans up after query.
919
* This function is used to reset thread data to its default state.
921
* This function is not suitable for setting thread data to some
922
* non-default values, as there is only one replication thread, so
923
* different master threads may overwrite data of each other on
1485
926
void cleanup_after_query();
1486
bool store_globals();
1487
void awake(THD::killed_state state_to_set);
1489
enum enum_binlog_query_type {
1491
The query can be logged row-based or statement-based
1496
The query has to be logged statement-based
1501
The query represents a change to a table in the "mysql"
1502
database and is currently mapped to ROW_QUERY_TYPE.
1508
int binlog_query(enum_binlog_query_type qtype,
1509
char const *query, ulong query_len,
1510
bool is_trans, bool suppress_use,
1511
THD::killed_state killed_err_arg= THD::KILLED_NO_VALUE);
928
void awake(Session::killed_state state_to_set);
930
* Pulls thread-specific variables into Session state.
932
* Returns true most times, or false if there was a problem
933
* allocating resources for thread-specific storage.
935
* @TODO Kill this. It's not necessary once my_thr_init() is bye bye.
941
Initialize memory roots necessary for query processing and (!)
942
pre-allocate memory for it. We can't do that in Session constructor because
943
there are use cases where it's vital to not allocate excessive and not used
946
void prepareForQueries();
949
* Executes a single statement received from the
952
* Returns true if the statement was successful, or false
957
* For profiling to work, it must never be called recursively.
959
* In MySQL, this used to be the do_command() C function whic
960
* accepted a single parameter of the THD pointer.
962
bool executeStatement();
965
* Reads a query from packet and stores it.
967
* Returns true if query is read and allocated successfully,
968
* false otherwise. On a return of false, Session::fatal_error
971
* @note Used in COM_QUERY and COM_STMT_PREPARE.
973
* Sets the following Session variables:
977
* @param The packet pointer to read from
978
* @param The length of the query to read
980
bool readAndStoreQuery(const char *in_packet, uint32_t in_packet_length);
983
* Ends the current transaction and (maybe) begins the next.
985
* Returns true if the transaction completed successfully,
988
* @param Completion type
990
bool endTransaction(enum enum_mysql_completiontype completion);
991
bool endActiveTransaction();
992
bool startTransaction();
995
* Authenticates users, with error reporting.
997
* Returns true on success, or false on failure.
1004
* This will initialize the session and begin the command loop.
1009
* Schedule a session to be run on the default scheduler.
1514
1014
For enter_cond() / exit_cond() to work the mutex must be got before
1515
1015
enter_cond(); this mutex is then released by exit_cond().
1516
1016
Usage must be: lock mutex; enter_cond(); your code; exit_cond().
1518
inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex,
1018
inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex, const char* msg)
1521
1020
const char* old_msg = get_proc_info();
1522
1021
safe_mutex_assert_owner(mutex);
1523
1022
mysys_var->current_mutex = mutex;
1524
1023
mysys_var->current_cond = cond;
1525
thd_proc_info(this, msg);
1024
this->set_proc_info(msg);
1526
1025
return old_msg;
1528
1027
inline void exit_cond(const char* old_msg)
1815
1298
tree itself is reused between executions and thus is stored elsewhere.
1817
1300
MEM_ROOT main_mem_root;
1821
/** A short cut for thd->main_da.set_ok_status(). */
1824
my_ok(THD *thd, ha_rows affected_rows= 0, uint64_t id= 0,
1825
const char *message= NULL)
1827
thd->main_da.set_ok_status(thd, affected_rows, id, message);
1831
/** A short cut for thd->main_da.set_eof_status(). */
1836
thd->main_da.set_eof_status(thd);
1839
#define tmp_disable_binlog(A) \
1840
{uint64_t tmp_disable_binlog__save_options= (A)->options; \
1841
(A)->options&= ~OPTION_BIN_LOG
1843
#define reenable_binlog(A) (A)->options= tmp_disable_binlog__save_options;}
1847
Used to hold information about file and file structure in exchange
1848
via non-DB file (...INTO OUTFILE..., ...LOAD DATA...)
1849
XXX: We never call destructor for objects of this class.
1852
class sql_exchange :public Sql_alloc
1855
enum enum_filetype filetype; /* load XML, Added by Arnold & Erik */
1857
String *field_term,*enclosed,*line_term,*line_start,*escaped;
1861
const CHARSET_INFO *cs;
1862
sql_exchange(char *name, bool dumpfile_flag,
1863
enum_filetype filetype_arg= FILETYPE_CSV);
1866
#include "log_event.h"
1869
This is used to get result from a select
1303
* Marks all tables in the list which were used by current substatement
1304
* as free for reuse.
1306
* @param Head of the list of tables
1310
* The reason we reset query_id is that it's not enough to just test
1311
* if table->query_id != session->query_id to know if a table is in use.
1315
* SELECT f1_that_uses_t1() FROM t1;
1317
* In f1_that_uses_t1() we will see one instance of t1 where query_id is
1318
* set to query_id of original query.
1320
void mark_used_tables_as_free_for_reuse(Table *table);
1322
Mark all temporary tables which were used by the current statement or
1323
substatement as free for reuse, but only if the query_id can be cleared.
1325
@param session thread context
1327
@remark For temp tables associated with a open SQL HANDLER the query_id
1328
is not reset until the HANDLER is closed.
1330
void mark_temp_tables_as_free_for_reuse();
1334
/** A short cut for session->main_da.set_ok_status(). */
1335
inline void my_ok(ha_rows affected_rows= 0, ha_rows found_rows_arg= 0,
1336
uint64_t passed_id= 0, const char *message= NULL)
1338
main_da.set_ok_status(this, affected_rows, found_rows_arg, passed_id, message);
1342
/** A short cut for session->main_da.set_eof_status(). */
1344
inline void my_eof()
1346
main_da.set_eof_status(this);
1349
/* Some inline functions for more speed */
1351
inline bool add_item_to_list(Item *item)
1353
return lex->current_select->add_item_to_list(this, item);
1356
inline bool add_value_to_list(Item *value)
1358
return lex->value_list.push_back(value);
1361
inline bool add_order_to_list(Item *item, bool asc)
1363
return lex->current_select->add_order_to_list(this, item, asc);
1366
inline bool add_group_to_list(Item *item, bool asc)
1368
return lex->current_select->add_group_to_list(this, item, asc);
1370
void refresh_status();
1371
user_var_entry *getVariable(LEX_STRING &name, bool create_if_not_exists);
1374
* Closes all tables used by the current substatement, or all tables
1375
* used by this thread if we are on the upper level.
1377
void close_thread_tables();
1378
void close_old_data_files(bool morph_locks= false,
1379
bool send_refresh= false);
1380
void close_open_tables();
1381
void close_data_files_and_morph_locks(const char *db, const char *table_name);
1384
bool free_cached_table();
1388
* Prepares statement for reopening of tables and recalculation of set of
1391
* @param Pointer to a pointer to a list of tables which we were trying to open and lock
1393
void close_tables_for_reopen(TableList **tables);
1397
* Open all tables in list, locks them (all, including derived)
1399
* @param Pointer to a list of tables for open & locking
1408
* The lock will automaticaly be freed by close_thread_tables()
1410
bool openTablesLock(TableList *tables);
1413
* Open all tables in list and process derived tables
1415
* @param Pointer to a list of tables for open
1416
* @param Bitmap of flags to modify how the tables will be open:
1417
* DRIZZLE_LOCK_IGNORE_FLUSH - open table even if someone has
1418
* done a flush or namelock on it.
1427
* This is to be used on prepare stage when you don't read any
1428
* data from the tables.
1430
bool openTables(TableList *tables, uint32_t flags= 0);
1432
int open_tables_from_list(TableList **start, uint32_t *counter, uint32_t flags= 0);
1434
Table *openTableLock(TableList *table_list, thr_lock_type lock_type);
1435
Table *openTable(TableList *table_list, bool *refresh, uint32_t flags= 0);
1437
void unlink_open_table(Table *find);
1438
void drop_open_table(Table *table, const char *db_name,
1439
const char *table_name);
1440
void close_cached_table(Table *table);
1442
/* Create a lock in the cache */
1443
Table *table_cache_insert_placeholder(const char *key, uint32_t key_length);
1444
bool lock_table_name_if_not_cached(const char *db,
1445
const char *table_name, Table **table);
1447
/* Work with temporary tables */
1448
Table *find_temporary_table(TableList *table_list);
1449
Table *find_temporary_table(const char *db, const char *table_name);
1450
void close_temporary_tables();
1451
void close_temporary_table(Table *table, bool free_share, bool delete_table);
1452
void close_temporary(Table *table, bool free_share, bool delete_table);
1453
int drop_temporary_table(TableList *table_list);
1454
bool rm_temporary_table(StorageEngine *base, char *path);
1455
Table *open_temporary_table(const char *path, const char *db,
1456
const char *table_name, bool link_in_list,
1457
open_table_mode open_mode);
1459
/* Reopen operations */
1460
bool reopen_tables(bool get_locks, bool mark_share_as_old);
1461
bool reopen_name_locked_table(TableList* table_list, bool link_in);
1462
bool close_cached_tables(TableList *tables, bool wait_for_refresh, bool wait_for_placeholders);
1464
void wait_for_condition(pthread_mutex_t *mutex, pthread_cond_t *cond);
1465
int setup_conds(TableList *leaves, COND **conds);
1466
int lock_tables(TableList *tables, uint32_t count, bool *need_reopen);
1874
class select_result :public Sql_alloc {
1877
SELECT_LEX_UNIT *unit;
1880
virtual ~select_result() {};
1881
virtual int prepare(List<Item> &list __attribute__((unused)),
1887
virtual int prepare2(void) { return 0; }
1889
Because of peculiarities of prepared statements protocol
1890
we need to know number of columns in the result set (if
1891
there is a result set) apart from sending columns metadata.
1893
virtual uint32_t field_count(List<Item> &fields) const
1894
{ return fields.elements; }
1895
virtual bool send_fields(List<Item> &list, uint32_t flags)=0;
1896
virtual bool send_data(List<Item> &items)=0;
1897
virtual bool initialize_tables (JOIN __attribute__((unused)) *join=0)
1899
virtual void send_error(uint32_t errcode,const char *err);
1900
virtual bool send_eof()=0;
1902
Check if this query returns a result set and therefore is allowed in
1903
cursors and set an error message if it is not the case.
1905
@retval false success
1906
@retval true error, an error message is set
1908
virtual bool check_simple_select() const;
1909
virtual void abort() {}
1911
Cleanup instance of this class for next execution of a prepared
1912
statement/stored procedure.
1914
virtual void cleanup();
1915
void set_thd(THD *thd_arg) { thd= thd_arg; }
1916
void begin_dataset() {}
1921
Base class for select_result descendands which intercept and
1922
transform result set rows. As the rows are not sent to the client,
1923
sending of result set metadata should be suppressed as well.
1926
class select_result_interceptor: public select_result
1929
select_result_interceptor() {} /* Remove gcc warning */
1930
uint32_t field_count(List<Item> &fields __attribute__((unused))) const
1932
bool send_fields(List<Item> &fields __attribute__((unused)),
1933
uint32_t flag __attribute__((unused))) { return false; }
1937
class select_send :public select_result {
1939
True if we have sent result set metadata to the client.
1940
In this case the client always expects us to end the result
1941
set with an eof or error packet
1943
bool is_result_set_started;
1945
select_send() :is_result_set_started(false) {}
1946
bool send_fields(List<Item> &list, uint32_t flags);
1947
bool send_data(List<Item> &items);
1949
virtual bool check_simple_select() const { return false; }
1951
virtual void cleanup();
1955
class select_to_file :public select_result_interceptor {
1957
sql_exchange *exchange;
1961
char path[FN_REFLEN];
1964
select_to_file(sql_exchange *ex) :exchange(ex), file(-1),row_count(0L)
1967
void send_error(uint32_t errcode,const char *err);
1973
1471
#define ESCAPE_CHARS "ntrb0ZN" // keep synchronous with READ_INFO::unescape
1977
List of all possible characters of a numeric value text representation.
1979
#define NUMERIC_CHARS ".0123456789e+-"
1982
class select_export :public select_to_file {
1983
uint32_t field_term_length;
1984
int field_sep_char,escape_char,line_sep_char;
1985
int field_term_char; // first char of FIELDS TERMINATED BY or MAX_INT
1987
The is_ambiguous_field_sep field is true if a value of the field_sep_char
1988
field is one of the 'n', 't', 'r' etc characters
1989
(see the READ_INFO::unescape method and the ESCAPE_CHARS constant value).
1991
bool is_ambiguous_field_sep;
1993
The is_ambiguous_field_term is true if field_sep_char contains the first
1994
char of the FIELDS TERMINATED BY (ENCLOSED BY is empty), and items can
1995
contain this character.
1997
bool is_ambiguous_field_term;
1999
The is_unsafe_field_sep field is true if a value of the field_sep_char
2000
field is one of the '0'..'9', '+', '-', '.' and 'e' characters
2001
(see the NUMERIC_CHARS constant value).
2003
bool is_unsafe_field_sep;
2004
bool fixed_row_size;
2006
select_export(sql_exchange *ex) :select_to_file(ex) {}
2008
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2009
bool send_data(List<Item> &items);
2013
class select_dump :public select_to_file {
2015
select_dump(sql_exchange *ex) :select_to_file(ex) {}
2016
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2017
bool send_data(List<Item> &items);
2021
class select_insert :public select_result_interceptor {
2023
TableList *table_list;
2026
uint64_t autoinc_value_of_last_inserted_row; // autogenerated or not
2028
bool insert_into_view;
2029
select_insert(TableList *table_list_par,
2030
Table *table_par, List<Item> *fields_par,
2031
List<Item> *update_fields, List<Item> *update_values,
2032
enum_duplicates duplic, bool ignore);
2034
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2035
virtual int prepare2(void);
2036
bool send_data(List<Item> &items);
2037
virtual void store_values(List<Item> &values);
2038
virtual bool can_rollback_data() { return 0; }
2039
void send_error(uint32_t errcode,const char *err);
2042
/* not implemented: select_insert is never re-used in prepared statements */
2047
class select_create: public select_insert {
2049
TableList *create_table;
2050
HA_CREATE_INFO *create_info;
2051
TableList *select_tables;
2052
Alter_info *alter_info;
2054
/* lock data for tmp table */
2055
DRIZZLE_LOCK *m_lock;
2056
/* m_lock or thd->extra_lock */
2057
DRIZZLE_LOCK **m_plock;
2059
select_create (TableList *table_arg,
2060
HA_CREATE_INFO *create_info_par,
2061
Alter_info *alter_info_arg,
2062
List<Item> &select_fields,enum_duplicates duplic, bool ignore,
2063
TableList *select_tables_arg)
2064
:select_insert (NULL, NULL, &select_fields, 0, 0, duplic, ignore),
2065
create_table(table_arg),
2066
create_info(create_info_par),
2067
select_tables(select_tables_arg),
2068
alter_info(alter_info_arg),
2071
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2073
void binlog_show_create_table(Table **tables, uint32_t count);
2074
void store_values(List<Item> &values);
2075
void send_error(uint32_t errcode,const char *err);
2078
virtual bool can_rollback_data() { return 1; }
2080
// Needed for access from local class MY_HOOKS in prepare(), since thd is proteted.
2081
const THD *get_thd(void) { return thd; }
2082
const HA_CREATE_INFO *get_create_info() { return create_info; };
2083
int prepare2(void) { return 0; }
2086
#include <storage/myisam/myisam.h>
2089
Param to create temporary tables when doing SELECT:s
2091
This structure is copied using memcpy as a part of JOIN.
2094
class TMP_TABLE_PARAM :public Sql_alloc
2097
/* Prevent use of these (not safe because of lists and copy_field) */
2098
TMP_TABLE_PARAM(const TMP_TABLE_PARAM &);
2099
void operator=(TMP_TABLE_PARAM &);
2102
List<Item> copy_funcs;
2103
List<Item> save_copy_funcs;
2104
Copy_field *copy_field, *copy_field_end;
2105
Copy_field *save_copy_field, *save_copy_field_end;
2106
unsigned char *group_buff;
2107
Item **items_to_copy; /* Fields in tmp table */
2108
MI_COLUMNDEF *recinfo,*start_recinfo;
2110
ha_rows end_write_records;
2111
uint field_count,sum_func_count,func_count;
2112
uint32_t hidden_field_count;
2113
uint group_parts,group_length,group_null_parts;
2115
bool using_indirect_summary_function;
2116
/* If >0 convert all blob fields to varchar(convert_blob_length) */
2117
uint32_t convert_blob_length;
2118
const CHARSET_INFO *table_charset;
2121
True if GROUP BY and its aggregate functions are already computed
2122
by a table access method (e.g. by loose index scan). In this case
2123
query execution should not perform aggregation and should treat
2124
aggregate functions as normal functions.
2126
bool precomputed_group_by;
2127
bool force_copy_fields;
2129
If true, create_tmp_field called from create_tmp_table will convert
2130
all BIT fields to 64-bit longs. This is a workaround the limitation
2131
that MEMORY tables cannot index BIT columns.
2133
bool bit_fields_as_long;
2136
:copy_field(0), group_parts(0),
2137
group_length(0), group_null_parts(0), convert_blob_length(0),
2138
schema_table(0), precomputed_group_by(0), force_copy_fields(0),
2139
bit_fields_as_long(0)
2146
inline void cleanup(void)
2148
if (copy_field) /* Fix for Intel compiler */
2150
delete [] copy_field;
2151
save_copy_field= copy_field= 0;
2156
class select_union :public select_result_interceptor
2158
TMP_TABLE_PARAM tmp_table_param;
2162
select_union() :table(0) {}
2163
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2164
bool send_data(List<Item> &items);
2168
bool create_result_table(THD *thd, List<Item> *column_types,
2169
bool is_distinct, uint64_t options,
2170
const char *alias, bool bit_fields_as_long);
2173
/* Base subselect interface class */
2174
class select_subselect :public select_result_interceptor
2177
Item_subselect *item;
2179
select_subselect(Item_subselect *item);
2180
bool send_data(List<Item> &items)=0;
2181
bool send_eof() { return 0; };
2184
/* Single value subselect interface class */
2185
class select_singlerow_subselect :public select_subselect
2188
select_singlerow_subselect(Item_subselect *item_arg)
2189
:select_subselect(item_arg)
2191
bool send_data(List<Item> &items);
2194
/* used in independent ALL/ANY optimisation */
2195
class select_max_min_finder_subselect :public select_subselect
2198
bool (select_max_min_finder_subselect::*op)();
2201
select_max_min_finder_subselect(Item_subselect *item_arg, bool mx)
2202
:select_subselect(item_arg), cache(0), fmax(mx)
2205
bool send_data(List<Item> &items);
2212
/* EXISTS subselect interface class */
2213
class select_exists_subselect :public select_subselect
2216
select_exists_subselect(Item_subselect *item_arg)
2217
:select_subselect(item_arg){}
2218
bool send_data(List<Item> &items);
2221
/* Structs used when sorting */
2223
typedef struct st_sort_field {
2224
Field *field; /* Field to sort */
2225
Item *item; /* Item if not sorting fields */
2226
uint length; /* Length of sort field */
2227
uint32_t suffix_length; /* Length suffix (0-4) */
2228
Item_result result_type; /* Type of item */
2229
bool reverse; /* if descending sort */
2230
bool need_strxnfrm; /* If we have to use strxnfrm() */
1473
#include <drizzled/select_to_file.h>
1474
#include <drizzled/select_export.h>
1475
#include <drizzled/select_dump.h>
1476
#include <drizzled/select_insert.h>
1477
#include <drizzled/select_create.h>
1478
#include <plugin/myisam/myisam.h>
1479
#include <drizzled/tmp_table_param.h>
1480
#include <drizzled/select_union.h>
1481
#include <drizzled/select_subselect.h>
1482
#include <drizzled/select_singlerow_subselect.h>
1483
#include <drizzled/select_max_min_finder_subselect.h>
1484
#include <drizzled/select_exists_subselect.h>
1487
* A structure used to describe sort information
1488
* for a field or item used in ORDER BY.
1490
typedef struct st_sort_field
1492
Field *field; /**< Field to sort */
1493
Item *item; /**< Item if not sorting fields */
1494
size_t length; /**< Length of sort field */
1495
uint32_t suffix_length; /**< Length suffix (0-4) */
1496
Item_result result_type; /**< Type of item */
1497
bool reverse; /**< if descending sort */
1498
bool need_strxnfrm; /**< If we have to use strxnfrm() */
2234
typedef struct st_sort_buffer {
2235
uint32_t index; /* 0 or 1 */
1501
typedef struct st_sort_buffer
1503
uint32_t index; /* 0 or 1 */
2236
1504
uint32_t sort_orders;
2237
uint32_t change_pos; /* If sort-fields changed */
1505
uint32_t change_pos; /* If sort-fields changed */
2239
1507
SORT_FIELD *sortorder;
2242
/* Structure for db & table in sql_yacc */
2244
class Table_ident :public Sql_alloc
2249
SELECT_LEX_UNIT *sel;
2250
inline Table_ident(THD *thd, LEX_STRING db_arg, LEX_STRING table_arg,
2252
:table(table_arg), sel((SELECT_LEX_UNIT *)0)
2254
if (!force && (thd->client_capabilities & CLIENT_NO_SCHEMA))
2259
inline Table_ident(LEX_STRING table_arg)
2260
:table(table_arg), sel((SELECT_LEX_UNIT *)0)
2265
This constructor is used only for the case when we create a derived
2266
table. A derived table has no name and doesn't belong to any database.
2267
Later, if there was an alias specified for the table, it will be set
2268
by add_table_to_list.
2270
inline Table_ident(SELECT_LEX_UNIT *s) : sel(s)
2272
/* We must have a table name here as this is used with add_table_to_list */
2273
db.str= empty_c_string; /* a subject to casedn_str */
2275
table.str= internal_table_name;
2278
bool is_derived_table() const { return test(sel); }
2279
inline void change_db(char *db_name)
2281
db.str= db_name; db.length= (uint) strlen(db_name);
2285
// this is needed for user_vars hash
2286
class user_var_entry
2289
user_var_entry() {} /* Remove gcc warning */
2293
query_id_t update_query_id, used_query_id;
2297
double val_real(bool *null_value);
2298
int64_t val_int(bool *null_value) const;
2299
String *val_str(bool *null_value, String *str, uint32_t decimals);
2300
my_decimal *val_decimal(bool *null_value, my_decimal *result);
2301
DTCollation collation;
2305
Unique -- class for unique (removing of duplicates).
2306
Puts all values to the TREE. If the tree becomes too big,
2307
it's dumped to the file. User can request sorted values, or
2308
just iterate through them. In the last case tree merging is performed in
2309
memory simultaneously with iteration, so it should be ~2-3x faster.
2312
class Unique :public Sql_alloc
2314
DYNAMIC_ARRAY file_ptrs;
2316
uint64_t max_in_memory_size;
2319
unsigned char *record_pointers;
2325
Unique(qsort_cmp2 comp_func, void *comp_func_fixed_arg,
2326
uint32_t size_arg, uint64_t max_in_memory_size_arg);
2328
ulong elements_in_tree() { return tree.elements_in_tree; }
2329
inline bool unique_add(void *ptr)
2331
if (tree.elements_in_tree > max_elements && flush())
2333
return(!tree_insert(&tree, ptr, 0, tree.custom_arg));
2336
bool get(Table *table);
2337
static double get_use_cost(uint32_t *buffer, uint32_t nkeys, uint32_t key_size,
2338
uint64_t max_in_memory_size);
2339
inline static int get_cost_calc_buff_size(ulong nkeys, uint32_t key_size,
2340
uint64_t max_in_memory_size)
2342
register uint64_t max_elems_in_tree=
2343
(1 + max_in_memory_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size));
2344
return (int) (sizeof(uint)*(1 + nkeys/max_elems_in_tree));
2348
bool walk(tree_walk_action action, void *walk_action_arg);
2350
friend int unique_write_to_file(unsigned char* key, element_count count, Unique *unique);
2351
friend int unique_write_to_ptrs(unsigned char* key, element_count count, Unique *unique);
2355
class multi_delete :public select_result_interceptor
2357
TableList *delete_tables, *table_being_deleted;
2359
ha_rows deleted, found;
2360
uint32_t num_of_tables;
2363
/* True if at least one table we delete from is transactional */
2364
bool transactional_tables;
2365
/* True if at least one table we delete from is not transactional */
2367
bool delete_while_scanning;
2369
error handling (rollback and binlogging) can happen in send_eof()
2370
so that afterward send_error() needs to find out that.
2375
multi_delete(TableList *dt, uint32_t num_of_tables);
2377
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2378
bool send_data(List<Item> &items);
2379
bool initialize_tables (JOIN *join);
2380
void send_error(uint32_t errcode,const char *err);
2383
virtual void abort();
2387
class multi_update :public select_result_interceptor
2389
TableList *all_tables; /* query/update command tables */
2390
TableList *leaves; /* list of leves of join table tree */
2391
TableList *update_tables, *table_being_updated;
2392
Table **tmp_tables, *main_table, *table_to_update;
2393
TMP_TABLE_PARAM *tmp_table_param;
2394
ha_rows updated, found;
2395
List <Item> *fields, *values;
2396
List <Item> **fields_for_table, **values_for_table;
2397
uint32_t table_count;
2399
List of tables referenced in the CHECK OPTION condition of
2400
the updated view excluding the updated table.
2402
List <Table> unupdated_check_opt_tables;
2403
Copy_field *copy_field;
2404
enum enum_duplicates handle_duplicates;
2405
bool do_update, trans_safe;
2406
/* True if the update operation has made a change in a transactional table */
2407
bool transactional_tables;
2410
error handling (rollback and binlogging) can happen in send_eof()
2411
so that afterward send_error() needs to find out that.
2416
multi_update(TableList *ut, TableList *leaves_list,
2417
List<Item> *fields, List<Item> *values,
2418
enum_duplicates handle_duplicates, bool ignore);
2420
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2421
bool send_data(List<Item> &items);
2422
bool initialize_tables (JOIN *join);
2423
void send_error(uint32_t errcode,const char *err);
2426
virtual void abort();
2429
class my_var : public Sql_alloc {
2434
enum_field_types type;
2435
my_var (LEX_STRING& j, bool i, uint32_t o, enum_field_types t)
2436
:s(j), local(i), offset(o), type(t)
2441
class select_dumpvar :public select_result_interceptor {
2444
List<my_var> var_list;
2445
select_dumpvar() { var_list.empty(); row_count= 0;}
2446
~select_dumpvar() {}
2447
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2448
bool send_data(List<Item> &items);
2450
virtual bool check_simple_select() const;
1510
#include <drizzled/table_ident.h>
1511
#include <drizzled/user_var_entry.h>
1512
#include <drizzled/unique.h>
1513
#include <drizzled/my_var.h>
1514
#include <drizzled/select_dumpvar.h>
2454
1516
/* Bits in sql_command_flags */
2456
#define CF_CHANGES_DATA 1
2457
#define CF_HAS_ROW_COUNT 2
2458
#define CF_STATUS_COMMAND 4
2459
#define CF_SHOW_TABLE_COMMAND 8
2460
#define CF_WRITE_LOGS_COMMAND 16
1518
enum sql_command_flag_bits
1520
CF_BIT_CHANGES_DATA,
1521
CF_BIT_HAS_ROW_COUNT,
1522
CF_BIT_STATUS_COMMAND,
1523
CF_BIT_SHOW_TABLE_COMMAND,
1524
CF_BIT_WRITE_LOGS_COMMAND,
1528
static const std::bitset<CF_BIT_SIZE> CF_CHANGES_DATA(1 << CF_BIT_CHANGES_DATA);
1529
static const std::bitset<CF_BIT_SIZE> CF_HAS_ROW_COUNT(1 << CF_BIT_HAS_ROW_COUNT);
1530
static const std::bitset<CF_BIT_SIZE> CF_STATUS_COMMAND(1 << CF_BIT_STATUS_COMMAND);
1531
static const std::bitset<CF_BIT_SIZE> CF_SHOW_TABLE_COMMAND(1 << CF_BIT_SHOW_TABLE_COMMAND);
1532
static const std::bitset<CF_BIT_SIZE> CF_WRITE_LOGS_COMMAND(1 << CF_BIT_WRITE_LOGS_COMMAND);
2462
1534
/* Functions in sql_class.cc */
2464
1535
void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var);
2466
1537
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
2467
1538
STATUS_VAR *dec_var);
2469
#endif /* DRIZZLE_SERVER */
1540
#endif /* DRIZZLED_SESSION_H */