Skip to content

Commit 5bc707e

Browse files
MDEV-40088 [to-squash] Disallow subqueries in INTERVAL clause in range interval auto partitioning
This is consistent with system time (versioning) partitioning. Also consistent is that both allow expressions otherwise.
1 parent 292dac4 commit 5bc707e

4 files changed

Lines changed: 103 additions & 1 deletion

File tree

mysql-test/main/partition_range_interval.result

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2473,3 +2473,50 @@ t1 CREATE TABLE `t1` (
24732473
PARTITION `p6` VALUES LESS THAN ('2026-04-26') ENGINE = InnoDB)
24742474
DROP TABLE t1, t2;
24752475
drop function f;
2476+
#
2477+
# MDEV-40088 Assertion `fixed()' failed with INTERVAL (SELECT 1) DAY
2478+
#
2479+
# Existing error should remain the same
2480+
create table t1 (c date) engine=innodb
2481+
PARTITION BY RANGE COLUMNS (c)
2482+
(
2483+
PARTITION p0 VALUES LESS THAN ((select '2026-04-20'))
2484+
);
2485+
ERROR HY000: This partition function is not allowed
2486+
create table t1 (c date) engine=innodb
2487+
PARTITION BY RANGE COLUMNS (c)
2488+
INTERVAL (SELECT 1) DAY
2489+
(
2490+
PARTITION p0 VALUES LESS THAN ('2026-04-20')
2491+
);
2492+
ERROR 42000: INTERVAL does not support subqueries or stored functions
2493+
create table t1 (c date) engine=innodb
2494+
PARTITION BY RANGE COLUMNS (c)
2495+
INTERVAL (1 + 2 + 3) DAY
2496+
(
2497+
PARTITION p0 VALUES LESS THAN ('2026-04-20')
2498+
);
2499+
show create table t1;
2500+
Table Create Table
2501+
t1 CREATE TABLE `t1` (
2502+
`c` date DEFAULT NULL
2503+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
2504+
PARTITION BY RANGE COLUMNS(`c`) INTERVAL 6 DAY
2505+
(PARTITION `p0` VALUES LESS THAN ('2026-04-20') ENGINE = InnoDB)
2506+
drop table t1;
2507+
# Existing error should remain the same, even if subquries are
2508+
# banned for INTERVAL
2509+
create table t1 (c date) engine=innodb
2510+
PARTITION BY RANGE COLUMNS (c)
2511+
INTERVAL 1 DAY
2512+
(
2513+
PARTITION p0 VALUES LESS THAN ((select '2026-04-20'))
2514+
);
2515+
ERROR HY000: This partition function is not allowed
2516+
create table t1 (c date) engine=innodb
2517+
PARTITION BY RANGE COLUMNS (c)
2518+
INTERVAL "hello" DAY
2519+
(
2520+
PARTITION p0 VALUES LESS THAN ('2026-04-20')
2521+
);
2522+
ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'INTERVAL'

mysql-test/main/partition_range_interval.test

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,3 +960,50 @@ SHOW CREATE TABLE t1;
960960
DROP TABLE t1, t2;
961961
drop function f;
962962

963+
--echo #
964+
--echo # MDEV-40088 Assertion `fixed()' failed with INTERVAL (SELECT 1) DAY
965+
--echo #
966+
967+
--echo # Existing error should remain the same
968+
--error ER_PARTITION_FUNCTION_IS_NOT_ALLOWED
969+
create table t1 (c date) engine=innodb
970+
PARTITION BY RANGE COLUMNS (c)
971+
(
972+
PARTITION p0 VALUES LESS THAN ((select '2026-04-20'))
973+
);
974+
975+
--error ER_SUBQUERIES_NOT_SUPPORTED
976+
create table t1 (c date) engine=innodb
977+
PARTITION BY RANGE COLUMNS (c)
978+
INTERVAL (SELECT 1) DAY
979+
(
980+
PARTITION p0 VALUES LESS THAN ('2026-04-20')
981+
);
982+
983+
create table t1 (c date) engine=innodb
984+
PARTITION BY RANGE COLUMNS (c)
985+
INTERVAL (1 + 2 + 3) DAY
986+
(
987+
PARTITION p0 VALUES LESS THAN ('2026-04-20')
988+
);
989+
990+
show create table t1;
991+
drop table t1;
992+
993+
--echo # Existing error should remain the same, even if subquries are
994+
--echo # banned for INTERVAL
995+
--error ER_PARTITION_FUNCTION_IS_NOT_ALLOWED
996+
create table t1 (c date) engine=innodb
997+
PARTITION BY RANGE COLUMNS (c)
998+
INTERVAL 1 DAY
999+
(
1000+
PARTITION p0 VALUES LESS THAN ((select '2026-04-20'))
1001+
);
1002+
1003+
--error ER_PART_WRONG_VALUE
1004+
create table t1 (c date) engine=innodb
1005+
PARTITION BY RANGE COLUMNS (c)
1006+
INTERVAL "hello" DAY
1007+
(
1008+
PARTITION p0 VALUES LESS THAN ('2026-04-20')
1009+
);

sql/sql_partition_auto_interval.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ bool partition_info::set_range_interval(THD* thd, Item* ival,
391391
interval_type type,
392392
const char *table_name)
393393
{
394+
if (ival->fix_fields_if_needed_for_scalar(thd, &ival))
395+
return true;
394396
bool error= get_interval_value(thd, ival, type, &interval) ||
395397
interval.neg || interval.second_part ||
396398
!(interval.year || interval.month || interval.day || interval.hour ||

sql/sql_yacc.yy

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5199,7 +5199,13 @@ part_column_list:
51995199

52005200
opt_part_interval:
52015201
/* empty */ {}
5202-
| INTERVAL_SYM expr interval opt_auto
5202+
| { Lex->clause_that_disallows_subselect= "INTERVAL"; }
5203+
opt_part_interval2
5204+
{ Lex->clause_that_disallows_subselect= NULL; }
5205+
;
5206+
5207+
opt_part_interval2:
5208+
INTERVAL_SYM expr interval opt_auto
52035209
{
52045210
partition_info *part_info= Lex->part_info;
52055211
const char *table_name=

0 commit comments

Comments
 (0)