summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2020-02-27 10:28:49 +0100
committerSergei Golubchik <serg@mariadb.org>2020-02-27 10:30:21 +0100
commit98adcffe460447c43a86afdf6588e31379b7f52d (patch)
tree0c0cf97a066b2449f99b3bc8be3cf85c8866fa4e /sql
parent9894751a2a61ef952ac6ac556fd683e53fc150e2 (diff)
downloadmariadb-git-98adcffe460447c43a86afdf6588e31379b7f52d.tar.gz
Revert "MDEV-17554 Auto-create new partition for system versioned tables with history partitioned by INTERVAL/LIMIT"
This reverts commit 9894751a2a61ef952ac6ac556fd683e53fc150e2. This reverts commit f707c83fff4fa3f5291684e6226542fdb75bbdeb.
Diffstat (limited to 'sql')
-rw-r--r--sql/mysqld.cc5
-rw-r--r--sql/mysqld.h2
-rw-r--r--sql/partition_info.cc278
-rw-r--r--sql/partition_info.h41
-rw-r--r--sql/share/errmsg-utf8.txt6
-rw-r--r--sql/sql_partition.cc15
-rw-r--r--sql/sql_yacc.yy38
-rw-r--r--sql/table.h3
8 files changed, 43 insertions, 345 deletions
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 7fdbb300298..b2f8afca7a6 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -1090,7 +1090,7 @@ static PSI_cond_info all_server_conds[]=
PSI_thread_key key_thread_delayed_insert,
key_thread_handle_manager, key_thread_main,
key_thread_one_connection, key_thread_signal_hand,
- key_thread_slave_background, key_rpl_parallel_thread, key_thread_query;
+ key_thread_slave_background, key_rpl_parallel_thread;
PSI_thread_key key_thread_ack_receiver;
static PSI_thread_info all_server_threads[]=
@@ -1102,8 +1102,7 @@ static PSI_thread_info all_server_threads[]=
{ &key_thread_signal_hand, "signal_handler", PSI_FLAG_GLOBAL},
{ &key_thread_slave_background, "slave_background", PSI_FLAG_GLOBAL},
{ &key_thread_ack_receiver, "Ack_receiver", PSI_FLAG_GLOBAL},
- { &key_rpl_parallel_thread, "rpl_parallel_thread", 0},
- { &key_thread_query, "vers_add_hist_part_thread", 0}
+ { &key_rpl_parallel_thread, "rpl_parallel_thread", 0}
};
#ifdef HAVE_MMAP
diff --git a/sql/mysqld.h b/sql/mysqld.h
index d1e13c2fc77..4f4e608e811 100644
--- a/sql/mysqld.h
+++ b/sql/mysqld.h
@@ -388,7 +388,7 @@ extern PSI_cond_key key_TABLE_SHARE_COND_rotation;
extern PSI_thread_key key_thread_delayed_insert,
key_thread_handle_manager, key_thread_kill_server, key_thread_main,
key_thread_one_connection, key_thread_signal_hand,
- key_thread_slave_background, key_rpl_parallel_thread, key_thread_query;
+ key_thread_slave_background, key_rpl_parallel_thread;
extern PSI_file_key key_file_binlog, key_file_binlog_index, key_file_casetest,
key_file_dbopt, key_file_des_key_file, key_file_ERRMSG, key_select_to_file,
diff --git a/sql/partition_info.cc b/sql/partition_info.cc
index cb79a28d4df..252744a3a73 100644
--- a/sql/partition_info.cc
+++ b/sql/partition_info.cc
@@ -322,11 +322,13 @@ bool partition_info::set_partition_bitmaps_from_table(TABLE_LIST *table_list)
The external routine needing this code is check_partition_info
*/
+#define MAX_PART_NAME_SIZE 8
+
char *partition_info::create_default_partition_names(THD *thd, uint part_no,
uint num_parts_arg,
uint start_no)
{
- char *ptr= (char*) thd->calloc(num_parts_arg * MAX_PART_NAME_SIZE + 1);
+ char *ptr= (char*) thd->calloc(num_parts_arg * MAX_PART_NAME_SIZE);
char *move_ptr= ptr;
uint i= 0;
DBUG_ENTER("create_default_partition_names");
@@ -335,8 +337,7 @@ char *partition_info::create_default_partition_names(THD *thd, uint part_no,
{
do
{
- if (make_partition_name(move_ptr, (start_no + i)))
- DBUG_RETURN(NULL);
+ sprintf(move_ptr, "p%u", (start_no + i));
move_ptr+= MAX_PART_NAME_SIZE;
} while (++i < num_parts_arg);
}
@@ -807,13 +808,6 @@ bool partition_info::has_unique_name(partition_element *element)
}
-/* Auto-create history partition configuration */
-static const uint VERS_MIN_EMPTY= 1;
-static const uint VERS_MIN_INTERVAL= 3600; // seconds
-static const uint VERS_MIN_LIMIT= 1000;
-static const uint VERS_ERROR_TIMEOUT= 300; // seconds
-
-
/**
@brief Switch history partition according limit or interval
@@ -851,266 +845,29 @@ void partition_info::vers_set_hist_part(THD *thd)
else
vers_info->hist_part= next;
}
- if (vers_info->limit >= VERS_MIN_LIMIT)
- goto add_hist_part;
return;
}
if (vers_info->interval.is_set())
{
- if (vers_info->hist_part->range_value <= thd->query_start())
- {
- partition_element *next= NULL;
- bool error= true;
- List_iterator<partition_element> it(partitions);
- while (next != vers_info->hist_part)
- next= it++;
-
- while ((next= it++) != vers_info->now_part)
- {
- vers_info->hist_part= next;
- if (next->range_value > thd->query_start())
- {
- error= false;
- break;
- }
- }
- if (error)
- my_error(WARN_VERS_PART_FULL, MYF(ME_WARNING|ME_ERROR_LOG),
- table->s->db.str, table->s->table_name.str,
- vers_info->hist_part->partition_name, "INTERVAL");
- }
- if (vers_info->interval.ge(VERS_MIN_INTERVAL))
- goto add_hist_part;
- }
-
- return;
-
-add_hist_part:
- if (!vers_info->auto_inc)
- return;
- switch (thd->lex->sql_command)
- {
- case SQLCOM_DELETE:
- if (thd->lex->last_table()->vers_conditions.type == SYSTEM_TIME_HISTORY)
- break;
- /* fallthrough */
- case SQLCOM_UPDATE:
- case SQLCOM_INSERT:
- case SQLCOM_INSERT_SELECT:
- case SQLCOM_LOAD:
- case SQLCOM_REPLACE:
- case SQLCOM_REPLACE_SELECT:
- case SQLCOM_DELETE_MULTI:
- case SQLCOM_UPDATE_MULTI:
- {
- time_t &timeout= table->s->vers_hist_part_timeout;
- if (!thd->slave_thread &&
- vers_info->hist_part->id + VERS_MIN_EMPTY == vers_info->now_part->id)
- {
- if (!timeout || timeout < thd->query_start())
- vers_add_hist_part(thd);
- else if (table->s->vers_hist_part_error)
- {
- my_error(WARN_VERS_HIST_PART_ERROR, MYF(ME_WARNING),
- table->s->db.str, table->s->table_name.str,
- table->s->vers_hist_part_error);
- }
- }
- }
- default:;
- }
-}
-
-
-struct vers_add_hist_part_data
-{
- LEX_STRING query;
- LEX_CSTRING db;
- LEX_CSTRING table_name;
- LEX_STRING part_name;
- my_time_t start_time;
- ulong start_time_sec_part;
-
- TABLE_SHARE *s;
-
- void assign(THD *thd, String &q, TABLE *table, LEX_CSTRING p)
- {
- start_time= thd->start_time;
- start_time_sec_part= thd->start_time_sec_part;
- s= table->s;
-
- memcpy(query.str, q.c_ptr_quick(), q.length());
- query.str[q.length()]= 0;
- query.length= q.length();
-
- db.length= table->s->db.length;
- memcpy((char *)db.str, table->s->db.str, db.length);
- ((char *)db.str)[db.length]= 0;
-
- table_name.length= table->s->table_name.length;
- memcpy((char *)table_name.str, table->s->table_name.str, table_name.length);
- ((char *)table_name.str)[table_name.length]= 0;
+ if (vers_info->hist_part->range_value > thd->query_start())
+ return;
- memcpy(part_name.str, p.str, p.length + 1);
- part_name.length= p.length;
- }
-};
-
-pthread_handler_t vers_add_hist_part_thread(void *arg)
-{
- Parser_state parser_state;
- uint error;
- DBUG_ASSERT(arg);
- vers_add_hist_part_data &d= *(vers_add_hist_part_data *) arg;
- sql_print_information("Adding history partition `%s` for table `%s`.`%s`",
- d.part_name.str,
- d.db.str,
- d.table_name.str);
- my_thread_init();
- /* Initialize THD */
- THD *thd= new THD(next_thread_id());
- if (unlikely(!thd))
- {
- my_error(ER_OUT_OF_RESOURCES, MYF(ME_ERROR_LOG));
- goto err1;
- }
- thd->thread_stack= (char*) &thd;
- thd->store_globals();
- thd->set_command(COM_DAEMON);
- thd->system_thread= SYSTEM_THREAD_GENERIC;
- thd->security_ctx->host_or_ip= "";
- thd->security_ctx->master_access= ALTER_ACL;
- thd->log_all_errors= true;
- thd->start_time= d.start_time;
- thd->start_time_sec_part= d.start_time_sec_part;
- server_threads.insert(thd);
- thd_proc_info(thd, "Add history partition");
- /* Initialize parser */
- lex_start(thd);
- if (unlikely(parser_state.init(thd, d.query.str, d.query.length)))
- {
- my_error(ER_OUT_OF_RESOURCES, MYF(ME_ERROR_LOG));
- lex_end(thd->lex);
- goto err2;
- }
- if (unlikely(parse_sql(thd, &parser_state, NULL)))
- {
- lex_end(thd->lex);
- goto err2;
- }
- thd->set_query_and_id(d.query.str, (uint32)d.query.length, thd->charset(), next_query_id());
- MYSQL_QUERY_EXEC_START(thd->query(), thd->thread_id, "", "", "", 0);
- error= (uint) mysql_execute_command(thd);
- MYSQL_QUERY_EXEC_DONE(error);
- if (unlikely(error) && thd->is_error())
- {
- error= thd->get_stmt_da()->get_sql_errno();
- thd->clear_error();
- TABLE_LIST table_list;
- table_list.init_one_table(&d.db, &d.table_name, &d.table_name, TL_UNLOCK);
- TABLE_SHARE *s= tdc_acquire_share(thd, &table_list, GTS_TABLE);
- if (s == d.s)
- {
- /* Timeout new ALTER for 5 minutes in case of error */
- s->vers_hist_part_timeout= thd->query_start() + VERS_ERROR_TIMEOUT;
- s->vers_hist_part_error= error;
- s->vers_altering= false;
- }
- if (s)
- tdc_release_share(s);
- }
- /* In case of success ALTER invalidates TABLE_SHARE */
- thd->end_statement();
- thd->cleanup_after_query();
-err2:
- server_threads.erase(thd);
- delete thd;
-err1:
- my_free(arg);
- my_thread_end();
- return NULL;
-}
-
-
-void partition_info::vers_add_hist_part(THD *thd)
-{
- pthread_t hThread;
- int error;
- char part_name[MAX_PART_NAME_SIZE + 1];
-
- /* Prevent spawning multiple instances of same task */
- bool altering;
- mysql_mutex_lock(&table->s->LOCK_share);
- altering= table->s->vers_altering;
- if (!altering)
- table->s->vers_altering= true;
- mysql_mutex_unlock(&table->s->LOCK_share);
- if (altering)
- return;
-
- /* Choose first non-occupied name suffix starting from id + 1 */
- uint32 suffix= vers_info->hist_part->id + 1;
- if (make_partition_name(part_name, suffix))
- {
- sql_print_warning("vers_add_hist_part name generation failed for suffix %d",
- suffix);
- my_error(WARN_VERS_HIST_PART_ERROR, MYF(ME_WARNING),
- table->s->db.str, table->s->table_name.str, 0);
- return;
- }
- List_iterator_fast<partition_element> it(partitions);
- partition_element *el;
+ partition_element *next= NULL;
+ List_iterator<partition_element> it(partitions);
+ while (next != vers_info->hist_part)
+ next= it++;
- while ((el= it++))
- {
- if (0 == my_strcasecmp(&my_charset_latin1, el->partition_name, part_name))
+ while ((next= it++) != vers_info->now_part)
{
- if (make_partition_name(part_name, ++suffix))
- {
- sql_print_warning("vers_add_hist_part name generation failed for suffix %d",
- suffix);
- my_error(WARN_VERS_HIST_PART_ERROR, MYF(ME_WARNING),
- table->s->db.str, table->s->table_name.str, 0);
+ vers_info->hist_part= next;
+ if (next->range_value > thd->query_start())
return;
- }
- it.rewind();
}
+ my_error(WARN_VERS_PART_FULL, MYF(ME_WARNING|ME_ERROR_LOG),
+ table->s->db.str, table->s->table_name.str,
+ vers_info->hist_part->partition_name, "INTERVAL");
}
-
- String q(STRING_WITH_LEN("ALTER TABLE `"), &my_charset_latin1);
- if (q.append(table->s->db) ||
- q.append(STRING_WITH_LEN("`.`")) ||
- q.append(table->s->table_name) ||
- q.append("` ADD PARTITION (PARTITION `") ||
- q.append(part_name) ||
- q.append("` HISTORY)"))
- {
- my_error(ER_OUT_OF_RESOURCES, MYF(ME_ERROR_LOG));
- return;
- }
- vers_add_hist_part_data *data;
- vers_add_hist_part_data bufs;
- LEX_CSTRING part_name2;
- part_name2.str= part_name;
- part_name2.length= strlen(part_name);
- if (!my_multi_malloc(MYF(MY_WME|ME_ERROR_LOG), &data, sizeof(*data),
- &bufs.query.str, q.length() + 1,
- &bufs.db.str, table->s->db.length + 1,
- &bufs.table_name.str, table->s->table_name.length + 1,
- &bufs.part_name.str, part_name2.length + 1,
- NULL))
- return;
- bufs.assign(thd, q, table, part_name2);
- *data= bufs;
-
- if ((error= mysql_thread_create(key_thread_query, &hThread,
- &connection_attrib, vers_add_hist_part_thread, data)))
- {
- sql_print_warning("Can't create vers_add_hist_part thread (errno= %d)",
- error);
- }
- return;
}
@@ -2889,14 +2646,13 @@ bool partition_info::vers_init_info(THD * thd)
bool partition_info::vers_set_interval(THD* thd, Item* interval,
interval_type int_type, Item* starts,
- bool auto_inc, const char *table_name)
+ const char *table_name)
{
DBUG_ASSERT(part_type == VERSIONING_PARTITION);
MYSQL_TIME ltime;
uint err;
vers_info->interval.type= int_type;
- vers_info->auto_inc= auto_inc;
/* 1. assign INTERVAL to interval.step */
if (interval->fix_fields_if_needed_for_scalar(thd, &interval))
diff --git a/sql/partition_info.h b/sql/partition_info.h
index 1534189af2a..eb8e53a381a 100644
--- a/sql/partition_info.h
+++ b/sql/partition_info.h
@@ -38,7 +38,6 @@ struct Vers_part_info : public Sql_alloc
{
Vers_part_info() :
limit(0),
- auto_inc(false),
now_part(NULL),
hist_part(NULL)
{
@@ -47,7 +46,6 @@ struct Vers_part_info : public Sql_alloc
Vers_part_info(Vers_part_info &src) :
interval(src.interval),
limit(src.limit),
- auto_inc(src.auto_inc),
now_part(NULL),
hist_part(NULL)
{
@@ -71,30 +69,9 @@ struct Vers_part_info : public Sql_alloc
my_time_t start;
INTERVAL step;
enum interval_type type;
- bool is_set() const { return type < INTERVAL_LAST; }
- bool lt(size_t seconds) const
- {
- if (step.second)
- return step.second < seconds;
- if (step.minute)
- return step.minute * 60 < seconds;
- if (step.hour)
- return step.hour * 3600 < seconds;
- if (step.day)
- return step.day * 3600 * 24 < seconds;
- // comparison is used in rough estimates, it doesn't need to be calendar-correct
- if (step.month)
- return step.month * 3600 * 24 * 30 < seconds;
- DBUG_ASSERT(step.year);
- return step.year * 86400 * 30 * 365 < seconds;
- }
- bool ge(size_t seconds) const
- {
- return !(this->lt(seconds));
- }
+ bool is_set() { return type < INTERVAL_LAST; }
} interval;
ulonglong limit;
- bool auto_inc;
partition_element *now_part;
partition_element *hist_part;
};
@@ -417,16 +394,14 @@ public:
bool vers_init_info(THD *thd);
bool vers_set_interval(THD *thd, Item *interval,
interval_type int_type, Item *starts,
- bool auto_inc, const char *table_name);
- bool vers_set_limit(ulonglong limit, bool auto_inc)
+ const char *table_name);
+ bool vers_set_limit(ulonglong limit)
{
DBUG_ASSERT(part_type == VERSIONING_PARTITION);
vers_info->limit= limit;
- vers_info->auto_inc= auto_inc;
return !limit;
}
void vers_set_hist_part(THD *thd);
- void vers_add_hist_part(THD *thd);
bool vers_fix_field_list(THD *thd);
void vers_update_el_ids();
partition_element *get_partition(uint part_id)
@@ -525,14 +500,4 @@ void partition_info::vers_update_el_ids()
}
}
-
-#define MAX_PART_NAME_SIZE 8
-
-inline
-bool make_partition_name(char *move_ptr, uint i)
-{
- int res= snprintf(move_ptr, MAX_PART_NAME_SIZE + 1, "p%u", i);
- return res < 0 || res > MAX_PART_NAME_SIZE;
-}
-
#endif /* PARTITION_INFO_INCLUDED */
diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index 01cf2745c41..78b6cfa63c8 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -7944,8 +7944,4 @@ ER_WARN_HISTORY_ROW_START_TIME
ER_PART_STARTS_BEYOND_INTERVAL
eng "%`s: STARTS is later than query time, first history partition may exceed INTERVAL value"
ER_GALERA_REPLICATION_NOT_SUPPORTED
- eng "DDL-statement is forbidden as table storage engine does not support Galera replication"
-ER_VERS_MODIFY_HISTORY
- eng "Modifying history is prohibited, set `secure_timestamp` to NO or SUPER"
-WARN_VERS_HIST_PART_ERROR
- eng "Versioned table %`s.%`s: adding HISTORY partition failed with error %u, see error log for details"
+ eng "DDL-statement is forbidden as table storage engine does not support Galera replication" \ No newline at end of file
diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
index f8ae91114f0..5885e3715bf 100644
--- a/sql/sql_partition.cc
+++ b/sql/sql_partition.cc
@@ -2584,15 +2584,11 @@ char *generate_partition_syntax(THD *thd, partition_info *part_info,
err+= str.append(ctime, ctime_len);
err+= str.append('\'');
}
- if (vers_info->auto_inc)
- err+= str.append(STRING_WITH_LEN(" AUTO_INCREMENT"));
}
- else if (vers_info->limit)
+ if (vers_info->limit)
{
err+= str.append(STRING_WITH_LEN("LIMIT "));
err+= str.append_ulonglong(vers_info->limit);
- if (vers_info->auto_inc)
- err+= str.append(STRING_WITH_LEN(" AUTO_INCREMENT"));
}
}
else if (part_info->part_expr)
@@ -5317,6 +5313,12 @@ that are reorganised.
now_part= el;
}
}
+ if (*fast_alter_table && tab_part_info->vers_info->interval.is_set())
+ {
+ partition_element *hist_part= tab_part_info->vers_info->hist_part;
+ if (hist_part->range_value <= thd->query_start())
+ hist_part->part_state= PART_CHANGED;
+ }
}
List_iterator<partition_element> alt_it(alt_part_info->partitions);
uint part_count= 0;
@@ -7216,8 +7218,7 @@ uint fast_alter_partition_table(THD *thd, TABLE *table,
}
else if ((alter_info->partition_flags & ALTER_PARTITION_ADD) &&
(part_info->part_type == RANGE_PARTITION ||
- part_info->part_type == LIST_PARTITION ||
- part_info->part_type == VERSIONING_PARTITION))
+ part_info->part_type == LIST_PARTITION))
{
/*
ADD RANGE/LIST PARTITIONS
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 692ed48ab8c..f24da3ed412 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1464,8 +1464,6 @@ End SQL_MODE_ORACLE_SPECIFIC */
condition_number
opt_versioning_interval_start
-%type <num> opt_vers_auto_inc
-
%type <item_param> param_marker
%type <item_num>
@@ -5308,24 +5306,24 @@ opt_part_option:
opt_versioning_rotation:
/* empty */ {}
- | INTERVAL_SYM expr interval opt_versioning_interval_start opt_vers_auto_inc
+ | INTERVAL_SYM expr interval opt_versioning_interval_start
{
partition_info *part_info= Lex->part_info;
const char *table_name= Lex->create_last_non_select_table->table_name.str;
- if (unlikely(part_info->vers_set_interval(thd, $2, $3, $4, $5, table_name)))
+ if (unlikely(part_info->vers_set_interval(thd, $2, $3, $4, table_name)))
MYSQL_YYABORT;
}
- | LIMIT ulonglong_num opt_vers_auto_inc
+ | LIMIT ulonglong_num
+ {
+ partition_info *part_info= Lex->part_info;
+ if (unlikely(part_info->vers_set_limit($2)))
{
- partition_info *part_info= Lex->part_info;
- if (unlikely(part_info->vers_set_limit($2, $3)))
- {
- my_error(ER_PART_WRONG_VALUE, MYF(0),
- Lex->create_last_non_select_table->table_name.str,
- "LIMIT");
- MYSQL_YYABORT;
- }
+ my_error(ER_PART_WRONG_VALUE, MYF(0),
+ Lex->create_last_non_select_table->table_name.str,
+ "LIMIT");
+ MYSQL_YYABORT;
}
+ }
;
@@ -5340,20 +5338,6 @@ opt_versioning_interval_start:
}
;
-opt_vers_auto_inc:
- /* empty */
- {
- $$= 0;
- }
- | AUTO_INC
- {
- $$= 1;
- }
- | AUTO_SYM
- {
- $$= 1;
- }
- ;
/*
End of partition parser part
*/
diff --git a/sql/table.h b/sql/table.h
index 50ac46fbe39..6ce92ee048e 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -800,9 +800,6 @@ struct TABLE_SHARE
uint partition_info_str_len;
uint partition_info_buffer_size;
plugin_ref default_part_plugin;
- bool vers_altering;
- time_t vers_hist_part_timeout;
- uint vers_hist_part_error;
#endif
/**