summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/CMakeLists.txt2
-rw-r--r--sql/Makefile.am2
-rw-r--r--sql/derror.cc23
-rw-r--r--sql/event_data_objects.cc39
-rw-r--r--sql/event_queue.cc6
-rw-r--r--sql/field.cc19
-rw-r--r--sql/field.h19
-rw-r--r--sql/filesort.cc21
-rw-r--r--sql/ha_ndbcluster.cc183
-rw-r--r--sql/ha_ndbcluster_binlog.cc14
-rw-r--r--sql/ha_partition.cc34
-rw-r--r--sql/ha_partition.h6
-rw-r--r--sql/handler.cc191
-rw-r--r--sql/handler.h18
-rw-r--r--sql/item.cc6
-rw-r--r--sql/item.h3
-rw-r--r--sql/item_cmpfunc.cc285
-rw-r--r--sql/item_cmpfunc.h105
-rw-r--r--sql/item_create.cc415
-rw-r--r--sql/item_create.h6
-rw-r--r--sql/item_func.cc132
-rw-r--r--sql/item_func.h13
-rw-r--r--sql/item_subselect.cc21
-rw-r--r--sql/item_sum.cc11
-rw-r--r--sql/key.cc23
-rw-r--r--sql/lock.cc26
-rw-r--r--sql/log.cc6
-rw-r--r--sql/log.h6
-rw-r--r--sql/log_event.cc14
-rw-r--r--sql/my_decimal.cc11
-rw-r--r--sql/my_decimal.h3
-rw-r--r--sql/mysql_priv.h52
-rw-r--r--sql/mysqld.cc587
-rw-r--r--sql/opt_range.cc9
-rw-r--r--sql/opt_range.h4
-rw-r--r--sql/opt_sum.cc87
-rw-r--r--sql/partition_element.h4
-rw-r--r--sql/rpl_mi.cc4
-rw-r--r--sql/rpl_utility.h2
-rw-r--r--sql/set_var.cc1384
-rw-r--r--sql/set_var.h393
-rw-r--r--sql/slave.cc3
-rw-r--r--sql/sp.cc9
-rw-r--r--sql/sp_head.cc51
-rw-r--r--sql/sp_head.h10
-rw-r--r--sql/sql_base.cc457
-rw-r--r--sql/sql_cache.cc36
-rw-r--r--sql/sql_class.cc118
-rw-r--r--sql/sql_class.h33
-rw-r--r--sql/sql_connect.cc1
-rw-r--r--sql/sql_delete.cc2
-rw-r--r--sql/sql_handler.cc25
-rw-r--r--sql/sql_insert.cc622
-rw-r--r--sql/sql_lex.cc337
-rw-r--r--sql/sql_lex.h94
-rw-r--r--sql/sql_load.cc4
-rw-r--r--sql/sql_parse.cc186
-rw-r--r--sql/sql_partition.cc28
-rw-r--r--sql/sql_plugin.cc2424
-rw-r--r--sql/sql_plugin.h69
-rw-r--r--sql/sql_prepare.cc33
-rw-r--r--sql/sql_repl.cc143
-rw-r--r--sql/sql_repl.h1
-rw-r--r--sql/sql_select.cc99
-rw-r--r--sql/sql_select.h8
-rw-r--r--sql/sql_show.cc331
-rw-r--r--sql/sql_table.cc325
-rw-r--r--sql/sql_tablespace.cc4
-rw-r--r--sql/sql_trigger.cc12
-rw-r--r--sql/sql_union.cc10
-rw-r--r--sql/sql_update.cc5
-rw-r--r--sql/sql_view.cc10
-rw-r--r--sql/sql_yacc.yy370
-rw-r--r--sql/structs.h2
-rw-r--r--sql/table.cc67
-rw-r--r--sql/table.h50
76 files changed, 6784 insertions, 3384 deletions
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
index cd1a5527abc..2aef0e0dc25 100644
--- a/sql/CMakeLists.txt
+++ b/sql/CMakeLists.txt
@@ -85,7 +85,7 @@ TARGET_LINK_LIBRARIES(mysqld heap myisam myisammrg mysys yassl zlib dbug yassl
taocrypt strings vio regex wsock32 ws2_32)
IF(EMBED_MANIFESTS)
- MYSQL_EMBED_MANIFEST("mysqld" "requireAdministrator")
+ MYSQL_EMBED_MANIFEST("mysqld" "asInvoker")
ENDIF(EMBED_MANIFESTS)
IF(WITH_ARCHIVE_STORAGE_ENGINE)
TARGET_LINK_LIBRARIES(mysqld archive)
diff --git a/sql/Makefile.am b/sql/Makefile.am
index 465e5c843f4..d280b22f493 100644
--- a/sql/Makefile.am
+++ b/sql/Makefile.am
@@ -33,7 +33,7 @@ SUPPORTING_LIBS = $(top_builddir)/vio/libvio.a \
$(top_builddir)/regex/libregex.a \
$(top_builddir)/strings/libmystrings.a
mysqld_DEPENDENCIES= @mysql_plugin_libs@ $(SUPPORTING_LIBS)
-LDADD = $(SUPPORTING_LIBS) @ZLIB_LIBS@
+LDADD = $(SUPPORTING_LIBS) @ZLIB_LIBS@ @NDB_SCI_LIBS@
mysqld_LDADD = @MYSQLD_EXTRA_LDFLAGS@ \
@pstack_libs@ \
@mysql_plugin_libs@ \
diff --git a/sql/derror.cc b/sql/derror.cc
index aa7edd639da..3b67e0f5bf0 100644
--- a/sql/derror.cc
+++ b/sql/derror.cc
@@ -31,6 +31,9 @@ static void init_myfunc_errs(void);
DESCRIPTION
This function can be called multiple times to reload the messages.
+ If it fails to load the messages, it will fail softly by initializing
+ the errmesg pointer to an array of empty strings or by keeping the
+ old array if it exists.
RETURN
FALSE OK
@@ -39,7 +42,7 @@ static void init_myfunc_errs(void);
bool init_errmessage(void)
{
- const char **errmsgs;
+ const char **errmsgs, **ptr;
DBUG_ENTER("init_errmessage");
/*
@@ -49,8 +52,15 @@ bool init_errmessage(void)
errmsgs= my_error_unregister(ER_ERROR_FIRST, ER_ERROR_LAST);
/* Read messages from file. */
- if (read_texts(ERRMSG_FILE, &errmsgs, ER_ERROR_LAST - ER_ERROR_FIRST + 1))
- DBUG_RETURN(TRUE);
+ if (read_texts(ERRMSG_FILE, &errmsgs, ER_ERROR_LAST - ER_ERROR_FIRST + 1) &&
+ !errmsgs)
+ {
+ if (!(errmsgs= (const char**) my_malloc((ER_ERROR_LAST-ER_ERROR_FIRST+1)*
+ sizeof(char*), MYF(0))))
+ DBUG_RETURN(TRUE);
+ for (ptr= errmsgs; ptr < errmsgs + ER_ERROR_LAST - ER_ERROR_FIRST; ptr++)
+ *ptr= "";
+ }
/* Register messages for use with my_error(). */
if (my_error_register(errmsgs, ER_ERROR_FIRST, ER_ERROR_LAST))
@@ -66,7 +76,6 @@ bool init_errmessage(void)
/* Read text from packed textfile in language-directory */
- /* If we can't read messagefile then it's panic- we can't continue */
static bool read_texts(const char *file_name,const char ***point,
uint error_messages)
@@ -81,7 +90,6 @@ static bool read_texts(const char *file_name,const char ***point,
const char *errmsg;
DBUG_ENTER("read_texts");
- *point=0; // If something goes wrong
LINT_INIT(buff);
funktpos=0;
if ((file=my_open(fn_format(name,file_name,language,"",4),
@@ -121,7 +129,7 @@ but it should contain at least %d error messages.\n\
Check that the above file is the right version for this program!",
name,count,error_messages);
VOID(my_close(file,MYF(MY_WME)));
- unireg_abort(1);
+ DBUG_RETURN(1);
}
x_free((uchar*) *point); /* Free old language */
@@ -166,8 +174,7 @@ err:
err1:
if (file != FERR)
VOID(my_close(file,MYF(MY_WME)));
- unireg_abort(1);
- DBUG_RETURN(1); // keep compiler happy
+ DBUG_RETURN(1);
} /* read_texts */
diff --git a/sql/event_data_objects.cc b/sql/event_data_objects.cc
index 71a87c12169..40564f9cafb 100644
--- a/sql/event_data_objects.cc
+++ b/sql/event_data_objects.cc
@@ -156,10 +156,14 @@ void
Event_parse_data::init_body(THD *thd)
{
DBUG_ENTER("Event_parse_data::init_body");
+
+ /* This method is called from within the parser, from sql_yacc.yy */
+ DBUG_ASSERT(thd->m_lip != NULL);
+
DBUG_PRINT("info", ("body: '%s' body_begin: 0x%lx end: 0x%lx", body_begin,
- (long) body_begin, (long) thd->lex->ptr));
+ (long) body_begin, (long) thd->m_lip->ptr));
- body.length= thd->lex->ptr - body_begin;
+ body.length= thd->m_lip->ptr - body_begin;
const char *body_end= body_begin + body.length - 1;
/* Trim nuls or close-comments ('*'+'/') or spaces at the end */
@@ -1910,18 +1914,28 @@ Event_job_data::execute(THD *thd, bool drop)
thd->variables.sql_mode= sql_mode;
thd->variables.time_zone= time_zone;
+ /*
+ Peculiar initialization order is a crutch to avoid races in SHOW
+ PROCESSLIST which reads thd->{query/query_length} without a mutex.
+ */
+ thd->query_length= 0;
thd->query= sp_sql.c_ptr_safe();
thd->query_length= sp_sql.length();
- lex_start(thd, thd->query, thd->query_length);
-
- if (MYSQLparse(thd) || thd->is_fatal_error)
{
- sql_print_error("Event Scheduler: "
- "%serror during compilation of %s.%s",
- thd->is_fatal_error ? "fatal " : "",
- (const char *) dbname.str, (const char *) name.str);
- goto end;
+ Lex_input_stream lip(thd, thd->query, thd->query_length);
+ thd->m_lip= &lip;
+ lex_start(thd);
+ int err= MYSQLparse(thd);
+
+ if (err || thd->is_fatal_error)
+ {
+ sql_print_error("Event Scheduler: "
+ "%serror during compilation of %s.%s",
+ thd->is_fatal_error ? "fatal " : "",
+ (const char *) dbname.str, (const char *) name.str);
+ goto end;
+ }
}
{
@@ -1960,6 +1974,11 @@ end:
ret= 1;
else
{
+ /*
+ Peculiar initialization order is a crutch to avoid races in SHOW
+ PROCESSLIST which reads thd->{query/query_length} without a mutex.
+ */
+ thd->query_length= 0;
thd->query= sp_sql.c_ptr_safe();
thd->query_length= sp_sql.length();
if (Events::drop_event(thd, dbname, name, FALSE))
diff --git a/sql/event_queue.cc b/sql/event_queue.cc
index e1bf3a85a7a..cd276c661ab 100644
--- a/sql/event_queue.cc
+++ b/sql/event_queue.cc
@@ -70,11 +70,11 @@ event_queue_element_compare_q(void *vptr, uchar* a, uchar *b)
*/
Event_queue::Event_queue()
- :mutex_last_unlocked_at_line(0), mutex_last_locked_at_line(0),
+ :mutex_last_locked_at_line(0), mutex_last_unlocked_at_line(0),
mutex_last_attempted_lock_at_line(0),
mutex_queue_data_locked(FALSE),
- mutex_queue_data_attempting_lock(FALSE),
- next_activation_at(0)
+ next_activation_at(0),
+ mutex_queue_data_attempting_lock(FALSE)
{
mutex_last_unlocked_in_func= mutex_last_locked_in_func=
mutex_last_attempted_lock_in_func= "";
diff --git a/sql/field.cc b/sql/field.cc
index e883831a828..d323f6e384e 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -7021,34 +7021,34 @@ Field_blob::Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
}
-void Field_blob::store_length(uint32 number)
+void Field_blob::store_length(char *i_ptr, uint i_packlength, uint32 i_number)
{
- switch (packlength) {
+ switch (i_packlength) {
case 1:
- ptr[0]= (uchar) number;
+ i_ptr[0]= (uchar) i_number;
break;
case 2:
#ifdef WORDS_BIGENDIAN
if (table->s->db_low_byte_first)
{
- int2store(ptr,(unsigned short) number);
+ int2store(i_ptr,(unsigned short) i_number);
}
else
#endif
- shortstore(ptr,(unsigned short) number);
+ shortstore(i_ptr,(unsigned short) i_number);
break;
case 3:
- int3store(ptr,number);
+ int3store(i_ptr,i_number);
break;
case 4:
#ifdef WORDS_BIGENDIAN
if (table->s->db_low_byte_first)
{
- int4store(ptr,number);
+ int4store(i_ptr,i_number);
}
else
#endif
- longstore(ptr,number);
+ longstore(i_ptr,i_number);
}
}
@@ -8794,8 +8794,7 @@ bool create_field::init(THD *thd, char *fld_name, enum_field_types fld_type,
case MYSQL_TYPE_NULL:
break;
case MYSQL_TYPE_NEWDECIMAL:
- if (!fld_length && !decimals)
- length= 10;
+ my_decimal_trim(&length, &decimals);
if (length > DECIMAL_MAX_PRECISION)
{
my_error(ER_TOO_BIG_PRECISION, MYF(0), length, fld_name,
diff --git a/sql/field.h b/sql/field.h
index 2bb9864e904..e787922c296 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -1310,7 +1310,15 @@ public:
}
int reset(void) { bzero(ptr, packlength+sizeof(uchar*)); return 0; }
void reset_fields() { bzero((uchar*) &value,sizeof(value)); }
- void store_length(uint32 number);
+#ifndef WORDS_BIGENDIAN
+ static
+#endif
+ void store_length(char *i_ptr, uint i_packlength, uint32 i_number);
+ inline void store_length(uint32 number)
+ {
+ store_length(ptr, packlength, number);
+ }
+
inline uint32 get_length(uint row_offset=0)
{ return get_length(ptr+row_offset); }
uint32 get_length(const uchar *ptr);
@@ -1328,10 +1336,15 @@ public:
memcpy(ptr,length,packlength);
memcpy_fixed(ptr+packlength,&data,sizeof(char*));
}
+ void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32 length,char *data)
+ {
+ char *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,char*);
+ store_length(ptr_ofs, packlength, length);
+ memcpy_fixed(ptr_ofs+packlength,&data,sizeof(char*));
+ }
inline void set_ptr(uint32 length, uchar *data)
{
- store_length(length);
- memcpy_fixed(ptr+packlength,&data,sizeof(char*));
+ set_ptr_offset(0, length, data);
}
uint get_key_image(uchar *buff,uint length, imagetype type);
void set_key_image(const uchar *buff,uint length);
diff --git a/sql/filesort.cc b/sql/filesort.cc
index 1091282aea1..204ba87329a 100644
--- a/sql/filesort.cc
+++ b/sql/filesort.cc
@@ -255,7 +255,8 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
open_cached_file(outfile,mysql_tmpdir,TEMP_PREFIX,READ_RECORD_BUFFER,
MYF(MY_WME)))
goto err;
- reinit_io_cache(outfile,WRITE_CACHE,0L,0,0);
+ if (reinit_io_cache(outfile,WRITE_CACHE,0L,0,0))
+ goto err;
/*
Use also the space previously used by string pointers in sort_buffer
@@ -375,6 +376,8 @@ static BUFFPEK *read_buffpek_from_file(IO_CACHE *buffpek_pointers, uint count)
ulong length;
BUFFPEK *tmp;
DBUG_ENTER("read_buffpek_from_file");
+ if (count > UINT_MAX/sizeof(BUFFPEK))
+ return 0; /* sizeof(BUFFPEK)*count will overflow */
tmp=(BUFFPEK*) my_malloc(length=sizeof(BUFFPEK)*count, MYF(MY_WME));
if (tmp)
{
@@ -625,6 +628,9 @@ write_keys(SORTPARAM *param, register uchar **sort_keys, uint count,
open_cached_file(tempfile, mysql_tmpdir, TEMP_PREFIX, DISK_BUFFER_SIZE,
MYF(MY_WME)))
goto err; /* purecov: inspected */
+ /* check we won't have more buffpeks than we can possibly keep in memory */
+ if (my_b_tell(buffpek_pointers) + sizeof(BUFFPEK) > (ulonglong)UINT_MAX)
+ goto err;
buffpek.file_pos= my_b_tell(tempfile);
if ((ha_rows) count > param->max_rows)
count=(uint) param->max_rows; /* purecov: inspected */
@@ -983,7 +989,7 @@ static bool save_index(SORTPARAM *param, uchar **sort_keys, uint count,
int merge_many_buff(SORTPARAM *param, uchar *sort_buffer,
BUFFPEK *buffpek, uint *maxbuffer, IO_CACHE *t_file)
{
- register int i;
+ register uint i;
IO_CACHE t_file2,*from_file,*to_file,*temp;
BUFFPEK *lastbuff;
DBUG_ENTER("merge_many_buff");
@@ -998,14 +1004,16 @@ int merge_many_buff(SORTPARAM *param, uchar *sort_buffer,
from_file= t_file ; to_file= &t_file2;
while (*maxbuffer >= MERGEBUFF2)
{
- reinit_io_cache(from_file,READ_CACHE,0L,0,0);
- reinit_io_cache(to_file,WRITE_CACHE,0L,0,0);
+ if (reinit_io_cache(from_file,READ_CACHE,0L,0,0))
+ goto cleanup;
+ if (reinit_io_cache(to_file,WRITE_CACHE,0L,0,0))
+ goto cleanup;
lastbuff=buffpek;
- for (i=0 ; i <= (int) *maxbuffer-MERGEBUFF*3/2 ; i+=MERGEBUFF)
+ for (i=0 ; i <= *maxbuffer-MERGEBUFF*3/2 ; i+=MERGEBUFF)
{
if (merge_buffers(param,from_file,to_file,sort_buffer,lastbuff++,
buffpek+i,buffpek+i+MERGEBUFF-1,0))
- break; /* purecov: inspected */
+ goto cleanup;
}
if (merge_buffers(param,from_file,to_file,sort_buffer,lastbuff++,
buffpek+i,buffpek+ *maxbuffer,0))
@@ -1017,6 +1025,7 @@ int merge_many_buff(SORTPARAM *param, uchar *sort_buffer,
setup_io_cache(to_file);
*maxbuffer= (uint) (lastbuff-buffpek)-1;
}
+cleanup:
close_cached_file(to_file); // This holds old result
if (to_file == t_file)
{
diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
index ad6572d7a6b..adbde36066b 100644
--- a/sql/ha_ndbcluster.cc
+++ b/sql/ha_ndbcluster.cc
@@ -874,9 +874,7 @@ int get_ndb_blobs_value(TABLE* table, NdbValue* value_array,
i, offset, (long) buf, len, (int)ptrdiff));
DBUG_ASSERT(len == len64);
// Ugly hack assumes only ptr needs to be changed
- field_blob->ptr+= ptrdiff;
- field_blob->set_ptr(len, buf);
- field_blob->ptr-= ptrdiff;
+ field_blob->set_ptr_offset(ptrdiff, len, buf);
}
offset+= size;
}
@@ -885,9 +883,7 @@ int get_ndb_blobs_value(TABLE* table, NdbValue* value_array,
// have to set length even in this case
uchar *buf= buffer + offset; // or maybe NULL
uint32 len= 0;
- field_blob->ptr+= ptrdiff;
- field_blob->set_ptr(len, buf);
- field_blob->ptr-= ptrdiff;
+ field_blob->set_ptr_offset(ptrdiff, len, buf);
DBUG_PRINT("info", ("[%u] isNull=%d", i, isNull));
}
}
@@ -1909,6 +1905,33 @@ bool ha_ndbcluster::check_all_operations_for_error(NdbTransaction *trans,
}
+/**
+ * Check if record contains any null valued columns that are part of a key
+ */
+static
+int
+check_null_in_record(const KEY* key_info, const byte *record)
+{
+ KEY_PART_INFO *curr_part, *end_part;
+ curr_part= key_info->key_part;
+ end_part= curr_part + key_info->key_parts;
+
+ while (curr_part != end_part)
+ {
+ if (curr_part->null_bit &&
+ (record[curr_part->null_offset] & curr_part->null_bit))
+ return 1;
+ curr_part++;
+ }
+ return 0;
+ /*
+ We could instead pre-compute a bitmask in table_share with one bit for
+ every null-bit in the key, and so check this just by OR'ing the bitmask
+ with the null bitmap in the record.
+ But not sure it's worth it.
+ */
+}
+
/*
* Peek to check if any rows already exist with conflicting
* primary key or unique index values
@@ -1966,7 +1989,17 @@ int ha_ndbcluster::peek_indexed_rows(const uchar *record,
if (i != table->s->primary_key &&
key_info->flags & HA_NOSAME)
{
- // A unique index is defined on table
+ /*
+ A unique index is defined on table.
+ We cannot look up a NULL field value in a unique index. But since
+ keys with NULLs are not indexed, such rows cannot conflict anyway, so
+ we just skip the index in this case.
+ */
+ if (check_null_in_record(key_info, record))
+ {
+ DBUG_PRINT("info", ("skipping check for key with NULL"));
+ continue;
+ }
NdbIndexOperation *iop;
const NDBINDEX *unique_index = m_index[i].unique_index;
key_part= key_info->key_part;
@@ -2668,7 +2701,7 @@ int ha_ndbcluster::write_row(uchar *record)
DBUG_RETURN(peek_res);
}
- statistic_increment(thd->status_var.ha_write_count, &LOCK_status);
+ ha_statistic_increment(&SSV::ha_write_count);
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
table->timestamp_field->set_time();
@@ -2698,17 +2731,24 @@ int ha_ndbcluster::write_row(uchar *record)
{
// Table has hidden primary key
Ndb *ndb= get_ndb();
- int ret;
Uint64 auto_value;
uint retries= NDB_AUTO_INCREMENT_RETRIES;
- do {
+ int retry_sleep= 30; /* 30 milliseconds, transaction */
+ for (;;)
+ {
Ndb_tuple_id_range_guard g(m_share);
- ret= ndb->getAutoIncrementValue(m_table, g.range, auto_value, 1);
- } while (ret == -1 &&
- --retries &&
- ndb->getNdbError().status == NdbError::TemporaryError);
- if (ret == -1)
- ERR_RETURN(ndb->getNdbError());
+ if (ndb->getAutoIncrementValue(m_table, g.range, auto_value, 1) == -1)
+ {
+ if (--retries &&
+ ndb->getNdbError().status == NdbError::TemporaryError);
+ {
+ my_sleep(retry_sleep);
+ continue;
+ }
+ ERR_RETURN(ndb->getNdbError());
+ }
+ break;
+ }
if (set_hidden_key(op, table_share->fields, (const uchar*)&auto_value))
ERR_RETURN(op->getNdbError());
}
@@ -2897,7 +2937,7 @@ int ha_ndbcluster::update_row(const uchar *old_data, uchar *new_data)
DBUG_RETURN(peek_res);
}
- statistic_increment(thd->status_var.ha_update_count, &LOCK_status);
+ ha_statistic_increment(&SSV::ha_update_count);
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
{
table->timestamp_field->set_time();
@@ -3077,7 +3117,7 @@ int ha_ndbcluster::delete_row(const uchar *record)
DBUG_ENTER("delete_row");
m_write_op= TRUE;
- statistic_increment(thd->status_var.ha_delete_count,&LOCK_status);
+ ha_statistic_increment(&SSV::ha_delete_count);
m_rows_changed++;
if (m_use_partition_function &&
@@ -3471,8 +3511,7 @@ int ha_ndbcluster::index_read(uchar *buf,
int ha_ndbcluster::index_next(uchar *buf)
{
DBUG_ENTER("ha_ndbcluster::index_next");
- statistic_increment(current_thd->status_var.ha_read_next_count,
- &LOCK_status);
+ ha_statistic_increment(&SSV::ha_read_next_count);
DBUG_RETURN(next_result(buf));
}
@@ -3480,8 +3519,7 @@ int ha_ndbcluster::index_next(uchar *buf)
int ha_ndbcluster::index_prev(uchar *buf)
{
DBUG_ENTER("ha_ndbcluster::index_prev");
- statistic_increment(current_thd->status_var.ha_read_prev_count,
- &LOCK_status);
+ ha_statistic_increment(&SSV::ha_read_prev_count);
DBUG_RETURN(next_result(buf));
}
@@ -3489,8 +3527,7 @@ int ha_ndbcluster::index_prev(uchar *buf)
int ha_ndbcluster::index_first(uchar *buf)
{
DBUG_ENTER("ha_ndbcluster::index_first");
- statistic_increment(current_thd->status_var.ha_read_first_count,
- &LOCK_status);
+ ha_statistic_increment(&SSV::ha_read_first_count);
// Start the ordered index scan and fetch the first row
// Only HA_READ_ORDER indexes get called by index_first
@@ -3501,7 +3538,7 @@ int ha_ndbcluster::index_first(uchar *buf)
int ha_ndbcluster::index_last(uchar *buf)
{
DBUG_ENTER("ha_ndbcluster::index_last");
- statistic_increment(current_thd->status_var.ha_read_last_count,&LOCK_status);
+ ha_statistic_increment(&SSV::ha_read_last_count);
DBUG_RETURN(ordered_index_scan(0, 0, TRUE, TRUE, buf, NULL));
}
@@ -3687,8 +3724,7 @@ int ha_ndbcluster::rnd_end()
int ha_ndbcluster::rnd_next(uchar *buf)
{
DBUG_ENTER("rnd_next");
- statistic_increment(current_thd->status_var.ha_read_rnd_next_count,
- &LOCK_status);
+ ha_statistic_increment(&SSV::ha_read_rnd_next_count);
if (!m_active_cursor)
DBUG_RETURN(full_table_scan(buf));
@@ -3706,8 +3742,7 @@ int ha_ndbcluster::rnd_next(uchar *buf)
int ha_ndbcluster::rnd_pos(uchar *buf, uchar *pos)
{
DBUG_ENTER("rnd_pos");
- statistic_increment(current_thd->status_var.ha_read_rnd_count,
- &LOCK_status);
+ ha_statistic_increment(&SSV::ha_read_rnd_count);
// The primary key for the record is stored in pos
// Perform a pk_read using primary key "index"
{
@@ -6039,24 +6074,28 @@ void ha_ndbcluster::get_auto_increment(ulonglong offset, ulonglong increment,
m_rows_to_insert - m_rows_inserted :
((m_rows_to_insert > m_autoincrement_prefetch) ?
m_rows_to_insert : m_autoincrement_prefetch));
- int ret;
uint retries= NDB_AUTO_INCREMENT_RETRIES;
- do {
+ int retry_sleep= 30; /* 30 milliseconds, transaction */
+ for (;;)
+ {
Ndb_tuple_id_range_guard g(m_share);
- ret=
- m_skip_auto_increment ?
- ndb->readAutoIncrementValue(m_table, g.range, auto_value) :
- ndb->getAutoIncrementValue(m_table, g.range, auto_value, cache_size);
- } while (ret == -1 &&
- --retries &&
- ndb->getNdbError().status == NdbError::TemporaryError);
- if (ret == -1)
- {
- const NdbError err= ndb->getNdbError();
- sql_print_error("Error %lu in ::get_auto_increment(): %s",
- (ulong) err.code, err.message);
- *first_value= ~(ulonglong) 0;
- DBUG_VOID_RETURN;
+ if (m_skip_auto_increment &&
+ ndb->readAutoIncrementValue(m_table, g.range, auto_value) ||
+ ndb->getAutoIncrementValue(m_table, g.range, auto_value, cache_size))
+ {
+ if (--retries &&
+ ndb->getNdbError().status == NdbError::TemporaryError);
+ {
+ my_sleep(retry_sleep);
+ continue;
+ }
+ const NdbError err= ndb->getNdbError();
+ sql_print_error("Error %lu in ::get_auto_increment(): %s",
+ (ulong) err.code, err.message);
+ *first_value= ~(ulonglong) 0;
+ DBUG_VOID_RETURN;
+ }
+ break;
}
*first_value= (longlong)auto_value;
/* From the point of view of MySQL, NDB reserves one row at a time */
@@ -6238,23 +6277,23 @@ int ha_ndbcluster::open(const char *name, int mode, uint test_if_locked)
set_dbname(name);
set_tabname(name);
- if (check_ndb_connection())
+ if ((res= check_ndb_connection()) ||
+ (res= get_metadata(name)))
{
/* ndb_share reference handler free */
DBUG_PRINT("NDB_SHARE", ("%s handler free use_count: %u",
m_share->key, m_share->use_count));
free_share(&m_share);
m_share= 0;
- DBUG_RETURN(HA_ERR_NO_CONNECTION);
+ DBUG_RETURN(res);
}
-
- res= get_metadata(name);
- if (!res)
+ while (1)
{
Ndb *ndb= get_ndb();
if (ndb->setDatabaseName(m_dbname))
{
- ERR_RETURN(ndb->getNdbError());
+ res= ndb_to_mysql_error(&ndb->getNdbError());
+ break;
}
struct Ndb_statistics stat;
res= ndb_get_table_statistics(NULL, FALSE, ndb, m_table, &stat);
@@ -6263,14 +6302,20 @@ int ha_ndbcluster::open(const char *name, int mode, uint test_if_locked)
stats.records= stat.row_count;
if(!res)
res= info(HA_STATUS_CONST);
+ break;
+ }
+ if (res)
+ {
+ free_share(&m_share);
+ m_share= 0;
+ release_metadata(current_thd, get_ndb());
+ DBUG_RETURN(res);
}
-
#ifdef HAVE_NDB_BINLOG
if (!ndb_binlog_tables_inited && ndb_binlog_running)
table->db_stat|= HA_READ_ONLY;
#endif
-
- DBUG_RETURN(res);
+ DBUG_RETURN(0);
}
/*
@@ -6536,9 +6581,9 @@ int ndbcluster_table_exists_in_engine(handlerton *hton, THD* thd,
if (my_strcasecmp(system_charset_info, elmt.name, name))
continue;
DBUG_PRINT("info", ("Found table"));
- DBUG_RETURN(1);
+ DBUG_RETURN(HA_ERR_TABLE_EXIST);
}
- DBUG_RETURN(0);
+ DBUG_RETURN(HA_ERR_NO_SUCH_TABLE);
}
@@ -6649,7 +6694,7 @@ int ndb_create_table_from_engine(THD *thd, const char *db,
LEX *old_lex= thd->lex, newlex;
thd->lex= &newlex;
newlex.current_select= NULL;
- lex_start(thd, "", 0);
+ lex_start(thd);
int res= ha_create_table_from_engine(thd, db, table_name);
thd->lex= old_lex;
return res;
@@ -6903,7 +6948,7 @@ int ndbcluster_find_files(handlerton *hton, THD *thd,
DBUG_PRINT("info", ("%s existed on disk", name));
// The .ndb file exists on disk, but it's not in list of tables in ndb
// Verify that handler agrees table is gone.
- if (ndbcluster_table_exists_in_engine(hton, thd, db, file_name) == 0)
+ if (ndbcluster_table_exists_in_engine(hton, thd, db, file_name) == HA_ERR_NO_SUCH_TABLE)
{
DBUG_PRINT("info", ("NDB says %s does not exists", file_name));
it.remove();
@@ -7032,6 +7077,7 @@ static int connect_callback()
}
extern int ndb_dictionary_is_mysqld;
+extern pthread_mutex_t LOCK_plugin;
static int ndbcluster_init(void *p)
{
@@ -7041,6 +7087,13 @@ static int ndbcluster_init(void *p)
if (ndbcluster_inited)
DBUG_RETURN(FALSE);
+ /*
+ Below we create new THD's. They'll need LOCK_plugin, but it's taken now by
+ plugin initialization code. Release it to avoid deadlocks. It's safe, as
+ there're no threads that may concurrently access plugin control structures.
+ */
+ pthread_mutex_unlock(&LOCK_plugin);
+
pthread_mutex_init(&ndbcluster_mutex,MY_MUTEX_INIT_FAST);
pthread_mutex_init(&LOCK_ndb_util_thread, MY_MUTEX_INIT_FAST);
pthread_cond_init(&COND_ndb_util_thread, NULL);
@@ -7052,7 +7105,7 @@ static int ndbcluster_init(void *p)
{
handlerton *h= ndbcluster_hton;
- h->state= have_ndbcluster;
+ h->state= SHOW_OPTION_YES;
h->db_type= DB_TYPE_NDBCLUSTER;
h->close_connection= ndbcluster_close_connection;
h->commit= ndbcluster_commit;
@@ -7074,9 +7127,6 @@ static int ndbcluster_init(void *p)
h->table_exists_in_engine= ndbcluster_table_exists_in_engine;
}
- if (have_ndbcluster != SHOW_OPTION_YES)
- DBUG_RETURN(0); // nothing else to do
-
// Initialize ndb interface
ndb_init_internal();
@@ -7184,6 +7234,8 @@ static int ndbcluster_init(void *p)
goto ndbcluster_init_error;
}
+ pthread_mutex_lock(&LOCK_plugin);
+
ndbcluster_inited= 1;
DBUG_RETURN(FALSE);
@@ -7194,9 +7246,10 @@ ndbcluster_init_error:
if (g_ndb_cluster_connection)
delete g_ndb_cluster_connection;
g_ndb_cluster_connection= NULL;
- have_ndbcluster= SHOW_OPTION_DISABLED; // If we couldn't use handler
ndbcluster_hton->state= SHOW_OPTION_DISABLED; // If we couldn't use handler
+ pthread_mutex_lock(&LOCK_plugin);
+
DBUG_RETURN(TRUE);
}
@@ -9216,10 +9269,6 @@ ndbcluster_show_status(handlerton *hton, THD* thd, stat_print_fn *stat_print,
uint buflen;
DBUG_ENTER("ndbcluster_show_status");
- if (have_ndbcluster != SHOW_OPTION_YES)
- {
- DBUG_RETURN(FALSE);
- }
if (stat_type != HA_ENGINE_STATUS)
{
DBUG_RETURN(FALSE);
diff --git a/sql/ha_ndbcluster_binlog.cc b/sql/ha_ndbcluster_binlog.cc
index bfaaaadab43..8b2250a9a9b 100644
--- a/sql/ha_ndbcluster_binlog.cc
+++ b/sql/ha_ndbcluster_binlog.cc
@@ -230,6 +230,7 @@ static void run_query(THD *thd, char *buf, char *end,
ulonglong save_thd_options= thd->options;
DBUG_ASSERT(sizeof(save_thd_options) == sizeof(thd->options));
NET save_net= thd->net;
+ const char* found_semicolon= NULL;
bzero((char*) &thd->net, sizeof(NET));
thd->query_length= end - buf;
@@ -239,7 +240,7 @@ static void run_query(THD *thd, char *buf, char *end,
thd->options&= ~OPTION_BIN_LOG;
DBUG_PRINT("query", ("%s", thd->query));
- mysql_parse(thd, thd->query, thd->query_length);
+ mysql_parse(thd, thd->query, thd->query_length, &found_semicolon);
if (print_error && thd->query_error)
{
@@ -3809,6 +3810,17 @@ restart:
res= i_ndb->pollEvents(tot_poll_wait, &gci);
tot_poll_wait= 0;
}
+ else
+ {
+ /*
+ Just consume any events, not used if no binlogging
+ e.g. node failure events
+ */
+ Uint64 tmp_gci;
+ if (i_ndb->pollEvents(0, &tmp_gci))
+ while (i_ndb->nextEvent())
+ ;
+ }
int schema_res= s_ndb->pollEvents(tot_poll_wait, &schema_gci);
ndb_latest_received_binlog_epoch= gci;
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index 5393e8499b0..36711cc100b 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -1986,6 +1986,8 @@ bool ha_partition::create_handler_file(const char *name)
void ha_partition::clear_handler_file()
{
+ if (m_engine_array)
+ plugin_unlock_list(NULL, m_engine_array, m_tot_parts);
my_free((char*) m_file_buffer, MYF(MY_ALLOW_ZERO_PTR));
my_free((char*) m_engine_array, MYF(MY_ALLOW_ZERO_PTR));
m_file_buffer= NULL;
@@ -2008,6 +2010,7 @@ bool ha_partition::create_handlers(MEM_ROOT *mem_root)
{
uint i;
uint alloc_len= (m_tot_parts + 1) * sizeof(handler*);
+ handlerton *hton0;
DBUG_ENTER("create_handlers");
if (!(m_file= (handler **) alloc_root(mem_root, alloc_len)))
@@ -2016,19 +2019,21 @@ bool ha_partition::create_handlers(MEM_ROOT *mem_root)
bzero((char*) m_file, alloc_len);
for (i= 0; i < m_tot_parts; i++)
{
+ handlerton *hton= plugin_data(m_engine_array[i], handlerton*);
if (!(m_file[i]= get_new_handler(table_share, mem_root,
- m_engine_array[i])))
+ hton)))
DBUG_RETURN(TRUE);
- DBUG_PRINT("info", ("engine_type: %u", m_engine_array[i]->db_type));
+ DBUG_PRINT("info", ("engine_type: %u", hton->db_type));
}
/* For the moment we only support partition over the same table engine */
- if (m_engine_array[0] == myisam_hton)
+ hton0= plugin_data(m_engine_array[0], handlerton*);
+ if (hton0 == myisam_hton)
{
DBUG_PRINT("info", ("MyISAM"));
m_myisam= TRUE;
}
/* INNODB may not be compiled in... */
- else if (ha_legacy_type(m_engine_array[0]) == DB_TYPE_INNODB)
+ else if (ha_legacy_type(hton0) == DB_TYPE_INNODB)
{
DBUG_PRINT("info", ("InnoDB"));
m_innodb= TRUE;
@@ -2159,8 +2164,7 @@ bool ha_partition::get_from_handler_file(const char *name, MEM_ROOT *mem_root)
m_tot_parts= uint4korr((file_buffer) + 8);
DBUG_PRINT("info", ("No of parts = %u", m_tot_parts));
tot_partition_words= (m_tot_parts + 3) / 4;
- if (!(engine_array= (handlerton **) my_malloc(m_tot_parts * sizeof(handlerton*),MYF(0))))
- goto err2;
+ engine_array= (handlerton **) my_alloca(m_tot_parts * sizeof(handlerton*));
for (i= 0; i < m_tot_parts; i++)
engine_array[i]= ha_resolve_by_legacy_type(current_thd,
(enum legacy_db_type)
@@ -2168,12 +2172,21 @@ bool ha_partition::get_from_handler_file(const char *name, MEM_ROOT *mem_root)
address_tot_name_len= file_buffer + 12 + 4 * tot_partition_words;
tot_name_words= (uint4korr(address_tot_name_len) + 3) / 4;
if (len_words != (tot_partition_words + tot_name_words + 4))
- goto err2;
+ goto err3;
name_buffer_ptr= file_buffer + 16 + 4 * tot_partition_words;
VOID(my_close(file, MYF(0)));
m_file_buffer= file_buffer; // Will be freed in clear_handler_file()
m_name_buffer_ptr= name_buffer_ptr;
- m_engine_array= engine_array;
+
+ if (!(m_engine_array= (plugin_ref*)
+ my_malloc(m_tot_parts * sizeof(plugin_ref), MYF(MY_WME))))
+ goto err3;
+
+ for (i= 0; i < m_tot_parts; i++)
+ m_engine_array[i]= ha_lock_engine(NULL, engine_array[i]);
+
+ my_afree((gptr) engine_array);
+
if (!m_file && create_handlers(mem_root))
{
clear_handler_file();
@@ -2181,6 +2194,8 @@ bool ha_partition::get_from_handler_file(const char *name, MEM_ROOT *mem_root)
}
DBUG_RETURN(FALSE);
+err3:
+ my_afree((gptr) engine_array);
err2:
my_free(file_buffer, MYF(0));
err1:
@@ -2324,7 +2339,8 @@ err_handler:
handler *ha_partition::clone(MEM_ROOT *mem_root)
{
- handler *new_handler= get_new_handler(table->s, mem_root, table->s->db_type);
+ handler *new_handler= get_new_handler(table->s, mem_root,
+ table->s->db_type());
((ha_partition*)new_handler)->m_part_info= m_part_info;
((ha_partition*)new_handler)->is_clone= TRUE;
if (new_handler && !new_handler->ha_open(table,
diff --git a/sql/ha_partition.h b/sql/ha_partition.h
index 0878c75ec42..a168007ea04 100644
--- a/sql/ha_partition.h
+++ b/sql/ha_partition.h
@@ -27,6 +27,7 @@ enum partition_keywords
The partition implements the minimum of what you will probably need.
*/
+#ifdef NOT_USED
typedef struct st_partition_share
{
char *table_name;
@@ -34,6 +35,7 @@ typedef struct st_partition_share
pthread_mutex_t mutex;
THR_LOCK lock;
} PARTITION_SHARE;
+#endif
#define PARTITION_BYTES_IN_POS 2
@@ -54,7 +56,7 @@ private:
uint m_open_test_lock; // Open test_if_locked
char *m_file_buffer; // Buffer with names
char *m_name_buffer_ptr; // Pointer to first partition name
- handlerton **m_engine_array; // Array of types of the handlers
+ plugin_ref *m_engine_array; // Array of types of the handlers
handler **m_file; // Array of references to handler inst.
uint m_file_tot_parts; // Debug
handler **m_new_file; // Array of references to new handlers
@@ -130,7 +132,9 @@ private:
Variables for lock structures.
*/
THR_LOCK_DATA lock; /* MySQL lock */
+#ifdef NOT_USED
PARTITION_SHARE *share; /* Shared lock info */
+#endif
/*
TRUE <=> this object was created with ha_partition::clone and doesn't
diff --git a/sql/handler.cc b/sql/handler.cc
index f28e0d0bc20..846741146d4 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -77,6 +77,15 @@ static TYPELIB known_extensions= {0,"known_exts", NULL, NULL};
uint known_extensions_id= 0;
+
+static plugin_ref ha_default_plugin(THD *thd)
+{
+ if (thd->variables.table_plugin)
+ return thd->variables.table_plugin;
+ return my_plugin_lock(thd, &global_system_variables.table_plugin);
+}
+
+
/** @brief
Return the default storage engine handlerton for thread
@@ -89,10 +98,11 @@ uint known_extensions_id= 0;
*/
handlerton *ha_default_handlerton(THD *thd)
{
- return (thd->variables.table_type != NULL) ?
- thd->variables.table_type :
- (global_system_variables.table_type != NULL ?
- global_system_variables.table_type : myisam_hton);
+ plugin_ref plugin= ha_default_plugin(thd);
+ DBUG_ASSERT(plugin);
+ handlerton *hton= plugin_data(plugin, handlerton*);
+ DBUG_ASSERT(hton);
+ return hton;
}
@@ -105,26 +115,30 @@ handlerton *ha_default_handlerton(THD *thd)
name name of storage engine
RETURN
- pointer to handlerton
+ pointer to storage engine plugin handle
*/
-handlerton *ha_resolve_by_name(THD *thd, const LEX_STRING *name)
+plugin_ref ha_resolve_by_name(THD *thd, const LEX_STRING *name)
{
const LEX_STRING *table_alias;
- st_plugin_int *plugin;
+ plugin_ref plugin;
redo:
/* my_strnncoll is a macro and gcc doesn't do early expansion of macro */
if (thd && !my_charset_latin1.coll->strnncoll(&my_charset_latin1,
(const uchar *)name->str, name->length,
(const uchar *)STRING_WITH_LEN("DEFAULT"), 0))
- return ha_default_handlerton(thd);
+ return ha_default_plugin(thd);
- if ((plugin= plugin_lock(name, MYSQL_STORAGE_ENGINE_PLUGIN)))
+ if ((plugin= my_plugin_lock_by_name(thd, name, MYSQL_STORAGE_ENGINE_PLUGIN)))
{
- handlerton *hton= (handlerton *)plugin->data;
+ handlerton *hton= plugin_data(plugin, handlerton *);
if (!(hton->flags & HTON_NOT_USER_SELECTABLE))
- return hton;
- plugin_unlock(plugin);
+ return plugin;
+
+ /*
+ unlocking plugin immediately after locking is relatively low cost.
+ */
+ plugin_unlock(thd, plugin);
}
/*
@@ -145,19 +159,19 @@ redo:
}
-const char *ha_get_storage_engine(enum legacy_db_type db_type)
+plugin_ref ha_lock_engine(THD *thd, handlerton *hton)
{
- switch (db_type) {
- case DB_TYPE_DEFAULT:
- return "DEFAULT";
- default:
- if (db_type > DB_TYPE_UNKNOWN && db_type < DB_TYPE_DEFAULT &&
- installed_htons[db_type])
- return hton2plugin[installed_htons[db_type]->slot]->name.str;
- /* fall through */
- case DB_TYPE_UNKNOWN:
- return "UNKNOWN";
+ if (hton)
+ {
+ st_plugin_int **plugin= hton2plugin + hton->slot;
+
+#ifdef DBUG_OFF
+ return my_plugin_lock(thd, plugin);
+#else
+ return my_plugin_lock(thd, &plugin);
+#endif
}
+ return NULL;
}
@@ -172,14 +186,16 @@ static handler *create_default(TABLE_SHARE *table, MEM_ROOT *mem_root)
handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type)
{
+ plugin_ref plugin;
switch (db_type) {
case DB_TYPE_DEFAULT:
return ha_default_handlerton(thd);
- case DB_TYPE_UNKNOWN:
- return NULL;
default:
- if (db_type > DB_TYPE_UNKNOWN && db_type < DB_TYPE_DEFAULT)
- return installed_htons[db_type];
+ if (db_type > DB_TYPE_UNKNOWN && db_type < DB_TYPE_DEFAULT &&
+ (plugin= ha_lock_engine(thd, installed_htons[db_type])))
+ return plugin_data(plugin, handlerton*);
+ /* fall through */
+ case DB_TYPE_UNKNOWN:
return NULL;
}
}
@@ -199,7 +215,7 @@ handlerton *ha_checktype(THD *thd, enum legacy_db_type database_type,
{
if (report_error)
{
- const char *engine_name= ha_get_storage_engine(database_type);
+ const char *engine_name= ha_resolve_storage_engine_name(hton);
my_error(ER_FEATURE_DISABLED,MYF(0),engine_name,engine_name);
}
return NULL;
@@ -238,8 +254,7 @@ handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc,
Here the call to current_thd() is ok as we call this function a lot of
times but we enter this branch very seldom.
*/
- DBUG_RETURN(get_new_handler(share, alloc,
- current_thd->variables.table_type));
+ DBUG_RETURN(get_new_handler(share, alloc, ha_default_handlerton(current_thd)));
}
@@ -401,6 +416,7 @@ int ha_initialize_handlerton(st_plugin_int *plugin)
{
handlerton *hton;
DBUG_ENTER("ha_initialize_handlerton");
+ DBUG_PRINT("plugin", ("initialize plugin: '%s'", plugin->name.str));
hton= (handlerton *)my_malloc(sizeof(handlerton),
MYF(MY_WME | MY_ZEROFILL));
@@ -522,10 +538,10 @@ int ha_end()
DBUG_RETURN(error);
}
-static my_bool dropdb_handlerton(THD *unused1, st_plugin_int *plugin,
+static my_bool dropdb_handlerton(THD *unused1, plugin_ref plugin,
void *path)
{
- handlerton *hton= (handlerton *)plugin->data;
+ handlerton *hton= plugin_data(plugin, handlerton *);
if (hton->state == SHOW_OPTION_YES && hton->drop_database)
hton->drop_database(hton, (char *)path);
return FALSE;
@@ -538,10 +554,10 @@ void ha_drop_database(char* path)
}
-static my_bool closecon_handlerton(THD *thd, st_plugin_int *plugin,
+static my_bool closecon_handlerton(THD *thd, plugin_ref plugin,
void *unused)
{
- handlerton *hton= (handlerton *)plugin->data;
+ handlerton *hton= plugin_data(plugin, handlerton *);
/*
there's no need to rollback here as all transactions must
be rolled back already
@@ -638,7 +654,7 @@ int ha_prepare(THD *thd)
{
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
- hton2plugin[(*ht)->slot]->name.str);
+ ha_resolve_storage_engine_name(*ht));
}
}
}
@@ -886,10 +902,10 @@ struct xahton_st {
int result;
};
-static my_bool xacommit_handlerton(THD *unused1, st_plugin_int *plugin,
+static my_bool xacommit_handlerton(THD *unused1, plugin_ref plugin,
void *arg)
{
- handlerton *hton= (handlerton *)plugin->data;
+ handlerton *hton= plugin_data(plugin, handlerton *);
if (hton->state == SHOW_OPTION_YES && hton->recover)
{
hton->commit_by_xid(hton, ((struct xahton_st *)arg)->xid);
@@ -898,10 +914,10 @@ static my_bool xacommit_handlerton(THD *unused1, st_plugin_int *plugin,
return FALSE;
}
-static my_bool xarollback_handlerton(THD *unused1, st_plugin_int *plugin,
+static my_bool xarollback_handlerton(THD *unused1, plugin_ref plugin,
void *arg)
{
- handlerton *hton= (handlerton *)plugin->data;
+ handlerton *hton= plugin_data(plugin, handlerton *);
if (hton->state == SHOW_OPTION_YES && hton->recover)
{
hton->rollback_by_xid(hton, ((struct xahton_st *)arg)->xid);
@@ -1004,10 +1020,10 @@ struct xarecover_st
bool dry_run;
};
-static my_bool xarecover_handlerton(THD *unused, st_plugin_int *plugin,
+static my_bool xarecover_handlerton(THD *unused, plugin_ref plugin,
void *arg)
{
- handlerton *hton= (handlerton *)plugin->data;
+ handlerton *hton= plugin_data(plugin, handlerton *);
struct xarecover_st *info= (struct xarecover_st *) arg;
int got;
@@ -1016,7 +1032,7 @@ static my_bool xarecover_handlerton(THD *unused, st_plugin_int *plugin,
while ((got= hton->recover(hton, info->list, info->len)) > 0 )
{
sql_print_information("Found %d prepared transaction(s) in %s",
- got, hton2plugin[hton->slot]->name.str);
+ got, ha_resolve_storage_engine_name(hton));
for (int i=0; i < got; i ++)
{
my_xid x=info->list[i].get_my_xid();
@@ -1192,10 +1208,10 @@ bool mysql_xa_recover(THD *thd)
thd: the thread handle of the current connection
return value: always 0
*/
-static my_bool release_temporary_latches(THD *thd, st_plugin_int *plugin,
+static my_bool release_temporary_latches(THD *thd, plugin_ref plugin,
void *unused)
{
- handlerton *hton= (handlerton *)plugin->data;
+ handlerton *hton= plugin_data(plugin, handlerton *);
if (hton->state == SHOW_OPTION_YES && hton->release_temporary_latches)
hton->release_temporary_latches(hton, thd);
@@ -1318,10 +1334,10 @@ int ha_release_savepoint(THD *thd, SAVEPOINT *sv)
}
-static my_bool snapshot_handlerton(THD *thd, st_plugin_int *plugin,
+static my_bool snapshot_handlerton(THD *thd, plugin_ref plugin,
void *arg)
{
- handlerton *hton= (handlerton *)plugin->data;
+ handlerton *hton= plugin_data(plugin, handlerton *);
if (hton->state == SHOW_OPTION_YES &&
hton->start_consistent_snapshot)
{
@@ -1349,10 +1365,10 @@ int ha_start_consistent_snapshot(THD *thd)
}
-static my_bool flush_handlerton(THD *thd, st_plugin_int *plugin,
+static my_bool flush_handlerton(THD *thd, plugin_ref plugin,
void *arg)
{
- handlerton *hton= (handlerton *)plugin->data;
+ handlerton *hton= plugin_data(plugin, handlerton *);
if (hton->state == SHOW_OPTION_YES && hton->flush_logs &&
hton->flush_logs(hton))
return TRUE;
@@ -1397,7 +1413,7 @@ int ha_delete_table(THD *thd, handlerton *table_type, const char *path,
/* DB_TYPE_UNKNOWN is used in ALTER TABLE when renaming only .frm files */
if (table_type == NULL ||
- ! (file=get_new_handler(&dummy_share, thd->mem_root, table_type)))
+ ! (file=get_new_handler((TABLE_SHARE*)0, thd->mem_root, table_type)))
DBUG_RETURN(ENOENT);
if (lower_case_table_names == 2 && !(file->ha_table_flags() & HA_FILE_BASED))
@@ -1438,6 +1454,8 @@ int ha_delete_table(THD *thd, handlerton *table_type, const char *path,
dummy_share.table_name.length= strlen(alias);
dummy_table.alias= alias;
+ file->table_share= &dummy_share;
+ file->table= &dummy_table;
file->print_error(error, 0);
strmake(new_error, thd->net.last_error, sizeof(buff)-1);
@@ -1458,7 +1476,7 @@ int ha_delete_table(THD *thd, handlerton *table_type, const char *path,
****************************************************************************/
handler *handler::clone(MEM_ROOT *mem_root)
{
- handler *new_handler= get_new_handler(table->s, mem_root, table->s->db_type);
+ handler *new_handler= get_new_handler(table->s, mem_root, table->s->db_type());
if (new_handler && !new_handler->ha_open(table,
table->s->normalized_path.str,
table->db_stat,
@@ -1474,6 +1492,17 @@ void handler::ha_statistic_increment(ulong SSV::*offset) const
statistic_increment(table->in_use->status_var.*offset, &LOCK_status);
}
+void **handler::ha_data(THD *thd) const
+{
+ return (void **) thd->ha_data + ht->slot;
+}
+
+THD *handler::ha_thd(void) const
+{
+ DBUG_ASSERT(!table || !table->in_use || table->in_use == current_thd);
+ return (table && table->in_use) ? table->in_use : current_thd;
+}
+
bool handler::check_if_log_table_locking_is_allowed(uint sql_command,
ulong type, TABLE *table)
@@ -1567,8 +1596,7 @@ int handler::read_first_row(uchar * buf, uint primary_key)
register int error;
DBUG_ENTER("handler::read_first_row");
- statistic_increment(table->in_use->status_var.ha_read_first_count,
- &LOCK_status);
+ ha_statistic_increment(&SSV::ha_read_first_count);
/*
If there is very few deleted rows in the table, find the first row by
@@ -2778,11 +2806,11 @@ struct st_discover_args
size_t *frmlen;
};
-static my_bool discover_handlerton(THD *thd, st_plugin_int *plugin,
+static my_bool discover_handlerton(THD *thd, plugin_ref plugin,
void *arg)
{
st_discover_args *vargs= (st_discover_args *)arg;
- handlerton *hton= (handlerton *)plugin->data;
+ handlerton *hton= plugin_data(plugin, handlerton *);
if (hton->state == SHOW_OPTION_YES && hton->discover &&
(!(hton->discover(hton, thd, vargs->db, vargs->name,
vargs->frmblob,
@@ -2827,11 +2855,11 @@ struct st_find_files_args
List<char> *files;
};
-static my_bool find_files_handlerton(THD *thd, st_plugin_int *plugin,
+static my_bool find_files_handlerton(THD *thd, plugin_ref plugin,
void *arg)
{
st_find_files_args *vargs= (st_find_files_args *)arg;
- handlerton *hton= (handlerton *)plugin->data;
+ handlerton *hton= plugin_data(plugin, handlerton *);
if (hton->state == SHOW_OPTION_YES && hton->find_files)
@@ -2858,45 +2886,50 @@ ha_find_files(THD *thd,const char *db,const char *path,
DBUG_RETURN(error);
}
-
-/** @brief
+/*
Ask handler if the table exists in engine
RETURN
- 0 Table does not exist
- 1 Table exists
- # Error code
+ HA_ERR_NO_SUCH_TABLE Table does not exist
+ HA_ERR_TABLE_EXIST Table exists
+ # Error code
+
+ */
-*/
struct st_table_exists_in_engine_args
{
const char *db;
const char *name;
+ int err;
};
-static my_bool table_exists_in_engine_handlerton(THD *thd, st_plugin_int *plugin,
+static my_bool table_exists_in_engine_handlerton(THD *thd, plugin_ref plugin,
void *arg)
{
st_table_exists_in_engine_args *vargs= (st_table_exists_in_engine_args *)arg;
- handlerton *hton= (handlerton *)plugin->data;
+ handlerton *hton= plugin_data(plugin, handlerton *);
+
+ int err= HA_ERR_NO_SUCH_TABLE;
if (hton->state == SHOW_OPTION_YES && hton->table_exists_in_engine)
- if ((hton->table_exists_in_engine(hton, thd, vargs->db, vargs->name)) == 1)
- return TRUE;
+ err = hton->table_exists_in_engine(hton, thd, vargs->db, vargs->name);
+
+ vargs->err = err;
+ if (vargs->err == HA_ERR_TABLE_EXIST)
+ return TRUE;
return FALSE;
}
int ha_table_exists_in_engine(THD* thd, const char* db, const char* name)
{
- int error= 0;
DBUG_ENTER("ha_table_exists_in_engine");
DBUG_PRINT("enter", ("db: %s, name: %s", db, name));
- st_table_exists_in_engine_args args= {db, name};
- error= plugin_foreach(thd, table_exists_in_engine_handlerton,
+ st_table_exists_in_engine_args args= {db, name, HA_ERR_NO_SUCH_TABLE};
+ plugin_foreach(thd, table_exists_in_engine_handlerton,
MYSQL_STORAGE_ENGINE_PLUGIN, &args);
- DBUG_PRINT("exit", ("error: %d", error));
- DBUG_RETURN(error);
+ DBUG_PRINT("exit", ("error: %d", args.err));
+ DBUG_RETURN(args.err);
}
#ifdef HAVE_NDB_BINLOG
@@ -2922,10 +2955,10 @@ struct binlog_func_st
/** @brief
Listing handlertons first to avoid recursive calls and deadlock
*/
-static my_bool binlog_func_list(THD *thd, st_plugin_int *plugin, void *arg)
+static my_bool binlog_func_list(THD *thd, plugin_ref plugin, void *arg)
{
hton_list_st *hton_list= (hton_list_st *)arg;
- handlerton *hton= (handlerton *)plugin->data;
+ handlerton *hton= plugin_data(plugin, handlerton *);
if (hton->state == SHOW_OPTION_YES && hton->binlog_func)
{
uint sz= hton_list->sz;
@@ -3012,10 +3045,10 @@ static my_bool binlog_log_query_handlerton2(THD *thd,
}
static my_bool binlog_log_query_handlerton(THD *thd,
- st_plugin_int *plugin,
+ plugin_ref plugin,
void *args)
{
- return binlog_log_query_handlerton2(thd, (handlerton *)plugin->data, args);
+ return binlog_log_query_handlerton2(thd, plugin_data(plugin, handlerton *), args);
}
void ha_binlog_log_query(THD *thd, handlerton *hton,
@@ -3307,11 +3340,11 @@ int handler::index_read_idx(uchar * buf, uint index, const uchar * key,
RETURN VALUE
pointer pointer to TYPELIB structure
*/
-static my_bool exts_handlerton(THD *unused, st_plugin_int *plugin,
+static my_bool exts_handlerton(THD *unused, plugin_ref plugin,
void *arg)
{
List<char> *found_exts= (List<char> *) arg;
- handlerton *hton= (handlerton *)plugin->data;
+ handlerton *hton= plugin_data(plugin, handlerton *);
handler *file;
if (hton->state == SHOW_OPTION_YES && hton->create &&
(file= hton->create(hton, (TABLE_SHARE*) 0, current_thd->mem_root)))
@@ -3382,11 +3415,11 @@ static bool stat_print(THD *thd, const char *type, uint type_len,
}
-static my_bool showstat_handlerton(THD *thd, st_plugin_int *plugin,
+static my_bool showstat_handlerton(THD *thd, plugin_ref plugin,
void *arg)
{
enum ha_stat_type stat= *(enum ha_stat_type *) arg;
- handlerton *hton= (handlerton *)plugin->data;
+ handlerton *hton= plugin_data(plugin, handlerton *);
if (hton->state == SHOW_OPTION_YES && hton->show_status &&
hton->show_status(hton, thd, stat_print, stat))
return TRUE;
diff --git a/sql/handler.h b/sql/handler.h
index ff0d5a362a5..fcf84f59af9 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -888,6 +888,8 @@ uint calculate_key_len(TABLE *, uint, const uchar *, key_part_map);
class handler :public Sql_alloc
{
friend class ha_partition;
+ friend int ha_delete_table(THD*,handlerton*,const char*,const char*,
+ const char*,bool);
protected:
struct st_table_share *table_share; /* The table definition */
@@ -906,7 +908,10 @@ class handler :public Sql_alloc
virtual int rnd_init(bool scan) =0;
virtual int rnd_end() { return 0; }
virtual ulonglong table_flags(void) const =0;
+
void ha_statistic_increment(ulong SSV::*offset) const;
+ void **ha_data(THD *) const;
+ THD *ha_thd(void) const;
ha_rows estimation_rows_to_insert;
virtual void start_bulk_insert(ha_rows rows) {}
@@ -963,11 +968,12 @@ public:
Discrete_interval auto_inc_interval_for_cur_row;
handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
- :table_share(share_arg), estimation_rows_to_insert(0), ht(ht_arg),
+ :table_share(share_arg), table(0),
+ estimation_rows_to_insert(0), ht(ht_arg),
ref(0), key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
ref_length(sizeof(my_off_t)),
ft_handler(0), inited(NONE), implicit_emptied(0),
- pushed_cond(NULL), next_insert_id(0), insert_id_for_cur_row(0)
+ pushed_cond(0), next_insert_id(0), insert_id_for_cur_row(0)
{}
virtual ~handler(void)
{
@@ -1570,6 +1576,10 @@ public:
/* lock_count() can be more than one if the table is a MERGE */
virtual uint lock_count(void) const { return 1; }
+ /*
+ NOTE that one can NOT rely on table->in_use in store_lock(). It may
+ refer to a different thread if called from mysql_lock_abort_for_thread().
+ */
virtual THR_LOCK_DATA **store_lock(THD *thd,
THR_LOCK_DATA **to,
enum thr_lock_type lock_type)=0;
@@ -1687,9 +1697,9 @@ extern ulong total_ha, total_ha_2pc;
/* lookups */
handlerton *ha_default_handlerton(THD *thd);
-handlerton *ha_resolve_by_name(THD *thd, const LEX_STRING *name);
+plugin_ref ha_resolve_by_name(THD *thd, const LEX_STRING *name);
+plugin_ref ha_lock_engine(THD *thd, handlerton *hton);
handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type);
-const char *ha_get_storage_engine(enum legacy_db_type db_type);
handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc,
handlerton *db_type);
handlerton *ha_checktype(THD *thd, enum legacy_db_type database_type,
diff --git a/sql/item.cc b/sql/item.cc
index 0371f5e891f..6f68ba37603 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -1058,6 +1058,7 @@ Item_splocal::Item_splocal(const LEX_STRING &sp_var_name,
maybe_null= TRUE;
m_type= sp_map_item_type(sp_var_type);
+ m_field_type= sp_var_type;
m_result_type= sp_map_result_type(sp_var_type);
}
@@ -3558,7 +3559,8 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
prev_subselect_item->const_item_cache= 0;
set_field(*from_field);
if (!last_checked_context->select_lex->having_fix_field &&
- select->group_list.elements)
+ select->group_list.elements &&
+ (place == SELECT_LIST || place == IN_HAVING))
{
Item_outer_ref *rf;
/*
@@ -4731,7 +4733,6 @@ inline uint char_val(char X)
Item_hex_string::Item_hex_string(const char *str, uint str_length)
{
- name=(char*) str-2; // Lex makes this start with 0x
max_length=(str_length+1)/2;
char *ptr=(char*) sql_alloc(max_length+1);
if (!ptr)
@@ -4842,7 +4843,6 @@ Item_bin_string::Item_bin_string(const char *str, uint str_length)
uchar bits= 0;
uint power= 1;
- name= (char*) str - 2;
max_length= (str_length + 7) >> 3;
char *ptr= (char*) sql_alloc(max_length + 1);
if (!ptr)
diff --git a/sql/item.h b/sql/item.h
index 24b7bbfa5bc..1c8b46fe0c7 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -1041,7 +1041,7 @@ class Item_splocal :public Item_sp_variable,
Type m_type;
Item_result m_result_type;
-
+ enum_field_types m_field_type;
public:
/*
Position of this reference to SP variable in the statement (the
@@ -1073,6 +1073,7 @@ public:
inline enum Type type() const;
inline Item_result result_type() const;
+ inline enum_field_types field_type() const { return m_field_type; }
private:
bool set_value(THD *thd, sp_rcontext *ctx, Item **it);
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 2d61b6f1f9f..36342151f4a 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -690,7 +690,13 @@ Arg_comparator::can_compare_as_dates(Item *a, Item *b, ulonglong *const_value)
if (cmp_type != CMP_DATE_DFLT)
{
- if (cmp_type != CMP_DATE_WITH_DATE && str_arg->const_item())
+ /*
+ Do not cache GET_USER_VAR() function as its const_item() may return TRUE
+ for the current thread but it still may change during the execution.
+ */
+ if (cmp_type != CMP_DATE_WITH_DATE && str_arg->const_item() &&
+ (str_arg->type() != Item::FUNC_ITEM ||
+ ((Item_func*)str_arg)->functype() != Item_func::GUSERVAR_FUNC))
{
THD *thd= current_thd;
ulonglong value;
@@ -718,7 +724,7 @@ int Arg_comparator::set_cmp_func(Item_bool_func2 *owner_arg,
Item_result type)
{
enum enum_date_cmp_type cmp_type;
- ulonglong const_value;
+ ulonglong const_value= (ulonglong)-1;
a= a1;
b= a2;
@@ -731,8 +737,7 @@ int Arg_comparator::set_cmp_func(Item_bool_func2 *owner_arg,
a_cache= 0;
b_cache= 0;
- if (cmp_type != CMP_DATE_WITH_DATE &&
- ((*b)->const_item() || (*a)->const_item()))
+ if (const_value != (ulonglong)-1)
{
Item_cache_int *cache= new Item_cache_int();
/* Mark the cache as non-const to prevent re-caching. */
@@ -802,7 +807,7 @@ void Arg_comparator::set_datetime_cmp_func(Item **a1, Item **b1)
obtained value
*/
-static ulonglong
+ulonglong
get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
Item *warn_item, bool *is_null)
{
@@ -838,7 +843,12 @@ get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
MYSQL_TYPE_DATE ? MYSQL_TIMESTAMP_DATE : MYSQL_TIMESTAMP_DATETIME;
value= get_date_from_str(thd, str, t_type, warn_item->name, &error);
}
- if (item->const_item())
+ /*
+ Do not cache GET_USER_VAR() function as its const_item() may return TRUE
+ for the current thread but it still may change during the execution.
+ */
+ if (item->const_item() && cache_arg && (item->type() != Item::FUNC_ITEM ||
+ ((Item_func*)item)->functype() != Item_func::GUSERVAR_FUNC))
{
Item_cache_int *cache= new Item_cache_int();
/* Mark the cache as non-const to prevent re-caching. */
@@ -2830,7 +2840,6 @@ in_row::in_row(uint elements, Item * item)
base= (char*) new cmp_item_row[count= elements];
size= sizeof(cmp_item_row);
compare= (qsort2_cmp) cmp_row;
- tmp.store_value(item);
/*
We need to reset these as otherwise we will call sort() with
uninitialized (even if not used) elements
@@ -2882,6 +2891,27 @@ uchar *in_longlong::get_value(Item *item)
return (uchar*) &tmp;
}
+void in_datetime::set(uint pos,Item *item)
+{
+ Item **tmp= &item;
+ bool is_null;
+ struct packed_longlong *buff= &((packed_longlong*) base)[pos];
+
+ buff->val= get_datetime_value(thd, &tmp, 0, warn_item, &is_null);
+ buff->unsigned_flag= 1L;
+}
+
+byte *in_datetime::get_value(Item *item)
+{
+ bool is_null;
+ Item **tmp_item= lval_cache ? &lval_cache : &item;
+ tmp.val= get_datetime_value(thd, &tmp_item, &lval_cache, warn_item, &is_null);
+ if (item->null_value)
+ return 0;
+ tmp.unsigned_flag= 1L;
+ return (byte*) &tmp;
+}
+
in_double::in_double(uint elements)
:in_vector(elements,sizeof(double),(qsort2_cmp) cmp_double, 0)
{}
@@ -2986,12 +3016,18 @@ cmp_item_row::~cmp_item_row()
}
+void cmp_item_row::alloc_comparators()
+{
+ if (!comparators)
+ comparators= (cmp_item **) current_thd->calloc(sizeof(cmp_item *)*n);
+}
+
+
void cmp_item_row::store_value(Item *item)
{
DBUG_ENTER("cmp_item_row::store_value");
n= item->cols();
- if (!comparators)
- comparators= (cmp_item **) current_thd->calloc(sizeof(cmp_item *)*n);
+ alloc_comparators();
if (comparators)
{
item->bring_value();
@@ -3103,6 +3139,36 @@ cmp_item* cmp_item_decimal::make_same()
}
+void cmp_item_datetime::store_value(Item *item)
+{
+ bool is_null;
+ Item **tmp_item= lval_cache ? &lval_cache : &item;
+ value= get_datetime_value(thd, &tmp_item, &lval_cache, warn_item, &is_null);
+}
+
+
+int cmp_item_datetime::cmp(Item *arg)
+{
+ bool is_null;
+ Item **tmp_item= &arg;
+ return value !=
+ get_datetime_value(thd, &tmp_item, 0, warn_item, &is_null);
+}
+
+
+int cmp_item_datetime::compare(cmp_item *ci)
+{
+ cmp_item_datetime *l_cmp= (cmp_item_datetime *)ci;
+ return (value < l_cmp->value) ? -1 : ((value == l_cmp->value) ? 0 : 1);
+}
+
+
+cmp_item *cmp_item_datetime::make_same()
+{
+ return new cmp_item_datetime(warn_item);
+}
+
+
bool Item_func_in::nulls_in_row()
{
Item **arg,**arg_end;
@@ -3178,6 +3244,10 @@ void Item_func_in::fix_length_and_dec()
Item **arg, **arg_end;
bool const_itm= 1;
THD *thd= current_thd;
+ bool datetime_found= FALSE;
+ /* TRUE <=> arguments values will be compared as DATETIMEs. */
+ bool compare_as_datetime= FALSE;
+ Item *date_arg= 0;
uint found_types= 0;
uint type_cnt= 0, i;
Item_result cmp_type= STRING_RESULT;
@@ -3209,58 +3279,151 @@ void Item_func_in::fix_length_and_dec()
return;
arg_types_compatible= TRUE;
}
+ if (type_cnt == 1)
+ {
+ /*
+ When comparing rows create the row comparator object beforehand to ease
+ the DATETIME comparison detection procedure.
+ */
+ if (cmp_type == ROW_RESULT)
+ {
+ cmp_item_row *cmp= 0;
+ if (const_itm && !nulls_in_row())
+ {
+ array= new in_row(arg_count-1, 0);
+ cmp= &((in_row*)array)->tmp;
+ }
+ else
+ {
+ if (!(cmp= new cmp_item_row))
+ return;
+ cmp_items[ROW_RESULT]= cmp;
+ }
+ cmp->n= args[0]->cols();
+ cmp->alloc_comparators();
+ }
+ /* All DATE/DATETIME fields/functions has the STRING result type. */
+ if (cmp_type == STRING_RESULT || cmp_type == ROW_RESULT)
+ {
+ uint col, cols= args[0]->cols();
+ for (col= 0; col < cols; col++)
+ {
+ bool skip_column= FALSE;
+ /*
+ Check that all items to be compared has the STRING result type and at
+ least one of them is a DATE/DATETIME item.
+ */
+ for (arg= args, arg_end= args + arg_count; arg != arg_end ; arg++)
+ {
+ Item *itm= ((cmp_type == STRING_RESULT) ? arg[0] :
+ arg[0]->element_index(col));
+ if (itm->result_type() != STRING_RESULT)
+ {
+ skip_column= TRUE;
+ break;
+ }
+ else if (itm->is_datetime())
+ {
+ datetime_found= TRUE;
+ /*
+ Internally all DATE/DATETIME values are converted to the DATETIME
+ type. So try to find a DATETIME item to issue correct warnings.
+ */
+ if (!date_arg)
+ date_arg= itm;
+ else if (itm->field_type() == MYSQL_TYPE_DATETIME)
+ {
+ date_arg= itm;
+ /* All arguments are already checked to have the STRING result. */
+ if (cmp_type == STRING_RESULT)
+ break;
+ }
+ }
+ }
+ if (skip_column)
+ continue;
+ if (datetime_found)
+ {
+ if (cmp_type == ROW_RESULT)
+ {
+ cmp_item **cmp= 0;
+ if (array)
+ cmp= ((in_row*)array)->tmp.comparators + col;
+ else
+ cmp= ((cmp_item_row*)cmp_items[ROW_RESULT])->comparators + col;
+ *cmp= new cmp_item_datetime(date_arg);
+ /* Reset variables for the next column. */
+ date_arg= 0;
+ datetime_found= FALSE;
+ }
+ else
+ compare_as_datetime= TRUE;
+ }
+ }
+ }
+ }
/*
Row item with NULLs inside can return NULL or FALSE =>
they can't be processed as static
*/
if (type_cnt == 1 && const_itm && !nulls_in_row())
{
- /*
- IN must compare INT/DATE/DATETIME/TIMESTAMP columns and constants
- as int values (the same way as equality does).
- So we must check here if the column on the left and all the constant
- values on the right can be compared as integers and adjust the
- comparison type accordingly.
- */
- if (args[0]->real_item()->type() == FIELD_ITEM &&
- thd->lex->sql_command != SQLCOM_CREATE_VIEW &&
- thd->lex->sql_command != SQLCOM_SHOW_CREATE &&
- cmp_type != INT_RESULT)
+ if (compare_as_datetime)
+ array= new in_datetime(date_arg, arg_count - 1);
+ else
{
- Field *field= ((Item_field*) (args[0]->real_item()))->field;
- if (field->can_be_compared_as_longlong())
+ /*
+ IN must compare INT columns and constants as int values (the same
+ way as equality does).
+ So we must check here if the column on the left and all the constant
+ values on the right can be compared as integers and adjust the
+ comparison type accordingly.
+ */
+ if (args[0]->real_item()->type() == FIELD_ITEM &&
+ thd->lex->sql_command != SQLCOM_CREATE_VIEW &&
+ thd->lex->sql_command != SQLCOM_SHOW_CREATE &&
+ cmp_type != INT_RESULT)
{
- bool all_converted= TRUE;
- for (arg=args+1, arg_end=args+arg_count; arg != arg_end ; arg++)
+ Field *field= ((Item_field*) (args[0]->real_item()))->field;
+ if (field->can_be_compared_as_longlong())
{
- if (!convert_constant_item (thd, field, &arg[0]))
- all_converted= FALSE;
+ bool all_converted= TRUE;
+ for (arg=args+1, arg_end=args+arg_count; arg != arg_end ; arg++)
+ {
+ if (!convert_constant_item (thd, field, &arg[0]))
+ all_converted= FALSE;
+ }
+ if (all_converted)
+ cmp_type= INT_RESULT;
}
- if (all_converted)
- cmp_type= INT_RESULT;
}
- }
- switch (cmp_type) {
- case STRING_RESULT:
- array=new in_string(arg_count - 1,(qsort2_cmp) srtcmp_in,
- cmp_collation.collation);
- break;
- case INT_RESULT:
- array= new in_longlong(arg_count - 1);
- break;
- case REAL_RESULT:
- array= new in_double(arg_count - 1);
- break;
- case ROW_RESULT:
- array= new in_row(arg_count - 1, args[0]);
- break;
- case DECIMAL_RESULT:
- array= new in_decimal(arg_count - 1);
- break;
- default:
- DBUG_ASSERT(0);
- return;
+ switch (cmp_type) {
+ case STRING_RESULT:
+ array=new in_string(arg_count-1,(qsort2_cmp) srtcmp_in,
+ cmp_collation.collation);
+ break;
+ case INT_RESULT:
+ array= new in_longlong(arg_count-1);
+ break;
+ case REAL_RESULT:
+ array= new in_double(arg_count-1);
+ break;
+ case ROW_RESULT:
+ /*
+ The row comparator was created at the beginning but only DATETIME
+ items comparators were initialized. Call store_value() to setup
+ others.
+ */
+ ((in_row*)array)->tmp.store_value(args[0]);
+ break;
+ case DECIMAL_RESULT:
+ array= new in_decimal(arg_count - 1);
+ break;
+ default:
+ DBUG_ASSERT(0);
+ return;
+ }
}
if (array && !(thd->is_fatal_error)) // If not EOM
{
@@ -3279,17 +3442,23 @@ void Item_func_in::fix_length_and_dec()
}
else
{
- for (i= 0; i <= (uint) DECIMAL_RESULT; i++)
+ if (compare_as_datetime)
+ cmp_items[STRING_RESULT]= new cmp_item_datetime(date_arg);
+ else
{
- if (found_types & (1 << i) && !cmp_items[i])
+ for (i= 0; i <= (uint) DECIMAL_RESULT; i++)
{
- if ((Item_result)i == STRING_RESULT &&
- agg_arg_charsets(cmp_collation, args, arg_count, MY_COLL_CMP_CONV, 1))
- return;
- if (!(cmp_items[i]=
- cmp_item::get_comparator((Item_result)i,
- cmp_collation.collation)))
- return;
+ if (found_types & (1 << i) && !cmp_items[i])
+ {
+ if ((Item_result)i == STRING_RESULT &&
+ agg_arg_charsets(cmp_collation, args, arg_count,
+ MY_COLL_CMP_CONV, 1))
+ return;
+ if (!cmp_items[i] && !(cmp_items[i]=
+ cmp_item::get_comparator((Item_result)i,
+ cmp_collation.collation)))
+ return;
+ }
}
}
}
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index 15ddab8b32e..de6c20420c3 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -798,6 +798,7 @@ public:
class in_longlong :public in_vector
{
+protected:
/*
Here we declare a temporary variable (tmp) of the same type as the
elements of this vector. tmp is used in finding if a given value is in
@@ -832,6 +833,30 @@ public:
friend int cmp_longlong(void *cmp_arg, packed_longlong *a,packed_longlong *b);
};
+
+/*
+ Class to represent a vector of constant DATE/DATETIME values.
+ Values are obtained with help of the get_datetime_value() function.
+ If the left item is a constant one then its value is cached in the
+ lval_cache variable.
+*/
+class in_datetime :public in_longlong
+{
+public:
+ THD *thd;
+ /* An item used to issue warnings. */
+ Item *warn_item;
+ /* Cache for the left item. */
+ Item *lval_cache;
+
+ in_datetime(Item *warn_item_arg, uint elements)
+ :in_longlong(elements), thd(current_thd), warn_item(warn_item_arg),
+ lval_cache(0) {};
+ void set(uint pos,Item *item);
+ byte *get_value(Item *item);
+ friend int cmp_longlong(void *cmp_arg, packed_longlong *a,packed_longlong *b);
+};
+
class in_double :public in_vector
{
double tmp;
@@ -964,6 +989,30 @@ public:
cmp_item *make_same();
};
+/*
+ Compare items in the DATETIME context.
+ Values are obtained with help of the get_datetime_value() function.
+ If the left item is a constant one then its value is cached in the
+ lval_cache variable.
+*/
+class cmp_item_datetime :public cmp_item
+{
+ ulonglong value;
+public:
+ THD *thd;
+ /* Item used for issuing warnings. */
+ Item *warn_item;
+ /* Cache for the left item. */
+ Item *lval_cache;
+
+ cmp_item_datetime(Item *warn_item_arg)
+ :thd(current_thd), warn_item(warn_item_arg), lval_cache(0) {}
+ void store_value(Item *item);
+ int cmp(Item *arg);
+ int compare(cmp_item *ci);
+ cmp_item *make_same();
+};
+
class cmp_item_real :public cmp_item
{
double value;
@@ -998,32 +1047,6 @@ public:
};
-class cmp_item_row :public cmp_item
-{
- cmp_item **comparators;
- uint n;
-public:
- cmp_item_row(): comparators(0), n(0) {}
- ~cmp_item_row();
- void store_value(Item *item);
- int cmp(Item *arg);
- int compare(cmp_item *arg);
- cmp_item *make_same();
- void store_value_by_template(cmp_item *tmpl, Item *);
-};
-
-
-class in_row :public in_vector
-{
- cmp_item_row tmp;
-public:
- in_row(uint elements, Item *);
- ~in_row();
- void set(uint pos,Item *item);
- uchar *get_value(Item *item);
- Item_result result_type() { return ROW_RESULT; }
-};
-
/*
cmp_item for optimized IN with row (right part string, which never
be changed)
@@ -1163,7 +1186,7 @@ public:
*/
bool arg_types_compatible;
Item_result left_result_type;
- cmp_item *cmp_items[5]; /* One cmp_item for each result type */
+ cmp_item *cmp_items[6]; /* One cmp_item for each result type */
DTCollation cmp_collation;
Item_func_in(List<Item> &list)
@@ -1184,7 +1207,7 @@ public:
Item_int_func::cleanup();
delete array;
array= 0;
- for (i= 0; i <= (uint)DECIMAL_RESULT; i++)
+ for (i= 0; i <= (uint)DECIMAL_RESULT + 1; i++)
{
delete cmp_items[i];
cmp_items[i]= 0;
@@ -1202,6 +1225,32 @@ public:
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
};
+class cmp_item_row :public cmp_item
+{
+ cmp_item **comparators;
+ uint n;
+public:
+ cmp_item_row(): comparators(0), n(0) {}
+ ~cmp_item_row();
+ void store_value(Item *item);
+ int cmp(Item *arg);
+ int compare(cmp_item *arg);
+ cmp_item *make_same();
+ void store_value_by_template(cmp_item *tmpl, Item *);
+};
+
+
+class in_row :public in_vector
+{
+ cmp_item_row tmp;
+public:
+ in_row(uint elements, Item *);
+ ~in_row();
+ void set(uint pos,Item *item);
+ uchar *get_value(Item *item);
+ Item_result result_type() { return ROW_RESULT; }
+};
+
/* Functions used by where clause */
class Item_func_isnull :public Item_bool_func
diff --git a/sql/item_create.cc b/sql/item_create.cc
index 4687a3c647b..19a7a8b6d3f 100644
--- a/sql/item_create.cc
+++ b/sql/item_create.cc
@@ -3929,6 +3929,7 @@ Create_func_master_pos_wait Create_func_master_pos_wait::s_singleton;
Item*
Create_func_master_pos_wait::create_native(THD *thd, LEX_STRING name,
List<Item> *item_list)
+
{
Item *func= NULL;
int arg_count= 0;
@@ -4704,204 +4705,204 @@ struct Native_func_registry
static Native_func_registry func_array[] =
{
- { C_STRING_WITH_LEN("ABS"), BUILDER(Create_func_abs)},
- { C_STRING_WITH_LEN("ACOS"), BUILDER(Create_func_acos)},
- { C_STRING_WITH_LEN("ADDTIME"), BUILDER(Create_func_addtime)},
- { C_STRING_WITH_LEN("AES_DECRYPT"), BUILDER(Create_func_aes_decrypt)},
- { C_STRING_WITH_LEN("AES_ENCRYPT"), BUILDER(Create_func_aes_encrypt)},
- { C_STRING_WITH_LEN("AREA"), GEOM_BUILDER(Create_func_area)},
- { C_STRING_WITH_LEN("ASBINARY"), GEOM_BUILDER(Create_func_as_wkb)},
- { C_STRING_WITH_LEN("ASIN"), BUILDER(Create_func_asin)},
- { C_STRING_WITH_LEN("ASTEXT"), GEOM_BUILDER(Create_func_as_wkt)},
- { C_STRING_WITH_LEN("ASWKB"), GEOM_BUILDER(Create_func_as_wkb)},
- { C_STRING_WITH_LEN("ASWKT"), GEOM_BUILDER(Create_func_as_wkt)},
- { C_STRING_WITH_LEN("ATAN"), BUILDER(Create_func_atan)},
- { C_STRING_WITH_LEN("ATAN2"), BUILDER(Create_func_atan)},
- { C_STRING_WITH_LEN("BENCHMARK"), BUILDER(Create_func_benchmark)},
- { C_STRING_WITH_LEN("BIN"), BUILDER(Create_func_bin)},
- { C_STRING_WITH_LEN("BIT_COUNT"), BUILDER(Create_func_bit_count)},
- { C_STRING_WITH_LEN("BIT_LENGTH"), BUILDER(Create_func_bit_length)},
- { C_STRING_WITH_LEN("CEIL"), BUILDER(Create_func_ceiling)},
- { C_STRING_WITH_LEN("CEILING"), BUILDER(Create_func_ceiling)},
- { C_STRING_WITH_LEN("CENTROID"), GEOM_BUILDER(Create_func_centroid)},
- { C_STRING_WITH_LEN("CHARACTER_LENGTH"), BUILDER(Create_func_char_length)},
- { C_STRING_WITH_LEN("CHAR_LENGTH"), BUILDER(Create_func_char_length)},
- { C_STRING_WITH_LEN("COERCIBILITY"), BUILDER(Create_func_coercibility)},
- { C_STRING_WITH_LEN("COMPRESS"), BUILDER(Create_func_compress)},
- { C_STRING_WITH_LEN("CONCAT"), BUILDER(Create_func_concat)},
- { C_STRING_WITH_LEN("CONCAT_WS"), BUILDER(Create_func_concat_ws)},
- { C_STRING_WITH_LEN("CONNECTION_ID"), BUILDER(Create_func_connection_id)},
- { C_STRING_WITH_LEN("CONV"), BUILDER(Create_func_conv)},
- { C_STRING_WITH_LEN("CONVERT_TZ"), BUILDER(Create_func_convert_tz)},
- { C_STRING_WITH_LEN("COS"), BUILDER(Create_func_cos)},
- { C_STRING_WITH_LEN("COT"), BUILDER(Create_func_cot)},
- { C_STRING_WITH_LEN("CRC32"), BUILDER(Create_func_crc32)},
- { C_STRING_WITH_LEN("CROSSES"), GEOM_BUILDER(Create_func_crosses)},
- { C_STRING_WITH_LEN("DATEDIFF"), BUILDER(Create_func_datediff)},
- { C_STRING_WITH_LEN("DATE_FORMAT"), BUILDER(Create_func_date_format)},
- { C_STRING_WITH_LEN("DAYNAME"), BUILDER(Create_func_dayname)},
- { C_STRING_WITH_LEN("DAYOFMONTH"), BUILDER(Create_func_dayofmonth)},
- { C_STRING_WITH_LEN("DAYOFWEEK"), BUILDER(Create_func_dayofweek)},
- { C_STRING_WITH_LEN("DAYOFYEAR"), BUILDER(Create_func_dayofyear)},
- { C_STRING_WITH_LEN("DECODE"), BUILDER(Create_func_decode)},
- { C_STRING_WITH_LEN("DEGREES"), BUILDER(Create_func_degrees)},
- { C_STRING_WITH_LEN("DES_DECRYPT"), BUILDER(Create_func_des_decrypt)},
- { C_STRING_WITH_LEN("DES_ENCRYPT"), BUILDER(Create_func_des_encrypt)},
- { C_STRING_WITH_LEN("DIMENSION"), GEOM_BUILDER(Create_func_dimension)},
- { C_STRING_WITH_LEN("DISJOINT"), GEOM_BUILDER(Create_func_disjoint)},
- { C_STRING_WITH_LEN("ELT"), BUILDER(Create_func_elt)},
- { C_STRING_WITH_LEN("ENCODE"), BUILDER(Create_func_encode)},
- { C_STRING_WITH_LEN("ENCRYPT"), BUILDER(Create_func_encrypt)},
- { C_STRING_WITH_LEN("ENDPOINT"), GEOM_BUILDER(Create_func_endpoint)},
- { C_STRING_WITH_LEN("ENVELOPE"), GEOM_BUILDER(Create_func_envelope)},
- { C_STRING_WITH_LEN("EQUALS"), GEOM_BUILDER(Create_func_equals)},
- { C_STRING_WITH_LEN("EXP"), BUILDER(Create_func_exp)},
- { C_STRING_WITH_LEN("EXPORT_SET"), BUILDER(Create_func_export_set)},
- { C_STRING_WITH_LEN("EXTERIORRING"), GEOM_BUILDER(Create_func_exteriorring)},
- { C_STRING_WITH_LEN("EXTRACTVALUE"), BUILDER(Create_func_xml_extractvalue)},
- { C_STRING_WITH_LEN("FIELD"), BUILDER(Create_func_field)},
- { C_STRING_WITH_LEN("FIND_IN_SET"), BUILDER(Create_func_find_in_set)},
- { C_STRING_WITH_LEN("FLOOR"), BUILDER(Create_func_floor)},
- { C_STRING_WITH_LEN("FORMAT"), BUILDER(Create_func_format)},
- { C_STRING_WITH_LEN("FOUND_ROWS"), BUILDER(Create_func_found_rows)},
- { C_STRING_WITH_LEN("FROM_DAYS"), BUILDER(Create_func_from_days)},
- { C_STRING_WITH_LEN("FROM_UNIXTIME"), BUILDER(Create_func_from_unixtime)},
- { C_STRING_WITH_LEN("GEOMCOLLFROMTEXT"), GEOM_BUILDER(Create_func_geometry_from_text)},
- { C_STRING_WITH_LEN("GEOMCOLLFROMWKB"), GEOM_BUILDER(Create_func_geometry_from_wkb)},
- { C_STRING_WITH_LEN("GEOMETRYCOLLECTIONFROMTEXT"), GEOM_BUILDER(Create_func_geometry_from_text)},
- { C_STRING_WITH_LEN("GEOMETRYCOLLECTIONFROMWKB"), GEOM_BUILDER(Create_func_geometry_from_wkb)},
- { C_STRING_WITH_LEN("GEOMETRYFROMTEXT"), GEOM_BUILDER(Create_func_geometry_from_text)},
- { C_STRING_WITH_LEN("GEOMETRYFROMWKB"), GEOM_BUILDER(Create_func_geometry_from_wkb)},
- { C_STRING_WITH_LEN("GEOMETRYN"), GEOM_BUILDER(Create_func_geometryn)},
- { C_STRING_WITH_LEN("GEOMETRYTYPE"), GEOM_BUILDER(Create_func_geometry_type)},
- { C_STRING_WITH_LEN("GEOMFROMTEXT"), GEOM_BUILDER(Create_func_geometry_from_text)},
- { C_STRING_WITH_LEN("GEOMFROMWKB"), GEOM_BUILDER(Create_func_geometry_from_wkb)},
- { C_STRING_WITH_LEN("GET_LOCK"), BUILDER(Create_func_get_lock)},
- { C_STRING_WITH_LEN("GLENGTH"), GEOM_BUILDER(Create_func_glength)},
- { C_STRING_WITH_LEN("GREATEST"), BUILDER(Create_func_greatest)},
- { C_STRING_WITH_LEN("HEX"), BUILDER(Create_func_hex)},
- { C_STRING_WITH_LEN("IFNULL"), BUILDER(Create_func_ifnull)},
- { C_STRING_WITH_LEN("INET_ATON"), BUILDER(Create_func_inet_aton)},
- { C_STRING_WITH_LEN("INET_NTOA"), BUILDER(Create_func_inet_ntoa)},
- { C_STRING_WITH_LEN("INSTR"), BUILDER(Create_func_instr)},
- { C_STRING_WITH_LEN("INTERIORRINGN"), GEOM_BUILDER(Create_func_interiorringn)},
- { C_STRING_WITH_LEN("INTERSECTS"), GEOM_BUILDER(Create_func_intersects)},
- { C_STRING_WITH_LEN("ISCLOSED"), GEOM_BUILDER(Create_func_isclosed)},
- { C_STRING_WITH_LEN("ISEMPTY"), GEOM_BUILDER(Create_func_isempty)},
- { C_STRING_WITH_LEN("ISNULL"), BUILDER(Create_func_isnull)},
- { C_STRING_WITH_LEN("ISSIMPLE"), GEOM_BUILDER(Create_func_issimple)},
- { C_STRING_WITH_LEN("IS_FREE_LOCK"), BUILDER(Create_func_is_free_lock)},
- { C_STRING_WITH_LEN("IS_USED_LOCK"), BUILDER(Create_func_is_used_lock)},
- { C_STRING_WITH_LEN("LAST_DAY"), BUILDER(Create_func_last_day)},
- { C_STRING_WITH_LEN("LAST_INSERT_ID"), BUILDER(Create_func_last_insert_id)},
- { C_STRING_WITH_LEN("LCASE"), BUILDER(Create_func_lcase)},
- { C_STRING_WITH_LEN("LEAST"), BUILDER(Create_func_least)},
- { C_STRING_WITH_LEN("LENGTH"), BUILDER(Create_func_length)},
- { C_STRING_WITH_LEN("LINEFROMTEXT"), GEOM_BUILDER(Create_func_geometry_from_text)},
- { C_STRING_WITH_LEN("LINEFROMWKB"), GEOM_BUILDER(Create_func_geometry_from_wkb)},
- { C_STRING_WITH_LEN("LINESTRINGFROMTEXT"), GEOM_BUILDER(Create_func_geometry_from_text)},
- { C_STRING_WITH_LEN("LINESTRINGFROMWKB"), GEOM_BUILDER(Create_func_geometry_from_wkb)},
- { C_STRING_WITH_LEN("LN"), BUILDER(Create_func_ln)},
- { C_STRING_WITH_LEN("LOAD_FILE"), BUILDER(Create_func_load_file)},
- { C_STRING_WITH_LEN("LOCATE"), BUILDER(Create_func_locate)},
- { C_STRING_WITH_LEN("LOG"), BUILDER(Create_func_log)},
- { C_STRING_WITH_LEN("LOG10"), BUILDER(Create_func_log10)},
- { C_STRING_WITH_LEN("LOG2"), BUILDER(Create_func_log2)},
- { C_STRING_WITH_LEN("LOWER"), BUILDER(Create_func_lcase)},
- { C_STRING_WITH_LEN("LPAD"), BUILDER(Create_func_lpad)},
- { C_STRING_WITH_LEN("LTRIM"), BUILDER(Create_func_ltrim)},
- { C_STRING_WITH_LEN("MAKEDATE"), BUILDER(Create_func_makedate)},
- { C_STRING_WITH_LEN("MAKETIME"), BUILDER(Create_func_maketime)},
- { C_STRING_WITH_LEN("MAKE_SET"), BUILDER(Create_func_make_set)},
- { C_STRING_WITH_LEN("MASTER_POS_WAIT"), BUILDER(Create_func_master_pos_wait)},
- { C_STRING_WITH_LEN("MBRCONTAINS"), GEOM_BUILDER(Create_func_contains)},
- { C_STRING_WITH_LEN("MBRDISJOINT"), GEOM_BUILDER(Create_func_disjoint)},
- { C_STRING_WITH_LEN("MBREQUAL"), GEOM_BUILDER(Create_func_equals)},
- { C_STRING_WITH_LEN("MBRINTERSECTS"), GEOM_BUILDER(Create_func_intersects)},
- { C_STRING_WITH_LEN("MBROVERLAPS"), GEOM_BUILDER(Create_func_overlaps)},
- { C_STRING_WITH_LEN("MBRTOUCHES"), GEOM_BUILDER(Create_func_touches)},
- { C_STRING_WITH_LEN("MBRWITHIN"), GEOM_BUILDER(Create_func_within)},
- { C_STRING_WITH_LEN("MD5"), BUILDER(Create_func_md5)},
- { C_STRING_WITH_LEN("MLINEFROMTEXT"), GEOM_BUILDER(Create_func_geometry_from_text)},
- { C_STRING_WITH_LEN("MLINEFROMWKB"), GEOM_BUILDER(Create_func_geometry_from_wkb)},
- { C_STRING_WITH_LEN("MONTHNAME"), BUILDER(Create_func_monthname)},
- { C_STRING_WITH_LEN("MPOINTFROMTEXT"), GEOM_BUILDER(Create_func_geometry_from_text)},
- { C_STRING_WITH_LEN("MPOINTFROMWKB"), GEOM_BUILDER(Create_func_geometry_from_wkb)},
- { C_STRING_WITH_LEN("MPOLYFROMTEXT"), GEOM_BUILDER(Create_func_geometry_from_text)},
- { C_STRING_WITH_LEN("MPOLYFROMWKB"), GEOM_BUILDER(Create_func_geometry_from_wkb)},
- { C_STRING_WITH_LEN("MULTILINESTRINGFROMTEXT"), GEOM_BUILDER(Create_func_geometry_from_text)},
- { C_STRING_WITH_LEN("MULTILINESTRINGFROMWKB"), GEOM_BUILDER(Create_func_geometry_from_wkb)},
- { C_STRING_WITH_LEN("MULTIPOINTFROMTEXT"), GEOM_BUILDER(Create_func_geometry_from_text)},
- { C_STRING_WITH_LEN("MULTIPOINTFROMWKB"), GEOM_BUILDER(Create_func_geometry_from_wkb)},
- { C_STRING_WITH_LEN("MULTIPOLYGONFROMTEXT"), GEOM_BUILDER(Create_func_geometry_from_text)},
- { C_STRING_WITH_LEN("MULTIPOLYGONFROMWKB"), GEOM_BUILDER(Create_func_geometry_from_wkb)},
- { C_STRING_WITH_LEN("NAME_CONST"), BUILDER(Create_func_name_const)},
- { C_STRING_WITH_LEN("NULLIF"), BUILDER(Create_func_nullif)},
- { C_STRING_WITH_LEN("NUMGEOMETRIES"), GEOM_BUILDER(Create_func_numgeometries)},
- { C_STRING_WITH_LEN("NUMINTERIORRINGS"), GEOM_BUILDER(Create_func_numinteriorring)},
- { C_STRING_WITH_LEN("NUMPOINTS"), GEOM_BUILDER(Create_func_numpoints)},
- { C_STRING_WITH_LEN("OCT"), BUILDER(Create_func_oct)},
- { C_STRING_WITH_LEN("OCTET_LENGTH"), BUILDER(Create_func_length)},
- { C_STRING_WITH_LEN("ORD"), BUILDER(Create_func_ord)},
- { C_STRING_WITH_LEN("OVERLAPS"), GEOM_BUILDER(Create_func_overlaps)},
- { C_STRING_WITH_LEN("PERIOD_ADD"), BUILDER(Create_func_period_add)},
- { C_STRING_WITH_LEN("PERIOD_DIFF"), BUILDER(Create_func_period_diff)},
- { C_STRING_WITH_LEN("PI"), BUILDER(Create_func_pi)},
- { C_STRING_WITH_LEN("POINTFROMTEXT"), GEOM_BUILDER(Create_func_geometry_from_text)},
- { C_STRING_WITH_LEN("POINTFROMWKB"), GEOM_BUILDER(Create_func_geometry_from_wkb)},
- { C_STRING_WITH_LEN("POINTN"), GEOM_BUILDER(Create_func_pointn)},
- { C_STRING_WITH_LEN("POLYFROMTEXT"), GEOM_BUILDER(Create_func_geometry_from_text)},
- { C_STRING_WITH_LEN("POLYFROMWKB"), GEOM_BUILDER(Create_func_geometry_from_wkb)},
- { C_STRING_WITH_LEN("POLYGONFROMTEXT"), GEOM_BUILDER(Create_func_geometry_from_text)},
- { C_STRING_WITH_LEN("POLYGONFROMWKB"), GEOM_BUILDER(Create_func_geometry_from_wkb)},
- { C_STRING_WITH_LEN("POW"), BUILDER(Create_func_pow)},
- { C_STRING_WITH_LEN("POWER"), BUILDER(Create_func_pow)},
- { C_STRING_WITH_LEN("QUOTE"), BUILDER(Create_func_quote)},
- { C_STRING_WITH_LEN("RADIANS"), BUILDER(Create_func_radians)},
- { C_STRING_WITH_LEN("RAND"), BUILDER(Create_func_rand)},
- { C_STRING_WITH_LEN("RELEASE_LOCK"), BUILDER(Create_func_release_lock)},
- { C_STRING_WITH_LEN("REVERSE"), BUILDER(Create_func_reverse)},
- { C_STRING_WITH_LEN("ROUND"), BUILDER(Create_func_round)},
- { C_STRING_WITH_LEN("ROW_COUNT"), BUILDER(Create_func_row_count)},
- { C_STRING_WITH_LEN("RPAD"), BUILDER(Create_func_rpad)},
- { C_STRING_WITH_LEN("RTRIM"), BUILDER(Create_func_rtrim)},
- { C_STRING_WITH_LEN("SEC_TO_TIME"), BUILDER(Create_func_sec_to_time)},
- { C_STRING_WITH_LEN("SHA"), BUILDER(Create_func_sha)},
- { C_STRING_WITH_LEN("SHA1"), BUILDER(Create_func_sha)},
- { C_STRING_WITH_LEN("SIGN"), BUILDER(Create_func_sign)},
- { C_STRING_WITH_LEN("SIN"), BUILDER(Create_func_sin)},
- { C_STRING_WITH_LEN("SLEEP"), BUILDER(Create_func_sleep)},
- { C_STRING_WITH_LEN("SOUNDEX"), BUILDER(Create_func_soundex)},
- { C_STRING_WITH_LEN("SPACE"), BUILDER(Create_func_space)},
- { C_STRING_WITH_LEN("SQRT"), BUILDER(Create_func_sqrt)},
- { C_STRING_WITH_LEN("SRID"), GEOM_BUILDER(Create_func_srid)},
- { C_STRING_WITH_LEN("STARTPOINT"), GEOM_BUILDER(Create_func_startpoint)},
- { C_STRING_WITH_LEN("STRCMP"), BUILDER(Create_func_strcmp)},
- { C_STRING_WITH_LEN("STR_TO_DATE"), BUILDER(Create_func_str_to_date)},
- { C_STRING_WITH_LEN("SUBSTRING_INDEX"), BUILDER(Create_func_substr_index)},
- { C_STRING_WITH_LEN("SUBTIME"), BUILDER(Create_func_subtime)},
- { C_STRING_WITH_LEN("TAN"), BUILDER(Create_func_tan)},
- { C_STRING_WITH_LEN("TIMEDIFF"), BUILDER(Create_func_timediff)},
- { C_STRING_WITH_LEN("TIME_FORMAT"), BUILDER(Create_func_time_format)},
- { C_STRING_WITH_LEN("TIME_TO_SEC"), BUILDER(Create_func_time_to_sec)},
- { C_STRING_WITH_LEN("TOUCHES"), GEOM_BUILDER(Create_func_touches)},
- { C_STRING_WITH_LEN("TO_DAYS"), BUILDER(Create_func_to_days)},
- { C_STRING_WITH_LEN("UCASE"), BUILDER(Create_func_ucase)},
- { C_STRING_WITH_LEN("UNCOMPRESS"), BUILDER(Create_func_uncompress)},
- { C_STRING_WITH_LEN("UNCOMPRESSED_LENGTH"), BUILDER(Create_func_uncompressed_length)},
- { C_STRING_WITH_LEN("UNHEX"), BUILDER(Create_func_unhex)},
- { C_STRING_WITH_LEN("UNIX_TIMESTAMP"), BUILDER(Create_func_unix_timestamp)},
- { C_STRING_WITH_LEN("UPDATEXML"), BUILDER(Create_func_xml_update)},
- { C_STRING_WITH_LEN("UPPER"), BUILDER(Create_func_ucase)},
- { C_STRING_WITH_LEN("UUID"), BUILDER(Create_func_uuid)},
- { C_STRING_WITH_LEN("UUID_SHORT"), BUILDER(Create_func_uuid_short)},
- { C_STRING_WITH_LEN("VERSION"), BUILDER(Create_func_version)},
- { C_STRING_WITH_LEN("WEEKDAY"), BUILDER(Create_func_weekday)},
- { C_STRING_WITH_LEN("WEEKOFYEAR"), BUILDER(Create_func_weekofyear)},
- { C_STRING_WITH_LEN("WITHIN"), GEOM_BUILDER(Create_func_within)},
- { C_STRING_WITH_LEN("X"), GEOM_BUILDER(Create_func_x)},
- { C_STRING_WITH_LEN("Y"), GEOM_BUILDER(Create_func_y)},
- { C_STRING_WITH_LEN("YEARWEEK"), BUILDER(Create_func_year_week)},
+ { { C_STRING_WITH_LEN("ABS") }, BUILDER(Create_func_abs)},
+ { { C_STRING_WITH_LEN("ACOS") }, BUILDER(Create_func_acos)},
+ { { C_STRING_WITH_LEN("ADDTIME") }, BUILDER(Create_func_addtime)},
+ { { C_STRING_WITH_LEN("AES_DECRYPT") }, BUILDER(Create_func_aes_decrypt)},
+ { { C_STRING_WITH_LEN("AES_ENCRYPT") }, BUILDER(Create_func_aes_encrypt)},
+ { { C_STRING_WITH_LEN("AREA") }, GEOM_BUILDER(Create_func_area)},
+ { { C_STRING_WITH_LEN("ASBINARY") }, GEOM_BUILDER(Create_func_as_wkb)},
+ { { C_STRING_WITH_LEN("ASIN") }, BUILDER(Create_func_asin)},
+ { { C_STRING_WITH_LEN("ASTEXT") }, GEOM_BUILDER(Create_func_as_wkt)},
+ { { C_STRING_WITH_LEN("ASWKB") }, GEOM_BUILDER(Create_func_as_wkb)},
+ { { C_STRING_WITH_LEN("ASWKT") }, GEOM_BUILDER(Create_func_as_wkt)},
+ { { C_STRING_WITH_LEN("ATAN") }, BUILDER(Create_func_atan)},
+ { { C_STRING_WITH_LEN("ATAN2") }, BUILDER(Create_func_atan)},
+ { { C_STRING_WITH_LEN("BENCHMARK") }, BUILDER(Create_func_benchmark)},
+ { { C_STRING_WITH_LEN("BIN") }, BUILDER(Create_func_bin)},
+ { { C_STRING_WITH_LEN("BIT_COUNT") }, BUILDER(Create_func_bit_count)},
+ { { C_STRING_WITH_LEN("BIT_LENGTH") }, BUILDER(Create_func_bit_length)},
+ { { C_STRING_WITH_LEN("CEIL") }, BUILDER(Create_func_ceiling)},
+ { { C_STRING_WITH_LEN("CEILING") }, BUILDER(Create_func_ceiling)},
+ { { C_STRING_WITH_LEN("CENTROID") }, GEOM_BUILDER(Create_func_centroid)},
+ { { C_STRING_WITH_LEN("CHARACTER_LENGTH") }, BUILDER(Create_func_char_length)},
+ { { C_STRING_WITH_LEN("CHAR_LENGTH") }, BUILDER(Create_func_char_length)},
+ { { C_STRING_WITH_LEN("COERCIBILITY") }, BUILDER(Create_func_coercibility)},
+ { { C_STRING_WITH_LEN("COMPRESS") }, BUILDER(Create_func_compress)},
+ { { C_STRING_WITH_LEN("CONCAT") }, BUILDER(Create_func_concat)},
+ { { C_STRING_WITH_LEN("CONCAT_WS") }, BUILDER(Create_func_concat_ws)},
+ { { C_STRING_WITH_LEN("CONNECTION_ID") }, BUILDER(Create_func_connection_id)},
+ { { C_STRING_WITH_LEN("CONV") }, BUILDER(Create_func_conv)},
+ { { C_STRING_WITH_LEN("CONVERT_TZ") }, BUILDER(Create_func_convert_tz)},
+ { { C_STRING_WITH_LEN("COS") }, BUILDER(Create_func_cos)},
+ { { C_STRING_WITH_LEN("COT") }, BUILDER(Create_func_cot)},
+ { { C_STRING_WITH_LEN("CRC32") }, BUILDER(Create_func_crc32)},
+ { { C_STRING_WITH_LEN("CROSSES") }, GEOM_BUILDER(Create_func_crosses)},
+ { { C_STRING_WITH_LEN("DATEDIFF") }, BUILDER(Create_func_datediff)},
+ { { C_STRING_WITH_LEN("DATE_FORMAT") }, BUILDER(Create_func_date_format)},
+ { { C_STRING_WITH_LEN("DAYNAME") }, BUILDER(Create_func_dayname)},
+ { { C_STRING_WITH_LEN("DAYOFMONTH") }, BUILDER(Create_func_dayofmonth)},
+ { { C_STRING_WITH_LEN("DAYOFWEEK") }, BUILDER(Create_func_dayofweek)},
+ { { C_STRING_WITH_LEN("DAYOFYEAR") }, BUILDER(Create_func_dayofyear)},
+ { { C_STRING_WITH_LEN("DECODE") }, BUILDER(Create_func_decode)},
+ { { C_STRING_WITH_LEN("DEGREES") }, BUILDER(Create_func_degrees)},
+ { { C_STRING_WITH_LEN("DES_DECRYPT") }, BUILDER(Create_func_des_decrypt)},
+ { { C_STRING_WITH_LEN("DES_ENCRYPT") }, BUILDER(Create_func_des_encrypt)},
+ { { C_STRING_WITH_LEN("DIMENSION") }, GEOM_BUILDER(Create_func_dimension)},
+ { { C_STRING_WITH_LEN("DISJOINT") }, GEOM_BUILDER(Create_func_disjoint)},
+ { { C_STRING_WITH_LEN("ELT") }, BUILDER(Create_func_elt)},
+ { { C_STRING_WITH_LEN("ENCODE") }, BUILDER(Create_func_encode)},
+ { { C_STRING_WITH_LEN("ENCRYPT") }, BUILDER(Create_func_encrypt)},
+ { { C_STRING_WITH_LEN("ENDPOINT") }, GEOM_BUILDER(Create_func_endpoint)},
+ { { C_STRING_WITH_LEN("ENVELOPE") }, GEOM_BUILDER(Create_func_envelope)},
+ { { C_STRING_WITH_LEN("EQUALS") }, GEOM_BUILDER(Create_func_equals)},
+ { { C_STRING_WITH_LEN("EXP") }, BUILDER(Create_func_exp)},
+ { { C_STRING_WITH_LEN("EXPORT_SET") }, BUILDER(Create_func_export_set)},
+ { { C_STRING_WITH_LEN("EXTERIORRING") }, GEOM_BUILDER(Create_func_exteriorring)},
+ { { C_STRING_WITH_LEN("EXTRACTVALUE") }, BUILDER(Create_func_xml_extractvalue)},
+ { { C_STRING_WITH_LEN("FIELD") }, BUILDER(Create_func_field)},
+ { { C_STRING_WITH_LEN("FIND_IN_SET") }, BUILDER(Create_func_find_in_set)},
+ { { C_STRING_WITH_LEN("FLOOR") }, BUILDER(Create_func_floor)},
+ { { C_STRING_WITH_LEN("FORMAT") }, BUILDER(Create_func_format)},
+ { { C_STRING_WITH_LEN("FOUND_ROWS") }, BUILDER(Create_func_found_rows)},
+ { { C_STRING_WITH_LEN("FROM_DAYS") }, BUILDER(Create_func_from_days)},
+ { { C_STRING_WITH_LEN("FROM_UNIXTIME") }, BUILDER(Create_func_from_unixtime)},
+ { { C_STRING_WITH_LEN("GEOMCOLLFROMTEXT") }, GEOM_BUILDER(Create_func_geometry_from_text)},
+ { { C_STRING_WITH_LEN("GEOMCOLLFROMWKB") }, GEOM_BUILDER(Create_func_geometry_from_wkb)},
+ { { C_STRING_WITH_LEN("GEOMETRYCOLLECTIONFROMTEXT") }, GEOM_BUILDER(Create_func_geometry_from_text)},
+ { { C_STRING_WITH_LEN("GEOMETRYCOLLECTIONFROMWKB") }, GEOM_BUILDER(Create_func_geometry_from_wkb)},
+ { { C_STRING_WITH_LEN("GEOMETRYFROMTEXT") }, GEOM_BUILDER(Create_func_geometry_from_text)},
+ { { C_STRING_WITH_LEN("GEOMETRYFROMWKB") }, GEOM_BUILDER(Create_func_geometry_from_wkb)},
+ { { C_STRING_WITH_LEN("GEOMETRYN") }, GEOM_BUILDER(Create_func_geometryn)},
+ { { C_STRING_WITH_LEN("GEOMETRYTYPE") }, GEOM_BUILDER(Create_func_geometry_type)},
+ { { C_STRING_WITH_LEN("GEOMFROMTEXT") }, GEOM_BUILDER(Create_func_geometry_from_text)},
+ { { C_STRING_WITH_LEN("GEOMFROMWKB") }, GEOM_BUILDER(Create_func_geometry_from_wkb)},
+ { { C_STRING_WITH_LEN("GET_LOCK") }, BUILDER(Create_func_get_lock)},
+ { { C_STRING_WITH_LEN("GLENGTH") }, GEOM_BUILDER(Create_func_glength)},
+ { { C_STRING_WITH_LEN("GREATEST") }, BUILDER(Create_func_greatest)},
+ { { C_STRING_WITH_LEN("HEX") }, BUILDER(Create_func_hex)},
+ { { C_STRING_WITH_LEN("IFNULL") }, BUILDER(Create_func_ifnull)},
+ { { C_STRING_WITH_LEN("INET_ATON") }, BUILDER(Create_func_inet_aton)},
+ { { C_STRING_WITH_LEN("INET_NTOA") }, BUILDER(Create_func_inet_ntoa)},
+ { { C_STRING_WITH_LEN("INSTR") }, BUILDER(Create_func_instr)},
+ { { C_STRING_WITH_LEN("INTERIORRINGN") }, GEOM_BUILDER(Create_func_interiorringn)},
+ { { C_STRING_WITH_LEN("INTERSECTS") }, GEOM_BUILDER(Create_func_intersects)},
+ { { C_STRING_WITH_LEN("ISCLOSED") }, GEOM_BUILDER(Create_func_isclosed)},
+ { { C_STRING_WITH_LEN("ISEMPTY") }, GEOM_BUILDER(Create_func_isempty)},
+ { { C_STRING_WITH_LEN("ISNULL") }, BUILDER(Create_func_isnull)},
+ { { C_STRING_WITH_LEN("ISSIMPLE") }, GEOM_BUILDER(Create_func_issimple)},
+ { { C_STRING_WITH_LEN("IS_FREE_LOCK") }, BUILDER(Create_func_is_free_lock)},
+ { { C_STRING_WITH_LEN("IS_USED_LOCK") }, BUILDER(Create_func_is_used_lock)},
+ { { C_STRING_WITH_LEN("LAST_DAY") }, BUILDER(Create_func_last_day)},
+ { { C_STRING_WITH_LEN("LAST_INSERT_ID") }, BUILDER(Create_func_last_insert_id)},
+ { { C_STRING_WITH_LEN("LCASE") }, BUILDER(Create_func_lcase)},
+ { { C_STRING_WITH_LEN("LEAST") }, BUILDER(Create_func_least)},
+ { { C_STRING_WITH_LEN("LENGTH") }, BUILDER(Create_func_length)},
+ { { C_STRING_WITH_LEN("LINEFROMTEXT") }, GEOM_BUILDER(Create_func_geometry_from_text)},
+ { { C_STRING_WITH_LEN("LINEFROMWKB") }, GEOM_BUILDER(Create_func_geometry_from_wkb)},
+ { { C_STRING_WITH_LEN("LINESTRINGFROMTEXT") }, GEOM_BUILDER(Create_func_geometry_from_text)},
+ { { C_STRING_WITH_LEN("LINESTRINGFROMWKB") }, GEOM_BUILDER(Create_func_geometry_from_wkb)},
+ { { C_STRING_WITH_LEN("LN") }, BUILDER(Create_func_ln)},
+ { { C_STRING_WITH_LEN("LOAD_FILE") }, BUILDER(Create_func_load_file)},
+ { { C_STRING_WITH_LEN("LOCATE") }, BUILDER(Create_func_locate)},
+ { { C_STRING_WITH_LEN("LOG") }, BUILDER(Create_func_log)},
+ { { C_STRING_WITH_LEN("LOG10") }, BUILDER(Create_func_log10)},
+ { { C_STRING_WITH_LEN("LOG2") }, BUILDER(Create_func_log2)},
+ { { C_STRING_WITH_LEN("LOWER") }, BUILDER(Create_func_lcase)},
+ { { C_STRING_WITH_LEN("LPAD") }, BUILDER(Create_func_lpad)},
+ { { C_STRING_WITH_LEN("LTRIM") }, BUILDER(Create_func_ltrim)},
+ { { C_STRING_WITH_LEN("MAKEDATE") }, BUILDER(Create_func_makedate)},
+ { { C_STRING_WITH_LEN("MAKETIME") }, BUILDER(Create_func_maketime)},
+ { { C_STRING_WITH_LEN("MAKE_SET") }, BUILDER(Create_func_make_set)},
+ { { C_STRING_WITH_LEN("MASTER_POS_WAIT") }, BUILDER(Create_func_master_pos_wait)},
+ { { C_STRING_WITH_LEN("MBRCONTAINS") }, GEOM_BUILDER(Create_func_contains)},
+ { { C_STRING_WITH_LEN("MBRDISJOINT") }, GEOM_BUILDER(Create_func_disjoint)},
+ { { C_STRING_WITH_LEN("MBREQUAL") }, GEOM_BUILDER(Create_func_equals)},
+ { { C_STRING_WITH_LEN("MBRINTERSECTS") }, GEOM_BUILDER(Create_func_intersects)},
+ { { C_STRING_WITH_LEN("MBROVERLAPS") }, GEOM_BUILDER(Create_func_overlaps)},
+ { { C_STRING_WITH_LEN("MBRTOUCHES") }, GEOM_BUILDER(Create_func_touches)},
+ { { C_STRING_WITH_LEN("MBRWITHIN") }, GEOM_BUILDER(Create_func_within)},
+ { { C_STRING_WITH_LEN("MD5") }, BUILDER(Create_func_md5)},
+ { { C_STRING_WITH_LEN("MLINEFROMTEXT") }, GEOM_BUILDER(Create_func_geometry_from_text)},
+ { { C_STRING_WITH_LEN("MLINEFROMWKB") }, GEOM_BUILDER(Create_func_geometry_from_wkb)},
+ { { C_STRING_WITH_LEN("MONTHNAME") }, BUILDER(Create_func_monthname)},
+ { { C_STRING_WITH_LEN("MPOINTFROMTEXT") }, GEOM_BUILDER(Create_func_geometry_from_text)},
+ { { C_STRING_WITH_LEN("MPOINTFROMWKB") }, GEOM_BUILDER(Create_func_geometry_from_wkb)},
+ { { C_STRING_WITH_LEN("MPOLYFROMTEXT") }, GEOM_BUILDER(Create_func_geometry_from_text)},
+ { { C_STRING_WITH_LEN("MPOLYFROMWKB") }, GEOM_BUILDER(Create_func_geometry_from_wkb)},
+ { { C_STRING_WITH_LEN("MULTILINESTRINGFROMTEXT") }, GEOM_BUILDER(Create_func_geometry_from_text)},
+ { { C_STRING_WITH_LEN("MULTILINESTRINGFROMWKB") }, GEOM_BUILDER(Create_func_geometry_from_wkb)},
+ { { C_STRING_WITH_LEN("MULTIPOINTFROMTEXT") }, GEOM_BUILDER(Create_func_geometry_from_text)},
+ { { C_STRING_WITH_LEN("MULTIPOINTFROMWKB") }, GEOM_BUILDER(Create_func_geometry_from_wkb)},
+ { { C_STRING_WITH_LEN("MULTIPOLYGONFROMTEXT") }, GEOM_BUILDER(Create_func_geometry_from_text)},
+ { { C_STRING_WITH_LEN("MULTIPOLYGONFROMWKB") }, GEOM_BUILDER(Create_func_geometry_from_wkb)},
+ { { C_STRING_WITH_LEN("NAME_CONST") }, BUILDER(Create_func_name_const)},
+ { { C_STRING_WITH_LEN("NULLIF") }, BUILDER(Create_func_nullif)},
+ { { C_STRING_WITH_LEN("NUMGEOMETRIES") }, GEOM_BUILDER(Create_func_numgeometries)},
+ { { C_STRING_WITH_LEN("NUMINTERIORRINGS") }, GEOM_BUILDER(Create_func_numinteriorring)},
+ { { C_STRING_WITH_LEN("NUMPOINTS") }, GEOM_BUILDER(Create_func_numpoints)},
+ { { C_STRING_WITH_LEN("OCT") }, BUILDER(Create_func_oct)},
+ { { C_STRING_WITH_LEN("OCTET_LENGTH") }, BUILDER(Create_func_length)},
+ { { C_STRING_WITH_LEN("ORD") }, BUILDER(Create_func_ord)},
+ { { C_STRING_WITH_LEN("OVERLAPS") }, GEOM_BUILDER(Create_func_overlaps)},
+ { { C_STRING_WITH_LEN("PERIOD_ADD") }, BUILDER(Create_func_period_add)},
+ { { C_STRING_WITH_LEN("PERIOD_DIFF") }, BUILDER(Create_func_period_diff)},
+ { { C_STRING_WITH_LEN("PI") }, BUILDER(Create_func_pi)},
+ { { C_STRING_WITH_LEN("POINTFROMTEXT") }, GEOM_BUILDER(Create_func_geometry_from_text)},
+ { { C_STRING_WITH_LEN("POINTFROMWKB") }, GEOM_BUILDER(Create_func_geometry_from_wkb)},
+ { { C_STRING_WITH_LEN("POINTN") }, GEOM_BUILDER(Create_func_pointn)},
+ { { C_STRING_WITH_LEN("POLYFROMTEXT") }, GEOM_BUILDER(Create_func_geometry_from_text)},
+ { { C_STRING_WITH_LEN("POLYFROMWKB") }, GEOM_BUILDER(Create_func_geometry_from_wkb)},
+ { { C_STRING_WITH_LEN("POLYGONFROMTEXT") }, GEOM_BUILDER(Create_func_geometry_from_text)},
+ { { C_STRING_WITH_LEN("POLYGONFROMWKB") }, GEOM_BUILDER(Create_func_geometry_from_wkb)},
+ { { C_STRING_WITH_LEN("POW") }, BUILDER(Create_func_pow)},
+ { { C_STRING_WITH_LEN("POWER") }, BUILDER(Create_func_pow)},
+ { { C_STRING_WITH_LEN("QUOTE") }, BUILDER(Create_func_quote)},
+ { { C_STRING_WITH_LEN("RADIANS") }, BUILDER(Create_func_radians)},
+ { { C_STRING_WITH_LEN("RAND") }, BUILDER(Create_func_rand)},
+ { { C_STRING_WITH_LEN("RELEASE_LOCK") }, BUILDER(Create_func_release_lock)},
+ { { C_STRING_WITH_LEN("REVERSE") }, BUILDER(Create_func_reverse)},
+ { { C_STRING_WITH_LEN("ROUND") }, BUILDER(Create_func_round)},
+ { { C_STRING_WITH_LEN("ROW_COUNT") }, BUILDER(Create_func_row_count)},
+ { { C_STRING_WITH_LEN("RPAD") }, BUILDER(Create_func_rpad)},
+ { { C_STRING_WITH_LEN("RTRIM") }, BUILDER(Create_func_rtrim)},
+ { { C_STRING_WITH_LEN("SEC_TO_TIME") }, BUILDER(Create_func_sec_to_time)},
+ { { C_STRING_WITH_LEN("SHA") }, BUILDER(Create_func_sha)},
+ { { C_STRING_WITH_LEN("SHA1") }, BUILDER(Create_func_sha)},
+ { { C_STRING_WITH_LEN("SIGN") }, BUILDER(Create_func_sign)},
+ { { C_STRING_WITH_LEN("SIN") }, BUILDER(Create_func_sin)},
+ { { C_STRING_WITH_LEN("SLEEP") }, BUILDER(Create_func_sleep)},
+ { { C_STRING_WITH_LEN("SOUNDEX") }, BUILDER(Create_func_soundex)},
+ { { C_STRING_WITH_LEN("SPACE") }, BUILDER(Create_func_space)},
+ { { C_STRING_WITH_LEN("SQRT") }, BUILDER(Create_func_sqrt)},
+ { { C_STRING_WITH_LEN("SRID") }, GEOM_BUILDER(Create_func_srid)},
+ { { C_STRING_WITH_LEN("STARTPOINT") }, GEOM_BUILDER(Create_func_startpoint)},
+ { { C_STRING_WITH_LEN("STRCMP") }, BUILDER(Create_func_strcmp)},
+ { { C_STRING_WITH_LEN("STR_TO_DATE") }, BUILDER(Create_func_str_to_date)},
+ { { C_STRING_WITH_LEN("SUBSTRING_INDEX") }, BUILDER(Create_func_substr_index)},
+ { { C_STRING_WITH_LEN("SUBTIME") }, BUILDER(Create_func_subtime)},
+ { { C_STRING_WITH_LEN("TAN") }, BUILDER(Create_func_tan)},
+ { { C_STRING_WITH_LEN("TIMEDIFF") }, BUILDER(Create_func_timediff)},
+ { { C_STRING_WITH_LEN("TIME_FORMAT") }, BUILDER(Create_func_time_format)},
+ { { C_STRING_WITH_LEN("TIME_TO_SEC") }, BUILDER(Create_func_time_to_sec)},
+ { { C_STRING_WITH_LEN("TOUCHES") }, GEOM_BUILDER(Create_func_touches)},
+ { { C_STRING_WITH_LEN("TO_DAYS") }, BUILDER(Create_func_to_days)},
+ { { C_STRING_WITH_LEN("UCASE") }, BUILDER(Create_func_ucase)},
+ { { C_STRING_WITH_LEN("UNCOMPRESS") }, BUILDER(Create_func_uncompress)},
+ { { C_STRING_WITH_LEN("UNCOMPRESSED_LENGTH") }, BUILDER(Create_func_uncompressed_length)},
+ { { C_STRING_WITH_LEN("UNHEX") }, BUILDER(Create_func_unhex)},
+ { { C_STRING_WITH_LEN("UNIX_TIMESTAMP") }, BUILDER(Create_func_unix_timestamp)},
+ { { C_STRING_WITH_LEN("UPDATEXML") }, BUILDER(Create_func_xml_update)},
+ { { C_STRING_WITH_LEN("UPPER") }, BUILDER(Create_func_ucase)},
+ { { C_STRING_WITH_LEN("UUID") }, BUILDER(Create_func_uuid)},
+ { { C_STRING_WITH_LEN("UUID_SHORT") }, BUILDER(Create_func_uuid_short)},
+ { { C_STRING_WITH_LEN("VERSION") }, BUILDER(Create_func_version)},
+ { { C_STRING_WITH_LEN("WEEKDAY") }, BUILDER(Create_func_weekday)},
+ { { C_STRING_WITH_LEN("WEEKOFYEAR") }, BUILDER(Create_func_weekofyear)},
+ { { C_STRING_WITH_LEN("WITHIN") }, GEOM_BUILDER(Create_func_within)},
+ { { C_STRING_WITH_LEN("X") }, GEOM_BUILDER(Create_func_x)},
+ { { C_STRING_WITH_LEN("Y") }, GEOM_BUILDER(Create_func_y)},
+ { { C_STRING_WITH_LEN("YEARWEEK") }, BUILDER(Create_func_year_week)},
{ {0, 0}, NULL}
};
@@ -4995,11 +4996,15 @@ find_qualified_function_builder(THD *thd)
return & Create_sp_func::s_singleton;
}
-Item*
-create_func_cast(THD *thd, Item *a, Cast_target cast_type, int len, int dec,
+
+Item *
+create_func_cast(THD *thd, Item *a, Cast_target cast_type,
+ const char *c_len, const char *c_dec,
CHARSET_INFO *cs)
{
Item *res;
+ ulong len;
+ uint dec;
LINT_INIT(res);
switch (cast_type) {
@@ -5023,18 +5028,21 @@ create_func_cast(THD *thd, Item *a, Cast_target cast_type, int len, int dec,
break;
case ITEM_CAST_DECIMAL:
{
- int tmp_len= (len>0) ? len : 10;
- if (tmp_len < dec)
+ len= c_len ? atoi(c_len) : 0;
+ dec= c_dec ? atoi(c_dec) : 0;
+ my_decimal_trim(&len, &dec);
+ if (len < dec)
{
my_error(ER_M_BIGGER_THAN_D, MYF(0), "");
return 0;
}
- res= new (thd->mem_root) Item_decimal_typecast(a, tmp_len, dec);
+ res= new (thd->mem_root) Item_decimal_typecast(a, len, dec);
break;
}
case ITEM_CAST_CHAR:
{
CHARSET_INFO *real_cs= (cs ? cs : thd->variables.collation_connection);
+ len= c_len ? atoi(c_len) : -1;
res= new (thd->mem_root) Item_char_typecast(a, len, real_cs);
break;
}
@@ -5047,4 +5055,3 @@ create_func_cast(THD *thd, Item *a, Cast_target cast_type, int len, int dec,
}
return res;
}
-
diff --git a/sql/item_create.h b/sql/item_create.h
index 0a668b3e67f..7ace4032515 100644
--- a/sql/item_create.h
+++ b/sql/item_create.h
@@ -159,9 +159,9 @@ protected:
@param dec TODO
@param cs The character set
*/
-Item*
-create_func_cast(THD *thd, Item *a, Cast_target cast_type, int len, int dec,
+Item *
+create_func_cast(THD *thd, Item *a, Cast_target cast_type,
+ const char *len, const char *dec,
CHARSET_INFO *cs);
-
#endif
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 64c181fde71..af5bdb5ecd7 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -956,7 +956,8 @@ longlong Item_func_signed::val_int()
longlong value;
int error;
- if (args[0]->cast_to_int_type() != STRING_RESULT)
+ if (args[0]->cast_to_int_type() != STRING_RESULT ||
+ args[0]->result_as_longlong())
{
value= args[0]->val_int();
null_value= args[0]->null_value;
@@ -995,7 +996,8 @@ longlong Item_func_unsigned::val_int()
my_decimal2int(E_DEC_FATAL_ERROR, dec, 1, &value);
return value;
}
- else if (args[0]->cast_to_int_type() != STRING_RESULT)
+ else if (args[0]->cast_to_int_type() != STRING_RESULT ||
+ args[0]->result_as_longlong())
{
value= args[0]->val_int();
null_value= args[0]->null_value;
@@ -1047,6 +1049,8 @@ my_decimal *Item_decimal_typecast::val_decimal(my_decimal *dec)
{
my_decimal tmp_buf, *tmp= args[0]->val_decimal(&tmp_buf);
bool sign;
+ uint precision;
+
if ((null_value= args[0]->null_value))
return NULL;
my_decimal_round(E_DEC_FATAL_ERROR, tmp, decimals, FALSE, dec);
@@ -1059,9 +1063,11 @@ my_decimal *Item_decimal_typecast::val_decimal(my_decimal *dec)
goto err;
}
}
- if (max_length - 2 - decimals < (uint) my_decimal_intg(dec))
+ precision= my_decimal_length_to_precision(max_length,
+ decimals, unsigned_flag);
+ if (precision - decimals < (uint) my_decimal_intg(dec))
{
- max_my_decimal(dec, max_length - 2, decimals);
+ max_my_decimal(dec, precision, decimals);
dec->sign(sign);
goto err;
}
@@ -1078,9 +1084,25 @@ err:
void Item_decimal_typecast::print(String *str)
{
+ char len_buf[20*3 + 1];
+ char *end;
+
+ uint precision= my_decimal_length_to_precision(max_length, decimals,
+ unsigned_flag);
str->append(STRING_WITH_LEN("cast("));
args[0]->print(str);
- str->append(STRING_WITH_LEN(" as decimal)"));
+ str->append(STRING_WITH_LEN(" as decimal("));
+
+ end=int10_to_str(precision, len_buf,10);
+ str->append(len_buf, (uint32) (end - len_buf));
+
+ str->append(',');
+
+ end=int10_to_str(decimals, len_buf,10);
+ str->append(len_buf, (uint32) (end - len_buf));
+
+ str->append(')');
+ str->append(')');
}
@@ -1499,7 +1521,7 @@ void Item_func_neg::fix_length_and_dec()
*/
if (hybrid_type == INT_RESULT &&
args[0]->type() == INT_ITEM &&
- ((ulonglong) args[0]->val_int() >= (ulonglong) LONGLONG_MIN))
+ ((ulonglong) args[0]->val_int() > (ulonglong) LONGLONG_MIN))
{
/*
Ensure that result is converted to DECIMAL, as longlong can't hold
@@ -2001,9 +2023,9 @@ double my_double_round(double value, longlong dec, bool dec_unsigned,
tmp=(abs_dec < array_elements(log_10) ?
log_10[abs_dec] : pow(10.0,(double) abs_dec));
- if (dec_negative && isinf(tmp))
+ if (dec_negative && my_isinf(tmp))
tmp2= 0;
- else if (!dec_negative && isinf(value * tmp))
+ else if (!dec_negative && my_isinf(value * tmp))
tmp2= value;
else if (truncate)
{
@@ -2180,6 +2202,7 @@ double Item_func_units::val_real()
void Item_func_min_max::fix_length_and_dec()
{
int max_int_part=0;
+ bool datetime_found= FALSE;
decimals=0;
max_length=0;
maybe_null=0;
@@ -2193,18 +2216,88 @@ void Item_func_min_max::fix_length_and_dec()
if (args[i]->maybe_null)
maybe_null=1;
cmp_type=item_cmp_type(cmp_type,args[i]->result_type());
+ if (args[i]->result_type() != ROW_RESULT && args[i]->is_datetime())
+ {
+ datetime_found= TRUE;
+ if (!datetime_item || args[i]->field_type() == MYSQL_TYPE_DATETIME)
+ datetime_item= args[i];
+ }
}
if (cmp_type == STRING_RESULT)
+ {
agg_arg_charsets(collation, args, arg_count, MY_COLL_CMP_CONV, 1);
+ if (datetime_found)
+ {
+ thd= current_thd;
+ compare_as_dates= TRUE;
+ }
+ }
else if ((cmp_type == DECIMAL_RESULT) || (cmp_type == INT_RESULT))
max_length= my_decimal_precision_to_length(max_int_part+decimals, decimals,
unsigned_flag);
}
+/*
+ Compare item arguments in the DATETIME context.
+
+ SYNOPSIS
+ cmp_datetimes()
+ value [out] found least/greatest DATE/DATETIME value
+
+ DESCRIPTION
+ Compare item arguments as DATETIME values and return the index of the
+ least/greatest argument in the arguments array.
+ The correct integer DATE/DATETIME value of the found argument is
+ stored to the value pointer, if latter is provided.
+
+ RETURN
+ 0 If one of arguments is NULL
+ # index of the least/greatest argument
+*/
+
+uint Item_func_min_max::cmp_datetimes(ulonglong *value)
+{
+ ulonglong min_max;
+ uint min_max_idx= 0;
+ LINT_INIT(min_max);
+
+ for (uint i=0; i < arg_count ; i++)
+ {
+ Item **arg= args + i;
+ bool is_null;
+ ulonglong res= get_datetime_value(thd, &arg, 0, datetime_item, &is_null);
+ if ((null_value= args[i]->null_value))
+ return 0;
+ if (i == 0 || (res < min_max ? cmp_sign : -cmp_sign) > 0)
+ {
+ min_max= res;
+ min_max_idx= i;
+ }
+ }
+ if (value)
+ {
+ *value= min_max;
+ if (datetime_item->field_type() == MYSQL_TYPE_DATE)
+ *value/= 1000000L;
+ }
+ return min_max_idx;
+}
+
+
String *Item_func_min_max::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
+ if (compare_as_dates)
+ {
+ String *str_res;
+ uint min_max_idx= cmp_datetimes(NULL);
+ if (null_value)
+ return 0;
+ str_res= args[min_max_idx]->val_str(str);
+ str_res->set_charset(collation.collation);
+ return str_res;
+ }
switch (cmp_type) {
case INT_RESULT:
{
@@ -2269,6 +2362,12 @@ double Item_func_min_max::val_real()
{
DBUG_ASSERT(fixed == 1);
double value=0.0;
+ if (compare_as_dates)
+ {
+ ulonglong result= 0;
+ (void)cmp_datetimes(&result);
+ return (double)result;
+ }
for (uint i=0; i < arg_count ; i++)
{
if (i == 0)
@@ -2290,6 +2389,12 @@ longlong Item_func_min_max::val_int()
{
DBUG_ASSERT(fixed == 1);
longlong value=0;
+ if (compare_as_dates)
+ {
+ ulonglong result= 0;
+ (void)cmp_datetimes(&result);
+ return (longlong)result;
+ }
for (uint i=0; i < arg_count ; i++)
{
if (i == 0)
@@ -2313,6 +2418,13 @@ my_decimal *Item_func_min_max::val_decimal(my_decimal *dec)
my_decimal tmp_buf, *tmp, *res;
LINT_INIT(res);
+ if (compare_as_dates)
+ {
+ ulonglong value= 0;
+ (void)cmp_datetimes(&value);
+ ulonglong2decimal(value, dec);
+ return dec;
+ }
for (uint i=0; i < arg_count ; i++)
{
if (i == 0)
@@ -4309,7 +4421,7 @@ int get_var_with_binlog(THD *thd, enum_sql_command sql_command,
List<set_var_base> tmp_var_list;
LEX *sav_lex= thd->lex, lex_tmp;
thd->lex= &lex_tmp;
- lex_start(thd, NULL, 0);
+ lex_start(thd);
tmp_var_list.push_back(new set_var_user(new Item_func_set_user_var(name,
new Item_null())));
/* Create the variable */
@@ -4948,7 +5060,7 @@ Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name,
component_name= &component; // Empty string
}
- if (!(var= find_sys_var(base_name->str, base_name->length)))
+ if (!(var= find_sys_var(thd, base_name->str, base_name->length)))
return 0;
if (component.str)
{
diff --git a/sql/item_func.h b/sql/item_func.h
index 8077f03d7ae..43959e882f8 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -333,8 +333,8 @@ class Item_decimal_typecast :public Item_func
public:
Item_decimal_typecast(Item *a, int len, int dec) :Item_func(a)
{
- max_length= len + 2;
decimals= dec;
+ max_length= my_decimal_precision_to_length(len, dec, unsigned_flag);
}
String *val_str(String *str);
double val_real();
@@ -708,16 +708,25 @@ class Item_func_min_max :public Item_func
Item_result cmp_type;
String tmp_value;
int cmp_sign;
+ /* TRUE <=> arguments should be compared in the DATETIME context. */
+ bool compare_as_dates;
+ /* An item used for issuing warnings while string to DATETIME conversion. */
+ Item *datetime_item;
+ THD *thd;
+
public:
Item_func_min_max(List<Item> &list,int cmp_sign_arg) :Item_func(list),
- cmp_type(INT_RESULT), cmp_sign(cmp_sign_arg) {}
+ cmp_type(INT_RESULT), cmp_sign(cmp_sign_arg), compare_as_dates(FALSE),
+ datetime_item(0) {}
double val_real();
longlong val_int();
String *val_str(String *);
my_decimal *val_decimal(my_decimal *);
void fix_length_and_dec();
enum Item_result result_type () const { return cmp_type; }
+ bool result_as_longlong() { return compare_as_dates; };
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
+ uint cmp_datetimes(ulonglong *value);
};
class Item_func_min :public Item_func_min_max
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index e15fba78009..9494d1dc2ee 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -1817,6 +1817,21 @@ int subselect_single_select_engine::exec()
thd->lex->current_select= save_select;
DBUG_RETURN(join->error ? join->error : 1);
}
+ if (!select_lex->uncacheable && thd->lex->describe &&
+ !(join->select_options & SELECT_DESCRIBE) &&
+ join->need_tmp && item->const_item())
+ {
+ /*
+ Force join->join_tmp creation, because this subquery will be replaced
+ by a simple select from the materialization temp table by optimize()
+ called by EXPLAIN and we need to preserve the initial query structure
+ so we can display it.
+ */
+ select_lex->uncacheable|= UNCACHEABLE_EXPLAIN;
+ select_lex->master_unit()->uncacheable|= UNCACHEABLE_EXPLAIN;
+ if (join->init_save_join_tab())
+ DBUG_RETURN(1); /* purecov: inspected */
+ }
if (item->engine_changed)
{
DBUG_RETURN(1);
@@ -1857,6 +1872,8 @@ int subselect_single_select_engine::exec()
if (cond_guard && !*cond_guard)
{
/* Change the access method to full table scan */
+ tab->save_read_first_record= tab->read_first_record;
+ tab->save_read_record= tab->read_record.read_record;
tab->read_first_record= init_read_record_seq;
tab->read_record.record= tab->table->record[0];
tab->read_record.thd= join->thd;
@@ -1877,8 +1894,8 @@ int subselect_single_select_engine::exec()
JOIN_TAB *tab= *ptab;
tab->read_record.record= 0;
tab->read_record.ref_length= 0;
- tab->read_first_record= join_read_always_key_or_null;
- tab->read_record.read_record= join_read_next_same_or_null;
+ tab->read_first_record= tab->save_read_first_record;
+ tab->read_record.read_record= tab->save_read_record;
}
executed= 1;
thd->where= save_where;
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index f8d2c1e1122..69148d81b9a 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -2491,7 +2491,7 @@ bool Item_sum_count_distinct::setup(THD *thd)
table->file->extra(HA_EXTRA_NO_ROWS); // Don't update rows
table->no_rows=1;
- if (table->s->db_type == heap_hton)
+ if (table->s->db_type() == heap_hton)
{
/*
No blobs, otherwise it would have been MyISAM: set up a compare
@@ -3360,6 +3360,10 @@ String* Item_func_group_concat::val_str(String* str)
DBUG_ASSERT(fixed == 1);
if (null_value)
return 0;
+ if (!result.length() && tree)
+ /* Tree is used for sorting as in ORDER BY */
+ tree_walk(tree, (tree_walk_action)&dump_leaf_key, (void*)this,
+ left_root_right);
if (count_cut_values && !warning)
{
/*
@@ -3371,11 +3375,6 @@ String* Item_func_group_concat::val_str(String* str)
ER_CUT_VALUE_GROUP_CONCAT,
ER(ER_CUT_VALUE_GROUP_CONCAT));
}
- if (result.length())
- return &result;
- if (tree)
- tree_walk(tree, (tree_walk_action)&dump_leaf_key, (void*)this,
- left_root_right);
return &result;
}
diff --git a/sql/key.cc b/sql/key.cc
index 851b5251b50..6626215a72c 100644
--- a/sql/key.cc
+++ b/sql/key.cc
@@ -215,23 +215,34 @@ void key_restore(uchar *to_record, uchar *from_key, KEY *key_info,
}
if (key_part->key_part_flag & HA_BLOB_PART)
{
+ /*
+ This in fact never happens, as we have only partial BLOB
+ keys yet anyway, so it's difficult to find any sence to
+ restore the part of a record.
+ Maybe this branch is to be removed, but now we
+ have to ignore GCov compaining.
+ */
uint blob_length= uint2korr(from_key);
+ Field_blob *field= (Field_blob*) key_part->field;
from_key+= HA_KEY_BLOB_LENGTH;
key_length-= HA_KEY_BLOB_LENGTH;
- ((Field_blob*) key_part->field)->set_ptr((ulong) blob_length,
- from_key);
+ field->set_ptr_offset(to_record - field->table->record[0],
+ (ulong) blob_length, (char*) from_key);
length= key_part->length;
}
else if (key_part->key_part_flag & HA_VAR_LENGTH_PART)
{
+ Field *field= key_part->field;
my_bitmap_map *old_map;
+ my_ptrdiff_t ptrdiff= to_record - field->table->record[0];
+ field->move_field_offset(ptrdiff);
key_length-= HA_KEY_BLOB_LENGTH;
length= min(key_length, key_part->length);
- old_map= dbug_tmp_use_all_columns(key_part->field->table,
- key_part->field->table->write_set);
- key_part->field->set_key_image(from_key, length);
- dbug_tmp_restore_column_map(key_part->field->table->write_set, old_map);
+ old_map= dbug_tmp_use_all_columns(field->table, field->table->write_set);
+ field->set_key_image((char *) from_key, length);
+ dbug_tmp_restore_column_map(field->table->write_set, old_map);
from_key+= HA_KEY_BLOB_LENGTH;
+ field->move_field_offset(-ptrdiff);
}
else
{
diff --git a/sql/lock.cc b/sql/lock.cc
index eeb895a3c8e..6f1dd0669ee 100644
--- a/sql/lock.cc
+++ b/sql/lock.cc
@@ -892,8 +892,6 @@ end:
int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use)
{
TABLE *table;
- TABLE_SHARE *share;
- char *key_buff;
char key[MAX_DBKEY_LENGTH];
char *db= table_list->db;
uint key_length;
@@ -921,29 +919,11 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use)
}
}
}
- /*
- Create a table entry with the right key and with an old refresh version
- Note that we must use my_multi_malloc() here as this is freed by the
- table cache
- */
- if (!my_multi_malloc(MYF(MY_WME | MY_ZEROFILL),
- &table, (uint) sizeof(*table),
- &share, (uint) sizeof(*share),
- &key_buff, (uint) key_length,
- NullS))
- DBUG_RETURN(-1);
- table->s= share;
- share->set_table_cache_key(key_buff, key, key_length);
- share->tmp_table= INTERNAL_TMP_TABLE; // for intern_close_table
- table->in_use= thd;
- table->locked_by_name=1;
- table_list->table=table;
- if (my_hash_insert(&open_cache, (uchar*) table))
- {
- my_free((uchar*) table,MYF(0));
+ if (!(table= table_cache_insert_placeholder(thd, key, key_length)))
DBUG_RETURN(-1);
- }
+
+ table_list->table=table;
/* Return 1 if table is in use */
DBUG_RETURN(test(remove_table_from_cache(thd, db, table_list->table_name,
diff --git a/sql/log.cc b/sql/log.cc
index d7252b56d22..11afdc8d20d 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -1917,8 +1917,8 @@ shutdown the MySQL server and restart it.", name, errno);
}
MYSQL_LOG::MYSQL_LOG()
- : name(0), log_type(LOG_UNKNOWN), log_state(LOG_CLOSED), write_error(FALSE),
- inited(FALSE)
+ : name(0), write_error(FALSE), inited(FALSE), log_type(LOG_UNKNOWN),
+ log_state(LOG_CLOSED)
{
/*
We don't want to initialize LOCK_Log here as such initialization depends on
@@ -3892,7 +3892,7 @@ void MYSQL_BIN_LOG::rotate_and_purge(uint flags)
#ifdef HAVE_REPLICATION
if (expire_logs_days)
{
- long purge_time= (long) (time(0) - expire_logs_days*24*60*60);
+ time_t purge_time= time(0) - expire_logs_days*24*60*60;
if (purge_time >= 0)
purge_logs_before_date(purge_time);
}
diff --git a/sql/log.h b/sql/log.h
index ed0c3557d08..25bcbd6c62d 100644
--- a/sql/log.h
+++ b/sql/log.h
@@ -603,13 +603,13 @@ public:
};
enum enum_binlog_format {
- BINLOG_FORMAT_STMT= 0, // statement-based
- BINLOG_FORMAT_ROW= 1, // row_based
/*
statement-based except for cases where only row-based can work (UUID()
etc):
*/
- BINLOG_FORMAT_MIXED= 2,
+ BINLOG_FORMAT_MIXED= 0,
+ BINLOG_FORMAT_STMT= 1, // statement-based
+ BINLOG_FORMAT_ROW= 2, // row_based
/*
This value is last, after the end of binlog_format_typelib: it has no
corresponding cell in this typelib. We use this value to be able to know if
diff --git a/sql/log_event.cc b/sql/log_event.cc
index bde19f38df1..a0a3b065ede 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -2055,7 +2055,8 @@ int Query_log_event::do_apply_event(RELAY_LOG_INFO const *rli,
thd->variables.collation_database= thd->db_charset;
/* Execute the query (note that we bypass dispatch_command()) */
- mysql_parse(thd, thd->query, thd->query_length);
+ const char* found_semicolon= NULL;
+ mysql_parse(thd, thd->query, thd->query_length, &found_semicolon);
}
else
@@ -3226,10 +3227,12 @@ int Load_log_event::do_apply_event(NET* net, RELAY_LOG_INFO const *rli,
/* see Query_log_event::do_apply_event() and BUG#13360 */
DBUG_ASSERT(!rli->m_table_map.count());
/*
- Usually mysql_init_query() is called by mysql_parse(), but we need it here
+ Usually lex_start() is called by mysql_parse(), but we need it here
as the present method does not call mysql_parse().
*/
- mysql_init_query(thd, 0, 0);
+ lex_start(thd);
+ mysql_reset_thd_for_next_command(thd);
+
if (!use_rli_only_for_errors)
{
/*
@@ -5873,7 +5876,7 @@ int Rows_log_event::do_apply_event(RELAY_LOG_INFO const *rli)
Table_map_log_event::do_apply_event() we don't call
mysql_init_query() as that may reset the binlog format.
*/
- lex_start(thd, NULL, 0);
+ lex_start(thd);
while ((error= lock_tables(thd, rli->tables_to_lock,
rli->tables_to_lock_count, &need_reopen)))
@@ -6516,7 +6519,8 @@ int Table_map_log_event::do_apply_event(RELAY_LOG_INFO const *rli)
initialized, so we should call lex_start(); to be even safer, we
call mysql_init_query() which does a more complete set of inits.
*/
- mysql_init_query(thd, NULL, 0);
+ lex_start(thd);
+ mysql_reset_thd_for_next_command(thd);
/*
Check if the slave is set to use SBR. If so, it should switch
to using RBR until the end of the "statement", i.e., next
diff --git a/sql/my_decimal.cc b/sql/my_decimal.cc
index 66c8d87e2e0..1f0ebf32795 100644
--- a/sql/my_decimal.cc
+++ b/sql/my_decimal.cc
@@ -208,6 +208,17 @@ my_decimal *date2my_decimal(MYSQL_TIME *ltime, my_decimal *dec)
}
+void my_decimal_trim(ulong *precision, uint *scale)
+{
+ if (!(*precision) && !(*scale))
+ {
+ *precision= 10;
+ *scale= 0;
+ return;
+ }
+}
+
+
#ifndef DBUG_OFF
/* routines for debugging print */
diff --git a/sql/my_decimal.h b/sql/my_decimal.h
index 284f6642b74..d6cefb3e080 100644
--- a/sql/my_decimal.h
+++ b/sql/my_decimal.h
@@ -394,5 +394,8 @@ int my_decimal_intg(const my_decimal *a)
}
+void my_decimal_trim(ulong *precision, uint *scale);
+
+
#endif /*my_decimal_h*/
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index a47da122bcc..71b8cc6d361 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -38,6 +38,7 @@
#include <queues.h>
#include "sql_bitmap.h"
#include "sql_array.h"
+#include "sql_plugin.h"
#include "scheduler.h"
/* TODO convert all these three maps to Bitmap classes */
@@ -258,9 +259,9 @@ MY_LOCALE *my_locale_by_number(uint number);
#define MAX_CONNECT_ERRORS 10 // errors before disabling host
#ifdef __NETWARE__
-#define IF_NETWARE(A,B) (A)
+#define IF_NETWARE(A,B) A
#else
-#define IF_NETWARE(A,B) (B)
+#define IF_NETWARE(A,B) B
#endif
#if defined(__WIN__)
@@ -547,11 +548,6 @@ inline THD *_current_thd(void)
}
#define current_thd _current_thd()
-/* below functions are required for plugins as THD class is opaque */
-my_bool thd_in_lock_tables(const THD *thd);
-my_bool thd_tablespace_op(const THD *thd);
-const char *thd_proc_info(THD *thd, const char *info);
-void **thd_ha_data(const THD *thd, const struct handlerton *hton);
/*
External variables
@@ -566,7 +562,6 @@ typedef my_bool (*qc_engine_callback)(THD *thd, char *table_key,
#include "sql_list.h"
#include "sql_map.h"
#include "my_decimal.h"
-#include "sql_plugin.h"
#include "handler.h"
#include "parse_file.h"
#include "table.h"
@@ -659,6 +654,8 @@ struct Query_cache_query_flags
ulong sql_mode;
ulong max_sort_length;
ulong group_concat_max_len;
+ ulong default_week_format;
+ ulong div_precision_increment;
MY_LOCALE *lc_time_names;
};
#define QUERY_CACHE_FLAGS_SIZE sizeof(Query_cache_query_flags)
@@ -794,8 +791,6 @@ check_and_unset_inject_value(int value)
#endif
-uint build_table_path(char *buff, size_t bufflen, const char *db,
- const char *table, const char *ext);
void write_bin_log(THD *thd, bool clear_error,
char const *query, ulong query_length);
@@ -838,13 +833,15 @@ bool do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db,
bool skip_error);
bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name,
bool force_switch);
-void mysql_parse(THD *thd,char *inBuf,uint length);
+
+void mysql_parse(THD *thd, const char *inBuf, uint length,
+ const char ** semicolon);
+
bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length);
bool is_update_query(enum enum_sql_command command);
bool alloc_query(THD *thd, const char *packet, uint packet_length);
void mysql_init_select(LEX *lex);
void mysql_reset_thd_for_next_command(THD *thd);
-void mysql_init_query(THD *thd, const char *buf, uint length);
bool mysql_new_select(LEX *lex, bool move_down);
void create_select_for_variable(const char *var_name);
void mysql_init_multi_delete(LEX *lex);
@@ -968,6 +965,12 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name,
List<create_field> &fields, List<Key> &keys,
bool tmp_table, uint select_field_count,
bool use_copy_create_info);
+bool mysql_create_table_no_lock(THD *thd, const char *db,
+ const char *table_name,
+ HA_CREATE_INFO *create_info,
+ List<create_field> &fields, List<Key> &keys,
+ bool tmp_table, uint select_field_count,
+ bool use_copy_create_info);
bool mysql_alter_table(THD *thd, char *new_db, char *new_name,
HA_CREATE_INFO *create_info,
@@ -1025,7 +1028,11 @@ TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update);
TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT* mem,
bool *refresh, uint flags);
-bool reopen_name_locked_table(THD* thd, TABLE_LIST* table);
+bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list, bool link_in);
+TABLE *table_cache_insert_placeholder(THD *thd, const char *key,
+ uint key_length);
+bool lock_table_name_if_not_cached(THD *thd, const char *db,
+ const char *table_name, TABLE **table);
TABLE *find_locked_table(THD *thd, const char *db,const char *table_name);
bool reopen_tables(THD *thd,bool get_locks,bool in_refresh);
bool close_data_tables(THD *thd,const char *db, const char *table_name);
@@ -1115,6 +1122,7 @@ int add_status_vars(SHOW_VAR *list);
void remove_status_vars(SHOW_VAR *list);
void init_status_vars();
void free_status_vars();
+void reset_status_vars();
/* information schema */
extern LEX_STRING INFORMATION_SCHEMA_NAME;
@@ -1193,7 +1201,9 @@ void add_join_on(TABLE_LIST *b,Item *expr);
void add_join_natural(TABLE_LIST *a,TABLE_LIST *b,List<String> *using_fields,
SELECT_LEX *lex);
bool add_proc_to_list(THD *thd, Item *item);
-TABLE *unlink_open_table(THD *thd,TABLE *list,TABLE *find);
+void unlink_open_table(THD *thd, TABLE *find, bool unlock);
+void drop_open_table(THD *thd, TABLE *table, const char *db_name,
+ const char *table_name);
void update_non_unique_table_error(TABLE_LIST *update,
const char *operation,
TABLE_LIST *duplicate);
@@ -1628,7 +1638,7 @@ extern double log_01[32];
extern ulonglong log_10_int[20];
extern ulonglong keybuff_size;
extern ulonglong thd_startup_options;
-extern ulong refresh_version, thread_id;
+extern ulong thread_id;
extern ulong binlog_cache_use, binlog_cache_disk_use;
extern ulong aborted_threads,aborted_connects;
extern ulong delayed_insert_timeout;
@@ -1711,6 +1721,7 @@ extern pthread_mutex_t LOCK_server_started;
extern pthread_cond_t COND_server_started;
extern int mysqld_server_started;
extern rw_lock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave;
+extern rw_lock_t LOCK_system_variables_hash;
extern pthread_cond_t COND_refresh, COND_thread_count, COND_manager;
extern pthread_cond_t COND_global_read_lock;
extern pthread_attr_t connection_attrib;
@@ -1719,7 +1730,7 @@ extern I_List<NAMED_LIST> key_caches;
extern MY_BITMAP temp_pool;
extern String my_empty_string;
extern const String my_null_string;
-extern SHOW_VAR init_vars[], status_vars[], internal_vars[];
+extern SHOW_VAR status_vars[];
extern struct system_variables global_system_variables;
extern struct system_variables max_system_variables;
extern struct system_status_var global_status_var;
@@ -1742,11 +1753,6 @@ extern TYPELIB log_output_typelib;
/* optional things, have_* variables */
-extern SHOW_COMP_OPTION have_innodb;
-extern SHOW_COMP_OPTION have_csv_db;
-extern SHOW_COMP_OPTION have_ndbcluster;
-extern SHOW_COMP_OPTION have_partition_db;
-
extern handlerton *partition_hton;
extern handlerton *myisam_hton;
extern handlerton *heap_hton;
@@ -1771,7 +1777,7 @@ MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **table, uint count,
#define MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK 0x0001
#define MYSQL_LOCK_IGNORE_FLUSH 0x0002
#define MYSQL_LOCK_NOTIFY_IF_NEED_REOPEN 0x0004
-#define MYSQL_OPEN_IGNORE_LOCKED_TABLES 0x0008
+#define MYSQL_OPEN_TEMPORARY_ONLY 0x0008
void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock);
void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock);
@@ -1877,6 +1883,8 @@ void make_date(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
void make_time(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
String *str);
int my_time_compare(MYSQL_TIME *a, MYSQL_TIME *b);
+ulonglong get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
+ Item *warn_item, bool *is_null);
int test_if_number(char *str,int *res,bool allow_wildcards);
void change_byte(uchar *,uint,char,char);
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 7a4601c34fd..be376a07c49 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -30,22 +30,13 @@
#include "rpl_injector.h"
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
-#define OPT_INNODB_DEFAULT 1
-#else
-#define OPT_INNODB_DEFAULT 0
-#endif
-#define OPT_BDB_DEFAULT 0
#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
-#define OPT_NDBCLUSTER_DEFAULT 0
#if defined(NOT_ENOUGH_TESTED) \
&& defined(NDB_SHM_TRANSPORTER) && MYSQL_VERSION_ID >= 50000
#define OPT_NDB_SHM_DEFAULT 1
#else
#define OPT_NDB_SHM_DEFAULT 0
#endif
-#else
-#define OPT_NDBCLUSTER_DEFAULT 0
#endif
#ifndef DEFAULT_SKIP_THREAD_PRIORITY
@@ -326,7 +317,6 @@ static bool lower_case_table_names_used= 0;
static bool volatile select_thread_in_use, signal_thread_in_use;
static bool volatile ready_to_exit;
static my_bool opt_debugging= 0, opt_external_locking= 0, opt_console= 0;
-static my_bool opt_ndbcluster;
static my_bool opt_short_log_format= 0;
static uint kill_cached_threads, wake_thread;
static ulong killed_threads, thread_created;
@@ -370,7 +360,6 @@ my_bool opt_local_infile, opt_slave_compressed_protocol;
my_bool opt_safe_user_create = 0, opt_no_mix_types = 0;
my_bool opt_show_slave_auth_info, opt_sql_bin_update = 0;
my_bool opt_log_slave_updates= 0;
-my_bool opt_innodb;
bool slave_warning_issued = false;
/*
@@ -380,49 +369,10 @@ handlerton *heap_hton;
handlerton *myisam_hton;
handlerton *partition_hton;
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
-extern ulong innobase_fast_shutdown;
-extern ulong innobase_large_page_size;
-extern char *innobase_home, *innobase_tmpdir, *innobase_logdir;
-extern long innobase_lock_scan_time;
-extern long innobase_mirrored_log_groups, innobase_log_files_in_group;
-extern longlong innobase_log_file_size;
-extern long innobase_log_buffer_size;
-extern longlong innobase_buffer_pool_size;
-extern long innobase_additional_mem_pool_size;
-extern long innobase_file_io_threads, innobase_lock_wait_timeout;
-extern long innobase_force_recovery;
-extern long innobase_open_files;
-extern char *innobase_data_home_dir, *innobase_data_file_path;
-extern char *innobase_log_group_home_dir, *innobase_log_arch_dir;
-extern char *innobase_unix_file_flush_method;
-/* The following variables have to be my_bool for SHOW VARIABLES to work */
-extern my_bool innobase_log_archive,
- innobase_use_doublewrite,
- innobase_use_checksums,
- innobase_use_large_pages,
- innobase_use_native_aio,
- innobase_file_per_table, innobase_locks_unsafe_for_binlog,
- innobase_rollback_on_timeout,
- innobase_stats_on_metadata,
- innobase_create_status_file;
-extern "C" {
-extern ulong srv_max_buf_pool_modified_pct;
-extern ulong srv_max_purge_lag;
-extern ulong srv_auto_extend_increment;
-extern ulong srv_n_spin_wait_rounds;
-extern ulong srv_n_free_tickets_to_enter;
-extern ulong srv_thread_sleep_delay;
-extern ulong srv_thread_concurrency;
-extern ulong srv_commit_concurrency;
-extern ulong srv_flush_log_at_trx_commit;
-}
-#endif
-
#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
const char *opt_ndbcluster_connectstring= 0;
const char *opt_ndb_connectstring= 0;
-char opt_ndb_constrbuf[1024];
+char opt_ndb_constrbuf[1024]= {0};
unsigned opt_ndb_constrbuf_len= 0;
my_bool opt_ndb_shm, opt_ndb_optimized_node_selection;
ulong opt_ndb_cache_check_time;
@@ -459,7 +409,7 @@ my_bool opt_noacl;
my_bool sp_automatic_privileges= 1;
ulong opt_binlog_rows_event_max_size;
-const char *binlog_format_names[]= {"STATEMENT", "ROW", "MIXED", NullS};
+const char *binlog_format_names[]= {"MIXED", "STATEMENT", "ROW", NullS};
TYPELIB binlog_format_typelib=
{ array_elements(binlog_format_names) - 1, "",
binlog_format_names, NULL };
@@ -604,6 +554,7 @@ pthread_mutex_t LOCK_prepared_stmt_count;
pthread_mutex_t LOCK_des_key_file;
#endif
rw_lock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave;
+rw_lock_t LOCK_system_variables_hash;
pthread_cond_t COND_refresh, COND_thread_count, COND_global_read_lock;
pthread_t signal_thread;
pthread_attr_t connection_attrib;
@@ -635,6 +586,7 @@ static ulong opt_specialflag, opt_myisam_block_size;
static char *opt_update_logname, *opt_binlog_index_name;
static char *opt_tc_heuristic_recover;
static char *mysql_home_ptr, *pidfile_name_ptr;
+static int defaults_argc;
static char **defaults_argv;
static char *opt_bin_logname;
@@ -727,7 +679,8 @@ struct st_VioSSLFd *ssl_acceptor_fd;
pthread_handler_t signal_hand(void *arg);
static void mysql_init_variables(void);
-static void get_options(int argc,char **argv);
+static void get_options(int *argc,char **argv);
+static my_bool get_one_option(int, const struct my_option *, char *);
static void set_server_version(void);
static int init_thread_environment();
static char *get_relative_path(const char *path);
@@ -750,6 +703,7 @@ static void clean_up(bool print_message);
static int test_if_case_insensitive(const char *dir_name);
#ifndef EMBEDDED_LIBRARY
+static void usage(void);
static void start_signal_handler(void);
static void close_server_sock();
static void clean_up_mutexes(void);
@@ -1175,6 +1129,8 @@ extern "C" void unireg_abort(int exit_code)
DBUG_ENTER("unireg_abort");
if (exit_code)
sql_print_error("Aborting\n");
+ else if (opt_help)
+ usage();
clean_up(exit_code || !opt_bootstrap); /* purecov: inspected */
DBUG_PRINT("quit",("done with cleanup in unireg_abort"));
wait_for_signal_thread_to_end();
@@ -1360,6 +1316,7 @@ static void clean_up_mutexes()
(void) rwlock_destroy(&LOCK_sys_init_connect);
(void) rwlock_destroy(&LOCK_sys_init_slave);
(void) pthread_mutex_destroy(&LOCK_global_system_variables);
+ (void) rwlock_destroy(&LOCK_system_variables_hash);
(void) pthread_mutex_destroy(&LOCK_global_read_lock);
(void) pthread_mutex_destroy(&LOCK_uuid_generator);
(void) pthread_mutex_destroy(&LOCK_prepared_stmt_count);
@@ -1378,6 +1335,7 @@ static void clean_up_mutexes()
** Init IP and UNIX socket
****************************************************************************/
+#ifndef EMBEDDED_LIBRARY
static void set_ports()
{
char *env;
@@ -1402,7 +1360,6 @@ static void set_ports()
}
}
-#ifndef EMBEDDED_LIBRARY
/* Change to run as another user if started with --user */
static struct passwd *check_user(const char *user)
@@ -2360,7 +2317,7 @@ static void init_signals(void)
sigaddset(&set,SIGTSTP);
#endif
if (thd_lib_detected != THD_LIB_LT)
- sigaddset(&set,THR_SERVER_ALARM);
+ sigaddset(&set,THR_SERVER_ALARM);
if (test_flags & TEST_SIGINT)
{
// May be SIGINT
@@ -2661,16 +2618,18 @@ int STDCALL handle_kill(ulong ctrl_type)
}
#endif
+#if !defined(EMBEDDED_LIBRARY)
static const char *load_default_groups[]= {
#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
"mysql_cluster",
#endif
"mysqld","server", MYSQL_BASE_VERSION, 0, 0};
-#if defined(__WIN__) && !defined(EMBEDDED_LIBRARY)
+#if defined(__WIN__)
static const int load_default_groups_sz=
sizeof(load_default_groups)/sizeof(load_default_groups[0]);
#endif
+#endif /*!EMBEDDED_LIBRARY*/
/*
@@ -2718,7 +2677,7 @@ static bool init_global_datetime_format(timestamp_type format_type,
static int init_common_variables(const char *conf_file_name, int argc,
char **argv, const char **groups)
{
- char buff[FN_REFLEN];
+ char buff[FN_REFLEN], *s;
umask(((~my_umask) & 0666));
my_decimal_set_zero(&decimal_zero); // set decimal_zero constant;
tzset(); // Set tzname
@@ -2770,7 +2729,7 @@ static int init_common_variables(const char *conf_file_name, int argc,
strmake(pidfile_name, STRING_WITH_LEN("mysql"));
}
else
- strmake(pidfile_name, glob_hostname, sizeof(pidfile_name)-5);
+ strmake(pidfile_name, glob_hostname, sizeof(pidfile_name)-5);
strmov(fn_ext(pidfile_name),".pid"); // Add proper extension
/*
@@ -2784,7 +2743,8 @@ static int init_common_variables(const char *conf_file_name, int argc,
load_defaults(conf_file_name, groups, &argc, &argv);
defaults_argv=argv;
- get_options(argc,argv);
+ defaults_argc=argc;
+ get_options(&defaults_argc, defaults_argv);
set_server_version();
DBUG_PRINT("info",("%s Ver %s for %s on %s\n",my_progname,
@@ -2796,10 +2756,6 @@ static int init_common_variables(const char *conf_file_name, int argc,
{
my_use_large_pages= 1;
my_large_page_size= opt_large_page_size;
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
- innobase_use_large_pages= 1;
- innobase_large_page_size= opt_large_page_size;
-#endif
}
#endif /* HAVE_LARGE_PAGES */
@@ -2862,7 +2818,12 @@ static int init_common_variables(const char *conf_file_name, int argc,
if (item_create_init())
return 1;
item_init();
- set_var_init();
+ if (set_var_init())
+ return 1;
+#ifdef HAVE_REPLICATION
+ if (init_replication_sys_vars())
+ return 1;
+#endif
mysys_uses_curses=0;
#ifdef USE_REGEX
my_regex_init(&my_charset_latin1);
@@ -2959,15 +2920,13 @@ static int init_common_variables(const char *conf_file_name, int argc,
"--log-slow-queries option, log tables are used. "
"To enable logging to files use the --log-output option.");
- if (!opt_logname)
- opt_logname= make_default_log_name(buff, ".log");
- sys_var_general_log_path.value= my_strdup(opt_logname, MYF(0));
- sys_var_general_log_path.value_length= strlen(opt_logname);
+ s= opt_logname ? opt_logname : make_default_log_name(buff, ".log");
+ sys_var_general_log_path.value= my_strdup(s, MYF(0));
+ sys_var_general_log_path.value_length= strlen(s);
- if (!opt_slow_logname)
- opt_slow_logname= make_default_log_name(buff, "-slow.log");
- sys_var_slow_log_path.value= my_strdup(opt_slow_logname, MYF(0));
- sys_var_slow_log_path.value_length= strlen(opt_slow_logname);
+ s= opt_slow_logname ? opt_slow_logname : make_default_log_name(buff, "-slow.log");
+ sys_var_slow_log_path.value= my_strdup(s, MYF(0));
+ sys_var_slow_log_path.value_length= strlen(s);
if (use_temp_pool && bitmap_init(&temp_pool,0,1024,1))
return 1;
@@ -3046,6 +3005,7 @@ static int init_thread_environment()
(void) pthread_mutex_init(&LOCK_user_conn, MY_MUTEX_INIT_FAST);
(void) pthread_mutex_init(&LOCK_active_mi, MY_MUTEX_INIT_FAST);
(void) pthread_mutex_init(&LOCK_global_system_variables, MY_MUTEX_INIT_FAST);
+ (void) my_rwlock_init(&LOCK_system_variables_hash, NULL);
(void) pthread_mutex_init(&LOCK_global_read_lock, MY_MUTEX_INIT_FAST);
(void) pthread_mutex_init(&LOCK_prepared_stmt_count, MY_MUTEX_INIT_FAST);
(void) pthread_mutex_init(&LOCK_uuid_generator, MY_MUTEX_INIT_FAST);
@@ -3233,8 +3193,12 @@ static int init_server_components()
/* Setup logs */
- /* enable old-fashioned error log */
- if (opt_error_log)
+ /*
+ Enable old-fashioned error log, except when the user has requested
+ help information. Since the implementation of plugin server
+ variables the help output is now written much later.
+ */
+ if (opt_error_log && !opt_help)
{
if (!log_error_file_ptr[0])
fn_format(log_error_file, pidfile_name, mysql_data_home, ".err",
@@ -3320,13 +3284,13 @@ with --log-bin instead.");
}
if (!opt_bin_log)
if (opt_binlog_format_id != BINLOG_FORMAT_UNSPEC)
- {
- sql_print_error("You need to use --log-bin to make "
- "--binlog-format work.");
- unireg_abort(1);
- }
+ {
+ sql_print_error("You need to use --log-bin to make "
+ "--binlog-format work.");
+ unireg_abort(1);
+ }
else
- {
+ {
global_system_variables.binlog_format= BINLOG_FORMAT_UNSPEC;
}
else
@@ -3335,7 +3299,7 @@ with --log-bin instead.");
else
{
DBUG_ASSERT(global_system_variables.binlog_format != BINLOG_FORMAT_UNSPEC);
- }
+ }
/* Check that we have not let the format to unspecified at this point */
DBUG_ASSERT((uint)global_system_variables.binlog_format <=
@@ -3389,12 +3353,51 @@ server.");
using_update_log=1;
}
- if (plugin_init(opt_bootstrap))
+ if (plugin_init(&defaults_argc, defaults_argv,
+ (opt_noacl ? PLUGIN_INIT_SKIP_PLUGIN_TABLE : 0) |
+ (opt_help ? PLUGIN_INIT_SKIP_INITIALIZATION : 0)))
{
- sql_print_error("Failed to init plugins.");
- return 1;
+ sql_print_error("Failed to initialize plugins.");
+ unireg_abort(1);
}
+ if (opt_help)
+ unireg_abort(0);
+
+ /* we do want to exit if there are any other unknown options */
+ if (defaults_argc > 1)
+ {
+ int ho_error;
+ char **tmp_argv= defaults_argv;
+ struct my_option no_opts[]=
+ {
+ {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
+ };
+ /*
+ We need to eat any 'loose' arguments first before we conclude
+ that there are unprocessed options.
+ But we need to preserve defaults_argv pointer intact for
+ free_defaults() to work. Thus we use a copy here.
+ */
+ my_getopt_skip_unknown= 0;
+
+ if ((ho_error= handle_options(&defaults_argc, &tmp_argv, no_opts,
+ get_one_option)))
+ unireg_abort(ho_error);
+
+ if (defaults_argc)
+ {
+ fprintf(stderr, "%s: Too many arguments (first extra is '%s').\n"
+ "Use --verbose --help to get a list of available options\n",
+ my_progname, *tmp_argv);
+ unireg_abort(1);
+ }
+ }
+
+ /* if the errmsg.sys is not loaded, terminate to maintain behaviour */
+ if (!errmesg[0][0])
+ unireg_abort(1);
+
/* We have to initialize the storage engines before CSV logging */
if (ha_init())
{
@@ -3423,7 +3426,8 @@ server.");
else
{
/* fall back to the log files if tables are not present */
- if (have_csv_db == SHOW_OPTION_NO)
+ LEX_STRING csv_name={C_STRING_WITH_LEN("csv")};
+ if (!plugin_is_ready(&csv_name, MYSQL_STORAGE_ENGINE_PLUGIN))
{
/* purecov: begin inspected */
sql_print_error("CSV engine is not present, falling back to the "
@@ -3443,11 +3447,16 @@ server.");
/*
Check that the default storage engine is actually available.
*/
+ if (default_storage_engine_str)
{
LEX_STRING name= { default_storage_engine_str,
strlen(default_storage_engine_str) };
- handlerton *hton= ha_resolve_by_name(0, &name);
- if (hton == NULL)
+ plugin_ref plugin;
+ handlerton *hton;
+
+ if ((plugin= ha_resolve_by_name(0, &name)))
+ hton= plugin_data(plugin, handlerton*);
+ else
{
sql_print_error("Unknown/unsupported table type: %s",
default_storage_engine_str);
@@ -3461,9 +3470,17 @@ server.");
default_storage_engine_str);
unireg_abort(1);
}
- hton= myisam_hton;
+ DBUG_ASSERT(global_system_variables.table_plugin);
+ }
+ else
+ {
+ /*
+ Need to unlock as global_system_variables.table_plugin
+ was acquired during plugin_init()
+ */
+ plugin_unlock(0, global_system_variables.table_plugin);
+ global_system_variables.table_plugin= plugin;
}
- global_system_variables.table_type= hton;
}
tc_log= (total_ha_2pc > 1 ? (opt_bin_log ?
@@ -3489,7 +3506,7 @@ server.");
#ifdef HAVE_REPLICATION
if (opt_bin_log && expire_logs_days)
{
- long purge_time= (long) (time(0) - expire_logs_days*24*60*60);
+ time_t purge_time= time(0) - expire_logs_days*24*60*60;
if (purge_time >= 0)
mysql_bin_log.purge_logs_before_date(purge_time);
}
@@ -3740,7 +3757,7 @@ int main(int argc, char **argv)
We have enough space for fiddling with the argv, continue
*/
check_data_home(mysql_real_data_home);
- if (my_setwd(mysql_real_data_home,MYF(MY_WME)))
+ if (my_setwd(mysql_real_data_home,MYF(MY_WME)) && !opt_help)
unireg_abort(1); /* purecov: inspected */
mysql_data_home= mysql_data_home_buff;
mysql_data_home[0]=FN_CURLIB; // all paths are relative from here
@@ -4874,11 +4891,6 @@ enum options_mysqld
OPT_STORAGE_ENGINE, OPT_INIT_FILE,
OPT_DELAY_KEY_WRITE_ALL, OPT_SLOW_QUERY_LOG,
OPT_DELAY_KEY_WRITE, OPT_CHARSETS_DIR,
- OPT_BDB_HOME, OPT_BDB_LOG,
- OPT_BDB_TMP, OPT_BDB_SYNC,
- OPT_BDB_LOCK, OPT_BDB,
- OPT_BDB_NO_RECOVER, OPT_BDB_SHARED,
- OPT_BDB_DATA_DIRECT, OPT_BDB_LOG_DIRECT,
OPT_MASTER_HOST, OPT_MASTER_USER,
OPT_MASTER_PASSWORD, OPT_MASTER_PORT,
OPT_MASTER_INFO_FILE, OPT_MASTER_CONNECT_RETRY,
@@ -4897,28 +4909,14 @@ enum options_mysqld
OPT_WANT_CORE, OPT_CONCURRENT_INSERT,
OPT_MEMLOCK, OPT_MYISAM_RECOVER,
OPT_REPLICATE_REWRITE_DB, OPT_SERVER_ID,
- OPT_SKIP_SLAVE_START, OPT_SKIP_INNOBASE,
+ OPT_SKIP_SLAVE_START, OPT_SAFE_SHOW_DB,
OPT_SAFEMALLOC_MEM_LIMIT, OPT_REPLICATE_DO_TABLE,
OPT_REPLICATE_IGNORE_TABLE, OPT_REPLICATE_WILD_DO_TABLE,
OPT_REPLICATE_WILD_IGNORE_TABLE, OPT_REPLICATE_SAME_SERVER_ID,
OPT_DISCONNECT_SLAVE_EVENT_COUNT, OPT_TC_HEURISTIC_RECOVER,
OPT_ABORT_SLAVE_EVENT_COUNT,
- OPT_INNODB_DATA_HOME_DIR,
- OPT_INNODB_DATA_FILE_PATH,
- OPT_INNODB_LOG_GROUP_HOME_DIR,
- OPT_INNODB_LOG_ARCH_DIR,
- OPT_INNODB_LOG_ARCHIVE,
- OPT_INNODB_FLUSH_LOG_AT_TRX_COMMIT,
- OPT_INNODB_FLUSH_METHOD,
- OPT_INNODB_DOUBLEWRITE,
- OPT_INNODB_CHECKSUMS,
- OPT_INNODB_FAST_SHUTDOWN,
- OPT_INNODB_FILE_PER_TABLE, OPT_CRASH_BINLOG_INNODB,
- OPT_INNODB_LOCKS_UNSAFE_FOR_BINLOG,
OPT_LOG_BIN_TRUST_FUNCTION_CREATORS,
- OPT_SAFE_SHOW_DB, OPT_INNODB_SAFE_BINLOG,
- OPT_INNODB, OPT_ISAM,
- OPT_ENGINE_CONDITION_PUSHDOWN, OPT_NDBCLUSTER, OPT_NDB_CONNECTSTRING,
+ OPT_ENGINE_CONDITION_PUSHDOWN, OPT_NDB_CONNECTSTRING,
OPT_NDB_USE_EXACT_COUNT, OPT_NDB_USE_TRANSACTIONS,
OPT_NDB_FORCE_SEND, OPT_NDB_AUTOINCREMENT_PREFETCH_SZ,
OPT_NDB_SHM, OPT_NDB_OPTIMIZED_NODE_SELECTION, OPT_NDB_CACHE_CHECK_TIME,
@@ -4981,34 +4979,6 @@ enum options_mysqld
OPT_THREAD_CONCURRENCY, OPT_THREAD_CACHE_SIZE,
OPT_TMP_TABLE_SIZE, OPT_THREAD_STACK,
OPT_WAIT_TIMEOUT, OPT_MYISAM_REPAIR_THREADS,
- OPT_INNODB_MIRRORED_LOG_GROUPS,
- OPT_INNODB_LOG_FILES_IN_GROUP,
- OPT_INNODB_LOG_FILE_SIZE,
- OPT_INNODB_LOG_BUFFER_SIZE,
- OPT_INNODB_BUFFER_POOL_SIZE,
- OPT_INNODB_BUFFER_POOL_AWE_MEM_MB,
- OPT_INNODB_ADDITIONAL_MEM_POOL_SIZE,
- OPT_INNODB_MAX_PURGE_LAG,
- OPT_INNODB_FILE_IO_THREADS,
- OPT_INNODB_LOCK_WAIT_TIMEOUT,
- OPT_INNODB_THREAD_CONCURRENCY,
- OPT_INNODB_COMMIT_CONCURRENCY,
- OPT_INNODB_FORCE_RECOVERY,
- OPT_INNODB_STATUS_FILE,
- OPT_INNODB_MAX_DIRTY_PAGES_PCT,
- OPT_INNODB_TABLE_LOCKS,
- OPT_INNODB_SUPPORT_XA,
- OPT_INNODB_OPEN_FILES,
- OPT_INNODB_AUTOEXTEND_INCREMENT,
- OPT_INNODB_SYNC_SPIN_LOOPS,
- OPT_INNODB_CONCURRENCY_TICKETS,
- OPT_INNODB_THREAD_SLEEP_DELAY,
- OPT_INNODB_STATS_ON_METADATA,
- OPT_BDB_CACHE_SIZE,
- OPT_BDB_CACHE_PARTS,
- OPT_BDB_LOG_BUFFER_SIZE,
- OPT_BDB_MAX_LOCK,
- OPT_BDB_REGION_SIZE,
OPT_ERROR_LOG_FILE,
OPT_DEFAULT_WEEK_FORMAT,
OPT_RANGE_ALLOC_BLOCK_SIZE, OPT_ALLOW_SUSPICIOUS_UDFS,
@@ -5018,7 +4988,6 @@ enum options_mysqld
OPT_SYNC_REPLICATION,
OPT_SYNC_REPLICATION_SLAVE_ID,
OPT_SYNC_REPLICATION_TIMEOUT,
- OPT_BDB_NOSYNC,
OPT_ENABLE_SHARED_MEMORY,
OPT_SHARED_MEMORY_BASE_NAME,
OPT_OLD_PASSWORDS,
@@ -5049,12 +5018,12 @@ enum options_mysqld
OPT_OLD_STYLE_USER_LIMITS,
OPT_LOG_SLOW_ADMIN_STATEMENTS,
OPT_TABLE_LOCK_WAIT_TIMEOUT,
+ OPT_PLUGIN_LOAD,
OPT_PLUGIN_DIR,
OPT_LOG_OUTPUT,
OPT_PORT_OPEN_TIMEOUT,
OPT_GENERAL_LOG,
OPT_SLOW_LOG,
- OPT_MERGE,
OPT_THREAD_HANDLING,
OPT_INNODB_ROLLBACK_ON_TIMEOUT,
OPT_SECURE_FILE_PRIV,
@@ -5121,8 +5090,7 @@ struct my_option my_long_options[] =
" to 'row' and back implicitly per each query accessing a NDB table."
#endif
,(uchar**) &opt_binlog_format, (uchar**) &opt_binlog_format,
- 0, GET_STR, REQUIRED_ARG, BINLOG_FORMAT_MIXED, BINLOG_FORMAT_STMT,
- BINLOG_FORMAT_MIXED, 0, 0, 0},
+ 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"binlog-do-db", OPT_BINLOG_DO_DB,
"Tells the master it should log updates for the specified database, and exclude all others not explicitly mentioned.",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -5276,99 +5244,7 @@ Disable with --skip-large-pages.",
{"init-slave", OPT_INIT_SLAVE, "Command(s) that are executed when a slave connects to this master",
(uchar**) &opt_init_slave, (uchar**) &opt_init_slave, 0, GET_STR_ALLOC,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
- {"innodb", OPT_INNODB, "Enable InnoDB (if this version of MySQL supports it). \
-Disable with --skip-innodb (will save memory).",
- (uchar**) &opt_innodb, (uchar**) &opt_innodb, 0, GET_BOOL, NO_ARG, OPT_INNODB_DEFAULT, 0, 0,
- 0, 0, 0},
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
- {"innodb_checksums", OPT_INNODB_CHECKSUMS, "Enable InnoDB checksums validation (enabled by default). \
-Disable with --skip-innodb-checksums.", (uchar**) &innobase_use_checksums,
- (uchar**) &innobase_use_checksums, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
-#endif
- {"innodb_data_file_path", OPT_INNODB_DATA_FILE_PATH,
- "Path to individual files and their sizes.",
- 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
- {"innodb_data_home_dir", OPT_INNODB_DATA_HOME_DIR,
- "The common part for InnoDB table spaces.", (uchar**) &innobase_data_home_dir,
- (uchar**) &innobase_data_home_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0,
- 0},
- {"innodb_doublewrite", OPT_INNODB_DOUBLEWRITE, "Enable InnoDB doublewrite buffer (enabled by default). \
-Disable with --skip-innodb-doublewrite.", (uchar**) &innobase_use_doublewrite,
- (uchar**) &innobase_use_doublewrite, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
- {"innodb_fast_shutdown", OPT_INNODB_FAST_SHUTDOWN,
- "Speeds up the shutdown process of the InnoDB storage engine. Possible "
- "values are 0, 1 (faster)"
- /*
- NetWare can't close unclosed files, can't automatically kill remaining
- threads, etc, so on this OS we disable the crash-like InnoDB shutdown.
- */
-#ifndef __NETWARE__
- " or 2 (fastest - crash-like)"
-#endif
- ".",
- (uchar**) &innobase_fast_shutdown,
- (uchar**) &innobase_fast_shutdown, 0, GET_ULONG, OPT_ARG, 1, 0,
- IF_NETWARE(1,2), 0, 0, 0},
- {"innodb_file_per_table", OPT_INNODB_FILE_PER_TABLE,
- "Stores each InnoDB table to an .ibd file in the database dir.",
- (uchar**) &innobase_file_per_table,
- (uchar**) &innobase_file_per_table, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
- {"innodb_flush_log_at_trx_commit", OPT_INNODB_FLUSH_LOG_AT_TRX_COMMIT,
- "Set to 0 (write and flush once per second), 1 (write and flush at each commit) or 2 (write at commit, flush once per second).",
- (uchar**) &srv_flush_log_at_trx_commit,
- (uchar**) &srv_flush_log_at_trx_commit,
- 0, GET_ULONG, OPT_ARG, 1, 0, 2, 0, 0, 0},
- {"innodb_flush_method", OPT_INNODB_FLUSH_METHOD,
- "With which method to flush data.", (uchar**) &innobase_unix_file_flush_method,
- (uchar**) &innobase_unix_file_flush_method, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
- 0, 0, 0},
- {"innodb_locks_unsafe_for_binlog", OPT_INNODB_LOCKS_UNSAFE_FOR_BINLOG,
- "Force InnoDB to not use next-key locking, to use only row-level locking.",
- (uchar**) &innobase_locks_unsafe_for_binlog,
- (uchar**) &innobase_locks_unsafe_for_binlog, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
- {"innodb_log_arch_dir", OPT_INNODB_LOG_ARCH_DIR,
- "Where full logs should be archived.", (uchar**) &innobase_log_arch_dir,
- (uchar**) &innobase_log_arch_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
- {"innodb_log_archive", OPT_INNODB_LOG_ARCHIVE,
- "Set to 1 if you want to have logs archived.", 0, 0, 0, GET_LONG, OPT_ARG,
- 0, 0, 0, 0, 0, 0},
- {"innodb_log_group_home_dir", OPT_INNODB_LOG_GROUP_HOME_DIR,
- "Path to InnoDB log files.", (uchar**) &innobase_log_group_home_dir,
- (uchar**) &innobase_log_group_home_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0,
- 0, 0},
- {"innodb_max_dirty_pages_pct", OPT_INNODB_MAX_DIRTY_PAGES_PCT,
- "Percentage of dirty pages allowed in bufferpool.", (uchar**) &srv_max_buf_pool_modified_pct,
- (uchar**) &srv_max_buf_pool_modified_pct, 0, GET_ULONG, REQUIRED_ARG, 90, 0, 100, 0, 0, 0},
- {"innodb_max_purge_lag", OPT_INNODB_MAX_PURGE_LAG,
- "Desired maximum length of the purge queue (0 = no limit)",
- (uchar**) &srv_max_purge_lag,
- (uchar**) &srv_max_purge_lag, 0, GET_LONG, REQUIRED_ARG, 0, 0, ~0L,
- 0, 1L, 0},
- {"innodb_rollback_on_timeout", OPT_INNODB_ROLLBACK_ON_TIMEOUT,
- "Roll back the complete transaction on lock wait timeout, for 4.x compatibility (disabled by default)",
- (uchar**) &innobase_rollback_on_timeout, (uchar**) &innobase_rollback_on_timeout,
- 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
- {"innodb_status_file", OPT_INNODB_STATUS_FILE,
- "Enable SHOW INNODB STATUS output in the innodb_status.<pid> file",
- (uchar**) &innobase_create_status_file, (uchar**) &innobase_create_status_file,
- 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
- {"innodb_stats_on_metadata", OPT_INNODB_STATS_ON_METADATA,
- "Enable statistics gathering for metadata commands such as SHOW TABLE STATUS (on by default)",
- (uchar**) &innobase_stats_on_metadata, (uchar**) &innobase_stats_on_metadata,
- 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
- {"innodb_support_xa", OPT_INNODB_SUPPORT_XA,
- "Enable InnoDB support for the XA two-phase commit",
- (uchar**) &global_system_variables.innodb_support_xa,
- (uchar**) &global_system_variables.innodb_support_xa,
- 0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, 0},
- {"innodb_table_locks", OPT_INNODB_TABLE_LOCKS,
- "Enable InnoDB locking in LOCK TABLES",
- (uchar**) &global_system_variables.innodb_table_locks,
- (uchar**) &global_system_variables.innodb_table_locks,
- 0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, 0},
-#endif /* End WITH_INNOBASE_STORAGE_ENGINE */
- {"language", 'L',
+ {"language", 'L',
"Client error messages in given language. May be given as a full path.",
(uchar**) &language_ptr, (uchar**) &language_ptr, 0, GET_STR, REQUIRED_ARG,
0, 0, 0, 0, 0, 0},
@@ -5546,10 +5422,6 @@ master-ssl",
"Syntax: myisam-recover[=option[,option...]], where option can be DEFAULT, BACKUP, FORCE or QUICK.",
(uchar**) &myisam_recover_options_str, (uchar**) &myisam_recover_options_str, 0,
GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
- {"ndbcluster", OPT_NDBCLUSTER, "Enable NDB Cluster (if this version of MySQL supports it). \
-Disable with --skip-ndbcluster (will save memory).",
- (uchar**) &opt_ndbcluster, (uchar**) &opt_ndbcluster, 0, GET_BOOL, NO_ARG,
- OPT_NDBCLUSTER_DEFAULT, 0, 0, 0, 0, 0},
#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
{"ndb-connectstring", OPT_NDB_CONNECTSTRING,
"Connect string for ndbcluster.",
@@ -6009,84 +5881,6 @@ log and this option does nothing anymore.",
(uchar**) &global_system_variables.group_concat_max_len,
(uchar**) &max_system_variables.group_concat_max_len, 0, GET_ULONG,
REQUIRED_ARG, 1024, 4, (long) ~0, 0, 1, 0},
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
- {"innodb_additional_mem_pool_size", OPT_INNODB_ADDITIONAL_MEM_POOL_SIZE,
- "Size of a memory pool InnoDB uses to store data dictionary information and other internal data structures.",
- (uchar**) &innobase_additional_mem_pool_size,
- (uchar**) &innobase_additional_mem_pool_size, 0, GET_LONG, REQUIRED_ARG,
- 1*1024*1024L, 512*1024L, ~0L, 0, 1024, 0},
- {"innodb_autoextend_increment", OPT_INNODB_AUTOEXTEND_INCREMENT,
- "Data file autoextend increment in megabytes",
- (uchar**) &srv_auto_extend_increment,
- (uchar**) &srv_auto_extend_increment,
- 0, GET_LONG, REQUIRED_ARG, 8L, 1L, 1000L, 0, 1L, 0},
- {"innodb_buffer_pool_size", OPT_INNODB_BUFFER_POOL_SIZE,
- "The size of the memory buffer InnoDB uses to cache data and indexes of its tables.",
- (uchar**) &innobase_buffer_pool_size, (uchar**) &innobase_buffer_pool_size, 0,
- GET_LL, REQUIRED_ARG, 8*1024*1024L, 1024*1024L, LONGLONG_MAX, 0,
- 1024*1024L, 0},
- {"innodb_commit_concurrency", OPT_INNODB_COMMIT_CONCURRENCY,
- "Helps in performance tuning in heavily concurrent environments.",
- (uchar**) &srv_commit_concurrency, (uchar**) &srv_commit_concurrency,
- 0, GET_LONG, REQUIRED_ARG, 0, 0, 1000, 0, 1, 0},
- {"innodb_concurrency_tickets", OPT_INNODB_CONCURRENCY_TICKETS,
- "Number of times a thread is allowed to enter InnoDB within the same \
- SQL query after it has once got the ticket",
- (uchar**) &srv_n_free_tickets_to_enter,
- (uchar**) &srv_n_free_tickets_to_enter,
- 0, GET_LONG, REQUIRED_ARG, 500L, 1L, ~0L, 0, 1L, 0},
- {"innodb_file_io_threads", OPT_INNODB_FILE_IO_THREADS,
- "Number of file I/O threads in InnoDB.", (uchar**) &innobase_file_io_threads,
- (uchar**) &innobase_file_io_threads, 0, GET_LONG, REQUIRED_ARG, 4, 4, 64, 0,
- 1, 0},
- {"innodb_force_recovery", OPT_INNODB_FORCE_RECOVERY,
- "Helps to save your data in case the disk image of the database becomes corrupt.",
- (uchar**) &innobase_force_recovery, (uchar**) &innobase_force_recovery, 0,
- GET_LONG, REQUIRED_ARG, 0, 0, 6, 0, 1, 0},
- {"innodb_lock_wait_timeout", OPT_INNODB_LOCK_WAIT_TIMEOUT,
- "Timeout in seconds an InnoDB transaction may wait for a lock before being rolled back.",
- (uchar**) &innobase_lock_wait_timeout, (uchar**) &innobase_lock_wait_timeout,
- 0, GET_LONG, REQUIRED_ARG, 50, 1, 1024 * 1024 * 1024, 0, 1, 0},
- {"innodb_log_buffer_size", OPT_INNODB_LOG_BUFFER_SIZE,
- "The size of the buffer which InnoDB uses to write log to the log files on disk.",
- (uchar**) &innobase_log_buffer_size, (uchar**) &innobase_log_buffer_size, 0,
- GET_LONG, REQUIRED_ARG, 1024*1024L, 256*1024L, ~0L, 0, 1024, 0},
- {"innodb_log_file_size", OPT_INNODB_LOG_FILE_SIZE,
- "Size of each log file in a log group.",
- (uchar**) &innobase_log_file_size, (uchar**) &innobase_log_file_size, 0,
- GET_LL, REQUIRED_ARG, 5*1024*1024L, 1*1024*1024L, LONGLONG_MAX, 0,
- 1024*1024L, 0},
- {"innodb_log_files_in_group", OPT_INNODB_LOG_FILES_IN_GROUP,
- "Number of log files in the log group. InnoDB writes to the files in a circular fashion. Value 3 is recommended here.",
- (uchar**) &innobase_log_files_in_group, (uchar**) &innobase_log_files_in_group,
- 0, GET_LONG, REQUIRED_ARG, 2, 2, 100, 0, 1, 0},
- {"innodb_mirrored_log_groups", OPT_INNODB_MIRRORED_LOG_GROUPS,
- "Number of identical copies of log groups we keep for the database. Currently this should be set to 1.",
- (uchar**) &innobase_mirrored_log_groups,
- (uchar**) &innobase_mirrored_log_groups, 0, GET_LONG, REQUIRED_ARG, 1, 1, 10,
- 0, 1, 0},
- {"innodb_open_files", OPT_INNODB_OPEN_FILES,
- "How many files at the maximum InnoDB keeps open at the same time.",
- (uchar**) &innobase_open_files, (uchar**) &innobase_open_files, 0,
- GET_LONG, REQUIRED_ARG, 300L, 10L, ~0L, 0, 1L, 0},
- {"innodb_sync_spin_loops", OPT_INNODB_SYNC_SPIN_LOOPS,
- "Count of spin-loop rounds in InnoDB mutexes",
- (uchar**) &srv_n_spin_wait_rounds,
- (uchar**) &srv_n_spin_wait_rounds,
- 0, GET_LONG, REQUIRED_ARG, 20L, 0L, ~0L, 0, 1L, 0},
- {"innodb_thread_concurrency", OPT_INNODB_THREAD_CONCURRENCY,
- "Helps in performance tuning in heavily concurrent environments. "
- "Sets the maximum number of threads allowed inside InnoDB. Value 0"
- " will disable the thread throttling.",
- (uchar**) &srv_thread_concurrency, (uchar**) &srv_thread_concurrency,
- 0, GET_LONG, REQUIRED_ARG, 8, 0, 1000, 0, 1, 0},
- {"innodb_thread_sleep_delay", OPT_INNODB_THREAD_SLEEP_DELAY,
- "Time of innodb thread sleeping before joining InnoDB queue (usec). Value 0"
- " disable a sleep",
- (uchar**) &srv_thread_sleep_delay,
- (uchar**) &srv_thread_sleep_delay,
- 0, GET_LONG, REQUIRED_ARG, 10000L, 0L, ~0L, 0, 1L, 0},
-#endif /* WITH_INNOBASE_STORAGE_ENGINE */
{"interactive_timeout", OPT_INTERACTIVE_TIMEOUT,
"The number of seconds the server waits for activity on an interactive connection before closing it.",
(uchar**) &global_system_variables.net_interactive_timeout,
@@ -6316,7 +6110,12 @@ The minimum value for this variable is 4096.",
"Directory for plugins.",
(uchar**) &opt_plugin_dir_ptr, (uchar**) &opt_plugin_dir_ptr, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
- {"preload_buffer_size", OPT_PRELOAD_BUFFER_SIZE,
+ {"plugin_load", OPT_PLUGIN_LOAD,
+ "Optional colon separated list of plugins to load, where each plugin is "
+ "identified by name and path to library seperated by an equals.",
+ (uchar**) &opt_plugin_load, (uchar**) &opt_plugin_load, 0,
+ GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"preload_buffer_size", OPT_PRELOAD_BUFFER_SIZE,
"The size of the buffer that is allocated when preloading indexes",
(uchar**) &global_system_variables.preload_buff_size,
(uchar**) &max_system_variables.preload_buff_size, 0, GET_ULONG,
@@ -6870,6 +6669,7 @@ SHOW_VAR status_vars[]= {
{"Com_analyze", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_ANALYZE]), SHOW_LONG_STATUS},
{"Com_backup_table", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_BACKUP_TABLE]), SHOW_LONG_STATUS},
{"Com_begin", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_BEGIN]), SHOW_LONG_STATUS},
+ {"Com_call_procedure", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CALL]), SHOW_LONG_STATUS},
{"Com_change_db", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CHANGE_DB]), SHOW_LONG_STATUS},
{"Com_change_master", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CHANGE_MASTER]), SHOW_LONG_STATUS},
{"Com_check", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_CHECK]), SHOW_LONG_STATUS},
@@ -7092,6 +6892,7 @@ static void print_version(void)
server_version,SYSTEM_TYPE,MACHINE_TYPE, MYSQL_COMPILATION_COMMENT);
}
+#ifndef EMBEDDED_LIBRARY
static void usage(void)
{
if (!(default_charset_info= get_charset_by_csname(default_character_set_name,
@@ -7127,17 +6928,17 @@ Starts the MySQL database server\n");
#endif
print_defaults(MYSQL_CONFIG_NAME,load_default_groups);
puts("");
- fix_paths();
set_ports();
- my_print_help(my_long_options);
- my_print_variables(my_long_options);
+ /* Print out all the options including plugin supplied options */
+ my_print_help_inc_plugins(my_long_options, sizeof(my_long_options)/sizeof(my_option));
puts("\n\
To see what values a running MySQL server is using, type\n\
'mysqladmin variables' instead of 'mysqld --verbose --help'.\n");
}
}
+#endif /*!EMBEDDED_LIBRARY*/
/*
@@ -7174,6 +6975,7 @@ static void mysql_init_variables(void)
mqh_used= 0;
segfaulted= kill_in_progress= 0;
cleanup_done= 0;
+ defaults_argc= 0;
defaults_argv= 0;
server_id_supplied= 0;
test_flags= select_errors= dropping_tables= ha_open_options=0;
@@ -7261,7 +7063,7 @@ static void mysql_init_variables(void)
lc_time_names_name= (char*) "en_US";
/* Set default values for some option variables */
default_storage_engine_str= (char*) "MyISAM";
- global_system_variables.table_type= myisam_hton;
+ global_system_variables.table_plugin= NULL;
global_system_variables.tx_isolation= ISO_REPEATABLE_READ;
global_system_variables.select_limit= (ulonglong) HA_POS_ERROR;
max_system_variables.select_limit= (ulonglong) HA_POS_ERROR;
@@ -7282,36 +7084,13 @@ static void mysql_init_variables(void)
"d:t:i:o,/tmp/mysqld.trace");
#endif
opt_error_log= IF_WIN(1,0);
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
- have_innodb= SHOW_OPTION_YES;
-#else
- have_innodb= SHOW_OPTION_NO;
-#endif
-#ifdef WITH_CSV_STORAGE_ENGINE
- have_csv_db= SHOW_OPTION_YES;
-#else
- have_csv_db= SHOW_OPTION_NO;
-#endif
#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
- have_ndbcluster= SHOW_OPTION_DISABLED;
-#else
- have_ndbcluster= SHOW_OPTION_NO;
-#endif
-#ifdef WITH_PARTITION_STORAGE_ENGINE
- have_partition_db= SHOW_OPTION_YES;
-#else
- have_partition_db= SHOW_OPTION_NO;
-#endif
-#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
- have_ndbcluster=SHOW_OPTION_DISABLED;
global_system_variables.ndb_index_stat_enable=FALSE;
max_system_variables.ndb_index_stat_enable=TRUE;
global_system_variables.ndb_index_stat_cache_entries=32;
max_system_variables.ndb_index_stat_cache_entries=~0L;
global_system_variables.ndb_index_stat_update_freq=20;
max_system_variables.ndb_index_stat_update_freq=~0L;
-#else
- have_ndbcluster=SHOW_OPTION_NO;
#endif
#ifdef HAVE_OPENSSL
have_ssl=SHOW_OPTION_YES;
@@ -7604,7 +7383,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
#endif
case OPT_EVENT_SCHEDULER:
if (Events::set_opt_event_scheduler(argument))
- exit(1);
+ exit(1);
break;
case (int) OPT_SKIP_NEW:
opt_specialflag|= SPECIAL_NO_NEW_FUNC;
@@ -7756,17 +7535,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
global_system_variables.tx_isolation= (type-1);
break;
}
- case OPT_MERGE:
- case OPT_BDB:
- break;
- case OPT_NDBCLUSTER:
-#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
- if (opt_ndbcluster)
- have_ndbcluster= SHOW_OPTION_YES;
- else
- have_ndbcluster= SHOW_OPTION_DISABLED;
-#endif
- break;
#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
case OPT_NDB_MGMD:
case OPT_NDB_NODEID:
@@ -7805,24 +7573,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
ndb_extra_logging= atoi(argument);
break;
#endif
- case OPT_INNODB:
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
- if (opt_innodb)
- have_innodb= SHOW_OPTION_YES;
- else
- have_innodb= SHOW_OPTION_DISABLED;
-#endif
- break;
- case OPT_INNODB_DATA_FILE_PATH:
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
- innobase_data_file_path= argument;
-#endif
- break;
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
- case OPT_INNODB_LOG_ARCHIVE:
- innobase_log_archive= argument ? test(atoi(argument)) : 1;
- break;
-#endif /* WITH_INNOBASE_STORAGE_ENGINE */
case OPT_MYISAM_RECOVER:
{
if (!argument || !argument[0])
@@ -7953,7 +7703,7 @@ static void option_error_reporter(enum loglevel level, const char *format, ...)
}
-static void get_options(int argc,char **argv)
+static void get_options(int *argc,char **argv)
{
int ho_error;
@@ -7961,34 +7711,20 @@ static void get_options(int argc,char **argv)
strmake(def_ft_boolean_syntax, ft_boolean_syntax,
sizeof(ft_boolean_syntax)-1);
my_getopt_error_reporter= option_error_reporter;
- if ((ho_error= handle_options(&argc, &argv, my_long_options,
+
+ /* Skip unknown options so that they may be processed later by plugins */
+ my_getopt_skip_unknown= TRUE;
+
+ if ((ho_error= handle_options(argc, &argv, my_long_options,
get_one_option)))
exit(ho_error);
+ (*argc)++; /* add back one for the progname handle_options removes */
+ /* no need to do this for argv as we are discarding it. */
-#ifndef WITH_NDBCLUSTER_STORAGE_ENGINE
- if (opt_ndbcluster)
- sql_print_warning("this binary does not contain NDBCLUSTER storage engine");
-#endif
-#ifndef WITH_INNOBASE_STORAGE_ENGINE
- if (opt_innodb)
- sql_print_warning("this binary does not contain INNODB storage engine");
-#endif
if ((opt_log_slow_admin_statements || opt_log_queries_not_using_indexes) &&
!opt_slow_log)
sql_print_warning("options --log-slow-admin-statements and --log-queries-not-using-indexes have no effect if --log-slow-queries is not set");
- if (argc > 0)
- {
- fprintf(stderr, "%s: Too many arguments (first extra is '%s').\nUse --help to get a list of available options\n", my_progname, *argv);
- /* FIXME add EXIT_TOO_MANY_ARGUMENTS to "mysys_err.h" and return that code? */
- exit(1);
- }
-
- if (opt_help)
- {
- usage();
- exit(0);
- }
#if defined(HAVE_BROKEN_REALPATH)
my_use_symdir=0;
my_disable_symlinks=1;
@@ -8341,12 +8077,7 @@ void refresh_status(THD *thd)
bzero((char*) &thd->status_var, sizeof(thd->status_var));
/* Reset some global variables */
- for (SHOW_VAR *ptr= status_vars; ptr->name; ptr++)
- {
- /* Note that SHOW_LONG_NOFLUSH variables are not reset */
- if (ptr->type == SHOW_LONG)
- *(ulong*) ptr->value= 0;
- }
+ reset_status_vars();
/* Reset the counters of all key caches (default and named). */
process_key_caches(reset_key_cache_counters);
@@ -8365,51 +8096,9 @@ void refresh_status(THD *thd)
/*****************************************************************************
- Instantiate have_xyx for missing storage engines
+ Instantiate variables for missing storage engines
+ This section should go away soon
*****************************************************************************/
-#undef have_innodb
-#undef have_ndbcluster
-#undef have_csv_db
-
-SHOW_COMP_OPTION have_innodb= SHOW_OPTION_NO;
-SHOW_COMP_OPTION have_ndbcluster= SHOW_OPTION_NO;
-SHOW_COMP_OPTION have_csv_db= SHOW_OPTION_NO;
-SHOW_COMP_OPTION have_partition_db= SHOW_OPTION_NO;
-
-#ifndef WITH_INNOBASE_STORAGE_ENGINE
-uint innobase_flush_log_at_trx_commit;
-ulong innobase_fast_shutdown;
-long innobase_mirrored_log_groups, innobase_log_files_in_group;
-longlong innobase_log_file_size;
-long innobase_log_buffer_size;
-longlong innobase_buffer_pool_size;
-long innobase_additional_mem_pool_size;
-long innobase_file_io_threads, innobase_lock_wait_timeout;
-long innobase_force_recovery;
-long innobase_open_files;
-char *innobase_data_home_dir, *innobase_data_file_path;
-char *innobase_log_group_home_dir, *innobase_log_arch_dir;
-char *innobase_unix_file_flush_method;
-my_bool innobase_log_archive,
- innobase_use_doublewrite,
- innobase_use_checksums,
- innobase_file_per_table,
- innobase_locks_unsafe_for_binlog,
- innobase_rollback_on_timeout,
- innobase_stats_on_metadata;
-
-extern "C" {
-ulong srv_max_buf_pool_modified_pct;
-ulong srv_max_purge_lag;
-ulong srv_auto_extend_increment;
-ulong srv_n_spin_wait_rounds;
-ulong srv_n_free_tickets_to_enter;
-ulong srv_thread_sleep_delay;
-ulong srv_thread_concurrency;
-ulong srv_commit_concurrency;
-}
-
-#endif
#ifndef WITH_NDBCLUSTER_STORAGE_ENGINE
ulong ndb_cache_check_time;
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index f606e96e94c..4944c994d3d 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -1551,8 +1551,8 @@ QUICK_ROR_UNION_SELECT::~QUICK_ROR_UNION_SELECT()
QUICK_RANGE::QUICK_RANGE()
:min_key(0),max_key(0),min_length(0),max_length(0),
- min_keypart_map(0), max_keypart_map(0),
- flag(NO_MIN_RANGE | NO_MAX_RANGE)
+ flag(NO_MIN_RANGE | NO_MAX_RANGE),
+ min_keypart_map(0), max_keypart_map(0)
{}
SEL_ARG::SEL_ARG(SEL_ARG &arg) :Sql_alloc()
@@ -10013,11 +10013,12 @@ QUICK_GROUP_MIN_MAX_SELECT(TABLE *table, JOIN *join_arg, bool have_min_arg,
ha_rows records_arg, uint key_infix_len_arg,
uchar *key_infix_arg, MEM_ROOT *parent_alloc)
:join(join_arg), index_info(index_info_arg),
- group_prefix_len(group_prefix_len_arg), have_min(have_min_arg),
+ group_prefix_len(group_prefix_len_arg),
+ group_key_parts(group_key_parts_arg), have_min(have_min_arg),
have_max(have_max_arg), seen_first_key(FALSE),
min_max_arg_part(min_max_arg_part_arg), key_infix(key_infix_arg),
key_infix_len(key_infix_len_arg), min_functions_it(NULL),
- max_functions_it(NULL), group_key_parts(group_key_parts_arg)
+ max_functions_it(NULL)
{
head= table;
file= head->file;
diff --git a/sql/opt_range.h b/sql/opt_range.h
index d86cab11ef3..dd219129167 100644
--- a/sql/opt_range.h
+++ b/sql/opt_range.h
@@ -52,9 +52,9 @@ class QUICK_RANGE :public Sql_alloc {
max_key((uchar*) sql_memdup(max_key_arg,max_length_arg+1)),
min_length((uint16) min_length_arg),
max_length((uint16) max_length_arg),
+ flag((uint16) flag_arg),
min_keypart_map(min_keypart_map_arg),
- max_keypart_map(max_keypart_map_arg),
- flag((uint16) flag_arg)
+ max_keypart_map(max_keypart_map_arg)
{
#ifdef HAVE_purify
dummy=0;
diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc
index 83023b59867..8851401d21f 100644
--- a/sql/opt_sum.cc
+++ b/sql/opt_sum.cc
@@ -249,12 +249,69 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
if (!ref.key_length)
error= table->file->index_first(table->record[0]);
- else
- error= table->file->index_read(table->record[0],key_buff,
- make_prev_keypart_map(ref.key_parts),
- range_fl & NEAR_MIN ?
- HA_READ_AFTER_KEY :
- HA_READ_KEY_OR_NEXT);
+ else
+ {
+ /*
+ Use index to replace MIN/MAX functions with their values
+ according to the following rules:
+
+ 1) Insert the minimum non-null values where the WHERE clause still
+ matches, or
+ 2) a NULL value if there are only NULL values for key_part_k.
+ 3) Fail, producing a row of nulls
+
+ Implementation: Read the smallest value using the search key. If
+ the interval is open, read the next value after the search
+ key. If read fails, and we're looking for a MIN() value for a
+ nullable column, test if there is an exact match for the key.
+ */
+ if (!(range_fl & NEAR_MIN))
+ /*
+ Closed interval: Either The MIN argument is non-nullable, or
+ we have a >= predicate for the MIN argument.
+ */
+ error= table->file->index_read(table->record[0], ref.key_buff,
+ make_prev_keypart_map(ref.key_parts),
+ HA_READ_KEY_OR_NEXT);
+ else
+ {
+ /*
+ Open interval: There are two cases:
+ 1) We have only MIN() and the argument column is nullable, or
+ 2) there is a > predicate on it, nullability is irrelevant.
+ We need to scan the next bigger record first.
+ */
+ error= table->file->index_read(table->record[0], ref.key_buff,
+ make_prev_keypart_map(ref.key_parts),
+ HA_READ_AFTER_KEY);
+ /*
+ If the found record is outside the group formed by the search
+ prefix, or there is no such record at all, check if all
+ records in that group have NULL in the MIN argument
+ column. If that is the case return that NULL.
+
+ Check if case 1 from above holds. If it does, we should read
+ the skipped tuple.
+ */
+ if (ref.key_buff[prefix_len] == 1 &&
+ /*
+ Last keypart (i.e. the argument to MIN) is set to NULL by
+ find_key_for_maxmin only if all other keyparts are bound
+ to constants in a conjunction of equalities. Hence, we
+ can detect this by checking only if the last keypart is
+ NULL.
+ */
+ (error == HA_ERR_KEY_NOT_FOUND ||
+ key_cmp_if_same(table, ref.key_buff, ref.key, prefix_len)))
+ {
+ DBUG_ASSERT(item_field->field->real_maybe_null());
+ error= table->file->index_read(table->record[0], ref.key_buff,
+ make_prev_keypart_map(ref.key_parts),
+ HA_READ_KEY_EXACT);
+ }
+ }
+ }
+ /* Verify that the read tuple indeed matches the search key */
if (!error && reckey_in_range(0, &ref, item_field->field,
conds, range_fl, prefix_len))
error= HA_ERR_KEY_NOT_FOUND;
@@ -784,16 +841,26 @@ static bool find_key_for_maxmin(bool max_fl, TABLE_REF *ref,
if (!max_fl && key_part_used == key_part_to_use && part->null_bit)
{
/*
- SELECT MIN(key_part2) FROM t1 WHERE key_part1=const
- If key_part2 may be NULL, then we want to find the first row
- that is not null
+ The query is on this form:
+
+ SELECT MIN(key_part_k)
+ FROM t1
+ WHERE key_part_1 = const and ... and key_part_k-1 = const
+
+ If key_part_k is nullable, we want to find the first matching row
+ where key_part_k is not null. The key buffer is now {const, ...,
+ NULL}. This will be passed to the handler along with a flag
+ indicating open interval. If a tuple is read that does not match
+ these search criteria, an attempt will be made to read an exact
+ match for the key buffer.
*/
+ /* Set the first byte of key_part_k to 1, that means NULL */
ref->key_buff[ref->key_length]= 1;
ref->key_length+= part->store_length;
ref->key_parts++;
DBUG_ASSERT(ref->key_parts == jdx+1);
*range_fl&= ~NO_MIN_RANGE;
- *range_fl|= NEAR_MIN; // > NULL
+ *range_fl|= NEAR_MIN; // Open interval
}
/*
The following test is false when the key in the key tree is
diff --git a/sql/partition_element.h b/sql/partition_element.h
index c056d40b85b..905bc38165b 100644
--- a/sql/partition_element.h
+++ b/sql/partition_element.h
@@ -84,9 +84,9 @@ public:
partition_element(partition_element *part_elem)
: part_max_rows(part_elem->part_max_rows),
part_min_rows(part_elem->part_min_rows),
- partition_name(NULL),
+ range_value(0), partition_name(NULL),
tablespace_name(part_elem->tablespace_name),
- range_value(0), part_comment(part_elem->part_comment),
+ part_comment(part_elem->part_comment),
data_file_name(part_elem->data_file_name),
index_file_name(part_elem->index_file_name),
engine_type(part_elem->engine_type),
diff --git a/sql/rpl_mi.cc b/sql/rpl_mi.cc
index 354a97cefde..bb9d0e6d953 100644
--- a/sql/rpl_mi.cc
+++ b/sql/rpl_mi.cc
@@ -29,8 +29,8 @@ int init_strvar_from_file(char *var, int max_size, IO_CACHE *f,
MASTER_INFO::MASTER_INFO()
:ssl(0), fd(-1), io_thd(0), inited(0),
- abort_slave(0),slave_running(0), slave_run_id(0),
- ssl_verify_server_cert(0)
+ abort_slave(0),slave_running(0),
+ ssl_verify_server_cert(0), slave_run_id(0)
{
host[0] = 0; user[0] = 0; password[0] = 0;
ssl_ca[0]= 0; ssl_capath[0]= 0; ssl_cert[0]= 0;
diff --git a/sql/rpl_utility.h b/sql/rpl_utility.h
index baca224a3e5..2ce8def4577 100644
--- a/sql/rpl_utility.h
+++ b/sql/rpl_utility.h
@@ -59,7 +59,7 @@ public:
@param size Number of elements in array 'types'
*/
table_def(field_type *types, ulong size)
- : m_type(new unsigned char [size]), m_size(size)
+ : m_size(size), m_type(new unsigned char [size])
{
if (m_type)
memcpy(m_type, types, size);
diff --git a/sql/set_var.cc b/sql/set_var.cc
index 283aa0104ce..f57680d275f 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -27,8 +27,6 @@
of it in the my_option structure list in mysqld.cc
- Don't forget to initialize new fields in global_system_variables and
max_system_variables!
- - If the variable should show up in 'show variables' add it to the
- init_vars[] struct in this file
NOTES:
- Be careful with var->save_result: sys_var::check() only updates
@@ -59,52 +57,24 @@
#include "events.h"
-/* WITH_INNOBASE_STORAGE_ENGINE */
-extern uint innobase_flush_log_at_trx_commit;
-extern ulong innobase_fast_shutdown;
-extern long innobase_mirrored_log_groups, innobase_log_files_in_group;
-extern longlong innobase_log_file_size;
-extern long innobase_log_buffer_size;
-extern longlong innobase_buffer_pool_size;
-extern long innobase_additional_mem_pool_size;
-extern long innobase_file_io_threads, innobase_lock_wait_timeout;
-extern long innobase_force_recovery;
-extern long innobase_open_files;
-extern char *innobase_data_home_dir, *innobase_data_file_path;
-extern char *innobase_log_group_home_dir, *innobase_log_arch_dir;
-extern char *innobase_unix_file_flush_method;
-/* The following variables have to be my_bool for SHOW VARIABLES to work */
-extern my_bool innobase_log_archive,
- innobase_use_doublewrite,
- innobase_use_checksums,
- innobase_file_per_table,
- innobase_locks_unsafe_for_binlog,
- innobase_rollback_on_timeout,
- innobase_stats_on_metadata;
-
-extern "C" {
-extern ulong srv_max_buf_pool_modified_pct;
-extern ulong srv_max_purge_lag;
-extern ulong srv_auto_extend_increment;
-extern ulong srv_n_spin_wait_rounds;
-extern ulong srv_n_free_tickets_to_enter;
-extern ulong srv_thread_sleep_delay;
-extern ulong srv_thread_concurrency;
-extern ulong srv_commit_concurrency;
-extern ulong srv_flush_log_at_trx_commit;
-}
-
/* WITH_NDBCLUSTER_STORAGE_ENGINE */
+#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
extern ulong ndb_cache_check_time;
+extern char opt_ndb_constrbuf[];
extern ulong ndb_extra_logging;
+#endif
+
#ifdef HAVE_NDB_BINLOG
extern ulong ndb_report_thresh_binlog_epoch_slip;
extern ulong ndb_report_thresh_binlog_mem_usage;
#endif
+extern CHARSET_INFO *character_set_filesystem;
+static DYNAMIC_ARRAY fixed_show_vars;
static HASH system_variable_hash;
+
const char *bool_type_names[]= { "OFF", "ON", NullS };
TYPELIB bool_typelib=
{
@@ -171,888 +141,570 @@ static void sys_default_slow_log_path(THD *thd, enum_var_type type);
it in the constructor (see sys_var class for details).
*/
-sys_var *sys_var::first= NULL;
-uint sys_var::sys_vars= 0;
+static sys_var_chain vars = { NULL, NULL };
-sys_var_thd_ulong sys_auto_increment_increment("auto_increment_increment",
+static sys_var_thd_ulong sys_auto_increment_increment(&vars, "auto_increment_increment",
&SV::auto_increment_increment);
-sys_var_thd_ulong sys_auto_increment_offset("auto_increment_offset",
+static sys_var_thd_ulong sys_auto_increment_offset(&vars, "auto_increment_offset",
&SV::auto_increment_offset);
-sys_var_bool_ptr sys_automatic_sp_privileges("automatic_sp_privileges",
+static sys_var_bool_ptr sys_automatic_sp_privileges(&vars, "automatic_sp_privileges",
&sp_automatic_privileges);
-sys_var_const_str sys_basedir("basedir", mysql_home);
-sys_var_long_ptr sys_binlog_cache_size("binlog_cache_size",
+static sys_var_const_str sys_basedir(&vars, "basedir", mysql_home);
+static sys_var_long_ptr sys_binlog_cache_size(&vars, "binlog_cache_size",
&binlog_cache_size);
-sys_var_thd_binlog_format sys_binlog_format("binlog_format",
+static sys_var_thd_binlog_format sys_binlog_format(&vars, "binlog_format",
&SV::binlog_format);
-sys_var_thd_ulong sys_bulk_insert_buff_size("bulk_insert_buffer_size",
+static sys_var_thd_ulong sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
&SV::bulk_insert_buff_size);
-sys_var_character_set_server sys_character_set_server("character_set_server");
-sys_var_const_str sys_charset_system("character_set_system",
+static sys_var_character_set_sv sys_character_set_server(&vars, "character_set_server",
+ &SV::collation_server,
+ &default_charset_info);
+sys_var_const_str sys_charset_system(&vars, "character_set_system",
(char *)my_charset_utf8_general_ci.name);
-sys_var_character_set_database sys_character_set_database("character_set_database");
-sys_var_character_set_client sys_character_set_client("character_set_client");
-sys_var_character_set_connection sys_character_set_connection("character_set_connection");
-sys_var_character_set_results sys_character_set_results("character_set_results");
-sys_var_character_set_filesystem sys_character_set_filesystem("character_set_filesystem");
-sys_var_thd_ulong sys_completion_type("completion_type",
+static sys_var_character_set_database sys_character_set_database(&vars, "character_set_database");
+static sys_var_character_set_sv sys_character_set_client(&vars, "character_set_client",
+ &SV::character_set_client,
+ &default_charset_info);
+static sys_var_character_set_sv sys_character_set_connection(&vars, "character_set_connection",
+ &SV::collation_connection,
+ &default_charset_info);
+static sys_var_character_set_sv sys_character_set_results(&vars, "character_set_results",
+ &SV::character_set_results,
+ &default_charset_info, true);
+static sys_var_character_set_sv sys_character_set_filesystem(&vars, "character_set_filesystem",
+ &SV::character_set_filesystem,
+ &character_set_filesystem);
+static sys_var_thd_ulong sys_completion_type(&vars, "completion_type",
&SV::completion_type,
check_completion_type,
fix_completion_type);
-sys_var_collation_connection sys_collation_connection("collation_connection");
-sys_var_collation_database sys_collation_database("collation_database");
-sys_var_collation_server sys_collation_server("collation_server");
-sys_var_long_ptr sys_concurrent_insert("concurrent_insert",
+static sys_var_collation_sv sys_collation_connection(&vars, "collation_connection",
+ &SV::collation_connection,
+ &default_charset_info);
+static sys_var_collation_sv sys_collation_database(&vars, "collation_database",
+ &SV::collation_database,
+ &default_charset_info);
+static sys_var_collation_sv sys_collation_server(&vars, "collation_server",
+ &SV::collation_server,
+ &default_charset_info);
+static sys_var_long_ptr sys_concurrent_insert(&vars, "concurrent_insert",
&myisam_concurrent_insert);
-sys_var_long_ptr sys_connect_timeout("connect_timeout",
+static sys_var_long_ptr sys_connect_timeout(&vars, "connect_timeout",
&connect_timeout);
-sys_var_const_str sys_datadir("datadir", mysql_real_data_home);
+static sys_var_const_str sys_datadir(&vars, "datadir", mysql_real_data_home);
#ifndef DBUG_OFF
-sys_var_thd_dbug sys_dbug("debug");
+static sys_var_thd_dbug sys_dbug(&vars, "debug");
#endif
-sys_var_enum sys_delay_key_write("delay_key_write",
+static sys_var_enum sys_delay_key_write(&vars, "delay_key_write",
&delay_key_write_options,
&delay_key_write_typelib,
fix_delay_key_write);
-sys_var_long_ptr sys_delayed_insert_limit("delayed_insert_limit",
+static sys_var_long_ptr sys_delayed_insert_limit(&vars, "delayed_insert_limit",
&delayed_insert_limit);
-sys_var_long_ptr sys_delayed_insert_timeout("delayed_insert_timeout",
+static sys_var_long_ptr sys_delayed_insert_timeout(&vars, "delayed_insert_timeout",
&delayed_insert_timeout);
-sys_var_long_ptr sys_delayed_queue_size("delayed_queue_size",
+static sys_var_long_ptr sys_delayed_queue_size(&vars, "delayed_queue_size",
&delayed_queue_size);
-sys_var_event_scheduler sys_event_scheduler("event_scheduler");
-sys_var_long_ptr sys_expire_logs_days("expire_logs_days",
+static sys_var_event_scheduler sys_event_scheduler(&vars, "event_scheduler");
+static sys_var_long_ptr sys_expire_logs_days(&vars, "expire_logs_days",
&expire_logs_days);
-sys_var_bool_ptr sys_flush("flush", &myisam_flush);
-sys_var_long_ptr sys_flush_time("flush_time", &flush_time);
-sys_var_str sys_ft_boolean_syntax("ft_boolean_syntax",
+static sys_var_bool_ptr sys_flush(&vars, "flush", &myisam_flush);
+static sys_var_long_ptr sys_flush_time(&vars, "flush_time", &flush_time);
+static sys_var_str sys_ft_boolean_syntax(&vars, "ft_boolean_syntax",
sys_check_ftb_syntax,
sys_update_ftb_syntax,
sys_default_ftb_syntax,
ft_boolean_syntax);
-sys_var_str sys_init_connect("init_connect", 0,
+sys_var_str sys_init_connect(&vars, "init_connect", 0,
sys_update_init_connect,
sys_default_init_connect,0);
-sys_var_str sys_init_slave("init_slave", 0,
+sys_var_str sys_init_slave(&vars, "init_slave", 0,
sys_update_init_slave,
sys_default_init_slave,0);
-sys_var_thd_ulong sys_interactive_timeout("interactive_timeout",
+static sys_var_thd_ulong sys_interactive_timeout(&vars, "interactive_timeout",
&SV::net_interactive_timeout);
-sys_var_thd_ulong sys_join_buffer_size("join_buffer_size",
+static sys_var_thd_ulong sys_join_buffer_size(&vars, "join_buffer_size",
&SV::join_buff_size);
-sys_var_key_buffer_size sys_key_buffer_size("key_buffer_size");
-sys_var_key_cache_long sys_key_cache_block_size("key_cache_block_size",
+static sys_var_key_buffer_size sys_key_buffer_size(&vars, "key_buffer_size");
+static sys_var_key_cache_long sys_key_cache_block_size(&vars, "key_cache_block_size",
offsetof(KEY_CACHE,
param_block_size));
-sys_var_key_cache_long sys_key_cache_division_limit("key_cache_division_limit",
+static sys_var_key_cache_long sys_key_cache_division_limit(&vars, "key_cache_division_limit",
offsetof(KEY_CACHE,
param_division_limit));
-sys_var_key_cache_long sys_key_cache_age_threshold("key_cache_age_threshold",
+static sys_var_key_cache_long sys_key_cache_age_threshold(&vars, "key_cache_age_threshold",
offsetof(KEY_CACHE,
param_age_threshold));
-sys_var_bool_ptr sys_local_infile("local_infile",
+static sys_var_bool_ptr sys_local_infile(&vars, "local_infile",
&opt_local_infile);
-sys_var_trust_routine_creators
-sys_trust_routine_creators("log_bin_trust_routine_creators",
+static sys_var_trust_routine_creators
+sys_trust_routine_creators(&vars, "log_bin_trust_routine_creators",
&trust_function_creators);
-sys_var_bool_ptr
-sys_trust_function_creators("log_bin_trust_function_creators",
+static sys_var_bool_ptr
+sys_trust_function_creators(&vars, "log_bin_trust_function_creators",
&trust_function_creators);
-sys_var_bool_ptr
- sys_log_queries_not_using_indexes("log_queries_not_using_indexes",
+static sys_var_bool_ptr
+ sys_log_queries_not_using_indexes(&vars, "log_queries_not_using_indexes",
&opt_log_queries_not_using_indexes);
-sys_var_thd_ulong sys_log_warnings("log_warnings", &SV::log_warnings);
-sys_var_thd_ulong sys_long_query_time("long_query_time",
+static sys_var_thd_ulong sys_log_warnings(&vars, "log_warnings", &SV::log_warnings);
+static sys_var_thd_ulong sys_long_query_time(&vars, "long_query_time",
&SV::long_query_time);
-sys_var_thd_bool sys_low_priority_updates("low_priority_updates",
+static sys_var_thd_bool sys_low_priority_updates(&vars, "low_priority_updates",
&SV::low_priority_updates,
fix_low_priority_updates);
#ifndef TO_BE_DELETED /* Alias for the low_priority_updates */
-sys_var_thd_bool sys_sql_low_priority_updates("sql_low_priority_updates",
+static sys_var_thd_bool sys_sql_low_priority_updates(&vars, "sql_low_priority_updates",
&SV::low_priority_updates,
fix_low_priority_updates);
#endif
-sys_var_thd_ulong sys_max_allowed_packet("max_allowed_packet",
+static sys_var_thd_ulong sys_max_allowed_packet(&vars, "max_allowed_packet",
&SV::max_allowed_packet);
-sys_var_long_ptr sys_max_binlog_cache_size("max_binlog_cache_size",
+static sys_var_long_ptr sys_max_binlog_cache_size(&vars, "max_binlog_cache_size",
&max_binlog_cache_size);
-sys_var_long_ptr sys_max_binlog_size("max_binlog_size",
+static sys_var_long_ptr sys_max_binlog_size(&vars, "max_binlog_size",
&max_binlog_size,
fix_max_binlog_size);
-sys_var_long_ptr sys_max_connections("max_connections",
+static sys_var_long_ptr sys_max_connections(&vars, "max_connections",
&max_connections,
fix_max_connections);
-sys_var_long_ptr sys_max_connect_errors("max_connect_errors",
+static sys_var_long_ptr sys_max_connect_errors(&vars, "max_connect_errors",
&max_connect_errors);
-sys_var_thd_ulong sys_max_insert_delayed_threads("max_insert_delayed_threads",
+static sys_var_thd_ulong sys_max_insert_delayed_threads(&vars, "max_insert_delayed_threads",
&SV::max_insert_delayed_threads,
check_max_delayed_threads,
fix_max_connections);
-sys_var_thd_ulong sys_max_delayed_threads("max_delayed_threads",
+static sys_var_thd_ulong sys_max_delayed_threads(&vars, "max_delayed_threads",
&SV::max_insert_delayed_threads,
check_max_delayed_threads,
fix_max_connections);
-sys_var_thd_ulong sys_max_error_count("max_error_count",
+static sys_var_thd_ulong sys_max_error_count(&vars, "max_error_count",
&SV::max_error_count);
-sys_var_thd_ulonglong sys_max_heap_table_size("max_heap_table_size",
+static sys_var_thd_ulonglong sys_max_heap_table_size(&vars, "max_heap_table_size",
&SV::max_heap_table_size);
-sys_var_thd_ulong sys_pseudo_thread_id("pseudo_thread_id",
+static sys_var_thd_ulong sys_pseudo_thread_id(&vars, "pseudo_thread_id",
&SV::pseudo_thread_id,
check_pseudo_thread_id, 0);
-sys_var_thd_ha_rows sys_max_join_size("max_join_size",
+static sys_var_thd_ha_rows sys_max_join_size(&vars, "max_join_size",
&SV::max_join_size,
fix_max_join_size);
-sys_var_thd_ulong sys_max_seeks_for_key("max_seeks_for_key",
+static sys_var_thd_ulong sys_max_seeks_for_key(&vars, "max_seeks_for_key",
&SV::max_seeks_for_key);
-sys_var_thd_ulong sys_max_length_for_sort_data("max_length_for_sort_data",
+static sys_var_thd_ulong sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
&SV::max_length_for_sort_data);
#ifndef TO_BE_DELETED /* Alias for max_join_size */
-sys_var_thd_ha_rows sys_sql_max_join_size("sql_max_join_size",
+static sys_var_thd_ha_rows sys_sql_max_join_size(&vars, "sql_max_join_size",
&SV::max_join_size,
fix_max_join_size);
#endif
static sys_var_long_ptr_global
-sys_max_prepared_stmt_count("max_prepared_stmt_count",
+sys_max_prepared_stmt_count(&vars, "max_prepared_stmt_count",
&max_prepared_stmt_count,
&LOCK_prepared_stmt_count);
-sys_var_long_ptr sys_max_relay_log_size("max_relay_log_size",
+static sys_var_long_ptr sys_max_relay_log_size(&vars, "max_relay_log_size",
&max_relay_log_size,
fix_max_relay_log_size);
-sys_var_thd_ulong sys_max_sort_length("max_sort_length",
+static sys_var_thd_ulong sys_max_sort_length(&vars, "max_sort_length",
&SV::max_sort_length);
-sys_var_thd_ulong sys_max_sp_recursion_depth("max_sp_recursion_depth",
+static sys_var_thd_ulong sys_max_sp_recursion_depth(&vars, "max_sp_recursion_depth",
&SV::max_sp_recursion_depth);
-sys_var_max_user_conn sys_max_user_connections("max_user_connections");
-sys_var_thd_ulong sys_max_tmp_tables("max_tmp_tables",
+static sys_var_max_user_conn sys_max_user_connections(&vars, "max_user_connections");
+static sys_var_thd_ulong sys_max_tmp_tables(&vars, "max_tmp_tables",
&SV::max_tmp_tables);
-sys_var_long_ptr sys_max_write_lock_count("max_write_lock_count",
+static sys_var_long_ptr sys_max_write_lock_count(&vars, "max_write_lock_count",
&max_write_lock_count);
-sys_var_thd_ulong sys_multi_range_count("multi_range_count",
+static sys_var_thd_ulong sys_multi_range_count(&vars, "multi_range_count",
&SV::multi_range_count);
-sys_var_long_ptr sys_myisam_data_pointer_size("myisam_data_pointer_size",
+static sys_var_long_ptr sys_myisam_data_pointer_size(&vars, "myisam_data_pointer_size",
&myisam_data_pointer_size);
-sys_var_thd_ulonglong sys_myisam_max_sort_file_size("myisam_max_sort_file_size", &SV::myisam_max_sort_file_size, fix_myisam_max_sort_file_size, 1);
-sys_var_thd_ulong sys_myisam_repair_threads("myisam_repair_threads", &SV::myisam_repair_threads);
-sys_var_thd_ulong sys_myisam_sort_buffer_size("myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
-sys_var_bool_ptr sys_myisam_use_mmap("myisam_use_mmap",
+static sys_var_thd_ulonglong sys_myisam_max_sort_file_size(&vars, "myisam_max_sort_file_size", &SV::myisam_max_sort_file_size, fix_myisam_max_sort_file_size, 1);
+static sys_var_thd_ulong sys_myisam_repair_threads(&vars, "myisam_repair_threads", &SV::myisam_repair_threads);
+static sys_var_thd_ulong sys_myisam_sort_buffer_size(&vars, "myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
+static sys_var_bool_ptr sys_myisam_use_mmap(&vars, "myisam_use_mmap",
&opt_myisam_use_mmap);
-sys_var_thd_enum sys_myisam_stats_method("myisam_stats_method",
+static sys_var_thd_enum sys_myisam_stats_method(&vars, "myisam_stats_method",
&SV::myisam_stats_method,
&myisam_stats_method_typelib,
NULL);
-sys_var_thd_ulong sys_net_buffer_length("net_buffer_length",
+static sys_var_thd_ulong sys_net_buffer_length(&vars, "net_buffer_length",
&SV::net_buffer_length);
-sys_var_thd_ulong sys_net_read_timeout("net_read_timeout",
+static sys_var_thd_ulong sys_net_read_timeout(&vars, "net_read_timeout",
&SV::net_read_timeout,
0, fix_net_read_timeout);
-sys_var_thd_ulong sys_net_write_timeout("net_write_timeout",
+static sys_var_thd_ulong sys_net_write_timeout(&vars, "net_write_timeout",
&SV::net_write_timeout,
0, fix_net_write_timeout);
-sys_var_thd_ulong sys_net_retry_count("net_retry_count",
+static sys_var_thd_ulong sys_net_retry_count(&vars, "net_retry_count",
&SV::net_retry_count,
0, fix_net_retry_count);
-sys_var_thd_bool sys_new_mode("new", &SV::new_mode);
-sys_var_bool_ptr_readonly sys_old_mode("old",
+static sys_var_thd_bool sys_new_mode(&vars, "new", &SV::new_mode);
+static sys_var_bool_ptr_readonly sys_old_mode(&vars, "old",
&global_system_variables.old_mode);
-sys_var_thd_bool sys_old_alter_table("old_alter_table",
- &SV::old_alter_table);
-sys_var_thd_bool sys_old_passwords("old_passwords", &SV::old_passwords);
-sys_var_thd_ulong sys_optimizer_prune_level("optimizer_prune_level",
+/* these two cannot be static */
+sys_var_thd_bool sys_old_alter_table(&vars, "old_alter_table",
+ &SV::old_alter_table);
+sys_var_thd_bool sys_old_passwords(&vars, "old_passwords", &SV::old_passwords);
+static sys_var_thd_ulong sys_optimizer_prune_level(&vars, "optimizer_prune_level",
&SV::optimizer_prune_level);
-sys_var_thd_ulong sys_optimizer_search_depth("optimizer_search_depth",
+static sys_var_thd_ulong sys_optimizer_search_depth(&vars, "optimizer_search_depth",
&SV::optimizer_search_depth);
-sys_var_thd_ulong sys_preload_buff_size("preload_buffer_size",
+static sys_var_thd_ulong sys_preload_buff_size(&vars, "preload_buffer_size",
&SV::preload_buff_size);
-sys_var_thd_ulong sys_read_buff_size("read_buffer_size",
+static sys_var_thd_ulong sys_read_buff_size(&vars, "read_buffer_size",
&SV::read_buff_size);
-sys_var_opt_readonly sys_readonly("read_only", &opt_readonly);
-sys_var_thd_ulong sys_read_rnd_buff_size("read_rnd_buffer_size",
+static sys_var_opt_readonly sys_readonly(&vars, "read_only", &opt_readonly);
+static sys_var_thd_ulong sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
&SV::read_rnd_buff_size);
-sys_var_thd_ulong sys_div_precincrement("div_precision_increment",
+static sys_var_thd_ulong sys_div_precincrement(&vars, "div_precision_increment",
&SV::div_precincrement);
-#ifdef HAVE_REPLICATION
-sys_var_bool_ptr sys_relay_log_purge("relay_log_purge",
- &relay_log_purge);
-#endif
-sys_var_long_ptr sys_rpl_recovery_rank("rpl_recovery_rank",
+static sys_var_long_ptr sys_rpl_recovery_rank(&vars, "rpl_recovery_rank",
&rpl_recovery_rank);
-sys_var_long_ptr sys_query_cache_size("query_cache_size",
+static sys_var_long_ptr sys_query_cache_size(&vars, "query_cache_size",
&query_cache_size,
fix_query_cache_size);
-sys_var_thd_ulong sys_range_alloc_block_size("range_alloc_block_size",
+static sys_var_thd_ulong sys_range_alloc_block_size(&vars, "range_alloc_block_size",
&SV::range_alloc_block_size);
-sys_var_thd_ulong sys_query_alloc_block_size("query_alloc_block_size",
+static sys_var_thd_ulong sys_query_alloc_block_size(&vars, "query_alloc_block_size",
&SV::query_alloc_block_size,
0, fix_thd_mem_root);
-sys_var_thd_ulong sys_query_prealloc_size("query_prealloc_size",
+static sys_var_thd_ulong sys_query_prealloc_size(&vars, "query_prealloc_size",
&SV::query_prealloc_size,
0, fix_thd_mem_root);
-sys_var_readonly sys_tmpdir("tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
-sys_var_thd_ulong sys_trans_alloc_block_size("transaction_alloc_block_size",
+static sys_var_readonly sys_tmpdir(&vars, "tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
+static sys_var_thd_ulong sys_trans_alloc_block_size(&vars, "transaction_alloc_block_size",
&SV::trans_alloc_block_size,
0, fix_trans_mem_root);
-sys_var_thd_ulong sys_trans_prealloc_size("transaction_prealloc_size",
+static sys_var_thd_ulong sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
&SV::trans_prealloc_size,
0, fix_trans_mem_root);
-sys_var_thd_enum sys_thread_handling("thread_handling",
+sys_var_thd_enum sys_thread_handling(&vars, "thread_handling",
&SV::thread_handling,
&thread_handling_typelib,
NULL);
#ifdef HAVE_QUERY_CACHE
-sys_var_long_ptr sys_query_cache_limit("query_cache_limit",
+static sys_var_long_ptr sys_query_cache_limit(&vars, "query_cache_limit",
&query_cache.query_cache_limit);
-sys_var_long_ptr sys_query_cache_min_res_unit("query_cache_min_res_unit",
+static sys_var_long_ptr sys_query_cache_min_res_unit(&vars, "query_cache_min_res_unit",
&query_cache_min_res_unit,
fix_query_cache_min_res_unit);
-sys_var_thd_enum sys_query_cache_type("query_cache_type",
+static sys_var_thd_enum sys_query_cache_type(&vars, "query_cache_type",
&SV::query_cache_type,
&query_cache_type_typelib);
-sys_var_thd_bool
-sys_query_cache_wlock_invalidate("query_cache_wlock_invalidate",
+static sys_var_thd_bool
+sys_query_cache_wlock_invalidate(&vars, "query_cache_wlock_invalidate",
&SV::query_cache_wlock_invalidate);
#endif /* HAVE_QUERY_CACHE */
-sys_var_bool_ptr sys_secure_auth("secure_auth", &opt_secure_auth);
-sys_var_const_str_ptr sys_secure_file_priv("secure_file_priv",
+static sys_var_bool_ptr sys_secure_auth(&vars, "secure_auth", &opt_secure_auth);
+static sys_var_const_str_ptr sys_secure_file_priv(&vars, "secure_file_priv",
&opt_secure_file_priv);
-sys_var_long_ptr sys_server_id("server_id", &server_id, fix_server_id);
-sys_var_bool_ptr sys_slave_compressed_protocol("slave_compressed_protocol",
+static sys_var_long_ptr sys_server_id(&vars, "server_id", &server_id, fix_server_id);
+static sys_var_bool_ptr sys_slave_compressed_protocol(&vars, "slave_compressed_protocol",
&opt_slave_compressed_protocol);
-#ifdef HAVE_REPLICATION
-sys_var_long_ptr sys_slave_net_timeout("slave_net_timeout",
- &slave_net_timeout);
-sys_var_long_ptr sys_slave_trans_retries("slave_transaction_retries",
- &slave_trans_retries);
-#endif
-sys_var_long_ptr sys_slow_launch_time("slow_launch_time",
+static sys_var_long_ptr sys_slow_launch_time(&vars, "slow_launch_time",
&slow_launch_time);
-sys_var_thd_ulong sys_sort_buffer("sort_buffer_size",
+static sys_var_thd_ulong sys_sort_buffer(&vars, "sort_buffer_size",
&SV::sortbuff_size);
-sys_var_thd_sql_mode sys_sql_mode("sql_mode",
+static sys_var_thd_sql_mode sys_sql_mode(&vars, "sql_mode",
&SV::sql_mode);
#ifdef HAVE_OPENSSL
extern char *opt_ssl_ca, *opt_ssl_capath, *opt_ssl_cert, *opt_ssl_cipher,
*opt_ssl_key;
-sys_var_const_str_ptr sys_ssl_ca("ssl_ca", &opt_ssl_ca);
-sys_var_const_str_ptr sys_ssl_capath("ssl_capath", &opt_ssl_capath);
-sys_var_const_str_ptr sys_ssl_cert("ssl_cert", &opt_ssl_cert);
-sys_var_const_str_ptr sys_ssl_cipher("ssl_cipher", &opt_ssl_cipher);
-sys_var_const_str_ptr sys_ssl_key("ssl_key", &opt_ssl_key);
+static sys_var_const_str_ptr sys_ssl_ca(&vars, "ssl_ca", &opt_ssl_ca);
+static sys_var_const_str_ptr sys_ssl_capath(&vars, "ssl_capath", &opt_ssl_capath);
+static sys_var_const_str_ptr sys_ssl_cert(&vars, "ssl_cert", &opt_ssl_cert);
+static sys_var_const_str_ptr sys_ssl_cipher(&vars, "ssl_cipher", &opt_ssl_cipher);
+static sys_var_const_str_ptr sys_ssl_key(&vars, "ssl_key", &opt_ssl_key);
#else
-sys_var_const_str sys_ssl_ca("ssl_ca", NULL);
-sys_var_const_str sys_ssl_capath("ssl_capath", NULL);
-sys_var_const_str sys_ssl_cert("ssl_cert", NULL);
-sys_var_const_str sys_ssl_cipher("ssl_cipher", NULL);
-sys_var_const_str sys_ssl_key("ssl_key", NULL);
+static sys_var_const_str sys_ssl_ca(&vars, "ssl_ca", NULL);
+static sys_var_const_str sys_ssl_capath(&vars, "ssl_capath", NULL);
+static sys_var_const_str sys_ssl_cert(&vars, "ssl_cert", NULL);
+static sys_var_const_str sys_ssl_cipher(&vars, "ssl_cipher", NULL);
+static sys_var_const_str sys_ssl_key(&vars, "ssl_key", NULL);
#endif
-sys_var_thd_enum
-sys_updatable_views_with_limit("updatable_views_with_limit",
+static sys_var_thd_enum
+sys_updatable_views_with_limit(&vars, "updatable_views_with_limit",
&SV::updatable_views_with_limit,
&updatable_views_with_limit_typelib);
-sys_var_thd_table_type sys_table_type("table_type",
- &SV::table_type);
-sys_var_thd_storage_engine sys_storage_engine("storage_engine",
- &SV::table_type);
-#ifdef HAVE_REPLICATION
-sys_var_sync_binlog_period sys_sync_binlog_period("sync_binlog", &sync_binlog_period);
-#endif
-sys_var_bool_ptr sys_sync_frm("sync_frm", &opt_sync_frm);
-sys_var_const_str sys_system_time_zone("system_time_zone",
+static sys_var_thd_table_type sys_table_type(&vars, "table_type",
+ &SV::table_plugin);
+static sys_var_thd_storage_engine sys_storage_engine(&vars, "storage_engine",
+ &SV::table_plugin);
+static sys_var_bool_ptr sys_sync_frm(&vars, "sync_frm", &opt_sync_frm);
+static sys_var_const_str sys_system_time_zone(&vars, "system_time_zone",
system_time_zone);
-sys_var_long_ptr sys_table_def_size("table_definition_cache",
+static sys_var_long_ptr sys_table_def_size(&vars, "table_definition_cache",
&table_def_size);
-sys_var_long_ptr sys_table_cache_size("table_open_cache",
+static sys_var_long_ptr sys_table_cache_size(&vars, "table_open_cache",
&table_cache_size);
-sys_var_long_ptr sys_table_lock_wait_timeout("table_lock_wait_timeout",
+static sys_var_long_ptr sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
&table_lock_wait_timeout);
-sys_var_long_ptr sys_thread_cache_size("thread_cache_size",
+static sys_var_long_ptr sys_thread_cache_size(&vars, "thread_cache_size",
&thread_cache_size);
#if HAVE_POOL_OF_THREADS == 1
-sys_var_long_ptr sys_thread_pool_size("thread_pool_size",
+sys_var_long_ptr sys_thread_pool_size(&vars, "thread_pool_size",
&thread_pool_size);
#endif
-sys_var_thd_enum sys_tx_isolation("tx_isolation",
+static sys_var_thd_enum sys_tx_isolation(&vars, "tx_isolation",
&SV::tx_isolation,
&tx_isolation_typelib,
fix_tx_isolation,
check_tx_isolation);
-sys_var_thd_ulonglong sys_tmp_table_size("tmp_table_size",
+static sys_var_thd_ulonglong sys_tmp_table_size(&vars, "tmp_table_size",
&SV::tmp_table_size);
-sys_var_bool_ptr sys_timed_mutexes("timed_mutexes",
+static sys_var_bool_ptr sys_timed_mutexes(&vars, "timed_mutexes",
&timed_mutexes);
-sys_var_const_str sys_version("version", server_version);
-sys_var_const_str sys_version_comment("version_comment",
+static sys_var_const_str sys_version(&vars, "version", server_version);
+static sys_var_const_str sys_version_comment(&vars, "version_comment",
MYSQL_COMPILATION_COMMENT);
-sys_var_const_str sys_version_compile_machine("version_compile_machine",
+static sys_var_const_str sys_version_compile_machine(&vars, "version_compile_machine",
MACHINE_TYPE);
-sys_var_const_str sys_version_compile_os("version_compile_os",
+static sys_var_const_str sys_version_compile_os(&vars, "version_compile_os",
SYSTEM_TYPE);
-sys_var_thd_ulong sys_net_wait_timeout("wait_timeout",
+static sys_var_thd_ulong sys_net_wait_timeout(&vars, "wait_timeout",
&SV::net_wait_timeout);
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
-sys_var_long_ptr sys_innodb_fast_shutdown("innodb_fast_shutdown",
- &innobase_fast_shutdown);
-sys_var_long_ptr sys_innodb_max_dirty_pages_pct("innodb_max_dirty_pages_pct",
- &srv_max_buf_pool_modified_pct);
-sys_var_long_ptr sys_innodb_max_purge_lag("innodb_max_purge_lag",
- &srv_max_purge_lag);
-sys_var_thd_bool sys_innodb_table_locks("innodb_table_locks",
- &SV::innodb_table_locks);
-sys_var_thd_bool sys_innodb_support_xa("innodb_support_xa",
- &SV::innodb_support_xa);
-sys_var_long_ptr sys_innodb_autoextend_increment("innodb_autoextend_increment",
- &srv_auto_extend_increment);
-sys_var_long_ptr sys_innodb_sync_spin_loops("innodb_sync_spin_loops",
- &srv_n_spin_wait_rounds);
-sys_var_long_ptr sys_innodb_concurrency_tickets("innodb_concurrency_tickets",
- &srv_n_free_tickets_to_enter);
-sys_var_long_ptr sys_innodb_thread_sleep_delay("innodb_thread_sleep_delay",
- &srv_thread_sleep_delay);
-sys_var_long_ptr sys_innodb_thread_concurrency("innodb_thread_concurrency",
- &srv_thread_concurrency);
-sys_var_long_ptr sys_innodb_commit_concurrency("innodb_commit_concurrency",
- &srv_commit_concurrency);
-sys_var_long_ptr sys_innodb_flush_log_at_trx_commit(
- "innodb_flush_log_at_trx_commit",
- &srv_flush_log_at_trx_commit);
-#endif
+
/* Condition pushdown to storage engine */
-sys_var_thd_bool
-sys_engine_condition_pushdown("engine_condition_pushdown",
+static sys_var_thd_bool
+sys_engine_condition_pushdown(&vars, "engine_condition_pushdown",
&SV::engine_condition_pushdown);
+#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
/* ndb thread specific variable settings */
-sys_var_thd_ulong
-sys_ndb_autoincrement_prefetch_sz("ndb_autoincrement_prefetch_sz",
+static sys_var_thd_ulong
+sys_ndb_autoincrement_prefetch_sz(&vars, "ndb_autoincrement_prefetch_sz",
&SV::ndb_autoincrement_prefetch_sz);
-sys_var_thd_bool
-sys_ndb_force_send("ndb_force_send", &SV::ndb_force_send);
+static sys_var_thd_bool
+sys_ndb_force_send(&vars, "ndb_force_send", &SV::ndb_force_send);
#ifdef HAVE_NDB_BINLOG
-sys_var_long_ptr
-sys_ndb_report_thresh_binlog_epoch_slip("ndb_report_thresh_binlog_epoch_slip",
+static sys_var_long_ptr
+sys_ndb_report_thresh_binlog_epoch_slip(&vars, "ndb_report_thresh_binlog_epoch_slip",
&ndb_report_thresh_binlog_epoch_slip);
-sys_var_long_ptr
-sys_ndb_report_thresh_binlog_mem_usage("ndb_report_thresh_binlog_mem_usage",
+static sys_var_long_ptr
+sys_ndb_report_thresh_binlog_mem_usage(&vars, "ndb_report_thresh_binlog_mem_usage",
&ndb_report_thresh_binlog_mem_usage);
#endif
-sys_var_thd_bool
-sys_ndb_use_exact_count("ndb_use_exact_count", &SV::ndb_use_exact_count);
-sys_var_thd_bool
-sys_ndb_use_transactions("ndb_use_transactions", &SV::ndb_use_transactions);
-sys_var_long_ptr
-sys_ndb_cache_check_time("ndb_cache_check_time", &ndb_cache_check_time);
-sys_var_thd_bool
-sys_ndb_index_stat_enable("ndb_index_stat_enable",
+static sys_var_thd_bool
+sys_ndb_use_exact_count(&vars, "ndb_use_exact_count", &SV::ndb_use_exact_count);
+static sys_var_thd_bool
+sys_ndb_use_transactions(&vars, "ndb_use_transactions", &SV::ndb_use_transactions);
+static sys_var_long_ptr
+sys_ndb_cache_check_time(&vars, "ndb_cache_check_time", &ndb_cache_check_time);
+static sys_var_const_str
+sys_ndb_connectstring(&vars, "ndb_connectstring", opt_ndb_constrbuf);
+static sys_var_thd_bool
+sys_ndb_index_stat_enable(&vars, "ndb_index_stat_enable",
&SV::ndb_index_stat_enable);
-sys_var_thd_ulong
-sys_ndb_index_stat_cache_entries("ndb_index_stat_cache_entries",
+static sys_var_thd_ulong
+sys_ndb_index_stat_cache_entries(&vars, "ndb_index_stat_cache_entries",
&SV::ndb_index_stat_cache_entries);
-sys_var_thd_ulong
-sys_ndb_index_stat_update_freq("ndb_index_stat_update_freq",
+static sys_var_thd_ulong
+sys_ndb_index_stat_update_freq(&vars, "ndb_index_stat_update_freq",
&SV::ndb_index_stat_update_freq);
-sys_var_long_ptr
-sys_ndb_extra_logging("ndb_extra_logging", &ndb_extra_logging);
-sys_var_thd_bool
-sys_ndb_use_copying_alter_table("ndb_use_copying_alter_table", &SV::ndb_use_copying_alter_table);
+static sys_var_long_ptr
+sys_ndb_extra_logging(&vars, "ndb_extra_logging", &ndb_extra_logging);
+static sys_var_thd_bool
+sys_ndb_use_copying_alter_table(&vars, "ndb_use_copying_alter_table", &SV::ndb_use_copying_alter_table);
+#endif //WITH_NDBCLUSTER_STORAGE_ENGINE
/* Time/date/datetime formats */
-sys_var_thd_date_time_format sys_time_format("time_format",
+static sys_var_thd_date_time_format sys_time_format(&vars, "time_format",
&SV::time_format,
MYSQL_TIMESTAMP_TIME);
-sys_var_thd_date_time_format sys_date_format("date_format",
+static sys_var_thd_date_time_format sys_date_format(&vars, "date_format",
&SV::date_format,
MYSQL_TIMESTAMP_DATE);
-sys_var_thd_date_time_format sys_datetime_format("datetime_format",
+static sys_var_thd_date_time_format sys_datetime_format(&vars, "datetime_format",
&SV::datetime_format,
MYSQL_TIMESTAMP_DATETIME);
/* Variables that are bits in THD */
-sys_var_thd_bit sys_autocommit("autocommit", 0,
+sys_var_thd_bit sys_autocommit(&vars, "autocommit", 0,
set_option_autocommit,
OPTION_NOT_AUTOCOMMIT,
1);
-static sys_var_thd_bit sys_big_tables("big_tables", 0,
+static sys_var_thd_bit sys_big_tables(&vars, "big_tables", 0,
set_option_bit,
OPTION_BIG_TABLES);
#ifndef TO_BE_DELETED /* Alias for big_tables */
-static sys_var_thd_bit sys_sql_big_tables("sql_big_tables", 0,
+static sys_var_thd_bit sys_sql_big_tables(&vars, "sql_big_tables", 0,
set_option_bit,
OPTION_BIG_TABLES);
#endif
-static sys_var_thd_bit sys_big_selects("sql_big_selects", 0,
+static sys_var_thd_bit sys_big_selects(&vars, "sql_big_selects", 0,
set_option_bit,
OPTION_BIG_SELECTS);
-static sys_var_thd_bit sys_log_off("sql_log_off",
+static sys_var_thd_bit sys_log_off(&vars, "sql_log_off",
check_log_update,
set_option_bit,
OPTION_LOG_OFF);
-static sys_var_thd_bit sys_log_update("sql_log_update",
+static sys_var_thd_bit sys_log_update(&vars, "sql_log_update",
check_log_update,
set_log_update,
OPTION_BIN_LOG);
-static sys_var_thd_bit sys_log_binlog("sql_log_bin",
+static sys_var_thd_bit sys_log_binlog(&vars, "sql_log_bin",
check_log_update,
set_option_bit,
OPTION_BIN_LOG);
-static sys_var_thd_bit sys_sql_warnings("sql_warnings", 0,
+static sys_var_thd_bit sys_sql_warnings(&vars, "sql_warnings", 0,
set_option_bit,
OPTION_WARNINGS);
-static sys_var_thd_bit sys_sql_notes("sql_notes", 0,
+static sys_var_thd_bit sys_sql_notes(&vars, "sql_notes", 0,
set_option_bit,
OPTION_SQL_NOTES);
-static sys_var_thd_bit sys_auto_is_null("sql_auto_is_null", 0,
+static sys_var_thd_bit sys_auto_is_null(&vars, "sql_auto_is_null", 0,
set_option_bit,
OPTION_AUTO_IS_NULL);
-static sys_var_thd_bit sys_safe_updates("sql_safe_updates", 0,
+static sys_var_thd_bit sys_safe_updates(&vars, "sql_safe_updates", 0,
set_option_bit,
OPTION_SAFE_UPDATES);
-static sys_var_thd_bit sys_buffer_results("sql_buffer_result", 0,
+static sys_var_thd_bit sys_buffer_results(&vars, "sql_buffer_result", 0,
set_option_bit,
OPTION_BUFFER_RESULT);
-static sys_var_thd_bit sys_quote_show_create("sql_quote_show_create", 0,
+static sys_var_thd_bit sys_quote_show_create(&vars, "sql_quote_show_create", 0,
set_option_bit,
OPTION_QUOTE_SHOW_CREATE);
-static sys_var_thd_bit sys_foreign_key_checks("foreign_key_checks", 0,
+static sys_var_thd_bit sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
set_option_bit,
OPTION_NO_FOREIGN_KEY_CHECKS,
1);
-static sys_var_thd_bit sys_unique_checks("unique_checks", 0,
+static sys_var_thd_bit sys_unique_checks(&vars, "unique_checks", 0,
set_option_bit,
OPTION_RELAXED_UNIQUE_CHECKS,
1);
/* Local state variables */
-static sys_var_thd_ha_rows sys_select_limit("sql_select_limit",
+static sys_var_thd_ha_rows sys_select_limit(&vars, "sql_select_limit",
&SV::select_limit);
-static sys_var_timestamp sys_timestamp("timestamp");
-static sys_var_last_insert_id sys_last_insert_id("last_insert_id");
-static sys_var_last_insert_id sys_identity("identity");
+static sys_var_timestamp sys_timestamp(&vars, "timestamp");
+static sys_var_last_insert_id sys_last_insert_id(&vars, "last_insert_id");
+static sys_var_last_insert_id sys_identity(&vars, "identity");
-static sys_var_thd_lc_time_names sys_lc_time_names("lc_time_names");
+static sys_var_thd_lc_time_names sys_lc_time_names(&vars, "lc_time_names");
-static sys_var_insert_id sys_insert_id("insert_id");
-static sys_var_readonly sys_error_count("error_count",
+static sys_var_insert_id sys_insert_id(&vars, "insert_id");
+static sys_var_readonly sys_error_count(&vars, "error_count",
OPT_SESSION,
SHOW_LONG,
get_error_count);
-static sys_var_readonly sys_warning_count("warning_count",
+static sys_var_readonly sys_warning_count(&vars, "warning_count",
OPT_SESSION,
SHOW_LONG,
get_warning_count);
/* alias for last_insert_id() to be compatible with Sybase */
-#ifdef HAVE_REPLICATION
-static sys_var_slave_skip_counter sys_slave_skip_counter("sql_slave_skip_counter");
-#endif
-static sys_var_rand_seed1 sys_rand_seed1("rand_seed1");
-static sys_var_rand_seed2 sys_rand_seed2("rand_seed2");
+static sys_var_rand_seed1 sys_rand_seed1(&vars, "rand_seed1");
+static sys_var_rand_seed2 sys_rand_seed2(&vars, "rand_seed2");
-static sys_var_thd_ulong sys_default_week_format("default_week_format",
+static sys_var_thd_ulong sys_default_week_format(&vars, "default_week_format",
&SV::default_week_format);
-sys_var_thd_ulong sys_group_concat_max_len("group_concat_max_len",
+sys_var_thd_ulong sys_group_concat_max_len(&vars, "group_concat_max_len",
&SV::group_concat_max_len);
-sys_var_thd_time_zone sys_time_zone("time_zone");
+sys_var_thd_time_zone sys_time_zone(&vars, "time_zone");
+
+/* Global read-only variable containing hostname */
+static sys_var_const_str sys_hostname(&vars, "hostname", glob_hostname);
/* Read only variables */
-/* Global read-only variable containing hostname */
-sys_var_const_str sys_hostname("hostname", glob_hostname);
-
-
-sys_var_have_variable sys_have_compress("have_compress", &have_compress);
-sys_var_have_variable sys_have_crypt("have_crypt", &have_crypt);
-sys_var_have_variable sys_have_csv_db("have_csv", &have_csv_db);
-sys_var_have_variable sys_have_dlopen("have_dynamic_loading", &have_dlopen);
-sys_var_have_variable sys_have_geometry("have_geometry", &have_geometry);
-sys_var_have_variable sys_have_innodb("have_innodb", &have_innodb);
-sys_var_have_variable sys_have_ndbcluster("have_ndbcluster", &have_ndbcluster);
-sys_var_have_variable sys_have_openssl("have_openssl", &have_ssl);
-sys_var_have_variable sys_have_ssl("have_ssl", &have_ssl);
-sys_var_have_variable sys_have_partition_db("have_partitioning",
- &have_partition_db);
-sys_var_have_variable sys_have_query_cache("have_query_cache",
+static sys_var_have_variable sys_have_compress(&vars, "have_compress", &have_compress);
+static sys_var_have_variable sys_have_crypt(&vars, "have_crypt", &have_crypt);
+static sys_var_have_plugin sys_have_csv(&vars, "have_csv", C_STRING_WITH_LEN("csv"), MYSQL_STORAGE_ENGINE_PLUGIN);
+static sys_var_have_variable sys_have_dlopen(&vars, "have_dynamic_loading", &have_dlopen);
+static sys_var_have_variable sys_have_geometry(&vars, "have_geometry", &have_geometry);
+static sys_var_have_plugin sys_have_innodb(&vars, "have_innodb", C_STRING_WITH_LEN("innodb"), MYSQL_STORAGE_ENGINE_PLUGIN);
+static sys_var_have_plugin sys_have_ndbcluster(&vars, "have_ndbcluster", C_STRING_WITH_LEN("ndbcluster"), MYSQL_STORAGE_ENGINE_PLUGIN);
+static sys_var_have_variable sys_have_openssl(&vars, "have_openssl", &have_ssl);
+static sys_var_have_variable sys_have_ssl(&vars, "have_ssl", &have_ssl);
+static sys_var_have_plugin sys_have_partition_db(&vars, "have_partitioning", C_STRING_WITH_LEN("partition"), MYSQL_STORAGE_ENGINE_PLUGIN);
+static sys_var_have_variable sys_have_query_cache(&vars, "have_query_cache",
&have_query_cache);
-sys_var_have_variable sys_have_rtree_keys("have_rtree_keys", &have_rtree_keys);
-sys_var_have_variable sys_have_symlink("have_symlink", &have_symlink);
+static sys_var_have_variable sys_have_rtree_keys(&vars, "have_rtree_keys", &have_rtree_keys);
+static sys_var_have_variable sys_have_symlink(&vars, "have_symlink", &have_symlink);
/* Global read-only variable describing server license */
-sys_var_const_str sys_license("license", STRINGIFY_ARG(LICENSE));
+static sys_var_const_str sys_license(&vars, "license", STRINGIFY_ARG(LICENSE));
/* Global variables which enable|disable logging */
-sys_var_log_state sys_var_general_log("general_log", &opt_log,
+static sys_var_log_state sys_var_general_log(&vars, "general_log", &opt_log,
QUERY_LOG_GENERAL);
-sys_var_log_state sys_var_slow_query_log("slow_query_log", &opt_slow_log,
+static sys_var_log_state sys_var_slow_query_log(&vars, "slow_query_log", &opt_slow_log,
QUERY_LOG_SLOW);
-sys_var_str sys_var_general_log_path("general_log_file", sys_check_log_path,
+sys_var_str sys_var_general_log_path(&vars, "general_log_file", sys_check_log_path,
sys_update_general_log_path,
sys_default_general_log_path,
opt_logname);
-sys_var_str sys_var_slow_log_path("slow_query_log_file", sys_check_log_path,
+sys_var_str sys_var_slow_log_path(&vars, "slow_query_log_file", sys_check_log_path,
sys_update_slow_log_path,
sys_default_slow_log_path,
opt_slow_logname);
-sys_var_log_output sys_var_log_output_state("log_output", &log_output_options,
+static sys_var_log_output sys_var_log_output_state(&vars, "log_output", &log_output_options,
&log_output_typelib, 0);
-#ifdef HAVE_REPLICATION
-static int show_slave_skip_errors(THD *thd, SHOW_VAR *var, char *buff)
-{
- var->type=SHOW_CHAR;
- var->value= buff;
- if (!use_slave_mask || bitmap_is_clear_all(&slave_error_mask))
- {
- var->value= const_cast<char *>("OFF");
- }
- else if (bitmap_is_set_all(&slave_error_mask))
- {
- var->value= const_cast<char *>("ALL");
- }
- else
- {
- /* 10 is enough assuming errors are max 4 digits */
- int i;
- var->value= buff;
- for (i= 1;
- i < MAX_SLAVE_ERROR &&
- (buff - var->value) < SHOW_VAR_FUNC_BUFF_SIZE;
- i++)
- {
- if (bitmap_is_set(&slave_error_mask, i))
- {
- buff= int10_to_str(i, buff, 10);
- *buff++= ',';
- }
- }
- if (var->value != buff)
- buff--; // Remove last ','
- if (i < MAX_SLAVE_ERROR)
- buff= strmov(buff, "..."); // Couldn't show all errors
- *buff=0;
- }
- return 0;
-}
-#endif /* HAVE_REPLICATION */
/*
- Variables shown by SHOW VARIABLES in alphabetical order
+ Additional variables (not derived from sys_var class, not accessible as
+ @@varname in SELECT or SET). Sorted in alphabetical order to facilitate
+ maintenance - SHOW VARIABLES will sort its output.
+ TODO: remove this list completely
*/
-SHOW_VAR init_vars[]= {
- {"auto_increment_increment", (char*) &sys_auto_increment_increment, SHOW_SYS},
- {"auto_increment_offset", (char*) &sys_auto_increment_offset, SHOW_SYS},
- {sys_automatic_sp_privileges.name,(char*) &sys_automatic_sp_privileges, SHOW_SYS},
+#define FIXED_VARS_SIZE (sizeof(fixed_vars) / sizeof(SHOW_VAR))
+static SHOW_VAR fixed_vars[]= {
{"back_log", (char*) &back_log, SHOW_LONG},
- {sys_basedir.name, (char*) &sys_basedir, SHOW_SYS},
- {sys_binlog_cache_size.name,(char*) &sys_binlog_cache_size, SHOW_SYS},
- {sys_binlog_format.name, (char*) &sys_binlog_format, SHOW_SYS},
- {sys_bulk_insert_buff_size.name,(char*) &sys_bulk_insert_buff_size,SHOW_SYS},
- {sys_character_set_client.name,(char*) &sys_character_set_client, SHOW_SYS},
- {sys_character_set_connection.name,(char*) &sys_character_set_connection,SHOW_SYS},
- {sys_character_set_database.name, (char*) &sys_character_set_database,SHOW_SYS},
- {sys_character_set_filesystem.name,(char*) &sys_character_set_filesystem, SHOW_SYS},
- {sys_character_set_results.name,(char*) &sys_character_set_results, SHOW_SYS},
- {sys_character_set_server.name, (char*) &sys_character_set_server,SHOW_SYS},
- {sys_charset_system.name, (char*) &sys_charset_system, SHOW_SYS},
{"character_sets_dir", mysql_charsets_dir, SHOW_CHAR},
- {sys_collation_connection.name,(char*) &sys_collation_connection, SHOW_SYS},
- {sys_collation_database.name,(char*) &sys_collation_database, SHOW_SYS},
- {sys_collation_server.name,(char*) &sys_collation_server, SHOW_SYS},
- {sys_completion_type.name, (char*) &sys_completion_type, SHOW_SYS},
- {sys_concurrent_insert.name,(char*) &sys_concurrent_insert, SHOW_SYS},
- {sys_connect_timeout.name, (char*) &sys_connect_timeout, SHOW_SYS},
- {sys_datadir.name, (char*) &sys_datadir, SHOW_SYS},
- {sys_date_format.name, (char*) &sys_date_format, SHOW_SYS},
- {sys_datetime_format.name, (char*) &sys_datetime_format, SHOW_SYS},
-#ifndef DBUG_OFF
- {sys_dbug.name, (char*) &sys_dbug, SHOW_SYS},
-#endif
- {sys_default_week_format.name, (char*) &sys_default_week_format, SHOW_SYS},
- {sys_delay_key_write.name, (char*) &sys_delay_key_write, SHOW_SYS},
- {sys_delayed_insert_limit.name, (char*) &sys_delayed_insert_limit,SHOW_SYS},
- {sys_delayed_insert_timeout.name, (char*) &sys_delayed_insert_timeout, SHOW_SYS},
- {sys_delayed_queue_size.name,(char*) &sys_delayed_queue_size, SHOW_SYS},
- {sys_div_precincrement.name,(char*) &sys_div_precincrement,SHOW_SYS},
- {sys_engine_condition_pushdown.name,
- (char*) &sys_engine_condition_pushdown, SHOW_SYS},
- {sys_event_scheduler.name, (char*) &sys_event_scheduler, SHOW_SYS},
- {sys_expire_logs_days.name, (char*) &sys_expire_logs_days, SHOW_SYS},
- {sys_flush.name, (char*) &sys_flush, SHOW_SYS},
- {sys_flush_time.name, (char*) &sys_flush_time, SHOW_SYS},
- {sys_ft_boolean_syntax.name,(char*) &ft_boolean_syntax, SHOW_CHAR},
{"ft_max_word_len", (char*) &ft_max_word_len, SHOW_LONG},
{"ft_min_word_len", (char*) &ft_min_word_len, SHOW_LONG},
{"ft_query_expansion_limit",(char*) &ft_query_expansion_limit, SHOW_LONG},
{"ft_stopword_file", (char*) &ft_stopword_file, SHOW_CHAR_PTR},
- {sys_var_general_log.name, (char*) &opt_log, SHOW_MY_BOOL},
- {sys_var_general_log_path.name, (char*) &sys_var_general_log_path, SHOW_SYS},
- {sys_group_concat_max_len.name, (char*) &sys_group_concat_max_len, SHOW_SYS},
- {sys_hostname.name, (char*) &sys_hostname, SHOW_SYS},
- {sys_have_compress.name, (char*) &have_compress, SHOW_HAVE},
- {sys_have_crypt.name, (char*) &have_crypt, SHOW_HAVE},
- {sys_have_csv_db.name, (char*) &have_csv_db, SHOW_HAVE},
- {sys_have_dlopen.name, (char*) &have_dlopen, SHOW_HAVE},
- {sys_have_geometry.name, (char*) &have_geometry, SHOW_HAVE},
- {sys_have_innodb.name, (char*) &have_innodb, SHOW_HAVE},
- {sys_have_ndbcluster.name, (char*) &have_ndbcluster, SHOW_HAVE},
- {sys_have_openssl.name, (char*) &have_ssl, SHOW_HAVE},
- {sys_have_ssl.name, (char*) &have_ssl, SHOW_HAVE},
- {sys_have_partition_db.name,(char*) &have_partition_db, SHOW_HAVE},
- {sys_have_query_cache.name, (char*) &have_query_cache, SHOW_HAVE},
- {sys_have_rtree_keys.name, (char*) &have_rtree_keys, SHOW_HAVE},
- {sys_have_symlink.name, (char*) &have_symlink, SHOW_HAVE},
- {"init_connect", (char*) &sys_init_connect, SHOW_SYS},
{"init_file", (char*) &opt_init_file, SHOW_CHAR_PTR},
- {"init_slave", (char*) &sys_init_slave, SHOW_SYS},
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
- {"innodb_additional_mem_pool_size", (char*) &innobase_additional_mem_pool_size, SHOW_LONG },
- {sys_innodb_autoextend_increment.name, (char*) &sys_innodb_autoextend_increment, SHOW_SYS},
- {"innodb_buffer_pool_size", (char*) &innobase_buffer_pool_size, SHOW_LONGLONG },
- {"innodb_checksums", (char*) &innobase_use_checksums, SHOW_MY_BOOL},
- {sys_innodb_commit_concurrency.name, (char*) &sys_innodb_commit_concurrency, SHOW_SYS},
- {sys_innodb_concurrency_tickets.name, (char*) &sys_innodb_concurrency_tickets, SHOW_SYS},
- {"innodb_data_file_path", (char*) &innobase_data_file_path, SHOW_CHAR_PTR},
- {"innodb_data_home_dir", (char*) &innobase_data_home_dir, SHOW_CHAR_PTR},
- {"innodb_doublewrite", (char*) &innobase_use_doublewrite, SHOW_MY_BOOL},
- {sys_innodb_fast_shutdown.name,(char*) &sys_innodb_fast_shutdown, SHOW_SYS},
- {"innodb_file_io_threads", (char*) &innobase_file_io_threads, SHOW_LONG },
- {"innodb_file_per_table", (char*) &innobase_file_per_table, SHOW_MY_BOOL},
- {"innodb_flush_method", (char*) &innobase_unix_file_flush_method, SHOW_CHAR_PTR},
- {"innodb_force_recovery", (char*) &innobase_force_recovery, SHOW_LONG },
- {"innodb_lock_wait_timeout", (char*) &innobase_lock_wait_timeout, SHOW_LONG },
- {"innodb_locks_unsafe_for_binlog", (char*) &innobase_locks_unsafe_for_binlog, SHOW_MY_BOOL},
- {"innodb_log_arch_dir", (char*) &innobase_log_arch_dir, SHOW_CHAR_PTR},
- {"innodb_log_archive", (char*) &innobase_log_archive, SHOW_MY_BOOL},
- {"innodb_log_buffer_size", (char*) &innobase_log_buffer_size, SHOW_LONG },
- {"innodb_log_file_size", (char*) &innobase_log_file_size, SHOW_LONGLONG},
- {"innodb_log_files_in_group", (char*) &innobase_log_files_in_group, SHOW_LONG},
- {"innodb_log_group_home_dir", (char*) &innobase_log_group_home_dir, SHOW_CHAR_PTR},
- {sys_innodb_max_dirty_pages_pct.name, (char*) &sys_innodb_max_dirty_pages_pct, SHOW_SYS},
- {sys_innodb_max_purge_lag.name, (char*) &sys_innodb_max_purge_lag, SHOW_SYS},
- {"innodb_mirrored_log_groups", (char*) &innobase_mirrored_log_groups, SHOW_LONG},
- {"innodb_open_files", (char*) &innobase_open_files, SHOW_LONG },
- {"innodb_rollback_on_timeout", (char*) &innobase_rollback_on_timeout, SHOW_MY_BOOL},
- {"innodb_stats_on_metadata", (char*) &innobase_stats_on_metadata, SHOW_MY_BOOL},
- {sys_innodb_support_xa.name, (char*) &sys_innodb_support_xa, SHOW_SYS},
- {sys_innodb_sync_spin_loops.name, (char*) &sys_innodb_sync_spin_loops, SHOW_SYS},
- {sys_innodb_table_locks.name, (char*) &sys_innodb_table_locks, SHOW_SYS},
- {sys_innodb_thread_concurrency.name, (char*) &sys_innodb_thread_concurrency, SHOW_SYS},
- {sys_innodb_thread_sleep_delay.name, (char*) &sys_innodb_thread_sleep_delay, SHOW_SYS},
- {sys_innodb_flush_log_at_trx_commit.name, (char*) &sys_innodb_flush_log_at_trx_commit, SHOW_SYS},
-#endif
- {sys_interactive_timeout.name,(char*) &sys_interactive_timeout, SHOW_SYS},
- {sys_join_buffer_size.name, (char*) &sys_join_buffer_size, SHOW_SYS},
- {sys_key_buffer_size.name, (char*) &sys_key_buffer_size, SHOW_SYS},
- {sys_key_cache_age_threshold.name, (char*) &sys_key_cache_age_threshold,
- SHOW_SYS},
- {sys_key_cache_block_size.name, (char*) &sys_key_cache_block_size,
- SHOW_SYS},
- {sys_key_cache_division_limit.name, (char*) &sys_key_cache_division_limit,
- SHOW_SYS},
{"language", language, SHOW_CHAR},
{"large_files_support", (char*) &opt_large_files, SHOW_BOOL},
{"large_page_size", (char*) &opt_large_page_size, SHOW_INT},
{"large_pages", (char*) &opt_large_pages, SHOW_MY_BOOL},
- {sys_lc_time_names.name, (char*) &sys_lc_time_names, SHOW_SYS},
- {sys_license.name, (char*) &sys_license, SHOW_SYS},
- {sys_local_infile.name, (char*) &sys_local_infile, SHOW_SYS},
#ifdef HAVE_MLOCKALL
- {"locked_in_memory", (char*) &locked_in_memory, SHOW_BOOL},
+ {"locked_in_memory", (char*) &locked_in_memory, SHOW_MY_BOOL},
#endif
- {"log", (char*) &opt_log, SHOW_BOOL},
+ {"log", (char*) &opt_log, SHOW_MY_BOOL},
{"log_bin", (char*) &opt_bin_log, SHOW_BOOL},
- {sys_trust_function_creators.name,(char*) &sys_trust_function_creators, SHOW_SYS},
{"log_error", (char*) log_error_file, SHOW_CHAR},
- {sys_var_log_output_state.name, (char*) &sys_var_log_output_state, SHOW_SYS},
- {sys_log_queries_not_using_indexes.name,
- (char*) &sys_log_queries_not_using_indexes, SHOW_SYS},
-#ifdef HAVE_REPLICATION
- {"log_slave_updates", (char*) &opt_log_slave_updates, SHOW_MY_BOOL},
-#endif
{"log_slow_queries", (char*) &opt_slow_log, SHOW_MY_BOOL},
- {sys_log_warnings.name, (char*) &sys_log_warnings, SHOW_SYS},
- {sys_long_query_time.name, (char*) &sys_long_query_time, SHOW_SYS},
- {sys_low_priority_updates.name, (char*) &sys_low_priority_updates, SHOW_SYS},
{"lower_case_file_system", (char*) &lower_case_file_system, SHOW_MY_BOOL},
{"lower_case_table_names", (char*) &lower_case_table_names, SHOW_INT},
- {sys_max_allowed_packet.name,(char*) &sys_max_allowed_packet, SHOW_SYS},
- {sys_max_binlog_cache_size.name,(char*) &sys_max_binlog_cache_size, SHOW_SYS},
- {sys_max_binlog_size.name, (char*) &sys_max_binlog_size, SHOW_SYS},
- {sys_max_connect_errors.name, (char*) &sys_max_connect_errors, SHOW_SYS},
- {sys_max_connections.name, (char*) &sys_max_connections, SHOW_SYS},
- {sys_max_delayed_threads.name,(char*) &sys_max_delayed_threads, SHOW_SYS},
- {sys_max_error_count.name, (char*) &sys_max_error_count, SHOW_SYS},
- {sys_max_heap_table_size.name,(char*) &sys_max_heap_table_size, SHOW_SYS},
- {sys_max_insert_delayed_threads.name,
- (char*) &sys_max_insert_delayed_threads, SHOW_SYS},
- {sys_max_join_size.name, (char*) &sys_max_join_size, SHOW_SYS},
- {sys_max_length_for_sort_data.name, (char*) &sys_max_length_for_sort_data,
- SHOW_SYS},
- {sys_max_prepared_stmt_count.name, (char*) &sys_max_prepared_stmt_count,
- SHOW_SYS},
- {sys_max_relay_log_size.name, (char*) &sys_max_relay_log_size, SHOW_SYS},
- {sys_max_seeks_for_key.name, (char*) &sys_max_seeks_for_key, SHOW_SYS},
- {sys_max_sort_length.name, (char*) &sys_max_sort_length, SHOW_SYS},
- {sys_max_sp_recursion_depth.name,
- (char*) &sys_max_sp_recursion_depth, SHOW_SYS},
- {sys_max_tmp_tables.name, (char*) &sys_max_tmp_tables, SHOW_SYS},
- {sys_max_user_connections.name,(char*) &sys_max_user_connections, SHOW_SYS},
- {sys_max_write_lock_count.name, (char*) &sys_max_write_lock_count,SHOW_SYS},
- {sys_multi_range_count.name, (char*) &sys_multi_range_count, SHOW_SYS},
- {sys_myisam_data_pointer_size.name, (char*) &sys_myisam_data_pointer_size, SHOW_SYS},
- {sys_myisam_max_sort_file_size.name, (char*) &sys_myisam_max_sort_file_size,
- SHOW_SYS},
{"myisam_recover_options", (char*) &myisam_recover_options_str, SHOW_CHAR_PTR},
- {sys_myisam_repair_threads.name, (char*) &sys_myisam_repair_threads,
- SHOW_SYS},
- {sys_myisam_sort_buffer_size.name, (char*) &sys_myisam_sort_buffer_size, SHOW_SYS},
-
- {sys_myisam_stats_method.name, (char*) &sys_myisam_stats_method, SHOW_SYS},
- {sys_myisam_use_mmap.name, (char*) &sys_myisam_use_mmap, SHOW_SYS},
-
#ifdef __NT__
{"named_pipe", (char*) &opt_enable_named_pipe, SHOW_MY_BOOL},
#endif
- {sys_ndb_autoincrement_prefetch_sz.name,
- (char*) &sys_ndb_autoincrement_prefetch_sz, SHOW_SYS},
- {sys_ndb_cache_check_time.name,(char*) &sys_ndb_cache_check_time, SHOW_SYS},
- {sys_ndb_extra_logging.name,(char*) &sys_ndb_extra_logging, SHOW_SYS},
- {sys_ndb_force_send.name, (char*) &sys_ndb_force_send, SHOW_SYS},
- {sys_ndb_index_stat_cache_entries.name, (char*) &sys_ndb_index_stat_cache_entries, SHOW_SYS},
- {sys_ndb_index_stat_enable.name, (char*) &sys_ndb_index_stat_enable, SHOW_SYS},
- {sys_ndb_index_stat_update_freq.name, (char*) &sys_ndb_index_stat_update_freq, SHOW_SYS},
-#ifdef HAVE_NDB_BINLOG
- {sys_ndb_report_thresh_binlog_epoch_slip.name,
- (char*) &sys_ndb_report_thresh_binlog_epoch_slip, SHOW_SYS},
- {sys_ndb_report_thresh_binlog_mem_usage.name,
- (char*) &sys_ndb_report_thresh_binlog_mem_usage, SHOW_SYS},
-#endif
- {sys_ndb_use_copying_alter_table.name,
- (char*) &sys_ndb_use_copying_alter_table, SHOW_SYS},
- {sys_ndb_use_exact_count.name,(char*) &sys_ndb_use_exact_count, SHOW_SYS},
- {sys_ndb_use_transactions.name,(char*) &sys_ndb_use_transactions, SHOW_SYS},
- {sys_net_buffer_length.name,(char*) &sys_net_buffer_length, SHOW_SYS},
- {sys_net_read_timeout.name, (char*) &sys_net_read_timeout, SHOW_SYS},
- {sys_net_retry_count.name, (char*) &sys_net_retry_count, SHOW_SYS},
- {sys_net_write_timeout.name,(char*) &sys_net_write_timeout, SHOW_SYS},
- {sys_new_mode.name, (char*) &sys_new_mode, SHOW_SYS},
- {sys_old_mode.name, (char*) &sys_old_mode, SHOW_SYS},
- {sys_old_alter_table.name, (char*) &sys_old_alter_table, SHOW_SYS},
- {sys_old_passwords.name, (char*) &sys_old_passwords, SHOW_SYS},
{"open_files_limit", (char*) &open_files_limit, SHOW_LONG},
- {sys_optimizer_prune_level.name, (char*) &sys_optimizer_prune_level,
- SHOW_SYS},
- {sys_optimizer_search_depth.name,(char*) &sys_optimizer_search_depth,
- SHOW_SYS},
{"pid_file", (char*) pidfile_name, SHOW_CHAR},
{"plugin_dir", (char*) opt_plugin_dir, SHOW_CHAR},
- {"port", (char*) &mysqld_port, SHOW_INT},
- {sys_preload_buff_size.name, (char*) &sys_preload_buff_size, SHOW_SYS},
+ {"port", (char*) &mysqld_port, SHOW_INT},
{"protocol_version", (char*) &protocol_version, SHOW_INT},
- {sys_query_alloc_block_size.name, (char*) &sys_query_alloc_block_size,
- SHOW_SYS},
-#ifdef HAVE_QUERY_CACHE
- {sys_query_cache_limit.name,(char*) &sys_query_cache_limit, SHOW_SYS},
- {sys_query_cache_min_res_unit.name, (char*) &sys_query_cache_min_res_unit,
- SHOW_SYS},
- {sys_query_cache_size.name, (char*) &sys_query_cache_size, SHOW_SYS},
- {sys_query_cache_type.name, (char*) &sys_query_cache_type, SHOW_SYS},
- {sys_query_cache_wlock_invalidate.name,
- (char *) &sys_query_cache_wlock_invalidate, SHOW_SYS},
-#endif /* HAVE_QUERY_CACHE */
- {sys_query_prealloc_size.name, (char*) &sys_query_prealloc_size, SHOW_SYS},
- {sys_range_alloc_block_size.name, (char*) &sys_range_alloc_block_size,
- SHOW_SYS},
- {sys_read_buff_size.name, (char*) &sys_read_buff_size, SHOW_SYS},
- {sys_readonly.name, (char*) &sys_readonly, SHOW_SYS},
- {sys_read_rnd_buff_size.name,(char*) &sys_read_rnd_buff_size, SHOW_SYS},
-#ifdef HAVE_REPLICATION
- {sys_relay_log_purge.name, (char*) &sys_relay_log_purge, SHOW_SYS},
- {"relay_log_space_limit", (char*) &relay_log_space_limit, SHOW_LONGLONG},
-#endif
- {sys_rpl_recovery_rank.name,(char*) &sys_rpl_recovery_rank, SHOW_SYS},
- {"secure_auth", (char*) &sys_secure_auth, SHOW_SYS},
- {"secure_file_priv", (char*) &sys_secure_file_priv, SHOW_SYS},
#ifdef HAVE_SMEM
{"shared_memory", (char*) &opt_enable_shared_memory, SHOW_MY_BOOL},
{"shared_memory_base_name", (char*) &shared_memory_base_name, SHOW_CHAR_PTR},
#endif
- {sys_server_id.name, (char*) &sys_server_id, SHOW_SYS},
{"skip_external_locking", (char*) &my_disable_locking, SHOW_MY_BOOL},
{"skip_networking", (char*) &opt_disable_networking, SHOW_BOOL},
{"skip_show_database", (char*) &opt_skip_show_db, SHOW_BOOL},
-#ifdef HAVE_REPLICATION
- {sys_slave_compressed_protocol.name,
- (char*) &sys_slave_compressed_protocol, SHOW_SYS},
- {"slave_load_tmpdir", (char*) &slave_load_tmpdir, SHOW_CHAR_PTR},
- {sys_slave_net_timeout.name,(char*) &sys_slave_net_timeout, SHOW_SYS},
- {"slave_skip_errors", (char*) &show_slave_skip_errors, SHOW_FUNC},
- {sys_slave_trans_retries.name,(char*) &sys_slave_trans_retries, SHOW_SYS},
-#endif
- {sys_slow_launch_time.name, (char*) &sys_slow_launch_time, SHOW_SYS},
- {sys_var_slow_query_log.name, (char*) &opt_slow_log, SHOW_MY_BOOL},
- {sys_var_slow_log_path.name, (char*) &sys_var_slow_log_path, SHOW_SYS},
#ifdef HAVE_SYS_UN_H
- {"socket", (char*) &mysqld_unix_port, SHOW_CHAR_PTR},
-#endif
- {sys_sort_buffer.name, (char*) &sys_sort_buffer, SHOW_SYS},
- {sys_big_selects.name, (char*) &sys_big_selects, SHOW_SYS},
- {sys_sql_mode.name, (char*) &sys_sql_mode, SHOW_SYS},
- {"sql_notes", (char*) &sys_sql_notes, SHOW_SYS},
- {"sql_warnings", (char*) &sys_sql_warnings, SHOW_SYS},
- {sys_ssl_ca.name, (char*) &sys_ssl_ca, SHOW_SYS},
- {sys_ssl_capath.name, (char*) &sys_ssl_capath, SHOW_SYS},
- {sys_ssl_cert.name, (char*) &sys_ssl_cert, SHOW_SYS},
- {sys_ssl_cipher.name, (char*) &sys_ssl_cipher, SHOW_SYS},
- {sys_ssl_key.name, (char*) &sys_ssl_key, SHOW_SYS},
- {sys_storage_engine.name, (char*) &sys_storage_engine, SHOW_SYS},
-#ifdef HAVE_REPLICATION
- {sys_sync_binlog_period.name,(char*) &sys_sync_binlog_period, SHOW_SYS},
-#endif
- {sys_sync_frm.name, (char*) &sys_sync_frm, SHOW_SYS},
-#ifdef HAVE_TZNAME
- {"system_time_zone", system_time_zone, SHOW_CHAR},
+ {"socket", (char*) &mysqld_unix_port, SHOW_CHAR_PTR},
#endif
{"table_definition_cache", (char*) &table_def_size, SHOW_LONG},
{"table_lock_wait_timeout", (char*) &table_lock_wait_timeout, SHOW_LONG },
- {"table_open_cache", (char*) &table_cache_size, SHOW_LONG},
- {sys_table_type.name, (char*) &sys_table_type, SHOW_SYS},
- {sys_thread_cache_size.name,(char*) &sys_thread_cache_size, SHOW_SYS},
#ifdef HAVE_THR_SETCONCURRENCY
{"thread_concurrency", (char*) &concurrency, SHOW_LONG},
#endif
- {sys_thread_handling.name, (char*) &sys_thread_handling, SHOW_SYS},
-#if HAVE_POOL_OF_THREADS == 1
- {sys_thread_pool_size.name, (char*) &sys_thread_pool_size, SHOW_SYS},
-#endif
{"thread_stack", (char*) &thread_stack, SHOW_LONG},
- {sys_time_format.name, (char*) &sys_time_format, SHOW_SYS},
- {"time_zone", (char*) &sys_time_zone, SHOW_SYS},
- {sys_timed_mutexes.name, (char*) &sys_timed_mutexes, SHOW_SYS},
- {sys_tmp_table_size.name, (char*) &sys_tmp_table_size, SHOW_SYS},
- {sys_tmpdir.name, (char*) &sys_tmpdir, SHOW_SYS},
- {sys_trans_alloc_block_size.name, (char*) &sys_trans_alloc_block_size,
- SHOW_SYS},
- {sys_trans_prealloc_size.name, (char*) &sys_trans_prealloc_size, SHOW_SYS},
- {sys_tx_isolation.name, (char*) &sys_tx_isolation, SHOW_SYS},
- {sys_updatable_views_with_limit.name,
- (char*) &sys_updatable_views_with_limit,SHOW_SYS},
- {sys_version.name, (char*) &sys_version, SHOW_SYS},
- {sys_version_comment.name, (char*) &sys_version_comment, SHOW_SYS},
- {sys_version_compile_machine.name, (char*) &sys_version_compile_machine,
- SHOW_SYS},
- {sys_version_compile_os.name, (char*) &sys_version_compile_os, SHOW_SYS},
- {sys_net_wait_timeout.name, (char*) &sys_net_wait_timeout, SHOW_SYS},
- {NullS, NullS, SHOW_LONG}
};
@@ -1150,6 +802,11 @@ static bool sys_update_ftb_syntax(THD *thd, set_var * var)
{
strmake(ft_boolean_syntax, var->value->str_value.c_ptr(),
sizeof(ft_boolean_syntax)-1);
+
+#ifdef HAVE_QUERY_CACHE
+ query_cache.flush();
+#endif /* HAVE_QUERY_CACHE */
+
return 0;
}
@@ -1347,7 +1004,8 @@ bool sys_var_thd_binlog_format::is_readonly() const
/*
Cluster does not support changing the binlog format on the fly yet.
*/
- if (opt_bin_log && (have_ndbcluster == SHOW_OPTION_YES))
+ LEX_STRING ndb_name= {(char*)STRING_WITH_LEN("ndbcluster")};
+ if (opt_bin_log && plugin_is_ready(&ndb_name, MYSQL_STORAGE_ENGINE_PLUGIN))
{
my_error(ER_NDB_CANT_SWITCH_BINLOG_FORMAT, MYF(0));
return 1;
@@ -1438,9 +1096,9 @@ static void fix_server_id(THD *thd, enum_var_type type)
sys_var_long_ptr::
-sys_var_long_ptr(const char *name_arg, ulong *value_ptr_arg,
+sys_var_long_ptr(sys_var_chain *chain, const char *name_arg, ulong *value_ptr_arg,
sys_after_update_func after_update_arg)
- :sys_var_long_ptr_global(name_arg, value_ptr_arg,
+ :sys_var_long_ptr_global(chain, name_arg, value_ptr_arg,
&LOCK_global_system_variables, after_update_arg)
{}
@@ -1824,7 +1482,13 @@ Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base)
return new Item_int((longlong) value);
}
case SHOW_MY_BOOL:
- return new Item_int((int32) *(my_bool*) value_ptr(thd, var_type, base),1);
+ {
+ int32 value;
+ pthread_mutex_lock(&LOCK_global_system_variables);
+ value= *(my_bool*) value_ptr(thd, var_type, base);
+ pthread_mutex_unlock(&LOCK_global_system_variables);
+ return new Item_int(value,1);
+ }
case SHOW_CHAR:
{
Item *tmp;
@@ -2133,122 +1797,25 @@ uchar *sys_var_character_set::value_ptr(THD *thd, enum_var_type type,
}
-CHARSET_INFO ** sys_var_character_set_connection::ci_ptr(THD *thd,
- enum_var_type type)
-{
- if (type == OPT_GLOBAL)
- return &global_system_variables.collation_connection;
- else
- return &thd->variables.collation_connection;
-}
-
-
-void sys_var_character_set_connection::set_default(THD *thd,
- enum_var_type type)
-{
- if (type == OPT_GLOBAL)
- global_system_variables.collation_connection= default_charset_info;
- else
- {
- thd->variables.collation_connection= global_system_variables.collation_connection;
- thd->update_charset();
- }
-}
-
-
-CHARSET_INFO ** sys_var_character_set_client::ci_ptr(THD *thd,
- enum_var_type type)
-{
- if (type == OPT_GLOBAL)
- return &global_system_variables.character_set_client;
- else
- return &thd->variables.character_set_client;
-}
-
-
-void sys_var_character_set_client::set_default(THD *thd, enum_var_type type)
-{
- if (type == OPT_GLOBAL)
- global_system_variables.character_set_client= default_charset_info;
- else
- {
- thd->variables.character_set_client= (global_system_variables.
- character_set_client);
- thd->update_charset();
- }
-}
-
-
-CHARSET_INFO **
-sys_var_character_set_filesystem::ci_ptr(THD *thd, enum_var_type type)
-{
- if (type == OPT_GLOBAL)
- return &global_system_variables.character_set_filesystem;
- else
- return &thd->variables.character_set_filesystem;
-}
-
-
-extern CHARSET_INFO *character_set_filesystem;
-
-void
-sys_var_character_set_filesystem::set_default(THD *thd, enum_var_type type)
-{
- if (type == OPT_GLOBAL)
- global_system_variables.character_set_filesystem= character_set_filesystem;
- else
- {
- thd->variables.character_set_filesystem= (global_system_variables.
- character_set_filesystem);
- thd->update_charset();
- }
-}
-
-
-CHARSET_INFO **
-sys_var_character_set_results::ci_ptr(THD *thd, enum_var_type type)
+void sys_var_character_set_sv::set_default(THD *thd, enum_var_type type)
{
if (type == OPT_GLOBAL)
- return &global_system_variables.character_set_results;
+ global_system_variables.*offset= *global_default;
else
- return &thd->variables.character_set_results;
-}
-
-
-void sys_var_character_set_results::set_default(THD *thd, enum_var_type type)
-{
- if (type == OPT_GLOBAL)
- global_system_variables.character_set_results= default_charset_info;
- else
- {
- thd->variables.character_set_results= (global_system_variables.
- character_set_results);
- thd->update_charset();
- }
+ {
+ thd->variables.*offset= global_system_variables.*offset;
+ thd->update_charset();
+ }
}
-
-
-CHARSET_INFO **
-sys_var_character_set_server::ci_ptr(THD *thd, enum_var_type type)
+CHARSET_INFO **sys_var_character_set_sv::ci_ptr(THD *thd, enum_var_type type)
{
if (type == OPT_GLOBAL)
- return &global_system_variables.collation_server;
+ return &(global_system_variables.*offset);
else
- return &thd->variables.collation_server;
+ return &(thd->variables.*offset);
}
-void sys_var_character_set_server::set_default(THD *thd, enum_var_type type)
-{
- if (type == OPT_GLOBAL)
- global_system_variables.collation_server= default_charset_info;
- else
- {
- thd->variables.collation_server= global_system_variables.collation_server;
- thd->update_charset();
- }
-}
-
CHARSET_INFO ** sys_var_character_set_database::ci_ptr(THD *thd,
enum_var_type type)
{
@@ -2271,74 +1838,28 @@ void sys_var_character_set_database::set_default(THD *thd, enum_var_type type)
}
-bool sys_var_collation_connection::update(THD *thd, set_var *var)
+bool sys_var_collation_sv::update(THD *thd, set_var *var)
{
if (var->type == OPT_GLOBAL)
- global_system_variables.collation_connection= var->save_result.charset;
+ global_system_variables.*offset= var->save_result.charset;
else
{
- thd->variables.collation_connection= var->save_result.charset;
+ thd->variables.*offset= var->save_result.charset;
thd->update_charset();
}
return 0;
}
-uchar *sys_var_collation_connection::value_ptr(THD *thd, enum_var_type type,
- LEX_STRING *base)
-{
- CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
- global_system_variables.collation_connection :
- thd->variables.collation_connection);
- return cs ? (uchar*) cs->name : (uchar*) "NULL";
-}
-
-
-void sys_var_collation_connection::set_default(THD *thd, enum_var_type type)
+void sys_var_collation_sv::set_default(THD *thd, enum_var_type type)
{
- if (type == OPT_GLOBAL)
- global_system_variables.collation_connection= default_charset_info;
- else
- {
- thd->variables.collation_connection= (global_system_variables.
- collation_connection);
- thd->update_charset();
- }
-}
-
-bool sys_var_collation_database::update(THD *thd, set_var *var)
-{
- if (var->type == OPT_GLOBAL)
- global_system_variables.collation_database= var->save_result.charset;
+ if (type == OPT_GLOBAL)
+ global_system_variables.*offset= *global_default;
else
{
- thd->variables.collation_database= var->save_result.charset;
+ thd->variables.*offset= global_system_variables.*offset;
thd->update_charset();
}
- return 0;
-}
-
-
-uchar *sys_var_collation_database::value_ptr(THD *thd, enum_var_type type,
- LEX_STRING *base)
-{
- CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
- global_system_variables.collation_database :
- thd->variables.collation_database);
- return cs ? (uchar*) cs->name : (uchar*) "NULL";
-}
-
-
-void sys_var_collation_database::set_default(THD *thd, enum_var_type type)
-{
- if (type == OPT_GLOBAL)
- global_system_variables.collation_database= default_charset_info;
- else
- {
- thd->variables.collation_database= (global_system_variables.
- collation_database);
- thd->update_charset();
- }
}
@@ -2355,29 +1876,15 @@ bool sys_var_collation_server::update(THD *thd, set_var *var)
}
-uchar *sys_var_collation_server::value_ptr(THD *thd, enum_var_type type,
- LEX_STRING *base)
+uchar *sys_var_collation_sv::value_ptr(THD *thd, enum_var_type type,
+ LEX_STRING *base)
{
CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
- global_system_variables.collation_server :
- thd->variables.collation_server);
+ global_system_variables.*offset : thd->variables.*offset);
return cs ? (uchar*) cs->name : (uchar*) "NULL";
}
-void sys_var_collation_server::set_default(THD *thd, enum_var_type type)
-{
- if (type == OPT_GLOBAL)
- global_system_variables.collation_server= default_charset_info;
- else
- {
- thd->variables.collation_server= (global_system_variables.
- collation_server);
- thd->update_charset();
- }
-}
-
-
LEX_STRING default_key_cache_base= {(char *) "default", 7 };
static KEY_CACHE zero_key_cache;
@@ -2820,52 +2327,6 @@ uchar *sys_var_insert_id::value_ptr(THD *thd, enum_var_type type,
}
-#ifdef HAVE_REPLICATION
-bool sys_var_slave_skip_counter::check(THD *thd, set_var *var)
-{
- int result= 0;
- pthread_mutex_lock(&LOCK_active_mi);
- pthread_mutex_lock(&active_mi->rli.run_lock);
- if (active_mi->rli.slave_running)
- {
- my_message(ER_SLAVE_MUST_STOP, ER(ER_SLAVE_MUST_STOP), MYF(0));
- result=1;
- }
- pthread_mutex_unlock(&active_mi->rli.run_lock);
- pthread_mutex_unlock(&LOCK_active_mi);
- var->save_result.ulong_value= (ulong) var->value->val_int();
- return result;
-}
-
-
-bool sys_var_slave_skip_counter::update(THD *thd, set_var *var)
-{
- pthread_mutex_lock(&LOCK_active_mi);
- pthread_mutex_lock(&active_mi->rli.run_lock);
- /*
- The following test should normally never be true as we test this
- in the check function; To be safe against multiple
- SQL_SLAVE_SKIP_COUNTER request, we do the check anyway
- */
- if (!active_mi->rli.slave_running)
- {
- pthread_mutex_lock(&active_mi->rli.data_lock);
- active_mi->rli.slave_skip_counter= var->save_result.ulong_value;
- pthread_mutex_unlock(&active_mi->rli.data_lock);
- }
- pthread_mutex_unlock(&active_mi->rli.run_lock);
- pthread_mutex_unlock(&LOCK_active_mi);
- return 0;
-}
-
-
-bool sys_var_sync_binlog_period::update(THD *thd, set_var *var)
-{
- sync_binlog_period= (ulong) var->save_result.ulonglong_value;
- return 0;
-}
-#endif /* HAVE_REPLICATION */
-
bool sys_var_rand_seed1::update(THD *thd, set_var *var)
{
thd->rand.seed1= (ulong) var->save_result.ulonglong_value;
@@ -3255,22 +2716,152 @@ static uchar *get_sys_var_length(const sys_var *var, size_t *length,
/*
- Initialises sys variables and put them in system_variable_hash
+ Add variables to the dynamic hash of system variables
+
+ SYNOPSIS
+ mysql_add_sys_var_chain()
+ first Pointer to first system variable to add
+ long_opt (optional)command line arguments may be tied for limit checks.
+
+ RETURN VALUES
+ 0 SUCCESS
+ otherwise FAILURE
*/
-void set_var_init()
+int mysql_add_sys_var_chain(sys_var *first, struct my_option *long_options)
{
sys_var *var;
-
- hash_init(&system_variable_hash, system_charset_info, sys_var::sys_vars, 0,
- 0, (hash_get_key) get_sys_var_length, 0, 0);
- for (var= sys_var::first; var; var= var->next)
+
+ /* A write lock should be held on LOCK_system_variables_hash */
+
+ for (var= first; var; var= var->next)
{
var->name_length= strlen(var->name);
- var->option_limits= find_option(my_long_options, var->name);
- my_hash_insert(&system_variable_hash, (uchar*) var);
+ /* this fails if there is a conflicting variable name. see HASH_UNIQUE */
+ if (my_hash_insert(&system_variable_hash, (uchar*) var))
+ goto error;
+ if (long_options)
+ var->option_limits= find_option(long_options, var->name);
+ }
+ return 0;
+
+error:
+ for (; first != var; first= first->next)
+ hash_delete(&system_variable_hash, (uchar*) first);
+ return 1;
+}
+
+
+/*
+ Remove variables to the dynamic hash of system variables
+
+ SYNOPSIS
+ mysql_del_sys_var_chain()
+ first Pointer to first system variable to remove
+
+ RETURN VALUES
+ 0 SUCCESS
+ otherwise FAILURE
+*/
+
+int mysql_del_sys_var_chain(sys_var *first)
+{
+ int result= 0;
+
+ /* A write lock should be held on LOCK_system_variables_hash */
+
+ for (sys_var *var= first; var; var= var->next)
+ result|= hash_delete(&system_variable_hash, (uchar*) var);
+
+ return result;
+}
+
+
+static int show_cmp(SHOW_VAR *a, SHOW_VAR *b)
+{
+ return strcmp(a->name, b->name);
+}
+
+
+/*
+ Constructs an array of system variables for display to the user.
+
+ SYNOPSIS
+ enumerate_sys_vars()
+ thd current thread
+ sorted If TRUE, the system variables should be sorted
+
+ RETURN VALUES
+ pointer Array of SHOW_VAR elements for display
+ NULL FAILURE
+*/
+
+SHOW_VAR* enumerate_sys_vars(THD *thd, bool sorted)
+{
+ int count= system_variable_hash.records, i;
+ int fixed_count= fixed_show_vars.elements;
+ int size= sizeof(SHOW_VAR) * (count + fixed_count + 1);
+ SHOW_VAR *result= (SHOW_VAR*) thd->alloc(size);
+
+ if (result)
+ {
+ SHOW_VAR *show= result + fixed_count;
+ memcpy(result, fixed_show_vars.buffer, fixed_count * sizeof(SHOW_VAR));
+
+ for (i= 0; i < count; i++)
+ {
+ sys_var *var= (sys_var*) hash_element(&system_variable_hash, i);
+ show->name= var->name;
+ show->value= (char*) var;
+ show->type= SHOW_SYS;
+ show++;
+ }
+
+ /* sort into order */
+ if (sorted)
+ qsort(result, count + fixed_count, sizeof(SHOW_VAR), (qsort_cmp)show_cmp);
+
+ /* make last element empty */
+ bzero(show, sizeof(SHOW_VAR));
}
+ return result;
+}
+
+
+/*
+ Initialize the system variables
+
+ SYNOPSIS
+ set_var_init()
+
+ RETURN VALUES
+ 0 SUCCESS
+ otherwise FAILURE
+*/
+
+int set_var_init()
+{
+ uint count= 0;
+ DBUG_ENTER("set_var_init");
+
+ for (sys_var *var=vars.first; var; var= var->next, count++);
+
+ if (my_init_dynamic_array(&fixed_show_vars, sizeof(SHOW_VAR),
+ FIXED_VARS_SIZE + 64, 64))
+ goto error;
+
+ fixed_show_vars.elements= FIXED_VARS_SIZE;
+ memcpy(fixed_show_vars.buffer, fixed_vars, sizeof(fixed_vars));
+
+ if (hash_init(&system_variable_hash, system_charset_info, count, 0,
+ 0, (hash_get_key) get_sys_var_length, 0, HASH_UNIQUE))
+ goto error;
+
+ vars.last->next= NULL;
+ if (mysql_add_sys_var_chain(vars.first, my_long_options))
+ goto error;
+
/*
Special cases
Needed because MySQL can't find the limits for a variable it it has
@@ -3278,12 +2869,40 @@ void set_var_init()
As these variables are deprecated, this code will disappear soon...
*/
sys_sql_max_join_size.option_limits= sys_max_join_size.option_limits;
+
+ DBUG_RETURN(0);
+
+error:
+ fprintf(stderr, "failed to initialize system variables");
+ DBUG_RETURN(1);
}
void set_var_free()
{
hash_free(&system_variable_hash);
+ delete_dynamic(&fixed_show_vars);
+}
+
+
+/*
+ Add elements to the dynamic list of read-only system variables.
+
+ SYNOPSIS
+ mysql_append_static_vars()
+ show_vars Pointer to start of array
+ count Number of elements
+
+ RETURN VALUES
+ 0 SUCCESS
+ otherwise FAILURE
+*/
+int mysql_append_static_vars(const SHOW_VAR *show_vars, uint count)
+{
+ for (; count > 0; count--, show_vars++)
+ if (insert_dynamic(&fixed_show_vars, (char*) show_vars))
+ return 1;
+ return 0;
}
@@ -3291,7 +2910,7 @@ void set_var_free()
Find a user set-table variable
SYNOPSIS
- find_sys_var()
+ intern_find_sys_var()
str Name of system variable to find
length Length of variable. zero means that we should use strlen()
on the variable
@@ -3301,14 +2920,19 @@ void set_var_free()
0 Unknown variable (error message is given)
*/
-sys_var *find_sys_var(const char *str, uint length)
+sys_var *intern_find_sys_var(const char *str, uint length, bool no_error)
{
- sys_var *var= (sys_var*) hash_search(&system_variable_hash,
- (uchar*) str,
- length ? length :
- strlen(str));
- if (!var)
+ sys_var *var;
+
+ /*
+ This function is only called from the sql_plugin.cc.
+ A lock on LOCK_system_variable_hash should be held
+ */
+ var= (sys_var*) hash_search(&system_variable_hash,
+ (uchar*) str, length ? length : strlen(str));
+ if (!(var || no_error))
my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
+
return var;
}
@@ -3574,14 +3198,16 @@ bool sys_var_thd_storage_engine::check(THD *thd, set_var *var)
const char *value;
String str(buff, sizeof(buff), &my_charset_latin1), *res;
+ var->save_result.plugin= NULL;
if (var->value->result_type() == STRING_RESULT)
{
LEX_STRING name;
- handlerton *db_type;
+ handlerton *hton;
if (!(res=var->value->val_str(&str)) ||
!(name.str= (char *)res->ptr()) || !(name.length= res->length()) ||
- !(var->save_result.hton= db_type= ha_resolve_by_name(thd, &name)) ||
- ha_checktype(thd, ha_legacy_type(db_type), 1, 0) != db_type)
+ !(var->save_result.plugin= ha_resolve_by_name(thd, &name)) ||
+ !(hton= plugin_data(var->save_result.plugin, handlerton *)) ||
+ ha_checktype(thd, ha_legacy_type(hton), 1, 0) != hton)
{
value= res ? res->c_ptr() : "NULL";
goto err;
@@ -3599,28 +3225,52 @@ err:
uchar *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type,
LEX_STRING *base)
{
- handlerton *val;
- val= (type == OPT_GLOBAL) ? global_system_variables.*offset :
- thd->variables.*offset;
- return (uchar *) hton2plugin[val->slot]->name.str;
+ uchar* result;
+ handlerton *hton;
+ LEX_STRING *name;
+ plugin_ref plugin= thd->variables.*offset;
+ if (type == OPT_GLOBAL)
+ plugin= my_plugin_lock(thd, &(global_system_variables.*offset));
+ hton= plugin_data(plugin, handlerton*);
+ name= &hton2plugin[hton->slot]->name;
+ result= (uchar *) thd->strmake(name->str, name->length);
+ if (type == OPT_GLOBAL)
+ plugin_unlock(thd, plugin);
+ return result;
}
void sys_var_thd_storage_engine::set_default(THD *thd, enum_var_type type)
{
+ plugin_ref old_value, new_value, *value;
if (type == OPT_GLOBAL)
- global_system_variables.*offset= myisam_hton;
+ {
+ value= &(global_system_variables.*offset);
+ new_value= ha_lock_engine(NULL, myisam_hton);
+ }
else
- thd->variables.*offset= global_system_variables.*offset;
+ {
+ value= &(thd->variables.*offset);
+ new_value= my_plugin_lock(NULL, &(global_system_variables.*offset));
+ }
+ DBUG_ASSERT(new_value);
+ old_value= *value;
+ *value= new_value;
+ plugin_unlock(NULL, old_value);
}
bool sys_var_thd_storage_engine::update(THD *thd, set_var *var)
{
- handlerton **value= &(global_system_variables.*offset);
- if (var->type != OPT_GLOBAL)
- value= &(thd->variables.*offset);
- *value= var->save_result.hton;
+ plugin_ref *value= &(global_system_variables.*offset), old_value;
+ if (var->type != OPT_GLOBAL)
+ value= &(thd->variables.*offset);
+ old_value= *value;
+ if (old_value != var->save_result.plugin)
+ {
+ *value= my_plugin_lock(NULL, &var->save_result.plugin);
+ plugin_unlock(NULL, old_value);
+ }
return 0;
}
diff --git a/sql/set_var.h b/sql/set_var.h
index 8e506734f60..4d58d64a725 100644
--- a/sql/set_var.h
+++ b/sql/set_var.h
@@ -26,6 +26,7 @@
class sys_var;
class set_var;
+class sys_var_pluginvar; /* opaque */
typedef struct system_variables SV;
typedef struct my_locale_st MY_LOCALE;
@@ -37,11 +38,15 @@ typedef void (*sys_after_update_func)(THD *,enum_var_type);
typedef void (*sys_set_default_func)(THD *, enum_var_type);
typedef uchar *(*sys_value_ptr_func)(THD *thd);
+struct sys_var_chain
+{
+ sys_var *first;
+ sys_var *last;
+};
+
class sys_var
{
public:
- static sys_var *first;
- static uint sys_vars;
sys_var *next;
struct my_option *option_limits; /* Updated by by set_var_init() */
uint name_length; /* Updated by by set_var_init() */
@@ -52,13 +57,15 @@ public:
sys_var(const char *name_arg,sys_after_update_func func= NULL)
:name(name_arg), after_update(func)
, no_support_one_shot(1)
- { add_sys_var(); }
+ {}
virtual ~sys_var() {}
- void add_sys_var()
+ void chain_sys_var(sys_var_chain *chain_arg)
{
- next= first;
- first= this;
- sys_vars++;
+ if (chain_arg->last)
+ chain_arg->last->next= this;
+ else
+ chain_arg->first= this;
+ chain_arg->last= this;
}
virtual bool check(THD *thd, set_var *var);
bool check_enum(THD *thd, set_var *var, const TYPELIB *enum_names);
@@ -77,6 +84,7 @@ public:
Item *item(THD *thd, enum_var_type type, LEX_STRING *base);
virtual bool is_struct() { return 0; }
virtual bool is_readonly() const { return 0; }
+ virtual sys_var_pluginvar *cast_pluginvar() { return 0; }
};
@@ -105,12 +113,12 @@ class sys_var_long_ptr_global: public sys_var_global
{
public:
ulong *value;
- sys_var_long_ptr_global(const char *name_arg, ulong *value_ptr_arg,
+ sys_var_long_ptr_global(sys_var_chain *chain, const char *name_arg, ulong *value_ptr_arg,
pthread_mutex_t *guard_arg,
sys_after_update_func after_update_arg= NULL)
:sys_var_global(name_arg, after_update_arg, guard_arg),
value(value_ptr_arg)
- {}
+ { chain_sys_var(chain); }
bool check(THD *thd, set_var *var);
bool update(THD *thd, set_var *var);
void set_default(THD *thd, enum_var_type type);
@@ -127,7 +135,7 @@ public:
class sys_var_long_ptr :public sys_var_long_ptr_global
{
public:
- sys_var_long_ptr(const char *name_arg, ulong *value_ptr,
+ sys_var_long_ptr(sys_var_chain *chain, const char *name_arg, ulong *value_ptr,
sys_after_update_func after_update_arg= NULL);
};
@@ -136,11 +144,13 @@ class sys_var_ulonglong_ptr :public sys_var
{
public:
ulonglong *value;
- sys_var_ulonglong_ptr(const char *name_arg, ulonglong *value_ptr_arg)
- :sys_var(name_arg),value(value_ptr_arg) {}
- sys_var_ulonglong_ptr(const char *name_arg, ulonglong *value_ptr_arg,
+ sys_var_ulonglong_ptr(sys_var_chain *chain, const char *name_arg, ulonglong *value_ptr_arg)
+ :sys_var(name_arg),value(value_ptr_arg)
+ { chain_sys_var(chain); }
+ sys_var_ulonglong_ptr(sys_var_chain *chain, const char *name_arg, ulonglong *value_ptr_arg,
sys_after_update_func func)
- :sys_var(name_arg,func), value(value_ptr_arg) {}
+ :sys_var(name_arg,func), value(value_ptr_arg)
+ { chain_sys_var(chain); }
bool update(THD *thd, set_var *var);
void set_default(THD *thd, enum_var_type type);
SHOW_TYPE show_type() { return SHOW_LONGLONG; }
@@ -153,9 +163,9 @@ class sys_var_bool_ptr :public sys_var
{
public:
my_bool *value;
- sys_var_bool_ptr(const char *name_arg, my_bool *value_arg)
+ sys_var_bool_ptr(sys_var_chain *chain, const char *name_arg, my_bool *value_arg)
:sys_var(name_arg),value(value_arg)
- {}
+ { chain_sys_var(chain); }
bool check(THD *thd, set_var *var)
{
return check_enum(thd, var, &bool_typelib);
@@ -172,8 +182,9 @@ public:
class sys_var_bool_ptr_readonly :public sys_var_bool_ptr
{
public:
- sys_var_bool_ptr_readonly(const char *name_arg, my_bool *value_arg)
- :sys_var_bool_ptr(name_arg, value_arg)
+ sys_var_bool_ptr_readonly(sys_var_chain *chain, const char *name_arg,
+ my_bool *value_arg)
+ :sys_var_bool_ptr(chain, name_arg, value_arg)
{}
bool is_readonly() const { return 1; }
};
@@ -187,14 +198,14 @@ public:
sys_check_func check_func;
sys_update_func update_func;
sys_set_default_func set_default_func;
- sys_var_str(const char *name_arg,
+ sys_var_str(sys_var_chain *chain, const char *name_arg,
sys_check_func check_func_arg,
sys_update_func update_func_arg,
sys_set_default_func set_default_func_arg,
char *value_arg)
:sys_var(name_arg), value(value_arg), check_func(check_func_arg),
update_func(update_func_arg),set_default_func(set_default_func_arg)
- {}
+ { chain_sys_var(chain); }
bool check(THD *thd, set_var *var);
bool update(THD *thd, set_var *var)
{
@@ -219,9 +230,9 @@ class sys_var_const_str :public sys_var
{
public:
char *value; // Pointer to const value
- sys_var_const_str(const char *name_arg, const char *value_arg)
+ sys_var_const_str(sys_var_chain *chain, const char *name_arg, const char *value_arg)
:sys_var(name_arg),value((char*) value_arg)
- {}
+ { chain_sys_var(chain); }
bool check(THD *thd, set_var *var)
{
return 1;
@@ -248,9 +259,9 @@ class sys_var_const_str_ptr :public sys_var
{
public:
char **value; // Pointer to const value
- sys_var_const_str_ptr(const char *name_arg, char **value_arg)
+ sys_var_const_str_ptr(sys_var_chain *chain, const char *name_arg, char **value_arg)
:sys_var(name_arg),value(value_arg)
- {}
+ { chain_sys_var(chain); }
bool check(THD *thd, set_var *var)
{
return 1;
@@ -278,10 +289,10 @@ class sys_var_enum :public sys_var
uint *value;
TYPELIB *enum_names;
public:
- sys_var_enum(const char *name_arg, uint *value_arg,
+ sys_var_enum(sys_var_chain *chain, const char *name_arg, uint *value_arg,
TYPELIB *typelib, sys_after_update_func func)
:sys_var(name_arg,func), value(value_arg), enum_names(typelib)
- {}
+ { chain_sys_var(chain); }
bool check(THD *thd, set_var *var)
{
return check_enum(thd, var, enum_names);
@@ -296,7 +307,8 @@ public:
class sys_var_thd :public sys_var
{
public:
- sys_var_thd(const char *name_arg, sys_after_update_func func= NULL)
+ sys_var_thd(const char *name_arg,
+ sys_after_update_func func= NULL)
:sys_var(name_arg,func)
{}
bool check_type(enum_var_type type) { return 0; }
@@ -312,13 +324,13 @@ class sys_var_thd_ulong :public sys_var_thd
sys_check_func check_func;
public:
ulong SV::*offset;
- sys_var_thd_ulong(const char *name_arg, ulong SV::*offset_arg)
+ sys_var_thd_ulong(sys_var_chain *chain, const char *name_arg, ulong SV::*offset_arg)
:sys_var_thd(name_arg), check_func(0), offset(offset_arg)
- {}
- sys_var_thd_ulong(const char *name_arg, ulong SV::*offset_arg,
+ { chain_sys_var(chain); }
+ sys_var_thd_ulong(sys_var_chain *chain, const char *name_arg, ulong SV::*offset_arg,
sys_check_func c_func, sys_after_update_func au_func)
:sys_var_thd(name_arg,au_func), check_func(c_func), offset(offset_arg)
- {}
+ { chain_sys_var(chain); }
bool check(THD *thd, set_var *var);
bool update(THD *thd, set_var *var);
void set_default(THD *thd, enum_var_type type);
@@ -331,13 +343,15 @@ class sys_var_thd_ha_rows :public sys_var_thd
{
public:
ha_rows SV::*offset;
- sys_var_thd_ha_rows(const char *name_arg, ha_rows SV::*offset_arg)
+ sys_var_thd_ha_rows(sys_var_chain *chain, const char *name_arg,
+ ha_rows SV::*offset_arg)
:sys_var_thd(name_arg), offset(offset_arg)
- {}
- sys_var_thd_ha_rows(const char *name_arg, ha_rows SV::*offset_arg,
+ { chain_sys_var(chain); }
+ sys_var_thd_ha_rows(sys_var_chain *chain, const char *name_arg,
+ ha_rows SV::*offset_arg,
sys_after_update_func func)
:sys_var_thd(name_arg,func), offset(offset_arg)
- {}
+ { chain_sys_var(chain); }
bool update(THD *thd, set_var *var);
void set_default(THD *thd, enum_var_type type);
SHOW_TYPE show_type() { return SHOW_HA_ROWS; }
@@ -350,14 +364,16 @@ class sys_var_thd_ulonglong :public sys_var_thd
public:
ulonglong SV::*offset;
bool only_global;
- sys_var_thd_ulonglong(const char *name_arg, ulonglong SV::*offset_arg)
+ sys_var_thd_ulonglong(sys_var_chain *chain, const char *name_arg,
+ ulonglong SV::*offset_arg)
:sys_var_thd(name_arg), offset(offset_arg)
- {}
- sys_var_thd_ulonglong(const char *name_arg, ulonglong SV::*offset_arg,
+ { chain_sys_var(chain); }
+ sys_var_thd_ulonglong(sys_var_chain *chain, const char *name_arg,
+ ulonglong SV::*offset_arg,
sys_after_update_func func, bool only_global_arg)
:sys_var_thd(name_arg, func), offset(offset_arg),
only_global(only_global_arg)
- {}
+ { chain_sys_var(chain); }
bool update(THD *thd, set_var *var);
void set_default(THD *thd, enum_var_type type);
SHOW_TYPE show_type() { return SHOW_LONGLONG; }
@@ -377,13 +393,13 @@ class sys_var_thd_bool :public sys_var_thd
{
public:
my_bool SV::*offset;
- sys_var_thd_bool(const char *name_arg, my_bool SV::*offset_arg)
+ sys_var_thd_bool(sys_var_chain *chain, const char *name_arg, my_bool SV::*offset_arg)
:sys_var_thd(name_arg), offset(offset_arg)
- {}
- sys_var_thd_bool(const char *name_arg, my_bool SV::*offset_arg,
+ { chain_sys_var(chain); }
+ sys_var_thd_bool(sys_var_chain *chain, const char *name_arg, my_bool SV::*offset_arg,
sys_after_update_func func)
:sys_var_thd(name_arg,func), offset(offset_arg)
- {}
+ { chain_sys_var(chain); }
bool update(THD *thd, set_var *var);
void set_default(THD *thd, enum_var_type type);
SHOW_TYPE show_type() { return SHOW_MY_BOOL; }
@@ -403,23 +419,23 @@ protected:
TYPELIB *enum_names;
sys_check_func check_func;
public:
- sys_var_thd_enum(const char *name_arg, ulong SV::*offset_arg,
+ sys_var_thd_enum(sys_var_chain *chain, const char *name_arg, ulong SV::*offset_arg,
TYPELIB *typelib)
:sys_var_thd(name_arg), offset(offset_arg), enum_names(typelib),
check_func(0)
- {}
- sys_var_thd_enum(const char *name_arg, ulong SV::*offset_arg,
+ { chain_sys_var(chain); }
+ sys_var_thd_enum(sys_var_chain *chain, const char *name_arg, ulong SV::*offset_arg,
TYPELIB *typelib,
sys_after_update_func func)
:sys_var_thd(name_arg,func), offset(offset_arg), enum_names(typelib),
check_func(0)
- {}
- sys_var_thd_enum(const char *name_arg, ulong SV::*offset_arg,
+ { chain_sys_var(chain); }
+ sys_var_thd_enum(sys_var_chain *chain, const char *name_arg, ulong SV::*offset_arg,
TYPELIB *typelib, sys_after_update_func func,
sys_check_func check)
:sys_var_thd(name_arg,func), offset(offset_arg), enum_names(typelib),
check_func(check)
- {}
+ { chain_sys_var(chain); }
bool check(THD *thd, set_var *var)
{
int ret= 0;
@@ -440,8 +456,9 @@ extern void fix_sql_mode_var(THD *thd, enum_var_type type);
class sys_var_thd_sql_mode :public sys_var_thd_enum
{
public:
- sys_var_thd_sql_mode(const char *name_arg, ulong SV::*offset_arg)
- :sys_var_thd_enum(name_arg, offset_arg, &sql_mode_typelib,
+ sys_var_thd_sql_mode(sys_var_chain *chain, const char *name_arg,
+ ulong SV::*offset_arg)
+ :sys_var_thd_enum(chain, name_arg, offset_arg, &sql_mode_typelib,
fix_sql_mode_var)
{}
bool check(THD *thd, set_var *var)
@@ -458,11 +475,12 @@ public:
class sys_var_thd_storage_engine :public sys_var_thd
{
protected:
- handlerton *SV::*offset;
+ plugin_ref SV::*offset;
public:
- sys_var_thd_storage_engine(const char *name_arg, handlerton *SV::*offset_arg)
+ sys_var_thd_storage_engine(sys_var_chain *chain, const char *name_arg,
+ plugin_ref SV::*offset_arg)
:sys_var_thd(name_arg), offset(offset_arg)
- {}
+ { chain_sys_var(chain); }
bool check(THD *thd, set_var *var);
SHOW_TYPE show_type() { return SHOW_CHAR; }
bool check_update_type(Item_result type)
@@ -477,8 +495,9 @@ public:
class sys_var_thd_table_type :public sys_var_thd_storage_engine
{
public:
- sys_var_thd_table_type(const char *name_arg, handlerton *SV::*offset_arg)
- :sys_var_thd_storage_engine(name_arg, offset_arg)
+ sys_var_thd_table_type(sys_var_chain *chain, const char *name_arg,
+ plugin_ref SV::*offset_arg)
+ :sys_var_thd_storage_engine(chain, name_arg, offset_arg)
{}
void warn_deprecated(THD *thd);
void set_default(THD *thd, enum_var_type type);
@@ -492,12 +511,12 @@ class sys_var_thd_bit :public sys_var_thd
public:
ulonglong bit_flag;
bool reverse;
- sys_var_thd_bit(const char *name_arg,
+ sys_var_thd_bit(sys_var_chain *chain, const char *name_arg,
sys_check_func c_func, sys_update_func u_func,
ulonglong bit, bool reverse_arg=0)
:sys_var_thd(name_arg), check_func(c_func), update_func(u_func),
bit_flag(bit), reverse(reverse_arg)
- {}
+ { chain_sys_var(chain); }
bool check(THD *thd, set_var *var);
bool update(THD *thd, set_var *var);
bool check_update_type(Item_result type) { return 0; }
@@ -509,7 +528,9 @@ public:
class sys_var_thd_dbug :public sys_var_thd
{
public:
- sys_var_thd_dbug(const char *name_arg) :sys_var_thd(name_arg) {}
+ sys_var_thd_dbug(sys_var_chain *chain, const char *name_arg)
+ :sys_var_thd(name_arg)
+ { chain_sys_var(chain); }
bool check_update_type(Item_result type) { return type != STRING_RESULT; }
bool check(THD *thd, set_var *var);
SHOW_TYPE show_type() { return SHOW_CHAR; }
@@ -525,7 +546,9 @@ public:
class sys_var_timestamp :public sys_var
{
public:
- sys_var_timestamp(const char *name_arg) :sys_var(name_arg) {}
+ sys_var_timestamp(sys_var_chain *chain, const char *name_arg)
+ :sys_var(name_arg)
+ { chain_sys_var(chain); }
bool update(THD *thd, set_var *var);
void set_default(THD *thd, enum_var_type type);
bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
@@ -538,7 +561,9 @@ public:
class sys_var_last_insert_id :public sys_var
{
public:
- sys_var_last_insert_id(const char *name_arg) :sys_var(name_arg) {}
+ sys_var_last_insert_id(sys_var_chain *chain, const char *name_arg)
+ :sys_var(name_arg)
+ { chain_sys_var(chain); }
bool update(THD *thd, set_var *var);
bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
SHOW_TYPE show_type() { return SHOW_LONGLONG; }
@@ -549,7 +574,9 @@ public:
class sys_var_insert_id :public sys_var
{
public:
- sys_var_insert_id(const char *name_arg) :sys_var(name_arg) {}
+ sys_var_insert_id(sys_var_chain *chain, const char *name_arg)
+ :sys_var(name_arg)
+ { chain_sys_var(chain); }
bool update(THD *thd, set_var *var);
bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
SHOW_TYPE show_type() { return SHOW_LONGLONG; }
@@ -557,33 +584,12 @@ public:
};
-#ifdef HAVE_REPLICATION
-class sys_var_slave_skip_counter :public sys_var
-{
-public:
- sys_var_slave_skip_counter(const char *name_arg) :sys_var(name_arg) {}
- bool check(THD *thd, set_var *var);
- bool update(THD *thd, set_var *var);
- bool check_type(enum_var_type type) { return type != OPT_GLOBAL; }
- /*
- We can't retrieve the value of this, so we don't have to define
- show_type() or value_ptr()
- */
-};
-
-class sys_var_sync_binlog_period :public sys_var_long_ptr
-{
-public:
- sys_var_sync_binlog_period(const char *name_arg, ulong *value_ptr_arg)
- :sys_var_long_ptr(name_arg,value_ptr_arg) {}
- bool update(THD *thd, set_var *var);
-};
-#endif
-
class sys_var_rand_seed1 :public sys_var
{
public:
- sys_var_rand_seed1(const char *name_arg) :sys_var(name_arg) {}
+ sys_var_rand_seed1(sys_var_chain *chain, const char *name_arg)
+ :sys_var(name_arg)
+ { chain_sys_var(chain); }
bool update(THD *thd, set_var *var);
bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
};
@@ -591,7 +597,9 @@ public:
class sys_var_rand_seed2 :public sys_var
{
public:
- sys_var_rand_seed2(const char *name_arg) :sys_var(name_arg) {}
+ sys_var_rand_seed2(sys_var_chain *chain, const char *name_arg)
+ :sys_var(name_arg)
+ { chain_sys_var(chain); }
bool update(THD *thd, set_var *var);
bool check_type(enum_var_type type) { return type == OPT_GLOBAL; }
};
@@ -600,7 +608,8 @@ public:
class sys_var_collation :public sys_var_thd
{
public:
- sys_var_collation(const char *name_arg) :sys_var_thd(name_arg)
+ sys_var_collation(const char *name_arg)
+ :sys_var_thd(name_arg)
{
no_support_one_shot= 0;
}
@@ -618,10 +627,9 @@ class sys_var_character_set :public sys_var_thd
{
public:
bool nullable;
- sys_var_character_set(const char *name_arg) :
- sys_var_thd(name_arg)
+ sys_var_character_set(const char *name_arg, bool is_nullable= 0) :
+ sys_var_thd(name_arg), nullable(is_nullable)
{
- nullable= 0;
/*
In fact only almost all variables derived from sys_var_character_set
support ONE_SHOT; character_set_results doesn't. But that's good enough.
@@ -641,83 +649,46 @@ public:
virtual CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type)= 0;
};
-class sys_var_character_set_filesystem :public sys_var_character_set
-{
-public:
- sys_var_character_set_filesystem(const char *name_arg) :
- sys_var_character_set(name_arg) {}
- void set_default(THD *thd, enum_var_type type);
- CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type);
-};
-
-class sys_var_character_set_client :public sys_var_character_set
+class sys_var_character_set_sv :public sys_var_character_set
{
+ CHARSET_INFO *SV::*offset;
+ CHARSET_INFO **global_default;
public:
- sys_var_character_set_client(const char *name_arg) :
- sys_var_character_set(name_arg) {}
+ sys_var_character_set_sv(sys_var_chain *chain, const char *name_arg,
+ CHARSET_INFO *SV::*offset_arg,
+ CHARSET_INFO **global_default_arg,
+ bool is_nullable= 0)
+ : sys_var_character_set(name_arg, is_nullable),
+ offset(offset_arg), global_default(global_default_arg)
+ { chain_sys_var(chain); }
void set_default(THD *thd, enum_var_type type);
CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type);
};
-class sys_var_character_set_results :public sys_var_character_set
-{
-public:
- sys_var_character_set_results(const char *name_arg) :
- sys_var_character_set(name_arg)
- { nullable= 1; }
- void set_default(THD *thd, enum_var_type type);
- CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type);
-};
-
-class sys_var_character_set_server :public sys_var_character_set
-{
-public:
- sys_var_character_set_server(const char *name_arg) :
- sys_var_character_set(name_arg) {}
- void set_default(THD *thd, enum_var_type type);
- CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type);
-};
class sys_var_character_set_database :public sys_var_character_set
{
public:
- sys_var_character_set_database(const char *name_arg) :
- sys_var_character_set(name_arg) {}
- void set_default(THD *thd, enum_var_type type);
- CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type);
-};
-
-class sys_var_character_set_connection :public sys_var_character_set
-{
-public:
- sys_var_character_set_connection(const char *name_arg) :
- sys_var_character_set(name_arg) {}
+ sys_var_character_set_database(sys_var_chain *chain, const char *name_arg) :
+ sys_var_character_set(name_arg)
+ { chain_sys_var(chain); }
void set_default(THD *thd, enum_var_type type);
CHARSET_INFO **ci_ptr(THD *thd, enum_var_type type);
};
-class sys_var_collation_connection :public sys_var_collation
-{
-public:
- sys_var_collation_connection(const char *name_arg) :sys_var_collation(name_arg) {}
- bool update(THD *thd, set_var *var);
- void set_default(THD *thd, enum_var_type type);
- uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
-};
-
-class sys_var_collation_server :public sys_var_collation
+class sys_var_collation_sv :public sys_var_collation
{
+ CHARSET_INFO *SV::*offset;
+ CHARSET_INFO **global_default;
public:
- sys_var_collation_server(const char *name_arg) :sys_var_collation(name_arg) {}
- bool update(THD *thd, set_var *var);
- void set_default(THD *thd, enum_var_type type);
- uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
-};
-
-class sys_var_collation_database :public sys_var_collation
-{
-public:
- sys_var_collation_database(const char *name_arg) :sys_var_collation(name_arg) {}
+ sys_var_collation_sv(sys_var_chain *chain, const char *name_arg,
+ CHARSET_INFO *SV::*offset_arg,
+ CHARSET_INFO **global_default_arg)
+ :sys_var_collation(name_arg),
+ offset(offset_arg), global_default(global_default_arg)
+ {
+ chain_sys_var(chain);
+ }
bool update(THD *thd, set_var *var);
void set_default(THD *thd, enum_var_type type);
uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
@@ -729,9 +700,10 @@ class sys_var_key_cache_param :public sys_var
protected:
size_t offset;
public:
- sys_var_key_cache_param(const char *name_arg, size_t offset_arg)
+ sys_var_key_cache_param(sys_var_chain *chain, const char *name_arg,
+ size_t offset_arg)
:sys_var(name_arg), offset(offset_arg)
- {}
+ { chain_sys_var(chain); }
uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
bool check_default(enum_var_type type) { return 1; }
bool is_struct() { return 1; }
@@ -741,8 +713,9 @@ public:
class sys_var_key_buffer_size :public sys_var_key_cache_param
{
public:
- sys_var_key_buffer_size(const char *name_arg)
- :sys_var_key_cache_param(name_arg, offsetof(KEY_CACHE, param_buff_size))
+ sys_var_key_buffer_size(sys_var_chain *chain, const char *name_arg)
+ :sys_var_key_cache_param(chain, name_arg,
+ offsetof(KEY_CACHE, param_buff_size))
{}
bool update(THD *thd, set_var *var);
SHOW_TYPE show_type() { return SHOW_LONGLONG; }
@@ -752,8 +725,8 @@ public:
class sys_var_key_cache_long :public sys_var_key_cache_param
{
public:
- sys_var_key_cache_long(const char *name_arg, size_t offset_arg)
- :sys_var_key_cache_param(name_arg, offset_arg)
+ sys_var_key_cache_long(sys_var_chain *chain, const char *name_arg, size_t offset_arg)
+ :sys_var_key_cache_param(chain, name_arg, offset_arg)
{}
bool update(THD *thd, set_var *var);
SHOW_TYPE show_type() { return SHOW_LONG; }
@@ -765,12 +738,12 @@ class sys_var_thd_date_time_format :public sys_var_thd
DATE_TIME_FORMAT *SV::*offset;
timestamp_type date_time_type;
public:
- sys_var_thd_date_time_format(const char *name_arg,
+ sys_var_thd_date_time_format(sys_var_chain *chain, const char *name_arg,
DATE_TIME_FORMAT *SV::*offset_arg,
timestamp_type date_time_type_arg)
:sys_var_thd(name_arg), offset(offset_arg),
date_time_type(date_time_type_arg)
- {}
+ { chain_sys_var(chain); }
SHOW_TYPE show_type() { return SHOW_CHAR; }
bool check_update_type(Item_result type)
{
@@ -789,8 +762,9 @@ class sys_var_log_state :public sys_var_bool_ptr
{
uint log_type;
public:
- sys_var_log_state(const char *name_arg, my_bool *value_arg, uint log_type_arg)
- :sys_var_bool_ptr(name_arg, value_arg), log_type(log_type_arg) {}
+ sys_var_log_state(sys_var_chain *chain, const char *name_arg, my_bool *value_arg,
+ uint log_type_arg)
+ :sys_var_bool_ptr(chain, name_arg, value_arg), log_type(log_type_arg) {}
bool update(THD *thd, set_var *var);
void set_default(THD *thd, enum_var_type type);
};
@@ -801,10 +775,10 @@ class sys_var_log_output :public sys_var
ulong *value;
TYPELIB *enum_names;
public:
- sys_var_log_output(const char *name_arg, ulong *value_arg,
+ sys_var_log_output(sys_var_chain *chain, const char *name_arg, ulong *value_arg,
TYPELIB *typelib, sys_after_update_func func)
:sys_var(name_arg,func), value(value_arg), enum_names(typelib)
- {}
+ { chain_sys_var(chain); }
bool check(THD *thd, set_var *var)
{
return check_set(thd, var, enum_names);
@@ -825,12 +799,12 @@ public:
enum_var_type var_type;
SHOW_TYPE show_type_value;
sys_value_ptr_func value_ptr_func;
- sys_var_readonly(const char *name_arg, enum_var_type type,
+ sys_var_readonly(sys_var_chain *chain, const char *name_arg, enum_var_type type,
SHOW_TYPE show_type_arg,
sys_value_ptr_func value_ptr_func_arg)
:sys_var(name_arg), var_type(type),
show_type_value(show_type_arg), value_ptr_func(value_ptr_func_arg)
- {}
+ { chain_sys_var(chain); }
bool update(THD *thd, set_var *var) { return 1; }
bool check_default(enum_var_type type) { return 1; }
bool check_type(enum_var_type type) { return type != var_type; }
@@ -844,19 +818,17 @@ public:
};
-class sys_var_have_variable: public sys_var
+class sys_var_have_option: public sys_var
{
- SHOW_COMP_OPTION *have_variable;
-
+protected:
+ virtual SHOW_COMP_OPTION get_option() = 0;
public:
- sys_var_have_variable(const char *variable_name,
- SHOW_COMP_OPTION *have_variable_arg):
- sys_var(variable_name),
- have_variable(have_variable_arg)
- { }
+ sys_var_have_option(sys_var_chain *chain, const char *variable_name):
+ sys_var(variable_name)
+ { chain_sys_var(chain); }
uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
{
- return (uchar*) show_comp_option_name[*have_variable];
+ return (uchar*) show_comp_option_name[get_option()];
}
bool update(THD *thd, set_var *var) { return 1; }
bool check_default(enum_var_type type) { return 1; }
@@ -867,13 +839,47 @@ public:
};
+class sys_var_have_variable: public sys_var_have_option
+{
+ SHOW_COMP_OPTION *have_variable;
+
+public:
+ sys_var_have_variable(sys_var_chain *chain, const char *variable_name,
+ SHOW_COMP_OPTION *have_variable_arg):
+ sys_var_have_option(chain, variable_name),
+ have_variable(have_variable_arg)
+ { }
+ SHOW_COMP_OPTION get_option() { return *have_variable; }
+};
+
+
+class sys_var_have_plugin: public sys_var_have_option
+{
+ const char *plugin_name_str;
+ const uint plugin_name_len;
+ const int plugin_type;
+
+public:
+ sys_var_have_plugin(sys_var_chain *chain, const char *variable_name,
+ const char *plugin_name_str_arg, uint plugin_name_len_arg,
+ int plugin_type_arg):
+ sys_var_have_option(chain, variable_name),
+ plugin_name_str(plugin_name_str_arg), plugin_name_len(plugin_name_len_arg),
+ plugin_type(plugin_type_arg)
+ { }
+ /* the following method is declared in sql_plugin.cc */
+ SHOW_COMP_OPTION get_option();
+};
+
+
class sys_var_thd_time_zone :public sys_var_thd
{
public:
- sys_var_thd_time_zone(const char *name_arg):
+ sys_var_thd_time_zone(sys_var_chain *chain, const char *name_arg):
sys_var_thd(name_arg)
{
no_support_one_shot= 0;
+ chain_sys_var(chain);
}
bool check(THD *thd, set_var *var);
SHOW_TYPE show_type() { return SHOW_CHAR; }
@@ -891,8 +897,9 @@ public:
class sys_var_max_user_conn : public sys_var_thd
{
public:
- sys_var_max_user_conn(const char *name_arg):
- sys_var_thd(name_arg) {}
+ sys_var_max_user_conn(sys_var_chain *chain, const char *name_arg):
+ sys_var_thd(name_arg)
+ { chain_sys_var(chain); }
bool check(THD *thd, set_var *var);
bool update(THD *thd, set_var *var);
bool check_default(enum_var_type type)
@@ -908,8 +915,9 @@ class sys_var_trust_routine_creators :public sys_var_bool_ptr
{
/* We need a derived class only to have a warn_deprecated() */
public:
- sys_var_trust_routine_creators(const char *name_arg, my_bool *value_arg) :
- sys_var_bool_ptr(name_arg, value_arg) {};
+ sys_var_event_scheduler(sys_var_chain *chain, const char *name_arg) :
+ sys_var_long_ptr(chain, name_arg, NULL, NULL) {};
+ sys_var_bool_ptr(chain, name_arg, value_arg) {};
void warn_deprecated(THD *thd);
void set_default(THD *thd, enum_var_type type);
bool update(THD *thd, set_var *var);
@@ -923,8 +931,9 @@ public:
class sys_var_opt_readonly :public sys_var_bool_ptr
{
public:
- sys_var_opt_readonly(const char *name_arg, my_bool *value_arg) :
- sys_var_bool_ptr(name_arg, value_arg) {};
+ sys_var_opt_readonly(sys_var_chain *chain, const char *name_arg,
+ my_bool *value_arg) :
+ sys_var_bool_ptr(chain, name_arg, value_arg) {};
~sys_var_opt_readonly() {};
bool update(THD *thd, set_var *var);
};
@@ -933,12 +942,13 @@ public:
class sys_var_thd_lc_time_names :public sys_var_thd
{
public:
- sys_var_thd_lc_time_names(const char *name_arg):
- sys_var_thd(name_arg)
+ sys_var_thd_lc_time_names(sys_var_chain *chain, const char *name_arg):
+ sys_var_thd(name_arg)
{
#if MYSQL_VERSION_ID < 50000
no_support_one_shot= 0;
#endif
+ chain_sys_var(chain);
}
bool check(THD *thd, set_var *var);
SHOW_TYPE show_type() { return SHOW_CHAR; }
@@ -974,8 +984,9 @@ extern void fix_binlog_format_after_update(THD *thd, enum_var_type type);
class sys_var_thd_binlog_format :public sys_var_thd_enum
{
public:
- sys_var_thd_binlog_format(const char *name_arg, ulong SV::*offset_arg)
- :sys_var_thd_enum(name_arg, offset_arg,
+ sys_var_thd_binlog_format(sys_var_chain *chain, const char *name_arg,
+ ulong SV::*offset_arg)
+ :sys_var_thd_enum(chain, name_arg, offset_arg,
&binlog_format_typelib
, fix_binlog_format_after_update
)
@@ -1013,7 +1024,7 @@ public:
CHARSET_INFO *charset;
ulong ulong_value;
ulonglong ulonglong_value;
- handlerton *hton;
+ plugin_ref plugin;
DATE_TIME_FORMAT *date_time_format;
Time_zone *time_zone;
MY_LOCALE *locale_value;
@@ -1142,9 +1153,13 @@ struct sys_var_with_base
Prototypes for helper functions
*/
-void set_var_init();
+int set_var_init();
void set_var_free();
-sys_var *find_sys_var(const char *str, uint length=0);
+int mysql_append_static_vars(const SHOW_VAR *show_vars, uint count);
+SHOW_VAR* enumerate_sys_vars(THD *thd, bool sorted);
+int mysql_add_sys_var_chain(sys_var *chain, struct my_option *long_options);
+int mysql_del_sys_var_chain(sys_var *chain);
+sys_var *find_sys_var(THD *thd, const char *str, uint length=0);
int sql_set_variables(THD *thd, List<set_var_base> *var_list);
bool not_all_support_one_shot(List<set_var_base> *var_list);
void fix_delay_key_write(THD *thd, enum_var_type type);
diff --git a/sql/slave.cc b/sql/slave.cc
index 54504d18f00..7504585696d 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -924,6 +924,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db,
handler *file;
ulonglong save_options;
NET *net= &mysql->net;
+ const char *found_semicolon= NULL;
DBUG_ENTER("create_table_from_dump");
packet_len= my_net_read(net); // read create table statement
@@ -975,7 +976,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db,
thd->db = (char*)db;
DBUG_ASSERT(thd->db != 0);
thd->db_length= strlen(thd->db);
- mysql_parse(thd, thd->query, packet_len); // run create table
+ mysql_parse(thd, thd->query, packet_len, &found_semicolon); // run create table
thd->db = save_db; // leave things the way the were before
thd->db_length= save_db_length;
thd->options = save_options;
diff --git a/sql/sp.cc b/sql/sp.cc
index 244890f200d..40628156d8c 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -384,10 +384,15 @@ db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp,
if ((ret= sp_use_new_db(thd, name->m_db, &old_db, 1, &dbchanged)))
goto end;
- lex_start(thd, defstr.c_ptr(), defstr.length());
+ {
+ Lex_input_stream lip(thd, defstr.c_ptr(), defstr.length());
+ thd->m_lip= &lip;
+ lex_start(thd);
+ ret= MYSQLparse(thd);
+ }
thd->spcont= 0;
- if (MYSQLparse(thd) || thd->is_fatal_error || newlex.sphead == NULL)
+ if (ret || thd->is_fatal_error || newlex.sphead == NULL)
{
sp_head *sp= newlex.sphead;
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 8d4cf464be9..7fa267f1b40 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -556,6 +556,7 @@ sp_head::init_strings(THD *thd, LEX *lex)
const char *endp; /* Used to trim the end */
/* During parsing, we must use thd->mem_root */
MEM_ROOT *root= thd->mem_root;
+ Lex_input_stream *lip=thd->m_lip;
if (m_param_begin && m_param_end)
{
@@ -564,7 +565,7 @@ sp_head::init_strings(THD *thd, LEX *lex)
}
/* If ptr has overrun end_of_query then end_of_query is the end */
- endp= (lex->ptr > lex->end_of_query ? lex->end_of_query : lex->ptr);
+ endp= (lip->ptr > lip->end_of_query ? lip->end_of_query : lip->ptr);
/*
Trim "garbage" at the end. This is sometimes needed with the
"/ * ! VERSION... * /" wrapper in dump files.
@@ -573,8 +574,8 @@ sp_head::init_strings(THD *thd, LEX *lex)
m_body.length= endp - m_body_begin;
m_body.str= strmake_root(root, m_body_begin, m_body.length);
- m_defstr.length= endp - lex->buf;
- m_defstr.str= strmake_root(root, lex->buf, m_defstr.length);
+ m_defstr.length= endp - lip->buf;
+ m_defstr.str= strmake_root(root, lip->buf, m_defstr.length);
DBUG_VOID_RETURN;
}
@@ -1815,25 +1816,13 @@ sp_head::reset_lex(THD *thd)
DBUG_ENTER("sp_head::reset_lex");
LEX *sublex;
LEX *oldlex= thd->lex;
- my_lex_states org_next_state= oldlex->next_state;
(void)m_lex.push_front(oldlex);
thd->lex= sublex= new st_lex;
- /* Reset most stuff. The length arguments doesn't matter here. */
- lex_start(thd, oldlex->buf, (ulong) (oldlex->end_of_query - oldlex->ptr));
+ /* Reset most stuff. */
+ lex_start(thd);
- /*
- next_state is normally the same (0), but it happens that we swap lex in
- "mid-sentence", so we must restore it.
- */
- sublex->next_state= org_next_state;
- /* We must reset ptr and end_of_query again */
- sublex->ptr= oldlex->ptr;
- sublex->end_of_query= oldlex->end_of_query;
- sublex->tok_start= oldlex->tok_start;
- sublex->tok_end= oldlex->tok_end;
- sublex->yylineno= oldlex->yylineno;
/* And keep the SP stuff too */
sublex->sphead= oldlex->sphead;
sublex->spcont= oldlex->spcont;
@@ -1866,10 +1855,6 @@ sp_head::restore_lex(THD *thd)
if (! oldlex)
return; // Nothing to restore
- // Update some state in the old one first
- oldlex->ptr= sublex->ptr;
- oldlex->tok_end= sublex->tok_end;
- oldlex->next_state= sublex->next_state;
oldlex->trg_table_fields.push_back(&sublex->trg_table_fields);
/*
@@ -3062,10 +3047,20 @@ sp_instr_hreturn::print(String *str)
uint
sp_instr_hreturn::opt_mark(sp_head *sp, List<sp_instr> *leads)
{
- if (m_dest)
- return sp_instr_jump::opt_mark(sp, leads);
-
marked= 1;
+
+ if (m_dest)
+ {
+ /*
+ This is an EXIT handler; next instruction step is in m_dest.
+ */
+ return m_dest;
+ }
+
+ /*
+ This is a CONTINUE handler; next instruction step will come from
+ the handler stack and not from opt_mark.
+ */
return UINT_MAX;
}
@@ -3520,6 +3515,14 @@ sp_head::merge_table_list(THD *thd, TABLE_LIST *table, LEX *lex_for_tmp_check)
tname[tlen]= '\0';
/*
+ Upgrade the lock type because this table list will be used
+ only in pre-locked mode, in which DELAYED inserts are always
+ converted to normal inserts.
+ */
+ if (table->lock_type == TL_WRITE_DELAYED)
+ table->lock_type= TL_WRITE;
+
+ /*
We ignore alias when we check if table was already marked as temporary
(and therefore should not be prelocked). Otherwise we will erroneously
treat table with same name but with different alias as non-temporary.
diff --git a/sql/sp_head.h b/sql/sp_head.h
index bea03e5c2a0..63505054a98 100644
--- a/sql/sp_head.h
+++ b/sql/sp_head.h
@@ -176,7 +176,9 @@ public:
*/
HASH m_sroutines;
// Pointers set during parsing
- const char *m_param_begin, *m_param_end, *m_body_begin;
+ const char *m_param_begin;
+ const char *m_param_end;
+ const char *m_body_begin;
/*
Security context for stored routine which should be run under
@@ -990,6 +992,12 @@ public:
virtual void print(String *str);
+ /* This instruction will not be short cut optimized. */
+ virtual uint opt_shortcut_jump(sp_head *sp, sp_instr *start)
+ {
+ return m_ip;
+ }
+
virtual uint opt_mark(sp_head *sp, List<sp_instr> *leads);
private:
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 561d176c342..3cf0432560d 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -97,7 +97,7 @@ static bool open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias,
uint db_stat, uint prgflag,
uint ha_open_flags, TABLE *outparam,
TABLE_LIST *table_desc, MEM_ROOT *mem_root);
-static void close_old_data_files(THD *thd, TABLE *table, bool abort_locks,
+static void close_old_data_files(THD *thd, TABLE *table, bool morph_locks,
bool send_refresh);
static bool reopen_table(TABLE *table);
static bool
@@ -688,6 +688,8 @@ static void close_handle_and_leave_table_as_lock(TABLE *table)
MEM_ROOT *mem_root= &table->mem_root;
DBUG_ENTER("close_handle_and_leave_table_as_lock");
+ DBUG_ASSERT(table->db_stat);
+
/*
Make a local copy of the table share and free the current one.
This has to be done to ensure that the table share is removed from
@@ -934,8 +936,22 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh,
for (uint idx=0 ; idx < open_cache.records ; idx++)
{
TABLE *table=(TABLE*) hash_element(&open_cache,idx);
+ /*
+ Note that we wait here only for tables which are actually open, and
+ not for placeholders with TABLE::open_placeholder set. Waiting for
+ latter will cause deadlock in the following scenario, for example:
+
+ conn1: lock table t1 write;
+ conn2: lock table t2 write;
+ conn1: flush tables;
+ conn2: flush tables;
+
+ It also does not make sense to wait for those of placeholders that
+ are employed by CREATE TABLE as in this case table simply does not
+ exist yet.
+ */
if (!table->s->log_table &&
- ((table->s->version) < refresh_version && table->db_stat))
+ (table->needs_reopen_or_name_lock() && table->db_stat))
{
found=1;
DBUG_PRINT("signal", ("Waiting for COND_refresh"));
@@ -1249,10 +1265,10 @@ bool close_thread_table(THD *thd, TABLE **table_ptr)
TABLE *table= *table_ptr;
DBUG_ENTER("close_thread_table");
DBUG_ASSERT(table->key_read == 0);
- DBUG_ASSERT(table->file->inited == handler::NONE);
+ DBUG_ASSERT(!table->file || table->file->inited == handler::NONE);
*table_ptr=table->next;
- if (table->s->version != refresh_version ||
+ if (table->needs_reopen_or_name_lock() ||
thd->version != refresh_version || !table->db_stat)
{
VOID(hash_delete(&open_cache,(uchar*) table));
@@ -1260,6 +1276,12 @@ bool close_thread_table(THD *thd, TABLE **table_ptr)
}
else
{
+ /*
+ Open placeholders have TABLE::db_stat set to 0, so they should be
+ handled by the first alternative.
+ */
+ DBUG_ASSERT(!table->open_placeholder);
+
/* Free memory and reset for next loop */
table->file->ha_reset();
table->in_use=0;
@@ -1716,7 +1738,7 @@ void close_temporary_table(THD *thd, TABLE *table,
void close_temporary(TABLE *table, bool free_share, bool delete_table)
{
- handlerton *table_type= table->s->db_type;
+ handlerton *table_type= table->s->db_type();
DBUG_ENTER("close_temporary");
free_io_cache(table);
@@ -1778,18 +1800,32 @@ static void relink_unused(TABLE *table)
}
-/*
- Remove all instances of table from the current open list
- Free all locks on tables that are done with LOCK TABLES
- */
+/**
+ @brief Remove all instances of table from thread's open list and
+ table cache.
+
+ @param thd Thread context
+ @param find Table to remove
+ @param unlock TRUE - free all locks on tables removed that are
+ done with LOCK TABLES
+ FALSE - otherwise
+
+ @note When unlock parameter is FALSE or current thread doesn't have
+ any tables locked with LOCK TABLES tables are assumed to be
+ not locked (for example already unlocked).
+*/
-TABLE *unlink_open_table(THD *thd, TABLE *list, TABLE *find)
+void unlink_open_table(THD *thd, TABLE *find, bool unlock)
{
char key[MAX_DBKEY_LENGTH];
uint key_length= find->s->table_cache_key.length;
- TABLE *start=list,**prev,*next;
- prev= &start;
+ TABLE *list, **prev, *next;
+ DBUG_ENTER("unlink_open_table");
+
+ safe_mutex_assert_owner(&LOCK_open);
+ list= thd->open_tables;
+ prev= &thd->open_tables;
memcpy(key, find->s->table_cache_key.str, key_length);
for (; list ; list=next)
{
@@ -1797,7 +1833,7 @@ TABLE *unlink_open_table(THD *thd, TABLE *list, TABLE *find)
if (list->s->table_cache_key.length == key_length &&
!memcmp(list->s->table_cache_key.str, key, key_length))
{
- if (thd->locked_tables)
+ if (unlock && thd->locked_tables)
mysql_lock_remove(thd, thd->locked_tables,list);
VOID(hash_delete(&open_cache,(uchar*) list)); // Close table
}
@@ -1810,7 +1846,41 @@ TABLE *unlink_open_table(THD *thd, TABLE *list, TABLE *find)
*prev=0;
// Notify any 'refresh' threads
broadcast_refresh();
- return start;
+ DBUG_VOID_RETURN;
+}
+
+
+/**
+ @brief Auxiliary routine which closes and drops open table.
+
+ @param thd Thread handle
+ @param table TABLE object for table to be dropped
+ @param db_name Name of database for this table
+ @param table_name Name of this table
+
+ @note This routine assumes that table to be closed is open only
+ by calling thread so we needn't wait until other threads
+ will close the table. It also assumes that table to be
+ dropped is already unlocked.
+*/
+
+void drop_open_table(THD *thd, TABLE *table, const char *db_name,
+ const char *table_name)
+{
+ if (table->s->tmp_table)
+ close_temporary_table(thd, table, 1, 1);
+ else
+ {
+ handlerton *table_type= table->s->db_type();
+ VOID(pthread_mutex_lock(&LOCK_open));
+ /*
+ unlink_open_table() also tells threads waiting for refresh or close
+ that something has happened.
+ */
+ unlink_open_table(thd, table, FALSE);
+ quick_rm_table(table_type, db_name, table_name, 0);
+ VOID(pthread_mutex_unlock(&LOCK_open));
+ }
}
@@ -1867,6 +1937,11 @@ void wait_for_condition(THD *thd, pthread_mutex_t *mutex, pthread_cond_t *cond)
table_list TABLE_LIST object for table to be open, TABLE_LIST::table
member should point to TABLE object which was used for
name-locking.
+ link_in TRUE - if TABLE object for table to be opened should be
+ linked into THD::open_tables list.
+ FALSE - placeholder used for name-locking is already in
+ this list so we only need to preserve TABLE::next
+ pointer.
NOTE
This function assumes that its caller already acquired LOCK_open mutex.
@@ -1876,7 +1951,7 @@ void wait_for_condition(THD *thd, pthread_mutex_t *mutex, pthread_cond_t *cond)
TRUE - Error
*/
-bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list)
+bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list, bool link_in)
{
TABLE *table= table_list->table;
TABLE_SHARE *share;
@@ -1907,11 +1982,32 @@ bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list)
}
share= table->s;
+ /*
+ We want to prevent other connections from opening this table until end
+ of statement as it is likely that modifications of table's metadata are
+ not yet finished (for example CREATE TRIGGER have to change .TRG file,
+ or we might want to drop table if CREATE TABLE ... SELECT fails).
+ This also allows us to assume that no other connection will sneak in
+ before we will get table-level lock on this table.
+ */
share->version=0;
table->in_use = thd;
check_unused();
- table->next = thd->open_tables;
- thd->open_tables = table;
+
+ if (link_in)
+ {
+ table->next= thd->open_tables;
+ thd->open_tables= table;
+ }
+ else
+ {
+ /*
+ TABLE object should be already in THD::open_tables list so we just
+ need to set TABLE::next correctly.
+ */
+ table->next= orig_table.next;
+ }
+
table->tablenr=thd->current_tablenr++;
table->used_fields=0;
table->const_table=0;
@@ -1921,6 +2017,173 @@ bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list)
}
+/**
+ @brief Create and insert into table cache placeholder for table
+ which will prevent its opening (or creation) (a.k.a lock
+ table name).
+
+ @param thd Thread context
+ @param key Table cache key for name to be locked
+ @param key_length Table cache key length
+
+ @return Pointer to TABLE object used for name locking or 0 in
+ case of failure.
+*/
+
+TABLE *table_cache_insert_placeholder(THD *thd, const char *key,
+ uint key_length)
+{
+ TABLE *table;
+ TABLE_SHARE *share;
+ char *key_buff;
+ DBUG_ENTER("table_cache_insert_placeholder");
+
+ safe_mutex_assert_owner(&LOCK_open);
+
+ /*
+ Create a table entry with the right key and with an old refresh version
+ Note that we must use my_multi_malloc() here as this is freed by the
+ table cache
+ */
+ if (!my_multi_malloc(MYF(MY_WME | MY_ZEROFILL),
+ &table, sizeof(*table),
+ &share, sizeof(*share),
+ &key_buff, key_length,
+ NULL))
+ DBUG_RETURN(NULL);
+
+ table->s= share;
+ share->set_table_cache_key(key_buff, key, key_length);
+ share->tmp_table= INTERNAL_TMP_TABLE; // for intern_close_table
+ table->in_use= thd;
+ table->locked_by_name=1;
+
+ if (my_hash_insert(&open_cache, (uchar*)table))
+ {
+ my_free((gptr) table, MYF(0));
+ DBUG_RETURN(NULL);
+ }
+
+ DBUG_RETURN(table);
+}
+
+
+/**
+ @brief Obtain an exclusive name lock on the table if it is not cached
+ in the table cache.
+
+ @param thd Thread context
+ @param db Name of database
+ @param table_name Name of table
+ @param[out] table Out parameter which is either:
+ - set to NULL if table cache contains record for
+ the table or
+ - set to point to the TABLE instance used for
+ name-locking.
+
+ @note This function takes into account all records for table in table
+ cache, even placeholders used for name-locking. This means that
+ 'table' parameter can be set to NULL for some situations when
+ table does not really exist.
+
+ @retval TRUE Error occured (OOM)
+ @retval FALSE Success. 'table' parameter set according to above rules.
+*/
+
+bool lock_table_name_if_not_cached(THD *thd, const char *db,
+ const char *table_name, TABLE **table)
+{
+ char key[MAX_DBKEY_LENGTH];
+ uint key_length;
+ DBUG_ENTER("lock_table_name_if_not_cached");
+
+ key_length= (uint)(strmov(strmov(key, db) + 1, table_name) - key) + 1;
+ VOID(pthread_mutex_lock(&LOCK_open));
+
+ if (hash_search(&open_cache, (uchar *)key, key_length))
+ {
+ VOID(pthread_mutex_unlock(&LOCK_open));
+ DBUG_PRINT("info", ("Table is cached, name-lock is not obtained"));
+ *table= 0;
+ DBUG_RETURN(FALSE);
+ }
+ if (!(*table= table_cache_insert_placeholder(thd, key, key_length)))
+ {
+ VOID(pthread_mutex_unlock(&LOCK_open));
+ DBUG_RETURN(TRUE);
+ }
+ (*table)->open_placeholder= 1;
+ (*table)->next= thd->open_tables;
+ thd->open_tables= *table;
+ VOID(pthread_mutex_unlock(&LOCK_open));
+ DBUG_RETURN(FALSE);
+}
+
+
+/**
+ @brief Check that table exists in table definition cache, on disk
+ or in some storage engine.
+
+ @param thd Thread context
+ @param table Table list element
+ @param exists[out] Out parameter which is set to TRUE if table
+ exists and to FALSE otherwise.
+
+ @note This function assumes that caller owns LOCK_open mutex.
+ It also assumes that the fact that there are no name-locks
+ on the table was checked beforehand.
+
+ @note If there is no .FRM file for the table but it exists in one
+ of engines (e.g. it was created on another node of NDB cluster)
+ this function will fetch and create proper .FRM file for it.
+
+ @retval TRUE Some error occured
+ @retval FALSE No error. 'exists' out parameter set accordingly.
+*/
+
+bool check_if_table_exists(THD *thd, TABLE_LIST *table, bool *exists)
+{
+ char path[FN_REFLEN];
+ int rc;
+ DBUG_ENTER("check_if_table_exists");
+
+ safe_mutex_assert_owner(&LOCK_open);
+
+ *exists= TRUE;
+
+ if (get_cached_table_share(table->db, table->table_name))
+ DBUG_RETURN(FALSE);
+
+ build_table_filename(path, sizeof(path) - 1, table->db, table->table_name,
+ reg_ext, 0);
+
+ if (!access(path, F_OK))
+ DBUG_RETURN(FALSE);
+
+ /* .FRM file doesn't exist. Check if some engine can provide it. */
+
+ rc= ha_create_table_from_engine(thd, table->db, table->table_name);
+
+ if (rc < 0)
+ {
+ /* Table does not exists in engines as well. */
+ *exists= FALSE;
+ DBUG_RETURN(FALSE);
+ }
+ else if (!rc)
+ {
+ /* Table exists in some engine and .FRM for it was created. */
+ DBUG_RETURN(FALSE);
+ }
+ else /* (rc > 0) */
+ {
+ my_printf_error(ER_UNKNOWN_ERROR, "Failed to open '%-.64s', error while "
+ "unpacking from engine", MYF(0), table->table_name);
+ DBUG_RETURN(TRUE);
+ }
+}
+
+
/*
Open a table.
@@ -1936,12 +2199,17 @@ bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list)
MYSQL_LOCK_IGNORE_FLUSH - Open table even if
someone has done a flush or namelock on it.
No version number checking is done.
- MYSQL_OPEN_IGNORE_LOCKED_TABLES - Open table
- ignoring set of locked tables and prelocked mode.
+ MYSQL_OPEN_TEMPORARY_ONLY - Open only temporary
+ table not the base table or view.
IMPLEMENTATION
Uses a cache of open tables to find a table not in use.
+ If table list element for the table to be opened has "create" flag
+ set and table does not exist, this function will automatically insert
+ a placeholder for exclusive name lock into the open tables cache and
+ will return the TABLE instance that corresponds to this placeholder.
+
RETURN
NULL Open failed. If refresh is set then one should close
all other tables and retry the open.
@@ -2014,6 +2282,12 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
}
}
+ if (flags & MYSQL_OPEN_TEMPORARY_ONLY)
+ {
+ my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db, table_list->table_name);
+ DBUG_RETURN(0);
+ }
+
/*
The table is not temporary - if we're in pre-locked or LOCK TABLES
mode, let's try to find the requested table in the list of pre-opened
@@ -2021,8 +2295,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
open not pre-opened tables in pre-locked/LOCK TABLES mode.
TODO: move this block into a separate function.
*/
- if (!(flags & MYSQL_OPEN_IGNORE_LOCKED_TABLES) &&
- (thd->locked_tables || thd->prelocked_mode))
+ if (thd->locked_tables || thd->prelocked_mode)
{ // Using table locks
TABLE *best_table= 0;
int best_distance= INT_MIN;
@@ -2204,7 +2477,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
c1: name lock t2; -- blocks
c2: open t1; -- blocks
*/
- if (table->s->version != refresh_version && !table->s->log_table)
+ if (table->needs_reopen_or_name_lock() && !table->s->log_table)
{
DBUG_PRINT("note",
("Found table '%s.%s' with different refresh version",
@@ -2217,6 +2490,14 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
continue;
}
+ /* Avoid self-deadlocks by detecting self-dependencies. */
+ if (table->open_placeholder && table->in_use == thd)
+ {
+ VOID(pthread_mutex_unlock(&LOCK_open));
+ my_error(ER_UPDATE_TABLE_USED, MYF(0), table->s->table_name.str);
+ DBUG_RETURN(0);
+ }
+
/*
Back off, part 1: mark the table as "unused" for the
purpose of name-locking by setting table->db_stat to 0. Do
@@ -2233,6 +2514,14 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
and wait till the operation is complete: when any
operation that juggles with table->s->version completes,
it broadcasts COND_refresh condition variable.
+ If 'old' table we met is in use by current thread we return
+ without waiting since in this situation it's this thread
+ which is responsible for broadcasting on COND_refresh
+ (and this was done already in close_old_data_files()).
+ Good example of such situation is when we have statement
+ that needs two instances of table and FLUSH TABLES comes
+ after we open first instance but before we open second
+ instance.
*/
if (table->in_use != thd)
{
@@ -2273,6 +2562,40 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
while (open_cache.records > table_cache_size && unused_tables)
VOID(hash_delete(&open_cache,(uchar*) unused_tables)); /* purecov: tested */
+ if (table_list->create)
+ {
+ bool exists;
+
+ if (check_if_table_exists(thd, table_list, &exists))
+ {
+ VOID(pthread_mutex_unlock(&LOCK_open));
+ DBUG_RETURN(NULL);
+ }
+
+ if (!exists)
+ {
+ /*
+ Table to be created, so we need to create placeholder in table-cache.
+ */
+ if (!(table= table_cache_insert_placeholder(thd, key, key_length)))
+ {
+ VOID(pthread_mutex_unlock(&LOCK_open));
+ DBUG_RETURN(NULL);
+ }
+ /*
+ Link placeholder to the open tables list so it will be automatically
+ removed once tables are closed. Also mark it so it won't be ignored
+ by other trying to take name-lock.
+ */
+ table->open_placeholder= 1;
+ table->next= thd->open_tables;
+ thd->open_tables= table;
+ VOID(pthread_mutex_unlock(&LOCK_open));
+ DBUG_RETURN(table);
+ }
+ /* Table exists. Let us try to open it. */
+ }
+
/* make a new table */
if (!(table=(TABLE*) my_malloc(sizeof(*table),MYF(MY_WME))))
{
@@ -2489,9 +2812,24 @@ bool close_data_tables(THD *thd,const char *db, const char *table_name)
}
-/*
- Reopen all tables with closed data files
- One should have lock on LOCK_open when calling this
+/**
+ @brief Reopen all tables with closed data files.
+
+ @param thd Thread context
+ @param get_locks Should we get locks after reopening tables ?
+ @param in_refresh Are we in FLUSH TABLES ? TODO: It seems that
+ we can remove this parameter.
+
+ @note Since this function can't properly handle prelocking and
+ create placeholders it should be used in very special
+ situations like FLUSH TABLES or ALTER TABLE. In general
+ case one should just repeat open_tables()/lock_tables()
+ combination when one needs tables to be reopened (for
+ example see open_and_lock_tables()).
+
+ @note One should have lock on LOCK_open when calling this.
+
+ @return FALSE in case of success, TRUE - otherwise.
*/
bool reopen_tables(THD *thd,bool get_locks,bool in_refresh)
@@ -2537,7 +2875,7 @@ bool reopen_tables(THD *thd,bool get_locks,bool in_refresh)
if (in_refresh)
{
table->s->version=0;
- table->locked_by_flush=0;
+ table->open_placeholder= 0;
}
}
}
@@ -2564,13 +2902,21 @@ bool reopen_tables(THD *thd,bool get_locks,bool in_refresh)
}
-/*
- Close handlers for tables in list, but leave the TABLE structure
- intact so that we can re-open these quickly
- abort_locks is set if called from flush_tables.
+/**
+ @brief Close handlers for tables in list, but leave the TABLE structure
+ intact so that we can re-open these quickly.
+
+ @param thd Thread context
+ @param table Head of the list of TABLE objects
+ @param morph_locks TRUE - remove locks which we have on tables being closed
+ but ensure that no DML or DDL will sneak in before
+ we will re-open the table (i.e. temporarily morph
+ our table-level locks into name-locks).
+ FALSE - otherwise
+ @param send_refresh Should we awake waiters even if we didn't close any tables?
*/
-void close_old_data_files(THD *thd, TABLE *table, bool abort_locks,
+void close_old_data_files(THD *thd, TABLE *table, bool morph_locks,
bool send_refresh)
{
bool found= send_refresh;
@@ -2582,19 +2928,41 @@ void close_old_data_files(THD *thd, TABLE *table, bool abort_locks,
Reopen marked for flush. But close log tables. They are flushed only
explicitly on FLUSH LOGS
*/
- if (table->s->version != refresh_version && !table->s->log_table)
+ if (table->needs_reopen_or_name_lock() && !table->s->log_table)
{
found=1;
if (table->db_stat)
{
- if (abort_locks)
+ if (morph_locks)
{
- mysql_lock_abort(thd,table, TRUE); // Close waiting threads
- mysql_lock_remove(thd, thd->locked_tables,table);
- table->locked_by_flush=1; // Will be reopened with locks
+ /*
+ Wake up threads waiting for table-level lock on this table
+ so they won't sneak in when we will temporarily remove our
+ lock on it. This will also give them a chance to close their
+ instances of this table.
+ */
+ mysql_lock_abort(thd, table, TRUE);
+ mysql_lock_remove(thd, thd->locked_tables, table);
+ /*
+ We want to protect the table from concurrent DDL operations
+ (like RENAME TABLE) until we will re-open and re-lock it.
+ */
+ table->open_placeholder= 1;
}
close_handle_and_leave_table_as_lock(table);
}
+ else if (table->open_placeholder)
+ {
+ /*
+ We come here only in close-for-back-off scenario. So we have to
+ "close" create placeholder here to avoid deadlocks (for example,
+ in case of concurrent execution of CREATE TABLE t1 SELECT * FROM t2
+ and RENAME TABLE t2 TO t1). In close-for-re-open scenario we will
+ probably want to let it stay.
+ */
+ DBUG_ASSERT(!morph_locks);
+ table->open_placeholder= 0;
+ }
}
}
if (found)
@@ -2630,10 +2998,10 @@ bool table_is_used(TABLE *table, bool wait_for_name_lock)
key_length, &state))
{
DBUG_PRINT("info", ("share: 0x%lx locked_by_logger: %d "
- "locked_by_flush: %d locked_by_name: %d "
+ "open_placeholder: %d locked_by_name: %d "
"db_stat: %u version: %lu",
(ulong) search->s, search->locked_by_logger,
- search->locked_by_flush, search->locked_by_name,
+ search->open_placeholder, search->locked_by_name,
search->db_stat,
search->s->version));
if (search->in_use == table->in_use)
@@ -2649,8 +3017,7 @@ bool table_is_used(TABLE *table, bool wait_for_name_lock)
*/
if (!search->locked_by_logger &&
(search->locked_by_name && wait_for_name_lock ||
- search->locked_by_flush ||
- (search->db_stat && search->s->version < refresh_version)))
+ (search->is_name_opened() && search->needs_reopen_or_name_lock())))
DBUG_RETURN(1);
}
} while ((table=table->next));
@@ -3098,7 +3465,7 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags)
*/
if (!thd->prelocked_mode && !thd->lex->requires_prelocking() &&
- thd->lex->sroutines_list.elements)
+ thd->lex->uses_stored_routines())
{
bool first_no_prelocking, need_prelocking;
TABLE_LIST **save_query_tables_last= thd->lex->query_tables_last;
@@ -3284,7 +3651,7 @@ process_view_routines:
*/
if (tables->view && !thd->prelocked_mode &&
!thd->lex->requires_prelocking() &&
- tables->view->sroutines_list.elements)
+ tables->view->uses_stored_routines())
{
/* We have at least one table in TL here. */
if (!query_tables_last_own)
@@ -6513,7 +6880,7 @@ my_bool mysql_rm_tmp_tables(void)
init_tmp_table_share(&share, "", 0, "", filePathCopy);
if (!open_table_def(thd, &share, 0) &&
((handler_file= get_new_handler(&share, thd->mem_root,
- share.db_type))))
+ share.db_type()))))
{
handler_file->delete_table(filePathCopy);
delete handler_file;
@@ -6638,7 +7005,7 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name,
{
DBUG_PRINT("info", ("Table was in use by other thread"));
in_use->some_tables_deleted=1;
- if (table->db_stat)
+ if (table->is_name_opened())
{
DBUG_PRINT("info", ("Found another active instance of the table"));
result=1;
@@ -7013,7 +7380,7 @@ has_two_write_locked_tables_with_auto_increment(TABLE_LIST *tables)
for (TABLE_LIST *table= tables; table; table= table->next_global)
{
/* we must do preliminary checks as table->table may be NULL */
- if (!table->placeholder() && !table->schema_table &&
+ if (!table->placeholder() &&
table->table->found_next_number_field &&
(table->lock_type >= TL_WRITE_ALLOW_WRITE))
{
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index ae8f82204cb..8b14ad4f348 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -867,10 +867,13 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used)
flags.max_sort_length= thd->variables.max_sort_length;
flags.lc_time_names= thd->variables.lc_time_names;
flags.group_concat_max_len= thd->variables.group_concat_max_len;
+ flags.div_precision_increment= thd->variables.div_precincrement;
+ flags.default_week_format= thd->variables.default_week_format;
DBUG_PRINT("qcache", ("\
long %d, 4.1: %d, bin_proto: %d, more results %d, pkt_nr: %d, \
CS client: %u, CS result: %u, CS conn: %u, limit: %lu, TZ: 0x%lx, \
-sql mode: 0x%lx, sort len: %lu, conncat len: %lu",
+sql mode: 0x%lx, sort len: %lu, conncat len: %lu, div_precision: %lu, \
+def_week_frmt: %lu",
(int)flags.client_long_flag,
(int)flags.client_protocol_41,
(int)flags.result_in_binary_protocol,
@@ -883,7 +886,9 @@ sql mode: 0x%lx, sort len: %lu, conncat len: %lu",
(ulong) flags.time_zone,
flags.sql_mode,
flags.max_sort_length,
- flags.group_concat_max_len));
+ flags.group_concat_max_len,
+ flags.div_precision_increment,
+ flags.default_week_format));
/*
Make InnoDB to release the adaptive hash index latch before
acquiring the query cache mutex.
@@ -1112,11 +1117,14 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
flags.sql_mode= thd->variables.sql_mode;
flags.max_sort_length= thd->variables.max_sort_length;
flags.group_concat_max_len= thd->variables.group_concat_max_len;
+ flags.div_precision_increment= thd->variables.div_precincrement;
+ flags.default_week_format= thd->variables.default_week_format;
flags.lc_time_names= thd->variables.lc_time_names;
DBUG_PRINT("qcache", ("\
long %d, 4.1: %d, bin_proto: %d, more results %d, pkt_nr: %d, \
CS client: %u, CS result: %u, CS conn: %u, limit: %lu, TZ: 0x%lx, \
-sql mode: 0x%lx, sort len: %lu, conncat len: %lu",
+sql mode: 0x%lx, sort len: %lu, conncat len: %lu, div_precision: %lu, \
+def_week_frmt: %lu",
(int)flags.client_long_flag,
(int)flags.client_protocol_41,
(int)flags.result_in_binary_protocol,
@@ -1129,7 +1137,9 @@ sql mode: 0x%lx, sort len: %lu, conncat len: %lu",
(ulong) flags.time_zone,
flags.sql_mode,
flags.max_sort_length,
- flags.group_concat_max_len));
+ flags.group_concat_max_len,
+ flags.div_precision_increment,
+ flags.default_week_format));
memcpy((uchar *)(sql + (tot_length - QUERY_CACHE_FLAGS_SIZE)),
(uchar*) &flags, QUERY_CACHE_FLAGS_SIZE);
query_block = (Query_cache_block *) hash_search(&queries, (uchar*) sql,
@@ -2409,7 +2419,12 @@ Query_cache::register_tables_from_list(TABLE_LIST *tables_used,
tables_used->engine_data))
DBUG_RETURN(0);
- if (tables_used->table->s->db_type->db_type == DB_TYPE_MRG_MYISAM)
+#ifdef WITH_MYISAMMRG_STORAGE_ENGINE
+ /*
+ XXX FIXME: Some generic mechanism is required here instead of this
+ MYISAMMRG-specific implementation.
+ */
+ if (tables_used->table->s->db_type()->db_type == DB_TYPE_MRG_MYISAM)
{
ha_myisammrg *handler = (ha_myisammrg *) tables_used->table->file;
MYRG_INFO *file = handler->myrg_info();
@@ -2432,6 +2447,7 @@ Query_cache::register_tables_from_list(TABLE_LIST *tables_used,
DBUG_RETURN(0);
}
}
+#endif
}
}
DBUG_RETURN(n - counter);
@@ -3008,7 +3024,7 @@ static TABLE_COUNTER_TYPE process_and_count_tables(TABLE_LIST *tables_used,
DBUG_PRINT("qcache", ("table: %s db: %s type: %u",
tables_used->table->s->table_name.str,
tables_used->table->s->db.str,
- tables_used->table->s->db_type->db_type));
+ tables_used->table->s->db_type()->db_type));
if (tables_used->derived)
{
table_count--;
@@ -3033,12 +3049,18 @@ static TABLE_COUNTER_TYPE process_and_count_tables(TABLE_LIST *tables_used,
"other non-cacheable table(s)"));
DBUG_RETURN(0);
}
- if (tables_used->table->s->db_type->db_type == DB_TYPE_MRG_MYISAM)
+#ifdef WITH_MYISAMMRG_STORAGE_ENGINE
+ /*
+ XXX FIXME: Some generic mechanism is required here instead of this
+ MYISAMMRG-specific implementation.
+ */
+ if (tables_used->table->s->db_type()->db_type == DB_TYPE_MRG_MYISAM)
{
ha_myisammrg *handler = (ha_myisammrg *)tables_used->table->file;
MYRG_INFO *file = handler->myrg_info();
table_count+= (file->end_table - file->open_tables);
}
+#endif
}
}
DBUG_RETURN(table_count);
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 48a165dc34c..ffa058164dd 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -169,18 +169,25 @@ Open_tables_state::Open_tables_state(ulong version_arg)
reset_open_tables_state();
}
-my_bool thd_in_lock_tables(const THD *thd)
+/*
+ The following functions form part of the C plugin API
+*/
+
+extern "C"
+int thd_in_lock_tables(const THD *thd)
{
- return thd->in_lock_tables;
+ return test(thd->in_lock_tables);
}
-my_bool thd_tablespace_op(const THD *thd)
+extern "C"
+int thd_tablespace_op(const THD *thd)
{
- return thd->tablespace_op;
+ return test(thd->tablespace_op);
}
+extern "C"
const char *thd_proc_info(THD *thd, const char *info)
{
const char *old_info= thd->proc_info;
@@ -188,11 +195,98 @@ const char *thd_proc_info(THD *thd, const char *info)
return old_info;
}
+extern "C"
void **thd_ha_data(const THD *thd, const struct handlerton *hton)
{
return (void **) thd->ha_data + hton->slot;
}
+extern "C"
+long long thd_test_options(const THD *thd, long long test_options)
+{
+ return thd->options & test_options;
+}
+
+extern "C"
+int thd_sql_command(const THD *thd)
+{
+ return (int) thd->lex->sql_command;
+}
+
+extern "C"
+int thd_tx_isolation(const THD *thd)
+{
+ return (int) thd->variables.tx_isolation;
+}
+
+
+/*
+ Dumps a text description of a thread, its security context
+ (user, host) and the current query.
+
+ SYNOPSIS
+ thd_security_context()
+ thd current thread context
+ buffer pointer to preferred result buffer
+ length length of buffer
+ max_query_len how many chars of query to copy (0 for all)
+
+ RETURN VALUES
+ pointer to string
+*/
+extern "C"
+char *thd_security_context(THD *thd, char *buffer, unsigned int length,
+ unsigned int max_query_len)
+{
+ String str(buffer, length, &my_charset_latin1);
+ const Security_context *sctx= &thd->main_security_ctx;
+ char header[64];
+ int len;
+
+ len= my_snprintf(header, sizeof(header),
+ "MySQL thread id %lu, query id %lu",
+ thd->thread_id, (ulong) thd->query_id);
+ str.length(0);
+ str.append(header, len);
+
+ if (sctx->host)
+ {
+ str.append(' ');
+ str.append(sctx->host);
+ }
+
+ if (sctx->ip)
+ {
+ str.append(' ');
+ str.append(sctx->ip);
+ }
+
+ if (sctx->user)
+ {
+ str.append(' ');
+ str.append(sctx->user);
+ }
+
+ if (thd->proc_info)
+ {
+ str.append(' ');
+ str.append(thd->proc_info);
+ }
+
+ if (thd->query)
+ {
+ if (max_query_len < 1)
+ len= thd->query_length;
+ else
+ len= min(thd->query_length, max_query_len);
+ str.append('\n');
+ str.append(thd->query, len);
+ }
+ if (str.c_ptr_safe() == buffer)
+ return buffer;
+ return thd->strmake(str.ptr(), str.length());
+}
+
THD::THD()
@@ -202,14 +296,18 @@ THD::THD()
lock_id(&main_lock_id),
user_time(0), in_sub_stmt(0),
binlog_table_maps(0),
- global_read_lock(0), is_fatal_error(0),
- rand_used(0), time_zone_used(0),
arg_of_last_insert_id_function(FALSE),
first_successful_insert_id_in_prev_stmt(0),
first_successful_insert_id_in_prev_stmt_for_binlog(0),
first_successful_insert_id_in_cur_stmt(0),
- in_lock_tables(0), bootstrap(0), derived_tables_processing(FALSE),
stmt_depends_on_first_successful_insert_id_in_prev_stmt(FALSE),
+ global_read_lock(0),
+ is_fatal_error(0),
+ rand_used(0),
+ time_zone_used(0),
+ in_lock_tables(0),
+ bootstrap(0),
+ derived_tables_processing(FALSE),
spcont(NULL)
{
ulong tmp;
@@ -247,6 +345,7 @@ THD::THD()
time_after_lock=(time_t) 0;
current_linfo = 0;
slave_thread = 0;
+ bzero(&variables, sizeof(variables));
thread_id= variables.pseudo_thread_id= 0;
one_shot_set= 0;
file_id = 0;
@@ -357,7 +456,7 @@ void THD::pop_internal_handler()
void THD::init(void)
{
pthread_mutex_lock(&LOCK_global_system_variables);
- variables= global_system_variables;
+ plugin_thdvar_init(this);
variables.time_format= date_time_format_copy((THD*) 0,
variables.time_format);
variables.date_format= date_time_format_copy((THD*) 0,
@@ -506,6 +605,7 @@ THD::~THD()
cleanup();
ha_close_connection(this);
+ plugin_thdvar_cleanup(this);
DBUG_PRINT("info", ("freeing security context"));
main_security_ctx.destroy();
@@ -1735,7 +1835,7 @@ void Query_arena::cleanup_stmt()
}
/*
- Statement functions
+ Statement functions
*/
Statement::Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg,
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 95d07c57e46..a20292076bc 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -31,6 +31,7 @@ class Load_log_event;
class Slave_log_event;
class sp_rcontext;
class sp_cache;
+class Lex_input_stream;
class Rows_log_event;
enum enum_enable_or_disable { LEAVE_AS_IS, ENABLE, DISABLE };
@@ -171,7 +172,7 @@ public:
#include "sql_lex.h" /* Must be here */
-class delayed_insert;
+class Delayed_insert;
class select_result;
class Time_zone;
@@ -182,6 +183,20 @@ class Time_zone;
struct system_variables
{
+ /*
+ How dynamically allocated system variables are handled:
+
+ The global_system_variables and max_system_variables are "authoritative"
+ They both should have the same 'version' and 'size'.
+ When attempting to access a dynamic variable, if the session version
+ is out of date, then the session version is updated and realloced if
+ neccessary and bytes copied from global to make up for missing data.
+ */
+ ulong dynamic_variables_version;
+ char* dynamic_variables_ptr;
+ uint dynamic_variables_head; /* largest valid variable offset */
+ uint dynamic_variables_size; /* how many bytes are in use */
+
ulonglong myisam_max_extra_sort_file_size;
ulonglong myisam_max_sort_file_size;
ulonglong max_heap_table_size;
@@ -252,8 +267,6 @@ struct system_variables
my_bool old_mode;
my_bool query_cache_wlock_invalidate;
my_bool engine_condition_pushdown;
- my_bool innodb_table_locks;
- my_bool innodb_support_xa;
my_bool ndb_force_send;
my_bool ndb_use_copying_alter_table;
my_bool ndb_use_exact_count;
@@ -263,7 +276,7 @@ struct system_variables
my_bool old_alter_table;
my_bool old_passwords;
- handlerton *table_type;
+ plugin_ref table_plugin;
/* Only charset part of these variables is sensible */
CHARSET_INFO *character_set_filesystem;
@@ -1002,7 +1015,7 @@ public:
time_t start_time,time_after_lock,user_time;
time_t connect_time,thr_create_time; // track down slow pthread_create
thr_lock_type update_lock_default;
- delayed_insert *di;
+ Delayed_insert *di;
/* <> 0 if we are inside of trigger or stored function. */
uint in_sub_stmt;
@@ -1412,6 +1425,16 @@ public:
*/
query_id_t first_query_id;
} binlog_evt_union;
+
+ /**
+ Character input stream consumed by the lexical analyser,
+ used during parsing.
+ Note that since the parser is not re-entrant, we keep only one input
+ stream here. This member is valid only when executing code during parsing,
+ and may point to invalid memory after that.
+ */
+ Lex_input_stream *m_lip;
+
#ifdef WITH_PARTITION_STORAGE_ENGINE
partition_info *work_part_info;
#endif
diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc
index f01d9576c56..d23c9bb3454 100644
--- a/sql/sql_connect.cc
+++ b/sql/sql_connect.cc
@@ -967,6 +967,7 @@ bool login_connection(THD *thd)
void end_connection(THD *thd)
{
NET *net= &thd->net;
+ plugin_thdvar_cleanup(thd);
if (thd->user_connect)
decrease_user_connections(thd->user_connect);
if (net->error && net->vio != 0 && net->report_error)
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index c441c70d36f..fe54a12e4dc 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -903,7 +903,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
/* If it is a temporary table, close and regenerate it */
if (!dont_send_ok && (table= find_temporary_table(thd, table_list)))
{
- handlerton *table_type= table->s->db_type;
+ handlerton *table_type= table->s->db_type();
TABLE_SHARE *share= table->s;
if (!ha_check_storage_engine_flag(table_type, HTON_CAN_RECREATE))
goto trunc_by_del;
diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc
index db6fc03cbad..300ec7f3c62 100644
--- a/sql/sql_handler.cc
+++ b/sql/sql_handler.cc
@@ -682,7 +682,7 @@ int mysql_ha_flush(THD *thd, TABLE_LIST *tables, uint mode_flags,
while (*table_ptr)
{
if ((mode_flags & MYSQL_HA_FLUSH_ALL) ||
- ((*table_ptr)->s->version != refresh_version))
+ (*table_ptr)->needs_reopen_or_name_lock())
{
/* The first time it is required, lock for close_thread_table(). */
if (! did_lock && ! is_locked)
@@ -783,15 +783,22 @@ void mysql_ha_mark_tables_for_reopen(THD *thd, TABLE *table)
safe_mutex_assert_owner(&LOCK_open);
for (; table; table= table->next)
{
- TABLE_LIST *hash_tables;
- if ((hash_tables= (TABLE_LIST*) hash_search(&thd->handler_tables_hash,
- (uchar*) table->alias,
- strlen(table->alias) + 1)))
+ /*
+ Some elements in open table list, for example placeholders used for
+ name-locking, can have alias set to 0.
+ */
+ if (table->alias)
{
- /* Mark table as ready for reopen. */
- hash_tables->table= NULL;
- /* End open index/table scans. */
- table->file->ha_index_or_rnd_end();
+ TABLE_LIST *hash_tables;
+ if ((hash_tables= (TABLE_LIST*) hash_search(&thd->handler_tables_hash,
+ (uchar*) table->alias,
+ strlen(table->alias) + 1)))
+ {
+ /* Mark table as ready for reopen. */
+ hash_tables->table= NULL;
+ /* End open index/table scans. */
+ table->file->ha_index_or_rnd_end();
+ }
}
}
DBUG_VOID_RETURN;
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 4a7a7e67134..c75bd2c215d 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -29,7 +29,7 @@
waited for to open and lock the table.
If accessing the thread succeeded, in
- delayed_insert::get_local_table() the table of the thread is copied
+ Delayed_insert::get_local_table() the table of the thread is copied
for local use. A copy is required because the normal insert logic
works on a target table, but the other threads table object must not
be used. The insert logic uses the record buffer to create a record.
@@ -63,8 +63,8 @@
#include "rpl_mi.h"
#ifndef EMBEDDED_LIBRARY
-static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list);
-static int write_delayed(THD *thd, TABLE *table, enum_duplicates dup,
+static bool delayed_get_table(THD *thd, TABLE_LIST *table_list);
+static int write_delayed(THD *thd, TABLE *table, enum_duplicates duplic,
LEX_STRING query, bool ignore, bool log_on);
static void end_delayed_insert(THD *thd);
pthread_handler_t handle_delayed_insert(void *arg);
@@ -384,6 +384,163 @@ void prepare_triggers_for_insert_stmt(TABLE *table)
}
+/**
+ Upgrade table-level lock of INSERT statement to TL_WRITE if
+ a more concurrent lock is infeasible for some reason. This is
+ necessary for engines without internal locking support (MyISAM).
+ An engine with internal locking implementation might later
+ downgrade the lock in handler::store_lock() method.
+*/
+
+static
+void upgrade_lock_type(THD *thd, thr_lock_type *lock_type,
+ enum_duplicates duplic,
+ bool is_multi_insert)
+{
+ if (duplic == DUP_UPDATE ||
+ duplic == DUP_REPLACE && *lock_type == TL_WRITE_CONCURRENT_INSERT)
+ {
+ *lock_type= TL_WRITE;
+ return;
+ }
+
+ if (*lock_type == TL_WRITE_DELAYED)
+ {
+ /*
+ We do not use delayed threads if:
+ - we're running in the safe mode or skip-new mode -- the
+ feature is disabled in these modes
+ - we're executing this statement on a replication slave --
+ we need to ensure serial execution of queries on the
+ slave
+ - it is INSERT .. ON DUPLICATE KEY UPDATE - in this case the
+ insert cannot be concurrent
+ - this statement is directly or indirectly invoked from
+ a stored function or trigger (under pre-locking) - to
+ avoid deadlocks, since INSERT DELAYED involves a lock
+ upgrade (TL_WRITE_DELAYED -> TL_WRITE) which we should not
+ attempt while keeping other table level locks.
+ - this statement itself may require pre-locking.
+ We should upgrade the lock even though in most cases
+ delayed functionality may work. Unfortunately, we can't
+ easily identify whether the subject table is not used in
+ the statement indirectly via a stored function or trigger:
+ if it is used, that will lead to a deadlock between the
+ client connection and the delayed thread.
+ */
+ if (specialflag & (SPECIAL_NO_NEW_FUNC | SPECIAL_SAFE_MODE) ||
+ thd->slave_thread ||
+ thd->variables.max_insert_delayed_threads == 0 ||
+ thd->prelocked_mode ||
+ thd->lex->uses_stored_routines())
+ {
+ *lock_type= TL_WRITE;
+ return;
+ }
+ bool log_on= (thd->options & OPTION_BIN_LOG ||
+ ! (thd->security_ctx->master_access & SUPER_ACL));
+ if (global_system_variables.binlog_format == BINLOG_FORMAT_STMT &&
+ log_on && mysql_bin_log.is_open() && is_multi_insert)
+ {
+ /*
+ Statement-based binary logging does not work in this case, because:
+ a) two concurrent statements may have their rows intermixed in the
+ queue, leading to autoincrement replication problems on slave (because
+ the values generated used for one statement don't depend only on the
+ value generated for the first row of this statement, so are not
+ replicable)
+ b) if first row of the statement has an error the full statement is
+ not binlogged, while next rows of the statement may be inserted.
+ c) if first row succeeds, statement is binlogged immediately with a
+ zero error code (i.e. "no error"), if then second row fails, query
+ will fail on slave too and slave will stop (wrongly believing that the
+ master got no error).
+ So we fallback to non-delayed INSERT.
+ Note that to be fully correct, we should test the "binlog format which
+ the delayed thread is going to use for this row". But in the common case
+ where the global binlog format is not changed and the session binlog
+ format may be changed, that is equal to the global binlog format.
+ We test it without mutex for speed reasons (condition rarely true), and
+ in the common case (global not changed) it is as good as without mutex;
+ if global value is changed, anyway there is uncertainty as the delayed
+ thread may be old and use the before-the-change value.
+ */
+ *lock_type= TL_WRITE;
+ }
+ }
+}
+
+
+/**
+ Find or create a delayed insert thread for the first table in
+ the table list, then open and lock the remaining tables.
+ If a table can not be used with insert delayed, upgrade the lock
+ and open and lock all tables using the standard mechanism.
+
+ @param thd thread context
+ @param table_list list of "descriptors" for tables referenced
+ directly in statement SQL text.
+ The first element in the list corresponds to
+ the destination table for inserts, remaining
+ tables, if any, are usually tables referenced
+ by sub-queries in the right part of the
+ INSERT.
+
+ @return Status of the operation. In case of success 'table'
+ member of every table_list element points to an instance of
+ class TABLE.
+
+ @sa open_and_lock_tables for more information about MySQL table
+ level locking
+*/
+
+static
+bool open_and_lock_for_insert_delayed(THD *thd, TABLE_LIST *table_list)
+{
+ DBUG_ENTER("open_and_lock_for_insert_delayed");
+
+#ifndef EMBEDDED_LIBRARY
+ if (delayed_get_table(thd, table_list))
+ DBUG_RETURN(TRUE);
+
+ if (table_list->table)
+ {
+ /*
+ Open tables used for sub-selects or in stored functions, will also
+ cache these functions.
+ */
+ if (open_and_lock_tables(thd, table_list->next_global))
+ {
+ end_delayed_insert(thd);
+ DBUG_RETURN(TRUE);
+ }
+ /*
+ First table was not processed by open_and_lock_tables(),
+ we need to set updatability flag "by hand".
+ */
+ if (!table_list->derived && !table_list->view)
+ table_list->updatable= 1; // usual table
+ DBUG_RETURN(FALSE);
+ }
+#endif
+ /*
+ * This is embedded library and we don't have auxiliary
+ threads OR
+ * a lock upgrade was requested inside delayed_get_table
+ because
+ - there are too many delayed insert threads OR
+ - the table has triggers.
+ Use a normal insert.
+ */
+ table_list->lock_type= TL_WRITE;
+ DBUG_RETURN(open_and_lock_tables(thd, table_list));
+}
+
+
+/**
+ INSERT statement implementation
+*/
+
bool mysql_insert(THD *thd,TABLE_LIST *table_list,
List<Item> &fields,
List<List_item> &values_list,
@@ -406,7 +563,6 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
Name_resolution_context_state ctx_state;
#ifndef EMBEDDED_LIBRARY
char *query= thd->query;
-#endif
/*
log_on is about delayed inserts only.
By default, both logs are enabled (this won't cause problems if the server
@@ -414,98 +570,42 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
*/
bool log_on= ((thd->options & OPTION_BIN_LOG) ||
(!(thd->security_ctx->master_access & SUPER_ACL)));
+#endif
thr_lock_type lock_type = table_list->lock_type;
Item *unused_conds= 0;
DBUG_ENTER("mysql_insert");
/*
- in safe mode or with skip-new change delayed insert to be regular
- if we are told to replace duplicates, the insert cannot be concurrent
- delayed insert changed to regular in slave thread
- */
-#ifdef EMBEDDED_LIBRARY
- if (lock_type == TL_WRITE_DELAYED)
- lock_type=TL_WRITE;
-#else
- if ((lock_type == TL_WRITE_DELAYED &&
- ((specialflag & (SPECIAL_NO_NEW_FUNC | SPECIAL_SAFE_MODE)) ||
- thd->slave_thread || !thd->variables.max_insert_delayed_threads)) ||
- (lock_type == TL_WRITE_CONCURRENT_INSERT && duplic == DUP_REPLACE) ||
- (duplic == DUP_UPDATE))
- lock_type=TL_WRITE;
-#endif
- if ((lock_type == TL_WRITE_DELAYED) &&
- (global_system_variables.binlog_format == BINLOG_FORMAT_STMT) &&
- log_on && mysql_bin_log.is_open() &&
- (values_list.elements > 1))
+ Upgrade lock type if the requested lock is incompatible with
+ the current connection mode or table operation.
+ */
+ upgrade_lock_type(thd, &table_list->lock_type, duplic,
+ values_list.elements > 1);
+
+ /*
+ We can't write-delayed into a table locked with LOCK TABLES:
+ this will lead to a deadlock, since the delayed thread will
+ never be able to get a lock on the table. QQQ: why not
+ upgrade the lock here instead?
+ */
+ if (table_list->lock_type == TL_WRITE_DELAYED && thd->locked_tables &&
+ find_locked_table(thd, table_list->db, table_list->table_name))
{
- /*
- Statement-based binary logging does not work in this case, because:
- a) two concurrent statements may have their rows intermixed in the
- queue, leading to autoincrement replication problems on slave (because
- the values generated used for one statement don't depend only on the
- value generated for the first row of this statement, so are not
- replicable)
- b) if first row of the statement has an error the full statement is
- not binlogged, while next rows of the statement may be inserted.
- c) if first row succeeds, statement is binlogged immediately with a
- zero error code (i.e. "no error"), if then second row fails, query
- will fail on slave too and slave will stop (wrongly believing that the
- master got no error).
- So we fallback to non-delayed INSERT.
- Note that to be fully correct, we should test the "binlog format which
- the delayed thread is going to use for this row". But in the common case
- where the global binlog format is not changed and the session binlog
- format may be changed, that is equal to the global binlog format.
- We test it without mutex for speed reasons (condition rarely true), and
- in the common case (global not changed) it is as good as without mutex;
- if global value is changed, anyway there is uncertainty as the delayed
- thread may be old and use the before-the-change value.
- */
- lock_type= TL_WRITE;
+ my_error(ER_DELAYED_INSERT_TABLE_LOCKED, MYF(0),
+ table_list->table_name);
+ DBUG_RETURN(TRUE);
}
- table_list->lock_type= lock_type;
-#ifndef EMBEDDED_LIBRARY
- if (lock_type == TL_WRITE_DELAYED)
+ if (table_list->lock_type == TL_WRITE_DELAYED)
{
- res= 1;
- if (thd->locked_tables)
- {
- DBUG_ASSERT(table_list->db); /* Must be set in the parser */
- if (find_locked_table(thd, table_list->db, table_list->table_name))
- {
- my_error(ER_DELAYED_INSERT_TABLE_LOCKED, MYF(0),
- table_list->table_name);
- DBUG_RETURN(TRUE);
- }
- }
- if ((table= delayed_get_table(thd,table_list)) && !thd->is_fatal_error)
- {
- /*
- Open tables used for sub-selects or in stored functions, will also
- cache these functions.
- */
- res= open_and_lock_tables(thd, table_list->next_global);
- /*
- First is not processed by open_and_lock_tables() => we need set
- updateability flags "by hands".
- */
- if (!table_list->derived && !table_list->view)
- table_list->updatable= 1; // usual table
- }
- else
- {
- /* Too many delayed insert threads; Use a normal insert */
- table_list->lock_type= lock_type= TL_WRITE;
- res= open_and_lock_tables(thd, table_list);
- }
+ if (open_and_lock_for_insert_delayed(thd, table_list))
+ DBUG_RETURN(TRUE);
}
else
-#endif /* EMBEDDED_LIBRARY */
- res= open_and_lock_tables(thd, table_list);
- if (res || thd->is_fatal_error)
- DBUG_RETURN(TRUE);
+ {
+ if (open_and_lock_tables(thd, table_list))
+ DBUG_RETURN(TRUE);
+ }
thd->proc_info="init";
thd->used_tables=0;
@@ -523,6 +623,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
/* mysql_prepare_insert set table_list->table if it was not set */
table= table_list->table;
+ lock_type= table_list->lock_type;
context= &thd->lex->select_lex.context;
/*
@@ -1276,7 +1377,8 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
DBUG_ASSERT(info->update_fields->elements ==
info->update_values->elements);
if (fill_record_n_invoke_before_triggers(thd, *info->update_fields,
- *info->update_values, 0,
+ *info->update_values,
+ info->ignore,
table->triggers,
TRG_EVENT_UPDATE))
goto before_trg_err;
@@ -1502,8 +1604,14 @@ public:
}
};
+/**
+ Delayed_insert - context of a thread responsible for delayed insert
+ into one table. When processing delayed inserts, we create an own
+ thread for every distinct table. Later on all delayed inserts directed
+ into that table are handled by a dedicated thread.
+*/
-class delayed_insert :public ilink {
+class Delayed_insert :public ilink {
uint locks_in_memory;
public:
THD thd;
@@ -1517,7 +1625,7 @@ public:
ulong group_count;
TABLE_LIST table_list; // Argument
- delayed_insert()
+ Delayed_insert()
:locks_in_memory(0),
table(0),tables_in_use(0),stacked_inserts(0), status(0), dead(0),
group_count(0)
@@ -1547,7 +1655,7 @@ public:
delayed_insert_threads++;
VOID(pthread_mutex_unlock(&LOCK_thread_count));
}
- ~delayed_insert()
+ ~Delayed_insert()
{
/* The following is not really needed, but just for safety */
delayed_row *row;
@@ -1595,15 +1703,21 @@ public:
};
-I_List<delayed_insert> delayed_threads;
+I_List<Delayed_insert> delayed_threads;
+
+/**
+ Return an instance of delayed insert thread that can handle
+ inserts into a given table, if it exists. Otherwise return NULL.
+*/
-delayed_insert *find_handler(THD *thd, TABLE_LIST *table_list)
+static
+Delayed_insert *find_handler(THD *thd, TABLE_LIST *table_list)
{
thd->proc_info="waiting for delay_list";
pthread_mutex_lock(&LOCK_delayed_insert); // Protect master list
- I_List_iterator<delayed_insert> it(delayed_threads);
- delayed_insert *tmp;
+ I_List_iterator<Delayed_insert> it(delayed_threads);
+ Delayed_insert *tmp;
while ((tmp=it++))
{
if (!strcmp(tmp->thd.db, table_list->db) &&
@@ -1618,11 +1732,36 @@ delayed_insert *find_handler(THD *thd, TABLE_LIST *table_list)
}
-static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list)
+/**
+ Attempt to find or create a delayed insert thread to handle inserts
+ into this table.
+
+ @return In case of success, table_list->table points to a local copy
+ of the delayed table or is set to NULL, which indicates a
+ request for lock upgrade. In case of failure, value of
+ table_list->table is undefined.
+ @retval TRUE - this thread ran out of resources OR
+ - a newly created delayed insert thread ran out of
+ resources OR
+ - the created thread failed to open and lock the table
+ (e.g. because it does not exist) OR
+ - the table opened in the created thread turned out to
+ be a view
+ @retval FALSE - table successfully opened OR
+ - too many delayed insert threads OR
+ - the table has triggers and we have to fall back to
+ a normal INSERT
+ Two latter cases indicate a request for lock upgrade.
+
+ XXX: why do we regard INSERT DELAYED into a view as an error and
+ do not simply a lock upgrade?
+*/
+
+static
+bool delayed_get_table(THD *thd, TABLE_LIST *table_list)
{
int error;
- delayed_insert *tmp;
- TABLE *table;
+ Delayed_insert *tmp;
DBUG_ENTER("delayed_get_table");
/* Must be set in the parser */
@@ -1645,10 +1784,11 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list)
*/
if (! (tmp= find_handler(thd, table_list)))
{
- if (!(tmp=new delayed_insert()))
+ if (!(tmp=new Delayed_insert()))
{
- my_error(ER_OUTOFMEMORY,MYF(0),sizeof(delayed_insert));
- goto err1;
+ my_error(ER_OUTOFMEMORY,MYF(0),sizeof(Delayed_insert));
+ thd->fatal_error();
+ goto end_create;
}
pthread_mutex_lock(&LOCK_thread_count);
thread_count++;
@@ -1657,9 +1797,10 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list)
tmp->thd.query= my_strdup(table_list->table_name,MYF(MY_WME));
if (tmp->thd.db == NULL || tmp->thd.query == NULL)
{
+ /* The error is reported */
delete tmp;
- my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
- goto err1;
+ thd->fatal_error();
+ goto end_create;
}
tmp->table_list= *table_list; // Needed to open table
tmp->table_list.alias= tmp->table_list.table_name= tmp->thd.query;
@@ -1675,7 +1816,8 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list)
tmp->unlock();
delete tmp;
my_error(ER_CANT_CREATE_THREAD, MYF(0), error);
- goto err1;
+ thd->fatal_error();
+ goto end_create;
}
/* Wait until table is open */
@@ -1688,59 +1830,72 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list)
thd->proc_info="got old table";
if (tmp->thd.killed)
{
- if (tmp->thd.is_fatal_error)
- {
- /* Copy error message and abort */
- thd->fatal_error();
- strmov(thd->net.last_error,tmp->thd.net.last_error);
- thd->net.last_errno=tmp->thd.net.last_errno;
+ if (tmp->thd.net.report_error)
+ {
+ /*
+ Copy the error message. Note that we don't treat fatal
+ errors in the delayed thread as fatal errors in the
+ main thread. Use of my_message will enable stored
+ procedures continue handlers.
+ */
+ my_message(tmp->thd.net.last_errno, tmp->thd.net.last_error,
+ MYF(0));
}
tmp->unlock();
- goto err;
+ goto end_create;
}
if (thd->killed)
{
tmp->unlock();
- goto err;
+ goto end_create;
}
}
pthread_mutex_unlock(&LOCK_delayed_create);
}
pthread_mutex_lock(&tmp->mutex);
- table= tmp->get_local_table(thd);
+ table_list->table= tmp->get_local_table(thd);
pthread_mutex_unlock(&tmp->mutex);
- if (table)
+ if (table_list->table)
+ {
+ DBUG_ASSERT(thd->net.report_error == 0);
thd->di=tmp;
- else if (tmp->thd.is_fatal_error)
- thd->fatal_error();
+ }
/* Unlock the delayed insert object after its last access. */
tmp->unlock();
- DBUG_RETURN((table_list->table=table));
+ DBUG_RETURN((table_list->table == NULL));
- err1:
+end_create:
thd->fatal_error();
- err:
pthread_mutex_unlock(&LOCK_delayed_create);
- DBUG_RETURN(0); // Continue with normal insert
+ DBUG_RETURN(thd->net.report_error);
}
-/*
- As we can't let many threads modify the same TABLE structure, we create
- an own structure for each tread. This includes a row buffer to save the
- column values and new fields that points to the new row buffer.
- The memory is allocated in the client thread and is freed automaticly.
+/**
+ As we can't let many client threads modify the same TABLE
+ structure of the dedicated delayed insert thread, we create an
+ own structure for each client thread. This includes a row
+ buffer to save the column values and new fields that point to
+ the new row buffer. The memory is allocated in the client
+ thread and is freed automatically.
+
+ @pre This function is called from the client thread. Delayed
+ insert thread mutex must be acquired before invoking this
+ function.
+
+ @return Not-NULL table object on success. NULL in case of an error,
+ which is set in client_thd.
*/
-TABLE *delayed_insert::get_local_table(THD* client_thd)
+TABLE *Delayed_insert::get_local_table(THD* client_thd)
{
my_ptrdiff_t adjust_ptrs;
Field **field,**org_field, *found_next_number_field;
TABLE *copy;
TABLE_SHARE *share= table->s;
uchar *bitmap;
- DBUG_ENTER("delayed_insert::get_local_table");
+ DBUG_ENTER("Delayed_insert::get_local_table");
/* First request insert thread to get a lock */
status=1;
@@ -1758,8 +1913,7 @@ TABLE *delayed_insert::get_local_table(THD* client_thd)
goto error;
if (dead)
{
- strmov(client_thd->net.last_error,thd.net.last_error);
- client_thd->net.last_errno=thd.net.last_errno;
+ my_message(thd.net.last_errno, thd.net.last_error, MYF(0));
goto error;
}
}
@@ -1799,7 +1953,7 @@ TABLE *delayed_insert::get_local_table(THD* client_thd)
for (org_field= table->field; *org_field; org_field++, field++)
{
if (!(*field= (*org_field)->new_field(client_thd->mem_root, copy, 1)))
- DBUG_RETURN(0);
+ goto error;
(*field)->orig_table= copy; // Remove connection
(*field)->move_field_offset(adjust_ptrs); // Point at copy->record[0]
if (*org_field == found_next_number_field)
@@ -1845,12 +1999,12 @@ TABLE *delayed_insert::get_local_table(THD* client_thd)
/* Put a question in queue */
-static int
-write_delayed(THD *thd,TABLE *table, enum_duplicates duplic,
- LEX_STRING query, bool ignore, bool log_on)
+static
+int write_delayed(THD *thd, TABLE *table, enum_duplicates duplic,
+ LEX_STRING query, bool ignore, bool log_on)
{
delayed_row *row= 0;
- delayed_insert *di=thd->di;
+ Delayed_insert *di=thd->di;
const Discrete_interval *forced_auto_inc;
DBUG_ENTER("write_delayed");
DBUG_PRINT("enter", ("query = '%s' length %lu", query.str,
@@ -1930,11 +2084,15 @@ write_delayed(THD *thd,TABLE *table, enum_duplicates duplic,
DBUG_RETURN(1);
}
+/**
+ Signal the delayed insert thread that this user connection
+ is finished using it for this statement.
+*/
static void end_delayed_insert(THD *thd)
{
DBUG_ENTER("end_delayed_insert");
- delayed_insert *di=thd->di;
+ Delayed_insert *di=thd->di;
pthread_mutex_lock(&di->mutex);
DBUG_PRINT("info",("tables in use: %d",di->tables_in_use));
if (!--di->tables_in_use || di->thd.killed)
@@ -1953,8 +2111,8 @@ void kill_delayed_threads(void)
{
VOID(pthread_mutex_lock(&LOCK_delayed_insert)); // For unlink from list
- I_List_iterator<delayed_insert> it(delayed_threads);
- delayed_insert *tmp;
+ I_List_iterator<Delayed_insert> it(delayed_threads);
+ Delayed_insert *tmp;
while ((tmp=it++))
{
tmp->thd.killed= THD::KILL_CONNECTION;
@@ -1986,7 +2144,7 @@ void kill_delayed_threads(void)
pthread_handler_t handle_delayed_insert(void *arg)
{
- delayed_insert *di=(delayed_insert*) arg;
+ Delayed_insert *di=(Delayed_insert*) arg;
THD *thd= &di->thd;
pthread_detach_this_thread();
@@ -2036,6 +2194,15 @@ pthread_handler_t handle_delayed_insert(void *arg)
my_error(ER_ILLEGAL_HA, MYF(0), di->table_list.table_name);
goto err;
}
+ if (di->table->triggers)
+ {
+ /*
+ Table has triggers. This is not an error, but we do
+ not support triggers with delayed insert. Terminate the delayed
+ thread without an error and thus request lock upgrade.
+ */
+ goto err;
+ }
di->table->copy_blobs=1;
/* One can now use this */
@@ -2237,7 +2404,7 @@ static void free_delayed_insert_blobs(register TABLE *table)
}
-bool delayed_insert::handle_inserts(void)
+bool Delayed_insert::handle_inserts(void)
{
int error;
ulong max_rows;
@@ -2262,7 +2429,7 @@ bool delayed_insert::handle_inserts(void)
thd.proc_info="insert";
max_rows= delayed_insert_limit;
- if (thd.killed || table->s->version != refresh_version)
+ if (thd.killed || table->needs_reopen_or_name_lock())
{
thd.killed= THD::KILL_CONNECTION;
max_rows= ULONG_MAX; // Do as much as possible
@@ -2964,8 +3131,8 @@ bool select_insert::send_eof()
***************************************************************************/
/*
- Create table from lists of fields and items (or open existing table
- with same name).
+ Create table from lists of fields and items (or just return TABLE
+ object for pre-opened existing table).
SYNOPSIS
create_table_from_items()
@@ -2980,19 +3147,25 @@ bool select_insert::send_eof()
of fields for the table (corresponding fields will
be added to the end of 'extra_fields' list)
lock out Pointer to the MYSQL_LOCK object for table created
- (open) will be returned in this parameter. Since
- this table is not included in THD::lock caller is
- responsible for explicitly unlocking this table.
+ (or open temporary table) will be returned in this
+ parameter. Since this table is not included in
+ THD::lock caller is responsible for explicitly
+ unlocking this table.
hooks
NOTES
- If 'create_info->options' bitmask has HA_LEX_CREATE_IF_NOT_EXISTS
- flag and table with name provided already exists then this function will
- simply open existing table.
- Also note that create, open and lock sequence in this function is not
- atomic and thus contains gap for deadlock and can cause other troubles.
- Since this function contains some logic specific to CREATE TABLE ... SELECT
- it should be changed before it can be used in other contexts.
+ This function behaves differently for base and temporary tables:
+ - For base table we assume that either table exists and was pre-opened
+ and locked at open_and_lock_tables() stage (and in this case we just
+ emit error or warning and return pre-opened TABLE object) or special
+ placeholder was put in table cache that guarantees that this table
+ won't be created or opened until the placeholder will be removed
+ (so there is an exclusive lock on this table).
+ - We don't pre-open existing temporary table, instead we either open
+ or create and then open table in this function.
+
+ Since this function contains some logic specific to CREATE TABLE ...
+ SELECT it should be changed before it can be used in other contexts.
RETURN VALUES
non-zero Pointer to TABLE object for table created or opened
@@ -3018,6 +3191,25 @@ static TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info,
bool not_used;
DBUG_ENTER("create_table_from_items");
+ DBUG_EXECUTE_IF("sleep_create_select_before_check_if_exists", my_sleep(6000000););
+
+ if (!(create_info->options & HA_LEX_CREATE_TMP_TABLE) &&
+ create_table->table->db_stat)
+ {
+ /* Table already exists and was open at open_and_lock_tables() stage. */
+ if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)
+ {
+ create_info->table_existed= 1; // Mark that table existed
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
+ ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
+ create_table->table_name);
+ DBUG_RETURN(create_table->table);
+ }
+
+ my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->table_name);
+ DBUG_RETURN(0);
+ }
+
tmp_table.alias= 0;
tmp_table.timestamp_field= 0;
tmp_table.s= &share;
@@ -3049,8 +3241,15 @@ static TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info,
cr_field->flags &= ~NOT_NULL_FLAG;
extra_fields->push_back(cr_field);
}
+
+ DBUG_EXECUTE_IF("sleep_create_select_before_create", my_sleep(6000000););
+
/*
- create and lock table
+ Create and lock table.
+
+ Note that we either creating (or opening existing) temporary table or
+ creating base table on which name we have exclusive lock. So code below
+ should not cause deadlocks or races.
We don't log the statement, it will be logged later.
@@ -3060,63 +3259,72 @@ static TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info,
don't want to delete from it) 2) it would be written before the CREATE
TABLE, which is a wrong order. So we keep binary logging disabled when we
open_table().
- NOTE: By locking table which we just have created (or for which we just
- have have found that it already exists) separately from other tables used
- by the statement we create potential window for deadlock.
- TODO: create and open should be done atomic !
*/
{
tmp_disable_binlog(thd);
- if (!mysql_create_table(thd, create_table->db, create_table->table_name,
- create_info, *extra_fields, *keys, 0,
- select_field_count, 0))
+ if (!mysql_create_table_no_lock(thd, create_table->db,
+ create_table->table_name,
+ create_info, *extra_fields, *keys, 0,
+ select_field_count, 0))
{
- /*
- If we are here in prelocked mode we either create temporary table
- or prelocked mode is caused by the SELECT part of this statement.
- */
- DBUG_ASSERT(!thd->prelocked_mode ||
- create_info->options & HA_LEX_CREATE_TMP_TABLE ||
- thd->lex->requires_prelocking());
+ if (create_info->table_existed &&
+ !(create_info->options & HA_LEX_CREATE_TMP_TABLE))
+ {
+ /*
+ This means that someone created table underneath server
+ or it was created via different mysqld front-end to the
+ cluster. We don't have much options but throw an error.
+ */
+ my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->table_name);
+ DBUG_RETURN(0);
+ }
- /*
- NOTE: We don't want to ignore set of locked tables here if we are
- under explicit LOCK TABLES since it will open gap for deadlock
- too wide (and also is not backward compatible).
- */
+ DBUG_EXECUTE_IF("sleep_create_select_before_open", my_sleep(6000000););
- if (! (table= open_table(thd, create_table, thd->mem_root, (bool*) 0,
- (MYSQL_LOCK_IGNORE_FLUSH |
- ((thd->prelocked_mode == PRELOCKED) ?
- MYSQL_OPEN_IGNORE_LOCKED_TABLES:0)))))
- quick_rm_table(create_info->db_type, create_table->db,
- table_case_name(create_info, create_table->table_name),
- 0);
+ if (!(create_info->options & HA_LEX_CREATE_TMP_TABLE))
+ {
+ VOID(pthread_mutex_lock(&LOCK_open));
+ if (reopen_name_locked_table(thd, create_table, FALSE))
+ {
+ quick_rm_table(create_info->db_type, create_table->db,
+ table_case_name(create_info, create_table->table_name),
+ 0);
+ }
+ else
+ table= create_table->table;
+ VOID(pthread_mutex_unlock(&LOCK_open));
+ }
+ else
+ {
+ if (!(table= open_table(thd, create_table, thd->mem_root, (bool*) 0,
+ MYSQL_OPEN_TEMPORARY_ONLY)) &&
+ !create_info->table_existed)
+ {
+ /*
+ This shouldn't happen as creation of temporary table should make
+ it preparable for open. But let us do close_temporary_table() here
+ just in case.
+ */
+ close_temporary_table(thd, create_table);
+ }
+ }
}
reenable_binlog(thd);
if (!table) // open failed
DBUG_RETURN(0);
}
- /*
- FIXME: What happens if trigger manages to be created while we are
- obtaining this lock ? May be it is sensible just to disable
- trigger execution in this case ? Or will MYSQL_LOCK_IGNORE_FLUSH
- save us from that ?
- */
+ DBUG_EXECUTE_IF("sleep_create_select_before_lock", my_sleep(6000000););
+
table->reginfo.lock_type=TL_WRITE;
hooks->prelock(&table, 1); // Call prelock hooks
if (! ((*lock)= mysql_lock_tables(thd, &table, 1,
MYSQL_LOCK_IGNORE_FLUSH, &not_used)))
{
- VOID(pthread_mutex_lock(&LOCK_open));
- hash_delete(&open_cache,(uchar*) table);
- VOID(pthread_mutex_unlock(&LOCK_open));
- quick_rm_table(create_info->db_type, create_table->db,
- table_case_name(create_info, create_table->table_name), 0);
+ if (!create_info->table_existed)
+ drop_open_table(thd, table, create_table->db, create_table->table_name);
DBUG_RETURN(0);
}
- table->file->extra(HA_EXTRA_WRITE_CACHE);
DBUG_RETURN(table);
}
@@ -3219,6 +3427,7 @@ select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
if (check_that_all_fields_are_given_values(thd, table, table_list))
DBUG_RETURN(1);
table->mark_columns_needed_for_insert();
+ table->file->extra(HA_EXTRA_WRITE_CACHE);
DBUG_RETURN(0);
}
@@ -3321,24 +3530,19 @@ bool select_create::send_eof()
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
- VOID(pthread_mutex_lock(&LOCK_open));
- mysql_unlock_tables(thd, thd->extra_lock);
- if (!table->s->tmp_table)
+ if (thd->extra_lock)
{
- if (close_thread_table(thd, &table))
- broadcast_refresh();
+ mysql_unlock_tables(thd, thd->extra_lock);
+ thd->extra_lock=0;
}
- thd->extra_lock=0;
- table=0;
- VOID(pthread_mutex_unlock(&LOCK_open));
}
return tmp;
}
+
void select_create::abort()
{
DBUG_ENTER("select_create::abort");
- VOID(pthread_mutex_lock(&LOCK_open));
/*
We roll back the statement, including truncating the transaction
@@ -3366,24 +3570,10 @@ void select_create::abort()
{
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
- handlerton *table_type=table->s->db_type;
- if (!table->s->tmp_table)
- {
- ulong version= table->s->version;
- table->s->version= 0;
- hash_delete(&open_cache,(uchar*) table);
- if (!create_info->table_existed)
- quick_rm_table(table_type, create_table->db,
- create_table->table_name, 0);
- /* Tell threads waiting for refresh that something has happened */
- if (version != refresh_version)
- broadcast_refresh();
- }
- else if (!create_info->table_existed)
- close_temporary_table(thd, table, 1, 1);
+ if (!create_info->table_existed)
+ drop_open_table(thd, table, create_table->db, create_table->table_name);
table=0; // Safety
}
- VOID(pthread_mutex_unlock(&LOCK_open));
DBUG_VOID_RETURN;
}
@@ -3395,8 +3585,8 @@ void select_create::abort()
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
template class List_iterator_fast<List_item>;
#ifndef EMBEDDED_LIBRARY
-template class I_List<delayed_insert>;
-template class I_List_iterator<delayed_insert>;
+template class I_List<Delayed_insert>;
+template class I_List_iterator<Delayed_insert>;
template class I_List<delayed_row>;
#endif /* EMBEDDED_LIBRARY */
#endif /* HAVE_EXPLICIT_TEMPLATE_INSTANTIATION */
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 5e5308f4ab7..7d8e5004f7f 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -33,13 +33,13 @@ sys_var *trg_new_row_fake_var= (sys_var*) 0x01;
/* Macros to look like lex */
-#define yyGet() ((uchar) *(lex->ptr++))
-#define yyGetLast() ((uchar) lex->ptr[-1])
-#define yyPeek() ((uchar) lex->ptr[0])
-#define yyPeek2() ((uchar) lex->ptr[1])
-#define yyUnget() lex->ptr--
-#define yySkip() lex->ptr++
-#define yyLength() ((uint) (lex->ptr - lex->tok_start)-1)
+#define yyGet() ((uchar) *(lip->ptr++))
+#define yyGetLast() ((uchar) lip->ptr[-1])
+#define yyPeek() ((uchar) lip->ptr[0])
+#define yyPeek2() ((uchar) lip->ptr[1])
+#define yyUnget() lip->ptr--
+#define yySkip() lip->ptr++
+#define yyLength() ((uint) (lip->ptr - lip->tok_start)-1)
/* Longest standard keyword name */
#define TOCK_NAME_LENGTH 24
@@ -120,6 +120,29 @@ st_parsing_options::reset()
allows_derived= TRUE;
}
+Lex_input_stream::Lex_input_stream(THD *thd,
+ const char* buffer,
+ unsigned int length)
+: m_thd(thd),
+ yylineno(1),
+ yytoklen(0),
+ yylval(NULL),
+ ptr(buffer),
+ tok_start(NULL),
+ tok_end(NULL),
+ end_of_query(buffer + length),
+ tok_start_prev(NULL),
+ buf(buffer),
+ next_state(MY_LEX_START),
+ found_semicolon(NULL),
+ ignore_space(test(thd->variables.sql_mode & MODE_IGNORE_SPACE)),
+ stmt_prepare_mode(FALSE)
+{
+}
+
+Lex_input_stream::~Lex_input_stream()
+{}
+
/*
This is called before every query that is to be parsed.
@@ -127,14 +150,12 @@ st_parsing_options::reset()
(We already do too much here)
*/
-void lex_start(THD *thd, const char *buf, uint length)
+void lex_start(THD *thd)
{
LEX *lex= thd->lex;
DBUG_ENTER("lex_start");
lex->thd= lex->unit.thd= thd;
- lex->buf= lex->ptr= buf;
- lex->end_of_query= buf+length;
lex->context_stack.empty();
lex->unit.init_query();
@@ -164,17 +185,13 @@ void lex_start(THD *thd, const char *buf, uint length)
lex->describe= 0;
lex->subqueries= FALSE;
lex->view_prepare_mode= FALSE;
- lex->stmt_prepare_mode= FALSE;
lex->derived_tables= 0;
lex->lock_option= TL_READ;
- lex->found_semicolon= 0;
lex->safe_to_cache_query= 1;
lex->leaf_tables_insert= 0;
lex->parsing_options.reset();
lex->empty_field_list_on_rset= 0;
lex->select_lex.select_number= 1;
- lex->next_state=MY_LEX_START;
- lex->yylineno = 1;
lex->in_comment=0;
lex->length=0;
lex->part_info= 0;
@@ -184,7 +201,6 @@ void lex_start(THD *thd, const char *buf, uint length)
lex->select_lex.ftfunc_list= &lex->select_lex.ftfunc_list_alloc;
lex->select_lex.group_list.empty();
lex->select_lex.order_list.empty();
- lex->ignore_space=test(thd->variables.sql_mode & MODE_IGNORE_SPACE);
lex->sql_command= SQLCOM_END;
lex->duplicates= DUP_ERROR;
lex->ignore= 0;
@@ -193,6 +209,7 @@ void lex_start(THD *thd, const char *buf, uint length)
lex->spcont= NULL;
lex->proc_list.first= 0;
lex->escape_used= FALSE;
+ lex->query_tables= 0;
lex->reset_query_tables_list(FALSE);
lex->expr_allows_subselect= TRUE;
@@ -232,28 +249,34 @@ void lex_end(LEX *lex)
lex->yacc_yyss= 0;
lex->yacc_yyvs= 0;
}
+
+ /* release used plugins */
+ plugin_unlock_list(0, (plugin_ref*)lex->plugins.buffer,
+ lex->plugins.elements);
+ reset_dynamic(&lex->plugins);
+
DBUG_VOID_RETURN;
}
-static int find_keyword(LEX *lex, uint len, bool function)
+static int find_keyword(Lex_input_stream *lip, uint len, bool function)
{
- const char *tok= lex->tok_start;
+ const char *tok= lip->tok_start;
SYMBOL *symbol= get_hash_symbol(tok, len, function);
if (symbol)
{
- lex->yylval->symbol.symbol=symbol;
- lex->yylval->symbol.str= (char*) tok;
- lex->yylval->symbol.length=len;
-
+ lip->yylval->symbol.symbol=symbol;
+ lip->yylval->symbol.str= (char*) tok;
+ lip->yylval->symbol.length=len;
+
if ((symbol->tok == NOT_SYM) &&
- (lex->thd->variables.sql_mode & MODE_HIGH_NOT_PRECEDENCE))
+ (lip->m_thd->variables.sql_mode & MODE_HIGH_NOT_PRECEDENCE))
return NOT2_SYM;
if ((symbol->tok == OR_OR_SYM) &&
- !(lex->thd->variables.sql_mode & MODE_PIPES_AS_CONCAT))
+ !(lip->m_thd->variables.sql_mode & MODE_PIPES_AS_CONCAT))
return OR2_SYM;
-
+
return symbol->tok;
}
return 0;
@@ -286,12 +309,12 @@ bool is_lex_native_function(const LEX_STRING *name)
/* make a copy of token before ptr and set yytoklen */
-static LEX_STRING get_token(LEX *lex,uint length)
+static LEX_STRING get_token(Lex_input_stream *lip, uint skip, uint length)
{
LEX_STRING tmp;
yyUnget(); // ptr points now after last token char
- tmp.length=lex->yytoklen=length;
- tmp.str=(char*) lex->thd->strmake((char*) lex->tok_start,tmp.length);
+ tmp.length=lip->yytoklen=length;
+ tmp.str= lip->m_thd->strmake(lip->tok_start + skip, tmp.length);
return tmp;
}
@@ -302,17 +325,20 @@ static LEX_STRING get_token(LEX *lex,uint length)
future to operate multichar strings (like ucs2)
*/
-static LEX_STRING get_quoted_token(LEX *lex,uint length, char quote)
+static LEX_STRING get_quoted_token(Lex_input_stream *lip,
+ uint skip,
+ uint length, char quote)
{
LEX_STRING tmp;
const char *from, *end;
char *to;
yyUnget(); // ptr points now after last token char
- tmp.length=lex->yytoklen=length;
- tmp.str=(char*) lex->thd->alloc(tmp.length+1);
- for (from= lex->tok_start, to= tmp.str, end= to+length ;
- to != end ;
- )
+ tmp.length= lip->yytoklen=length;
+ tmp.str=(char*) lip->m_thd->alloc(tmp.length+1);
+ from= lip->tok_start + skip;
+ to= tmp.str;
+ end= to+length;
+ for ( ; to != end; )
{
if ((*to++= *from++) == quote)
from++; // Skip double quotes
@@ -327,31 +353,31 @@ static LEX_STRING get_quoted_token(LEX *lex,uint length, char quote)
Fix sometimes to do only one scan of the string
*/
-static char *get_text(LEX *lex)
+static char *get_text(Lex_input_stream *lip)
{
reg1 uchar c,sep;
uint found_escape=0;
- CHARSET_INFO *cs= lex->thd->charset();
+ CHARSET_INFO *cs= lip->m_thd->charset();
sep= yyGetLast(); // String should end with this
- while (lex->ptr != lex->end_of_query)
+ while (lip->ptr != lip->end_of_query)
{
c = yyGet();
#ifdef USE_MB
{
int l;
if (use_mb(cs) &&
- (l = my_ismbchar(cs, lex->ptr-1, lex->end_of_query))) {
- lex->ptr += l-1;
+ (l = my_ismbchar(cs, lip->ptr-1, lip->end_of_query))) {
+ lip->ptr += l-1;
continue;
}
}
#endif
if (c == '\\' &&
- !(lex->thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES))
+ !(lip->m_thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES))
{ // Escaped character
found_escape=1;
- if (lex->ptr == lex->end_of_query)
+ if (lip->ptr == lip->end_of_query)
return 0;
yySkip();
}
@@ -369,15 +395,15 @@ static char *get_text(LEX *lex)
const char *str, *end;
char *start;
- str=lex->tok_start+1;
- end=lex->ptr-1;
- if (!(start= (char*) lex->thd->alloc((uint) (end-str)+1)))
+ str=lip->tok_start+1;
+ end=lip->ptr-1;
+ if (!(start= (char*) lip->m_thd->alloc((uint) (end-str)+1)))
return (char*) ""; // Sql_alloc has set error flag
if (!found_escape)
{
- lex->yytoklen=(uint) (end-str);
- memcpy(start,str,lex->yytoklen);
- start[lex->yytoklen]=0;
+ lip->yytoklen=(uint) (end-str);
+ memcpy(start,str,lip->yytoklen);
+ start[lip->yytoklen]=0;
}
else
{
@@ -395,7 +421,7 @@ static char *get_text(LEX *lex)
continue;
}
#endif
- if (!(lex->thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) &&
+ if (!(lip->m_thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) &&
*str == '\\' && str+1 != end)
{
switch(*++str) {
@@ -432,7 +458,7 @@ static char *get_text(LEX *lex)
*to++ = *str;
}
*to=0;
- lex->yytoklen=(uint) (to-start);
+ lip->yytoklen=(uint) (to-start);
}
return start;
}
@@ -545,19 +571,21 @@ int MYSQLlex(void *arg, void *yythd)
int tokval, result_state;
uint length;
enum my_lex_states state;
- LEX *lex= ((THD *)yythd)->lex;
+ THD *thd= (THD *)yythd;
+ Lex_input_stream *lip= thd->m_lip;
+ LEX *lex= thd->lex;
YYSTYPE *yylval=(YYSTYPE*) arg;
- CHARSET_INFO *cs= ((THD *) yythd)->charset();
+ CHARSET_INFO *cs= thd->charset();
uchar *state_map= cs->state_map;
uchar *ident_map= cs->ident_map;
- lex->yylval=yylval; // The global state
+ lip->yylval=yylval; // The global state
- lex->tok_start_prev= lex->tok_start;
+ lip->tok_start_prev= lip->tok_start;
- lex->tok_start=lex->tok_end=lex->ptr;
- state=lex->next_state;
- lex->next_state=MY_LEX_OPERATOR_OR_IDENT;
+ lip->tok_start=lip->tok_end=lip->ptr;
+ state=lip->next_state;
+ lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
LINT_INIT(c);
for (;;)
{
@@ -568,9 +596,9 @@ int MYSQLlex(void *arg, void *yythd)
for (c=yyGet() ; (state_map[c] == MY_LEX_SKIP) ; c= yyGet())
{
if (c == '\n')
- lex->yylineno++;
+ lip->yylineno++;
}
- lex->tok_start=lex->ptr-1; // Start of real token
+ lip->tok_start=lip->ptr-1; // Start of real token
state= (enum my_lex_states) state_map[c];
break;
case MY_LEX_ESCAPE:
@@ -589,20 +617,20 @@ int MYSQLlex(void *arg, void *yythd)
state=MY_LEX_COMMENT;
break;
}
- yylval->lex_str.str=(char*) (lex->ptr=lex->tok_start);// Set to first chr
+ yylval->lex_str.str=(char*) (lip->ptr=lip->tok_start);// Set to first chr
yylval->lex_str.length=1;
c=yyGet();
if (c != ')')
- lex->next_state= MY_LEX_START; // Allow signed numbers
+ lip->next_state= MY_LEX_START; // Allow signed numbers
if (c == ',')
- lex->tok_start=lex->ptr; // Let tok_start point at next item
+ lip->tok_start=lip->ptr; // Let tok_start point at next item
/*
Check for a placeholder: it should not precede a possible identifier
because of binlogging: when a placeholder is replaced with
its value in a query for the binlog, the query must stay
grammatically correct.
*/
- else if (c == '?' && lex->stmt_prepare_mode && !ident_map[yyPeek()])
+ else if (c == '?' && lip->stmt_prepare_mode && !ident_map[yyPeek()])
return(PARAM_MARKER);
return((int) c);
@@ -613,14 +641,14 @@ int MYSQLlex(void *arg, void *yythd)
break;
}
/* Found N'string' */
- lex->tok_start++; // Skip N
+ lip->tok_start++; // Skip N
yySkip(); // Skip '
- if (!(yylval->lex_str.str = get_text(lex)))
+ if (!(yylval->lex_str.str = get_text(lip)))
{
state= MY_LEX_CHAR; // Read char by char
break;
}
- yylval->lex_str.length= lex->yytoklen;
+ yylval->lex_str.length= lip->yytoklen;
return(NCHAR_STRING);
case MY_LEX_IDENT_OR_HEX:
@@ -643,21 +671,21 @@ int MYSQLlex(void *arg, void *yythd)
result_state= IDENT_QUOTED;
if (my_mbcharlen(cs, yyGetLast()) > 1)
{
- int l = my_ismbchar(cs, lex->ptr-1, lex->end_of_query);
+ int l = my_ismbchar(cs, lip->ptr-1, lip->end_of_query);
if (l == 0) {
state = MY_LEX_CHAR;
continue;
}
- lex->ptr += l - 1;
+ lip->ptr += l - 1;
}
while (ident_map[c=yyGet()])
{
if (my_mbcharlen(cs, c) > 1)
{
int l;
- if ((l = my_ismbchar(cs, lex->ptr-1, lex->end_of_query)) == 0)
+ if ((l = my_ismbchar(cs, lip->ptr-1, lip->end_of_query)) == 0)
break;
- lex->ptr += l-1;
+ lip->ptr += l-1;
}
}
}
@@ -668,9 +696,9 @@ int MYSQLlex(void *arg, void *yythd)
/* If there were non-ASCII characters, mark that we must convert */
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
}
- length= (uint) (lex->ptr - lex->tok_start)-1;
- start= lex->ptr;
- if (lex->ignore_space)
+ length= (uint) (lip->ptr - lip->tok_start)-1;
+ start= lip->ptr;
+ if (lip->ignore_space)
{
/*
If we find a space then this can't be an identifier. We notice this
@@ -678,19 +706,19 @@ int MYSQLlex(void *arg, void *yythd)
*/
for (; state_map[c] == MY_LEX_SKIP ; c= yyGet());
}
- if (start == lex->ptr && c == '.' && ident_map[yyPeek()])
- lex->next_state=MY_LEX_IDENT_SEP;
+ if (start == lip->ptr && c == '.' && ident_map[yyPeek()])
+ lip->next_state=MY_LEX_IDENT_SEP;
else
{ // '(' must follow directly if function
yyUnget();
- if ((tokval = find_keyword(lex,length,c == '(')))
+ if ((tokval = find_keyword(lip, length,c == '(')))
{
- lex->next_state= MY_LEX_START; // Allow signed numbers
+ lip->next_state= MY_LEX_START; // Allow signed numbers
return(tokval); // Was keyword
}
yySkip(); // next state does a unget
}
- yylval->lex_str=get_token(lex,length);
+ yylval->lex_str=get_token(lip, 0, length);
/*
Note: "SELECT _bla AS 'alias'"
@@ -707,12 +735,12 @@ int MYSQLlex(void *arg, void *yythd)
return(result_state); // IDENT or IDENT_QUOTED
case MY_LEX_IDENT_SEP: // Found ident and now '.'
- yylval->lex_str.str=(char*) lex->ptr;
+ yylval->lex_str.str=(char*) lip->ptr;
yylval->lex_str.length=1;
c=yyGet(); // should be '.'
- lex->next_state= MY_LEX_IDENT_START;// Next is an ident (not a keyword)
+ lip->next_state= MY_LEX_IDENT_START;// Next is an ident (not a keyword)
if (!ident_map[yyPeek()]) // Probably ` or "
- lex->next_state= MY_LEX_START;
+ lip->next_state= MY_LEX_START;
return((int) c);
case MY_LEX_NUMBER_IDENT: // number or ident which num-start
@@ -732,36 +760,32 @@ int MYSQLlex(void *arg, void *yythd)
{
yySkip();
while (my_isdigit(cs,yyGet())) ;
- yylval->lex_str=get_token(lex,yyLength());
+ yylval->lex_str=get_token(lip, 0, yyLength());
return(FLOAT_NUM);
}
}
yyUnget(); /* purecov: inspected */
}
- else if (c == 'x' && (lex->ptr - lex->tok_start) == 2 &&
- lex->tok_start[0] == '0' )
+ else if (c == 'x' && (lip->ptr - lip->tok_start) == 2 &&
+ lip->tok_start[0] == '0' )
{ // Varbinary
while (my_isxdigit(cs,(c = yyGet()))) ;
- if ((lex->ptr - lex->tok_start) >= 4 && !ident_map[c])
+ if ((lip->ptr - lip->tok_start) >= 4 && !ident_map[c])
{
- yylval->lex_str=get_token(lex,yyLength());
- yylval->lex_str.str+=2; // Skip 0x
- yylval->lex_str.length-=2;
- lex->yytoklen-=2;
+ /* skip '0x' */
+ yylval->lex_str=get_token(lip, 2, yyLength()-2);
return (HEX_NUM);
}
yyUnget();
}
- else if (c == 'b' && (lex->ptr - lex->tok_start) == 2 &&
- lex->tok_start[0] == '0' )
+ else if (c == 'b' && (lip->ptr - lip->tok_start) == 2 &&
+ lip->tok_start[0] == '0' )
{ // b'bin-number'
while (my_isxdigit(cs,(c = yyGet()))) ;
- if ((lex->ptr - lex->tok_start) >= 4 && !ident_map[c])
+ if ((lip->ptr - lip->tok_start) >= 4 && !ident_map[c])
{
- yylval->lex_str= get_token(lex, yyLength());
- yylval->lex_str.str+= 2; // Skip 0x
- yylval->lex_str.length-= 2;
- lex->yytoklen-= 2;
+ /* Skip '0b' */
+ yylval->lex_str= get_token(lip, 2, yyLength()-2);
return (BIN_NUM);
}
yyUnget();
@@ -778,9 +802,9 @@ int MYSQLlex(void *arg, void *yythd)
if (my_mbcharlen(cs, c) > 1)
{
int l;
- if ((l = my_ismbchar(cs, lex->ptr-1, lex->end_of_query)) == 0)
+ if ((l = my_ismbchar(cs, lip->ptr-1, lip->end_of_query)) == 0)
break;
- lex->ptr += l-1;
+ lip->ptr += l-1;
}
}
}
@@ -792,16 +816,15 @@ int MYSQLlex(void *arg, void *yythd)
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
}
if (c == '.' && ident_map[yyPeek()])
- lex->next_state=MY_LEX_IDENT_SEP;// Next is '.'
+ lip->next_state=MY_LEX_IDENT_SEP;// Next is '.'
- yylval->lex_str= get_token(lex,yyLength());
+ yylval->lex_str= get_token(lip, 0, yyLength());
return(result_state);
case MY_LEX_USER_VARIABLE_DELIMITER: // Found quote char
{
uint double_quotes= 0;
char quote_char= c; // Used char
- lex->tok_start=lex->ptr; // Skip first `
while ((c=yyGet()))
{
int var_length;
@@ -819,23 +842,24 @@ int MYSQLlex(void *arg, void *yythd)
#ifdef USE_MB
else if (var_length < 1)
break; // Error
- lex->ptr+= var_length-1;
+ lip->ptr+= var_length-1;
#endif
}
if (double_quotes)
- yylval->lex_str=get_quoted_token(lex,yyLength() - double_quotes,
+ yylval->lex_str=get_quoted_token(lip, 1,
+ yyLength() - double_quotes -1,
quote_char);
else
- yylval->lex_str=get_token(lex,yyLength());
+ yylval->lex_str=get_token(lip, 1, yyLength() -1);
if (c == quote_char)
yySkip(); // Skip end `
- lex->next_state= MY_LEX_START;
+ lip->next_state= MY_LEX_START;
return(IDENT_QUOTED);
}
- case MY_LEX_INT_OR_REAL: // Compleat int or incompleat real
+ case MY_LEX_INT_OR_REAL: // Complete int or incomplete real
if (c != '.')
{ // Found complete integer number.
- yylval->lex_str=get_token(lex,yyLength());
+ yylval->lex_str=get_token(lip, 0, yyLength());
return int_token(yylval->lex_str.str,yylval->lex_str.length);
}
// fall through
@@ -853,47 +877,45 @@ int MYSQLlex(void *arg, void *yythd)
break;
}
while (my_isdigit(cs,yyGet())) ;
- yylval->lex_str=get_token(lex,yyLength());
+ yylval->lex_str=get_token(lip, 0, yyLength());
return(FLOAT_NUM);
}
- yylval->lex_str=get_token(lex,yyLength());
+ yylval->lex_str=get_token(lip, 0, yyLength());
return(DECIMAL_NUM);
case MY_LEX_HEX_NUMBER: // Found x'hexstring'
yyGet(); // Skip '
while (my_isxdigit(cs,(c = yyGet()))) ;
- length=(lex->ptr - lex->tok_start); // Length of hexnum+3
+ length=(lip->ptr - lip->tok_start); // Length of hexnum+3
if (!(length & 1) || c != '\'')
{
return(ABORT_SYM); // Illegal hex constant
}
yyGet(); // get_token makes an unget
- yylval->lex_str=get_token(lex,length);
- yylval->lex_str.str+=2; // Skip x'
- yylval->lex_str.length-=3; // Don't count x' and last '
- lex->yytoklen-=3;
+ yylval->lex_str=get_token(lip,
+ 2, // skip x'
+ length-3); // don't count x' and last '
return (HEX_NUM);
case MY_LEX_BIN_NUMBER: // Found b'bin-string'
yyGet(); // Skip '
while ((c= yyGet()) == '0' || c == '1');
- length= (lex->ptr - lex->tok_start); // Length of bin-num + 3
+ length= (lip->ptr - lip->tok_start); // Length of bin-num + 3
if (c != '\'')
return(ABORT_SYM); // Illegal hex constant
yyGet(); // get_token makes an unget
- yylval->lex_str= get_token(lex, length);
- yylval->lex_str.str+= 2; // Skip b'
- yylval->lex_str.length-= 3; // Don't count b' and last '
- lex->yytoklen-= 3;
- return (BIN_NUM);
+ yylval->lex_str= get_token(lip,
+ 2, // skip b'
+ length-3); // don't count b' and last '
+ return (BIN_NUM);
case MY_LEX_CMP_OP: // Incomplete comparison operator
if (state_map[yyPeek()] == MY_LEX_CMP_OP ||
state_map[yyPeek()] == MY_LEX_LONG_CMP_OP)
yySkip();
- if ((tokval = find_keyword(lex,(uint) (lex->ptr - lex->tok_start),0)))
+ if ((tokval = find_keyword(lip, (uint) (lip->ptr - lip->tok_start),0)))
{
- lex->next_state= MY_LEX_START; // Allow signed numbers
+ lip->next_state= MY_LEX_START; // Allow signed numbers
return(tokval);
}
state = MY_LEX_CHAR; // Something fishy found
@@ -907,9 +929,9 @@ int MYSQLlex(void *arg, void *yythd)
if (state_map[yyPeek()] == MY_LEX_CMP_OP)
yySkip();
}
- if ((tokval = find_keyword(lex,(uint) (lex->ptr - lex->tok_start),0)))
+ if ((tokval = find_keyword(lip, (uint) (lip->ptr - lip->tok_start),0)))
{
- lex->next_state= MY_LEX_START; // Found long op
+ lip->next_state= MY_LEX_START; // Found long op
return(tokval);
}
state = MY_LEX_CHAR; // Something fishy found
@@ -922,24 +944,24 @@ int MYSQLlex(void *arg, void *yythd)
break;
}
yySkip();
- tokval = find_keyword(lex,2,0); // Is a bool operator
- lex->next_state= MY_LEX_START; // Allow signed numbers
+ tokval = find_keyword(lip,2,0); // Is a bool operator
+ lip->next_state= MY_LEX_START; // Allow signed numbers
return(tokval);
case MY_LEX_STRING_OR_DELIMITER:
- if (((THD *) yythd)->variables.sql_mode & MODE_ANSI_QUOTES)
+ if (thd->variables.sql_mode & MODE_ANSI_QUOTES)
{
state= MY_LEX_USER_VARIABLE_DELIMITER;
break;
}
/* " used for strings */
case MY_LEX_STRING: // Incomplete text string
- if (!(yylval->lex_str.str = get_text(lex)))
+ if (!(yylval->lex_str.str = get_text(lip)))
{
state= MY_LEX_CHAR; // Read char by char
break;
}
- yylval->lex_str.length=lex->yytoklen;
+ yylval->lex_str.length=lip->yytoklen;
return(TEXT_STRING);
case MY_LEX_COMMENT: // Comment
@@ -963,7 +985,7 @@ int MYSQLlex(void *arg, void *yythd)
state=MY_LEX_START;
if (my_isdigit(cs,yyPeek()))
{ // Version number
- version=strtol((char*) lex->ptr,(char**) &lex->ptr,10);
+ version=strtol((char*) lip->ptr,(char**) &lip->ptr,10);
}
if (version <= MYSQL_VERSION_ID)
{
@@ -971,13 +993,13 @@ int MYSQLlex(void *arg, void *yythd)
break;
}
}
- while (lex->ptr != lex->end_of_query &&
+ while (lip->ptr != lip->end_of_query &&
((c=yyGet()) != '*' || yyPeek() != '/'))
{
if (c == '\n')
- lex->yylineno++;
+ lip->yylineno++;
}
- if (lex->ptr != lex->end_of_query)
+ if (lip->ptr != lip->end_of_query)
yySkip(); // remove last '/'
state = MY_LEX_START; // Try again
break;
@@ -1002,14 +1024,13 @@ int MYSQLlex(void *arg, void *yythd)
case MY_LEX_SEMICOLON: // optional line terminator
if (yyPeek())
{
- THD* thd= (THD*)yythd;
if ((thd->client_capabilities & CLIENT_MULTI_STATEMENTS) &&
- !lex->stmt_prepare_mode)
+ !lip->stmt_prepare_mode)
{
lex->safe_to_cache_query= 0;
- lex->found_semicolon=(char*) lex->ptr;
+ lip->found_semicolon= lip->ptr;
thd->server_status|= SERVER_MORE_RESULTS_EXISTS;
- lex->next_state= MY_LEX_END;
+ lip->next_state= MY_LEX_END;
return (END_OF_INPUT);
}
state= MY_LEX_CHAR; // Return ';'
@@ -1017,15 +1038,15 @@ int MYSQLlex(void *arg, void *yythd)
}
/* fall true */
case MY_LEX_EOL:
- if (lex->ptr >= lex->end_of_query)
+ if (lip->ptr >= lip->end_of_query)
{
- lex->next_state=MY_LEX_END; // Mark for next loop
+ lip->next_state=MY_LEX_END; // Mark for next loop
return(END_OF_INPUT);
}
state=MY_LEX_CHAR;
break;
case MY_LEX_END:
- lex->next_state=MY_LEX_END;
+ lip->next_state=MY_LEX_END;
return(0); // We found end of input last time
/* Actually real shouldn't start with . but allow them anyhow */
@@ -1045,26 +1066,26 @@ int MYSQLlex(void *arg, void *yythd)
case MY_LEX_STRING_OR_DELIMITER:
break;
case MY_LEX_USER_END:
- lex->next_state=MY_LEX_SYSTEM_VAR;
+ lip->next_state=MY_LEX_SYSTEM_VAR;
break;
default:
- lex->next_state=MY_LEX_HOSTNAME;
+ lip->next_state=MY_LEX_HOSTNAME;
break;
}
- yylval->lex_str.str=(char*) lex->ptr;
+ yylval->lex_str.str=(char*) lip->ptr;
yylval->lex_str.length=1;
return((int) '@');
case MY_LEX_HOSTNAME: // end '@' of user@hostname
for (c=yyGet() ;
my_isalnum(cs,c) || c == '.' || c == '_' || c == '$';
c= yyGet()) ;
- yylval->lex_str=get_token(lex,yyLength());
+ yylval->lex_str=get_token(lip, 0, yyLength());
return(LEX_HOSTNAME);
case MY_LEX_SYSTEM_VAR:
- yylval->lex_str.str=(char*) lex->ptr;
+ yylval->lex_str.str=(char*) lip->ptr;
yylval->lex_str.length=1;
yySkip(); // Skip '@'
- lex->next_state= (state_map[yyPeek()] ==
+ lip->next_state= (state_map[yyPeek()] ==
MY_LEX_USER_VARIABLE_DELIMITER ?
MY_LEX_OPERATOR_OR_IDENT :
MY_LEX_IDENT_OR_KEYWORD);
@@ -1081,16 +1102,16 @@ int MYSQLlex(void *arg, void *yythd)
result_state= result_state & 0x80 ? IDENT_QUOTED : IDENT;
if (c == '.')
- lex->next_state=MY_LEX_IDENT_SEP;
- length= (uint) (lex->ptr - lex->tok_start)-1;
+ lip->next_state=MY_LEX_IDENT_SEP;
+ length= (uint) (lip->ptr - lip->tok_start)-1;
if (length == 0)
return(ABORT_SYM); // Names must be nonempty.
- if ((tokval= find_keyword(lex,length,0)))
+ if ((tokval= find_keyword(lip, length,0)))
{
yyUnget(); // Put back 'c'
return(tokval); // Was keyword
}
- yylval->lex_str=get_token(lex,length);
+ yylval->lex_str=get_token(lip, 0, length);
return(result_state);
}
}
@@ -1700,6 +1721,17 @@ void st_lex::cleanup_lex_after_parse_error(THD *thd)
void Query_tables_list::reset_query_tables_list(bool init)
{
+ if (!init && query_tables)
+ {
+ TABLE_LIST *table= query_tables;
+ for (;;)
+ {
+ delete table->view;
+ if (query_tables_last == &table->next_global ||
+ !(table= table->next_global))
+ break;
+ }
+ }
query_tables= 0;
query_tables_last= &query_tables;
query_tables_own_last= 0;
@@ -1752,8 +1784,15 @@ void Query_tables_list::destroy_query_tables_list()
st_lex::st_lex()
:result(0), yacc_yyss(0), yacc_yyvs(0),
- sql_command(SQLCOM_END)
+ sql_command(SQLCOM_END), option_type(OPT_DEFAULT)
{
+ /* Check that plugins_static_buffer is declared immediately after plugins */
+ compile_time_assert((&plugins + 1) == (DYNAMIC_ARRAY*)plugins_static_buffer);
+
+ my_init_dynamic_array2(&plugins, sizeof(plugin_ref),
+ plugins_static_buffer,
+ INITIAL_LEX_PLUGIN_LIST_SIZE,
+ INITIAL_LEX_PLUGIN_LIST_SIZE);
reset_query_tables_list(TRUE);
}
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index e8f319a4dbc..f9b1be68ee4 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -543,7 +543,7 @@ public:
void set_thd(THD *thd_arg) { thd= thd_arg; }
inline bool is_union ();
- friend void lex_start(THD *thd, const char *buf, uint length);
+ friend void lex_start(THD *thd);
friend int subselect_union_engine::exec();
List<Item> *get_unit_column_types();
@@ -744,7 +744,7 @@ public:
void cut_subtree() { slave= 0; }
bool test_limit();
- friend void lex_start(THD *thd, const char *buf, uint length);
+ friend void lex_start(THD *thd);
st_select_lex() : n_sum_items(0), n_child_sum_items(0) {}
void make_empty_select()
{
@@ -971,6 +971,12 @@ public:
query_tables_own_last= 0;
}
}
+ /**
+ true if the parsed tree contains references to stored procedures
+ or functions, false otherwise
+ */
+ bool uses_stored_routines() const
+ { return sroutines_list.elements != 0; }
};
@@ -991,23 +997,72 @@ struct st_parsing_options
};
+/**
+ This class represents the character input stream consumed during
+ lexical analysis.
+*/
+class Lex_input_stream
+{
+public:
+ Lex_input_stream(THD *thd, const char* buff, unsigned int length);
+ ~Lex_input_stream();
+
+ /** Current thread. */
+ THD *m_thd;
+
+ /** Current line number. */
+ uint yylineno;
+
+ /** Length of the last token parsed. */
+ uint yytoklen;
+
+ /** Interface with bison, value of the last token parsed. */
+ LEX_YYSTYPE yylval;
+
+ /** Pointer to the current position in the input stream. */
+ const char* ptr;
+
+ /** Starting position of the last token parsed. */
+ const char* tok_start;
+
+ /** Ending position of the last token parsed. */
+ const char* tok_end;
+
+ /** End of the query text in the input stream. */
+ const char* end_of_query;
+
+ /** Starting position of the previous token parsed. */
+ const char* tok_start_prev;
+
+ /** Begining of the query text in the input stream. */
+ const char* buf;
+
+ /** Current state of the lexical analyser. */
+ enum my_lex_states next_state;
+
+ /** Position of ';' in the stream, to delimit multiple queries. */
+ const char* found_semicolon;
+
+ /** SQL_MODE = IGNORE_SPACE. */
+ bool ignore_space;
+ /*
+ TRUE if we're parsing a prepared statement: in this mode
+ we should allow placeholders and disallow multi-statements.
+ */
+ bool stmt_prepare_mode;
+};
+
+
/* The state of the lex parsing. This is saved in the THD struct */
typedef struct st_lex : public Query_tables_list
{
- uint yylineno,yytoklen; /* Simulate lex */
- LEX_YYSTYPE yylval;
SELECT_LEX_UNIT unit; /* most upper unit */
SELECT_LEX select_lex; /* first SELECT_LEX */
/* current SELECT_LEX in parsing */
SELECT_LEX *current_select;
/* list of all SELECT_LEX */
SELECT_LEX *all_selects_list;
- const char *buf; /* The beginning of string, used by SPs */
- const char *ptr,*tok_start,*tok_end,*end_of_query;
-
- /* The value of tok_start as they were one call of MYSQLlex before */
- const char *tok_start_prev;
char *length,*dec,*change;
LEX_STRING name;
@@ -1016,7 +1071,6 @@ typedef struct st_lex : public Query_tables_list
char *backup_dir; /* For RESTORE/BACKUP */
char* to_log; /* For PURGE MASTER LOGS TO */
char* x509_subject,*x509_issuer,*ssl_cipher;
- char* found_semicolon; /* For multi queries - next query */
String *wild;
sql_exchange *exchange;
select_result *result;
@@ -1026,6 +1080,11 @@ typedef struct st_lex : public Query_tables_list
XID *xid;
uchar* yacc_yyss, *yacc_yyvs;
THD *thd;
+
+ /* maintain a list of used plugins for this LEX */
+ DYNAMIC_ARRAY plugins;
+ plugin_ref plugins_static_buffer[INITIAL_LEX_PLUGIN_LIST_SIZE];
+
CHARSET_INFO *charset, *underscore_charset;
/* store original leaf_tables for INSERT SELECT and PS/SP */
TABLE_LIST *leaf_tables_insert;
@@ -1100,7 +1159,6 @@ typedef struct st_lex : public Query_tables_list
thr_lock_type lock_option;
enum SSL_type ssl_type; /* defined in violite.h */
- enum my_lex_states next_state;
enum enum_duplicates duplicates;
enum enum_tx_isolation tx_isolation;
enum enum_ha_read_modes ha_read_mode;
@@ -1132,7 +1190,7 @@ typedef struct st_lex : public Query_tables_list
uint8 create_view_algorithm;
uint8 create_view_check;
bool drop_if_exists, drop_temporary, local_file, one_shot_set;
- bool in_comment, ignore_space, verbose, no_write_to_binlog;
+ bool in_comment, verbose, no_write_to_binlog;
bool tx_chain, tx_release;
/*
Special JOIN::prepare mode: changing of query is prohibited.
@@ -1142,11 +1200,6 @@ typedef struct st_lex : public Query_tables_list
to an .frm file. We need this definition to stay untouched.
*/
bool view_prepare_mode;
- /*
- TRUE if we're parsing a prepared statement: in this mode
- we should allow placeholders and disallow multistatements.
- */
- bool stmt_prepare_mode;
bool safe_to_cache_query;
bool subqueries, ignore;
st_parsing_options parsing_options;
@@ -1209,7 +1262,8 @@ typedef struct st_lex : public Query_tables_list
Pointers to part of LOAD DATA statement that should be rewritten
during replication ("LOCAL 'filename' REPLACE INTO" part).
*/
- const char *fname_start, *fname_end;
+ const char *fname_start;
+ const char *fname_end;
/*
Reference to a struct that contains information in various commands
@@ -1224,6 +1278,8 @@ typedef struct st_lex : public Query_tables_list
virtual ~st_lex()
{
destroy_query_tables_list();
+ plugin_unlock_list(NULL, (plugin_ref *)plugins.buffer, plugins.elements);
+ delete_dynamic(&plugins);
}
inline void uncacheable(uint8 cause)
@@ -1326,7 +1382,7 @@ struct st_lex_local: public st_lex
extern void lex_init(void);
extern void lex_free(void);
-extern void lex_start(THD *thd, const char *buf, uint length);
+extern void lex_start(THD *thd);
extern void lex_end(LEX *lex);
extern int MYSQLlex(void *arg, void *yythd);
extern const char *skip_rear_comments(const char *ubegin, const char *uend);
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index e137481ccef..721a4dc2fc8 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -605,6 +605,8 @@ read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_TOO_FEW_RECORDS,
ER(ER_WARN_TOO_FEW_RECORDS), thd->row_count);
+ if (!field->maybe_null() && field->type() == FIELD_TYPE_TIMESTAMP)
+ ((Field_timestamp*) field)->set_time();
}
else
{
@@ -782,6 +784,8 @@ read_sep_field(THD *thd, COPY_INFO &info, TABLE_LIST *table_list,
thd->row_count);
DBUG_RETURN(1);
}
+ if (!field->maybe_null() && field->type() == FIELD_TYPE_TIMESTAMP)
+ ((Field_timestamp*) field)->set_time();
/*
QQ: We probably should not throw warning for each field.
But how about intention to always have the same number
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index ae297c11e4e..13de5bcd8f5 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -43,37 +43,37 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables);
const char *any_db="*any*"; // Special symbol for check_access
const LEX_STRING command_name[]={
- C_STRING_WITH_LEN("Sleep"),
- C_STRING_WITH_LEN("Quit"),
- C_STRING_WITH_LEN("Init DB"),
- C_STRING_WITH_LEN("Query"),
- C_STRING_WITH_LEN("Field List"),
- C_STRING_WITH_LEN("Create DB"),
- C_STRING_WITH_LEN("Drop DB"),
- C_STRING_WITH_LEN("Refresh"),
- C_STRING_WITH_LEN("Shutdown"),
- C_STRING_WITH_LEN("Statistics"),
- C_STRING_WITH_LEN("Processlist"),
- C_STRING_WITH_LEN("Connect"),
- C_STRING_WITH_LEN("Kill"),
- C_STRING_WITH_LEN("Debug"),
- C_STRING_WITH_LEN("Ping"),
- C_STRING_WITH_LEN("Time"),
- C_STRING_WITH_LEN("Delayed insert"),
- C_STRING_WITH_LEN("Change user"),
- C_STRING_WITH_LEN("Binlog Dump"),
- C_STRING_WITH_LEN("Table Dump"),
- C_STRING_WITH_LEN("Connect Out"),
- C_STRING_WITH_LEN("Register Slave"),
- C_STRING_WITH_LEN("Prepare"),
- C_STRING_WITH_LEN("Execute"),
- C_STRING_WITH_LEN("Long Data"),
- C_STRING_WITH_LEN("Close stmt"),
- C_STRING_WITH_LEN("Reset stmt"),
- C_STRING_WITH_LEN("Set option"),
- C_STRING_WITH_LEN("Fetch"),
- C_STRING_WITH_LEN("Daemon"),
- C_STRING_WITH_LEN("Error") // Last command number
+ { C_STRING_WITH_LEN("Sleep") },
+ { C_STRING_WITH_LEN("Quit") },
+ { C_STRING_WITH_LEN("Init DB") },
+ { C_STRING_WITH_LEN("Query") },
+ { C_STRING_WITH_LEN("Field List") },
+ { C_STRING_WITH_LEN("Create DB") },
+ { C_STRING_WITH_LEN("Drop DB") },
+ { C_STRING_WITH_LEN("Refresh") },
+ { C_STRING_WITH_LEN("Shutdown") },
+ { C_STRING_WITH_LEN("Statistics") },
+ { C_STRING_WITH_LEN("Processlist") },
+ { C_STRING_WITH_LEN("Connect") },
+ { C_STRING_WITH_LEN("Kill") },
+ { C_STRING_WITH_LEN("Debug") },
+ { C_STRING_WITH_LEN("Ping") },
+ { C_STRING_WITH_LEN("Time") },
+ { C_STRING_WITH_LEN("Delayed insert") },
+ { C_STRING_WITH_LEN("Change user") },
+ { C_STRING_WITH_LEN("Binlog Dump") },
+ { C_STRING_WITH_LEN("Table Dump") },
+ { C_STRING_WITH_LEN("Connect Out") },
+ { C_STRING_WITH_LEN("Register Slave") },
+ { C_STRING_WITH_LEN("Prepare") },
+ { C_STRING_WITH_LEN("Execute") },
+ { C_STRING_WITH_LEN("Long Data") },
+ { C_STRING_WITH_LEN("Close stmt") },
+ { C_STRING_WITH_LEN("Reset stmt") },
+ { C_STRING_WITH_LEN("Set option") },
+ { C_STRING_WITH_LEN("Fetch") },
+ { C_STRING_WITH_LEN("Daemon") },
+ { C_STRING_WITH_LEN("Error") } // Last command number
};
const char *xa_state_names[]={
@@ -300,6 +300,7 @@ pthread_handler_t handle_bootstrap(void *arg)
THD *thd=(THD*) arg;
FILE *file=bootstrap_file;
char *buff;
+ const char* found_semicolon= NULL;
/* The following must be called before DBUG_ENTER */
thd->thread_stack= (char*) &thd;
@@ -381,7 +382,7 @@ pthread_handler_t handle_bootstrap(void *arg)
*/
thd->query_id=next_query_id();
thd->set_time();
- mysql_parse(thd,thd->query,length);
+ mysql_parse(thd, thd->query, length, & found_semicolon);
close_thread_tables(thd); // Free tables
if (thd->is_fatal_error)
@@ -895,17 +896,19 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
char *packet_end= thd->query + thd->query_length;
/* 'b' stands for 'buffer' parameter', special for 'my_snprintf' */
const char *format= "%.*b";
+ const char* found_semicolon= NULL;
+
general_log_print(thd, command, format, thd->query_length, thd->query);
DBUG_PRINT("query",("%-.4096s",thd->query));
if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(),QUERY_PRIOR);
- mysql_parse(thd,thd->query, thd->query_length);
+ mysql_parse(thd, thd->query, thd->query_length, & found_semicolon);
- while (!thd->killed && thd->lex->found_semicolon && !thd->net.report_error)
+ while (!thd->killed && found_semicolon && !thd->net.report_error)
{
- char *next_packet= thd->lex->found_semicolon;
+ char *next_packet= (char*) found_semicolon;
net->no_send_error= 0;
/*
Multiple queries exits, execute them individually
@@ -930,7 +933,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
thd->set_time(); /* Reset the query start time. */
/* TODO: set thd->lex->sql_command to SQLCOM_END here */
VOID(pthread_mutex_unlock(&LOCK_thread_count));
- mysql_parse(thd, next_packet, length);
+ mysql_parse(thd, next_packet, length, & found_semicolon);
}
if (!(specialflag & SPECIAL_NO_PRIOR))
@@ -952,7 +955,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
size_t dummy;
/* used as fields initializator */
- lex_start(thd, 0, 0);
+ lex_start(thd);
statistic_increment(thd->status_var.com_stat[SQLCOM_SHOW_FIELDS],
&LOCK_status);
@@ -991,7 +994,10 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
break;
/* init structures for VIEW processing */
table_list.select_lex= &(thd->lex->select_lex);
- mysql_init_query(thd, "", 0);
+
+ lex_start(thd);
+ mysql_reset_thd_for_next_command(thd);
+
thd->lex->
select_lex.table_list.link_in_list((uchar*) &table_list,
(uchar**) &table_list.next_local);
@@ -2159,7 +2165,13 @@ mysql_execute_command(THD *thd)
select_lex->options|= SELECT_NO_UNLOCK;
unit->set_limit(select_lex);
- if (!(res= open_and_lock_tables(thd, select_tables)))
+ if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE))
+ {
+ lex->link_first_table_back(create_table, link_to_local);
+ create_table->create= TRUE;
+ }
+
+ if (!(res= open_and_lock_tables(thd, lex->query_tables)))
{
/*
Is table which we are changing used somewhere in other parts
@@ -2168,6 +2180,7 @@ mysql_execute_command(THD *thd)
if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE))
{
TABLE_LIST *duplicate;
+ create_table= lex->unlink_first_table(&link_to_local);
if ((duplicate= unique_table(thd, create_table, select_tables, 0)))
{
update_non_unique_table_error(create_table, "CREATE", duplicate);
@@ -2193,6 +2206,12 @@ mysql_execute_command(THD *thd)
}
}
+ /*
+ FIXME Temporary hack which will go away once Kostja pushes
+ his uber-fix for ALTER/CREATE TABLE.
+ */
+ lex->create_info.table_existed= 0;
+
if ((result= new select_create(create_table,
&lex->create_info,
lex->create_list,
@@ -2212,6 +2231,9 @@ mysql_execute_command(THD *thd)
lex->create_list.empty();
lex->key_list.empty();
}
+ else if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE))
+ create_table= lex->unlink_first_table(&link_to_local);
+
}
else
{
@@ -4571,7 +4593,8 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv,
if (schema_db)
{
- if (want_access & ~(SELECT_ACL | EXTRA_ACL))
+ if (!(sctx->master_access & FILE_ACL) && (want_access & FILE_ACL) ||
+ (want_access & ~(SELECT_ACL | EXTRA_ACL | FILE_ACL)))
{
if (!no_errors)
{
@@ -5044,20 +5067,6 @@ bool my_yyoverflow(short **yyss, YYSTYPE **yyvs, ulong *yystacksize)
}
-/****************************************************************************
- Initialize global thd variables needed for query
-****************************************************************************/
-
-void
-mysql_init_query(THD *thd, const char *buf, uint length)
-{
- DBUG_ENTER("mysql_init_query");
- lex_start(thd, buf, length);
- mysql_reset_thd_for_next_command(thd);
- DBUG_VOID_RETURN;
-}
-
-
/*
Reset THD part responsible for command processing state.
@@ -5269,22 +5278,55 @@ void mysql_init_multi_delete(LEX *lex)
mysql_test_parse_for_slave() in this same file.
*/
-void mysql_parse(THD *thd, char *inBuf, uint length)
+/**
+ Parse a query.
+ @param thd Current thread
+ @param inBuf Begining of the query text
+ @param length Length of the query text
+ @param [out] semicolon For multi queries, position of the character of
+ the next query in the query text.
+*/
+
+void mysql_parse(THD *thd, const char *inBuf, uint length,
+ const char ** found_semicolon)
{
DBUG_ENTER("mysql_parse");
DBUG_EXECUTE_IF("parser_debug", turn_parser_debug_on(););
- mysql_init_query(thd, inBuf, length);
+ /*
+ Warning.
+ The purpose of query_cache_send_result_to_client() is to lookup the
+ query in the query cache first, to avoid parsing and executing it.
+ So, the natural implementation would be to:
+ - first, call query_cache_send_result_to_client,
+ - second, if caching failed, initialise the lexical and syntactic parser.
+ The problem is that the query cache depends on a clean initialization
+ of (among others) lex->safe_to_cache_query and thd->server_status,
+ which are reset respectively in
+ - lex_start()
+ - mysql_reset_thd_for_next_command()
+ So, initializing the lexical analyser *before* using the query cache
+ is required for the cache to work properly.
+ FIXME: cleanup the dependencies in the code to simplify this.
+ */
+ lex_start(thd);
+ mysql_reset_thd_for_next_command(thd);
- if (query_cache_send_result_to_client(thd, inBuf, length) <= 0)
+ if (query_cache_send_result_to_client(thd, (char*) inBuf, length) <= 0)
{
LEX *lex= thd->lex;
-
+
sp_cache_flush_obsolete(&thd->sp_proc_cache);
sp_cache_flush_obsolete(&thd->sp_func_cache);
-
- if (!MYSQLparse((void *)thd) && ! thd->is_fatal_error)
+
+ Lex_input_stream lip(thd, inBuf, length);
+ thd->m_lip= &lip;
+
+ int err= MYSQLparse(thd);
+ *found_semicolon= lip.found_semicolon;
+
+ if (!err && ! thd->is_fatal_error)
{
#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (mqh_used && thd->user_connect &&
@@ -5307,8 +5349,8 @@ void mysql_parse(THD *thd, char *inBuf, uint length)
PROCESSLIST.
Note that we don't need LOCK_thread_count to modify query_length.
*/
- if (lex->found_semicolon &&
- (thd->query_length= (ulong)(lex->found_semicolon - thd->query)))
+ if (lip.found_semicolon &&
+ (thd->query_length= (ulong)(lip.found_semicolon - thd->query)))
thd->query_length--;
/* Actually execute the query */
mysql_execute_command(thd);
@@ -5335,6 +5377,12 @@ void mysql_parse(THD *thd, char *inBuf, uint length)
thd->cleanup_after_query();
DBUG_ASSERT(thd->change_list.is_empty());
}
+ else
+ {
+ /* There are no multi queries in the cache. */
+ *found_semicolon= NULL;
+ }
+
DBUG_VOID_RETURN;
}
@@ -5355,8 +5403,13 @@ bool mysql_test_parse_for_slave(THD *thd, char *inBuf, uint length)
bool error= 0;
DBUG_ENTER("mysql_test_parse_for_slave");
- mysql_init_query(thd, inBuf, length);
- if (!MYSQLparse((void*) thd) && ! thd->is_fatal_error &&
+ Lex_input_stream lip(thd, inBuf, length);
+ thd->m_lip= &lip;
+ lex_start(thd);
+ mysql_reset_thd_for_next_command(thd);
+ int err= MYSQLparse((void*) thd);
+
+ if (!err && ! thd->is_fatal_error &&
all_tables_not_ok(thd,(TABLE_LIST*) lex->select_lex.table_list.first))
error= 1; /* Ignore question */
thd->end_statement();
@@ -6407,8 +6460,9 @@ bool check_simple_select()
if (lex->current_select != &lex->select_lex)
{
char command[80];
- strmake(command, lex->yylval->symbol.str,
- min(lex->yylval->symbol.length, sizeof(command)-1));
+ Lex_input_stream *lip= thd->m_lip;
+ strmake(command, lip->yylval->symbol.str,
+ min(lip->yylval->symbol.length, sizeof(command)-1));
my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command);
return 1;
}
diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
index 149db3e6adf..2c5fe91681e 100644
--- a/sql/sql_partition.cc
+++ b/sql/sql_partition.cc
@@ -784,9 +784,9 @@ static bool handle_list_of_fields(List_iterator<char> it,
}
else
{
- if (table->s->db_type->partition_flags &&
- (table->s->db_type->partition_flags() & HA_USE_AUTO_PARTITION) &&
- (table->s->db_type->partition_flags() & HA_CAN_PARTITION))
+ if (table->s->db_type()->partition_flags &&
+ (table->s->db_type()->partition_flags() & HA_USE_AUTO_PARTITION) &&
+ (table->s->db_type()->partition_flags() & HA_CAN_PARTITION))
{
/*
This engine can handle automatic partitioning and there is no
@@ -1664,8 +1664,8 @@ bool fix_partition_func(THD *thd, TABLE *table,
goto end;
if (unlikely(check_primary_key(table)))
goto end;
- if (unlikely((!(table->s->db_type->partition_flags &&
- (table->s->db_type->partition_flags() & HA_CAN_PARTITION_UNIQUE))) &&
+ if (unlikely((!(table->s->db_type()->partition_flags &&
+ (table->s->db_type()->partition_flags() & HA_CAN_PARTITION_UNIQUE))) &&
check_unique_keys(table)))
goto end;
if (unlikely(set_up_partition_bitmap(thd, part_info)))
@@ -1872,7 +1872,7 @@ static int add_keyword_int(File fptr, const char *keyword, longlong num)
static int add_engine(File fptr, handlerton *engine_type)
{
- const char *engine_str= hton2plugin[engine_type->slot]->name.str;
+ const char *engine_str= ha_resolve_storage_engine_name(engine_type);
DBUG_PRINT("info", ("ENGINE: %s", engine_str));
int err= add_string(fptr, "ENGINE = ");
return err + add_string(fptr, engine_str);
@@ -2188,8 +2188,8 @@ bool partition_key_modified(TABLE *table, const MY_BITMAP *fields)
if (!part_info)
DBUG_RETURN(FALSE);
- if (table->s->db_type->partition_flags &&
- (table->s->db_type->partition_flags() & HA_CAN_UPDATE_PARTITION_KEY))
+ if (table->s->db_type()->partition_flags &&
+ (table->s->db_type()->partition_flags() & HA_CAN_UPDATE_PARTITION_KEY))
DBUG_RETURN(FALSE);
for (fld= part_info->full_part_field_array; *fld; fld++)
if (bitmap_is_set(fields, (*fld)->field_index))
@@ -3718,7 +3718,11 @@ bool mysql_unpack_partition(THD *thd,
thd->lex= &lex;
thd->variables.character_set_client= system_charset_info;
- lex_start(thd, part_buf, part_info_len);
+
+ Lex_input_stream lip(thd, part_buf, part_info_len);
+ thd->m_lip= &lip;
+
+ lex_start(thd);
/*
We need to use the current SELECT_LEX since I need to keep the
Name_resolution_context object which is referenced from the
@@ -4204,8 +4208,8 @@ uint prep_alter_part_table(THD *thd, TABLE *table, ALTER_INFO *alter_info,
alter_info->no_parts= curr_part_no - new_part_no;
}
}
- if (table->s->db_type->alter_table_flags &&
- (!(flags= table->s->db_type->alter_table_flags(alter_info->flags))))
+ if (table->s->db_type()->alter_table_flags &&
+ (!(flags= table->s->db_type()->alter_table_flags(alter_info->flags))))
{
my_error(ER_PARTITION_FUNCTION_FAILURE, MYF(0));
DBUG_RETURN(1);
@@ -4951,7 +4955,7 @@ the generated partition syntax in a correct manner.
create_info->db_type= table->part_info->default_engine_type;
}
DBUG_PRINT("info", ("New engine type: %s",
- hton2plugin[create_info->db_type->slot]->name.str));
+ ha_resolve_storage_engine_name(create_info->db_type)));
thd->work_part_info= NULL;
*partition_changed= TRUE;
}
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index 0344ce2fbb0..3d65830eddf 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -15,15 +15,25 @@
#include "mysql_priv.h"
#include <my_pthread.h>
+#include <my_getopt.h>
#define REPORT_TO_LOG 1
#define REPORT_TO_USER 2
+#ifdef DBUG_OFF
+#define plugin_ref_to_int(A) A
+#define plugin_int_to_ref(A) A
+#else
+#define plugin_ref_to_int(A) (A ? A[0] : NULL)
+#define plugin_int_to_ref(A) &(A)
+#endif
+
extern struct st_mysql_plugin *mysqld_builtins[];
+char *opt_plugin_load= NULL;
char *opt_plugin_dir_ptr;
char opt_plugin_dir[FN_REFLEN];
/*
- When you ad a new plugin type, add both a string and make sure that the
+ When you ad a new plugin type, add both a string and make sure that the
init and deinit array are correctly updated.
*/
const LEX_STRING plugin_type_names[MYSQL_MAX_PLUGIN_TYPE_NUM]=
@@ -39,10 +49,10 @@ extern int initialize_schema_table(st_plugin_int *plugin);
extern int finalize_schema_table(st_plugin_int *plugin);
/*
- The number of elements in both plugin_type_initialize and
+ The number of elements in both plugin_type_initialize and
plugin_type_deinitialize should equal to the number of plugins
defined.
-*/
+*/
plugin_type_init plugin_type_initialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
{
0,ha_initialize_handlerton,0,0,initialize_schema_table
@@ -82,28 +92,193 @@ static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION
};
+static bool initialized= 0;
+
+/*
+ A mutex LOCK_plugin must be acquired before accessing the
+ following variables/structures.
+ We are always manipulating ref count, so a rwlock here is unneccessary.
+*/
+pthread_mutex_t LOCK_plugin;
static DYNAMIC_ARRAY plugin_dl_array;
static DYNAMIC_ARRAY plugin_array;
static HASH plugin_hash[MYSQL_MAX_PLUGIN_TYPE_NUM];
-static rw_lock_t THR_LOCK_plugin;
-static bool initialized= 0;
-
+static bool reap_needed= false;
static int plugin_array_version=0;
+/*
+ write-lock on LOCK_system_variables_hash is required before modifying
+ the following variables/structures
+*/
+static MEM_ROOT plugin_mem_root;
+static uint global_variables_dynamic_size= 0;
+static HASH bookmark_hash;
+
+
+/*
+ hidden part of opaque value passed to variable check functions.
+ Used to provide a object-like structure to non C++ consumers.
+*/
+struct st_item_value_holder : public st_mysql_value
+{
+ Item *item;
+};
+
+
+/*
+ stored in bookmark_hash, this structure is never removed from the
+ hash and is used to mark a single offset for a thd local variable
+ even if plugins have been uninstalled and reinstalled, repeatedly.
+ This structure is allocated from plugin_mem_root.
+
+ The key format is as follows:
+ 1 byte - variable type code
+ name_len bytes - variable name
+ '\0' - end of key
+*/
+struct st_bookmark
+{
+ uint name_len;
+ int offset;
+ uint version;
+ char key[1];
+};
+
+
+/*
+ skeleton of a plugin variable - portion of structure common to all.
+*/
+struct st_mysql_sys_var
+{
+ MYSQL_PLUGIN_VAR_HEADER;
+};
+
+
+/*
+ sys_var class for access to all plugin variables visible to the user
+*/
+class sys_var_pluginvar: public sys_var
+{
+public:
+ struct st_plugin_int *plugin;
+ struct st_mysql_sys_var *plugin_var;
+
+ static void *operator new(size_t size, MEM_ROOT *mem_root)
+ { return (void*) alloc_root(mem_root, (uint) size); }
+ static void operator delete(void *ptr_arg,size_t size)
+ { TRASH(ptr_arg, size); }
+
+ sys_var_pluginvar(const char *name_arg,
+ struct st_mysql_sys_var *plugin_var_arg)
+ :sys_var(name_arg), plugin_var(plugin_var_arg) {}
+ sys_var_pluginvar *cast_pluginvar() { return this; }
+ bool is_readonly() const { return plugin_var->flags & PLUGIN_VAR_READONLY; }
+ bool check_type(enum_var_type type)
+ { return !(plugin_var->flags & PLUGIN_VAR_THDLOCAL) && type != OPT_GLOBAL; }
+ bool check_update_type(Item_result type);
+ SHOW_TYPE show_type();
+ byte* real_value_ptr(THD *thd, enum_var_type type);
+ TYPELIB* plugin_var_typelib(void);
+ byte* value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
+ bool check(THD *thd, set_var *var);
+ void set_default(THD *thd, enum_var_type type);
+ bool update(THD *thd, set_var *var);
+};
+
+
/* prototypes */
-my_bool plugin_register_builtin(struct st_mysql_plugin *plugin);
-void plugin_load(void);
+static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv);
+static bool plugin_load_list(MEM_ROOT *tmp_root, int *argc, char **argv,
+ const char *list);
+static int test_plugin_options(MEM_ROOT *, struct st_plugin_int *,
+ int *, char **, my_bool);
+static bool register_builtin(struct st_mysql_plugin *, struct st_plugin_int *,
+ struct st_plugin_int **);
+static void unlock_variables(THD *thd, struct system_variables *vars);
+static void cleanup_variables(THD *thd, struct system_variables *vars);
+static void plugin_vars_free_values(sys_var *vars);
+static void plugin_opt_set_limits(struct my_option *options,
+ const struct st_mysql_sys_var *opt);
+#define my_intern_plugin_lock(A,B) intern_plugin_lock(A,B CALLER_INFO)
+#define my_intern_plugin_lock_ci(A,B) intern_plugin_lock(A,B ORIG_CALLER_INFO)
+static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref plugin
+ CALLER_INFO_PROTO);
+static void intern_plugin_unlock(LEX *lex, plugin_ref plugin);
+static void reap_plugins(void);
+
+
+/* declared in set_var.cc */
+extern sys_var *intern_find_sys_var(const char *str, uint length, bool no_error);
+
+
+/****************************************************************************
+ Value type thunks, allows the C world to play in the C++ world
+****************************************************************************/
+
+static int item_value_type(struct st_mysql_value *value)
+{
+ switch (((st_item_value_holder*)value)->item->result_type()) {
+ case INT_RESULT:
+ return MYSQL_VALUE_TYPE_INT;
+ case REAL_RESULT:
+ return MYSQL_VALUE_TYPE_REAL;
+ default:
+ return MYSQL_VALUE_TYPE_STRING;
+ }
+}
+
+static const char *item_val_str(struct st_mysql_value *value,
+ char *buffer, int *length)
+{
+ String str(buffer, *length, system_charset_info), *res;
+ if (!(res= ((st_item_value_holder*)value)->item->val_str(&str)))
+ return NULL;
+ *length= res->length();
+ if (res->c_ptr_quick() == buffer)
+ return buffer;
+
+ /*
+ Lets be nice and create a temporary string since the
+ buffer was too small
+ */
+ return current_thd->strmake(res->c_ptr_quick(), res->length());
+}
+
+
+static int item_val_int(struct st_mysql_value *value, long long *buf)
+{
+ Item *item= ((st_item_value_holder*)value)->item;
+ *buf= item->val_int();
+ if (item->is_null())
+ return 1;
+ return 0;
+}
+
+
+static int item_val_real(struct st_mysql_value *value, double *buf)
+{
+ Item *item= ((st_item_value_holder*)value)->item;
+ *buf= item->val_real();
+ if (item->is_null())
+ return 1;
+ return 0;
+}
+
+
+/****************************************************************************
+ Plugin support code
+****************************************************************************/
#ifdef HAVE_DLOPEN
static struct st_plugin_dl *plugin_dl_find(const LEX_STRING *dl)
{
uint i;
+ struct st_plugin_dl *tmp;
DBUG_ENTER("plugin_dl_find");
for (i= 0; i < plugin_dl_array.elements; i++)
{
- struct st_plugin_dl *tmp= dynamic_element(&plugin_dl_array, i,
- struct st_plugin_dl *);
+ tmp= dynamic_element(&plugin_dl_array, i, struct st_plugin_dl *);
if (tmp->ref_count &&
! my_strnncoll(files_charset_info,
(const uchar *)dl->str, dl->length,
@@ -117,11 +292,11 @@ static struct st_plugin_dl *plugin_dl_find(const LEX_STRING *dl)
static st_plugin_dl *plugin_dl_insert_or_reuse(struct st_plugin_dl *plugin_dl)
{
uint i;
+ struct st_plugin_dl *tmp;
DBUG_ENTER("plugin_dl_insert_or_reuse");
for (i= 0; i < plugin_dl_array.elements; i++)
{
- struct st_plugin_dl *tmp= dynamic_element(&plugin_dl_array, i,
- struct st_plugin_dl *);
+ tmp= dynamic_element(&plugin_dl_array, i, struct st_plugin_dl *);
if (! tmp->ref_count)
{
memcpy(tmp, plugin_dl, sizeof(struct st_plugin_dl));
@@ -147,6 +322,7 @@ static inline void free_plugin_mem(struct st_plugin_dl *p)
my_free((uchar*)p->plugins, MYF(MY_ALLOW_ZERO_PTR));
}
+
static st_plugin_dl *plugin_dl_add(const LEX_STRING *dl, int report)
{
#ifdef HAVE_DLOPEN
@@ -335,6 +511,9 @@ static void plugin_dl_del(const LEX_STRING *dl)
#ifdef HAVE_DLOPEN
uint i;
DBUG_ENTER("plugin_dl_del");
+
+ safe_mutex_assert_owner(&LOCK_plugin);
+
for (i= 0; i < plugin_dl_array.elements; i++)
{
struct st_plugin_dl *tmp= dynamic_element(&plugin_dl_array, i,
@@ -364,6 +543,9 @@ static struct st_plugin_int *plugin_find_internal(const LEX_STRING *name, int ty
DBUG_ENTER("plugin_find_internal");
if (! initialized)
DBUG_RETURN(0);
+
+ safe_mutex_assert_owner(&LOCK_plugin);
+
if (type == MYSQL_ANY_PLUGIN)
{
for (i= 0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++)
@@ -381,33 +563,101 @@ static struct st_plugin_int *plugin_find_internal(const LEX_STRING *name, int ty
}
-my_bool plugin_is_ready(const LEX_STRING *name, int type)
+static SHOW_COMP_OPTION plugin_status(const LEX_STRING *name, int type)
{
- my_bool rc= FALSE;
+ SHOW_COMP_OPTION rc= SHOW_OPTION_NO;
struct st_plugin_int *plugin;
DBUG_ENTER("plugin_is_ready");
- rw_rdlock(&THR_LOCK_plugin);
- if ((plugin= plugin_find_internal(name, type)) &&
- plugin->state == PLUGIN_IS_READY)
- rc= TRUE;
- rw_unlock(&THR_LOCK_plugin);
+ pthread_mutex_lock(&LOCK_plugin);
+ if ((plugin= plugin_find_internal(name, type)))
+ {
+ rc= SHOW_OPTION_DISABLED;
+ if (plugin->state == PLUGIN_IS_READY)
+ rc= SHOW_OPTION_YES;
+ }
+ pthread_mutex_unlock(&LOCK_plugin);
DBUG_RETURN(rc);
}
-struct st_plugin_int *plugin_lock(const LEX_STRING *name, int type)
+bool plugin_is_ready(const LEX_STRING *name, int type)
{
- struct st_plugin_int *rc;
- DBUG_ENTER("plugin_lock");
- rw_wrlock(&THR_LOCK_plugin);
- if ((rc= plugin_find_internal(name, type)))
+ bool rc= FALSE;
+ if (plugin_status(name, type) == SHOW_OPTION_YES)
+ rc= TRUE;
+ return rc;
+}
+
+
+SHOW_COMP_OPTION sys_var_have_plugin::get_option()
+{
+ LEX_STRING plugin_name= { (char *) plugin_name_str, plugin_name_len };
+ return plugin_status(&plugin_name, plugin_type);
+}
+
+
+static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref rc CALLER_INFO_PROTO)
+{
+ st_plugin_int *pi= plugin_ref_to_int(rc);
+ DBUG_ENTER("intern_plugin_lock");
+
+ safe_mutex_assert_owner(&LOCK_plugin);
+
+ if (pi->state & (PLUGIN_IS_READY | PLUGIN_IS_UNINITIALIZED))
{
- if (rc->state & (PLUGIN_IS_READY | PLUGIN_IS_UNINITIALIZED))
- rc->ref_count++;
- else
- rc= 0;
+ plugin_ref plugin;
+#ifdef DBUG_OFF
+ /* built-in plugins don't need ref counting */
+ if (!pi->plugin_dl)
+ DBUG_RETURN(pi);
+
+ plugin= pi;
+#else
+ /*
+ For debugging, we do an additional malloc which allows the
+ memory manager and/or valgrind to track locked references and
+ double unlocks to aid resolving reference counting.problems.
+ */
+ if (!(plugin= (plugin_ref) my_malloc_ci(sizeof(pi), MYF(MY_WME))))
+ DBUG_RETURN(NULL);
+
+ *plugin= pi;
+#endif
+ pi->ref_count++;
+ DBUG_PRINT("info",("thd: 0x%lx, plugin: \"%s\", ref_count: %d",
+ (long) current_thd, pi->name.str, pi->ref_count));
+
+ if (lex)
+ insert_dynamic(&lex->plugins, (gptr)&plugin);
+ DBUG_RETURN(plugin);
}
- rw_unlock(&THR_LOCK_plugin);
+ DBUG_RETURN(NULL);
+}
+
+
+plugin_ref plugin_lock(THD *thd, plugin_ref *ptr CALLER_INFO_PROTO)
+{
+ LEX *lex= thd ? thd->lex : 0;
+ plugin_ref rc;
+ DBUG_ENTER("plugin_lock");
+ pthread_mutex_lock(&LOCK_plugin);
+ rc= my_intern_plugin_lock_ci(lex, *ptr);
+ pthread_mutex_unlock(&LOCK_plugin);
+ DBUG_RETURN(rc);
+}
+
+
+plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name, int type
+ CALLER_INFO_PROTO)
+{
+ LEX *lex= thd ? thd->lex : 0;
+ plugin_ref rc= NULL;
+ st_plugin_int *plugin;
+ DBUG_ENTER("plugin_lock_by_name");
+ pthread_mutex_lock(&LOCK_plugin);
+ if ((plugin= plugin_find_internal(name, type)))
+ rc= my_intern_plugin_lock_ci(lex, plugin_int_to_ref(plugin));
+ pthread_mutex_unlock(&LOCK_plugin);
DBUG_RETURN(rc);
}
@@ -432,7 +682,14 @@ static st_plugin_int *plugin_insert_or_reuse(struct st_plugin_int *plugin)
struct st_plugin_int *));
}
-static my_bool plugin_add(const LEX_STRING *name, const LEX_STRING *dl, int report)
+
+/*
+ NOTE
+ Requires that a write-lock is held on LOCK_system_variables_hash
+*/
+static bool plugin_add(MEM_ROOT *tmp_root,
+ const LEX_STRING *name, const LEX_STRING *dl,
+ int *argc, char **argv, int report)
{
struct st_plugin_int tmp;
struct st_mysql_plugin *plugin;
@@ -445,6 +702,8 @@ static my_bool plugin_add(const LEX_STRING *name, const LEX_STRING *dl, int repo
sql_print_error(ER(ER_UDF_EXISTS), name->str);
DBUG_RETURN(TRUE);
}
+ /* Clear the whole struct to catch future extensions. */
+ bzero((char*) &tmp, sizeof(tmp));
if (! (tmp.plugin_dl= plugin_dl_add(dl, report)))
DBUG_RETURN(TRUE);
/* Find plugin by name */
@@ -478,14 +737,23 @@ static my_bool plugin_add(const LEX_STRING *name, const LEX_STRING *dl, int repo
tmp.name.length= name_len;
tmp.ref_count= 0;
tmp.state= PLUGIN_IS_UNINITIALIZED;
- if (! (tmp_plugin_ptr= plugin_insert_or_reuse(&tmp)))
- goto err;
- plugin_array_version++;
- if (my_hash_insert(&plugin_hash[plugin->type], (uchar*)tmp_plugin_ptr))
+ if (!test_plugin_options(tmp_root, &tmp, argc, argv, true))
{
- tmp_plugin_ptr->state= PLUGIN_IS_FREED;
+ if ((tmp_plugin_ptr= plugin_insert_or_reuse(&tmp)))
+ {
+ plugin_array_version++;
+ if (!my_hash_insert(&plugin_hash[plugin->type], (uchar*)tmp_plugin_ptr))
+ {
+ init_alloc_root(&tmp_plugin_ptr->mem_root, 4096, 4096);
+ DBUG_RETURN(FALSE);
+ }
+ tmp_plugin_ptr->state= PLUGIN_IS_FREED;
+ }
+ mysql_del_sys_var_chain(tmp.system_vars);
goto err;
}
+ /* plugin was disabled */
+ plugin_dl_del(dl);
DBUG_RETURN(FALSE);
}
}
@@ -499,8 +767,14 @@ err:
}
-void plugin_deinitialize(struct st_plugin_int *plugin)
+static void plugin_deinitialize(struct st_plugin_int *plugin, bool ref_check)
{
+ /*
+ we don't want to hold the LOCK_plugin mutex as it may cause
+ deinitialization to deadlock if plugins have worker threads
+ with plugin locks
+ */
+ safe_mutex_assert_not_owner(&LOCK_plugin);
if (plugin->plugin->status_vars)
{
@@ -528,7 +802,7 @@ void plugin_deinitialize(struct st_plugin_int *plugin)
{
sql_print_error("Plugin '%s' of type %s failed deinitialization",
plugin->name.str, plugin_type_names[plugin->plugin->type].str);
- }
+ }
}
else if (plugin->plugin->deinit)
{
@@ -540,16 +814,32 @@ void plugin_deinitialize(struct st_plugin_int *plugin)
}
}
plugin->state= PLUGIN_IS_UNINITIALIZED;
+
+ /*
+ We do the check here because NDB has a worker THD which doesn't
+ exit until NDB is shut down.
+ */
+ if (ref_check && plugin->ref_count)
+ sql_print_error("Plugin '%s' has ref_count=%d after deinitialization.",
+ plugin->name.str, plugin->ref_count);
}
static void plugin_del(struct st_plugin_int *plugin)
{
DBUG_ENTER("plugin_del(plugin)");
+ safe_mutex_assert_owner(&LOCK_plugin);
+ /* Free allocated strings before deleting the plugin. */
+ plugin_vars_free_values(plugin->system_vars);
hash_delete(&plugin_hash[plugin->plugin->type], (uchar*)plugin);
- plugin_dl_del(&plugin->plugin_dl->dl);
+ if (plugin->plugin_dl)
+ plugin_dl_del(&plugin->plugin_dl->dl);
plugin->state= PLUGIN_IS_FREED;
plugin_array_version++;
+ rw_wrlock(&LOCK_system_variables_hash);
+ mysql_del_sys_var_chain(plugin->system_vars);
+ rw_unlock(&LOCK_system_variables_hash);
+ free_root(&plugin->mem_root, MYF(0));
DBUG_VOID_RETURN;
}
@@ -566,18 +856,123 @@ static void plugin_del(const LEX_STRING *name)
#endif
-void plugin_unlock(struct st_plugin_int *plugin)
+static void reap_plugins(void)
{
- DBUG_ENTER("plugin_unlock");
- rw_wrlock(&THR_LOCK_plugin);
- DBUG_ASSERT(plugin && plugin->ref_count);
- plugin->ref_count--;
- if (plugin->state == PLUGIN_IS_DELETED && ! plugin->ref_count)
+ uint count, idx;
+ struct st_plugin_int *plugin, **reap, **list;
+
+ safe_mutex_assert_owner(&LOCK_plugin);
+
+ if (!reap_needed)
+ return;
+
+ reap_needed= false;
+ count= plugin_array.elements;
+ reap= (struct st_plugin_int **)my_alloca(sizeof(plugin)*(count+1));
+ *(reap++)= NULL;
+
+ for (idx= 0; idx < count; idx++)
{
- plugin_deinitialize(plugin);
+ plugin= dynamic_element(&plugin_array, idx, struct st_plugin_int *);
+ if (plugin->state == PLUGIN_IS_DELETED && !plugin->ref_count)
+ {
+ /* change the status flag to prevent reaping by another thread */
+ plugin->state= PLUGIN_IS_DYING;
+ *(reap++)= plugin;
+ }
+ }
+
+ pthread_mutex_unlock(&LOCK_plugin);
+
+ list= reap;
+ while ((plugin= *(--list)))
+ plugin_deinitialize(plugin, true);
+
+ pthread_mutex_lock(&LOCK_plugin);
+
+ while ((plugin= *(--reap)))
plugin_del(plugin);
+
+ my_afree(reap);
+}
+
+static void intern_plugin_unlock(LEX *lex, plugin_ref plugin)
+{
+ int i;
+ st_plugin_int *pi;
+ DBUG_ENTER("intern_plugin_unlock");
+
+ safe_mutex_assert_owner(&LOCK_plugin);
+
+ if (!plugin)
+ DBUG_VOID_RETURN;
+
+ pi= plugin_ref_to_int(plugin);
+
+#ifdef DBUG_OFF
+ if (!pi->plugin_dl)
+ DBUG_VOID_RETURN;
+#else
+ my_free((gptr) plugin, MYF(MY_WME));
+#endif
+
+ DBUG_PRINT("info",("unlocking plugin, name= %s, ref_count= %d",
+ pi->name.str, pi->ref_count));
+ if (lex)
+ {
+ /*
+ Remove one instance of this plugin from the use list.
+ We are searching backwards so that plugins locked last
+ could be unlocked faster - optimizing for LIFO semantics.
+ */
+ for (i= lex->plugins.elements - 1; i >= 0; i--)
+ if (plugin == *dynamic_element(&lex->plugins, i, plugin_ref*))
+ {
+ delete_dynamic_element(&lex->plugins, i);
+ break;
+ }
+ DBUG_ASSERT(i >= 0);
}
- rw_unlock(&THR_LOCK_plugin);
+
+ DBUG_ASSERT(pi->ref_count);
+ pi->ref_count--;
+
+ if (pi->state == PLUGIN_IS_DELETED && !pi->ref_count)
+ reap_needed= true;
+
+ DBUG_VOID_RETURN;
+}
+
+
+void plugin_unlock(THD *thd, plugin_ref plugin)
+{
+ LEX *lex= thd ? thd->lex : 0;
+ DBUG_ENTER("plugin_unlock");
+ if (!plugin)
+ DBUG_VOID_RETURN;
+#ifdef DBUG_OFF
+ /* built-in plugins don't need ref counting */
+ if (!plugin_dlib(plugin))
+ DBUG_VOID_RETURN;
+#endif
+ pthread_mutex_lock(&LOCK_plugin);
+ intern_plugin_unlock(lex, plugin);
+ reap_plugins();
+ pthread_mutex_unlock(&LOCK_plugin);
+ DBUG_VOID_RETURN;
+}
+
+
+void plugin_unlock_list(THD *thd, plugin_ref *list, uint count)
+{
+ LEX *lex= thd ? thd->lex : 0;
+ DBUG_ENTER("plugin_unlock_list");
+ DBUG_ASSERT(list);
+ pthread_mutex_lock(&LOCK_plugin);
+ while (count--)
+ intern_plugin_unlock(lex, *list++);
+ reap_plugins();
+ pthread_mutex_unlock(&LOCK_plugin);
DBUG_VOID_RETURN;
}
@@ -586,6 +981,8 @@ static int plugin_initialize(struct st_plugin_int *plugin)
{
DBUG_ENTER("plugin_initialize");
+ safe_mutex_assert_owner(&LOCK_plugin);
+
if (plugin_type_initialize[plugin->plugin->type])
{
if ((*plugin_type_initialize[plugin->plugin->type])(plugin))
@@ -628,11 +1025,28 @@ static int plugin_initialize(struct st_plugin_int *plugin)
#endif /* FIX_LATER */
}
+ /*
+ set the plugin attribute of plugin's sys vars so they are pointing
+ to the active plugin
+ */
+ if (plugin->system_vars)
+ {
+ sys_var_pluginvar *var= plugin->system_vars->cast_pluginvar();
+ for (;;)
+ {
+ var->plugin= plugin;
+ if (!var->next)
+ break;
+ var= var->next->cast_pluginvar();
+ }
+ }
+
DBUG_RETURN(0);
err:
DBUG_RETURN(1);
}
+
static uchar *get_hash_key(const uchar *buff, size_t *length,
my_bool not_used __attribute__((unused)))
{
@@ -642,24 +1056,44 @@ static uchar *get_hash_key(const uchar *buff, size_t *length,
}
+static byte *get_bookmark_hash_key(const byte *buff, uint *length,
+ my_bool not_used __attribute__((unused)))
+{
+ struct st_bookmark *var= (st_bookmark *)buff;
+ *length= var->name_len + 1;
+ return (byte*) var->key;
+}
+
+
/*
The logic is that we first load and initialize all compiled in plugins.
From there we load up the dynamic types (assuming we have not been told to
skip this part).
- Finally we inializie everything, aka the dynamic that have yet to initialize.
+ Finally we initialize everything, aka the dynamic that have yet to initialize.
*/
-int plugin_init(int skip_dynamic_loading)
+int plugin_init(int *argc, char **argv, int flags)
{
uint i;
+ bool def_enabled, is_myisam;
struct st_mysql_plugin **builtins;
struct st_mysql_plugin *plugin;
+ struct st_plugin_int tmp, *plugin_ptr, **reap;
+ MEM_ROOT tmp_root;
DBUG_ENTER("plugin_init");
if (initialized)
DBUG_RETURN(0);
- my_rwlock_init(&THR_LOCK_plugin, NULL);
+ init_alloc_root(&plugin_mem_root, 4096, 4096);
+ init_alloc_root(&tmp_root, 4096, 4096);
+
+ if (hash_init(&bookmark_hash, &my_charset_bin, 16, 0, 0,
+ get_bookmark_hash_key, NULL, HASH_UNIQUE))
+ goto err;
+
+
+ pthread_mutex_init(&LOCK_plugin, MY_MUTEX_INIT_FAST);
if (my_init_dynamic_array(&plugin_dl_array,
sizeof(struct st_plugin_dl),16,16) ||
@@ -670,10 +1104,14 @@ int plugin_init(int skip_dynamic_loading)
for (i= 0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++)
{
if (hash_init(&plugin_hash[i], system_charset_info, 16, 0, 0,
- get_hash_key, NULL, 0))
+ get_hash_key, NULL, HASH_UNIQUE))
goto err;
}
+ pthread_mutex_lock(&LOCK_plugin);
+
+ initialized= 1;
+
/*
First we register builtin plugins
*/
@@ -681,83 +1119,185 @@ int plugin_init(int skip_dynamic_loading)
{
for (plugin= *builtins; plugin->info; plugin++)
{
-// if (!(strcmp(plugin->name, "MyISAM")))
+ /* by default, only ndbcluster is disabled */
+ def_enabled=
+ my_strcasecmp(&my_charset_latin1, plugin->name, "NDBCLUSTER") != 0;
+ bzero(&tmp, sizeof(tmp));
+ tmp.plugin= plugin;
+ tmp.name.str= (char *)plugin->name;
+ tmp.name.length= strlen(plugin->name);
+
+ free_root(&tmp_root, MYF(MY_MARK_BLOCKS_FREE));
+ if (test_plugin_options(&tmp_root, &tmp, argc, argv, def_enabled))
+ continue;
+
+ if (register_builtin(plugin, &tmp, &plugin_ptr))
+ goto err_unlock;
+
+ /* only initialize MyISAM and CSV at this stage */
+ if (!(is_myisam=
+ !my_strcasecmp(&my_charset_latin1, plugin->name, "MyISAM")) &&
+ my_strcasecmp(&my_charset_latin1, plugin->name, "CSV"))
+ continue;
+
+ if (plugin_initialize(plugin_ptr))
+ goto err_unlock;
+
+ /*
+ initialize the global default storage engine so that it may
+ not be null in any child thread.
+ */
+ if (is_myisam)
{
- if (plugin_register_builtin(plugin))
- goto err;
- struct st_plugin_int *tmp= dynamic_element(&plugin_array,
- plugin_array.elements-1,
- struct st_plugin_int *);
- if (plugin_initialize(tmp))
- goto err;
+ DBUG_ASSERT(!global_system_variables.table_plugin);
+ global_system_variables.table_plugin=
+ my_intern_plugin_lock(NULL, plugin_int_to_ref(plugin_ptr));
+ DBUG_ASSERT(plugin_ptr->ref_count == 1);
}
}
}
+ /* should now be set to MyISAM storage engine */
+ DBUG_ASSERT(global_system_variables.table_plugin);
+
+ pthread_mutex_unlock(&LOCK_plugin);
+
/* Register all dynamic plugins */
- if (!skip_dynamic_loading)
- plugin_load();
+ if (!(flags & PLUGIN_INIT_SKIP_DYNAMIC_LOADING))
+ {
+ if (opt_plugin_load &&
+ plugin_load_list(&tmp_root, argc, argv, opt_plugin_load))
+ goto err;
+ if (!(flags & PLUGIN_INIT_SKIP_PLUGIN_TABLE))
+ plugin_load(&tmp_root, argc, argv);
+ }
- initialized= 1;
+ if (flags & PLUGIN_INIT_SKIP_INITIALIZATION)
+ goto end;
/*
Now we initialize all remaining plugins
*/
+
+ pthread_mutex_lock(&LOCK_plugin);
+ reap= (st_plugin_int **) my_alloca((plugin_array.elements+1) * sizeof(void*));
+ *(reap++)= NULL;
+
for (i= 0; i < plugin_array.elements; i++)
{
- struct st_plugin_int *tmp= dynamic_element(&plugin_array, i,
- struct st_plugin_int *);
- if (tmp->state == PLUGIN_IS_UNINITIALIZED)
+ plugin_ptr= dynamic_element(&plugin_array, i, struct st_plugin_int *);
+ if (plugin_ptr->state == PLUGIN_IS_UNINITIALIZED)
{
- if (plugin_initialize(tmp))
+ if (plugin_initialize(plugin_ptr))
{
- plugin_deinitialize(tmp);
- plugin_del(tmp);
+ plugin_ptr->state= PLUGIN_IS_DYING;
+ *(reap++)= plugin_ptr;
}
}
}
+ /*
+ Check if any plugins have to be reaped
+ */
+ while ((plugin_ptr= *(--reap)))
+ {
+ pthread_mutex_unlock(&LOCK_plugin);
+ plugin_deinitialize(plugin_ptr, true);
+ pthread_mutex_lock(&LOCK_plugin);
+ plugin_del(plugin_ptr);
+ }
+
+ pthread_mutex_unlock(&LOCK_plugin);
+ my_afree(reap);
+
+end:
+ free_root(&tmp_root, MYF(0));
+
DBUG_RETURN(0);
+err_unlock:
+ pthread_mutex_unlock(&LOCK_plugin);
err:
+ free_root(&tmp_root, MYF(0));
DBUG_RETURN(1);
}
-my_bool plugin_register_builtin(struct st_mysql_plugin *plugin)
+static bool register_builtin(struct st_mysql_plugin *plugin,
+ struct st_plugin_int *tmp,
+ struct st_plugin_int **ptr)
{
- struct st_plugin_int tmp;
+ DBUG_ENTER("register_builtin");
+
+ tmp->state= PLUGIN_IS_UNINITIALIZED;
+ tmp->ref_count= 0;
+ tmp->plugin_dl= 0;
+
+ if (insert_dynamic(&plugin_array, (gptr)tmp))
+ DBUG_RETURN(1);
+
+ *ptr= dynamic_element(&plugin_array, plugin_array.elements - 1,
+ struct st_plugin_int *);
+
+ if (my_hash_insert(&plugin_hash[plugin->type],(byte*) *ptr))
+ DBUG_RETURN(1);
+
+ DBUG_RETURN(0);
+}
+
+
+#ifdef NOT_USED_YET
+/*
+ Register a plugin at run time. (note, this doesn't initialize a plugin)
+ Will be useful for embedded applications.
+
+ SYNOPSIS
+ plugin_register_builtin()
+ thd current thread (used to store scratch data in mem_root)
+ plugin static plugin to install
+
+ RETURN
+ false - plugin registered successfully
+*/
+bool plugin_register_builtin(THD *thd, struct st_mysql_plugin *plugin)
+{
+ struct st_plugin_int tmp, *ptr;
+ bool result= true;
+ int dummy_argc= 0;
DBUG_ENTER("plugin_register_builtin");
+ bzero(&tmp, sizeof(tmp));
tmp.plugin= plugin;
tmp.name.str= (char *)plugin->name;
tmp.name.length= strlen(plugin->name);
- tmp.state= PLUGIN_IS_UNINITIALIZED;
- /* Cannot be unloaded */
- tmp.ref_count= 1;
- tmp.plugin_dl= 0;
+ pthread_mutex_lock(&LOCK_plugin);
+ rw_wrlock(&LOCK_system_variables_hash);
- if (insert_dynamic(&plugin_array, (uchar*)&tmp))
- DBUG_RETURN(1);
+ if (test_plugin_options(thd->mem_root, &tmp, &dummy_argc, NULL, true))
+ goto end;
- if (my_hash_insert(&plugin_hash[plugin->type],
- (uchar*)dynamic_element(&plugin_array,
- plugin_array.elements - 1,
- struct st_plugin_int *)))
- DBUG_RETURN(1);
+ if ((result= register_builtin(plugin, &tmp, &ptr)))
+ mysql_del_sys_var_chain(tmp.system_vars);
- DBUG_RETURN(0);
+end:
+ rw_unlock(&LOCK_system_variables_hash);
+ pthread_mutex_unlock(&LOCK_plugin);
+
+ DBUG_RETURN(result);;
}
+#endif /* NOT_USED_YET */
-void plugin_load(void)
+/*
+ called only by plugin_init()
+*/
+static void plugin_load(MEM_ROOT *tmp_root, int *argc, char **argv)
{
TABLE_LIST tables;
TABLE *table;
READ_RECORD read_record_info;
int error;
- MEM_ROOT mem;
THD *new_thd;
DBUG_ENTER("plugin_load");
@@ -767,7 +1307,6 @@ void plugin_load(void)
delete new_thd;
DBUG_VOID_RETURN;
}
- init_sql_alloc(&mem, 1024, 0);
new_thd->thread_stack= (char*) &tables;
new_thd->store_globals();
new_thd->db= my_strdup("mysql", MYF(0));
@@ -786,26 +1325,34 @@ void plugin_load(void)
table= tables.table;
init_read_record(&read_record_info, new_thd, table, NULL, 1, 0);
table->use_all_columns();
+ /*
+ there're no other threads running yet, so we don't need a mutex.
+ but plugin_add() before is designed to work in multi-threaded
+ environment, and it uses safe_mutex_assert_owner(), so we lock
+ the mutex here to satisfy the assert
+ */
+ pthread_mutex_lock(&LOCK_plugin);
while (!(error= read_record_info.read_record(&read_record_info)))
{
DBUG_PRINT("info", ("init plugin record"));
String str_name, str_dl;
- get_field(&mem, table->field[0], &str_name);
- get_field(&mem, table->field[1], &str_dl);
-
+ get_field(tmp_root, table->field[0], &str_name);
+ get_field(tmp_root, table->field[1], &str_dl);
+
LEX_STRING name= {(char *)str_name.ptr(), str_name.length()};
LEX_STRING dl= {(char *)str_dl.ptr(), str_dl.length()};
- if (plugin_add(&name, &dl, REPORT_TO_LOG))
+ if (plugin_add(tmp_root, &name, &dl, argc, argv, REPORT_TO_LOG))
sql_print_warning("Couldn't load plugin named '%s' with soname '%s'.",
str_name.c_ptr(), str_dl.c_ptr());
+ free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE));
}
+ pthread_mutex_unlock(&LOCK_plugin);
if (error > 0)
sql_print_error(ER(ER_GET_ERRNO), my_errno);
end_read_record(&read_record_info);
new_thd->version--; // Force close to free memory
end:
- free_root(&mem, MYF(0));
close_thread_tables(new_thd);
delete new_thd;
/* Remember that we don't have a THD */
@@ -814,46 +1361,222 @@ end:
}
+/*
+ called only by plugin_init()
+*/
+static bool plugin_load_list(MEM_ROOT *tmp_root, int *argc, char **argv,
+ const char *list)
+{
+ char buffer[FN_REFLEN];
+ LEX_STRING name= {buffer, 0}, dl= {NULL, 0}, *str= &name;
+ struct st_plugin_dl *plugin_dl;
+ struct st_mysql_plugin *plugin;
+ char *p= buffer;
+ DBUG_ENTER("plugin_load_list");
+ while (list)
+ {
+ if (p == buffer + sizeof(buffer) - 1)
+ break;
+ switch ((*(p++)= *(list++))) {
+ case '\0':
+ list= NULL; /* terminate the loop */
+ /* fall through */
+#ifndef __WIN__
+ case ':': /* can't use this as delimiter as it may be drive letter */
+#endif
+ case ';':
+ name.str[name.length]= '\0';
+ if (str != &dl) // load all plugins in named module
+ {
+ dl= name;
+ if ((plugin_dl= plugin_dl_add(&dl, REPORT_TO_LOG)))
+ {
+ for (plugin= plugin_dl->plugins; plugin->info; plugin++)
+ {
+ name.str= (char *) plugin->name;
+ name.length= strlen(name.str);
+
+ free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE));
+ if (plugin_add(tmp_root, &name, &dl, argc, argv, REPORT_TO_LOG))
+ goto error;
+ }
+ plugin_dl_del(&dl); // reduce ref count
+ }
+ }
+ else
+ {
+ free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE));
+ if (plugin_add(tmp_root, &name, &dl, argc, argv, REPORT_TO_LOG))
+ goto error;
+ }
+ name.length= dl.length= 0;
+ dl.str= NULL; name.str= p= buffer;
+ str= &name;
+ continue;
+ case '=':
+ case '#':
+ if (str == &name)
+ {
+ str= &dl;
+ str->str= p;
+ continue;
+ }
+ default:
+ str->length++;
+ continue;
+ }
+ }
+ DBUG_RETURN(FALSE);
+error:
+ sql_print_error("Couldn't load plugin named '%s' with soname '%s'.",
+ name.str, dl.str);
+ DBUG_RETURN(TRUE);
+}
+
+
void plugin_shutdown(void)
{
- uint i;
+ uint i, count= plugin_array.elements, free_slots= 0;
+ struct st_plugin_int **plugins, *plugin;
+ struct st_plugin_dl **dl;
DBUG_ENTER("plugin_shutdown");
- /*
- We loop through all plugins and call deinit() if they have one.
- */
- for (i= 0; i < plugin_array.elements; i++)
+ if (initialized)
{
- struct st_plugin_int *tmp= dynamic_element(&plugin_array, i,
- struct st_plugin_int *);
- plugin_deinitialize(tmp);
+ pthread_mutex_lock(&LOCK_plugin);
+
+ reap_needed= true;
+
+ /*
+ We want to shut down plugins in a reasonable order, this will
+ become important when we have plugins which depend upon each other.
+ Circular references cannot be reaped so they are forced afterwards.
+ TODO: Have an additional step here to notify all active plugins that
+ shutdown is requested to allow plugins to deinitialize in parallel.
+ */
+ while (reap_needed && (count= plugin_array.elements))
+ {
+ reap_plugins();
+ for (i= free_slots= 0; i < count; i++)
+ {
+ plugin= dynamic_element(&plugin_array, i, struct st_plugin_int *);
+ switch (plugin->state) {
+ case PLUGIN_IS_READY:
+ plugin->state= PLUGIN_IS_DELETED;
+ reap_needed= true;
+ break;
+ case PLUGIN_IS_FREED:
+ case PLUGIN_IS_UNINITIALIZED:
+ free_slots++;
+ break;
+ }
+ }
+ if (!reap_needed)
+ {
+ /*
+ release any plugin references held.
+ */
+ unlock_variables(NULL, &global_system_variables);
+ unlock_variables(NULL, &max_system_variables);
+ }
+ }
+
+ if (count > free_slots)
+ sql_print_warning("Forcing shutdown of %d plugins", count - free_slots);
+
+ plugins= (struct st_plugin_int **) my_alloca(sizeof(void*) * (count+1));
+
+ /*
+ If we have any plugins which did not die cleanly, we force shutdown
+ */
+ for (i= 0; i < count; i++)
+ {
+ plugins[i]= dynamic_element(&plugin_array, i, struct st_plugin_int *);
+ /* change the state to ensure no reaping races */
+ if (plugins[i]->state == PLUGIN_IS_DELETED)
+ plugins[i]->state= PLUGIN_IS_DYING;
+ }
+ pthread_mutex_unlock(&LOCK_plugin);
+
+ /*
+ We loop through all plugins and call deinit() if they have one.
+ */
+ for (i= 0; i < count; i++)
+ if (!(plugins[i]->state & (PLUGIN_IS_UNINITIALIZED | PLUGIN_IS_FREED)))
+ {
+ sql_print_information("Plugin '%s' will be forced to shutdown",
+ plugins[i]->name.str);
+ /*
+ We are forcing deinit on plugins so we don't want to do a ref_count
+ check until we have processed all the plugins.
+ */
+ plugin_deinitialize(plugins[i], false);
+ }
+
+ /*
+ It's perfectly safe not to lock LOCK_plugin, as there're no
+ concurrent threads anymore. But some functions called from here
+ use safe_mutex_assert_owner(), so we lock the mutex to satisfy it
+ */
+ pthread_mutex_lock(&LOCK_plugin);
+
+ /*
+ We defer checking ref_counts until after all plugins are deinitialized
+ as some may have worker threads holding on to plugin references.
+ */
+ for (i= 0; i < count; i++)
+ {
+ if (plugins[i]->ref_count)
+ sql_print_error("Plugin '%s' has ref_count=%d after shutdown.",
+ plugins[i]->name.str, plugins[i]->ref_count);
+ if (plugins[i]->state & PLUGIN_IS_UNINITIALIZED)
+ plugin_del(plugins[i]);
+ }
+
+ /*
+ Now we can deallocate all memory.
+ */
+ cleanup_variables(NULL, &global_system_variables);
+ cleanup_variables(NULL, &max_system_variables);
+ pthread_mutex_unlock(&LOCK_plugin);
+
+ initialized= 0;
+ pthread_mutex_destroy(&LOCK_plugin);
+
+ my_afree(plugins);
}
+ /* Dispose of the memory */
+
for (i= 0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++)
hash_free(&plugin_hash[i]);
delete_dynamic(&plugin_array);
+
+ count= plugin_dl_array.elements;
+ dl= (struct st_plugin_dl **)my_alloca(sizeof(void*) * count);
+ for (i= 0; i < count; i++)
+ dl[i]= dynamic_element(&plugin_dl_array, i, struct st_plugin_dl *);
for (i= 0; i < plugin_dl_array.elements; i++)
- {
- struct st_plugin_dl *tmp= dynamic_element(&plugin_dl_array, i,
- struct st_plugin_dl *);
- free_plugin_mem(tmp);
- }
+ free_plugin_mem(dl[i]);
+ my_afree(dl);
delete_dynamic(&plugin_dl_array);
- if (initialized)
- {
- initialized= 0;
- rwlock_destroy(&THR_LOCK_plugin);
- }
+
+ hash_free(&bookmark_hash);
+ free_root(&plugin_mem_root, MYF(0));
+
+ global_variables_dynamic_size= 0;
+
DBUG_VOID_RETURN;
}
-my_bool mysql_install_plugin(THD *thd, const LEX_STRING *name, const LEX_STRING *dl)
+bool mysql_install_plugin(THD *thd, const LEX_STRING *name, const LEX_STRING *dl)
{
TABLE_LIST tables;
TABLE *table;
- int error;
+ int error, argc;
+ char *argv[2];
struct st_plugin_int *tmp;
DBUG_ENTER("mysql_install_plugin");
@@ -863,14 +1586,21 @@ my_bool mysql_install_plugin(THD *thd, const LEX_STRING *name, const LEX_STRING
if (check_table_access(thd, INSERT_ACL, &tables, 0))
DBUG_RETURN(TRUE);
- /* need to open before acquiring THR_LOCK_plugin or it will deadlock */
+ /* need to open before acquiring LOCK_plugin or it will deadlock */
if (! (table = open_ltable(thd, &tables, TL_WRITE)))
DBUG_RETURN(TRUE);
- rw_wrlock(&THR_LOCK_plugin);
- if (plugin_add(name, dl, REPORT_TO_USER))
+ pthread_mutex_lock(&LOCK_plugin);
+ rw_wrlock(&LOCK_system_variables_hash);
+ /* handle_options() assumes arg0 (program name) always exists */
+ argv[0]= const_cast<char*>(""); // without a cast gcc emits a warning
+ argv[1]= 0;
+ argc= 1;
+ error= plugin_add(thd->mem_root, name, dl, &argc, argv, REPORT_TO_USER);
+ rw_unlock(&LOCK_system_variables_hash);
+
+ if (error || !(tmp= plugin_find_internal(name, MYSQL_ANY_PLUGIN)))
goto err;
- tmp= plugin_find_internal(name, MYSQL_ANY_PLUGIN);
if (plugin_initialize(tmp))
{
@@ -890,18 +1620,19 @@ my_bool mysql_install_plugin(THD *thd, const LEX_STRING *name, const LEX_STRING
goto deinit;
}
- rw_unlock(&THR_LOCK_plugin);
+ pthread_mutex_unlock(&LOCK_plugin);
DBUG_RETURN(FALSE);
deinit:
- plugin_deinitialize(tmp);
- plugin_del(tmp);
+ tmp->state= PLUGIN_IS_DELETED;
+ reap_needed= true;
+ reap_plugins();
err:
- rw_unlock(&THR_LOCK_plugin);
+ pthread_mutex_unlock(&LOCK_plugin);
DBUG_RETURN(TRUE);
}
-my_bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name)
+bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name)
{
TABLE *table;
TABLE_LIST tables;
@@ -912,11 +1643,11 @@ my_bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name)
tables.db= (char *)"mysql";
tables.table_name= tables.alias= (char *)"plugin";
- /* need to open before acquiring THR_LOCK_plugin or it will deadlock */
+ /* need to open before acquiring LOCK_plugin or it will deadlock */
if (! (table= open_ltable(thd, &tables, TL_WRITE)))
DBUG_RETURN(TRUE);
- rw_wrlock(&THR_LOCK_plugin);
+ pthread_mutex_lock(&LOCK_plugin);
if (!(plugin= plugin_find_internal(name, MYSQL_ANY_PLUGIN)))
{
my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "PLUGIN", name->str);
@@ -930,17 +1661,14 @@ my_bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name)
goto err;
}
+ plugin->state= PLUGIN_IS_DELETED;
if (plugin->ref_count)
- {
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
"Plugin is busy and will be uninstalled on shutdown");
- plugin->state= PLUGIN_IS_DELETED;
- }
else
- {
- plugin_deinitialize(plugin);
- plugin_del(plugin);
- }
+ reap_needed= true;
+ reap_plugins();
+ pthread_mutex_unlock(&LOCK_plugin);
table->use_all_columns();
table->field[0]->store(name->str, name->length, system_charset_info);
@@ -952,17 +1680,17 @@ my_bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name)
if ((error= table->file->ha_delete_row(table->record[0])))
{
table->file->print_error(error, MYF(0));
- goto err;
+ DBUG_RETURN(TRUE);
}
}
- rw_unlock(&THR_LOCK_plugin);
DBUG_RETURN(FALSE);
err:
- rw_unlock(&THR_LOCK_plugin);
+ pthread_mutex_unlock(&LOCK_plugin);
DBUG_RETURN(TRUE);
}
-my_bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
+
+bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
int type, uint state_mask, void *arg)
{
uint idx, total;
@@ -970,16 +1698,19 @@ my_bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
int version=plugin_array_version;
DBUG_ENTER("plugin_foreach_with_mask");
+ if (!initialized)
+ DBUG_RETURN(FALSE);
+
state_mask= ~state_mask; // do it only once
- rw_rdlock(&THR_LOCK_plugin);
- total= type == MYSQL_ANY_PLUGIN ? plugin_array.elements
+ pthread_mutex_lock(&LOCK_plugin);
+ total= type == MYSQL_ANY_PLUGIN ? plugin_array.elements
: plugin_hash[type].records;
/*
Do the alloca out here in case we do have a working alloca:
- leaving the nested stack frame invalidates alloca allocation.
+ leaving the nested stack frame invalidates alloca allocation.
*/
- plugins=(struct st_plugin_int **)my_alloca(total*sizeof(*plugins));
+ plugins=(struct st_plugin_int **)my_alloca(total*sizeof(plugin));
if (type == MYSQL_ANY_PLUGIN)
{
for (idx= 0; idx < total; idx++)
@@ -997,20 +1728,21 @@ my_bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
plugins[idx]= !(plugin->state & state_mask) ? plugin : NULL;
}
}
- rw_unlock(&THR_LOCK_plugin);
+ pthread_mutex_unlock(&LOCK_plugin);
for (idx= 0; idx < total; idx++)
{
if (unlikely(version != plugin_array_version))
{
- rw_rdlock(&THR_LOCK_plugin);
+ pthread_mutex_lock(&LOCK_plugin);
for (uint i=idx; i < total; i++)
if (plugins[i] && plugins[i]->state & state_mask)
plugins[i]=0;
- rw_unlock(&THR_LOCK_plugin);
+ pthread_mutex_unlock(&LOCK_plugin);
}
plugin= plugins[idx];
- if (plugin && func(thd, plugin, arg))
+ /* It will stop iterating on first engine error when "func" returns TRUE */
+ if (plugin && func(thd, plugin_int_to_ref(plugin), arg))
goto err;
}
@@ -1021,3 +1753,1417 @@ err:
DBUG_RETURN(TRUE);
}
+
+/****************************************************************************
+ Internal type declarations for variables support
+****************************************************************************/
+
+#undef MYSQL_SYSVAR_NAME
+#define MYSQL_SYSVAR_NAME(name) name
+#define PLUGIN_VAR_TYPEMASK 0x007f
+
+#define EXTRA_OPTIONS 3 /* options for: 'foo', 'plugin-foo' and NULL */
+
+typedef DECLARE_MYSQL_SYSVAR_BASIC(sysvar_bool_t, my_bool);
+typedef DECLARE_MYSQL_THDVAR_BASIC(thdvar_bool_t, my_bool);
+typedef DECLARE_MYSQL_SYSVAR_BASIC(sysvar_str_t, char *);
+typedef DECLARE_MYSQL_THDVAR_BASIC(thdvar_str_t, char *);
+
+typedef DECLARE_MYSQL_SYSVAR_TYPELIB(sysvar_enum_t, unsigned long);
+typedef DECLARE_MYSQL_THDVAR_TYPELIB(thdvar_enum_t, unsigned long);
+typedef DECLARE_MYSQL_SYSVAR_TYPELIB(sysvar_set_t, ulonglong);
+typedef DECLARE_MYSQL_THDVAR_TYPELIB(thdvar_set_t, ulonglong);
+
+typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_int_t, int);
+typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_long_t, long);
+typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_longlong_t, longlong);
+typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_uint_t, uint);
+typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_ulong_t, ulong);
+typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_ulonglong_t, ulonglong);
+
+typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_int_t, int);
+typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_long_t, long);
+typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_longlong_t, longlong);
+typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_uint_t, uint);
+typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_ulong_t, ulong);
+typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_ulonglong_t, ulonglong);
+
+#define SET_PLUGIN_VAR_RESOLVE(opt)\
+ *(mysql_sys_var_ptr_p*)&((opt)->resolve)= mysql_sys_var_ptr
+typedef byte *(*mysql_sys_var_ptr_p)(void* a_thd, int offset);
+
+
+/****************************************************************************
+ default variable data check and update functions
+****************************************************************************/
+
+static int check_func_bool(THD *thd, struct st_mysql_sys_var *var,
+ void *save, st_mysql_value *value)
+{
+ char buff[STRING_BUFFER_USUAL_SIZE];
+ const char *strvalue= "NULL", *str;
+ int result, length;
+ long long tmp;
+
+ if (value->value_type(value) == MYSQL_VALUE_TYPE_STRING)
+ {
+ length= sizeof(buff);
+ if (!(str= value->val_str(value, buff, &length)) ||
+ (result= find_type(&bool_typelib, str, length, 1)-1) < 0)
+ {
+ if (str)
+ strvalue= str;
+ goto err;
+ }
+ }
+ else
+ {
+ if (value->val_int(value, &tmp) < 0)
+ goto err;
+ if (tmp > 1)
+ {
+ llstr(tmp, buff);
+ strvalue= buff;
+ goto err;
+ }
+ result= (int) tmp;
+ }
+ *(int*)save= -result;
+ return 0;
+err:
+ my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->name, strvalue);
+ return 1;
+}
+
+
+static int check_func_int(THD *thd, struct st_mysql_sys_var *var,
+ void *save, st_mysql_value *value)
+{
+ long long tmp;
+ struct my_option options;
+ value->val_int(value, &tmp);
+ plugin_opt_set_limits(&options, var);
+ *(int *)save= (int) getopt_ull_limit_value(tmp, &options);
+ return (thd->variables.sql_mode & MODE_STRICT_ALL_TABLES) &&
+ (*(int *)save != (int) tmp);
+}
+
+
+static int check_func_long(THD *thd, struct st_mysql_sys_var *var,
+ void *save, st_mysql_value *value)
+{
+ long long tmp;
+ struct my_option options;
+ value->val_int(value, &tmp);
+ plugin_opt_set_limits(&options, var);
+ *(long *)save= (long) getopt_ull_limit_value(tmp, &options);
+ return (thd->variables.sql_mode & MODE_STRICT_ALL_TABLES) &&
+ (*(long *)save != (long) tmp);
+}
+
+
+static int check_func_longlong(THD *thd, struct st_mysql_sys_var *var,
+ void *save, st_mysql_value *value)
+{
+ long long tmp;
+ struct my_option options;
+ value->val_int(value, &tmp);
+ plugin_opt_set_limits(&options, var);
+ *(ulonglong *)save= getopt_ull_limit_value(tmp, &options);
+ return (thd->variables.sql_mode & MODE_STRICT_ALL_TABLES) &&
+ (*(long long *)save != tmp);
+}
+
+static int check_func_str(THD *thd, struct st_mysql_sys_var *var,
+ void *save, st_mysql_value *value)
+{
+ char buff[STRING_BUFFER_USUAL_SIZE];
+ const char *str;
+ int length;
+
+ length= sizeof(buff);
+ if ((str= value->val_str(value, buff, &length)))
+ str= thd->strmake(str, length);
+ *(const char**)save= str;
+ return 0;
+}
+
+
+static int check_func_enum(THD *thd, struct st_mysql_sys_var *var,
+ void *save, st_mysql_value *value)
+{
+ char buff[STRING_BUFFER_USUAL_SIZE];
+ const char *strvalue= "NULL", *str;
+ TYPELIB *typelib;
+ long long tmp;
+ long result;
+ int length;
+
+ if (var->flags & PLUGIN_VAR_THDLOCAL)
+ typelib= ((thdvar_enum_t*) var)->typelib;
+ else
+ typelib= ((sysvar_enum_t*) var)->typelib;
+
+ if (value->value_type(value) == MYSQL_VALUE_TYPE_STRING)
+ {
+ length= sizeof(buff);
+ if (!(str= value->val_str(value, buff, &length)))
+ goto err;
+ if ((result= find_type(typelib, str, length, 1)-1) < 0)
+ {
+ strvalue= str;
+ goto err;
+ }
+ }
+ else
+ {
+ if (value->val_int(value, &tmp))
+ goto err;
+ if (tmp >= typelib->count)
+ {
+ llstr(tmp, buff);
+ strvalue= buff;
+ goto err;
+ }
+ result= (long) tmp;
+ }
+ *(long*)save= result;
+ return 0;
+err:
+ my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->name, strvalue);
+ return 1;
+}
+
+
+static int check_func_set(THD *thd, struct st_mysql_sys_var *var,
+ void *save, st_mysql_value *value)
+{
+ char buff[STRING_BUFFER_USUAL_SIZE], *error= 0;
+ const char *strvalue= "NULL", *str;
+ TYPELIB *typelib;
+ ulonglong result;
+ uint error_len;
+ bool not_used;
+ int length;
+
+ if (var->flags & PLUGIN_VAR_THDLOCAL)
+ typelib= ((thdvar_set_t*) var)->typelib;
+ else
+ typelib= ((sysvar_set_t*)var)->typelib;
+
+ if (value->value_type(value) == MYSQL_VALUE_TYPE_STRING)
+ {
+ length= sizeof(buff);
+ if (!(str= value->val_str(value, buff, &length)))
+ goto err;
+ result= find_set(typelib, str, length, NULL,
+ &error, &error_len, &not_used);
+ if (error_len)
+ {
+ strmake(buff, error, min(sizeof(buff), error_len));
+ strvalue= buff;
+ goto err;
+ }
+ }
+ else
+ {
+ if (value->val_int(value, (long long *)&result))
+ goto err;
+ if (unlikely((result >= (ULL(1) << typelib->count)) &&
+ (typelib->count < sizeof(long)*8)))
+ {
+ llstr(result, buff);
+ strvalue= buff;
+ goto err;
+ }
+ }
+ *(ulonglong*)save= result;
+ return 0;
+err:
+ my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->name, strvalue);
+ return 1;
+}
+
+
+static void update_func_bool(THD *thd, struct st_mysql_sys_var *var,
+ void *tgt, void *save)
+{
+ *(my_bool *) tgt= *(int *) save ? 1 : 0;
+}
+
+
+static void update_func_int(THD *thd, struct st_mysql_sys_var *var,
+ void *tgt, void *save)
+{
+ *(int *)tgt= *(int *) save;
+}
+
+
+static void update_func_long(THD *thd, struct st_mysql_sys_var *var,
+ void *tgt, void *save)
+{
+ *(long *)tgt= *(long *) save;
+}
+
+
+static void update_func_longlong(THD *thd, struct st_mysql_sys_var *var,
+ void *tgt, void *save)
+{
+ *(longlong *)tgt= *(ulonglong *) save;
+}
+
+
+static void update_func_str(THD *thd, struct st_mysql_sys_var *var,
+ void *tgt, void *save)
+{
+ char *old= *(char **) tgt;
+ *(char **)tgt= *(char **) save;
+ if (var->flags & PLUGIN_VAR_MEMALLOC)
+ {
+ *(char **)tgt= my_strdup(*(char **) save, MYF(0));
+ my_free(old, MYF(0));
+ }
+}
+
+
+/****************************************************************************
+ System Variables support
+****************************************************************************/
+
+
+sys_var *find_sys_var(THD *thd, const char *str, uint length)
+{
+ sys_var *var;
+ sys_var_pluginvar *pi= NULL;
+ plugin_ref plugin;
+ DBUG_ENTER("find_sys_var");
+
+ pthread_mutex_lock(&LOCK_plugin);
+ rw_rdlock(&LOCK_system_variables_hash);
+ if ((var= intern_find_sys_var(str, length, false)) &&
+ (pi= var->cast_pluginvar()))
+ {
+ rw_unlock(&LOCK_system_variables_hash);
+ LEX *lex= thd ? thd->lex : 0;
+ if (!(plugin= my_intern_plugin_lock(lex, plugin_int_to_ref(pi->plugin))))
+ var= NULL; /* failed to lock it, it must be uninstalling */
+ else
+ if (!(plugin_state(plugin) & PLUGIN_IS_READY))
+ {
+ /* initialization not completed */
+ var= NULL;
+ intern_plugin_unlock(lex, plugin);
+ }
+ }
+ else
+ rw_unlock(&LOCK_system_variables_hash);
+ pthread_mutex_unlock(&LOCK_plugin);
+
+ /*
+ If the variable exists but the plugin it is associated with is not ready
+ then the intern_plugin_lock did not raise an error, so we do it here.
+ */
+ if (pi && !var)
+ my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
+ DBUG_RETURN(var);
+}
+
+
+/*
+ called by register_var, construct_options and test_plugin_options.
+ Returns the 'bookmark' for the named variable.
+ LOCK_system_variables_hash should be at least read locked
+*/
+static st_bookmark *find_bookmark(const char *plugin, const char *name,
+ int flags)
+{
+ st_bookmark *result= NULL;
+ uint namelen, length, pluginlen= 0;
+ char *varname, *p;
+
+ if (!(flags & PLUGIN_VAR_THDLOCAL))
+ return NULL;
+
+ namelen= strlen(name);
+ if (plugin)
+ pluginlen= strlen(plugin) + 1;
+ length= namelen + pluginlen + 2;
+ varname= (char*) my_alloca(length);
+
+ if (plugin)
+ {
+ strxmov(varname + 1, plugin, "_", name, NullS);
+ for (p= varname + 1; *p; p++)
+ if (*p == '-')
+ *p= '_';
+ }
+ else
+ memcpy(varname + 1, name, namelen + 1);
+
+ varname[0]= flags & PLUGIN_VAR_TYPEMASK;
+
+ result= (st_bookmark*) hash_search(&bookmark_hash,
+ (const byte*) varname, length - 1);
+
+ my_afree(varname);
+ return result;
+}
+
+
+/*
+ returns a bookmark for thd-local variables, creating if neccessary.
+ returns null for non thd-local variables.
+ Requires that a write lock is obtained on LOCK_system_variables_hash
+*/
+static st_bookmark *register_var(const char *plugin, const char *name,
+ int flags)
+{
+ uint length= strlen(plugin) + strlen(name) + 3, size= 0, offset, new_size;
+ st_bookmark *result;
+ char *varname, *p;
+
+ if (!(flags & PLUGIN_VAR_THDLOCAL))
+ return NULL;
+
+ switch (flags & PLUGIN_VAR_TYPEMASK) {
+ case PLUGIN_VAR_BOOL:
+ size= sizeof(my_bool);
+ break;
+ case PLUGIN_VAR_INT:
+ size= sizeof(int);
+ break;
+ case PLUGIN_VAR_LONG:
+ size= sizeof(long);
+ break;
+ case PLUGIN_VAR_LONGLONG:
+ size= sizeof(ulonglong);
+ break;
+ case PLUGIN_VAR_STR:
+ size= sizeof(char*);
+ break;
+ default:
+ DBUG_ASSERT(0);
+ return NULL;
+ };
+
+ varname= ((char*) my_alloca(length));
+ strxmov(varname + 1, plugin, "_", name, NullS);
+ for (p= varname + 1; *p; p++)
+ if (*p == '-')
+ *p= '_';
+
+ if (!(result= find_bookmark(NULL, varname + 1, flags)))
+ {
+ result= (st_bookmark*) alloc_root(&plugin_mem_root,
+ sizeof(struct st_bookmark) + length-1);
+ varname[0]= flags & PLUGIN_VAR_TYPEMASK;
+ memcpy(result->key, varname, length);
+ result->name_len= length - 2;
+ result->offset= -1;
+
+ DBUG_ASSERT(size && !(size & (size-1))); /* must be power of 2 */
+
+ offset= global_system_variables.dynamic_variables_size;
+ offset= (offset + size - 1) & ~(size - 1);
+ result->offset= (int) offset;
+
+ new_size= (offset + size + 63) & ~63;
+
+ if (new_size > global_variables_dynamic_size)
+ {
+ global_system_variables.dynamic_variables_ptr=
+ my_realloc(global_system_variables.dynamic_variables_ptr, new_size,
+ MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
+ max_system_variables.dynamic_variables_ptr=
+ my_realloc(max_system_variables.dynamic_variables_ptr, new_size,
+ MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
+ /*
+ Clear the new variable value space. This is required for string
+ variables. If their value is non-NULL, it must point to a valid
+ string.
+ */
+ bzero(global_system_variables.dynamic_variables_ptr +
+ global_variables_dynamic_size,
+ new_size - global_variables_dynamic_size);
+ bzero(max_system_variables.dynamic_variables_ptr +
+ global_variables_dynamic_size,
+ new_size - global_variables_dynamic_size);
+ global_variables_dynamic_size= new_size;
+ }
+
+ global_system_variables.dynamic_variables_head= offset;
+ max_system_variables.dynamic_variables_head= offset;
+ global_system_variables.dynamic_variables_size= offset + size;
+ max_system_variables.dynamic_variables_size= offset + size;
+ global_system_variables.dynamic_variables_version++;
+ max_system_variables.dynamic_variables_version++;
+
+ result->version= global_system_variables.dynamic_variables_version;
+
+ /* this should succeed because we have already checked if a dup exists */
+ if (my_hash_insert(&bookmark_hash, (byte*) result))
+ {
+ fprintf(stderr, "failed to add placeholder to hash");
+ DBUG_ASSERT(0);
+ }
+ }
+ my_afree(varname);
+ return result;
+}
+
+
+/*
+ returns a pointer to the memory which holds the thd-local variable or
+ a pointer to the global variable if thd==null.
+ If required, will sync with global variables if the requested variable
+ has not yet been allocated in the current thread.
+*/
+static byte *intern_sys_var_ptr(THD* thd, int offset, bool global_lock)
+{
+ DBUG_ASSERT(offset >= 0);
+ DBUG_ASSERT((uint)offset <= global_system_variables.dynamic_variables_head);
+
+ if (!thd)
+ return (byte*) global_system_variables.dynamic_variables_ptr + offset;
+
+ /*
+ dynamic_variables_head points to the largest valid offset
+ */
+ if (!thd->variables.dynamic_variables_ptr ||
+ (uint)offset > thd->variables.dynamic_variables_head)
+ {
+ uint idx;
+
+ rw_rdlock(&LOCK_system_variables_hash);
+
+ thd->variables.dynamic_variables_ptr=
+ my_realloc(thd->variables.dynamic_variables_ptr,
+ global_variables_dynamic_size,
+ MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
+
+ if (global_lock)
+ pthread_mutex_lock(&LOCK_global_system_variables);
+
+ safe_mutex_assert_owner(&LOCK_global_system_variables);
+
+ memcpy(thd->variables.dynamic_variables_ptr +
+ thd->variables.dynamic_variables_size,
+ global_system_variables.dynamic_variables_ptr +
+ thd->variables.dynamic_variables_size,
+ global_system_variables.dynamic_variables_size -
+ thd->variables.dynamic_variables_size);
+
+ /*
+ now we need to iterate through any newly copied 'defaults'
+ and if it is a string type with MEMALLOC flag, we need to strdup
+ */
+ for (idx= 0; idx < bookmark_hash.records; idx++)
+ {
+ sys_var_pluginvar *pi;
+ sys_var *var;
+ st_bookmark *v= (st_bookmark*) hash_element(&bookmark_hash,idx);
+
+ if (v->version <= thd->variables.dynamic_variables_version ||
+ !(var= intern_find_sys_var(v->key + 1, v->name_len, true)) ||
+ !(pi= var->cast_pluginvar()) ||
+ v->key[0] != (pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK))
+ continue;
+
+ /* Here we do anything special that may be required of the data types */
+
+ if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
+ pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
+ {
+ char **pp= (char**) (thd->variables.dynamic_variables_ptr +
+ *(int*)(pi->plugin_var + 1));
+ if ((*pp= *(char**) (global_system_variables.dynamic_variables_ptr +
+ *(int*)(pi->plugin_var + 1))))
+ *pp= my_strdup(*pp, MYF(MY_WME|MY_FAE));
+ }
+ }
+
+ if (global_lock)
+ pthread_mutex_unlock(&LOCK_global_system_variables);
+
+ thd->variables.dynamic_variables_version=
+ global_system_variables.dynamic_variables_version;
+ thd->variables.dynamic_variables_head=
+ global_system_variables.dynamic_variables_head;
+ thd->variables.dynamic_variables_size=
+ global_system_variables.dynamic_variables_size;
+
+ rw_unlock(&LOCK_system_variables_hash);
+ }
+ return (byte*)thd->variables.dynamic_variables_ptr + offset;
+}
+
+static byte *mysql_sys_var_ptr(void* a_thd, int offset)
+{
+ return intern_sys_var_ptr((THD *)a_thd, offset, true);
+}
+
+
+void plugin_thdvar_init(THD *thd)
+{
+ plugin_ref old_table_plugin= thd->variables.table_plugin;
+ DBUG_ENTER("plugin_thdvar_init");
+
+ thd->variables.table_plugin= NULL;
+ cleanup_variables(thd, &thd->variables);
+
+ thd->variables= global_system_variables;
+ thd->variables.table_plugin= NULL;
+
+ /* we are going to allocate these lazily */
+ thd->variables.dynamic_variables_version= 0;
+ thd->variables.dynamic_variables_size= 0;
+ thd->variables.dynamic_variables_ptr= 0;
+
+ pthread_mutex_lock(&LOCK_plugin);
+ thd->variables.table_plugin=
+ my_intern_plugin_lock(NULL, global_system_variables.table_plugin);
+ intern_plugin_unlock(NULL, old_table_plugin);
+ pthread_mutex_unlock(&LOCK_plugin);
+ DBUG_VOID_RETURN;
+}
+
+
+/*
+ Unlocks all system variables which hold a reference
+*/
+static void unlock_variables(THD *thd, struct system_variables *vars)
+{
+ intern_plugin_unlock(NULL, vars->table_plugin);
+ vars->table_plugin= NULL;
+}
+
+
+/*
+ Frees memory used by system variables
+
+ Unlike plugin_vars_free_values() it frees all variables of all plugins,
+ it's used on shutdown.
+*/
+static void cleanup_variables(THD *thd, struct system_variables *vars)
+{
+ st_bookmark *v;
+ sys_var_pluginvar *pivar;
+ sys_var *var;
+ int flags;
+ uint idx;
+
+ rw_rdlock(&LOCK_system_variables_hash);
+ for (idx= 0; idx < bookmark_hash.records; idx++)
+ {
+ v= (st_bookmark*) hash_element(&bookmark_hash, idx);
+ if (v->version > vars->dynamic_variables_version ||
+ !(var= intern_find_sys_var(v->key + 1, v->name_len, true)) ||
+ !(pivar= var->cast_pluginvar()) ||
+ v->key[0] != (pivar->plugin_var->flags & PLUGIN_VAR_TYPEMASK))
+ continue;
+
+ flags= pivar->plugin_var->flags;
+
+ if ((flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
+ flags & PLUGIN_VAR_THDLOCAL && flags & PLUGIN_VAR_MEMALLOC)
+ {
+ char **ptr= (char**) pivar->real_value_ptr(thd, OPT_SESSION);
+ my_free(*ptr, MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
+ *ptr= NULL;
+ }
+ }
+ rw_unlock(&LOCK_system_variables_hash);
+
+ DBUG_ASSERT(vars->table_plugin == NULL);
+
+ my_free(vars->dynamic_variables_ptr, MYF(MY_ALLOW_ZERO_PTR));
+ vars->dynamic_variables_ptr= NULL;
+ vars->dynamic_variables_size= 0;
+ vars->dynamic_variables_version= 0;
+}
+
+
+void plugin_thdvar_cleanup(THD *thd)
+{
+ uint idx;
+ plugin_ref *list;
+ DBUG_ENTER("plugin_thdvar_cleanup");
+
+ pthread_mutex_lock(&LOCK_plugin);
+
+ unlock_variables(thd, &thd->variables);
+ cleanup_variables(thd, &thd->variables);
+
+ if ((idx= thd->lex->plugins.elements))
+ {
+ list= ((plugin_ref*) thd->lex->plugins.buffer) + idx - 1;
+ DBUG_PRINT("info",("unlocking %d plugins", idx));
+ while ((char*) list >= thd->lex->plugins.buffer)
+ intern_plugin_unlock(NULL, *list--);
+ }
+
+ reap_plugins();
+ pthread_mutex_unlock(&LOCK_plugin);
+
+ reset_dynamic(&thd->lex->plugins);
+
+ DBUG_VOID_RETURN;
+}
+
+
+/**
+ @brief Free values of thread variables of a plugin.
+
+ @detail This must be called before a plugin is deleted. Otherwise its
+ variables are no longer accessible and the value space is lost. Note
+ that only string values with PLUGIN_VAR_MEMALLOC are allocated and
+ must be freed.
+
+ @param[in] vars Chain of system variables of a plugin
+*/
+
+static void plugin_vars_free_values(sys_var *vars)
+{
+ DBUG_ENTER("plugin_vars_free_values");
+
+ for (sys_var *var= vars; var; var= var->next)
+ {
+ sys_var_pluginvar *piv= var->cast_pluginvar();
+ if (piv &&
+ ((piv->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR) &&
+ (piv->plugin_var->flags & PLUGIN_VAR_MEMALLOC))
+ {
+ /* Free the string from global_system_variables. */
+ char **valptr= (char**) piv->real_value_ptr(NULL, OPT_GLOBAL);
+ DBUG_PRINT("plugin", ("freeing value for: '%s' addr: 0x%lx",
+ var->name, (long) valptr));
+ my_free(*valptr, MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
+ *valptr= NULL;
+ }
+ }
+ DBUG_VOID_RETURN;
+}
+
+
+bool sys_var_pluginvar::check_update_type(Item_result type)
+{
+ if (is_readonly())
+ return 1;
+ switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
+ case PLUGIN_VAR_INT:
+ case PLUGIN_VAR_LONG:
+ case PLUGIN_VAR_LONGLONG:
+ return type != INT_RESULT;
+ case PLUGIN_VAR_STR:
+ return type != STRING_RESULT;
+ default:
+ return 0;
+ }
+}
+
+
+SHOW_TYPE sys_var_pluginvar::show_type()
+{
+ switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
+ case PLUGIN_VAR_BOOL:
+ return SHOW_MY_BOOL;
+ case PLUGIN_VAR_INT:
+ return SHOW_INT;
+ case PLUGIN_VAR_LONG:
+ return SHOW_LONG;
+ case PLUGIN_VAR_LONGLONG:
+ return SHOW_LONGLONG;
+ case PLUGIN_VAR_STR:
+ return SHOW_CHAR_PTR;
+ case PLUGIN_VAR_ENUM:
+ case PLUGIN_VAR_SET:
+ return SHOW_CHAR;
+ default:
+ DBUG_ASSERT(0);
+ return SHOW_UNDEF;
+ }
+}
+
+
+byte* sys_var_pluginvar::real_value_ptr(THD *thd, enum_var_type type)
+{
+ DBUG_ASSERT(thd || (type == OPT_GLOBAL));
+ if (plugin_var->flags & PLUGIN_VAR_THDLOCAL)
+ {
+ if (type == OPT_GLOBAL)
+ thd= NULL;
+
+ return intern_sys_var_ptr(thd, *(int*) (plugin_var+1), false);
+ }
+ return *(byte**) (plugin_var+1);
+}
+
+
+TYPELIB* sys_var_pluginvar::plugin_var_typelib(void)
+{
+ switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_THDLOCAL)) {
+ case PLUGIN_VAR_ENUM:
+ return ((sysvar_enum_t *)plugin_var)->typelib;
+ case PLUGIN_VAR_SET:
+ return ((sysvar_set_t *)plugin_var)->typelib;
+ case PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL:
+ return ((thdvar_enum_t *)plugin_var)->typelib;
+ case PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL:
+ return ((thdvar_set_t *)plugin_var)->typelib;
+ default:
+ return NULL;
+ }
+ return NULL;
+}
+
+
+byte* sys_var_pluginvar::value_ptr(THD *thd, enum_var_type type,
+ LEX_STRING *base)
+{
+ byte* result;
+
+ result= real_value_ptr(thd, type);
+
+ if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_ENUM)
+ result= (byte*) get_type(plugin_var_typelib(), *(ulong*)result);
+ else if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_SET)
+ {
+ char buffer[STRING_BUFFER_USUAL_SIZE];
+ String str(buffer, sizeof(buffer), system_charset_info);
+ TYPELIB *typelib= plugin_var_typelib();
+ ulonglong mask= 1, value= *(ulonglong*) result;
+ uint i;
+
+ str.length(0);
+ for (i= 0; i < typelib->count; i++, mask<<=1)
+ {
+ if (!(value & mask))
+ continue;
+ str.append(typelib->type_names[i], typelib->type_lengths[i]);
+ str.append(',');
+ }
+
+ result= (byte*) "";
+ if (str.length())
+ result= (byte*) thd->strmake(str.ptr(), str.length()-1);
+ }
+ return result;
+}
+
+
+bool sys_var_pluginvar::check(THD *thd, set_var *var)
+{
+ st_item_value_holder value;
+ DBUG_ASSERT(is_readonly() || plugin_var->check);
+
+ value.value_type= item_value_type;
+ value.val_str= item_val_str;
+ value.val_int= item_val_int;
+ value.val_real= item_val_real;
+ value.item= var->value;
+
+ return is_readonly() ||
+ plugin_var->check(thd, plugin_var, &var->save_result, &value);
+}
+
+
+void sys_var_pluginvar::set_default(THD *thd, enum_var_type type)
+{
+ void *tgt, *src;
+
+ DBUG_ASSERT(is_readonly() || plugin_var->update);
+
+ if (is_readonly())
+ return;
+
+ tgt= real_value_ptr(thd, type);
+ src= ((void **) (plugin_var + 1) + 1);
+
+ if (plugin_var->flags & PLUGIN_VAR_THDLOCAL)
+ {
+ src= ((int*) (plugin_var + 1) + 1);
+ if (type != OPT_GLOBAL)
+ src= real_value_ptr(thd, OPT_GLOBAL);
+ }
+
+ /* thd must equal current_thd if PLUGIN_VAR_THDLOCAL flag is set */
+ DBUG_ASSERT(!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) ||
+ thd == current_thd);
+
+ if (!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) || type == OPT_GLOBAL)
+ {
+ pthread_mutex_lock(&LOCK_plugin);
+ plugin_var->update(thd, plugin_var, tgt, src);
+ pthread_mutex_unlock(&LOCK_plugin);
+ }
+ else
+ plugin_var->update(thd, plugin_var, tgt, src);
+}
+
+
+bool sys_var_pluginvar::update(THD *thd, set_var *var)
+{
+ void *tgt;
+
+ DBUG_ASSERT(is_readonly() || plugin_var->update);
+
+ /* thd must equal current_thd if PLUGIN_VAR_THDLOCAL flag is set */
+ DBUG_ASSERT(!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) ||
+ thd == current_thd);
+
+ if (is_readonly())
+ return 1;
+
+ pthread_mutex_lock(&LOCK_global_system_variables);
+ tgt= real_value_ptr(thd, var->type);
+
+ if (!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) || var->type == OPT_GLOBAL)
+ {
+ /* variable we are updating has global scope, so we unlock after updating */
+ plugin_var->update(thd, plugin_var, tgt, &var->save_result);
+ pthread_mutex_unlock(&LOCK_global_system_variables);
+ }
+ else
+ {
+ pthread_mutex_unlock(&LOCK_global_system_variables);
+ plugin_var->update(thd, plugin_var, tgt, &var->save_result);
+ }
+ return 0;
+}
+
+
+#define OPTION_SET_LIMITS(type, options, opt) \
+ options->var_type= type; \
+ options->def_value= (opt)->def_val; \
+ options->min_value= (opt)->min_val; \
+ options->max_value= (opt)->max_val; \
+ options->block_size= (long) (opt)->blk_sz
+
+
+static void plugin_opt_set_limits(struct my_option *options,
+ const struct st_mysql_sys_var *opt)
+{
+ switch (opt->flags & (PLUGIN_VAR_TYPEMASK |
+ PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL)) {
+ /* global system variables */
+ case PLUGIN_VAR_INT:
+ OPTION_SET_LIMITS(GET_INT, options, (sysvar_int_t*) opt);
+ break;
+ case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED:
+ OPTION_SET_LIMITS(GET_UINT, options, (sysvar_uint_t*) opt);
+ break;
+ case PLUGIN_VAR_LONG:
+ OPTION_SET_LIMITS(GET_LONG, options, (sysvar_long_t*) opt);
+ break;
+ case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED:
+ OPTION_SET_LIMITS(GET_ULONG, options, (sysvar_ulong_t*) opt);
+ break;
+ case PLUGIN_VAR_LONGLONG:
+ OPTION_SET_LIMITS(GET_LL, options, (sysvar_longlong_t*) opt);
+ break;
+ case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED:
+ OPTION_SET_LIMITS(GET_ULL, options, (sysvar_ulonglong_t*) opt);
+ break;
+ case PLUGIN_VAR_ENUM:
+ options->var_type= GET_ENUM;
+ options->typelib= ((sysvar_enum_t*) opt)->typelib;
+ options->def_value= *(ulong*) ((int*) (opt + 1) + 1);
+ options->min_value= options->block_size= 0;
+ options->max_value= options->typelib->count - 1;
+ break;
+ case PLUGIN_VAR_SET:
+ options->var_type= GET_SET;
+ options->typelib= ((sysvar_set_t*) opt)->typelib;
+ options->def_value= *(ulonglong*) ((int*) (opt + 1) + 1);
+ options->min_value= options->block_size= 0;
+ options->max_value= (ULL(1) << options->typelib->count) - 1;
+ break;
+ case PLUGIN_VAR_BOOL:
+ options->var_type= GET_BOOL;
+ options->def_value= *(my_bool*) ((void**)(opt + 1) + 1);
+ break;
+ case PLUGIN_VAR_STR:
+ options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
+ GET_STR_ALLOC : GET_STR);
+ options->def_value= (ulonglong)(intptr) *((char**) ((void**) (opt + 1) + 1));
+ break;
+ /* threadlocal variables */
+ case PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL:
+ OPTION_SET_LIMITS(GET_INT, options, (thdvar_int_t*) opt);
+ break;
+ case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
+ OPTION_SET_LIMITS(GET_UINT, options, (thdvar_uint_t*) opt);
+ break;
+ case PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL:
+ OPTION_SET_LIMITS(GET_LONG, options, (thdvar_long_t*) opt);
+ break;
+ case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
+ OPTION_SET_LIMITS(GET_ULONG, options, (thdvar_ulong_t*) opt);
+ break;
+ case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL:
+ OPTION_SET_LIMITS(GET_LL, options, (thdvar_longlong_t*) opt);
+ break;
+ case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
+ OPTION_SET_LIMITS(GET_ULL, options, (thdvar_ulonglong_t*) opt);
+ break;
+ case PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL:
+ options->var_type= GET_ENUM;
+ options->typelib= ((thdvar_enum_t*) opt)->typelib;
+ options->def_value= *(ulong*) ((int*) (opt + 1) + 1);
+ options->min_value= options->block_size= 0;
+ options->max_value= options->typelib->count - 1;
+ break;
+ case PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL:
+ options->var_type= GET_SET;
+ options->typelib= ((thdvar_set_t*) opt)->typelib;
+ options->def_value= *(ulonglong*) ((int*) (opt + 1) + 1);
+ options->min_value= options->block_size= 0;
+ options->max_value= (ULL(1) << options->typelib->count) - 1;
+ break;
+ case PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL:
+ options->var_type= GET_BOOL;
+ options->def_value= *(my_bool*) ((int*) (opt + 1) + 1);
+ break;
+ case PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL:
+ options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
+ GET_STR_ALLOC : GET_STR);
+ options->def_value= (intptr) *((char**) ((void**) (opt + 1) + 1));
+ break;
+ default:
+ DBUG_ASSERT(0);
+ }
+ options->arg_type= REQUIRED_ARG;
+ if (opt->flags & PLUGIN_VAR_NOCMDARG)
+ options->arg_type= NO_ARG;
+ if (opt->flags & PLUGIN_VAR_OPCMDARG)
+ options->arg_type= OPT_ARG;
+}
+
+
+static my_bool get_one_option(int optid __attribute__((unused)),
+ const struct my_option *opt,
+ char *argument)
+{
+ return 0;
+}
+
+
+static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp,
+ my_option *options, my_bool **enabled,
+ bool can_disable)
+{
+ const char *plugin_name= tmp->plugin->name;
+ uint namelen= strlen(plugin_name), optnamelen;
+ uint buffer_length= namelen * 4 + (can_disable ? 75 : 10);
+ char *name= (char*) alloc_root(mem_root, buffer_length) + 1;
+ char *optname, *p;
+ int index= 0, offset= 0;
+ st_mysql_sys_var *opt, **plugin_option;
+ st_bookmark *v;
+ DBUG_ENTER("construct_options");
+ DBUG_PRINT("plugin", ("plugin: '%s' enabled: %d can_disable: %d",
+ plugin_name, **enabled, can_disable));
+
+ /* support --skip-plugin-foo syntax */
+ memcpy(name, plugin_name, namelen + 1);
+ my_casedn_str(&my_charset_latin1, name);
+ strxmov(name + namelen + 1, "plugin-", name, NullS);
+ /* Now we have namelen + 1 + 7 + namelen + 1 == namelen * 2 + 9. */
+
+ for (p= name + namelen*2 + 8; p > name; p--)
+ if (*p == '_')
+ *p= '-';
+
+ if (can_disable)
+ {
+ strxmov(name + namelen*2 + 10, "Enable ", plugin_name, " plugin. "
+ "Disable with --skip-", name," (will save memory).", NullS);
+ /*
+ Now we have namelen * 2 + 10 (one char unused) + 7 + namelen + 9 +
+ 20 + namelen + 20 + 1 == namelen * 4 + 67.
+ */
+
+ options[0].comment= name + namelen*2 + 10;
+ }
+
+ /*
+ NOTE: 'name' is one char above the allocated buffer!
+ NOTE: This code assumes that 'my_bool' and 'char' are of same size.
+ */
+ *((my_bool *)(name -1))= **enabled;
+ *enabled= (my_bool *)(name - 1);
+
+
+ options[1].name= (options[0].name= name) + namelen + 1;
+ options[0].id= options[1].id= 256; /* must be >255. dup id ok */
+ options[0].var_type= options[1].var_type= GET_BOOL;
+ options[0].arg_type= options[1].arg_type= NO_ARG;
+ options[0].def_value= options[1].def_value= **enabled;
+ options[0].value= options[0].u_max_value=
+ options[1].value= options[1].u_max_value= (gptr*) (name - 1);
+ options+= 2;
+
+ /*
+ Two passes as the 2nd pass will take pointer addresses for use
+ by my_getopt and register_var() in the first pass uses realloc
+ */
+
+ for (plugin_option= tmp->plugin->system_vars;
+ plugin_option && *plugin_option; plugin_option++, index++)
+ {
+ opt= *plugin_option;
+ if (!(opt->flags & PLUGIN_VAR_THDLOCAL))
+ continue;
+ if (!(register_var(name, opt->name, opt->flags)))
+ continue;
+ switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
+ case PLUGIN_VAR_BOOL:
+ SET_PLUGIN_VAR_RESOLVE((thdvar_bool_t *) opt);
+ break;
+ case PLUGIN_VAR_INT:
+ SET_PLUGIN_VAR_RESOLVE((thdvar_int_t *) opt);
+ break;
+ case PLUGIN_VAR_LONG:
+ SET_PLUGIN_VAR_RESOLVE((thdvar_long_t *) opt);
+ break;
+ case PLUGIN_VAR_LONGLONG:
+ SET_PLUGIN_VAR_RESOLVE((thdvar_longlong_t *) opt);
+ break;
+ case PLUGIN_VAR_STR:
+ SET_PLUGIN_VAR_RESOLVE((thdvar_str_t *) opt);
+ break;
+ case PLUGIN_VAR_ENUM:
+ SET_PLUGIN_VAR_RESOLVE((thdvar_enum_t *) opt);
+ break;
+ case PLUGIN_VAR_SET:
+ SET_PLUGIN_VAR_RESOLVE((thdvar_set_t *) opt);
+ break;
+ default:
+ sql_print_error("Unknown variable type code 0x%x in plugin '%s'.",
+ opt->flags, plugin_name);
+ DBUG_RETURN(-1);
+ };
+ }
+
+ for (plugin_option= tmp->plugin->system_vars;
+ plugin_option && *plugin_option; plugin_option++, index++)
+ {
+ switch ((opt= *plugin_option)->flags & PLUGIN_VAR_TYPEMASK) {
+ case PLUGIN_VAR_BOOL:
+ if (!opt->check)
+ opt->check= check_func_bool;
+ if (!opt->update)
+ opt->update= update_func_bool;
+ break;
+ case PLUGIN_VAR_INT:
+ if (!opt->check)
+ opt->check= check_func_int;
+ if (!opt->update)
+ opt->update= update_func_int;
+ break;
+ case PLUGIN_VAR_LONG:
+ if (!opt->check)
+ opt->check= check_func_long;
+ if (!opt->update)
+ opt->update= update_func_long;
+ break;
+ case PLUGIN_VAR_LONGLONG:
+ if (!opt->check)
+ opt->check= check_func_longlong;
+ if (!opt->update)
+ opt->update= update_func_longlong;
+ break;
+ case PLUGIN_VAR_STR:
+ if (!opt->check)
+ opt->check= check_func_str;
+ if (!opt->update)
+ {
+ opt->update= update_func_str;
+ if (!(opt->flags & PLUGIN_VAR_MEMALLOC))
+ {
+ opt->flags |= PLUGIN_VAR_READONLY;
+ sql_print_warning("Server variable %s of plugin %s was forced "
+ "to be read-only: string variable without "
+ "update_func and PLUGIN_VAR_MEMALLOC flag",
+ opt->name, plugin_name);
+ }
+ }
+ break;
+ case PLUGIN_VAR_ENUM:
+ if (!opt->check)
+ opt->check= check_func_enum;
+ if (!opt->update)
+ opt->update= update_func_long;
+ break;
+ case PLUGIN_VAR_SET:
+ if (!opt->check)
+ opt->check= check_func_set;
+ if (!opt->update)
+ opt->update= update_func_longlong;
+ break;
+ default:
+ sql_print_error("Unknown variable type code 0x%x in plugin '%s'.",
+ opt->flags, plugin_name);
+ DBUG_RETURN(-1);
+ }
+
+ if (opt->flags & PLUGIN_VAR_NOCMDOPT)
+ continue;
+
+ if (!opt->name)
+ {
+ sql_print_error("Missing variable name in plugin '%s'.",
+ plugin_name);
+ DBUG_RETURN(-1);
+ }
+
+ if (!(v= find_bookmark(name, opt->name, opt->flags)))
+ {
+ optnamelen= strlen(opt->name);
+ optname= (char*) alloc_root(mem_root, namelen + optnamelen + 2);
+ strxmov(optname, name, "-", opt->name, NullS);
+ optnamelen= namelen + optnamelen + 1;
+ }
+ else
+ optname= memdup_root(mem_root, v->key + 1, (optnamelen= v->name_len) + 1);
+
+ /* convert '_' to '-' */
+ for (p= optname; *p; p++)
+ if (*p == '_')
+ *p= '-';
+
+ options->name= optname;
+ options->comment= opt->comment;
+ options->app_type= opt;
+ options->id= (options-1)->id + 1;
+
+ if (opt->flags & PLUGIN_VAR_THDLOCAL)
+ *(int*)(opt + 1)= offset= v->offset;
+
+ plugin_opt_set_limits(options, opt);
+
+ if ((opt->flags & PLUGIN_VAR_TYPEMASK) != PLUGIN_VAR_ENUM &&
+ (opt->flags & PLUGIN_VAR_TYPEMASK) != PLUGIN_VAR_SET)
+ {
+ if (opt->flags & PLUGIN_VAR_THDLOCAL)
+ options->value= options->u_max_value= (gptr*)
+ (global_system_variables.dynamic_variables_ptr + offset);
+ else
+ options->value= options->u_max_value= *(gptr**) (opt + 1);
+ }
+
+ options[1]= options[0];
+ options[1].name= p= (char*) alloc_root(mem_root, optnamelen + 8);
+ options[1].comment= 0; // hidden
+ strxmov(p, "plugin-", optname, NullS);
+
+ options+= 2;
+ }
+
+ DBUG_RETURN(0);
+}
+
+
+static my_option *construct_help_options(MEM_ROOT *mem_root,
+ struct st_plugin_int *p)
+{
+ st_mysql_sys_var **opt;
+ my_option *opts;
+ my_bool dummy, can_disable;
+ my_bool *dummy2= &dummy;
+ uint count= EXTRA_OPTIONS;
+ DBUG_ENTER("construct_help_options");
+
+ for (opt= p->plugin->system_vars; opt && *opt; opt++, count+= 2);
+
+ if (!(opts= (my_option*) alloc_root(mem_root, sizeof(my_option) * count)))
+ DBUG_RETURN(NULL);
+
+ bzero(opts, sizeof(my_option) * count);
+
+ dummy= TRUE; /* plugin is enabled. */
+
+ can_disable=
+ my_strcasecmp(&my_charset_latin1, p->name.str, "MyISAM") &&
+ my_strcasecmp(&my_charset_latin1, p->name.str, "MEMORY");
+
+ if (construct_options(mem_root, p, opts, &dummy2, can_disable))
+ DBUG_RETURN(NULL);
+
+ DBUG_RETURN(opts);
+}
+
+
+/*
+ SYNOPSIS
+ test_plugin_options()
+ tmp_root temporary scratch space
+ plugin internal plugin structure
+ argc user supplied arguments
+ argv user supplied arguments
+ default_enabled default plugin enable status
+ RETURNS:
+ 0 SUCCESS - plugin should be enabled/loaded
+ NOTE:
+ Requires that a write-lock is held on LOCK_system_variables_hash
+*/
+static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp,
+ int *argc, char **argv, my_bool default_enabled)
+{
+ struct sys_var_chain chain= { NULL, NULL };
+ my_bool enabled_saved= default_enabled, can_disable;
+ my_bool *enabled= &default_enabled;
+ MEM_ROOT *mem_root= alloc_root_inited(&tmp->mem_root) ?
+ &tmp->mem_root : &plugin_mem_root;
+ st_mysql_sys_var **opt;
+ my_option *opts;
+ char *p, *varname;
+ int error;
+ st_mysql_sys_var *o;
+ sys_var *v;
+ struct st_bookmark *var;
+ uint len, count= EXTRA_OPTIONS;
+ DBUG_ENTER("test_plugin_options");
+ DBUG_ASSERT(tmp->plugin && tmp->name.str);
+
+ for (opt= tmp->plugin->system_vars; opt && *opt; opt++)
+ count+= 2; /* --{plugin}-{optname} and --plugin-{plugin}-{optname} */
+
+ can_disable=
+ my_strcasecmp(&my_charset_latin1, tmp->name.str, "MyISAM") &&
+ my_strcasecmp(&my_charset_latin1, tmp->name.str, "MEMORY");
+
+ if (count > EXTRA_OPTIONS || (*argc > 1))
+ {
+ if (!(opts= (my_option*) alloc_root(tmp_root, sizeof(my_option) * count)))
+ {
+ sql_print_error("Out of memory for plugin '%s'.", tmp->name.str);
+ DBUG_RETURN(-1);
+ }
+ bzero(opts, sizeof(my_option) * count);
+
+ if (construct_options(tmp_root, tmp, opts, &enabled, can_disable))
+ {
+ sql_print_error("Bad options for plugin '%s'.", tmp->name.str);
+ DBUG_RETURN(-1);
+ }
+
+ error= handle_options(argc, &argv, opts, get_one_option);
+ (*argc)++; /* add back one for the program name */
+
+ if (error)
+ {
+ sql_print_error("Parsing options for plugin '%s' failed.",
+ tmp->name.str);
+ DBUG_RETURN(error);
+ }
+ }
+
+ if (!*enabled && !can_disable)
+ {
+ sql_print_warning("Plugin '%s' cannot be disabled", tmp->name.str);
+ *enabled= TRUE;
+ }
+
+ if (*enabled)
+ {
+ for (opt= tmp->plugin->system_vars; opt && *opt; opt++)
+ {
+ if (((o= *opt)->flags & PLUGIN_VAR_NOSYSVAR))
+ continue;
+
+ if ((var= find_bookmark(tmp->name.str, o->name, o->flags)))
+ v= new (mem_root) sys_var_pluginvar(var->key + 1, o);
+ else
+ {
+ len= tmp->name.length + strlen(o->name) + 2;
+ varname= (char*) alloc_root(mem_root, len);
+ strxmov(varname, tmp->name.str, "-", o->name, NullS);
+ my_casedn_str(&my_charset_latin1, varname);
+
+ for (p= varname; *p; p++)
+ if (*p == '-')
+ *p= '_';
+
+ v= new (mem_root) sys_var_pluginvar(varname, o);
+ }
+ DBUG_ASSERT(v); /* check that an object was actually constructed */
+
+ /*
+ Add to the chain of variables.
+ Done like this for easier debugging so that the
+ pointer to v is not lost on optimized builds.
+ */
+ v->chain_sys_var(&chain);
+ }
+ if (chain.first)
+ {
+ chain.last->next = NULL;
+ if (mysql_add_sys_var_chain(chain.first, NULL))
+ {
+ sql_print_error("Plugin '%s' has conflicting system variables",
+ tmp->name.str);
+ DBUG_RETURN(1);
+ }
+ tmp->system_vars= chain.first;
+ }
+ DBUG_RETURN(0);
+ }
+
+ if (enabled_saved)
+ sql_print_information("Plugin '%s' disabled by command line option",
+ tmp->name.str);
+ DBUG_RETURN(1);
+}
+
+
+/****************************************************************************
+ Help Verbose text with Plugin System Variables
+****************************************************************************/
+
+static int option_cmp(my_option *a, my_option *b)
+{
+ return my_strcasecmp(&my_charset_latin1, a->name, b->name);
+}
+
+
+void my_print_help_inc_plugins(my_option *main_options, uint size)
+{
+ DYNAMIC_ARRAY all_options;
+ struct st_plugin_int *p;
+ MEM_ROOT mem_root;
+ my_option *opt;
+
+ init_alloc_root(&mem_root, 4096, 4096);
+ my_init_dynamic_array(&all_options, sizeof(my_option), size, size/4);
+
+ if (initialized)
+ for (uint idx= 0; idx < plugin_array.elements; idx++)
+ {
+ p= dynamic_element(&plugin_array, idx, struct st_plugin_int *);
+
+ if (!p->plugin->system_vars ||
+ !(opt= construct_help_options(&mem_root, p)))
+ continue;
+
+ /* Only options with a non-NULL comment are displayed in help text */
+ for (;opt->id; opt++)
+ if (opt->comment)
+ insert_dynamic(&all_options, (gptr) opt);
+ }
+
+ for (;main_options->id; main_options++)
+ insert_dynamic(&all_options, (gptr) main_options);
+
+ sort_dynamic(&all_options, (qsort_cmp) option_cmp);
+
+ /* main_options now points to the empty option terminator */
+ insert_dynamic(&all_options, (gptr) main_options);
+
+ my_print_help((my_option*) all_options.buffer);
+ my_print_variables((my_option*) all_options.buffer);
+
+ delete_dynamic(&all_options);
+ free_root(&mem_root, MYF(0));
+}
+
diff --git a/sql/sql_plugin.h b/sql/sql_plugin.h
index d86d9332a92..70ce21a64da 100644
--- a/sql/sql_plugin.h
+++ b/sql/sql_plugin.h
@@ -16,6 +16,17 @@
#ifndef _sql_plugin_h
#define _sql_plugin_h
+class sys_var;
+
+/*
+ the following flags are valid for plugin_init()
+*/
+#define PLUGIN_INIT_SKIP_DYNAMIC_LOADING 1
+#define PLUGIN_INIT_SKIP_PLUGIN_TABLE 2
+#define PLUGIN_INIT_SKIP_INITIALIZATION 4
+
+#define INITIAL_LEX_PLUGIN_LIST_SIZE 16
+
/*
the following #define adds server-only members to enum_mysql_show_type,
that is defined in plugin.h
@@ -41,6 +52,7 @@ typedef struct st_mysql_show_var SHOW_VAR;
#define PLUGIN_IS_DELETED 2
#define PLUGIN_IS_UNINITIALIZED 4
#define PLUGIN_IS_READY 8
+#define PLUGIN_IS_DYING 16
/* A handle for the dynamic library containing a plugin or plugins. */
@@ -63,25 +75,64 @@ struct st_plugin_int
uint state;
uint ref_count; /* number of threads using the plugin */
void *data; /* plugin type specific, e.g. handlerton */
+ MEM_ROOT mem_root; /* memory for dynamic plugin structures */
+ sys_var *system_vars; /* server variables for this plugin */
};
+
+/*
+ See intern_plugin_lock() for the explanation for the
+ conditionally defined plugin_ref type
+*/
+#ifdef DBUG_OFF
+typedef struct st_plugin_int *plugin_ref;
+#define plugin_decl(pi) ((pi)->plugin)
+#define plugin_dlib(pi) ((pi)->plugin_dl)
+#define plugin_data(pi,cast) ((cast)((pi)->data))
+#define plugin_name(pi) (&((pi)->name))
+#define plugin_state(pi) ((pi)->state)
+#define plugin_equals(p1,p2) ((p1) == (p2))
+#else
+typedef struct st_plugin_int **plugin_ref;
+#define plugin_decl(pi) ((pi)[0]->plugin)
+#define plugin_dlib(pi) ((pi)[0]->plugin_dl)
+#define plugin_data(pi,cast) ((cast)((pi)[0]->data))
+#define plugin_name(pi) (&((pi)[0]->name))
+#define plugin_state(pi) ((pi)[0]->state)
+#define plugin_equals(p1,p2) ((p1) && (p2) && (p1)[0] == (p2)[0])
+#endif
+
typedef int (*plugin_type_init)(struct st_plugin_int *);
+extern char *opt_plugin_load;
extern char *opt_plugin_dir_ptr;
extern char opt_plugin_dir[FN_REFLEN];
extern const LEX_STRING plugin_type_names[];
-extern int plugin_init(int);
+
+extern int plugin_init(int *argc, char **argv, int init_flags);
extern void plugin_shutdown(void);
-extern my_bool plugin_is_ready(const LEX_STRING *name, int type);
-extern st_plugin_int *plugin_lock(const LEX_STRING *name, int type);
-extern void plugin_unlock(struct st_plugin_int *plugin);
-extern my_bool mysql_install_plugin(THD *thd, const LEX_STRING *name, const LEX_STRING *dl);
-extern my_bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name);
+extern void my_print_help_inc_plugins(struct my_option *options, uint size);
+extern bool plugin_is_ready(const LEX_STRING *name, int type);
+#define my_plugin_lock_by_name(A,B,C) plugin_lock_by_name(A,B,C CALLER_INFO)
+#define my_plugin_lock_by_name_ci(A,B,C) plugin_lock_by_name(A,B,C ORIG_CALLER_INFO)
+#define my_plugin_lock(A,B) plugin_lock(A,B CALLER_INFO)
+#define my_plugin_lock_ci(A,B) plugin_lock(A,B ORIG_CALLER_INFO)
+extern plugin_ref plugin_lock(THD *thd, plugin_ref *ptr CALLER_INFO_PROTO);
+extern plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name,
+ int type CALLER_INFO_PROTO);
+extern void plugin_unlock(THD *thd, plugin_ref plugin);
+extern void plugin_unlock_list(THD *thd, plugin_ref *list, uint count);
+extern bool mysql_install_plugin(THD *thd, const LEX_STRING *name,
+ const LEX_STRING *dl);
+extern bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name);
+extern bool plugin_register_builtin(struct st_mysql_plugin *plugin);
+extern void plugin_thdvar_init(THD *thd);
+extern void plugin_thdvar_cleanup(THD *thd);
typedef my_bool (plugin_foreach_func)(THD *thd,
- st_plugin_int *plugin,
+ plugin_ref plugin,
void *arg);
#define plugin_foreach(A,B,C,D) plugin_foreach_with_mask(A,B,C,PLUGIN_IS_READY,D)
-extern my_bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
- int type, uint state_mask, void *arg);
+extern bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
+ int type, uint state_mask, void *arg);
#endif
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 73f315b2441..ae8d03e14ee 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -1164,8 +1164,9 @@ static int mysql_test_update(Prepared_statement *stmt,
goto error;
#ifndef NO_EMBEDDED_ACCESS_CHECKS
- /* TABLE_LIST contain right privilages request */
- want_privilege= table_list->grant.want_privilege;
+ /* Force privilege re-checking for views after they have been opened. */
+ want_privilege= (table_list->view ? UPDATE_ACL :
+ table_list->grant.want_privilege);
#endif
if (mysql_prepare_update(thd, table_list, &select->where,
@@ -1492,8 +1493,21 @@ static bool mysql_test_create_table(Prepared_statement *stmt)
if (select_lex->item_list.elements)
{
+ if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE))
+ {
+ lex->link_first_table_back(create_table, link_to_local);
+ create_table->create= TRUE;
+ }
+
+ if (open_normal_and_derived_tables(stmt->thd, lex->query_tables, 0))
+ DBUG_RETURN(TRUE);
+
+ if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE))
+ create_table= lex->unlink_first_table(&link_to_local);
+
select_lex->context.resolve_in_select_list= TRUE;
- res= select_like_stmt_test_with_open(stmt, tables, 0, 0);
+
+ res= select_like_stmt_test(stmt, 0, 0);
}
/* put tables back for PS rexecuting */
@@ -1794,6 +1808,9 @@ static bool check_prepared_statement(Prepared_statement *stmt,
case SQLCOM_KILL:
break;
+ case SQLCOM_PREPARE:
+ case SQLCOM_EXECUTE:
+ case SQLCOM_DEALLOCATE_PREPARE:
default:
/*
Trivial check of all status commands. This is easier than having
@@ -2851,10 +2868,14 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len)
old_stmt_arena= thd->stmt_arena;
thd->stmt_arena= this;
- lex_start(thd, thd->query, thd->query_length);
- lex->stmt_prepare_mode= TRUE;
- error= MYSQLparse((void *)thd) || thd->is_fatal_error ||
+ Lex_input_stream lip(thd, thd->query, thd->query_length);
+ lip.stmt_prepare_mode= TRUE;
+ thd->m_lip= &lip;
+ lex_start(thd);
+ int err= MYSQLparse((void *)thd);
+
+ error= err || thd->is_fatal_error ||
thd->net.report_error || init_param_array(this);
/*
diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc
index 596b13b5123..6125a00c8e1 100644
--- a/sql/sql_repl.cc
+++ b/sql/sql_repl.cc
@@ -1609,6 +1609,149 @@ int log_loaded_block(IO_CACHE* file)
return 0;
}
+/*
+ Replication System Variables
+*/
+
+class sys_var_slave_skip_counter :public sys_var
+{
+public:
+ sys_var_slave_skip_counter(sys_var_chain *chain, const char *name_arg)
+ :sys_var(name_arg)
+ { chain_sys_var(chain); }
+ bool check(THD *thd, set_var *var);
+ bool update(THD *thd, set_var *var);
+ bool check_type(enum_var_type type) { return type != OPT_GLOBAL; }
+ /*
+ We can't retrieve the value of this, so we don't have to define
+ type() or value_ptr()
+ */
+};
+
+class sys_var_sync_binlog_period :public sys_var_long_ptr
+{
+public:
+ sys_var_sync_binlog_period(sys_var_chain *chain, const char *name_arg,
+ ulong *value_ptr)
+ :sys_var_long_ptr(chain, name_arg,value_ptr) {}
+ bool update(THD *thd, set_var *var);
+};
+
+static sys_var_chain vars = { NULL, NULL };
+
+static sys_var_bool_ptr sys_relay_log_purge(&vars, "relay_log_purge",
+ &relay_log_purge);
+static sys_var_long_ptr sys_slave_net_timeout(&vars, "slave_net_timeout",
+ &slave_net_timeout);
+static sys_var_long_ptr sys_slave_trans_retries(&vars, "slave_transaction_retries",
+ &slave_trans_retries);
+static sys_var_sync_binlog_period sys_sync_binlog_period(&vars, "sync_binlog", &sync_binlog_period);
+static sys_var_slave_skip_counter sys_slave_skip_counter(&vars, "sql_slave_skip_counter");
+
+static int show_slave_skip_errors(THD *thd, SHOW_VAR *var, char *buff);
+
+
+static SHOW_VAR fixed_vars[]= {
+ {"log_slave_updates", (char*) &opt_log_slave_updates, SHOW_MY_BOOL},
+ {"relay_log_space_limit", (char*) &relay_log_space_limit, SHOW_LONGLONG},
+ {"slave_load_tmpdir", (char*) &slave_load_tmpdir, SHOW_CHAR_PTR},
+ {"slave_skip_errors", (char*) &show_slave_skip_errors, SHOW_FUNC},
+};
+
+static int show_slave_skip_errors(THD *thd, SHOW_VAR *var, char *buff)
+{
+ var->type=SHOW_CHAR;
+ var->value= buff;
+ if (!use_slave_mask || bitmap_is_clear_all(&slave_error_mask))
+ {
+ var->value= const_cast<char *>("OFF");
+ }
+ else if (bitmap_is_set_all(&slave_error_mask))
+ {
+ var->value= const_cast<char *>("ALL");
+ }
+ else
+ {
+ /* 10 is enough assuming errors are max 4 digits */
+ int i;
+ var->value= buff;
+ for (i= 1;
+ i < MAX_SLAVE_ERROR &&
+ (buff - var->value) < SHOW_VAR_FUNC_BUFF_SIZE;
+ i++)
+ {
+ if (bitmap_is_set(&slave_error_mask, i))
+ {
+ buff= int10_to_str(i, buff, 10);
+ *buff++= ',';
+ }
+ }
+ if (var->value != buff)
+ buff--; // Remove last ','
+ if (i < MAX_SLAVE_ERROR)
+ buff= strmov(buff, "..."); // Couldn't show all errors
+ *buff=0;
+ }
+ return 0;
+}
+
+bool sys_var_slave_skip_counter::check(THD *thd, set_var *var)
+{
+ int result= 0;
+ pthread_mutex_lock(&LOCK_active_mi);
+ pthread_mutex_lock(&active_mi->rli.run_lock);
+ if (active_mi->rli.slave_running)
+ {
+ my_message(ER_SLAVE_MUST_STOP, ER(ER_SLAVE_MUST_STOP), MYF(0));
+ result=1;
+ }
+ pthread_mutex_unlock(&active_mi->rli.run_lock);
+ pthread_mutex_unlock(&LOCK_active_mi);
+ var->save_result.ulong_value= (ulong) var->value->val_int();
+ return result;
+}
+
+
+bool sys_var_slave_skip_counter::update(THD *thd, set_var *var)
+{
+ pthread_mutex_lock(&LOCK_active_mi);
+ pthread_mutex_lock(&active_mi->rli.run_lock);
+ /*
+ The following test should normally never be true as we test this
+ in the check function; To be safe against multiple
+ SQL_SLAVE_SKIP_COUNTER request, we do the check anyway
+ */
+ if (!active_mi->rli.slave_running)
+ {
+ pthread_mutex_lock(&active_mi->rli.data_lock);
+ active_mi->rli.slave_skip_counter= var->save_result.ulong_value;
+ pthread_mutex_unlock(&active_mi->rli.data_lock);
+ }
+ pthread_mutex_unlock(&active_mi->rli.run_lock);
+ pthread_mutex_unlock(&LOCK_active_mi);
+ return 0;
+}
+
+
+bool sys_var_sync_binlog_period::update(THD *thd, set_var *var)
+{
+ sync_binlog_period= (ulong) var->save_result.ulonglong_value;
+ return 0;
+}
+
+int init_replication_sys_vars()
+{
+ mysql_append_static_vars(fixed_vars, sizeof(fixed_vars) / sizeof(SHOW_VAR));
+
+ if (mysql_add_sys_var_chain(vars.first, my_long_options))
+ {
+ /* should not happen */
+ fprintf(stderr, "failed to initialize replication system variables");
+ unireg_abort(1);
+ }
+ return 0;
+}
+
#endif /* HAVE_REPLICATION */
diff --git a/sql/sql_repl.h b/sql/sql_repl.h
index b106391245d..da50d47c60d 100644
--- a/sql/sql_repl.h
+++ b/sql/sql_repl.h
@@ -67,6 +67,7 @@ typedef struct st_load_file_info
} LOAD_FILE_INFO;
int log_loaded_block(IO_CACHE* file);
+int init_replication_sys_vars();
#endif /* HAVE_REPLICATION */
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index e67495a08f6..660318b6044 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -988,6 +988,12 @@ JOIN::optimize()
}
}
+ if (conds &&!outer_join && const_table_map != found_const_table_map &&
+ (select_options & SELECT_DESCRIBE) &&
+ select_lex->master_unit() == &thd->lex->unit) // upper level SELECT
+ {
+ conds=new Item_int((longlong) 0,1); // Always false
+ }
if (make_join_select(this, select, conds))
{
zero_result_cause=
@@ -1436,14 +1442,13 @@ JOIN::optimize()
}
}
- if (select_lex->uncacheable && !is_top_level_join())
- {
- /* If this join belongs to an uncacheable subquery */
- if (!(tmp_join= (JOIN*)thd->alloc(sizeof(JOIN))))
- DBUG_RETURN(-1);
- error= 0; // Ensure that tmp_join.error= 0
- restore_tmp();
- }
+ /*
+ If this join belongs to an uncacheable subquery save
+ the original join
+ */
+ if (select_lex->uncacheable && !is_top_level_join() &&
+ init_save_join_tab())
+ DBUG_RETURN(-1); /* purecov: inspected */
}
error= 0;
@@ -1505,6 +1510,27 @@ JOIN::reinit()
DBUG_RETURN(0);
}
+/**
+ @brief Save the original join layout
+
+ @details Saves the original join layout so it can be reused in
+ re-execution and for EXPLAIN.
+
+ @return Operation status
+ @retval 0 success.
+ @retval 1 error occurred.
+*/
+
+bool
+JOIN::init_save_join_tab()
+{
+ if (!(tmp_join= (JOIN*)thd->alloc(sizeof(JOIN))))
+ return 1; /* purecov: inspected */
+ error= 0; // Ensure that tmp_join.error= 0
+ restore_tmp();
+ return 0;
+}
+
bool
JOIN::save_join_tab()
@@ -4249,7 +4275,7 @@ best_access_path(JOIN *join,
!(s->quick && best_key && s->quick->index == best_key->key && // (2)
best_max_key_part >= s->table->quick_key_parts[best_key->key]) &&// (2)
!((s->table->file->ha_table_flags() & HA_TABLE_SCAN_ON_INDEX) && // (3)
- ! s->table->covering_keys.is_clear_all() && best_key) && // (3)
+ ! s->table->covering_keys.is_clear_all() && best_key && !s->quick) &&// (3)
!(s->table->force_index && best_key && !s->quick)) // (4)
{ // Check full join
ha_rows rnd_records= s->found_records;
@@ -5873,6 +5899,12 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
tab->ref.key= -1;
tab->ref.key_parts=0; // Don't use ref key.
join->best_positions[i].records_read= rows2double(tab->quick->records);
+ /*
+ We will use join cache here : prevent sorting of the first
+ table only and sort at the end.
+ */
+ if (i != join->const_tables && join->tables > join->const_tables + 1)
+ join->full_join= 1;
}
tmp= NULL;
@@ -6155,11 +6187,14 @@ make_join_readinfo(JOIN *join, ulonglong options)
disable join cache because it will change the ordering of the results.
Code handles sort table that is at any location (not only first after
the const tables) despite the fact that it's currently prohibited.
+ We must disable join cache if the first non-const table alone is
+ ordered. If there is a temp table the ordering is done as a last
+ operation and doesn't prevent join cache usage.
*/
- if (!ordered_set &&
- (table == join->sort_by_table &&
+ if (!ordered_set && !join->need_tmp &&
+ ((table == join->sort_by_table &&
(!join->order || join->skip_sort_order)) ||
- (join->sort_by_table == (TABLE *) 1 && i != join->const_tables))
+ (join->sort_by_table == (TABLE *) 1 && i != join->const_tables)))
ordered_set= 1;
tab->sorted= sorted;
@@ -9104,8 +9139,7 @@ Field *create_tmp_field_for_schema(THD *thd, Item *item, TABLE *table)
if (item->field_type() == MYSQL_TYPE_VARCHAR)
{
Field *field;
- if (item->max_length > MAX_FIELD_VARCHARLENGTH /
- item->collation.collation->mbmaxlen)
+ if (item->max_length > MAX_FIELD_VARCHARLENGTH)
field= new Field_blob(item->max_length, item->maybe_null,
item->name, item->collation.collation);
else
@@ -9623,12 +9657,14 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
share->fields= field_count;
/* If result table is small; use a heap */
+ /* future: storage engine selection can be made dynamic? */
if (blob_count || using_unique_constraint ||
(select_options & (OPTION_BIG_TABLES | SELECT_SMALL_RESULT)) ==
OPTION_BIG_TABLES || (select_options & TMP_TABLE_FORCE_MYISAM))
{
+ share->db_plugin= ha_lock_engine(0, myisam_hton);
table->file= get_new_handler(share, &table->mem_root,
- share->db_type= myisam_hton);
+ share->db_type());
if (group &&
(param->group_parts > table->file->max_key_parts() ||
param->group_length > table->file->max_key_length()))
@@ -9636,8 +9672,9 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
}
else
{
+ share->db_plugin= ha_lock_engine(0, heap_hton);
table->file= get_new_handler(share, &table->mem_root,
- share->db_type= heap_hton);
+ share->db_type());
}
if (!table->file)
goto err;
@@ -9799,7 +9836,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
if (thd->variables.tmp_table_size == ~ (ulonglong) 0) // No limit
share->max_rows= ~(ha_rows) 0;
else
- share->max_rows= (ha_rows) (((share->db_type == heap_hton) ?
+ share->max_rows= (ha_rows) (((share->db_type() == heap_hton) ?
min(thd->variables.tmp_table_size,
thd->variables.max_heap_table_size) :
thd->variables.tmp_table_size) /
@@ -9947,7 +9984,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
if (thd->is_fatal_error) // If end of memory
goto err; /* purecov: inspected */
share->db_record_offset= 1;
- if (share->db_type == myisam_hton)
+ if (share->db_type() == myisam_hton)
{
if (create_myisam_tmp_table(table,param,select_options))
goto err;
@@ -10254,6 +10291,8 @@ free_tmp_table(THD *thd, TABLE *entry)
if (entry->temp_pool_slot != MY_BIT_NONE)
bitmap_lock_clear_bit(&temp_pool, entry->temp_pool_slot);
+ plugin_unlock(0, entry->s->db_plugin);
+
free_root(&own_root, MYF(0)); /* the table is allocated in its own root */
thd->proc_info=save_proc_info;
@@ -10273,7 +10312,7 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param,
int write_err;
DBUG_ENTER("create_myisam_from_heap");
- if (table->s->db_type != heap_hton ||
+ if (table->s->db_type() != heap_hton ||
error != HA_ERR_RECORD_FILE_FULL)
{
table->file->print_error(error,MYF(0));
@@ -10282,9 +10321,9 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param,
new_table= *table;
share= *table->s;
new_table.s= &share;
- new_table.s->db_type= myisam_hton;
+ new_table.s->db_plugin= ha_lock_engine(thd, myisam_hton);
if (!(new_table.file= get_new_handler(&share, &new_table.mem_root,
- myisam_hton)))
+ new_table.s->db_type())))
DBUG_RETURN(1); // End of memory
save_proc_info=thd->proc_info;
@@ -10342,9 +10381,12 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param,
(void) table->file->delete_table(table->s->table_name.str);
delete table->file;
table->file=0;
+ plugin_unlock(0, table->s->db_plugin);
+ share.db_plugin= my_plugin_lock(0, &share.db_plugin);
new_table.s= table->s; // Keep old share
*table= new_table;
*table->s= share;
+
table->file->change_table_ptr(table, table->s);
table->use_all_columns();
if (save_proc_info)
@@ -10768,7 +10810,6 @@ static enum_nested_loop_state
evaluate_join_record(JOIN *join, JOIN_TAB *join_tab,
int error, my_bool *report_error)
{
- bool not_exists_optimize= join_tab->table->reginfo.not_exists_optimize;
bool not_used_in_distinct=join_tab->not_used_in_distinct;
ha_rows found_records=join->found_records;
COND *select_cond= join_tab->select_cond;
@@ -10805,6 +10846,8 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab,
first_unmatched->found= 1;
for (JOIN_TAB *tab= first_unmatched; tab <= join_tab; tab++)
{
+ if (tab->table->reginfo.not_exists_optimize)
+ return NESTED_LOOP_NO_MORE_ROWS;
/* Check all predicates that has just been activated. */
/*
Actually all predicates non-guarded by first_unmatched->found
@@ -10850,8 +10893,6 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab,
if (found)
{
enum enum_nested_loop_state rc;
- if (not_exists_optimize)
- return NESTED_LOOP_NO_MORE_ROWS;
/* A match from join_tab is found for the current partial join. */
rc= (*join_tab->next_select)(join, join_tab+1, 0);
if (rc != NESTED_LOOP_OK && rc != NESTED_LOOP_NO_MORE_ROWS)
@@ -12638,6 +12679,12 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
uint nr;
key_map keys;
+ /*
+ filesort() and join cache are usually faster than reading in
+ index order and not using join cache
+ */
+ if (tab->type == JT_ALL && tab->join->tables > tab->join->const_tables + 1)
+ DBUG_RETURN(0);
/*
If not used with LIMIT, only use keys if the whole query can be
resolved with a key; This is because filesort() is usually faster than
@@ -12932,7 +12979,7 @@ remove_duplicates(JOIN *join, TABLE *entry,List<Item> &fields, Item *having)
free_io_cache(entry); // Safety
entry->file->info(HA_STATUS_VARIABLE);
- if (entry->s->db_type == heap_hton ||
+ if (entry->s->db_type() == heap_hton ||
(!entry->s->blob_fields &&
((ALIGN_SIZE(reclength) + HASH_OVERHEAD) * entry->file->stats.records <
thd->variables.sortbuff_size)))
@@ -15490,6 +15537,8 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
break;
}
}
+ if (tab->next_select == sub_select_cache)
+ extra.append(STRING_WITH_LEN("; Using join cache"));
/* Skip initial "; "*/
const char *str= extra.ptr();
diff --git a/sql/sql_select.h b/sql/sql_select.h
index 4b8d07ff88b..290a0f5d992 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -160,6 +160,13 @@ typedef struct st_join_table {
Read_record_func read_first_record;
Next_select_func next_select;
READ_RECORD read_record;
+ /*
+ Currently the following two fields are used only for a [NOT] IN subquery
+ if it is executed by an alternative full table scan when the left operand of
+ the subquery predicate is evaluated to NULL.
+ */
+ Read_record_func save_read_first_record;/* to save read_first_record */
+ int (*save_read_record) (READ_RECORD *);/* to save read_record.read_record */
double worst_seeks;
key_map const_keys; /* Keys with constant part */
key_map checked_keys; /* Keys checked in find_best */
@@ -473,6 +480,7 @@ public:
void cleanup(bool full);
void clear();
bool save_join_tab();
+ bool init_save_join_tab();
bool send_row_on_empty_set()
{
return (do_send_rows && tmp_table_param.sum_func_count != 0 &&
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 09a00901dda..c9687e36699 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -79,24 +79,24 @@ append_algorithm(TABLE_LIST *table, String *buff);
** List all table types supported
***************************************************************************/
-static my_bool show_handlerton(THD *thd, st_plugin_int *plugin,
+static my_bool show_handlerton(THD *thd, plugin_ref plugin,
void *arg)
{
handlerton *default_type= (handlerton *) arg;
Protocol *protocol= thd->protocol;
- handlerton *hton= (handlerton *)plugin->data;
+ handlerton *hton= plugin_data(plugin, handlerton *);
if (!(hton->flags & HTON_HIDDEN))
{
protocol->prepare_for_resend();
- protocol->store(plugin->name.str, plugin->name.length,
+ protocol->store(plugin_name(plugin)->str, plugin_name(plugin)->length,
system_charset_info);
const char *option_name= show_comp_option_name[(int) hton->state];
if (hton->state == SHOW_OPTION_YES && default_type == hton)
option_name= "DEFAULT";
protocol->store(option_name, system_charset_info);
- protocol->store(plugin->plugin->descr, system_charset_info);
+ protocol->store(plugin_decl(plugin)->descr, system_charset_info);
protocol->store(hton->commit ? "YES" : "NO", system_charset_info);
protocol->store(hton->prepare ? "YES" : "NO", system_charset_info);
protocol->store(hton->savepoint_set ? "YES" : "NO", system_charset_info);
@@ -124,7 +124,7 @@ bool mysqld_show_storage_engines(THD *thd)
DBUG_RETURN(TRUE);
if (plugin_foreach(thd, show_handlerton,
- MYSQL_STORAGE_ENGINE_PLUGIN, thd->variables.table_type))
+ MYSQL_STORAGE_ENGINE_PLUGIN, ha_default_handlerton(thd)))
DBUG_RETURN(TRUE);
send_eof(thd);
@@ -136,24 +136,26 @@ static int make_version_string(char *buf, int buf_length, uint version)
return my_snprintf(buf, buf_length, "%d.%d", version>>8,version&0xff);
}
-static my_bool show_plugins(THD *thd, st_plugin_int *plugin,
+static my_bool show_plugins(THD *thd, plugin_ref plugin,
void *arg)
{
TABLE *table= (TABLE*) arg;
- struct st_mysql_plugin *plug= plugin->plugin;
+ struct st_mysql_plugin *plug= plugin_decl(plugin);
+ struct st_plugin_dl *plugin_dl= plugin_dlib(plugin);
CHARSET_INFO *cs= system_charset_info;
char version_buf[20];
restore_record(table, s->default_values);
- table->field[0]->store(plugin->name.str, plugin->name.length, cs);
+ table->field[0]->store(plugin_name(plugin)->str,
+ plugin_name(plugin)->length, cs);
table->field[1]->store(version_buf,
make_version_string(version_buf, sizeof(version_buf), plug->version),
cs);
- switch (plugin->state) {
+ switch (plugin_state(plugin)) {
/* case PLUGIN_IS_FREED: does not happen */
case PLUGIN_IS_DELETED:
table->field[2]->store(STRING_WITH_LEN("DELETED"), cs);
@@ -175,14 +177,13 @@ static my_bool show_plugins(THD *thd, st_plugin_int *plugin,
make_version_string(version_buf, sizeof(version_buf),
*(uint *)plug->info), cs);
- if (plugin->plugin_dl)
+ if (plugin_dl)
{
- table->field[5]->store(plugin->plugin_dl->dl.str,
- plugin->plugin_dl->dl.length, cs);
+ table->field[5]->store(plugin_dl->dl.str, plugin_dl->dl.length, cs);
table->field[5]->set_notnull();
table->field[6]->store(version_buf,
make_version_string(version_buf, sizeof(version_buf),
- plugin->plugin_dl->version),
+ plugin_dl->version),
cs);
table->field[6]->set_notnull();
}
@@ -1239,9 +1240,9 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
store_key_options(thd, packet, table, key_info);
if (key_info->parser)
{
+ LEX_STRING *parser_name= plugin_name(key_info->parser);
packet->append(STRING_WITH_LEN(" /*!50100 WITH PARSER "));
- append_identifier(thd, packet, key_info->parser->name.str,
- key_info->parser->name.length);
+ append_identifier(thd, packet, parser_name->str, parser_name->length);
packet->append(STRING_WITH_LEN(" */ "));
}
}
@@ -1936,6 +1937,18 @@ void init_status_vars()
sort_dynamic(&all_status_vars, show_var_cmp);
}
+void reset_status_vars()
+{
+ SHOW_VAR *ptr= (SHOW_VAR*) all_status_vars.buffer;
+ SHOW_VAR *last= ptr + all_status_vars.elements;
+ for (; ptr < last; ptr++)
+ {
+ /* Note that SHOW_LONG_NOFLUSH variables are not reset */
+ if (ptr->type == SHOW_LONG)
+ *(ulong*) ptr->value= 0;
+ }
+}
+
/*
catch-all cleanup function, cleans up everything no matter what
@@ -2066,6 +2079,8 @@ static bool show_status_array(THD *thd, const char *wild,
char *value=var->value;
const char *pos, *end; // We assign a lot of const's
+ pthread_mutex_lock(&LOCK_global_system_variables);
+
if (show_type == SHOW_SYS)
{
show_type= ((sys_var*) value)->show_type();
@@ -2148,6 +2163,9 @@ static bool show_status_array(THD *thd, const char *wild,
system_charset_info);
table->field[1]->store(pos, (uint32) (end - pos), system_charset_info);
table->field[1]->set_notnull();
+
+ pthread_mutex_unlock(&LOCK_global_system_variables);
+
if (schema_table_store_record(thd, table))
DBUG_RETURN(TRUE);
}
@@ -2457,13 +2475,13 @@ struct st_add_schema_table
const char *wild;
};
-static my_bool add_schema_table(THD *thd, st_plugin_int *plugin,
+static my_bool add_schema_table(THD *thd, plugin_ref plugin,
void* p_data)
{
st_add_schema_table *data= (st_add_schema_table *)p_data;
List<char> *file_list= data->files;
const char *wild= data->wild;
- ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data;
+ ST_SCHEMA_TABLE *schema_table= plugin_data(plugin, ST_SCHEMA_TABLE *);
DBUG_ENTER("add_schema_table");
if (schema_table->hidden)
@@ -3011,7 +3029,7 @@ static int get_schema_tables_record(THD *thd, struct st_table_list *tables,
ha_row_type[(uint) share->row_type],
NullS);
#ifdef WITH_PARTITION_STORAGE_ENGINE
- if (show_table->s->db_type == partition_hton &&
+ if (show_table->s->db_type() == partition_hton &&
show_table->part_info != NULL &&
show_table->part_info->no_parts > 0)
ptr= strmov(ptr, " partitioned");
@@ -3286,19 +3304,20 @@ int fill_schema_charsets(THD *thd, TABLE_LIST *tables, COND *cond)
}
-static my_bool iter_schema_engines(THD *thd, st_plugin_int *plugin,
+static my_bool iter_schema_engines(THD *thd, plugin_ref plugin,
void *ptable)
{
TABLE *table= (TABLE *) ptable;
- handlerton *hton= (handlerton *)plugin->data;
+ handlerton *hton= plugin_data(plugin, handlerton *);
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
CHARSET_INFO *scs= system_charset_info;
DBUG_ENTER("iter_schema_engines");
if (!(hton->flags & HTON_HIDDEN))
{
+ LEX_STRING *name= plugin_name(plugin);
if (!(wild && wild[0] &&
- wild_case_compare(scs, plugin->name.str,wild)))
+ wild_case_compare(scs, name->str,wild)))
{
LEX_STRING state[2]= {{ C_STRING_WITH_LEN("ENABLED") },
{ C_STRING_WITH_LEN("DISABLED") }};
@@ -3307,11 +3326,11 @@ static my_bool iter_schema_engines(THD *thd, st_plugin_int *plugin,
LEX_STRING *tmp;
restore_record(table, s->default_values);
- table->field[0]->store(plugin->name.str, plugin->name.length, scs);
+ table->field[0]->store(name->str, name->length, scs);
tmp= &state[test(hton->state)];
table->field[1]->store(tmp->str, tmp->length, scs);
- table->field[2]->store(plugin->plugin->descr,
- strlen(plugin->plugin->descr), scs);
+ table->field[2]->store(plugin_decl(plugin)->descr,
+ strlen(plugin_decl(plugin)->descr), scs);
tmp= &yesno[test(hton->commit)];
table->field[3]->store(tmp->str, tmp->length, scs);
tmp= &yesno[test(hton->prepare)];
@@ -4499,10 +4518,20 @@ int fill_variables(THD *thd, TABLE_LIST *tables, COND *cond)
int res= 0;
LEX *lex= thd->lex;
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
- pthread_mutex_lock(&LOCK_global_system_variables);
- res= show_status_array(thd, wild, init_vars,
- lex->option_type, 0, "", tables->table, 0);
- pthread_mutex_unlock(&LOCK_global_system_variables);
+ enum enum_schema_tables schema_table_idx=
+ get_schema_table_idx(tables->schema_table);
+ enum enum_var_type option_type= OPT_SESSION;
+ bool upper_case_names= (schema_table_idx != SCH_VARIABLES);
+ bool sorted_vars= (schema_table_idx == SCH_VARIABLES);
+
+ if (lex->option_type == OPT_GLOBAL ||
+ schema_table_idx == SCH_GLOBAL_VARIABLES)
+ option_type= OPT_GLOBAL;
+
+ rw_rdlock(&LOCK_system_variables_hash);
+ res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars),
+ option_type, NULL, "", tables->table, upper_case_names);
+ rw_unlock(&LOCK_system_variables_hash);
DBUG_RETURN(res);
}
@@ -4513,16 +4542,38 @@ int fill_status(THD *thd, TABLE_LIST *tables, COND *cond)
LEX *lex= thd->lex;
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
int res= 0;
- STATUS_VAR tmp;
+ STATUS_VAR *tmp1, tmp;
+ enum enum_schema_tables schema_table_idx=
+ get_schema_table_idx(tables->schema_table);
+ enum enum_var_type option_type;
+ bool upper_case_names= (schema_table_idx != SCH_STATUS);
+
+ if (schema_table_idx == SCH_STATUS)
+ {
+ option_type= lex->option_type;
+ if (option_type == OPT_GLOBAL)
+ tmp1= &tmp;
+ else
+ tmp1= thd->initial_status_var;
+ }
+ else if (schema_table_idx == SCH_GLOBAL_STATUS)
+ {
+ option_type= OPT_GLOBAL;
+ tmp1= &tmp;
+ }
+ else
+ {
+ option_type= OPT_SESSION;
+ tmp1= &thd->status_var;
+ }
+
pthread_mutex_lock(&LOCK_status);
- if (lex->option_type == OPT_GLOBAL)
+ if (option_type == OPT_GLOBAL)
calc_sum_of_all_status(&tmp);
res= show_status_array(thd, wild,
(SHOW_VAR *)all_status_vars.buffer,
- OPT_GLOBAL,
- (lex->option_type == OPT_GLOBAL ?
- &tmp: thd->initial_status_var),
- "", tables->table, 0);
+ option_type, tmp1, "", tables->table,
+ upper_case_names);
pthread_mutex_unlock(&LOCK_status);
DBUG_RETURN(res);
}
@@ -4618,12 +4669,12 @@ struct schema_table_ref
0 table not found
1 found the schema table
*/
-static my_bool find_schema_table_in_plugin(THD *thd, st_plugin_int *plugin,
+static my_bool find_schema_table_in_plugin(THD *thd, plugin_ref plugin,
void* p_table)
{
schema_table_ref *p_schema_table= (schema_table_ref *)p_table;
const char* table_name= p_schema_table->table_name;
- ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data;
+ ST_SCHEMA_TABLE *schema_table= plugin_data(plugin, ST_SCHEMA_TABLE *);
DBUG_ENTER("find_schema_table_in_plugin");
if (!my_strcasecmp(system_charset_info,
@@ -4765,12 +4816,10 @@ TABLE *create_schema_table(THD *thd, TABLE_LIST *table_list)
/* Don't let unimplemented types pass through. Could be a grave error. */
DBUG_ASSERT(fields_info->field_type == MYSQL_TYPE_STRING);
- /* this should be changed when Item_empty_string is fixed(in 4.1) */
- if (!(item= new Item_empty_string("", 0, cs)))
+ if (!(item= new Item_empty_string("", fields_info->field_length, cs)))
{
DBUG_RETURN(0);
}
- item->max_length= fields_info->field_length * cs->mbmaxlen;
item->set_name(fields_info->field_name,
strlen(fields_info->field_name), cs);
break;
@@ -5186,12 +5235,12 @@ struct run_hton_fill_schema_files_args
COND *cond;
};
-static my_bool run_hton_fill_schema_files(THD *thd, st_plugin_int *plugin,
+static my_bool run_hton_fill_schema_files(THD *thd, plugin_ref plugin,
void *arg)
{
struct run_hton_fill_schema_files_args *args=
(run_hton_fill_schema_files_args *) arg;
- handlerton *hton= (handlerton *)plugin->data;
+ handlerton *hton= plugin_data(plugin, handlerton *);
if(hton->fill_files_table && hton->state == SHOW_OPTION_YES)
hton->fill_files_table(hton, thd, args->tables, args->cond);
return false;
@@ -5211,172 +5260,6 @@ int fill_schema_files(THD *thd, TABLE_LIST *tables, COND *cond)
DBUG_RETURN(0);
}
-int fill_schema_status(THD *thd, SHOW_VAR *variables,
- struct system_status_var *status_var,
- const char *prefix, TABLE *table)
-{
- SHOW_VAR tmp, *var;
- SHOW_TYPE show_type;
- LEX_STRING null_lex_str;
- char buff[SHOW_VAR_FUNC_BUFF_SIZE];
- char name_buf[64], *name_pos;
- int name_len;
- DBUG_ENTER("fill_schema_status");
-
- null_lex_str.str= 0;
- null_lex_str.length= 0;
-
- name_pos= strnmov(name_buf, prefix, sizeof(name_buf) - 1);
- if (*prefix)
- *name_pos++= '_';
- name_len= name_buf + sizeof(name_buf) - name_pos;
-
- for (; variables->name; variables++)
- {
- strnmov(name_pos, variables->name, name_len);
- name_buf[sizeof(name_buf) - 1]= 0;
- make_upper(name_buf);
-
- for (var= variables; var->type == SHOW_FUNC; var= &tmp)
- ((mysql_show_var_func)(var->value))(thd, &tmp, buff);
-
- show_type= var->type;
-
- if (show_type == SHOW_ARRAY)
- {
- fill_schema_status(thd, (SHOW_VAR*) var->value,
- status_var, name_buf, table);
- }
- else
- {
- char *value= var->value;
-
- restore_record(table, s->default_values);
- table->field[0]->store(name_buf, strlen(name_buf), system_charset_info);
-
- if (show_type == SHOW_SYS)
- {
- show_type= ((sys_var*) value)->show_type();
- value= (char*) ((sys_var*) value)->value_ptr(thd, OPT_GLOBAL,
- &null_lex_str);
- }
-
- switch (show_type)
- {
- case SHOW_DOUBLE_STATUS:
- value= (char*) status_var + (ulong) value;
- table->field[1]->store(*(double*) value);
- break;
- case SHOW_LONG_STATUS:
- value= (char*) status_var + (ulong) value;
- /* fall through */
- case SHOW_LONG:
- case SHOW_LONG_NOFLUSH: /* the difference lies in refresh_status() */
- table->field[1]->store((longlong) *(long*) value, false);
- break;
- case SHOW_LONGLONG:
- table->field[1]->store(*(longlong*) value, false);
- break;
- case SHOW_HA_ROWS:
- table->field[1]->store((longlong) *(ha_rows*) value, false);
- break;
- case SHOW_BOOL:
- table->field[1]->store((longlong) *(bool*) value, false);
- break;
- case SHOW_MY_BOOL:
- table->field[1]->store((longlong) *(my_bool*) value, false);
- break;
- case SHOW_INT:
- table->field[1]->store((longlong) *(uint32*) value, false);
- break;
- case SHOW_HAVE: /* always displayed as 0 */
- table->field[1]->store((longlong) 0, false);
- break;
- case SHOW_CHAR_PTR:
- value= *(char**) value;
- /* fall through */
- case SHOW_CHAR: /* always displayed as 0 */
- table->field[1]->store((longlong) 0, false);
- break;
- case SHOW_KEY_CACHE_LONG:
- value= (char*) dflt_key_cache + (ulong) value;
- table->field[1]->store((longlong) *(long*) value, false);
- break;
- case SHOW_KEY_CACHE_LONGLONG:
- value= (char*) dflt_key_cache + (ulong) value;
- table->field[1]->store(*(longlong*) value, false);
- break;
- case SHOW_UNDEF: /* always displayed as 0 */
- table->field[1]->store((longlong) 0, false);
- break;
- case SHOW_SYS: /* cannot happen */
- default:
- DBUG_ASSERT(0);
- break;
- }
-
- table->field[1]->set_notnull();
- if (schema_table_store_record(thd, table))
- DBUG_RETURN(1);
- }
- }
-
- DBUG_RETURN(0);
-}
-
-int fill_schema_global_status(THD *thd, TABLE_LIST *tables, COND *cond)
-{
- STATUS_VAR tmp;
- int res= 0;
- DBUG_ENTER("fill_schema_global_status");
-
- pthread_mutex_lock(&LOCK_status);
- calc_sum_of_all_status(&tmp);
- res= fill_schema_status(thd, (SHOW_VAR*) all_status_vars.buffer,
- &tmp, "", tables->table);
- pthread_mutex_unlock(&LOCK_status);
-
- DBUG_RETURN(res);
-}
-
-int fill_schema_session_status(THD *thd, TABLE_LIST *tables, COND *cond)
-{
- int res= 0;
- DBUG_ENTER("fill_schema_session_status");
-
- pthread_mutex_lock(&LOCK_status);
- res= fill_schema_status(thd, (SHOW_VAR*) all_status_vars.buffer,
- &thd->status_var, "", tables->table);
- pthread_mutex_unlock(&LOCK_status);
-
- DBUG_RETURN(res);
-}
-
-int fill_schema_global_variables(THD *thd, TABLE_LIST *tables, COND *cond)
-{
- int res= 0;
- DBUG_ENTER("fill_schema_global_variables");
-
- pthread_mutex_lock(&LOCK_global_system_variables);
- res= show_status_array(thd, "", init_vars, OPT_GLOBAL,
- NULL, "", tables->table, 1);
- pthread_mutex_unlock(&LOCK_global_system_variables);
-
- DBUG_RETURN(res);
-}
-
-int fill_schema_session_variables(THD *thd, TABLE_LIST *tables, COND *cond)
-{
- int res= 0;
- DBUG_ENTER("fill_schema_session_variables");
-
- pthread_mutex_lock(&LOCK_global_system_variables);
- res= show_status_array(thd, "", init_vars, OPT_SESSION,
- NULL, "", tables->table, 1);
- pthread_mutex_unlock(&LOCK_global_system_variables);
-
- DBUG_RETURN(res);
-}
ST_FIELD_INFO schema_fields_info[]=
{
@@ -5746,24 +5629,8 @@ ST_FIELD_INFO partitions_fields_info[]=
ST_FIELD_INFO variables_fields_info[]=
{
- {"Variable_name", 80, MYSQL_TYPE_STRING, 0, 0, "Variable_name"},
- {"Value", FN_REFLEN, MYSQL_TYPE_STRING, 0, 0, "Value"},
- {0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
-};
-
-
-ST_FIELD_INFO status_fields_info[]=
-{
- {"VARIABLE_NAME", 64, MYSQL_TYPE_STRING, 0, 0, "Variable_name"},
- {"VARIABLE_VALUE", 2207, MYSQL_TYPE_DECIMAL, 0, 0, "Value"},
- {0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
-};
-
-
-ST_FIELD_INFO system_variables_fields_info[]=
-{
{"VARIABLE_NAME", 64, MYSQL_TYPE_STRING, 0, 0, "Variable_name"},
- {"VARIABLE_VALUE", 65535, MYSQL_TYPE_STRING, 0, 1, "Value"},
+ {"VARIABLE_VALUE", 20480, MYSQL_TYPE_STRING, 0, 1, "Value"},
{0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
};
@@ -5903,10 +5770,10 @@ ST_SCHEMA_TABLE schema_tables[]=
Events::fill_schema_events, make_old_format, 0, -1, -1, 0},
{"FILES", files_fields_info, create_schema_table,
fill_schema_files, 0, 0, -1, -1, 0},
- {"GLOBAL_STATUS", status_fields_info, create_schema_table,
- fill_schema_global_status, make_old_format, 0, -1, -1, 0},
- {"GLOBAL_VARIABLES", system_variables_fields_info, create_schema_table,
- fill_schema_global_variables, make_old_format, 0, -1, -1, 0},
+ {"GLOBAL_STATUS", variables_fields_info, create_schema_table,
+ fill_status, make_old_format, 0, -1, -1, 0},
+ {"GLOBAL_VARIABLES", variables_fields_info, create_schema_table,
+ fill_variables, make_old_format, 0, -1, -1, 0},
{"KEY_COLUMN_USAGE", key_column_usage_fields_info, create_schema_table,
get_all_tables, 0, get_schema_key_column_usage_record, 4, 5, 0},
{"OPEN_TABLES", open_tables_fields_info, create_schema_table,
@@ -5926,10 +5793,10 @@ ST_SCHEMA_TABLE schema_tables[]=
fill_schema_shemata, make_schemata_old_format, 0, 1, -1, 0},
{"SCHEMA_PRIVILEGES", schema_privileges_fields_info, create_schema_table,
fill_schema_schema_privileges, 0, 0, -1, -1, 0},
- {"SESSION_STATUS", status_fields_info, create_schema_table,
- fill_schema_session_status, make_old_format, 0, -1, -1, 0},
- {"SESSION_VARIABLES", system_variables_fields_info, create_schema_table,
- fill_schema_session_variables, make_old_format, 0, -1, -1, 0},
+ {"SESSION_STATUS", variables_fields_info, create_schema_table,
+ fill_status, make_old_format, 0, -1, -1, 0},
+ {"SESSION_VARIABLES", variables_fields_info, create_schema_table,
+ fill_variables, make_old_format, 0, -1, -1, 0},
{"STATISTICS", stat_fields_info, create_schema_table,
get_all_tables, make_old_format, get_schema_stat_record, 1, 2, 0},
{"STATUS", variables_fields_info, create_schema_table, fill_status,
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index d19fcfd57fb..c9bf4422c18 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -40,8 +40,7 @@ static int copy_data_between_tables(TABLE *from,TABLE *to,
enum enum_enable_or_disable keys_onoff);
static bool prepare_blob_field(THD *thd, create_field *sql_field);
-static bool check_engine(THD *thd, const char *table_name,
- HA_CREATE_INFO *create_info);
+static bool check_engine(THD *, const char *, HA_CREATE_INFO *);
static int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
List<create_field> *fields,
List<Key> *keys, bool tmp_table,
@@ -667,16 +666,14 @@ static int execute_ddl_log_action(THD *thd, DDL_LOG_ENTRY *ddl_log_entry)
frm_action= TRUE;
else
{
- TABLE_SHARE dummy;
-
- hton= ha_resolve_by_name(thd, &handler_name);
- if (!hton)
+ plugin_ref plugin= ha_resolve_by_name(thd, &handler_name);
+ if (!plugin)
{
my_error(ER_ILLEGAL_HA, MYF(0), ddl_log_entry->handler_name);
goto error;
}
- bzero(&dummy, sizeof(TABLE_SHARE));
- file= get_new_handler(&dummy, &mem_root, hton);
+ hton= plugin_data(plugin, handlerton*);
+ file= get_new_handler((TABLE_SHARE*)0, &mem_root, hton);
if (!file)
{
mem_alloc_error(sizeof(handler));
@@ -1640,7 +1637,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
TABLE_SHARE *share;
table->db_type= NULL;
if ((share= get_cached_table_share(table->db, table->table_name)))
- table->db_type= share->db_type;
+ table->db_type= share->db_type();
/* Disable drop of enabled log tables */
if (share && share->log_table &&
@@ -3198,7 +3195,7 @@ static HA_CREATE_INFO *copy_create_info(HA_CREATE_INFO *lex_create_info)
Create a table
SYNOPSIS
- mysql_create_table_internal()
+ mysql_create_table_no_lock()
thd Thread object
db Database
table_name Table name
@@ -3215,6 +3212,11 @@ static HA_CREATE_INFO *copy_create_info(HA_CREATE_INFO *lex_create_info)
DESCRIPTION
If one creates a temporary table, this is automatically opened
+ Note that this function assumes that caller already have taken
+ name-lock on table being created or used some other way to ensure
+ that concurrent operations won't intervene. mysql_create_table()
+ is a wrapper that can be used for this.
+
no_log is needed for the case of CREATE ... SELECT,
as the logging will be done later in sql_insert.cc
select_field_count is also used for CREATE ... SELECT,
@@ -3225,7 +3227,7 @@ static HA_CREATE_INFO *copy_create_info(HA_CREATE_INFO *lex_create_info)
TRUE error
*/
-bool mysql_create_table_internal(THD *thd,
+bool mysql_create_table_no_lock(THD *thd,
const char *db, const char *table_name,
HA_CREATE_INFO *lex_create_info,
List<create_field> &fields,
@@ -3241,7 +3243,7 @@ bool mysql_create_table_internal(THD *thd,
HA_CREATE_INFO *create_info;
handler *file;
bool error= TRUE;
- DBUG_ENTER("mysql_create_table_internal");
+ DBUG_ENTER("mysql_create_table_no_lock");
DBUG_PRINT("enter", ("db: '%s' table: '%s' tmp: %d",
db, table_name, internal_tmp_table));
@@ -3516,15 +3518,25 @@ bool mysql_create_table_internal(THD *thd,
{
bool create_if_not_exists =
create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS;
-
- if (ha_table_exists_in_engine(thd, db, table_name))
+ int retcode = ha_table_exists_in_engine(thd, db, table_name);
+ DBUG_PRINT("info", ("exists_in_engine: %u",retcode));
+ switch (retcode)
{
- DBUG_PRINT("info", ("Table with same name already existed in handler"));
+ case HA_ERR_NO_SUCH_TABLE:
+ /* Normal case, no table exists. we can go and create it */
+ break;
+ case HA_ERR_TABLE_EXIST:
+ DBUG_PRINT("info", ("Table existed in handler"));
- if (create_if_not_exists)
- goto warn;
- my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
- goto unlock_and_end;
+ if (create_if_not_exists)
+ goto warn;
+ my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
+ goto unlock_and_end;
+ break;
+ default:
+ DBUG_PRINT("info", ("error: %u from storage engine", retcode));
+ my_error(retcode, MYF(0),table_name);
+ goto unlock_and_end;
}
}
@@ -3583,7 +3595,7 @@ warn:
/*
- Database locking aware wrapper for mysql_create_table_internal(),
+ Database and name-locking aware wrapper for mysql_create_table_no_lock(),
*/
bool mysql_create_table(THD *thd, const char *db, const char *table_name,
@@ -3593,6 +3605,7 @@ bool mysql_create_table(THD *thd, const char *db, const char *table_name,
uint select_field_count,
bool use_copy_create_info)
{
+ TABLE *name_lock= 0;
bool result;
DBUG_ENTER("mysql_create_table");
@@ -3613,11 +3626,44 @@ bool mysql_create_table(THD *thd, const char *db, const char *table_name,
creating_table++;
pthread_mutex_unlock(&LOCK_lock_db);
- result= mysql_create_table_internal(thd, db, table_name, create_info,
- fields, keys, internal_tmp_table,
- select_field_count,
- use_copy_create_info);
+ if (!(create_info->options & HA_LEX_CREATE_TMP_TABLE))
+ {
+ if (lock_table_name_if_not_cached(thd, db, table_name, &name_lock))
+ {
+ result= TRUE;
+ goto unlock;
+ }
+ if (!name_lock)
+ {
+ if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)
+ {
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
+ ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
+ table_name);
+ create_info->table_existed= 1;
+ result= FALSE;
+ }
+ else
+ {
+ my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
+ result= TRUE;
+ }
+ goto unlock;
+ }
+ }
+
+ result= mysql_create_table_no_lock(thd, db, table_name, create_info,
+ fields, keys, internal_tmp_table,
+ select_field_count,
+ use_copy_create_info);
+unlock:
+ if (name_lock)
+ {
+ pthread_mutex_lock(&LOCK_open);
+ unlink_open_table(thd, name_lock, FALSE);
+ pthread_mutex_unlock(&LOCK_open);
+ }
pthread_mutex_lock(&LOCK_lock_db);
if (!--creating_table && creating_database)
pthread_cond_signal(&COND_refresh);
@@ -3820,7 +3866,7 @@ void close_cached_table(THD *thd, TABLE *table)
thd->lock=0; // Start locked threads
}
/* Close all copies of 'table'. This also frees all LOCK TABLES lock */
- thd->open_tables=unlink_open_table(thd,thd->open_tables,table);
+ unlink_open_table(thd, table, TRUE);
/* When lock on LOCK_open is freed other threads can continue */
broadcast_refresh();
@@ -3896,7 +3942,7 @@ static int prepare_for_restore(THD* thd, TABLE_LIST* table,
to finish the restore in the handler later on
*/
pthread_mutex_lock(&LOCK_open);
- if (reopen_name_locked_table(thd, table))
+ if (reopen_name_locked_table(thd, table, TRUE))
{
unlock_table_name(thd, table);
pthread_mutex_unlock(&LOCK_open);
@@ -4028,7 +4074,7 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list,
to finish the repair in the handler later on.
*/
pthread_mutex_lock(&LOCK_open);
- if (reopen_name_locked_table(thd, table_list))
+ if (reopen_name_locked_table(thd, table_list, TRUE))
{
unlock_table_name(thd, table_list);
pthread_mutex_unlock(&LOCK_open);
@@ -4634,7 +4680,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
HA_CREATE_INFO *lex_create_info,
Table_ident *table_ident)
{
- TABLE *tmp_table;
+ TABLE *tmp_table, *name_lock= 0;
char src_path[FN_REFLEN], dst_path[FN_REFLEN];
char src_table_name_buff[FN_REFLEN], src_db_name_buff[FN_REFLEN];
uint dst_path_length;
@@ -4643,14 +4689,14 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
char *src_db;
char *src_table= table_ident->table.str;
int err;
- bool res= TRUE, unlock_dst_table= FALSE;
+ bool res= TRUE;
enum legacy_db_type not_used;
HA_CREATE_INFO *create_info;
#ifdef WITH_PARTITION_STORAGE_ENGINE
char tmp_path[FN_REFLEN];
#endif
char ts_name[FN_LEN];
- TABLE_LIST src_tables_list, dst_tables_list;
+ TABLE_LIST src_tables_list;
DBUG_ENTER("mysql_create_like_table");
if (!(create_info= copy_create_info(lex_create_info)))
@@ -4758,6 +4804,10 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
}
else
{
+ if (lock_table_name_if_not_cached(thd, db, table_name, &name_lock))
+ goto err;
+ if (!name_lock)
+ goto table_exists;
dst_path_length= build_table_filename(dst_path, sizeof(dst_path),
db, table_name, reg_ext, 0);
if (!access(dst_path, F_OK))
@@ -4845,28 +4895,21 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
char buf[2048];
String query(buf, sizeof(buf), system_charset_info);
query.length(0); // Have to zero it since constructor doesn't
- uint counter;
/*
- Here we open the destination table. This is needed for
- store_create_info() to work. The table will be closed
- by close_thread_tables() at the end of the statement.
+ Here we open the destination table, on which we already have
+ name-lock. This is needed for store_create_info() to work.
+ The table will be closed by unlink_open_table() at the end
+ of this function.
*/
- if (open_tables(thd, &table, &counter, 0))
- goto err;
-
- bzero((uchar*)&dst_tables_list, sizeof(dst_tables_list));
- dst_tables_list.db= table->db;
- dst_tables_list.table_name= table->table_name;
-
- /*
- lock destination table name, to make sure that nobody
- can drop/alter the table while we execute store_create_info()
- */
- if (lock_and_wait_for_table_name(thd, &dst_tables_list))
+ table->table= name_lock;
+ VOID(pthread_mutex_lock(&LOCK_open));
+ if (reopen_name_locked_table(thd, table, FALSE))
+ {
+ VOID(pthread_mutex_unlock(&LOCK_open));
goto err;
- else
- unlock_dst_table= TRUE;
+ }
+ VOID(pthread_mutex_unlock(&LOCK_open));
IF_DBUG(int result=) store_create_info(thd, table, &query,
create_info);
@@ -4901,10 +4944,10 @@ table_exists:
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), table_name);
err:
- if (unlock_dst_table)
+ if (name_lock)
{
pthread_mutex_lock(&LOCK_open);
- unlock_table_name(thd, &dst_tables_list);
+ unlink_open_table(thd, name_lock, FALSE);
pthread_mutex_unlock(&LOCK_open);
}
DBUG_RETURN(res);
@@ -5082,7 +5125,7 @@ static uint compare_tables(TABLE *table, List<create_field> *create_list,
See BUG#6236.
*/
if (table->s->fields != create_list->elements ||
- table->s->db_type != create_info->db_type ||
+ table->s->db_type() != create_info->db_type ||
table->s->tmp_table ||
create_info->used_fields & HA_CREATE_USED_ENGINE ||
create_info->used_fields & HA_CREATE_USED_CHARSET ||
@@ -5351,7 +5394,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
uint order_num, ORDER *order, bool ignore,
ALTER_INFO *alter_info, bool do_send_ok)
{
- TABLE *table,*new_table=0;
+ TABLE *table, *new_table= 0, *name_lock= 0;
int error= 0;
char tmp_name[80],old_name[32],new_name_buff[FN_REFLEN];
char new_alias_buff[FN_REFLEN], *table_name, *db, *new_alias, *alias;
@@ -5488,6 +5531,18 @@ view_err:
DBUG_RETURN(TRUE);
table->use_all_columns();
+ List_iterator<Alter_drop> drop_it(alter_info->drop_list);
+ List_iterator<create_field> def_it(fields);
+ List_iterator<Alter_column> alter_it(alter_info->alter_list);
+ List<create_field> create_list; // Add new fields here
+ List<Key> key_list; // Add new keys here
+ List_iterator<create_field> find_it(create_list);
+ List_iterator<Key> key_it(keys);
+ List_iterator<create_field> field_it(create_list);
+ List<key_part_spec> key_parts;
+
+ KEY *key_info=table->key_info;
+
/* Check that we are not trying to rename to an existing table */
if (new_name)
{
@@ -5524,13 +5579,21 @@ view_err:
}
else
{
+ if (lock_table_name_if_not_cached(thd, new_db, new_name, &name_lock))
+ DBUG_RETURN(TRUE);
+ if (!name_lock)
+ {
+ my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
+ DBUG_RETURN(TRUE);
+ }
+
build_table_filename(new_name_buff, sizeof(new_name_buff),
new_db, new_name_buff, reg_ext, 0);
if (!access(new_name_buff, F_OK))
{
/* Table will be closed in do_command() */
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
- DBUG_RETURN(TRUE);
+ goto err;
}
}
}
@@ -5541,7 +5604,7 @@ view_err:
new_name= table_name;
}
- old_db_type= table->s->db_type;
+ old_db_type= table->s->db_type();
if (!create_info->db_type)
{
#ifdef WITH_PARTITION_STORAGE_ENGINE
@@ -5565,12 +5628,10 @@ view_err:
#ifdef WITH_PARTITION_STORAGE_ENGINE
if (prep_alter_part_table(thd, table, alter_info, create_info, old_db_type,
&partition_changed, &fast_alter_partition))
- {
- DBUG_RETURN(TRUE);
- }
+ goto err;
#endif
if (check_engine(thd, new_name, create_info))
- DBUG_RETURN(TRUE);
+ goto err;
new_db_type= create_info->db_type;
if (create_info->row_type == ROW_TYPE_NOT_USED)
create_info->row_type= table->s->row_type;
@@ -5583,7 +5644,7 @@ view_err:
{
DBUG_PRINT("info", ("doesn't support alter"));
my_error(ER_ILLEGAL_HA, MYF(0), table_name);
- DBUG_RETURN(TRUE);
+ goto err;
}
thd->proc_info="setup";
@@ -5642,7 +5703,19 @@ view_err:
if (!error && (new_name != table_name || new_db != db))
{
thd->proc_info="rename";
- /* Then do a 'simple' rename of the table */
+ /*
+ Then do a 'simple' rename of the table. First we need to close all
+ instances of 'source' table.
+ */
+ close_cached_table(thd, table);
+ /*
+ Then, we want check once again that target table does not exist.
+ Actually the order of these two steps does not matter since
+ earlier we took name-lock on the target table, so we do them
+ in this particular order only to be consistent with 5.0, in which
+ we don't take this name-lock and where this order really matters.
+ TODO: Investigate if we need this access() check at all.
+ */
if (!access(new_name_buff,F_OK))
{
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_name);
@@ -5651,8 +5724,6 @@ view_err:
else
{
*fn_ext(new_name)=0;
- table->s->version= 0; // Force removal of table def
- close_cached_table(thd, table);
if (mysql_rename_table(old_db_type,db,table_name,new_db,new_alias, 0))
error= -1;
else if (Table_triggers_list::change_table_name(thd, db, table_name,
@@ -5684,6 +5755,8 @@ view_err:
table->file->print_error(error, MYF(0));
error= -1;
}
+ if (name_lock)
+ unlink_open_table(thd, name_lock, FALSE);
VOID(pthread_mutex_unlock(&LOCK_open));
table_list->table= NULL; // For query cache
query_cache_invalidate3(thd, table_list, 0);
@@ -5720,11 +5793,6 @@ view_err:
create_info->tablespace= tablespace;
}
restore_record(table, s->default_values); // Empty record for DEFAULT
- List_iterator<Alter_drop> drop_it(alter_info->drop_list);
- List_iterator<create_field> def_it(fields);
- List_iterator<Alter_column> alter_it(alter_info->alter_list);
- List<create_field> create_list; // Add new fields here
- List<Key> key_list; // Add new keys here
create_field *def;
/*
@@ -5795,7 +5863,7 @@ view_err:
if (def->sql_type == MYSQL_TYPE_BLOB)
{
my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0), def->change);
- DBUG_RETURN(TRUE);
+ goto err;
}
if ((def->def=alter->def)) // Use new default
def->flags&= ~NO_DEFAULT_VALUE_FLAG;
@@ -5806,13 +5874,12 @@ view_err:
}
}
def_it.rewind();
- List_iterator<create_field> find_it(create_list);
while ((def=def_it++)) // Add new columns
{
if (def->change && ! def->field)
{
my_error(ER_BAD_FIELD_ERROR, MYF(0), def->change, table_name);
- DBUG_RETURN(TRUE);
+ goto err;
}
if (!def->after)
create_list.push_back(def);
@@ -5830,7 +5897,7 @@ view_err:
if (!find)
{
my_error(ER_BAD_FIELD_ERROR, MYF(0), def->after, table_name);
- DBUG_RETURN(TRUE);
+ goto err;
}
find_it.after(def); // Put element after this
}
@@ -5839,13 +5906,13 @@ view_err:
{
my_error(ER_BAD_FIELD_ERROR, MYF(0),
alter_info->alter_list.head()->name, table_name);
- DBUG_RETURN(TRUE);
+ goto err;
}
if (!create_list.elements)
{
my_message(ER_CANT_REMOVE_ALL_FIELDS, ER(ER_CANT_REMOVE_ALL_FIELDS),
MYF(0));
- DBUG_RETURN(TRUE);
+ goto err;
}
/*
@@ -5853,11 +5920,6 @@ view_err:
for which some fields exists.
*/
- List_iterator<Key> key_it(keys);
- List_iterator<create_field> field_it(create_list);
- List<key_part_spec> key_parts;
-
- KEY *key_info=table->key_info;
for (uint i=0 ; i < table->s->keys ; i++,key_info++)
{
char *key_name= key_info->name;
@@ -5961,7 +6023,7 @@ view_err:
!my_strcasecmp(system_charset_info,key->name,primary_key_name))
{
my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key->name);
- DBUG_RETURN(TRUE);
+ goto err;
}
}
}
@@ -6061,7 +6123,7 @@ view_err:
}
if (thd->variables.old_alter_table
- || (table->s->db_type != create_info->db_type)
+ || (table->s->db_type() != create_info->db_type)
#ifdef WITH_PARTITION_STORAGE_ENGINE
|| partition_changed
#endif
@@ -6099,8 +6161,8 @@ view_err:
uint *idx_p;
uint *idx_end_p;
- if (table->s->db_type->alter_table_flags)
- alter_flags= table->s->db_type->alter_table_flags(alter_info->flags);
+ if (table->s->db_type()->alter_table_flags)
+ alter_flags= table->s->db_type()->alter_table_flags(alter_info->flags);
DBUG_PRINT("info", ("alter_flags: %lu", alter_flags));
/* Check dropped indexes. */
for (idx_p= index_drop_buffer, idx_end_p= idx_p + index_drop_count;
@@ -6203,6 +6265,7 @@ view_err:
#ifdef WITH_PARTITION_STORAGE_ENGINE
if (fast_alter_partition)
{
+ DBUG_ASSERT(!name_lock);
DBUG_RETURN(fast_alter_partition_table(thd, table, alter_info,
create_info, table_list,
&create_list, &key_list,
@@ -6263,11 +6326,12 @@ view_err:
We don't log the statement, it will be logged later.
*/
tmp_disable_binlog(thd);
- error= mysql_create_table(thd, new_db, tmp_name,
- create_info,create_list,key_list,1,0,0);
+ error= mysql_create_table_no_lock(thd, new_db, tmp_name,
+ create_info, create_list,
+ key_list, 1, 0, 0);
reenable_binlog(thd);
if (error)
- DBUG_RETURN(error);
+ goto err;
/* Open the table if we need to copy the data. */
if (need_copy_table)
@@ -6528,17 +6592,6 @@ view_err:
current_pid, thd->thread_id);
if (lower_case_table_names)
my_casedn_str(files_charset_info, old_name);
- if (new_name != table_name || new_db != db)
- {
- if (!access(new_name_buff,F_OK))
- {
- error=1;
- my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_name_buff);
- VOID(quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP));
- VOID(pthread_mutex_unlock(&LOCK_open));
- goto err;
- }
- }
#if !defined( __WIN__)
if (table->file->has_transactions())
@@ -6548,7 +6601,6 @@ view_err:
Win32 and InnoDB can't drop a table that is in use, so we must
close the original table before doing the rename
*/
- table->s->version= 0; // Force removal of table def
close_cached_table(thd, table);
table=0; // Marker that table is closed
no_table_reopen= TRUE;
@@ -6558,6 +6610,21 @@ view_err:
table->file->extra(HA_EXTRA_FORCE_REOPEN); // Don't use this file anymore
#endif
+ if (new_name != table_name || new_db != db)
+ {
+ /*
+ Check that there is no table with target name. See the
+ comment describing code for 'simple' ALTER TABLE ... RENAME.
+ */
+ if (!access(new_name_buff,F_OK))
+ {
+ error=1;
+ my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_name_buff);
+ VOID(quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP));
+ VOID(pthread_mutex_unlock(&LOCK_open));
+ goto err;
+ }
+ }
error=0;
save_old_db_type= old_db_type;
@@ -6608,7 +6675,6 @@ view_err:
*/
if (table)
{
- table->s->version= 0; // Force removal of table def
close_cached_table(thd,table);
}
VOID(pthread_mutex_unlock(&LOCK_open));
@@ -6616,6 +6682,7 @@ view_err:
}
if (! need_copy_table)
{
+ bool needs_unlink= FALSE;
if (! table)
{
if (new_name != table_name || new_db != db)
@@ -6626,11 +6693,41 @@ view_err:
table_list->db= new_db;
table_list->db_length= strlen(new_db);
}
-
- VOID(pthread_mutex_unlock(&LOCK_open));
- if (! (table= open_ltable(thd, table_list, TL_WRITE_ALLOW_READ)))
+ else
+ {
+ /*
+ TODO: Creation of name-lock placeholder here is a temporary
+ work-around. Long term we should change close_cached_table() call
+ which we invoke before table renaming operation in such way that
+ it will leave placeholders for table in table cache/THD::open_tables
+ list. By doing this we will be able easily reopen and relock these
+ tables later and therefore behave under LOCK TABLES in the same way
+ on all platforms.
+ */
+ char key[MAX_DBKEY_LENGTH];
+ uint key_length;
+ key_length= create_table_def_key(thd, key, table_list, 0);
+ if (!(name_lock= table_cache_insert_placeholder(thd, key,
+ key_length)))
+ {
+ VOID(pthread_mutex_unlock(&LOCK_open));
+ goto err;
+ }
+ name_lock->next= thd->open_tables;
+ thd->open_tables= name_lock;
+ }
+ table_list->table= name_lock;
+ if (reopen_name_locked_table(thd, table_list, FALSE))
+ {
+ VOID(pthread_mutex_unlock(&LOCK_open));
goto err;
- VOID(pthread_mutex_lock(&LOCK_open));
+ }
+ table= table_list->table;
+ /*
+ We can't rely on later close_cached_table() calls to close
+ this instance of the table since it was not properly locked.
+ */
+ needs_unlink= TRUE;
}
/* Tell the handler that a new frm file is in place. */
if (table->file->create_handler_files(path, NULL, CHF_INDEX_FLAG,
@@ -6639,6 +6736,11 @@ view_err:
VOID(pthread_mutex_unlock(&LOCK_open));
goto err;
}
+ if (needs_unlink)
+ {
+ unlink_open_table(thd, table, FALSE);
+ table= name_lock= 0;
+ }
}
if (thd->lock || new_name != table_name || no_table_reopen) // True if WIN32
@@ -6649,7 +6751,6 @@ view_err:
*/
if (table)
{
- table->s->version= 0; // Force removal of table def
close_cached_table(thd,table);
}
VOID(quick_rm_table(old_db_type, db, old_name, FN_IS_TMP));
@@ -6675,7 +6776,6 @@ view_err:
{ // This shouldn't happen
if (table)
{
- table->s->version= 0; // Force removal of table def
close_cached_table(thd,table); // Remove lock for table
}
VOID(pthread_mutex_unlock(&LOCK_open));
@@ -6732,6 +6832,13 @@ view_err:
table_list->table=0; // For query cache
query_cache_invalidate3(thd, table_list, 0);
+ if (name_lock)
+ {
+ pthread_mutex_lock(&LOCK_open);
+ unlink_open_table(thd, name_lock, FALSE);
+ pthread_mutex_unlock(&LOCK_open);
+ }
+
end_temporary:
my_snprintf(tmp_name, sizeof(tmp_name), ER(ER_INSERT_INFO),
(ulong) (copied + deleted), (ulong) deleted,
@@ -6751,6 +6858,12 @@ err1:
VOID(quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP));
err:
+ if (name_lock)
+ {
+ pthread_mutex_lock(&LOCK_open);
+ unlink_open_table(thd, name_lock, FALSE);
+ pthread_mutex_unlock(&LOCK_open);
+ }
DBUG_RETURN(TRUE);
}
/* mysql_alter_table */
@@ -7117,7 +7230,7 @@ static bool check_engine(THD *thd, const char *table_name,
if (req_engine && req_engine != *new_engine)
{
- push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_WARN_USING_OTHER_HANDLER,
ER(ER_WARN_USING_OTHER_HANDLER),
ha_resolve_storage_engine_name(*new_engine),
@@ -7129,7 +7242,7 @@ static bool check_engine(THD *thd, const char *table_name,
if (create_info->used_fields & HA_CREATE_USED_ENGINE)
{
my_error(ER_ILLEGAL_HA_CREATE_OPTION, MYF(0),
- hton2plugin[(*new_engine)->slot]->name.str, "TEMPORARY");
+ ha_resolve_storage_engine_name(*new_engine), "TEMPORARY");
*new_engine= 0;
return TRUE;
}
diff --git a/sql/sql_tablespace.cc b/sql/sql_tablespace.cc
index 84391a54642..b4a03a370ba 100644
--- a/sql/sql_tablespace.cc
+++ b/sql/sql_tablespace.cc
@@ -34,7 +34,7 @@ int mysql_alter_tablespace(THD *thd, st_alter_tablespace *ts_info)
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
ER_WARN_USING_OTHER_HANDLER,
ER(ER_WARN_USING_OTHER_HANDLER),
- hton2plugin[hton->slot]->name.str,
+ ha_resolve_storage_engine_name(hton),
ts_info->tablespace_name ? ts_info->tablespace_name
: ts_info->logfile_group_name);
}
@@ -63,7 +63,7 @@ int mysql_alter_tablespace(THD *thd, st_alter_tablespace *ts_info)
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
ER_ILLEGAL_HA_CREATE_OPTION,
ER(ER_ILLEGAL_HA_CREATE_OPTION),
- hton2plugin[hton->slot]->name.str,
+ ha_resolve_storage_engine_name(hton),
"TABLESPACE or LOGFILE GROUP");
}
if (mysql_bin_log.is_open())
diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc
index 4540cab99c3..e15003ab243 100644
--- a/sql/sql_trigger.cc
+++ b/sql/sql_trigger.cc
@@ -279,7 +279,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
/* We also don't allow creation of triggers on views. */
tables->required_type= FRMTYPE_TABLE;
- if (reopen_name_locked_table(thd, tables))
+ if (reopen_name_locked_table(thd, tables, TRUE))
{
unlock_table_name(thd, tables);
goto end;
@@ -976,10 +976,14 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db,
LEX_STRING *trg_definer= it_definer++;
thd->variables.sql_mode= (ulong)*trg_sql_mode;
- lex_start(thd, trg_create_str->str, trg_create_str->length);
- thd->spcont= 0;
- if (MYSQLparse((void *)thd) || thd->is_fatal_error)
+ Lex_input_stream lip(thd, trg_create_str->str, trg_create_str->length);
+ thd->m_lip= &lip;
+ lex_start(thd);
+ thd->spcont= 0;
+ int err= MYSQLparse((void *)thd);
+
+ if (err || thd->is_fatal_error)
{
/* Currently sphead is always deleted in case of a parse error */
DBUG_ASSERT(lex.sphead == 0);
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 0197b9a9abc..c872d3cb241 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -147,8 +147,16 @@ st_select_lex_unit::init_prepare_fake_select_lex(THD *thd_arg)
fake_select_lex->table_list.link_in_list((uchar *)&result_table_list,
(uchar **)
&result_table_list.next_local);
- fake_select_lex->context.table_list= fake_select_lex->context.first_name_resolution_table=
+ fake_select_lex->context.table_list=
+ fake_select_lex->context.first_name_resolution_table=
fake_select_lex->get_table_list();
+ if (!fake_select_lex->first_execution)
+ {
+ for (ORDER *order= (ORDER *) global_parameters->order_list.first;
+ order;
+ order= order->next)
+ order->item= &order->item_ptr;
+ }
for (ORDER *order= (ORDER *)global_parameters->order_list.first;
order;
order=order->next)
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 0ce8d7e9113..1c6e324ea10 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -170,8 +170,9 @@ int mysql_update(THD *thd,
table->quick_keys.clear_all();
#ifndef NO_EMBEDDED_ACCESS_CHECKS
- /* TABLE_LIST contain right privilages request */
- want_privilege= table_list->grant.want_privilege;
+ /* Force privilege re-checking for views after they have been opened. */
+ want_privilege= (table_list->view ? UPDATE_ACL :
+ table_list->grant.want_privilege);
#endif
if (mysql_prepare_update(thd, table_list, &conds, order_num, order))
DBUG_RETURN(1);
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index a8816d611c5..3ba4fd6ed9c 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -985,10 +985,14 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table,
now Lex placed in statement memory
*/
table->view= lex= thd->lex= (LEX*) new(thd->mem_root) st_lex_local;
- lex_start(thd, table->query.str, table->query.length);
- view_select= &lex->select_lex;
- view_select->select_number= ++thd->select_number;
+
{
+ Lex_input_stream lip(thd, table->query.str, table->query.length);
+ thd->m_lip= &lip;
+ lex_start(thd);
+ view_select= &lex->select_lex;
+ view_select->select_number= ++thd->select_number;
+
ulong save_mode= thd->variables.sql_mode;
/* switch off modes which can prevent normal parsing of VIEW
- MODE_REAL_AS_FLOAT affect only CREATE TABLE parsing
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index d46eeb985c9..113fb33fb9b 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -49,9 +49,9 @@ const LEX_STRING null_lex_str={0,0};
#define MYSQL_YYABORT \
do \
- { \
+ { \
LEX::cleanup_lex_after_parse_error(YYTHD);\
- YYABORT; \
+ YYABORT; \
} while (0)
#define MYSQL_YYABORT_UNLESS(A) \
@@ -104,12 +104,13 @@ const LEX_STRING null_lex_str={0,0};
void my_parse_error(const char *s)
{
THD *thd= current_thd;
+ Lex_input_stream *lip= thd->m_lip;
- char *yytext= (char*) thd->lex->tok_start;
+ const char *yytext= lip->tok_start;
/* Push an error into the error stack */
my_printf_error(ER_PARSE_ERROR, ER(ER_PARSE_ERROR), MYF(0), s,
- (yytext ? (char*) yytext : ""),
- thd->lex->yylineno);
+ (yytext ? yytext : ""),
+ lip->yylineno);
}
/**
@@ -1363,11 +1364,6 @@ deallocate:
{
THD *thd= YYTHD;
LEX *lex= thd->lex;
- if (lex->stmt_prepare_mode)
- {
- my_parse_error(ER(ER_SYNTAX_ERROR));
- MYSQL_YYABORT;
- }
lex->sql_command= SQLCOM_DEALLOCATE_PREPARE;
lex->prepared_stmt_name= $3;
};
@@ -1383,11 +1379,6 @@ prepare:
{
THD *thd= YYTHD;
LEX *lex= thd->lex;
- if (lex->stmt_prepare_mode)
- {
- my_parse_error(ER(ER_SYNTAX_ERROR));
- MYSQL_YYABORT;
- }
lex->sql_command= SQLCOM_PREPARE;
lex->prepared_stmt_name= $2;
};
@@ -1413,11 +1404,6 @@ execute:
{
THD *thd= YYTHD;
LEX *lex= thd->lex;
- if (lex->stmt_prepare_mode)
- {
- my_parse_error(ER(ER_SYNTAX_ERROR));
- MYSQL_YYABORT;
- }
lex->sql_command= SQLCOM_EXECUTE;
lex->prepared_stmt_name= $2;
}
@@ -1581,9 +1567,7 @@ create:
lex->sql_command= SQLCOM_CREATE_TABLE;
if (!lex->select_lex.add_table_to_list(thd, $5, NULL,
TL_OPTION_UPDATING,
- (using_update_log ?
- TL_READ_NO_INSERT:
- TL_READ)))
+ TL_WRITE))
MYSQL_YYABORT;
lex->create_list.empty();
lex->key_list.empty();
@@ -1591,14 +1575,26 @@ create:
lex->change=NullS;
bzero((char*) &lex->create_info,sizeof(lex->create_info));
lex->create_info.options=$2 | $4;
- lex->create_info.db_type= lex->thd->variables.table_type;
+ lex->create_info.db_type= ha_default_handlerton(thd);
lex->create_info.default_table_charset= NULL;
lex->name.str= 0;
lex->name.length= 0;
lex->like_name= 0;
}
create2
- { Lex->current_select= &Lex->select_lex; }
+ {
+ LEX *lex= YYTHD->lex;
+ lex->current_select= &lex->select_lex;
+ if (!lex->create_info.db_type)
+ {
+ lex->create_info.db_type= ha_default_handlerton(YYTHD);
+ push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_WARN,
+ ER_WARN_USING_OTHER_HANDLER,
+ ER(ER_WARN_USING_OTHER_HANDLER),
+ ha_resolve_storage_engine_name(lex->create_info.db_type),
+ $5->table.str);
+ }
+ }
| CREATE opt_unique_or_fulltext INDEX_SYM ident key_alg ON
table_ident
{
@@ -1837,7 +1833,9 @@ opt_ev_comment: /* empty */ { $$= 0; }
ev_sql_stmt:
{
- LEX *lex= Lex;
+ THD *thd= YYTHD;
+ LEX *lex= thd->lex;
+ Lex_input_stream *lip= thd->m_lip;
/*
This stops the following :
@@ -1874,22 +1872,23 @@ ev_sql_stmt:
bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
lex->sphead->m_chistics= &lex->sp_chistics;
- lex->sphead->m_body_begin= lex->ptr;
+ lex->sphead->m_body_begin= lip->ptr;
- Lex->event_parse_data->body_begin= lex->ptr;
+ lex->event_parse_data->body_begin= lip->ptr;
}
ev_sql_stmt_inner
{
- LEX *lex=Lex;
+ THD *thd= YYTHD;
+ LEX *lex= thd->lex;
/* return back to the original memory root ASAP */
- lex->sphead->init_strings(YYTHD, lex);
- lex->sphead->restore_thd_mem_root(YYTHD);
+ lex->sphead->init_strings(thd, lex);
+ lex->sphead->restore_thd_mem_root(thd);
lex->sp_chistics.suid= SP_IS_SUID; //always the definer!
- Lex->event_parse_data->init_body(YYTHD);
+ lex->event_parse_data->init_body(thd);
}
;
@@ -1983,7 +1982,9 @@ create_function_tail:
}
| '('
{
- LEX *lex= Lex;
+ THD *thd= YYTHD;
+ LEX *lex= thd->lex;
+ Lex_input_stream *lip= thd->m_lip;
sp_head *sp;
/*
@@ -2003,9 +2004,9 @@ create_function_tail:
}
/* Order is important here: new - reset - init */
sp= new sp_head();
- sp->reset_thd_mem_root(YYTHD);
+ sp->reset_thd_mem_root(thd);
sp->init(lex);
- sp->init_sp_name(YYTHD, lex->spname);
+ sp->init_sp_name(thd, lex->spname);
sp->m_type= TYPE_ENUM_FUNCTION;
lex->sphead= sp;
@@ -2014,15 +2015,17 @@ create_function_tail:
stored procedure, otherwise yylex will chop it into pieces
at each ';'.
*/
- $<ulong_num>$= YYTHD->client_capabilities & CLIENT_MULTI_QUERIES;
- YYTHD->client_capabilities &= ~CLIENT_MULTI_QUERIES;
- lex->sphead->m_param_begin= lex->tok_start+1;
+ $<ulong_num>$= thd->client_capabilities & CLIENT_MULTI_QUERIES;
+ thd->client_capabilities &= ~CLIENT_MULTI_QUERIES;
+ lex->sphead->m_param_begin= lip->tok_start+1;
}
sp_fdparam_list ')'
{
- LEX *lex= Lex;
+ THD *thd= YYTHD;
+ LEX *lex= thd->lex;
+ Lex_input_stream *lip= thd->m_lip;
- lex->sphead->m_param_end= lex->tok_start;
+ lex->sphead->m_param_end= lip->tok_start;
}
RETURNS_SYM
{
@@ -2057,10 +2060,12 @@ create_function_tail:
}
sp_c_chistics
{
- LEX *lex= Lex;
+ THD *thd= YYTHD;
+ LEX *lex= thd->lex;
+ Lex_input_stream *lip= thd->m_lip;
lex->sphead->m_chistics= &lex->sp_chistics;
- lex->sphead->m_body_begin= lex->tok_start;
+ lex->sphead->m_body_begin= lip->tok_start;
}
sp_proc_stmt
{
@@ -2666,14 +2671,18 @@ sp_proc_stmt_if:
sp_proc_stmt_statement:
{
- LEX *lex= Lex;
+ THD *thd= YYTHD;
+ LEX *lex= thd->lex;
+ Lex_input_stream *lip= thd->m_lip;
- lex->sphead->reset_lex(YYTHD);
- lex->sphead->m_tmp_query= lex->tok_start;
+ lex->sphead->reset_lex(thd);
+ lex->sphead->m_tmp_query= lip->tok_start;
}
statement
{
- LEX *lex= Lex;
+ THD *thd= YYTHD;
+ LEX *lex= thd->lex;
+ Lex_input_stream *lip= thd->m_lip;
sp_head *sp= lex->sphead;
sp->m_flags|= sp_get_flags_for_command(lex);
@@ -2700,15 +2709,15 @@ sp_proc_stmt_statement:
lex->tok_end otherwise.
*/
if (yychar == YYEMPTY)
- i->m_query.length= lex->ptr - sp->m_tmp_query;
+ i->m_query.length= lip->ptr - sp->m_tmp_query;
else
- i->m_query.length= lex->tok_end - sp->m_tmp_query;
- i->m_query.str= strmake_root(YYTHD->mem_root,
+ i->m_query.length= lip->tok_end - sp->m_tmp_query;
+ i->m_query.str= strmake_root(thd->mem_root,
sp->m_tmp_query,
i->m_query.length);
sp->add_instr(i);
}
- sp->restore_lex(YYTHD);
+ sp->restore_lex(thd);
}
;
@@ -3669,6 +3678,13 @@ partitioning:
{
#ifdef WITH_PARTITION_STORAGE_ENGINE
LEX *lex= Lex;
+ LEX_STRING partition_name={C_STRING_WITH_LEN("partition")};
+ if (!plugin_is_ready(&partition_name, MYSQL_STORAGE_ENGINE_PLUGIN))
+ {
+ my_error(ER_FEATURE_DISABLED, MYF(0),
+ "partitioning", "--with-partition");
+ MYSQL_YYABORT;
+ }
lex->part_info= new partition_info();
if (!lex->part_info)
{
@@ -4384,35 +4400,42 @@ default_collation:
Lex->create_info.used_fields|= HA_CREATE_USED_DEFAULT_CHARSET;
};
-known_storage_engines:
- ident_or_text
- {
- $$ = ha_resolve_by_name(YYTHD, &$1);
- if ($$ == NULL)
- {
- my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
- MYSQL_YYABORT;
- }
- }
- ;
-
storage_engines:
ident_or_text
{
- $$ = ha_resolve_by_name(YYTHD, &$1);
- if ($$ == NULL)
+ plugin_ref plugin= ha_resolve_by_name(YYTHD, &$1);
+
+ if (plugin)
+ $$= plugin_data(plugin, handlerton*);
+ else
{
if (YYTHD->variables.sql_mode & MODE_NO_ENGINE_SUBSTITUTION)
- {
- my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
- MYSQL_YYABORT;
- }
-
+ {
+ my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
+ MYSQL_YYABORT;
+ }
+ $$= 0;
push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_UNKNOWN_STORAGE_ENGINE,
- ER(ER_UNKNOWN_STORAGE_ENGINE), $1.str);
+ ER(ER_UNKNOWN_STORAGE_ENGINE),
+ $1.str);
}
- };
+ }
+ ;
+
+known_storage_engines:
+ ident_or_text
+ {
+ plugin_ref plugin;
+ if ((plugin= ha_resolve_by_name(YYTHD, &$1)))
+ $$= plugin_data(plugin, handlerton*);
+ else
+ {
+ my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str);
+ MYSQL_YYABORT;
+ }
+ }
+ ;
row_types:
DEFAULT { $$= ROW_TYPE_DEFAULT; }
@@ -5155,7 +5178,7 @@ alter:
lex->spname= $3;
}
| ALTER view_algorithm definer
- {
+ {
Lex->create_view_mode= VIEW_ALTER;
}
view_tail
@@ -5169,10 +5192,10 @@ alter:
{
LEX *lex= Lex;
lex->create_view_algorithm= VIEW_ALGORITHM_UNDEFINED;
- lex->create_view_mode= VIEW_ALTER;
- }
+ lex->create_view_mode= VIEW_ALTER;
+ }
view_tail
- {}
+ {}
| ALTER definer EVENT_SYM sp_name
/*
BE CAREFUL when you add a new rule to update the block where
@@ -5982,7 +6005,7 @@ preload_keys:
;
cache_keys_spec:
- {
+ {
Lex->select_lex.alloc_index_hints(YYTHD);
Select->set_index_hint_type(INDEX_HINT_USE,
global_system_variables.old_mode ?
@@ -6089,7 +6112,7 @@ select_into:
| select_from into;
select_from:
- FROM join_table_list where_clause group_clause having_clause
+ FROM join_table_list where_clause group_clause having_clause
opt_order_clause opt_limit_clause procedure_clause
{
Select->context.table_list=
@@ -6196,26 +6219,36 @@ select_item_list:
select_item:
remember_name select_item2 remember_end select_alias
{
- if (add_item_to_list(YYTHD, $2))
+ THD *thd= YYTHD;
+ DBUG_ASSERT($1 < $3);
+
+ if (add_item_to_list(thd, $2))
MYSQL_YYABORT;
if ($4.str)
{
$2->is_autogenerated_name= FALSE;
$2->set_name($4.str, $4.length, system_charset_info);
}
- else if (!$2->name) {
- char *str = $1;
- if (str[-1] == '`')
- str--;
- $2->set_name(str,(uint) ($3 - str), YYTHD->charset());
+ else if (!$2->name)
+ {
+ $2->set_name($1, (uint) ($3 - $1), thd->charset());
}
};
+
remember_name:
- { $$=(char*) Lex->tok_start; };
+ {
+ THD *thd= YYTHD;
+ Lex_input_stream *lip= thd->m_lip;
+ $$= (char*) lip->tok_start;
+ };
remember_end:
- { $$=(char*) Lex->tok_end; };
+ {
+ THD *thd= YYTHD;
+ Lex_input_stream *lip= thd->m_lip;
+ $$=(char*) lip->tok_end;
+ };
select_item2:
table_wild { $$=$1; } /* table.* */
@@ -6296,8 +6329,8 @@ bool_test:
{ $$= new (YYTHD->mem_root) Item_func_isfalse($1); }
| bool_pri IS not FALSE_SYM
{ $$= new (YYTHD->mem_root) Item_func_isnotfalse($1); }
- | bool_pri IS UNKNOWN_SYM { $$= new Item_func_isnull($1); }
- | bool_pri IS not UNKNOWN_SYM { $$= new Item_func_isnotnull($1); }
+ | bool_pri IS UNKNOWN_SYM { $$= new Item_func_isnull($1); }
+ | bool_pri IS not UNKNOWN_SYM { $$= new Item_func_isnotnull($1); }
| bool_pri
;
@@ -6312,11 +6345,11 @@ bool_pri:
| predicate ;
predicate:
- bit_expr IN_SYM '(' subselect ')'
+ bit_expr IN_SYM '(' subselect ')'
{
$$= new (YYTHD->mem_root) Item_in_subselect($1, $4);
}
- | bit_expr not IN_SYM '(' subselect ')'
+ | bit_expr not IN_SYM '(' subselect ')'
{
THD *thd= YYTHD;
Item *item= new (thd->mem_root) Item_in_subselect($1, $5);
@@ -6326,23 +6359,23 @@ predicate:
{
$$= handle_sql2003_note184_exception(YYTHD, $1, true, $4);
}
- | bit_expr IN_SYM '(' expr ',' expr_list ')'
- {
- $6->push_front($4);
- $6->push_front($1);
+ | bit_expr IN_SYM '(' expr ',' expr_list ')'
+ {
+ $6->push_front($4);
+ $6->push_front($1);
$$= new (YYTHD->mem_root) Item_func_in(*$6);
}
| bit_expr not IN_SYM '(' expr ')'
{
$$= handle_sql2003_note184_exception(YYTHD, $1, false, $5);
}
- | bit_expr not IN_SYM '(' expr ',' expr_list ')'
+ | bit_expr not IN_SYM '(' expr ',' expr_list ')'
{
- $7->push_front($5);
- $7->push_front($1);
+ $7->push_front($5);
+ $7->push_front($1);
Item_func_in *item = new (YYTHD->mem_root) Item_func_in(*$7);
- item->negate();
- $$= item;
+ item->negate();
+ $$= item;
}
| bit_expr BETWEEN_SYM bit_expr AND_SYM predicate
{ $$= new Item_func_between($1,$3,$5); }
@@ -6477,15 +6510,13 @@ simple_expr:
}
| BINARY simple_expr %prec NEG
{
- $$= create_func_cast(YYTHD, $2, ITEM_CAST_CHAR, -1, 0,
+ $$= create_func_cast(YYTHD, $2, ITEM_CAST_CHAR, NULL, NULL,
&my_charset_bin);
}
| CAST_SYM '(' expr AS cast_type ')'
{
LEX *lex= Lex;
- $$= create_func_cast(YYTHD, $3, $5,
- lex->length ? atoi(lex->length) : -1,
- lex->dec ? atoi(lex->dec) : 0,
+ $$= create_func_cast(YYTHD, $3, $5, lex->length, lex->dec,
lex->charset);
if (!$$)
MYSQL_YYABORT;
@@ -6494,10 +6525,8 @@ simple_expr:
{ $$= new (YYTHD->mem_root) Item_func_case(* $3, $2, $4 ); }
| CONVERT_SYM '(' expr ',' cast_type ')'
{
- $$= create_func_cast(YYTHD, $3, $5,
- Lex->length ? atoi(Lex->length) : -1,
- Lex->dec ? atoi(Lex->dec) : 0,
- Lex->charset);
+ $$= create_func_cast(YYTHD, $3, $5, Lex->length, Lex->dec,
+ Lex->charset);
if (!$$)
MYSQL_YYABORT;
}
@@ -7546,10 +7575,10 @@ opt_outer:
index_hint_clause:
/* empty */
- {
+ {
$$= global_system_variables.old_mode ?
INDEX_HINT_MASK_JOIN : INDEX_HINT_MASK_ALL;
- }
+ }
| FOR_SYM JOIN_SYM { $$= INDEX_HINT_MASK_JOIN; }
| FOR_SYM ORDER_SYM BY { $$= INDEX_HINT_MASK_ORDER; }
| FOR_SYM GROUP_SYM BY { $$= INDEX_HINT_MASK_GROUP; }
@@ -7562,12 +7591,12 @@ index_hint_type:
index_hint_definition:
index_hint_type key_or_index index_hint_clause
- {
+ {
Select->set_index_hint_type($1, $3);
- }
+ }
'(' key_usage_list ')'
| USE_SYM key_or_index index_hint_clause
- {
+ {
Select->set_index_hint_type(INDEX_HINT_USE, $3);
}
'(' opt_key_usage_list ')'
@@ -7576,12 +7605,12 @@ index_hint_definition:
index_hints_list:
index_hint_definition
| index_hints_list index_hint_definition
- ;
+ ;
opt_index_hints_list:
/* empty */
| { Select->alloc_index_hints(YYTHD); } index_hints_list
- ;
+ ;
opt_key_definition:
{ Select->clear_index_hints(); }
@@ -7595,7 +7624,7 @@ opt_key_usage_list:
key_usage_element:
ident { Select->add_index_hint(YYTHD, $1.str, $1.length); }
- | PRIMARY_SYM
+ | PRIMARY_SYM
{
Select->add_index_hint(YYTHD, (char *)"PRIMARY", 7);
}
@@ -7983,12 +8012,14 @@ procedure_list2:
procedure_item:
remember_name expr
{
- LEX *lex= Lex;
- if (add_proc_to_list(lex->thd, $2))
+ THD *thd= YYTHD;
+ Lex_input_stream *lip= thd->m_lip;
+
+ if (add_proc_to_list(thd, $2))
MYSQL_YYABORT;
if (!$2->name)
- $2->set_name($1,(uint) ((char*) lex->tok_end - $1),
- YYTHD->charset());
+ $2->set_name($1,(uint) ((char*) lip->tok_end - $1),
+ thd->charset());
}
;
@@ -8632,7 +8663,7 @@ show_param:
{ Lex->create_info.db_type= NULL; }
| opt_full COLUMNS from_or_in table_ident opt_db wild_and_where
{
- LEX *lex= Lex;
+ LEX *lex= Lex;
lex->sql_command= SQLCOM_SHOW_FIELDS;
if ($5)
$4->change_db($5);
@@ -9078,13 +9109,16 @@ use: USE_SYM ident
load: LOAD DATA_SYM
{
- LEX *lex=Lex;
+ THD *thd= YYTHD;
+ LEX *lex= thd->lex;
+ Lex_input_stream *lip= thd->m_lip;
+
if (lex->sphead)
{
my_error(ER_SP_BADSTATEMENT, MYF(0), "LOAD DATA");
MYSQL_YYABORT;
}
- lex->fname_start= lex->ptr;
+ lex->fname_start= lip->ptr;
}
load_data
{}
@@ -9118,8 +9152,10 @@ load_data:
}
opt_duplicate INTO
{
- LEX *lex=Lex;
- lex->fname_end= lex->ptr;
+ THD *thd= YYTHD;
+ LEX *lex= thd->lex;
+ Lex_input_stream *lip= thd->m_lip;
+ lex->fname_end= lip->ptr;
}
TABLE_SYM table_ident
{
@@ -9300,14 +9336,15 @@ param_marker:
PARAM_MARKER
{
THD *thd= YYTHD;
- LEX *lex= thd->lex;
+ LEX *lex= thd->lex;
+ Lex_input_stream *lip= thd->m_lip;
Item_param *item;
if (! lex->parsing_options.allows_variable)
{
my_error(ER_VIEW_SELECT_VARIABLE, MYF(0));
MYSQL_YYABORT;
}
- item= new Item_param((uint) (lex->tok_start - thd->query));
+ item= new Item_param((uint) (lip->tok_start - thd->query));
if (!($$= item) || lex->param_list.push_back(item))
{
my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
@@ -9330,8 +9367,11 @@ signed_literal:
literal:
text_literal { $$ = $1; }
| NUM_literal { $$ = $1; }
- | NULL_SYM { $$ = new Item_null();
- Lex->next_state=MY_LEX_OPERATOR_OR_IDENT;}
+ | NULL_SYM
+ {
+ $$ = new Item_null();
+ YYTHD->m_lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
+ }
| FALSE_SYM { $$= new Item_int((char*) "FALSE",0,1); }
| TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); }
| HEX_NUM { $$ = new Item_hex_string($1.str, $1.length);}
@@ -9421,8 +9461,10 @@ order_ident:
simple_ident:
ident
{
+ THD *thd= YYTHD;
+ LEX *lex= thd->lex;
+ Lex_input_stream *lip= thd->m_lip;
sp_variable_t *spv;
- LEX *lex = Lex;
sp_pcontext *spc = lex->spcont;
if (spc && (spv = spc->find_variable(&$1)))
{
@@ -9435,7 +9477,7 @@ simple_ident:
Item_splocal *splocal;
splocal= new Item_splocal($1, spv->offset, spv->type,
- lex->tok_start_prev -
+ lip->tok_start_prev -
lex->sphead->m_tmp_query);
#ifndef DBUG_OFF
if (splocal)
@@ -10086,7 +10128,11 @@ option_value_list:
option_type_value:
{
- if (Lex->sphead)
+ THD *thd= YYTHD;
+ LEX *lex= thd->lex;
+ Lex_input_stream *lip= thd->m_lip;
+
+ if (lex->sphead)
{
/*
If we are in SP we want have own LEX for each assignment.
@@ -10098,9 +10144,8 @@ option_type_value:
QQ: May be we should simply prohibit group assignments in SP?
*/
- LEX *lex;
- Lex->sphead->reset_lex(YYTHD);
- lex= Lex;
+ lex->sphead->reset_lex(thd);
+ lex= thd->lex;
/* Set new LEX as if we at start of set rule. */
lex->sql_command= SQLCOM_SET_OPTION;
@@ -10108,12 +10153,14 @@ option_type_value:
lex->option_type=OPT_SESSION;
lex->var_list.empty();
lex->one_shot_set= 0;
- lex->sphead->m_tmp_query= lex->tok_start;
+ lex->sphead->m_tmp_query= lip->tok_start;
}
}
ext_option_value
{
- LEX *lex= Lex;
+ THD *thd= YYTHD;
+ LEX *lex= thd->lex;
+ Lex_input_stream *lip= thd->m_lip;
if (lex->sphead)
{
@@ -10135,16 +10182,15 @@ option_type_value:
/*
Extract the query statement from the tokenizer. The
- end is either lex->ptr, if there was no lookahead,
- lex->tok_end otherwise.
+ end is either lip->ptr, if there was no lookahead,
+ lip->tok_end otherwise.
*/
if (yychar == YYEMPTY)
- qbuff.length= lex->ptr - sp->m_tmp_query;
+ qbuff.length= lip->ptr - sp->m_tmp_query;
else
- qbuff.length= lex->tok_end - sp->m_tmp_query;
+ qbuff.length= lip->tok_end - sp->m_tmp_query;
- if (!(qbuff.str= (char*) alloc_root(YYTHD->mem_root,
- qbuff.length + 5)))
+ if (!(qbuff.str= alloc_root(thd->mem_root, qbuff.length + 5)))
MYSQL_YYABORT;
strmake(strmake(qbuff.str, "SET ", 4), sp->m_tmp_query,
@@ -10153,7 +10199,7 @@ option_type_value:
i->m_query= qbuff;
sp->add_instr(i);
}
- lex->sphead->restore_lex(YYTHD);
+ lex->sphead->restore_lex(thd);
}
};
@@ -10274,7 +10320,7 @@ sys_option_value:
LEX *lex=Lex;
lex->option_type= $1;
lex->var_list.push_back(new set_var(lex->option_type,
- find_sys_var("tx_isolation"),
+ find_sys_var(YYTHD, "tx_isolation"),
&null_lex_str,
new Item_int((int32) $5)));
}
@@ -10363,7 +10409,7 @@ internal_variable_name:
if (!spc || !(spv = spc->find_variable(&$1)))
{
/* Not an SP local variable */
- sys_var *tmp=find_sys_var($1.str, $1.length);
+ sys_var *tmp=find_sys_var(YYTHD, $1.str, $1.length);
if (!tmp)
MYSQL_YYABORT;
$$.var= tmp;
@@ -10418,7 +10464,7 @@ internal_variable_name:
}
else
{
- sys_var *tmp=find_sys_var($3.str, $3.length);
+ sys_var *tmp=find_sys_var(YYTHD, $3.str, $3.length);
if (!tmp)
MYSQL_YYABORT;
if (!tmp->is_struct())
@@ -10429,7 +10475,7 @@ internal_variable_name:
}
| DEFAULT '.' ident
{
- sys_var *tmp=find_sys_var($3.str, $3.length);
+ sys_var *tmp=find_sys_var(YYTHD, $3.str, $3.length);
if (!tmp)
MYSQL_YYABORT;
if (!tmp->is_struct())
@@ -11403,7 +11449,9 @@ trigger_tail:
TRIGGER_SYM remember_name sp_name trg_action_time trg_event
ON remember_name table_ident FOR_SYM remember_name EACH_SYM ROW_SYM
{
- LEX *lex= Lex;
+ THD *thd= YYTHD;
+ LEX *lex= thd->lex;
+ Lex_input_stream *lip= thd->m_lip;
sp_head *sp;
if (lex->sphead)
@@ -11414,9 +11462,9 @@ trigger_tail:
if (!(sp= new sp_head()))
MYSQL_YYABORT;
- sp->reset_thd_mem_root(YYTHD);
+ sp->reset_thd_mem_root(thd);
sp->init(lex);
- sp->init_sp_name(YYTHD, $3);
+ sp->init_sp_name(thd, $3);
lex->stmt_definition_begin= $2;
lex->ident.str= $7;
lex->ident.length= $10 - $7;
@@ -11429,12 +11477,12 @@ trigger_tail:
stored procedure, otherwise yylex will chop it into pieces
at each ';'.
*/
- $<ulong_num>$= YYTHD->client_capabilities & CLIENT_MULTI_QUERIES;
- YYTHD->client_capabilities &= ~CLIENT_MULTI_QUERIES;
+ $<ulong_num>$= thd->client_capabilities & CLIENT_MULTI_QUERIES;
+ thd->client_capabilities &= ~CLIENT_MULTI_QUERIES;
bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
lex->sphead->m_chistics= &lex->sp_chistics;
- lex->sphead->m_body_begin= lex->ptr;
+ lex->sphead->m_body_begin= lip->ptr;
while (my_isspace(system_charset_info, lex->sphead->m_body_begin[0]))
++lex->sphead->m_body_begin;
}
@@ -11513,24 +11561,30 @@ sp_tail:
}
'('
{
- LEX *lex= Lex;
+ THD *thd= YYTHD;
+ LEX *lex= thd->lex;
+ Lex_input_stream *lip= thd->m_lip;
- lex->sphead->m_param_begin= lex->tok_start+1;
+ lex->sphead->m_param_begin= lip->tok_start+1;
}
sp_pdparam_list
')'
{
- LEX *lex= Lex;
+ THD *thd= YYTHD;
+ LEX *lex= thd->lex;
+ Lex_input_stream *lip= thd->m_lip;
- lex->sphead->m_param_end= lex->tok_start;
+ lex->sphead->m_param_end= lip->tok_start;
bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
}
sp_c_chistics
{
- LEX *lex= Lex;
+ THD *thd= YYTHD;
+ LEX *lex= thd->lex;
+ Lex_input_stream *lip= thd->m_lip;
lex->sphead->m_chistics= &lex->sp_chistics;
- lex->sphead->m_body_begin= lex->tok_start;
+ lex->sphead->m_body_begin= lip->tok_start;
}
sp_proc_stmt
{
diff --git a/sql/structs.h b/sql/structs.h
index 22d08e51961..da2339d27f8 100644
--- a/sql/structs.h
+++ b/sql/structs.h
@@ -83,7 +83,7 @@ typedef struct st_key {
*/
union
{
- struct st_plugin_int *parser; /* Fulltext [pre]parser */
+ plugin_ref parser; /* Fulltext [pre]parser */
LEX_STRING *parser_name; /* Fulltext [pre]parser name */
};
KEY_PART_INFO *key_part;
diff --git a/sql/table.cc b/sql/table.cc
index e0690107f4e..5b2b78ed628 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -237,6 +237,9 @@ void free_table_share(TABLE_SHARE *share)
pthread_cond_destroy(&share->cond);
}
hash_free(&share->name_hash);
+
+ plugin_unlock(NULL, share->db_plugin);
+ share->db_plugin= NULL;
/* We must copy mem_root from share because share is allocated through it */
memcpy((char*) &mem_root, (char*) &share->mem_root, sizeof(mem_root));
@@ -501,7 +504,15 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
DBUG_PRINT("info", ("default_part_db_type = %u", head[61]));
#endif
legacy_db_type= (enum legacy_db_type) (uint) *(head+3);
- share->db_type= ha_checktype(thd, legacy_db_type, 0, 0);
+ DBUG_ASSERT(share->db_plugin == NULL);
+ /*
+ if the storage engine is dynamic, no point in resolving it by its
+ dynamically allocated legacy_db_type. We will resolve it later by name.
+ */
+ if (legacy_db_type > DB_TYPE_UNKNOWN &&
+ legacy_db_type < DB_TYPE_FIRST_DYNAMIC)
+ share->db_plugin= ha_lock_engine(NULL,
+ ha_checktype(thd, legacy_db_type, 0, 0));
share->db_create_options= db_create_options= uint2korr(head+30);
share->db_options_in_use= share->db_create_options;
share->mysql_version= uint4korr(head+51);
@@ -662,29 +673,50 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
{
uint str_db_type_length= uint2korr(next_chunk);
LEX_STRING name;
- handlerton *tmp_db_type;
-
name.str= (char*) next_chunk + 2;
name.length= str_db_type_length;
- tmp_db_type= ha_resolve_by_name(thd, &name);
- if (tmp_db_type != NULL)
+ plugin_ref tmp_plugin= ha_resolve_by_name(thd, &name);
+ if (tmp_plugin != NULL && !plugin_equals(tmp_plugin, share->db_plugin))
{
- share->db_type= tmp_db_type;
+ if (legacy_db_type > DB_TYPE_UNKNOWN &&
+ legacy_db_type < DB_TYPE_FIRST_DYNAMIC &&
+ legacy_db_type != ha_legacy_type(
+ plugin_data(tmp_plugin, handlerton *)))
+ {
+ /* bad file, legacy_db_type did not match the name */
+ my_free(buff, MYF(0));
+ goto err;
+ }
+ /*
+ tmp_plugin is locked with a local lock.
+ we unlock the old value of share->db_plugin before
+ replacing it with a globally locked version of tmp_plugin
+ */
+ plugin_unlock(NULL, share->db_plugin);
+ share->db_plugin= my_plugin_lock(NULL, &tmp_plugin);
DBUG_PRINT("info", ("setting dbtype to '%.*s' (%d)",
str_db_type_length, next_chunk + 2,
- ha_legacy_type(share->db_type)));
+ ha_legacy_type(share->db_type())));
}
#ifdef WITH_PARTITION_STORAGE_ENGINE
else
{
- if (!strncmp((char*) next_chunk + 2, "partition", str_db_type_length))
+ LEX_STRING pname= { C_STRING_WITH_LEN( "partition" ) };
+ if (str_db_type_length == pname.length &&
+ !strncmp(next_chunk + 2, pname.str, pname.length))
{
- /* Use partition handler */
- share->db_type= partition_hton;
+ /*
+ Use partition handler
+ tmp_plugin is locked with a local lock.
+ we unlock the old value of share->db_plugin before
+ replacing it with a globally locked version of tmp_plugin
+ */
+ plugin_unlock(NULL, share->db_plugin);
+ share->db_plugin= ha_lock_engine(NULL, partition_hton);
DBUG_PRINT("info", ("setting dbtype to '%.*s' (%d)",
str_db_type_length, next_chunk + 2,
- ha_legacy_type(share->db_type)));
+ ha_legacy_type(share->db_type())));
}
}
#endif
@@ -750,7 +782,8 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
}
parser_name.str= (char*) next_chunk;
parser_name.length= strlen((char*) next_chunk);
- keyinfo->parser= plugin_lock(&parser_name, MYSQL_FTPARSER_PLUGIN);
+ keyinfo->parser= my_plugin_lock_by_name(NULL, &parser_name,
+ MYSQL_FTPARSER_PLUGIN);
if (! keyinfo->parser)
{
my_error(ER_PLUGIN_IS_NOT_LOADED, MYF(0), parser_name.str);
@@ -866,7 +899,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
/* Allocate handler */
if (!(handler_file= get_new_handler(share, thd->mem_root,
- share->db_type)))
+ share->db_type())))
goto err;
record= share->default_values-1; /* Fieldstart = 1 */
@@ -1400,7 +1433,7 @@ int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
/* Allocate handler */
if (!(outparam->file= get_new_handler(share, &outparam->mem_root,
- share->db_type)))
+ share->db_type())))
goto err;
error= 4;
@@ -1684,7 +1717,7 @@ int closefrm(register TABLE *table, bool free_share)
{
if (key_info->flags & HA_USES_PARSER)
{
- plugin_unlock(key_info->parser);
+ plugin_unlock(NULL, key_info->parser);
key_info->flags= 0;
}
}
@@ -1900,10 +1933,10 @@ void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg)
handler *file= 0;
const char *datext= "";
- if (share->db_type != NULL)
+ if (share->db_type() != NULL)
{
if ((file= get_new_handler(share, current_thd->mem_root,
- share->db_type)))
+ share->db_type())))
{
if (!(datext= *file->bas_ext()))
datext= "";
diff --git a/sql/table.h b/sql/table.h
index f3fc33c2719..c4c7da7d0c2 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -172,7 +172,12 @@ typedef struct st_table_share
ulong timestamp_offset; /* Set to offset+1 of record */
ulong reclength; /* Recordlength */
- handlerton *db_type; /* table_type for handler */
+ plugin_ref db_plugin; /* storage engine plugin */
+ inline handlerton *db_type() const /* table_type for handler */
+ {
+ // DBUG_ASSERT(db_plugin);
+ return db_plugin ? plugin_data(db_plugin, handlerton*) : NULL;
+ }
enum row_type row_type; /* How rows are stored */
enum tmp_table_type tmp_table;
@@ -299,6 +304,8 @@ typedef struct st_table_share
} TABLE_SHARE;
+extern ulong refresh_version;
+
/* Information for one open table */
enum index_hint_type
{
@@ -314,8 +321,8 @@ struct st_table {
handler *file;
#ifdef NOT_YET
struct st_table *used_next, **used_prev; /* Link to used tables */
-#endif
struct st_table *open_next, **open_prev; /* Link to open tables */
+#endif
struct st_table *next, *prev;
THD *in_use; /* Which thread uses this */
@@ -433,7 +440,24 @@ struct st_table {
my_bool force_index;
my_bool distinct,const_table,no_rows;
my_bool key_read, no_keyread;
- my_bool locked_by_flush;
+ /*
+ Placeholder for an open table which prevents other connections
+ from taking name-locks on this table. Typically used with
+ TABLE_SHARE::version member to take an exclusive name-lock on
+ this table name -- a name lock that not only prevents other
+ threads from opening the table, but also blocks other name
+ locks. This is achieved by:
+ - setting open_placeholder to 1 - this will block other name
+ locks, as wait_for_locked_table_name will be forced to wait,
+ see table_is_used for details.
+ - setting version to 0 - this will force other threads to close
+ the instance of this table and wait (this is the same approach
+ as used for usual name locks).
+ An exclusively name-locked table currently can have no handler
+ object associated with it (db_stat is always 0), but please do
+ not rely on that.
+ */
+ my_bool open_placeholder;
my_bool locked_by_logger;
my_bool no_replicate;
my_bool locked_by_name;
@@ -494,7 +518,13 @@ struct st_table {
read_set= &def_read_set;
write_set= &def_write_set;
}
-
+ /* Is table open or should be treated as such by name-locking? */
+ inline bool is_name_opened() { return db_stat || open_placeholder; }
+ /*
+ Is this instance of the table should be reopen or represents a name-lock?
+ */
+ inline bool needs_reopen_or_name_lock()
+ { return s->version != refresh_version; }
};
enum enum_schema_table_state
@@ -890,6 +920,12 @@ typedef struct st_table_list
used for implicit LOCK TABLES only and won't be used in real statement.
*/
bool prelocking_placeholder;
+ /*
+ This TABLE_LIST object corresponds to the table to be created
+ so it is possible that it does not exist (used in CREATE TABLE
+ ... SELECT implementation).
+ */
+ bool create;
enum enum_schema_table_state schema_table_state;
void calc_md5(char *buffer);
@@ -897,7 +933,11 @@ typedef struct st_table_list
int view_check_option(THD *thd, bool ignore_failure);
bool setup_underlying(THD *thd);
void cleanup_items();
- bool placeholder() {return derived || view || schema_table || !table; }
+ bool placeholder()
+ {
+ return derived || view || schema_table || create && !table->db_stat ||
+ !table;
+ }
void print(THD *thd, String *str);
bool check_single_table(st_table_list **table, table_map map,
st_table_list *view);