Skip to content

Commit cf77951

Browse files
committed
Merge 10.3 into 10.4
2 parents 1921df6 + 592dc59 commit cf77951

File tree

18 files changed

+299
-73
lines changed

18 files changed

+299
-73
lines changed

mysql-test/main/order_by.result

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3343,6 +3343,63 @@ C
33433343
B
33443344
DROP TABLE t1;
33453345
#
3346+
# MDEV-16214: Incorrect plan taken by the optimizer , uses INDEX instead of ref access with ORDER BY
3347+
#
3348+
create table t1(a int);
3349+
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
3350+
create table t2(
3351+
id int primary key,
3352+
key1 int,key2 int,
3353+
col1 int,
3354+
key(key1), key(key2)
3355+
);
3356+
insert into t2
3357+
select
3358+
A.a + B.a*10 + C.a*100,
3359+
A.a + 10*B.a, A.a + 10*B.a,
3360+
123456
3361+
from t1 A, t1 B, t1 C;
3362+
# here type should show ref not index
3363+
explain select
3364+
(SELECT concat(id, '-', key1, '-', col1)
3365+
FROM t2
3366+
WHERE
3367+
t2.key1 = t1.a and t2.key1 IS NOT NULL
3368+
ORDER BY
3369+
t2.key2 ASC
3370+
LIMIT 1)
3371+
from t1;
3372+
id select_type table type possible_keys key key_len ref rows Extra
3373+
1 PRIMARY t1 ALL NULL NULL NULL NULL 10
3374+
2 DEPENDENT SUBQUERY t2 ref key1 key1 5 test.t1.a 10 Using index condition; Using where; Using filesort
3375+
select
3376+
(SELECT concat(id, '-', key1, '-', col1)
3377+
FROM t2
3378+
WHERE
3379+
t2.key1 = t1.a and t2.key1 IS NOT NULL
3380+
ORDER BY
3381+
t2.key2 ASC
3382+
LIMIT 1)
3383+
from t1;
3384+
(SELECT concat(id, '-', key1, '-', col1)
3385+
FROM t2
3386+
WHERE
3387+
t2.key1 = t1.a and t2.key1 IS NOT NULL
3388+
ORDER BY
3389+
t2.key2 ASC
3390+
LIMIT 1)
3391+
900-0-123456
3392+
901-1-123456
3393+
902-2-123456
3394+
903-3-123456
3395+
904-4-123456
3396+
905-5-123456
3397+
906-6-123456
3398+
907-7-123456
3399+
908-8-123456
3400+
909-9-123456
3401+
drop table t1,t2;
3402+
#
33463403
# MDEV-17761: Odd optimizer choice with ORDER BY LIMIT and condition selectivity
33473404
#
33483405
create table t1(a int);

mysql-test/main/order_by.test

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,6 +2204,43 @@ ORDER BY id+1 DESC;
22042204

22052205
DROP TABLE t1;
22062206

