Skip to content

Commit 53e01d6

Browse files
MDEV-40388: sequence.simple fails on replay
When the recording is enabled for the query, explain select * from seq_15_to_1_step_12345; it recorded the table context having a DDL definition as: - CREATE TABLE `seq_15_to_1_step_12345` ( -> `seq` bigint(20) unsigned NOT NULL, -> PRIMARY KEY (`seq`) -> ) ENGINE=SEQUENCE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; Now, when that context is replayed, the DDL statement is executed. But, we cannot create such the table and instead it errors out saying ERROR 1050 (42S01): Table 'seq_15_to_1_step_12345' already exists. The problem is that, sequence table was determined using tbl->table->s->sequence. The intention was to not record sequence table information. However, the check was only partially correct. Instead, we need an enhanced condition like: - if (!tbl->is_view() && tbl->table) { if (tbl->table->s->sequence || lex_string_eq(hton_name(tbl->table->s->db_type()), STRING_WITH_LEN("SEQUENCE"))) { continue; } } This makes both the following kinds of queries on sequences, to not record any table contexts on them: - 1. explain select * from seq_15_to_1_step_12345; 2. create sequence s1; EXPLAIN select * from s1;
1 parent feb3817 commit 53e01d6

3 files changed

Lines changed: 40 additions & 2 deletions

File tree

mysql-test/main/opt_context_store_stats.result

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,3 +591,21 @@ table_name file_stat_records index_name rec_per_key
591591
index_name ranges num_rows max_index_blocks max_row_blocks
592592
# == End of optimizer context
593593
drop table s1;
594+
#
595+
# MDEV-40388: sequence.simple fails on replay
596+
# Table context should *not* be recorded for seq
597+
#
598+
set optimizer_record_context=ON;
599+
explain select * from seq_15_to_1_step_12345;
600+
id select_type table type possible_keys key key_len ref rows Extra
601+
1 SIMPLE seq_15_to_1_step_12345 ALL NULL NULL NULL NULL 1
602+
# == Optimizer Context
603+
# === Tables
604+
# Tables in the context
605+
table_name file_stat_records index_name rec_per_key
606+
# === Range accesses
607+
index_name ranges num_rows max_index_blocks max_row_blocks
608+
# == End of optimizer context
609+
#
610+
# End of 13.1 tests
611+
#

mysql-test/main/opt_context_store_stats.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,3 +432,16 @@ EXPLAIN select * from s1;
432432

433433
--source include/opt_context_list_tables_and_ranges.inc
434434
drop table s1;
435+
436+
--echo #
437+
--echo # MDEV-40388: sequence.simple fails on replay
438+
--echo # Table context should *not* be recorded for seq
439+
--echo #
440+
set optimizer_record_context=ON;
441+
explain select * from seq_15_to_1_step_12345;
442+
443+
--source include/opt_context_list_tables_and_ranges.inc
444+
445+
--echo #
446+
--echo # End of 13.1 tests
447+
--echo #

sql/opt_context_store_replay.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,8 +746,15 @@ bool Optimizer_context_recorder::dump_sql_script(THD* thd, String &sql_script)
746746
/*
747747
Sequence table doesn't need CREATE TABLE or contain any stats
748748
*/
749-
if (tbl->table && tbl->table->s && tbl->table->s->sequence)
750-
continue;
749+
if (!tbl->is_view() && tbl->table)
750+
{
751+
if (tbl->table->s->sequence ||
752+
lex_string_eq(hton_name(tbl->table->s->db_type()),
753+
STRING_WITH_LEN("SEQUENCE")))
754+
{
755+
continue;
756+
}
757+
}
751758

752759
/*
753760
A query can use the same table multiple times. Do not dump the

0 commit comments

Comments
 (0)