Skip to content

Commit f7137a6

Browse files
authored
MDEV-28599 EXCHANGE PARTITION on view causes ER_CHECK_NO_SUCH_TABLE instead of ER_WRONG_OBJECT
ER_CHECK_NO_SUCH_TABLE was raised because a view does not have the corresponding TABLE instance connected to TABLE_LIST and the server interprets the absence as the absence of the table itself. To fix the problem, we add a check to ensure that the target table to be swapped with a partition is not a view. Reviewed by: Nayuta Yanagisawa
1 parent c4e87cb commit f7137a6

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

mysql-test/main/partition_error.result

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,18 @@ drop table if exists t1, t2;
66
CREATE TABLE t1 (a int);
77
CREATE OR REPLACE VIEW v1 AS SELECT * FROM t1;
88
ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE v1;
9-
ERROR 42000: Can't open table
9+
ERROR HY000: 'test.v1' is not of type 'BASE TABLE'
10+
DROP VIEW v1;
11+
DROP TABLE t1;
12+
#
13+
# MDEV-28599 EXCHANGE PARTITION on view causes ER_CHECK_NO_SUCH_TABLE instead of ER_WRONG_OBJECT
14+
#
15+
CREATE TABLE t1 (a int)
16+
PARTITION BY HASH (a)
17+
PARTITIONS 2;
18+
CREATE OR REPLACE VIEW v1 AS SELECT * FROM t1;
19+
ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE v1;
20+
ERROR HY000: 'test.v1' is not of type 'BASE TABLE'
1021
DROP VIEW v1;
1122
DROP TABLE t1;
1223
#

mysql-test/main/partition_error.test

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,19 @@ let $MYSQLD_DATADIR= `SELECT @@datadir`;
1616
--echo #
1717
CREATE TABLE t1 (a int);
1818
CREATE OR REPLACE VIEW v1 AS SELECT * FROM t1;
19-
--error ER_CHECK_NO_SUCH_TABLE
19+
--error ER_WRONG_OBJECT
20+
ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE v1;
21+
DROP VIEW v1;
22+
DROP TABLE t1;
23+
24+
--echo #
25+
--echo # MDEV-28599 EXCHANGE PARTITION on view causes ER_CHECK_NO_SUCH_TABLE instead of ER_WRONG_OBJECT
26+
--echo #
27+
CREATE TABLE t1 (a int)
28+
PARTITION BY HASH (a)
29+
PARTITIONS 2;
30+
CREATE OR REPLACE VIEW v1 AS SELECT * FROM t1;
31+
--error ER_WRONG_OBJECT
2032
ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE v1;
2133
DROP VIEW v1;
2234
DROP TABLE t1;

sql/sql_partition_admin.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,14 @@ bool Sql_cmd_alter_table_exchange_partition::
539539
part_table= table_list->table;
540540
swap_table= swap_table_list->table;
541541

542+
/* Don't allow to exchange with a VIEW */
543+
if (unlikely(swap_table_list->view))
544+
{
545+
my_error(ER_WRONG_OBJECT, MYF(0), table_list->db.str,
546+
swap_table_list->table_name.str, "BASE TABLE");
547+
DBUG_RETURN(TRUE);
548+
}
549+
542550
if (unlikely(check_exchange_partition(swap_table, part_table)))
543551
DBUG_RETURN(TRUE);
544552

0 commit comments

Comments
 (0)