2207+
--echo #
2208+
--echo # MDEV-16214: Incorrect plan taken by the optimizer , uses INDEX instead of ref access with ORDER BY
2209+
--echo #
2210+
2211+
create table t1(a int);
2212+
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
2213+
2214+
create table t2(
2215+
id int primary key,
2216+
key1 int,key2 int,
2217+
col1 int,
2218+
key(key1), key(key2)
2219+
);
2220+
2221+
insert into t2
2222+
select
2223+
A.a + B.a*10 + C.a*100,
2224+
A.a + 10*B.a, A.a + 10*B.a,
2225+
123456
2226+
from t1 A, t1 B, t1 C;
2227+
2228+
let $query= select
2229+
(SELECT concat(id, '-', key1, '-', col1)
2230+
FROM t2
2231+
WHERE
2232+
t2.key1 = t1.a and t2.key1 IS NOT NULL
2233+
ORDER BY
2234+
t2.key2 ASC
2235+
LIMIT 1)
2236+
from t1;
2237+
2238+
--echo # here type should show ref not index
2239+
eval explain $query;
2240+
eval $query;
2241+
2242+
drop table t1,t2;
2243+
22072244
--echo #
22082245
--echo # MDEV-17761: Odd optimizer choice with ORDER BY LIMIT and condition selectivity
22092246
--echo #

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,5 +520,12 @@ row_end bigint as row end,
520520
period for system_time (row_start, row_end)
521521
) engine=myisam with system versioning;
522522
ERROR HY000: `row_start` must be of type TIMESTAMP(6) for system-versioned table `t1`
523+
create table t (
524+
a int,
525+
row_start datetime(6) generated always as row start,
526+
row_end datetime(6) generated always as row end,
527+
period for system_time(row_start, row_end)
528+
) with system versioning;
529+
ERROR HY000: `row_start` must be of type TIMESTAMP(6) for system-versioned table `t`
523530
drop database test;
524531
create database test;

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,25 @@ set timestamp=1523466002.799571;
530530
insert into t1 values (11),(12);
531531
set timestamp=1523466004.169435;
532532
delete from t1 where pk in (11, 12);
533+
#
534+
# MDEV-18136 Server crashes in Item_func_dyncol_create::prepare_arguments
535+
#
536+
create or replace table t1 (pk int) with system versioning
537+
partition by system_time interval 7 second (
538+
partition ver_p1 history,
539+
partition ver_pn current);
540+
alter table t1
541+
partition by system_time interval column_get(column_create(7,7), 7 as int) second (
542+
partition ver_p1 history,
543+
partition ver_pn current);
544+
show create table t1;
545+
Table Create Table
546+
t1 CREATE TABLE `t1` (
547+
`pk` int(11) DEFAULT NULL
548+
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
549+
PARTITION BY SYSTEM_TIME INTERVAL 7 SECOND
550+
(PARTITION `ver_p1` HISTORY ENGINE = DEFAULT_ENGINE,
551+
PARTITION `ver_pn` CURRENT ENGINE = DEFAULT_ENGINE)
533552
# Test cleanup
534553
drop database test;
535554
create database test;

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,19 @@ insert into t1 values (1,1);
3232
create or replace table t2 (c int);
3333
create or replace view v as select t1.* from t1 join t2;
3434
replace into v (a, b) select a, b from t1;
35+
drop table t1;
36+
CREATE TABLE t1 (
37+
pk INT AUTO_INCREMENT,
38+
f INT,
39+
row_start SYS_DATATYPE AS ROW START INVISIBLE,
40+
row_end SYS_DATATYPE AS ROW END INVISIBLE,
41+
PRIMARY KEY(pk),
42+
UNIQUE(f),
43+
PERIOD FOR SYSTEM_TIME(row_start, row_end)
44+
) WITH SYSTEM VERSIONING;
45+
INSERT INTO t1 () VALUES (),(),(),(),(),();
46+
UPDATE IGNORE t1 SET f = 1;
47+
REPLACE t1 SELECT * FROM t1;
48+
DROP TABLE t1;
3549
drop database test;
3650
create database test;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,5 +387,14 @@ create or replace table t1 (
387387
period for system_time (row_start, row_end)
388388
) engine=myisam with system versioning;
389389

390+
--error ER_VERS_FIELD_WRONG_TYPE
391+
create table t (
392+
a int,
393+
row_start datetime(6) generated always as row start,
394+
row_end datetime(6) generated always as row end,
395+
period for system_time(row_start, row_end)
396+
) with system versioning;
397+
398+
390399
drop database test;
391400
create database test;

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,20 @@ insert into t1 values (11),(12);
466466
set timestamp=1523466004.169435;
467467
delete from t1 where pk in (11, 12);
468468

469+
--echo #
470+
--echo # MDEV-18136 Server crashes in Item_func_dyncol_create::prepare_arguments
471+
--echo #
472+
create or replace table t1 (pk int) with system versioning
473+
partition by system_time interval 7 second (
474+
partition ver_p1 history,
475+
partition ver_pn current);
476+
alter table t1
477+
partition by system_time interval column_get(column_create(7,7), 7 as int) second (
478+
partition ver_p1 history,
479+
partition ver_pn current);
480+
--replace_result $default_engine DEFAULT_ENGINE
481+
show create table t1;
482+
469483
--echo # Test cleanup
470484
drop database test;
471485
create database test;

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ insert into t1 values (1,1);
3535
create or replace table t2 (c int);
3636
create or replace view v as select t1.* from t1 join t2;
3737
replace into v (a, b) select a, b from t1;
38+
drop table t1;
39+
40+
--replace_result $sys_datatype_expl SYS_DATATYPE
41+
eval CREATE TABLE t1 (
42+
pk INT AUTO_INCREMENT,
43+
f INT,
44+
row_start $sys_datatype_expl AS ROW START INVISIBLE,
45+
row_end $sys_datatype_expl AS ROW END INVISIBLE,
46+
PRIMARY KEY(pk),
47+
UNIQUE(f),
48+
PERIOD FOR SYSTEM_TIME(row_start, row_end)
49+
) WITH SYSTEM VERSIONING;
50+
INSERT INTO t1 () VALUES (),(),(),(),(),();
51+
UPDATE IGNORE t1 SET f = 1;
52+
REPLACE t1 SELECT * FROM t1;
53+
DROP TABLE t1;
54+
3855

3956
drop database test;
4057
create database test;

sql/handler.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7650,8 +7650,7 @@ bool Vers_parse_info::check_conditions(const Lex_table_name &table_name,
76507650

76517651
static bool is_versioning_timestamp(const Create_field *f)
76527652
{
7653-
return (f->type_handler() == &type_handler_datetime2 ||
7654-
f->type_handler() == &type_handler_timestamp2) &&
7653+
return f->type_handler() == &type_handler_timestamp2 &&
76557654
f->length == MAX_DATETIME_FULL_WIDTH;
76567655
}
76577656

sql/partition_info.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,20 @@ class partition_info : public Sql_alloc
401401
DBUG_ASSERT(part_type == VERSIONING_PARTITION);
402402
vers_info->interval.type= int_type;
403403
vers_info->interval.start= start;
404-
return get_interval_value(thd, item, int_type, &vers_info->interval.step) ||
404+
if (item->fix_fields_if_needed_for_scalar(thd, &item))
405+
return true;
406+
bool error= get_interval_value(thd, item, int_type, &vers_info->interval.step) ||
405407
vers_info->interval.step.neg || vers_info->interval.step.second_part ||
406408
!(vers_info->interval.step.year || vers_info->interval.step.month ||
407409
vers_info->interval.step.day || vers_info->interval.step.hour ||
408410
vers_info->interval.step.minute || vers_info->interval.step.second);
411+
if (error)
412+
{
413+
my_error(ER_PART_WRONG_VALUE, MYF(0),
414+
thd->lex->create_last_non_select_table->table_name.str,
415+
"INTERVAL");
416+
}
417+
return error;
409418
}
410419
bool vers_set_limit(ulonglong limit)
411420
{

0 commit comments

Comments
 (0)