summaryrefslogtreecommitdiff
path: root/sql/sql_class.h
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_class.h')
-rw-r--r--sql/sql_class.h204
1 files changed, 135 insertions, 69 deletions
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 91ffb9bb7d9..f7ede9868a7 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -217,6 +217,7 @@ public:
typedef struct st_copy_info {
ha_rows records;
ha_rows deleted;
+ ha_rows updated;
ha_rows copied;
ha_rows error_count;
enum enum_duplicates handle_duplicates;
@@ -374,6 +375,7 @@ struct system_variables
ulong max_length_for_sort_data;
ulong max_sort_length;
ulong max_tmp_tables;
+ ulong max_insert_delayed_threads;
ulong myisam_repair_threads;
ulong myisam_sort_buff_size;
ulong net_buffer_length;
@@ -390,6 +392,8 @@ struct system_variables
ulong table_type;
ulong tmp_table_size;
ulong tx_isolation;
+ ulong heuristic;
+ ulong plan_search_depth;
/* Determines which non-standard SQL behaviour should be enabled */
ulong sql_mode;
ulong default_week_format;
@@ -409,6 +413,7 @@ struct system_variables
my_bool log_warnings;
my_bool low_priority_updates;
my_bool new_mode;
+ my_bool query_cache_wlock_invalidate;
my_bool old_passwords;
/* Only charset part of these variables is sensible */
@@ -428,7 +433,6 @@ struct system_variables
void free_tmp_table(THD *thd, TABLE *entry);
-class Prepared_statement;
/*
State of a single command executed against this connection.
@@ -451,7 +455,7 @@ class Statement
public:
/* FIXME: must be private */
LEX main_lex;
-public:
+
/*
Uniquely identifies each statement object in thread scope; change during
statement lifetime. FIXME: must be const
@@ -459,15 +463,6 @@ public:
ulong id;
/*
- Id of current query. Statement can be reused to execute several queries
- query_id is global in context of the whole MySQL server.
- ID is automatically generated from mutex-protected counter.
- It's used in handler code for various purposes: to check which columns
- from table are necessary for this select, to check if it's necessary to
- update auto-updatable fields (like auto_increment and timestamp).
- */
- ulong query_id;
- /*
- if set_query_id=1, we set field->query_id for all fields. In that case
field list can not contain duplicates.
*/
@@ -485,11 +480,6 @@ public:
See item_sum.cc for details.
*/
bool allow_sum_func;
- /*
- Type of current query: COM_PREPARE, COM_QUERY, etc. Set from
- first byte of the packet in do_command()
- */
- enum enum_server_command command;
LEX *lex; // parse tree descriptor
/*
@@ -500,7 +490,7 @@ public:
char *query;
uint32 query_length; // current query length
/*
- List of items created in the parser for this query. Every item puts
+ List of items created in the parser for this query. Every item puts
itself to the list on creation (see Item::Item() for details))
*/
Item *free_list;
@@ -527,6 +517,32 @@ public:
void set_statement(Statement *stmt);
/* return class type */
virtual Type type() const;
+
+ inline gptr alloc(unsigned int size) { return alloc_root(&mem_root,size); }
+ inline gptr calloc(unsigned int size)
+ {
+ gptr ptr;
+ if ((ptr=alloc_root(&mem_root,size)))
+ bzero((char*) ptr,size);
+ return ptr;
+ }
+ inline char *strdup(const char *str)
+ { return strdup_root(&mem_root,str); }
+ inline char *strmake(const char *str, uint size)
+ { return strmake_root(&mem_root,str,size); }
+ inline char *memdup(const char *str, uint size)
+ { return memdup_root(&mem_root,str,size); }
+ inline char *memdup_w_gap(const char *str, uint size, uint gap)
+ {
+ gptr ptr;
+ if ((ptr=alloc_root(&mem_root,size+gap)))
+ memcpy(ptr,str,size);
+ return ptr;
+ }
+
+ void set_n_backup_item_arena(Statement *set, Statement *backup);
+ void restore_backup_item_arena(Statement *set, Statement *backup);
+ void set_item_arena(Statement *set);
};
@@ -589,6 +605,7 @@ public:
struct st_mysql_bind *client_params;
char *extra_data;
ulong extra_length;
+ String query_rest;
#endif
NET net; // client connection descriptor
MEM_ROOT warn_root; // For warnings and errors
@@ -606,8 +623,7 @@ public:
Statement_map stmt_map;
/*
keeps THD state while it is used for active statement
- Note, that double free_root() is safe, so we don't need to do any
- special cleanup for it in THD destructor.
+ Note: we perform special cleanup for it in THD destructor.
*/
Statement stmt_backup;
/*
@@ -657,6 +673,19 @@ public:
and are still in use by this thread
*/
TABLE *open_tables,*temporary_tables, *handler_tables, *derived_tables;
+ /*
+ During a MySQL session, one can lock tables in two modes: automatic
+ or manual. In automatic mode all necessary tables are locked just before
+ statement execution, and all acquired locks are stored in 'lock'
+ member. Unlocking takes place automatically as well, when the
+ statement ends.
+ Manual mode comes into play when a user issues a 'LOCK TABLES'
+ statement. In this mode the user can only use the locked tables.
+ Trying to use any other tables will give an error. The locked tables are
+ stored in 'locked_tables' member. Manual locking is described in
+ the 'LOCK_TABLES' chapter of the MySQL manual.
+ See also lock_tables() for details.
+ */
MYSQL_LOCK *lock; /* Current locks */
MYSQL_LOCK *locked_tables; /* Tables locked with LOCK */
/*
@@ -664,11 +693,16 @@ public:
points to a lock object if the lock is present. See item_func.cc and
chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK.
*/
- ULL *ull;
+ User_level_lock *ull;
#ifndef DBUG_OFF
uint dbug_sentry; // watch out for memory corruption
#endif
struct st_my_thread_var *mysys_var;
+ /*
+ Type of current query: COM_PREPARE, COM_QUERY, etc. Set from
+ first byte of the packet in do_command()
+ */
+ enum enum_server_command command;
uint32 server_id;
uint32 file_id; // for LOAD DATA INFILE
/*
@@ -683,7 +717,7 @@ public:
delayed_insert *di;
my_bool tablespace_op; /* This is TRUE in DISCARD/IMPORT TABLESPACE */
struct st_transactions {
- IO_CACHE trans_log;
+ IO_CACHE trans_log; // Inited ONLY if binlog is open !
THD_TRANS all; // Trans since BEGIN WORK
THD_TRANS stmt; // Trans for current statement
uint bdb_lock_count;
@@ -709,6 +743,10 @@ public:
Vio* active_vio;
#endif
/*
+ Current prepared Statement if there one, or 0
+ */
+ Statement *current_statement;
+ /*
next_insert_id is set on SET INSERT_ID= #. This is used as the next
generated auto_increment value in handler.cc
*/
@@ -740,6 +778,15 @@ public:
List <MYSQL_ERROR> warn_list;
uint warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_END];
uint total_warn_count;
+ /*
+ Id of current query. Statement can be reused to execute several queries
+ query_id is global in context of the whole MySQL server.
+ ID is automatically generated from mutex-protected counter.
+ It's used in handler code for various purposes: to check which columns
+ from table are necessary for this select, to check if it's necessary to
+ update auto-updatable fields (like auto_increment and timestamp).
+ */
+ ulong query_id;
ulong warn_id, version, options, thread_id, col_access;
/* Statement id is thread-wide. This counter is used to generate ids */
@@ -784,6 +831,7 @@ public:
bool charset_is_system_charset, charset_is_collation_connection;
bool slow_command;
+ longlong row_count_func; /* For the ROW_COUNT() function */
sp_rcontext *spcont; // SP runtime context
sp_cache *sp_proc_cache;
sp_cache *sp_func_cache;
@@ -806,6 +854,16 @@ public:
~THD();
void init(void);
+ /*
+ Initialize memory roots necessary for query processing and (!)
+ pre-allocate memory for it. We can't do that in THD constructor because
+ there are use cases (acl_init, delayed inserts, watcher threads,
+ killing mysqld) where it's vital to not allocate excessive and not used
+ memory. Note, that we still don't return error from init_for_queries():
+ if preallocation fails, we should notice that at the first call to
+ alloc_root.
+ */
+ void init_for_queries();
void change_user(void);
void cleanup(void);
bool store_globals();
@@ -874,34 +932,14 @@ public:
return 0;
#endif
}
- inline gptr alloc(unsigned int size) { return alloc_root(&mem_root,size); }
- inline gptr calloc(unsigned int size)
- {
- gptr ptr;
- if ((ptr=alloc_root(&mem_root,size)))
- bzero((char*) ptr,size);
- return ptr;
- }
- inline char *strdup(const char *str)
- { return strdup_root(&mem_root,str); }
- inline char *strmake(const char *str, uint size)
- { return strmake_root(&mem_root,str,size); }
- inline char *memdup(const char *str, uint size)
- { return memdup_root(&mem_root,str,size); }
- inline char *memdup_w_gap(const char *str, uint size, uint gap)
- {
- gptr ptr;
- if ((ptr=alloc_root(&mem_root,size+gap)))
- memcpy(ptr,str,size);
- return ptr;
- }
- bool convert_string(LEX_STRING *to, CHARSET_INFO *to_cs,
- const char *from, uint from_length,
- CHARSET_INFO *from_cs);
inline gptr trans_alloc(unsigned int size)
{
return alloc_root(&transaction.mem_root,size);
}
+
+ bool convert_string(LEX_STRING *to, CHARSET_INFO *to_cs,
+ const char *from, uint from_length,
+ CHARSET_INFO *from_cs);
void add_changed_table(TABLE *table);
void add_changed_table(const char *key, long key_length);
CHANGED_TABLE_LIST * changed_table_dup(const char *key, long key_length);
@@ -924,6 +962,33 @@ public:
}
inline CHARSET_INFO *charset() { return variables.character_set_client; }
void update_charset();
+
+ inline void allocate_temporary_memory_pool_for_ps_preparing()
+ {
+ DBUG_ASSERT(current_statement!=0);
+ /*
+ We do not want to have in PS memory all that junk,
+ which will be created by preparation => substitute memory
+ from original thread pool.
+
+ We know that PS memory pool is now copied to THD, we move it back
+ to allow some code use it.
+ */
+ current_statement->set_item_arena(this);
+ init_sql_alloc(&mem_root,
+ variables.query_alloc_block_size,
+ variables.query_prealloc_size);
+ free_list= 0;
+ }
+ inline void free_temporary_memory_pool_for_ps_preparing()
+ {
+ DBUG_ASSERT(current_statement!=0);
+ cleanup_items(current_statement->free_list);
+ free_items(free_list);
+ close_thread_tables(this); // to close derived tables
+ free_root(&mem_root, MYF(0));
+ set_item_arena(current_statement);
+ }
};
/* Flags for the THD::system_thread (bitmap) variable */
@@ -987,41 +1052,41 @@ public:
};
-class select_export :public select_result {
+class select_to_file :public select_result {
+protected:
sql_exchange *exchange;
File file;
IO_CACHE cache;
ha_rows row_count;
+ char path[FN_REFLEN];
+
+public:
+ select_to_file(sql_exchange *ex) :exchange(ex), file(-1),row_count(0L)
+ { path[0]=0; }
+ ~select_to_file();
+ bool send_fields(List<Item> &list, uint flag) { return 0; }
+ void send_error(uint errcode,const char *err);
+};
+
+
+class select_export :public select_to_file {
uint field_term_length;
int field_sep_char,escape_char,line_sep_char;
bool fixed_row_size;
public:
- select_export(sql_exchange *ex) :exchange(ex),file(-1),row_count(0L) {}
+ select_export(sql_exchange *ex) :select_to_file(ex) {}
~select_export();
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
- bool send_fields(List<Item> &list,
- uint flag) { return 0; }
bool send_data(List<Item> &items);
- void send_error(uint errcode,const char *err);
bool send_eof();
};
-class select_dump :public select_result {
- sql_exchange *exchange;
- File file;
- IO_CACHE cache;
- ha_rows row_count;
- char path[FN_REFLEN];
+class select_dump :public select_to_file {
public:
- select_dump(sql_exchange *ex) :exchange(ex),file(-1),row_count(0L)
- { path[0]=0; }
- ~select_dump();
+ select_dump(sql_exchange *ex) :select_to_file(ex) {}
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
- bool send_fields(List<Item> &list,
- uint flag) { return 0; }
bool send_data(List<Item> &items);
- void send_error(uint errcode,const char *err);
bool send_eof();
};
@@ -1033,8 +1098,9 @@ class select_insert :public select_result {
ulonglong last_insert_id;
COPY_INFO info;
- select_insert(TABLE *table_par,List<Item> *fields_par,enum_duplicates duplic)
- :table(table_par),fields(fields_par), last_insert_id(0)
+ select_insert(TABLE *table_par, List<Item> *fields_par,
+ enum_duplicates duplic)
+ :table(table_par), fields(fields_par), last_insert_id(0)
{
bzero((char*) &info,sizeof(info));
info.handle_duplicates=duplic;
@@ -1059,11 +1125,11 @@ class select_create: public select_insert {
MYSQL_LOCK *lock;
Field **field;
public:
- select_create (const char *db_name, const char *table_name,
- HA_CREATE_INFO *create_info_par,
- List<create_field> &fields_par,
- List<Key> &keys_par,
- List<Item> &select_fields,enum_duplicates duplic)
+ select_create(const char *db_name, const char *table_name,
+ HA_CREATE_INFO *create_info_par,
+ List<create_field> &fields_par,
+ List<Key> &keys_par,
+ List<Item> &select_fields,enum_duplicates duplic)
:select_insert (NULL, &select_fields, duplic), db(db_name),
name(table_name), extra_fields(&fields_par),keys(&keys_par),
create_info(create_info_par), lock(0)