Skip to content

Commit 067cfbe

Browse files
MDEV-40388: sequence.simple fails on replay
The problem is that, when recording is enabled for the query such as, explain select * from seq_1_to_10; it recorded the table context having a DDL definition as: - CREATE TABLE `seq_1_to_10` ( -> `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 a table, and instead it errors out saying ERROR 1050 (42S01): Table 'seq_1_to_10' already exists. Solution is to use: - CREATE TABLE IF NOT EXISTS seq_1_to_10 ...; ===== Also, there is a different way to use sequences as: - Create sequence s1; Explain select * from s1; Here, we should be recording the DDL statement, but no need to store the stats for it. However, we didn't record the DDL statement earlier. Moreover, sequence's next value should be the same in the replay environment. Solution here is to record the DDL for such a sequence as CREATE TABLE IF NOT EXISTS s1 ...; and also set its start value as the recorded environment's previous value using SELECT SETVAL(s1, prev_value);
1 parent 97e8c62 commit 067cfbe

9 files changed

Lines changed: 227 additions & 198 deletions

mysql-test/main/opt_context_replay_basic.result

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@ Warnings:
118118
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
119119
Warnings:
120120
Note 1007 Can't create database 'db1'; database exists
121-
Warnings:
122-
Note 4092 Unknown VIEW: 'db1.t1'
123-
Warnings:
124-
Note 1051 Unknown table 'db1.t1'
125121
count(*)
126122
20
127123
set optimizer_replay_context='opt_context';
@@ -549,4 +545,28 @@ select context like '%bar%' from information_schema.optimizer_context;
549545
context like '%bar%'
550546
1
551547
drop table t1;
548+
#
549+
# MDEV-40388: sequence.simple fails on replay
550+
#
551+
set optimizer_record_context=0;
552+
create sequence s1;
553+
select setval(s1, 10);
554+
setval(s1, 10)
555+
10
556+
set optimizer_record_context=1;
557+
select nextval(s1) as nv;
558+
nv
559+
11
560+
select context into dumpfile "../../tmp/dump1.sql"
561+
from information_schema.optimizer_context;
562+
set optimizer_record_context=0;
563+
drop table s1;
564+
set optimizer_replay_context='opt_context';
565+
# Get the last recorded value from the sequence; must have same output as above
566+
select lastval(s1) as nv;
567+
nv
568+
11
569+
set optimizer_replay_context='';
570+
drop table s1;
571+
# End of 13.1 tests
552572
drop database db1;

mysql-test/main/opt_context_replay_basic.test

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--source include/not_embedded.inc
22
--source include/have_sequence.inc
3-
--source include/no_view_protocol.inc
3+
--source include/no_protocol.inc
44
--echo #enable optimizer_record_context
55
set optimizer_trace=0;
66
set optimizer_record_context=ON;
@@ -351,4 +351,31 @@ explain select * from t1 where a >'foo' or a < 'bar';
351351
select context like '%bar%' from information_schema.optimizer_context;
352352

353353
drop table t1;
354+
355+
--echo #
356+
--echo # MDEV-40388: sequence.simple fails on replay
357+
--echo #
358+
set optimizer_record_context=0;
359+
create sequence s1;
360+
select setval(s1, 10);
361+
set optimizer_record_context=1;
362+
select nextval(s1) as nv;
363+
select context into dumpfile "../../tmp/dump1.sql"
364+
from information_schema.optimizer_context;
365+
set optimizer_record_context=0;
366+
drop table s1;
367+
--disable_query_log
368+
--disable_result_log
369+
--source "$MYSQLTEST_VARDIR/tmp/dump1.sql"
370+
--enable_query_log
371+
--enable_result_log
372+
set optimizer_replay_context='opt_context';
373+
--echo # Get the last recorded value from the sequence; must have same output as above
374+
select lastval(s1) as nv;
375+
376+
set optimizer_replay_context='';
377+
--remove_file "$MYSQLTEST_VARDIR/tmp/dump1.sql"
378+
drop table s1;
379+
--echo # End of 13.1 tests
380+
354381
drop database db1;

mysql-test/main/opt_context_replay_innodb_comp.result

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,6 @@ Warnings:
197197
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
198198
Warnings:
199199
Note 1007 Can't create database 'db1'; database exists
200-
Warnings:
201-
Note 4092 Unknown VIEW: 'db1.t1'
202-
Warnings:
203-
Note 1051 Unknown table 'db1.t1'
204200
EXPLAIN
205201
{
206202
"query_block": {
@@ -323,10 +319,6 @@ Warnings:
323319
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
324320
Warnings:
325321
Note 1007 Can't create database 'db1'; database exists
326-
Warnings:
327-
Note 4092 Unknown VIEW: 'db1.t1'
328-
Warnings:
329-
Note 1051 Unknown table 'db1.t1'
330322
EXPLAIN
331323
{
332324
"query_block": {
@@ -444,10 +436,6 @@ Warnings:
444436
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
445437
Warnings:
446438
Note 1007 Can't create database 'db1'; database exists
447-
Warnings:
448-
Note 4092 Unknown VIEW: 'db1.t1'
449-
Warnings:
450-
Note 1051 Unknown table 'db1.t1'
451439
EXPLAIN
452440
{
453441
"query_block": {
@@ -569,10 +557,6 @@ Warnings:
569557
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
570558
Warnings:
571559
Note 1007 Can't create database 'db1'; database exists
572-
Warnings:
573-
Note 4092 Unknown VIEW: 'db1.t1'
574-
Warnings:
575-
Note 1051 Unknown table 'db1.t1'
576560
EXPLAIN
577561
{
578562
"query_block": {
@@ -698,10 +682,6 @@ Warnings:
698682
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
699683
Warnings:
700684
Note 1007 Can't create database 'db1'; database exists
701-
Warnings:
702-
Note 4092 Unknown VIEW: 'db1.t1'
703-
Warnings:
704-
Note 1051 Unknown table 'db1.t1'
705685
EXPLAIN
706686
{
707687
"query_block": {
@@ -823,10 +803,6 @@ Warnings:
823803
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
824804
Warnings:
825805
Note 1007 Can't create database 'db1'; database exists
826-
Warnings:
827-
Note 4092 Unknown VIEW: 'db1.t1'
828-
Warnings:
829-
Note 1051 Unknown table 'db1.t1'
830806
EXPLAIN
831807
{
832808
"query_block": {
@@ -933,10 +909,6 @@ Warnings:
933909
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
934910
Warnings:
935911
Note 1007 Can't create database 'db1'; database exists
936-
Warnings:
937-
Note 4092 Unknown VIEW: 'db1.t1'
938-
Warnings:
939-
Note 1051 Unknown table 'db1.t1'
940912
EXPLAIN
941913
{
942914
"query_block": {
@@ -1033,10 +1005,6 @@ Warnings:
10331005
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
10341006
Warnings:
10351007
Note 1007 Can't create database 'db1'; database exists
1036-
Warnings:
1037-
Note 4092 Unknown VIEW: 'db1.t1'
1038-
Warnings:
1039-
Note 1051 Unknown table 'db1.t1'
10401008
EXPLAIN
10411009
{
10421010
"query_block": {
@@ -1115,10 +1083,6 @@ Warnings:
11151083
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
11161084
Warnings:
11171085
Note 1007 Can't create database 'db1'; database exists
1118-
Warnings:
1119-
Note 4092 Unknown VIEW: 'db1.t1'
1120-
Warnings:
1121-
Note 1051 Unknown table 'db1.t1'
11221086
EXPLAIN
11231087
{
11241088
"query_block": {
@@ -1206,10 +1170,6 @@ Warnings:
12061170
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
12071171
Warnings:
12081172
Note 1007 Can't create database 'db1'; database exists
1209-
Warnings:
1210-
Note 4092 Unknown VIEW: 'db1.t1'
1211-
Warnings:
1212-
Note 1051 Unknown table 'db1.t1'
12131173
EXPLAIN
12141174
{
12151175
"query_block": {
@@ -1295,10 +1255,6 @@ Warnings:
12951255
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
12961256
Warnings:
12971257
Note 1007 Can't create database 'db1'; database exists
1298-
Warnings:
1299-
Note 4092 Unknown VIEW: 'db1.t1'
1300-
Warnings:
1301-
Note 1051 Unknown table 'db1.t1'
13021258
EXPLAIN
13031259
{
13041260
"query_block": {
@@ -1383,10 +1339,6 @@ Warnings:
13831339
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
13841340
Warnings:
13851341
Note 1007 Can't create database 'db1'; database exists
1386-
Warnings:
1387-
Note 4092 Unknown VIEW: 'db1.t1'
1388-
Warnings:
1389-
Note 1051 Unknown table 'db1.t1'
13901342
EXPLAIN
13911343
{
13921344
"query_block": {
@@ -1496,10 +1448,6 @@ Warnings:
14961448
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
14971449
Warnings:
14981450
Note 1007 Can't create database 'db1'; database exists
1499-
Warnings:
1500-
Note 4092 Unknown VIEW: 'db1.t1'
1501-
Warnings:
1502-
Note 1051 Unknown table 'db1.t1'
15031451
EXPLAIN
15041452
{
15051453
"query_block": {
@@ -1634,10 +1582,6 @@ Warnings:
16341582
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
16351583
Warnings:
16361584
Note 1007 Can't create database 'db1'; database exists
1637-
Warnings:
1638-
Note 4092 Unknown VIEW: 'db1.t1'
1639-
Warnings:
1640-
Note 1051 Unknown table 'db1.t1'
16411585
EXPLAIN
16421586
{
16431587
"query_block": {

mysql-test/main/opt_context_replay_innodb_pref.result

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,6 @@ Warnings:
197197
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
198198
Warnings:
199199
Note 1007 Can't create database 'db1'; database exists
200-
Warnings:
201-
Note 4092 Unknown VIEW: 'db1.t1'
202-
Warnings:
203-
Note 1051 Unknown table 'db1.t1'
204200
EXPLAIN
205201
{
206202
"query_block": {
@@ -323,10 +319,6 @@ Warnings:
323319
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
324320
Warnings:
325321
Note 1007 Can't create database 'db1'; database exists
326-
Warnings:
327-
Note 4092 Unknown VIEW: 'db1.t1'
328-
Warnings:
329-
Note 1051 Unknown table 'db1.t1'
330322
EXPLAIN
331323
{
332324
"query_block": {
@@ -444,10 +436,6 @@ Warnings:
444436
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
445437
Warnings:
446438
Note 1007 Can't create database 'db1'; database exists
447-
Warnings:
448-
Note 4092 Unknown VIEW: 'db1.t1'
449-
Warnings:
450-
Note 1051 Unknown table 'db1.t1'
451439
EXPLAIN
452440
{
453441
"query_block": {
@@ -569,10 +557,6 @@ Warnings:
569557
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
570558
Warnings:
571559
Note 1007 Can't create database 'db1'; database exists
572-
Warnings:
573-
Note 4092 Unknown VIEW: 'db1.t1'
574-
Warnings:
575-
Note 1051 Unknown table 'db1.t1'
576560
EXPLAIN
577561
{
578562
"query_block": {
@@ -698,10 +682,6 @@ Warnings:
698682
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
699683
Warnings:
700684
Note 1007 Can't create database 'db1'; database exists
701-
Warnings:
702-
Note 4092 Unknown VIEW: 'db1.t1'
703-
Warnings:
704-
Note 1051 Unknown table 'db1.t1'
705685
EXPLAIN
706686
{
707687
"query_block": {
@@ -823,10 +803,6 @@ Warnings:
823803
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
824804
Warnings:
825805
Note 1007 Can't create database 'db1'; database exists
826-
Warnings:
827-
Note 4092 Unknown VIEW: 'db1.t1'
828-
Warnings:
829-
Note 1051 Unknown table 'db1.t1'
830806
EXPLAIN
831807
{
832808
"query_block": {
@@ -933,10 +909,6 @@ Warnings:
933909
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
934910
Warnings:
935911
Note 1007 Can't create database 'db1'; database exists
936-
Warnings:
937-
Note 4092 Unknown VIEW: 'db1.t1'
938-
Warnings:
939-
Note 1051 Unknown table 'db1.t1'
940912
EXPLAIN
941913
{
942914
"query_block": {
@@ -1033,10 +1005,6 @@ Warnings:
10331005
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
10341006
Warnings:
10351007
Note 1007 Can't create database 'db1'; database exists
1036-
Warnings:
1037-
Note 4092 Unknown VIEW: 'db1.t1'
1038-
Warnings:
1039-
Note 1051 Unknown table 'db1.t1'
10401008
EXPLAIN
10411009
{
10421010
"query_block": {
@@ -1115,10 +1083,6 @@ Warnings:
11151083
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
11161084
Warnings:
11171085
Note 1007 Can't create database 'db1'; database exists
1118-
Warnings:
1119-
Note 4092 Unknown VIEW: 'db1.t1'
1120-
Warnings:
1121-
Note 1051 Unknown table 'db1.t1'
11221086
EXPLAIN
11231087
{
11241088
"query_block": {
@@ -1206,10 +1170,6 @@ Warnings:
12061170
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
12071171
Warnings:
12081172
Note 1007 Can't create database 'db1'; database exists
1209-
Warnings:
1210-
Note 4092 Unknown VIEW: 'db1.t1'
1211-
Warnings:
1212-
Note 1051 Unknown table 'db1.t1'
12131173
EXPLAIN
12141174
{
12151175
"query_block": {
@@ -1295,10 +1255,6 @@ Warnings:
12951255
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
12961256
Warnings:
12971257
Note 1007 Can't create database 'db1'; database exists
1298-
Warnings:
1299-
Note 4092 Unknown VIEW: 'db1.t1'
1300-
Warnings:
1301-
Note 1051 Unknown table 'db1.t1'
13021258
EXPLAIN
13031259
{
13041260
"query_block": {
@@ -1383,10 +1339,6 @@ Warnings:
13831339
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
13841340
Warnings:
13851341
Note 1007 Can't create database 'db1'; database exists
1386-
Warnings:
1387-
Note 4092 Unknown VIEW: 'db1.t1'
1388-
Warnings:
1389-
Note 1051 Unknown table 'db1.t1'
13901342
EXPLAIN
13911343
{
13921344
"query_block": {
@@ -1496,10 +1448,6 @@ Warnings:
14961448
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
14971449
Warnings:
14981450
Note 1007 Can't create database 'db1'; database exists
1499-
Warnings:
1500-
Note 4092 Unknown VIEW: 'db1.t1'
1501-
Warnings:
1502-
Note 1051 Unknown table 'db1.t1'
15031451
EXPLAIN
15041452
{
15051453
"query_block": {
@@ -1634,10 +1582,6 @@ Warnings:
16341582
Warning 4200 The setting 'optimizer_adjust_secondary_key_costs' is ignored. It only exists for compatibility with old installations and will be removed in a future release
16351583
Warnings:
16361584
Note 1007 Can't create database 'db1'; database exists
1637-
Warnings:
1638-
Note 4092 Unknown VIEW: 'db1.t1'
1639-
Warnings:
1640-
Note 1051 Unknown table 'db1.t1'
16411585
EXPLAIN
16421586
{
16431587
"query_block": {

0 commit comments

Comments
 (0)