Commit 9de37e07 authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-19569 Assertion `table_list->table' failed in find_field_in_table_ref.

Disallow subqueries in The PARTITIN BY INTERVAL syntax.
Fix various interval types that now fail as they break syntax in the par
file.
parent 3a62ff7e
...@@ -1145,5 +1145,106 @@ insert into t values (1),(2); ...@@ -1145,5 +1145,106 @@ insert into t values (1),(2);
create trigger tr before insert on t for each row update tcount set c = c + 1; create trigger tr before insert on t for each row update tcount set c = c + 1;
insert into t select * from t; insert into t select * from t;
drop table tcount, t; drop table tcount, t;
#
# MDEV-19569 Assertion `table_list->table' failed in find_field_in_table_ref and Assertion `table_ref->table || table_ref->view' in Field_iterator_table_ref::set_field_iterator
#
create table t1 (i int);
create table t2 (i int);
alter table t1 partition by system_time
interval (select i from t2) day (partition p1 history, partition pn current);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'select i from t2) day (partition p1 history, partition pn current)' at line 2
drop table t1;
create table t1 (id int) with system versioning
partition by system_time
interval (select i from t2) day (partition p1 history, partition pn current);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'select i from t2) day (partition p1 history, partition pn current)' at line 3
create table t1 (id int) with system versioning
partition by system_time
interval "hello" day (partition p1 history, partition pn current);
ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'INTERVAL'
create table t1 (id int) with system versioning
partition by system_time
interval 3.893 day (partition p1 history, partition pn current);
drop table t1, t2;
create table t1 (id int) with system versioning
partition by system_time interval "3-11" year_month (partition p1 history, partition pn current);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL '3-11' YEAR_MONTH
(PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE,
PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE)
drop table t1;
create table t1 (id int) with system versioning
partition by system_time interval "3 11" day_hour (partition p1 history, partition pn current);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL '3 11' DAY_HOUR
(PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE,
PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE)
drop table t1;
create table t1 (id int) with system versioning
partition by system_time interval "3 11:12" day_minute (partition p1 history, partition pn current);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL '3 11:12' DAY_MINUTE
(PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE,
PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE)
drop table t1;
create table t1 (id int) with system versioning
partition by system_time interval "3 11:12:13" day_second (partition p1 history, partition pn current);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL '3 11:12:13' DAY_SECOND
(PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE,
PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE)
drop table t1;
create table t1 (id int) with system versioning
partition by system_time interval "11:12" hour_minute (partition p1 history, partition pn current);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL '11:12' HOUR_MINUTE
(PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE,
PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE)
drop table t1;
create table t1 (id int) with system versioning
partition by system_time interval "11:12:13" hour_second (partition p1 history, partition pn current);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL '11:12:13' HOUR_SECOND
(PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE,
PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE)
drop table t1;
create table t1 (id int) with system versioning
partition by system_time interval "12:13" minute_second (partition p1 history, partition pn current);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
PARTITION BY SYSTEM_TIME INTERVAL '12:13' MINUTE_SECOND
(PARTITION `p1` HISTORY ENGINE = DEFAULT_ENGINE,
PARTITION `pn` CURRENT ENGINE = DEFAULT_ENGINE)
drop table t1;
create table t1 (id int) with system versioning
partition by system_time interval "12:13.123" minute_microsecond (partition p1 history, partition pn current);
ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'INTERVAL'
# End of 10.3 tests # End of 10.3 tests
set global innodb_stats_persistent= @save_persistent; set global innodb_stats_persistent= @save_persistent;
...@@ -1098,6 +1098,80 @@ insert into t select * from t; ...@@ -1098,6 +1098,80 @@ insert into t select * from t;
# cleanup # cleanup
drop table tcount, t; drop table tcount, t;
--echo #
--echo # MDEV-19569 Assertion `table_list->table' failed in find_field_in_table_ref and Assertion `table_ref->table || table_ref->view' in Field_iterator_table_ref::set_field_iterator
--echo #
create table t1 (i int);
create table t2 (i int);
--error ER_PARSE_ERROR
alter table t1 partition by system_time
interval (select i from t2) day (partition p1 history, partition pn current);
drop table t1;
--error ER_PARSE_ERROR
create table t1 (id int) with system versioning
partition by system_time
interval (select i from t2) day (partition p1 history, partition pn current);
--error ER_PART_WRONG_VALUE
create table t1 (id int) with system versioning
partition by system_time
interval "hello" day (partition p1 history, partition pn current);
create table t1 (id int) with system versioning
partition by system_time
interval 3.893 day (partition p1 history, partition pn current);
drop table t1, t2;
create table t1 (id int) with system versioning
partition by system_time interval "3-11" year_month (partition p1 history, partition pn current);
--replace_result $default_engine DEFAULT_ENGINE
show create table t1;
drop table t1;
create table t1 (id int) with system versioning
partition by system_time interval "3 11" day_hour (partition p1 history, partition pn current);
--replace_result $default_engine DEFAULT_ENGINE
show create table t1;
drop table t1;
create table t1 (id int) with system versioning
partition by system_time interval "3 11:12" day_minute (partition p1 history, partition pn current);
--replace_result $default_engine DEFAULT_ENGINE
show create table t1;
drop table t1;
create table t1 (id int) with system versioning
partition by system_time interval "3 11:12:13" day_second (partition p1 history, partition pn current);
--replace_result $default_engine DEFAULT_ENGINE
show create table t1;
drop table t1;
create table t1 (id int) with system versioning
partition by system_time interval "11:12" hour_minute (partition p1 history, partition pn current);
--replace_result $default_engine DEFAULT_ENGINE
show create table t1;
drop table t1;
create table t1 (id int) with system versioning
partition by system_time interval "11:12:13" hour_second (partition p1 history, partition pn current);
--replace_result $default_engine DEFAULT_ENGINE
show create table t1;
drop table t1;
create table t1 (id int) with system versioning
partition by system_time interval "12:13" minute_second (partition p1 history, partition pn current);
--replace_result $default_engine DEFAULT_ENGINE
show create table t1;
drop table t1;
--error ER_PART_WRONG_VALUE
create table t1 (id int) with system versioning
partition by system_time interval "12:13.123" minute_microsecond (partition p1 history, partition pn current);
--echo # End of 10.3 tests --echo # End of 10.3 tests
set global innodb_stats_persistent= @save_persistent; set global innodb_stats_persistent= @save_persistent;
......
...@@ -93,34 +93,43 @@ int append_interval(String *str, interval_type int_type, const INTERVAL &interva ...@@ -93,34 +93,43 @@ int append_interval(String *str, interval_type int_type, const INTERVAL &interva
len= my_snprintf(buf,sizeof(buf),"%u", interval.second_part); len= my_snprintf(buf,sizeof(buf),"%u", interval.second_part);
break; break;
case INTERVAL_YEAR_MONTH: case INTERVAL_YEAR_MONTH:
len= my_snprintf(buf,sizeof(buf),"%u-%02u", interval.day, interval.month); len= my_snprintf(buf,sizeof(buf),"'%u-%02u'",
interval.year, interval.month);
break; break;
case INTERVAL_DAY_HOUR: case INTERVAL_DAY_HOUR:
len= my_snprintf(buf,sizeof(buf),"%u %u", interval.day, interval.hour); len= my_snprintf(buf,sizeof(buf),"'%u %u'", interval.day, interval.hour);
break; break;
case INTERVAL_DAY_MINUTE: case INTERVAL_DAY_MINUTE:
len= my_snprintf(buf,sizeof(buf),"%u %u:%02u", interval.day, interval.hour, interval.minute); len= my_snprintf(buf,sizeof(buf),"'%u %u:%02u'",
interval.day, interval.hour, interval.minute);
break; break;
case INTERVAL_DAY_SECOND: case INTERVAL_DAY_SECOND:
len= my_snprintf(buf,sizeof(buf),"%u %u:%02u:%02u", interval.day, interval.hour, interval.minute, interval.second); len= my_snprintf(buf,sizeof(buf),"'%u %u:%02u:%02u'",
interval.day, interval.hour, interval.minute, interval.second);
break; break;
case INTERVAL_HOUR_MINUTE: case INTERVAL_HOUR_MINUTE:
len= my_snprintf(buf,sizeof(buf),"%u:%02u", interval.hour, interval.minute); len= my_snprintf(buf,sizeof(buf),"'%u:%02u'", interval.hour, interval.minute);
break; break;
case INTERVAL_HOUR_SECOND: case INTERVAL_HOUR_SECOND:
len= my_snprintf(buf,sizeof(buf),"%u:%02u:%02u", interval.hour, interval.minute, interval.second); len= my_snprintf(buf,sizeof(buf),"'%u:%02u:%02u'",
interval.hour, interval.minute, interval.second);
break; break;
case INTERVAL_MINUTE_SECOND: case INTERVAL_MINUTE_SECOND:
len= my_snprintf(buf,sizeof(buf),"%u:%02u", interval.minute, interval.second); len= my_snprintf(buf,sizeof(buf),"'%u:%02u'", interval.minute, interval.second);
break; break;
case INTERVAL_DAY_MICROSECOND: case INTERVAL_DAY_MICROSECOND:
len= my_snprintf(buf,sizeof(buf),"%u %u:%02u:%02u.%06u", interval.day, interval.hour, interval.minute, interval.second, interval.second_part); len= my_snprintf(buf,sizeof(buf),"'%u %u:%02u:%02u.%06u'",
interval.day, interval.hour, interval.minute,
interval.second, interval.second_part);
break; break;
case INTERVAL_HOUR_MICROSECOND: case INTERVAL_HOUR_MICROSECOND:
len= my_snprintf(buf,sizeof(buf),"%u:%02u:%02u.%06u", interval.hour, interval.minute, interval.second, interval.second_part); len= my_snprintf(buf,sizeof(buf),"'%u:%02u:%02u.%06u'",
interval.hour, interval.minute, interval.second,
interval.second_part);
break; break;
case INTERVAL_MINUTE_MICROSECOND: case INTERVAL_MINUTE_MICROSECOND:
len= my_snprintf(buf,sizeof(buf),"%u:%02u.%06u", interval.minute, interval.second, interval.second_part); len= my_snprintf(buf,sizeof(buf),"'%u:%02u.%06u'",
interval.minute, interval.second, interval.second_part);
break; break;
case INTERVAL_SECOND_MICROSECOND: case INTERVAL_SECOND_MICROSECOND:
len= my_snprintf(buf,sizeof(buf),"%u.%06u", interval.second, interval.second_part); len= my_snprintf(buf,sizeof(buf),"%u.%06u", interval.second, interval.second_part);
......
...@@ -6094,10 +6094,11 @@ opt_part_option: ...@@ -6094,10 +6094,11 @@ opt_part_option:
opt_versioning_rotation: opt_versioning_rotation:
/* empty */ {} /* empty */ {}
| INTERVAL_SYM expr interval opt_versioning_interval_start | { Lex->expr_allows_subselect= false; }
INTERVAL_SYM expr interval opt_versioning_interval_start
{ {
partition_info *part_info= Lex->part_info; partition_info *part_info= Lex->part_info;
if (unlikely(part_info->vers_set_interval(thd, $2, $3, $4))) if (unlikely(part_info->vers_set_interval(thd, $3, $4, $5)))
MYSQL_YYABORT; MYSQL_YYABORT;
} }
| LIMIT ulonglong_num | LIMIT ulonglong_num
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment