Skip to content

Commit 0a9023b

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 beef919 commit 0a9023b

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
@@ -958,3 +958,50 @@ SHOW CREATE TABLE t1;
958958
DROP TABLE t1, t2;
959959
drop function f;
960960

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

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)