Commit 7ebf5d93 authored by Otto Kekäläinen's avatar Otto Kekäläinen
Browse files

Merge tag 'upstream/5.5.56' into ubuntu-14.04

Upstream version 5.5.56

# gpg: Signature made su 18. kesäkuuta 2017 16.40.43 CEST
# gpg:                using RSA key BED8449FCEE8DA88
# gpg: Good signature from "Otto Kekäläinen <otto@seravo.fi>" [full]
# gpg:                 aka "Otto Kekäläinen <otto@kekalainen.net>" [full]
# gpg:                 aka "Otto Kekäläinen <otto@fsfe.org>" [full]
# gpg:                 aka "Otto Kekäläinen <otto@linux.com>" [full]
# gpg:                 aka "Otto Kekäläinen <otto.kekalainen@seravo.fi>" [full]
# gpg:                 aka "Otto Kekäläinen <otto@mariadb.org>" [undefined]
# gpg:                 aka "Otto Kekäläinen <otto@debian.org>" [undefined]
# gpg:                 aka "Otto Kekäläinen <otto@sange.fi>" [full]
parents 0aa16398 067768bd
...@@ -1755,7 +1755,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra ...@@ -1755,7 +1755,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index PRIMARY PRIMARY 4 NULL 2 100.00 Using where; Using index; Using temporary; Using filesort 1 PRIMARY t1 index PRIMARY PRIMARY 4 NULL 2 100.00 Using where; Using index; Using temporary; Using filesort
1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 func 1 100.00 Using where; Using index 1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 func 1 100.00 Using where; Using index
2 DEPENDENT SUBQUERY t3 eq_ref PRIMARY PRIMARY 4 func 1 100.00 Using where; Using index 2 DEPENDENT SUBQUERY t3 eq_ref PRIMARY PRIMARY 4 func 1 100.00 Using where; Using index
2 DEPENDENT SUBQUERY t4 eq_ref PRIMARY PRIMARY 4 test.t3.pk 1 100.00 Using where; Using index 2 DEPENDENT SUBQUERY t4 eq_ref PRIMARY PRIMARY 4 test.t3.pk 1 100.00 Using index
Warnings: Warnings:
Note 1276 Field or reference 'test.t2.pk' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t2.pk' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`t2`.`pk` AS `pk`,<expr_cache><`test`.`t2`.`pk`>((select (`test`.`t3`.`pk` + if(isnull(`test`.`t4`.`pk`),0,`test`.`t4`.`pk`)) from `test`.`t3` left join `test`.`t4` on((`test`.`t4`.`pk` = `test`.`t3`.`pk`)) where (`test`.`t3`.`pk` = (`test`.`t2`.`pk` + 1000)) limit 1)) AS `t` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`pk` = (`test`.`t1`.`pk` + 1000)) and (`test`.`t1`.`pk` > 1000)) group by `test`.`t2`.`pk` Note 1003 select `test`.`t2`.`pk` AS `pk`,<expr_cache><`test`.`t2`.`pk`>((select (`test`.`t3`.`pk` + if(isnull(`test`.`t4`.`pk`),0,`test`.`t4`.`pk`)) from `test`.`t3` left join `test`.`t4` on((`test`.`t4`.`pk` = `test`.`t3`.`pk`)) where (`test`.`t3`.`pk` = (`test`.`t2`.`pk` + 1000)) limit 1)) AS `t` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`pk` = (`test`.`t1`.`pk` + 1000)) and (`test`.`t1`.`pk` > 1000)) group by `test`.`t2`.`pk`
......
...@@ -316,7 +316,7 @@ FIELDS ESCAPED BY '\\' ...@@ -316,7 +316,7 @@ FIELDS ESCAPED BY '\\'
TERMINATED BY ',' TERMINATED BY ','
ENCLOSED BY '"' ENCLOSED BY '"'
LINES TERMINATED BY '\n' (c0, c2); LINES TERMINATED BY '\n' (c0, c2);
ERROR HY000: Invalid column reference (v2.c0) in LOAD DATA ERROR HY000: Column 'c0' is not updatable
LOAD DATA INFILE '../../std_data/bug35469.dat' INTO TABLE v3 LOAD DATA INFILE '../../std_data/bug35469.dat' INTO TABLE v3
FIELDS ESCAPED BY '\\' FIELDS ESCAPED BY '\\'
...@@ -532,3 +532,21 @@ FIELDS TERMINATED BY 't' LINES TERMINATED BY ''; ...@@ -532,3 +532,21 @@ FIELDS TERMINATED BY 't' LINES TERMINATED BY '';
Got one of the listed errors Got one of the listed errors
SET @@sql_mode= @old_mode; SET @@sql_mode= @old_mode;
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-11079 Regression: LOAD DATA INFILE lost BLOB support using utf8 load files
#
CREATE TABLE t1 (a mediumblob NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
LOAD DATA INFILE '../../std_data/loaddata/mdev-11079.txt' INTO TABLE t1 CHARSET utf8 FIELDS TERMINATED BY ';' ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\n';
SELECT HEX(a) FROM t1;
HEX(a)
25AAABAC
DROP TABLE t1;
#
# MDEV-11631 LOAD DATA INFILE fails to load data with an escape character followed by a multi-byte character
#
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf8);
LOAD DATA INFILE '../../std_data/loaddata/mdev-11631.txt' INTO TABLE t1 CHARACTER SET utf8;
SELECT HEX(a) FROM t1;
HEX(a)
C3A4
DROP TABLE t1;
...@@ -67,9 +67,9 @@ sleep(0.5) ...@@ -67,9 +67,9 @@ sleep(0.5)
select count(*) FROM mysql.slow_log; select count(*) FROM mysql.slow_log;
count(*) count(*)
1 1
truncate mysql.slow_log;
set @@long_query_time=default; set @@long_query_time=default;
set global slow_query_log= @org_slow_query_log; set global slow_query_log= @org_slow_query_log;
set @@log_slow_filter=default; set @@log_slow_filter=default;
set @@log_slow_verbosity=default; set @@log_slow_verbosity=default;
set global log_output= default; set global log_output= default;
truncate mysql.slow_log;
set @@global.log_output = 'TABLE';
set session long_query_time=10; set session long_query_time=10;
select get_lock('bug27638', 1); select get_lock('bug27638', 1);
get_lock('bug27638', 1) get_lock('bug27638', 1)
1 1
set session long_query_time=1; set session long_query_time=1;
truncate table mysql.slow_log;
select get_lock('bug27638', 2); select get_lock('bug27638', 2);
get_lock('bug27638', 2) get_lock('bug27638', 2)
0 0
select if (query_time between '00:00:01' and '00:00:10', 'OK', 'WRONG') as qt, sql_text from mysql.slow_log; select if (query_time >= '00:00:01', 'OK', 'WRONG') as qt, sql_text from mysql.slow_log
where sql_text = 'select get_lock(\'bug27638\', 2)';
qt sql_text qt sql_text
OK select get_lock('bug27638', 2) OK select get_lock('bug27638', 2)
truncate table mysql.slow_log;
select get_lock('bug27638', 60); select get_lock('bug27638', 60);
get_lock('bug27638', 60) get_lock('bug27638', 60)
0 0
select if (query_time between '00:00:59' and '00:01:10', 'OK', 'WRONG') as qt, sql_text from mysql.slow_log; select if (query_time >= '00:00:59', 'OK', 'WRONG') as qt, sql_text from mysql.slow_log
where sql_text = 'select get_lock(\'bug27638\', 60)';
qt sql_text qt sql_text
OK select get_lock('bug27638', 60) OK select get_lock('bug27638', 60)
truncate table mysql.slow_log;
select get_lock('bug27638', 101); select get_lock('bug27638', 101);
get_lock('bug27638', 101) get_lock('bug27638', 101)
0 0
select if (query_time between '00:01:40' and '00:01:50', 'OK', 'WRONG') as qt, sql_text from mysql.slow_log; select if (query_time >= '00:01:40', 'OK', 'WRONG') as qt, sql_text from mysql.slow_log
where sql_text = 'select get_lock(\'bug27638\', 101)';
qt sql_text qt sql_text
OK select get_lock('bug27638', 101) OK select get_lock('bug27638', 101)
select release_lock('bug27638'); select release_lock('bug27638');
release_lock('bug27638') release_lock('bug27638')
1 1
set @@global.log_output=default;
...@@ -436,7 +436,7 @@ WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10 ...@@ -436,7 +436,7 @@ WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
2 DEPENDENT SUBQUERY it eq_ref PRIMARY PRIMARY 4 func 1 Using index condition 2 DEPENDENT SUBQUERY it eq_ref PRIMARY PRIMARY 4 func 1 Using index condition
2 DEPENDENT SUBQUERY t2 index NULL PRIMARY 4 NULL 3 Using where; Using index; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY t2 index NULL PRIMARY 4 NULL 3 Using index; Using join buffer (flat, BNL join)
SELECT * FROM t1 SELECT * FROM t1
WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10); WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10);
pk i pk i
...@@ -797,7 +797,7 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -797,7 +797,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t ALL PRIMARY,c NULL NULL NULL 64 Using where 1 PRIMARY t ALL PRIMARY,c NULL NULL NULL 64 Using where
1 PRIMARY t2 ref g g 5 test.t.c 19 Using where 1 PRIMARY t2 ref g g 5 test.t.c 19 Using where
2 DEPENDENT SUBQUERY t1 index PRIMARY PRIMARY 4 NULL 64 Using where; Using index 2 DEPENDENT SUBQUERY t1 index PRIMARY PRIMARY 4 NULL 64 Using where; Using index
2 DEPENDENT SUBQUERY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using index condition; Using where 2 DEPENDENT SUBQUERY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using where
SELECT COUNT(*) FROM t1 AS t, t2 SELECT COUNT(*) FROM t1 AS t, t2
WHERE c = g WHERE c = g
AND (EXISTS (SELECT * FROM t1, t2 WHERE a = f AND h <= t.e AND a > t.b) AND (EXISTS (SELECT * FROM t1, t2 WHERE a = f AND h <= t.e AND a > t.b)
......
...@@ -5308,6 +5308,69 @@ a ...@@ -5308,6 +5308,69 @@ a
DROP TABLE t1; DROP TABLE t1;
DROP TABLE t2; DROP TABLE t2;
DROP DATABASE db_20772273; DROP DATABASE db_20772273;
#
# Bug #25717383: MYSQLDUMP MAY EXECUTE ANY ARBITRARY QUERY
#
CREATE DATABASE bug25717383;
use bug25717383;
CREATE TABLE `tab
one` (a int);
CREATE VIEW `view
one` as SELECT * FROM `tab
one`;
CREATE PROCEDURE `proc
one`() SELECT * from `tab
one`;
CREATE TEMPORARY TABLE `temp
one` (id INT);
CREATE TRIGGER `trig
one` BEFORE INSERT ON `tab
one` FOR EACH ROW SET NEW.a = 1;
CREATE EVENT `event
one` ON SCHEDULE AT '2030-01-01 00:00:00' DO SET @a=5;
SHOW TABLES FROM bug25717383;
Tables_in_bug25717383
tab
one
view
one
SHOW TRIGGERS FROM bug25717383;
Trigger Event Table Statement Timing Created sql_mode Definer character_set_client collation_connection Database Collation
trig
one INSERT tab
one SET NEW.a = 1 BEFORE NULL root@localhost utf8 utf8_general_ci latin1_swedish_ci
SHOW EVENTS FROM bug25717383;
Db Name Definer Time zone Type Execute at Interval value Interval field Starts Ends Status Originator character_set_client collation_connection Database Collation
bug25717383 event
one root@localhost SYSTEM ONE TIME # NULL NULL NULL NULL ENABLED 1 utf8 utf8_general_ci latin1_swedish_ci
SELECT ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_SCHEMA='bug25717383' AND ROUTINE_TYPE= 'PROCEDURE'
ORDER BY ROUTINE_NAME;
ROUTINE_NAME
proc
one
SHOW TABLES FROM bug25717383;
Tables_in_bug25717383
tab
one
view
one
SHOW TRIGGERS FROM bug25717383;
Trigger Event Table Statement Timing Created sql_mode Definer character_set_client collation_connection Database Collation
trig
one INSERT tab
one SET NEW.a = 1 BEFORE NULL root@localhost utf8 utf8_general_ci latin1_swedish_ci
SHOW EVENTS FROM bug25717383;
Db Name Definer Time zone Type Execute at Interval value Interval field Starts Ends Status Originator character_set_client collation_connection Database Collation
bug25717383 event
one root@localhost SYSTEM ONE TIME # NULL NULL NULL NULL ENABLED 1 utf8 utf8_general_ci latin1_swedish_ci
SELECT ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_SCHEMA='bug25717383' AND ROUTINE_TYPE= 'PROCEDURE'
ORDER BY ROUTINE_NAME;
ROUTINE_NAME
proc
one
DROP DATABASE bug25717383;
Usage: mysqldump [OPTIONS] database [tables] Usage: mysqldump [OPTIONS] database [tables]
OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...] OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR mysqldump [OPTIONS] --all-databases [OPTIONS] OR mysqldump [OPTIONS] --all-databases [OPTIONS]
......
...@@ -2050,4 +2050,15 @@ t2 A, t2 B ...@@ -2050,4 +2050,15 @@ t2 A, t2 B
where A.b = B.b where A.b = B.b
order by A.col2, B.col2 limit 10, 1000000; order by A.col2, B.col2 limit 10, 1000000;
drop table t1,t2,t3; drop table t1,t2,t3;
#
# mdev-10705 : long order by list that can be skipped
#
SELECT 1
UNION
( SELECT 2
ORDER BY NULL, @a0 := 3, @a1 := 3, @a2 := 3, @a3 := 3, @a4 := 3,
@a5 := 3, @a6 := 3, @a7 := 3, @a8 := 3, @a9 := 3, @a10 := 3 );
1
1
2
End of 5.5 tests End of 5.5 tests
...@@ -718,3 +718,92 @@ d ...@@ -718,3 +718,92 @@ d
1991-01-01 1991-01-01
DROP TABLE t1; DROP TABLE t1;
set global default_storage_engine=default; set global default_storage_engine=default;
#
# MDEV-9455: [ERROR] mysqld got signal 11
#
CREATE TABLE `t1` (
`DIARY_TOTAL_DAY_SEQ` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`IMORY_ID` bigint(20) NOT NULL,
`NAME` varchar(75) DEFAULT NULL,
`DATETIME` varchar(10) NOT NULL DEFAULT '',
`DAILY_CALL_CNT` int(11) DEFAULT NULL,
`DAILY_SMS_CNT` int(11) DEFAULT NULL,
`NUMBER` varchar(64) DEFAULT NULL,
`DURATION` varchar(16) DEFAULT NULL,
PRIMARY KEY (`DIARY_TOTAL_DAY_SEQ`,`DATETIME`),
KEY `IDX_t1_01` (`IMORY_ID`,`DATETIME`)
) AUTO_INCREMENT=328702514 DEFAULT CHARSET=utf8mb4
PARTITION BY RANGE COLUMNS(`DATETIME`)
(PARTITION p0 VALUES LESS THAN ('2015-10-01') ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN ('2015-11-01') ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN ('2015-12-01') ENGINE = InnoDB,
PARTITION p3 VALUES LESS THAN ('2016-01-01') ENGINE = InnoDB,
PARTITION p4 VALUES LESS THAN ('2016-02-01') ENGINE = InnoDB,
PARTITION p5 VALUES LESS THAN ('2016-03-01') ENGINE = InnoDB,
PARTITION p6 VALUES LESS THAN ('2016-04-01') ENGINE = InnoDB,
PARTITION p7 VALUES LESS THAN ('2016-05-01') ENGINE = InnoDB,
PARTITION p8 VALUES LESS THAN ('2016-06-01') ENGINE = InnoDB,
PARTITION p9 VALUES LESS THAN ('2016-07-01') ENGINE = InnoDB,
PARTITION p10 VALUES LESS THAN ('2016-08-01') ENGINE = InnoDB)
;
CREATE TABLE `t2` (
`DIARY_SEQ` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`IMORY_ID` bigint(20) NOT NULL,
`CALL_TYPE` varchar(1) DEFAULT NULL,
`DATA_TYPE` varchar(1) DEFAULT NULL,
`FEATURES` varchar(1) DEFAULT NULL,
`NAME` varchar(75) DEFAULT NULL,
`NUMBER` varchar(64) DEFAULT NULL,
`DATETIME` datetime NOT NULL,
`REG_DATE` datetime NOT NULL,
`TITLE` varchar(50) DEFAULT NULL,
`BODY` varchar(4200) DEFAULT NULL,
`MIME_TYPE` varchar(32) DEFAULT NULL,
`DURATION` varchar(16) DEFAULT NULL,
`DEVICE_ID` varchar(64) DEFAULT NULL,
`DEVICE_NAME` varchar(32) DEFAULT NULL,
PRIMARY KEY (`DIARY_SEQ`,`DATETIME`,`REG_DATE`),
KEY `IDX_TB_DIARY_01` (`IMORY_ID`,`DATETIME`,`CALL_TYPE`,`NUMBER`),
KEY `IDX_TB_DIARY_02` (`REG_DATE`)
) AUTO_INCREMENT=688799006 DEFAULT CHARSET=utf8mb4
PARTITION BY RANGE COLUMNS(REG_DATE)
(PARTITION p0 VALUES LESS THAN ('2015-10-01') ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN ('2015-11-01') ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN ('2015-12-01') ENGINE = InnoDB,
PARTITION p3 VALUES LESS THAN ('2016-01-01') ENGINE = InnoDB,
PARTITION p4 VALUES LESS THAN ('2016-02-01') ENGINE = InnoDB,
PARTITION p5 VALUES LESS THAN ('2016-03-01') ENGINE = InnoDB,
PARTITION p6 VALUES LESS THAN ('2016-04-01') ENGINE = InnoDB,
PARTITION p7 VALUES LESS THAN ('2016-05-01') ENGINE = InnoDB,
PARTITION p8 VALUES LESS THAN ('2016-06-01') ENGINE = InnoDB,
PARTITION p9 VALUES LESS THAN ('2016-07-01') ENGINE = InnoDB,
PARTITION p10 VALUES LESS THAN ('2016-08-01') ENGINE = InnoDB)
;
SELECT
A.IMORY_ID,
A.NUMBER,
A.NAME,
DATE_FORMAT(A.DATETIME, '%Y-%m-%d') AS TARGET_DATE,
SUM( CASE WHEN A.DATA_TYPE='1' THEN 1 ELSE 0 END) AS CALL_CNT,
SUM( CASE WHEN A.DATA_TYPE IN ('2', '3') THEN 1 ELSE 0 END) AS SMS_CNT,
SUM(CAST(A.DURATION AS INT)) AS DURATION,
( SELECT COUNT(*)
FROM t1
WHERE IMORY_ID=A.IMORY_ID
AND NUMBER=A.NUMBER
AND NAME=A.NAME
AND DATETIME = DATE_FORMAT(A.DATETIME, '%Y-%m-%d')
) STATS_COUNT
FROM t2 A
WHERE A.IMORY_ID = 55094102
AND A.DATETIME LIKE (
SELECT CONCAT (DATE_FORMAT(DATETIME, '%Y-%m-%d') ,'%')
FROM t2
WHERE IMORY_ID=55094102
AND DIARY_SEQ IN ( 608351221, 608351225, 608351229 )
group by DATE_FORMAT(DATETIME, '%Y-%m-%d')
)
GROUP BY A.IMORY_ID, A.NUMBER, A.NAME, DATE_FORMAT(A.DATETIME, '%Y-%m-%d')
;
IMORY_ID NUMBER NAME TARGET_DATE CALL_CNT SMS_CNT DURATION STATS_COUNT
drop table t2, t1;
...@@ -248,3 +248,19 @@ PARTITION p1 VALUES LESS THAN (100) MAX_ROWS=100, ...@@ -248,3 +248,19 @@ PARTITION p1 VALUES LESS THAN (100) MAX_ROWS=100,
PARTITION pMax VALUES LESS THAN MAXVALUE); PARTITION pMax VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (1, "Partition p1, first row"); INSERT INTO t1 VALUES (1, "Partition p1, first row");
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-10418 Assertion `m_extra_cache' failed
# in ha_partition::late_extra_cache(uint)
#
CREATE TABLE t1 (f1 INT) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (f2 INT) ENGINE=MyISAM PARTITION BY RANGE(f2) (PARTITION pmax VALUES LESS THAN MAXVALUE);
INSERT INTO t2 VALUES (8);
CREATE ALGORITHM = MERGE VIEW v AS SELECT f2 FROM t2, t1;
UPDATE v SET f2 = 1;
SELECT * FROM t2;
f2
1
DROP VIEW v;
DROP TABLE t2;
DROP TABLE t1;
...@@ -2157,23 +2157,22 @@ Warnings: ...@@ -2157,23 +2157,22 @@ Warnings:
Warning 1052 Column 'kundentyp' in group statement is ambiguous Warning 1052 Column 'kundentyp' in group statement is ambiguous
drop table t1; drop table t1;
SET optimizer_switch=@save_optimizer_switch; SET optimizer_switch=@save_optimizer_switch;
SELECT sleep(5); SELECT sleep(50);
SELECT sleep(5); SELECT sleep(50);
# -- Success: more than --thread_pool_max_threads normal connections not possible # -- Success: more than --thread_pool_max_threads normal connections not possible
sleep(5)
0
sleep(5)
0
SELECT sleep(5);
SELECT sleep(5);
SELECT 'Connection on extra port ok'; SELECT 'Connection on extra port ok';
Connection on extra port ok Connection on extra port ok
Connection on extra port ok Connection on extra port ok
SELECT sleep(5.5);
SELECT 'Connection on extra port 2 ok'; SELECT 'Connection on extra port 2 ok';
Connection on extra port 2 ok Connection on extra port 2 ok
Connection on extra port 2 ok Connection on extra port 2 ok
# -- Success: more than --extra-max-connections + 1 normal connections not possible # -- Success: more than --extra-max-connections + 1 normal connections not possible
sleep(5) KILL QUERY <default_connection_ID>;
0 KILL QUERY <con2_connection_ID>;
sleep(5) sleep(50)
1
sleep(50)
1
sleep(5.5)
0 0
...@@ -4103,4 +4103,74 @@ NULL ...@@ -4103,4 +4103,74 @@ NULL
NULL NULL
deallocate prepare stmt; deallocate prepare stmt;
drop table t1,t2,t3,t4; drop table t1,t2,t3,t4;
#
# MDEV-11859: the plans for the first and the second executions
# of PS are not the same
#
create table t1 (id int, c varchar(3), key idx(c))engine=myisam;
insert into t1 values (3,'bar'), (1,'xxx'), (2,'foo'), (5,'yyy');
prepare stmt1 from
"explain extended
select * from t1 where (1, 2) in ( select 3, 4 ) or c = 'foo'";
execute stmt1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ref idx idx 6 const 1 100.00 Using index condition
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`c` AS `c` from `test`.`t1` where (`test`.`t1`.`c` = 'foo')
execute stmt1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ref idx idx 6 const 1 100.00 Using index condition
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`c` AS `c` from `test`.`t1` where (`test`.`t1`.`c` = 'foo')
deallocate prepare stmt1;
prepare stmt1 from
"select * from t1 where (1, 2) in ( select 3, 4 ) or c = 'foo'";
flush status;
execute stmt1;
id c
2 foo
show status like '%Handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 1
Handler_read_last 0
Handler_read_next 1
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
flush status;
execute stmt1;
id c
2 foo
show status like '%Handler_read%';
Variable_name Value
Handler_read_first 0
Handler_read_key 1
Handler_read_last 0
Handler_read_next 1
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
deallocate prepare stmt1;
prepare stmt2 from
"explain extended
select * from t1 where (1, 2) in ( select 3, 4 )";
execute stmt2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`c` AS `c` from `test`.`t1` where 0
execute stmt2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`c` AS `c` from `test`.`t1` where 0
deallocate prepare stmt2;
drop table t1;
# End of 5.5 tests # End of 5.5 tests
...@@ -60,11 +60,11 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -60,11 +60,11 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE Population > 100000 AND Name LIKE 'Aba%' OR WHERE Population > 100000 AND Name LIKE 'Aba%' OR
Country IN ('CAN', 'ARG') AND ID < 3800 OR Country IN ('CAN', 'ARG') AND ID BETWEEN 120 AND 130 OR
Country < 'U' AND Name LIKE 'Zhu%' OR Country <= 'ALB' AND Name LIKE 'L%' OR
ID BETWEEN 3800 AND 3810; ID BETWEEN 3807 AND 3810;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,Country,PRIMARY 35,3,4 NULL 132 Using sort_union(Name,Country,PRIMARY); Using where 1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,PRIMARY,Country 35,4,3 NULL 31 Using sort_union(Name,PRIMARY,Country); Using where
EXPLAIN EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE (Population > 101000 AND Population < 115000); WHERE (Population > 101000 AND Population < 115000);
...@@ -1763,4 +1763,42 @@ a b ...@@ -1763,4 +1763,42 @@ a b
167 9999 167 9999
168 10000 168 10000
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-8603: Wrong result OR/AND condition over index fields
#
CREATE TABLE t1 (
id INT NOT NULL,
state VARCHAR(64),
capital VARCHAR(64),
UNIQUE KEY (id),
KEY state (state,id),
KEY capital (capital, id)
);
INSERT INTO t1 VALUES
(1,'Arizona','Phoenix'),
(2,'Hawaii','Honolulu'),
(3,'Georgia','Atlanta'),
(4,'Florida','Tallahassee'),
(5,'Alaska','Juneau'),
(6,'Michigan','Lansing'),
(7,'Pennsylvania','Harrisburg'),
(8,'Virginia','Richmond')
;
EXPLAIN
SELECT * FROM t1 FORCE KEY (state,capital)
WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9
OR ( capital >= 'Topeka' OR state = 'Kansas' ) AND state != 'Texas';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range state,capital state 71 NULL 12 Using index condition; Using where
SELECT * FROM t1 FORCE KEY (state,capital)
WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9
OR ( capital >= 'Topeka' OR state = 'Kansas' ) AND state != 'Texas';
id state capital
4 Florida Tallahassee
3 Georgia Atlanta
2 Hawaii Honolulu
6 Michigan Lansing
7 Pennsylvania Harrisburg
8 Virginia Richmond
DROP TABLE t1;
set session optimizer_switch='index_merge_sort_intersection=default'; set session optimizer_switch='index_merge_sort_intersection=default';
--- ./r/range_vs_index_merge_innodb.result 2012-11-21 19:35:14.000000000 +0100 --- range_vs_index_merge_innodb.result 2017-01-17 15:00:18.039148421 -0800
+++ ./r/range_vs_index_merge_innodb,innodb_plugin.reject 2012-11-21 20:56:00.000000000 +0100 +++ range_vs_index_merge_innodb,innodb_plugin.result 2017-01-17 14:58:45.129148312 -0800
@@ -50,14 +50,14 @@ @@ -50,14 +50,14 @@
WHERE (Population >= 100000 OR Name LIKE 'P%') AND Country='CAN' OR WHERE (Population >= 100000 OR Name LIKE 'P%') AND Country='CAN' OR
(Population < 100000 OR Name Like 'T%') AND Country='ARG'; (Population < 100000 OR Name Like 'T%') AND Country='ARG';
...@@ -278,3 +278,12 @@ ...@@ -278,3 +278,12 @@
FLUSH STATUS; FLUSH STATUS;
SELECT * FROM City SELECT * FROM City
WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'H')) WHERE ((Name > 'Ca' AND Name < 'Cf') OR (Country > 'E' AND Country < 'H'))
@@ -1790,7 +1790,7 @@
WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9
OR ( capital >= 'Topeka' OR state = 'Kansas' ) AND state != 'Texas';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range state,capital state 71 NULL 10 Using index condition; Using where
+1 SIMPLE t1 range state,capital state 71 NULL 10 Using where
SELECT * FROM t1 FORCE KEY (state,capital)
WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9
OR ( capital >= 'Topeka' OR state = 'Kansas' ) AND state != 'Texas';
...@@ -61,11 +61,11 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -61,11 +61,11 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE Population > 100000 AND Name LIKE 'Aba%' OR WHERE Population > 100000 AND Name LIKE 'Aba%' OR
Country IN ('CAN', 'ARG') AND ID < 3800 OR Country IN ('CAN', 'ARG') AND ID BETWEEN 120 AND 130 OR
Country < 'U' AND Name LIKE 'Zhu%' OR Country <= 'ALB' AND Name LIKE 'L%' OR
ID BETWEEN 3800 AND 3810; ID BETWEEN 3807 AND 3810;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,Country,PRIMARY 35,3,4 NULL 125 Using sort_union(Name,Country,PRIMARY); Using where 1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,Country,PRIMARY 35,3,4 NULL 33 Using sort_union(Name,Country,PRIMARY); Using where
EXPLAIN EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE (Population > 101000 AND Population < 115000); WHERE (Population > 101000 AND Population < 115000);
...@@ -369,7 +369,7 @@ WHERE ((ID < 200) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG'))) ...@@ -369,7 +369,7 @@ WHERE ((ID < 200) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
OR ((ID BETWEEN 100 AND 200) AND OR ((ID BETWEEN 100 AND 200) AND
(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000))); (Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000)));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE City range PRIMARY,Population,Country,Name PRIMARY 4 NULL 200 Using where 1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,Country,PRIMARY 35,3,4 NULL 181 Using sort_union(Name,Country,PRIMARY); Using where
SELECT * FROM City USE INDEX () SELECT * FROM City USE INDEX ()
WHERE ((ID < 10) AND (Name LIKE 'H%' OR (Country > 'A' AND Country < 'ARG'))) WHERE ((ID < 10) AND (Name LIKE 'H%' OR (Country > 'A' AND Country < 'ARG')))
OR ((ID BETWEEN 100 AND 110) AND OR ((ID BETWEEN 100 AND 110) AND
...@@ -1764,5 +1764,43 @@ a b ...@@ -1764,5 +1764,43 @@ a b
167 9999 167 9999
168 10000 168 10000
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-8603: Wrong result OR/AND condition over index fields
#
CREATE TABLE t1 (
id INT NOT NULL,
state VARCHAR(64),
capital VARCHAR(64),
UNIQUE KEY (id),
KEY state (state,id),
KEY capital (capital, id)
);
INSERT INTO t1 VALUES
(1,'Arizona','Phoenix'),
(2,'Hawaii','Honolulu'),
(3,'Georgia','Atlanta'),
(4,'Florida','Tallahassee'),
(5,'Alaska','Juneau'),
(6,'Michigan','Lansing'),
(7,'Pennsylvania','Harrisburg'),
(8,'Virginia','Richmond')
;
EXPLAIN
SELECT * FROM t1 FORCE KEY (state,capital)
WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9
OR ( capital >= 'Topeka' OR state = 'Kansas' ) AND state != 'Texas';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range state,capital state 71 NULL 10 Using index condition; Using where
SELECT * FROM t1 FORCE KEY (state,capital)
WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9
OR ( capital >= 'Topeka' OR state = 'Kansas' ) AND state != 'Texas';
id state capital
4 Florida Tallahassee
3 Georgia Atlanta
2 Hawaii Honolulu
6 Michigan Lansing
7 Pennsylvania Harrisburg
8 Virginia Richmond
DROP TABLE t1;
set session optimizer_switch='index_merge_sort_intersection=default'; set session optimizer_switch='index_merge_sort_intersection=default';
SET SESSION STORAGE_ENGINE=DEFAULT; SET SESSION STORAGE_ENGINE=DEFAULT;
...@@ -266,7 +266,7 @@ from t2; ...@@ -266,7 +266,7 @@ from t2;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00
2 DEPENDENT SUBQUERY t1 ref_or_null a a 5 func 2 100.00 Using where; Full scan on NULL key 2 DEPENDENT SUBQUERY t1 ref_or_null a a 5 func 2 100.00 Using where; Full scan on NULL key
2 DEPENDENT SUBQUERY t4 ALL NULL NULL NULL NULL 100 100.00 Using where; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY t4 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
Warnings: Warnings:
Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(select `test`.`t1`.`a`,`test`.`t1`.`b` from `test`.`t1` join `test`.`t4` where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`)))))) AS `Z` from `test`.`t2` Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(select `test`.`t1`.`a`,`test`.`t1`.`b` from `test`.`t1` join `test`.`t4` where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`)))))) AS `Z` from `test`.`t2`
...@@ -1240,19 +1240,19 @@ explain select * from t2 where a in (select straight_join A.a from t1 A, t1 B); ...@@ -1240,19 +1240,19 @@ explain select * from t2 where a in (select straight_join A.a from t1 A, t1 B);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 10 Using where 1 PRIMARY t2 ALL NULL NULL NULL NULL 10 Using where
2 DEPENDENT SUBQUERY A ALL NULL NULL NULL NULL 10 Using where 2 DEPENDENT SUBQUERY A ALL NULL NULL NULL NULL 10 Using where
2 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join)
explain select * from t2 where a in (select straight_join A.a from t1 A, t1 B); explain select * from t2 where a in (select straight_join A.a from t1 A, t1 B);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 10 Using where 1 PRIMARY t2 ALL NULL NULL NULL NULL 10 Using where
2 DEPENDENT SUBQUERY A ALL NULL NULL NULL NULL 10 Using where 2 DEPENDENT SUBQUERY A ALL NULL NULL NULL NULL 10 Using where
2 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join)
explain select straight_join * from t2 X, t2 Y explain select straight_join * from t2 X, t2 Y
where X.a in (select straight_join A.a from t1 A, t1 B); where X.a in (select straight_join A.a from t1 A, t1 B);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY X ALL NULL NULL NULL NULL 10 Using where 1 PRIMARY X ALL NULL NULL NULL NULL 10 Using where
1 PRIMARY Y ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join) 1 PRIMARY Y ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join)
2 DEPENDENT SUBQUERY A ALL NULL NULL NULL NULL 10 Using where 2 DEPENDENT SUBQUERY A ALL NULL NULL NULL NULL 10 Using where
2 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join)
create table t0 (a int, b int); create table t0 (a int, b int);
insert into t0 values(1,1); insert into t0 values(1,1);
explain select * from t0, t3 where t3.a in (select a from t2) and (t3.a < 10 or t3.a >30); explain select * from t0, t3 where t3.a in (select a from t2) and (t3.a < 10 or t3.a >30);
......
...@@ -276,7 +276,7 @@ from t2; ...@@ -276,7 +276,7 @@ from t2;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00
2 DEPENDENT SUBQUERY t1 ref_or_null a a 5 func 2 100.00 Using where; Full scan on NULL key 2 DEPENDENT SUBQUERY t1 ref_or_null a a 5 func 2 100.00 Using where; Full scan on NULL key
2 DEPENDENT SUBQUERY t4 ALL NULL NULL NULL NULL 100 100.00 Using where; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY t4 ALL NULL NULL NULL NULL 100 100.00 Using join buffer (flat, BNL join)
Warnings: Warnings:
Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(select `test`.`t1`.`a`,`test`.`t1`.`b` from `test`.`t1` join `test`.`t4` where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`)))))) AS `Z` from `test`.`t2` Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(select `test`.`t1`.`a`,`test`.`t1`.`b` from `test`.`t1` join `test`.`t4` where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`)))))) AS `Z` from `test`.`t2`
...@@ -1250,19 +1250,19 @@ explain select * from t2 where a in (select straight_join A.a from t1 A, t1 B); ...@@ -1250,19 +1250,19 @@ explain select * from t2 where a in (select straight_join A.a from t1 A, t1 B);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 10 Using where 1 PRIMARY t2 ALL NULL NULL NULL NULL 10 Using where
2 DEPENDENT SUBQUERY A ALL NULL NULL NULL NULL 10 Using where 2 DEPENDENT SUBQUERY A ALL NULL NULL NULL NULL 10 Using where
2 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join)
explain select * from t2 where a in (select straight_join A.a from t1 A, t1 B); explain select * from t2 where a in (select straight_join A.a from t1 A, t1 B);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 10 Using where 1 PRIMARY t2 ALL NULL NULL NULL NULL 10 Using where
2 DEPENDENT SUBQUERY A ALL NULL NULL NULL NULL 10 Using where 2 DEPENDENT SUBQUERY A ALL NULL NULL NULL NULL 10 Using where
2 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join)
explain select straight_join * from t2 X, t2 Y explain select straight_join * from t2 X, t2 Y
where X.a in (select straight_join A.a from t1 A, t1 B); where X.a in (select straight_join A.a from t1 A, t1 B);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY X ALL NULL NULL NULL NULL 10 Using where 1 PRIMARY X ALL NULL NULL NULL NULL 10 Using where
1 PRIMARY Y ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join) 1 PRIMARY Y ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join)
2 DEPENDENT SUBQUERY A ALL NULL NULL NULL NULL 10 Using where 2 DEPENDENT SUBQUERY A ALL NULL NULL NULL NULL 10 Using where
2 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join)
create table t0 (a int, b int); create table t0 (a int, b int);
insert into t0 values(1,1); insert into t0 values(1,1);
explain select * from t0, t3 where t3.a in (select a from t2) and (t3.a < 10 or t3.a >30); explain select * from t0, t3 where t3.a in (select a from t2) and (t3.a < 10 or t3.a >30);
......
...@@ -19,7 +19,7 @@ SELECT 1 FROM t1 ...@@ -19,7 +19,7 @@ SELECT 1 FROM t1
WHERE NOT EXISTS (SELECT 1 FROM t2 WHERE 1 = (SELECT MIN(t2.b) FROM t3)) WHERE NOT EXISTS (SELECT 1 FROM t2 WHERE 1 = (SELECT MIN(t2.b) FROM t3))
ORDER BY count(*); ORDER BY count(*);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL a 5 NULL 2 Using where; Using index; Using temporary 1 PRIMARY t1 index NULL a 5 NULL 2 Using index; Using temporary
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where
3 DEPENDENT SUBQUERY t3 system NULL NULL NULL NULL 0 const row not found 3 DEPENDENT SUBQUERY t3 system NULL NULL NULL NULL 0 const row not found
# should not crash the next statement # should not crash the next statement
...@@ -1418,7 +1418,7 @@ GROUP BY f9; ...@@ -1418,7 +1418,7 @@ GROUP BY f9;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2
SELECT COUNT(t2.f3), SELECT COUNT(t2.f3),
(SELECT COUNT(f3) FROM t1 WHERE t2.f1) AS f9 (SELECT COUNT(f3) FROM t1 WHERE t2.f1) AS f9
FROM t2 JOIN t1 ON t1.f3 FROM t2 JOIN t1 ON t1.f3
...@@ -1434,7 +1434,7 @@ ORDER BY f9; ...@@ -1434,7 +1434,7 @@ ORDER BY f9;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2
SELECT COUNT(t2.f3), SELECT COUNT(t2.f3),
(SELECT COUNT(f3) FROM t1 WHERE t2.f1) AS f9 (SELECT COUNT(f3) FROM t1 WHERE t2.f1) AS f9
FROM t2 JOIN t1 ON t1.f3 FROM t2 JOIN t1 ON t1.f3
...@@ -2444,10 +2444,59 @@ WHERE EXISTS ( ...@@ -2444,10 +2444,59 @@ WHERE EXISTS (
)"; )";
EXECUTE stmt; EXECUTE stmt;
i i
4
6 6
EXECUTE stmt; EXECUTE stmt;
i i
4
6 6
drop table t1, t2, t3; drop table t1, t2, t3;
#
# MDEV-11078: NULL NOT IN (non-empty subquery) should never return results
#
create table t1(a int,b int);
create table t2(a int,b int);
insert into t1 value (1,2);
select (NULL) in (select 1 from t1);
(NULL) in (select 1 from t1)
NULL
select (null) in (select 1 from t2);
(null) in (select 1 from t2)
0
select 1 in (select 1 from t1);
1 in (select 1 from t1)
1
select 1 in (select 1 from t2);
1 in (select 1 from t2)
0
select 1 from dual where null in (select 1 from t1);
1
select 1 from dual where null in (select 1 from t2);
1
select (null,null) in (select * from t1);
(null,null) in (select * from t1)
NULL
select (null,null) in (select * from t2);
(null,null) in (select * from t2)
0
select 1 from dual where null not in (select 1 from t1);
1
select 1 from dual where null not in (select 1 from t2);
1
1
drop table t1,t2;
#
# MDEV-6486: Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index))'
# failed with SELECT SQ, TEXT field
#
CREATE TABLE t1 (a VARCHAR(8), KEY(a)) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('foo'),( 'bar');
CREATE TABLE t2 (b VARCHAR(8), c TINYTEXT, KEY(b)) ENGINE=MyISAM;
INSERT INTO t2 VALUES ('baz','baz'),('qux', 'qux');
SELECT ( SELECT COUNT(*) FROM t1 WHERE a = c ) AS field, COUNT(DISTINCT c)
FROM t2 WHERE b <= 'quux' GROUP BY field;
field COUNT(DISTINCT c)
0 1
drop table t1,t2;
SET optimizer_switch= @@global.optimizer_switch; SET optimizer_switch= @@global.optimizer_switch;
set @@tmp_table_size= @@global.tmp_table_size; set @@tmp_table_size= @@global.tmp_table_size;
...@@ -273,7 +273,7 @@ EXPLAIN SELECT 1 FROM t1 WHERE NOT EXISTS ...@@ -273,7 +273,7 @@ EXPLAIN SELECT 1 FROM t1 WHERE NOT EXISTS
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 1 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 1 Using where
2 DEPENDENT SUBQUERY t2 eq_ref PRIMARY,d d 2 func 1 Using where 2 DEPENDENT SUBQUERY t2 eq_ref PRIMARY,d d 2 func 1 Using where
3 DEPENDENT SUBQUERY t2 index NULL d 2 NULL 1 Using where; Using index 3 DEPENDENT SUBQUERY t2 index NULL d 2 NULL 1 Using index
DROP TABLE t2; DROP TABLE t2;
CREATE TABLE t2 (b INT, c INT, UNIQUE KEY (b), UNIQUE KEY (b, c )) ENGINE=INNODB; CREATE TABLE t2 (b INT, c INT, UNIQUE KEY (b), UNIQUE KEY (b, c )) ENGINE=INNODB;
INSERT INTO t2 VALUES (1, 1); INSERT INTO t2 VALUES (1, 1);
...@@ -454,3 +454,32 @@ HAVING SQ2_alias1 . col_int_key >= 7 ...@@ -454,3 +454,32 @@ HAVING SQ2_alias1 . col_int_key >= 7
1 1
drop table t1; drop table t1;
set optimizer_switch=@subselect_innodb_tmp; set optimizer_switch=@subselect_innodb_tmp;
#
# MDEV-9635:Server crashes in part_of_refkey or assertion
# `!created && key_to_save < (int)s->keys' failed in
# TABLE::use_index(int) or with join_cache_level>2
#
SET join_cache_level=3;
CREATE TABLE t1 (f1 VARCHAR(1024)) ENGINE=InnoDB;
CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
CREATE TABLE t2 (f2 VARCHAR(4)) ENGINE=InnoDB;
INSERT INTO t2 VALUES ('foo'),('bar');
SELECT * FROM v1, t2 WHERE ( f1, f2 ) IN ( SELECT f1, f1 FROM t1 );
f1 f2
set join_cache_level = default;
drop view v1;
drop table t1,t2;
#
# MDEV-10693: cost-based choice between materialization and in-to-exists
# for a subquery from the expression used in ref access
#
CREATE TABLE t1 (i1 INT PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (i2 INT) ENGINE=InnoDB;
CREATE TABLE t3 (i3 INT PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t3 VALUES (3);
SELECT * FROM t1
WHERE NULL IN ( SELECT i2 FROM t2
WHERE i1 IN ( i2 IN ( SELECT i3 FROM t3 ) ) AND i2 = 2 );
i1
DROP TABLE t1,t2,t3;
...@@ -2163,6 +2163,115 @@ execute stmt; ...@@ -2163,6 +2163,115 @@ execute stmt;
a a
0 0
drop table t1; drop table t1;
#
# MDEV-12429: IN subquery used in WHERE of EXISTS subquery
#
CREATE TABLE t1 (
pk INT, f1 INT NOT NULL, f2 VARCHAR(3), f3 INT NULL, PRIMARY KEY(pk)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1,1,'foo',8), (2,5,'bar',7);
SELECT sq1.f2 FROM t1 AS sq1
WHERE EXISTS ( SELECT * FROM t1 AS sq2
WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
f2
foo
EXPLAIN
SELECT sq1.f2 FROM t1 AS sq1
WHERE EXISTS ( SELECT * FROM t1 AS sq2
WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY sq1 ALL NULL NULL NULL NULL 2 Using where
2 DEPENDENT SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1
2 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2
# this checks the result set above
set @save_optimizer_switch= @@optimizer_switch;
set optimizer_switch= 'materialization=off,semijoin=off';
SELECT sq1.f2 FROM t1 AS sq1
WHERE EXISTS ( SELECT * FROM t1 AS sq2
WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
f2
foo
set optimizer_switch= @save_optimizer_switch;
DROP TABLE t1;
#
# MDEV-12145: IN subquery used in WHERE of EXISTS subquery
#
CREATE TABLE t1 (f1 INT) ENGINE=MyISAM;
INSERT INTO t1 VALUES (4),(6);
CREATE TABLE t2 (i2 INT, KEY(i2)) ENGINE=MyISAM;
INSERT INTO t2 VALUES (8),(7),(1);
CREATE TABLE t3 (f3 INT, i3 INT, KEY(i3)) ENGINE=MyISAM;
INSERT INTO t3 VALUES (8,0),(6,3),(2,8),(3,8),(1,6),(0,0),(1,0),(1,5);
SELECT * FROM t1
WHERE EXISTS ( SELECT * FROM t2, t3
WHERE i3 = i2 AND f1 IN ( SELECT f3 FROM t3 ) );
f1
6
EXPLAIN EXTENDED
SELECT * FROM t1
WHERE EXISTS ( SELECT * FROM t2, t3
WHERE i3 = i2 AND f1 IN ( SELECT f3 FROM t3 ) );
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
2 DEPENDENT SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00
2 DEPENDENT SUBQUERY t2 index i2 i2 5 NULL 3 100.00 Using where; Using index; Using join buffer (flat, BNL join)
2 DEPENDENT SUBQUERY t3 ref i3 i3 5 test.t2.i2 2 100.00 Using index
3 MATERIALIZED t3 ALL NULL NULL NULL NULL 8 100.00
Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where <expr_cache><`test`.`t1`.`f1`>(exists(select 1 from `test`.`t2` semi join (`test`.`t3`) join `test`.`t3` where ((`test`.`t3`.`i3` = `test`.`t2`.`i2`) and (`test`.`t1`.`f1` = `test`.`t3`.`f3`))))
# this checks the result set above
set @save_optimizer_switch= @@optimizer_switch;
set optimizer_switch= 'materialization=off,semijoin=off';
SELECT * FROM t1
WHERE EXISTS ( SELECT * FROM t2, t3
WHERE i3 = i2 AND f1 IN ( SELECT f3 FROM t3 ) );
f1
6
set optimizer_switch= @save_optimizer_switch;
DROP TABLE t1,t2,t3;
#
# MDEV-9686: IN subquery used in WHERE of a subquery from select list
#
CREATE TABLE t1 (pk INT PRIMARY KEY, f1 INT);
INSERT INTO t1 VALUES (1, 4),(2, 3),(3, 3),(4, 6),(5, 3);
CREATE TABLE t2 (f2 INT);
INSERT INTO t2 VALUES (1),(2),(3),(4),(5);
# t1.pk is always IN ( SELECT f2 FROM t2 ),
# so the IN condition should be true for every row,
# and thus COUNT(*) should always return 5
SELECT pk, f1, ( SELECT COUNT(*) FROM t2
WHERE t1.pk IN ( SELECT f2 FROM t2 ) ) AS sq FROM t1;
pk f1 sq
1 4 5
2 3 5
3 3 5
4 6 5
5 3 5
EXPLAIN EXTENDED
SELECT pk, f1, ( SELECT COUNT(*) FROM t2
WHERE t1.pk IN ( SELECT f2 FROM t2 ) ) AS sq FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00
2 DEPENDENT SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using join buffer (flat, BNL join)
3 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00
Warnings:
Note 1276 Field or reference 'test.t1.pk' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`f1` AS `f1`,<expr_cache><`test`.`t1`.`pk`>((select count(0) from `test`.`t2` semi join (`test`.`t2`) where (`test`.`t1`.`pk` = `test`.`t2`.`f2`))) AS `sq` from `test`.`t1`
# this checks the result set above
set @save_optimizer_switch= @@optimizer_switch;
set optimizer_switch= 'materialization=off,semijoin=off';
SELECT pk, f1, ( SELECT COUNT(*) FROM t2
WHERE t1.pk IN ( SELECT f2 FROM t2 ) ) AS sq FROM t1;
pk f1 sq
1 4 5
2 3 5
3 3 5
4 6 5
5 3 5
set optimizer_switch= @save_optimizer_switch;
DROP TABLE t1,t2;
# End of 5.5 tests # End of 5.5 tests
set @subselect_mat_test_optimizer_switch_value=null; set @subselect_mat_test_optimizer_switch_value=null;
set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off'; set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off';
......
...@@ -177,7 +177,7 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -177,7 +177,7 @@ id select_type table type possible_keys key key_len ref rows Extra
2 DEPENDENT SUBQUERY m16 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY m16 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join)
2 DEPENDENT SUBQUERY m17 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY m17 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join)
2 DEPENDENT SUBQUERY m18 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY m18 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join)
2 DEPENDENT SUBQUERY m19 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY m19 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join)
select * from select * from
t1 left join t2 on (t2.a= t1.a and t2.a in (select pk from t10)) t1 left join t2 on (t2.a= t1.a and t2.a in (select pk from t10))
where t1.a < 5; where t1.a < 5;
......
Supports Markdown
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