Skip to content

Commit faec725

Browse files
committed
MDEV-37005 Unexpected ER_TABLE_EXISTS_ERROR on primary or replica upon CREATE OR REPLACE for partitioned table
cannot check thd->lex->part_info when a table is opened, it can describe anything, not necessarily the table in question
1 parent e05e6ab commit faec725

File tree

4 files changed

+50
-13
lines changed

4 files changed

+50
-13
lines changed

mysql-test/suite/versioning/r/trx_id.result

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,3 +595,24 @@ ERROR HY000: Lock wait timeout exceeded; try restarting transaction
595595
disconnect con1;
596596
connection default;
597597
drop table t1;
598+
# End of 10.4 tests
599+
#
600+
# MDEV-37005 Unexpected ER_TABLE_EXISTS_ERROR on primary or replica upon CREATE OR REPLACE for partitioned table
601+
#
602+
create table t1 (
603+
a int,
604+
row_start bigint unsigned generated always as row start,
605+
row_end bigint unsigned generated always as row end,
606+
period for system_time (row_start, row_end)
607+
) engine=innodb with system versioning
608+
partition by hash (a);
609+
create or replace table t1 (b int) engine=innodb with system versioning partition by system_time;
610+
show create table t1;
611+
Table Create Table
612+
t1 CREATE TABLE `t1` (
613+
`b` int(11) DEFAULT NULL
614+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci WITH SYSTEM VERSIONING
615+
PARTITION BY SYSTEM_TIME
616+
PARTITIONS 2
617+
drop table t1;
618+
# End of 11.8 tests

mysql-test/suite/versioning/t/trx_id.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,3 +643,21 @@ alter table xx;
643643
--disconnect con1
644644
--connection default
645645
drop table t1;
646+
647+
--echo # End of 10.4 tests
648+
649+
--echo #
650+
--echo # MDEV-37005 Unexpected ER_TABLE_EXISTS_ERROR on primary or replica upon CREATE OR REPLACE for partitioned table
651+
--echo #
652+
create table t1 (
653+
a int,
654+
row_start bigint unsigned generated always as row start,
655+
row_end bigint unsigned generated always as row end,
656+
period for system_time (row_start, row_end)
657+
) engine=innodb with system versioning
658+
partition by hash (a);
659+
create or replace table t1 (b int) engine=innodb with system versioning partition by system_time;
660+
show create table t1;
661+
drop table t1;
662+
663+
--echo # End of 11.8 tests

sql/ha_partition.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -494,18 +494,10 @@ class ha_partition final :public handler
494494

495495
bool vers_can_native(THD *thd) override
496496
{
497-
if (thd->lex->part_info)
498-
{
499-
// PARTITION BY SYSTEM_TIME is not supported for now
500-
return thd->lex->part_info->part_type != VERSIONING_PARTITION;
501-
}
502-
else
503-
{
504-
bool can= true;
505-
for (uint i= 0; i < m_tot_parts && can; i++)
506-
can= can && m_file[i]->vers_can_native(thd);
507-
return can;
508-
}
497+
bool can= true;
498+
for (uint i= 0; i < m_tot_parts && can; i++)
499+
can= can && m_file[i]->vers_can_native(thd);
500+
return can;
509501
}
510502

511503
/*

sql/partition_info.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,13 @@ bool partition_info::vers_fix_field_list(THD * thd)
487487
return true;
488488
}
489489
DBUG_ASSERT(part_type == VERSIONING_PARTITION);
490-
DBUG_ASSERT(table->versioned(VERS_TIMESTAMP));
490+
if (!table->versioned(VERS_TIMESTAMP))
491+
{
492+
my_error(ER_VERS_FIELD_WRONG_TYPE, MYF(0),
493+
table->vers_start_field()->field_name.str,
494+
"TIMESTAMP(6)", table->s->table_name.str);
495+
return true;
496+
}
491497

492498
Field *row_end= table->vers_end_field();
493499
// needed in handle_list_of_fields()

0 commit comments

Comments
 (0)