Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions mysql-test/main/opt_context_store_ddls.result
Original file line number Diff line number Diff line change
Expand Up @@ -542,4 +542,39 @@ CREATE TABLE `t1` (


drop table t1, t2;
#
# MDEV-40388: sequence.simple fails on replay
#
create sequence s1;
# context result should have the ddl
explain select * from s1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE s1 system NULL NULL NULL NULL 1
# == Optimizer Context Tables
name
# === Optimizer Context DDLs
@ddls
CREATE TABLE `s1` (
`next_not_cached_value` bigint(21) NOT NULL,
`minimum_value` bigint(21) NOT NULL,
`maximum_value` bigint(21) NOT NULL,
`start_value` bigint(21) NOT NULL COMMENT 'start value when sequences is created or value if RESTART is used',
`increment` bigint(21) NOT NULL COMMENT 'increment value',
`cache_size` bigint(21) unsigned NOT NULL,
`cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed',
`cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done'
) ENGINE=MyISAM SEQUENCE=1;


drop table s1;
# no ddl should be captured here
explain select * from seq_1_to_10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE seq_1_to_10 index NULL PRIMARY 8 NULL 10 Using index
# == Optimizer Context Tables
name
# === Optimizer Context DDLs
@ddls

# End of 13.1 tests
drop database db1;
15 changes: 15 additions & 0 deletions mysql-test/main/opt_context_store_ddls.test
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,19 @@ delete t1.*, t2.* from t1, t2 where t1.id1 = t2.id2;

drop table t1, t2;

--echo #
--echo # MDEV-40388: sequence.simple fails on replay
--echo #
create sequence s1;
--echo # context result should have the ddl
explain select * from s1;
--source include/opt_context_list_tables_ddls.inc
drop table s1;

--echo # no ddl should be captured here
explain select * from seq_1_to_10;
--source include/opt_context_list_tables_ddls.inc

--echo # End of 13.1 tests

drop database db1;
16 changes: 16 additions & 0 deletions mysql-test/main/opt_context_store_stats.result
Original file line number Diff line number Diff line change
Expand Up @@ -591,3 +591,19 @@ table_name file_stat_records index_name rec_per_key
index_name ranges num_rows max_index_blocks max_row_blocks
# == End of optimizer context
drop table s1;
#
# MDEV-40388: sequence.simple fails on replay
# Table context should *not* be recorded for seq
#
set optimizer_record_context=ON;
explain select * from seq_1_to_10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE seq_1_to_10 index NULL PRIMARY 8 NULL 10 Using index
# == Optimizer Context
# === Tables
# Tables in the context
table_name file_stat_records index_name rec_per_key
# === Range accesses
index_name ranges num_rows max_index_blocks max_row_blocks
# == End of optimizer context
# End of 13.1 tests
11 changes: 11 additions & 0 deletions mysql-test/main/opt_context_store_stats.test
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,14 @@ EXPLAIN select * from s1;

--source include/opt_context_list_tables_and_ranges.inc
drop table s1;

--echo #
--echo # MDEV-40388: sequence.simple fails on replay
--echo # Table context should *not* be recorded for seq
--echo #
set optimizer_record_context=ON;
explain select * from seq_1_to_10;

--source include/opt_context_list_tables_and_ranges.inc
Comment thread
bsrikanth-mariadb marked this conversation as resolved.

--echo # End of 13.1 tests
15 changes: 11 additions & 4 deletions sql/opt_context_store_replay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -756,10 +756,14 @@ bool Optimizer_context_recorder::dump_sql_script(THD* thd, String &sql_script)
append_table_or_view_name(tbl, &full_tbl_name);

/*
Sequence table doesn't need CREATE TABLE or contain any stats
Sequence table such as seq_1_to_10 is a virtual table and so
doesn't need CREATE TABLE STATEMENT, and stats.
*/
if (tbl->table && tbl->table->s && tbl->table->s->sequence)
if (!tbl->is_view() && tbl->table &&
tbl->table->s->db_type()->discover_table)
{
continue;
}

/*
A query can use the same table multiple times. Do not dump the
Expand Down Expand Up @@ -809,8 +813,11 @@ bool Optimizer_context_recorder::dump_sql_script(THD* thd, String &sql_script)
qry_ctx_script.append(ddl);
qry_ctx_script.append(STRING_WITH_LEN(";\n\n"));

/* If this is a VIEW, we've stored its DDL and we're done. */
if (tbl->is_view())
/* If this is a VIEW or a SEQUENCE table as
CREATE SEQUENCE s1;
explain SELECT * FROM s1;
we've stored its DDL and we're done. */
if (tbl->is_view() || (tbl->table && tbl->table->s->sequence))
continue;

/* No, it's a base table */
Expand Down
Loading