summaryrefslogtreecommitdiff
path: root/mysql-test/main
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2018-11-06 09:40:39 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2018-11-06 09:40:39 +0200
commitdf563e0c037f9b2cdb22e145575f92a121b4b529 (patch)
tree31d39796cebcef916eb7e0888537c18f946170ff /mysql-test/main
parente058a251c10350f3727ca1df022dc5786933535b (diff)
parentbdfe2784d5b73a1fdcdacb3d9adcc9dc71af344b (diff)
downloadmariadb-git-df563e0c037f9b2cdb22e145575f92a121b4b529.tar.gz
Merge 10.2 into 10.3
main.derived_cond_pushdown: Move all 10.3 tests to the end, trim trailing white space, and add an "End of 10.3 tests" marker. Add --sorted_result to tests where the ordering is not deterministic. main.win_percentile: Add --sorted_result to tests where the ordering is no longer deterministic.
Diffstat (limited to 'mysql-test/main')
-rw-r--r--mysql-test/main/alter_table.result53
-rw-r--r--mysql-test/main/alter_table.test50
-rw-r--r--mysql-test/main/create_or_replace.result8
-rw-r--r--mysql-test/main/create_or_replace.test8
-rw-r--r--mysql-test/main/ctype_latin1.result9
-rw-r--r--mysql-test/main/ctype_latin1.test12
-rw-r--r--mysql-test/main/ctype_uca.result21
-rw-r--r--mysql-test/main/ctype_uca.test18
-rw-r--r--mysql-test/main/derived_cond_pushdown.result7913
-rw-r--r--mysql-test/main/derived_cond_pushdown.test2312
-rw-r--r--mysql-test/main/flush.result1
-rw-r--r--mysql-test/main/flush.test1
-rw-r--r--mysql-test/main/func_concat.result20
-rw-r--r--mysql-test/main/func_concat.test22
-rw-r--r--mysql-test/main/index_merge_myisam.result50
-rw-r--r--mysql-test/main/index_merge_myisam.test35
-rw-r--r--mysql-test/main/lock.result4
-rw-r--r--mysql-test/main/lock.test4
-rw-r--r--mysql-test/main/lock_multi.result12
-rw-r--r--mysql-test/main/lock_multi.test14
-rw-r--r--mysql-test/main/lowercase_fs_off.result69
-rw-r--r--mysql-test/main/lowercase_fs_off.test15
-rw-r--r--mysql-test/main/order_by_zerolength-4285.result20
-rw-r--r--mysql-test/main/order_by_zerolength-4285.test14
-rw-r--r--mysql-test/main/partition_explicit_prune.result19
-rw-r--r--mysql-test/main/partition_explicit_prune.test19
-rw-r--r--mysql-test/main/set_password.result18
-rw-r--r--mysql-test/main/show_grants_with_plugin-7985.result2
-rw-r--r--mysql-test/main/type_datetime.test10
-rw-r--r--mysql-test/main/type_newdecimal.result44
-rw-r--r--mysql-test/main/type_newdecimal.test45
-rw-r--r--mysql-test/main/type_year.result9
-rw-r--r--mysql-test/main/type_year.test9
-rw-r--r--mysql-test/main/win.result401
-rw-r--r--mysql-test/main/win.test45
-rw-r--r--mysql-test/main/win_first_last_value.result20
-rw-r--r--mysql-test/main/win_percent_cume.result72
-rw-r--r--mysql-test/main/win_percent_cume.test6
-rw-r--r--mysql-test/main/win_percentile.result60
-rw-r--r--mysql-test/main/win_percentile.test7
-rw-r--r--mysql-test/main/win_rank.result81
-rw-r--r--mysql-test/main/win_rank.test17
-rw-r--r--mysql-test/main/win_std.test4
43 files changed, 6110 insertions, 5463 deletions
diff --git a/mysql-test/main/alter_table.result b/mysql-test/main/alter_table.result
index cb3783eca5a..49c42479516 100644
--- a/mysql-test/main/alter_table.result
+++ b/mysql-test/main/alter_table.result
@@ -1411,6 +1411,59 @@ t1 CREATE TABLE `t1` (
`consultant_id` bigint(20) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8
DROP TABLE t1;
+#
+# BUG#27788685: NO WARNING WHEN TRUNCATING A STRING WITH DATA LOSS
+#
+SET GLOBAL max_allowed_packet=17825792;
+connect con1, localhost, root,,;
+CREATE TABLE t1 (t1_fld1 TEXT);
+CREATE TABLE t2 (t2_fld1 MEDIUMTEXT);
+CREATE TABLE t3 (t3_fld1 LONGTEXT);
+INSERT INTO t1 VALUES (REPEAT('a',300));
+INSERT INTO t2 VALUES (REPEAT('b',65680));
+INSERT INTO t3 VALUES (REPEAT('c',16777300));
+SELECT LENGTH(t1_fld1) FROM t1;
+LENGTH(t1_fld1)
+300
+SELECT LENGTH(t2_fld1) FROM t2;
+LENGTH(t2_fld1)
+65680
+SELECT LENGTH(t3_fld1) FROM t3;
+LENGTH(t3_fld1)
+16777300
+# With strict mode
+SET SQL_MODE='STRICT_ALL_TABLES';
+ALTER TABLE t1 CHANGE `t1_fld1` `my_t1_fld1` TINYTEXT;
+ERROR 22001: Data too long for column 'my_t1_fld1' at row 1
+ALTER TABLE t2 CHANGE `t2_fld1` `my_t2_fld1` TEXT;
+ERROR 22001: Data too long for column 'my_t2_fld1' at row 1
+ALTER TABLE t3 CHANGE `t3_fld1` `my_t3_fld1` MEDIUMTEXT;
+ERROR 22001: Data too long for column 'my_t3_fld1' at row 1
+# With non-strict mode
+SET SQL_MODE='';
+ALTER TABLE t1 CHANGE `t1_fld1` `my_t1_fld1` TINYTEXT;
+Warnings:
+Warning 1265 Data truncated for column 'my_t1_fld1' at row 1
+ALTER TABLE t2 CHANGE `t2_fld1` `my_t2_fld1` TEXT;
+Warnings:
+Warning 1265 Data truncated for column 'my_t2_fld1' at row 1
+ALTER TABLE t3 CHANGE `t3_fld1` `my_t3_fld1` MEDIUMTEXT;
+Warnings:
+Warning 1265 Data truncated for column 'my_t3_fld1' at row 1
+SELECT LENGTH(my_t1_fld1) FROM t1;
+LENGTH(my_t1_fld1)
+255
+SELECT LENGTH(my_t2_fld1) FROM t2;
+LENGTH(my_t2_fld1)
+65535
+SELECT LENGTH(my_t3_fld1) FROM t3;
+LENGTH(my_t3_fld1)
+16777215
+disconnect con1;
+connection default;
+DROP TABLE t1, t2, t3;
+SET SQL_MODE=default;
+SET GLOBAL max_allowed_packet=default;
CREATE TABLE t1 (
id INT(11) NOT NULL,
x_param INT(11) DEFAULT NULL,
diff --git a/mysql-test/main/alter_table.test b/mysql-test/main/alter_table.test
index 5c218c26923..dfa8e2e148b 100644
--- a/mysql-test/main/alter_table.test
+++ b/mysql-test/main/alter_table.test
@@ -1292,6 +1292,56 @@ MODIFY COLUMN `consultant_id` BIGINT;
SHOW CREATE TABLE t1;
DROP TABLE t1;
+--echo #
+--echo # BUG#27788685: NO WARNING WHEN TRUNCATING A STRING WITH DATA LOSS
+--echo #
+
+SET GLOBAL max_allowed_packet=17825792;
+
+--connect(con1, localhost, root,,)
+CREATE TABLE t1 (t1_fld1 TEXT);
+CREATE TABLE t2 (t2_fld1 MEDIUMTEXT);
+CREATE TABLE t3 (t3_fld1 LONGTEXT);
+
+INSERT INTO t1 VALUES (REPEAT('a',300));
+INSERT INTO t2 VALUES (REPEAT('b',65680));
+INSERT INTO t3 VALUES (REPEAT('c',16777300));
+
+SELECT LENGTH(t1_fld1) FROM t1;
+SELECT LENGTH(t2_fld1) FROM t2;
+SELECT LENGTH(t3_fld1) FROM t3;
+
+--echo # With strict mode
+SET SQL_MODE='STRICT_ALL_TABLES';
+
+--error ER_DATA_TOO_LONG
+ALTER TABLE t1 CHANGE `t1_fld1` `my_t1_fld1` TINYTEXT;
+--error ER_DATA_TOO_LONG
+ALTER TABLE t2 CHANGE `t2_fld1` `my_t2_fld1` TEXT;
+--error ER_DATA_TOO_LONG
+ALTER TABLE t3 CHANGE `t3_fld1` `my_t3_fld1` MEDIUMTEXT;
+
+--echo # With non-strict mode
+SET SQL_MODE='';
+
+ALTER TABLE t1 CHANGE `t1_fld1` `my_t1_fld1` TINYTEXT;
+ALTER TABLE t2 CHANGE `t2_fld1` `my_t2_fld1` TEXT;
+ALTER TABLE t3 CHANGE `t3_fld1` `my_t3_fld1` MEDIUMTEXT;
+
+SELECT LENGTH(my_t1_fld1) FROM t1;
+SELECT LENGTH(my_t2_fld1) FROM t2;
+SELECT LENGTH(my_t3_fld1) FROM t3;
+
+# Cleanup
+--disconnect con1
+--source include/wait_until_disconnected.inc
+
+--connection default
+DROP TABLE t1, t2, t3;
+
+SET SQL_MODE=default;
+SET GLOBAL max_allowed_packet=default;
+
#
# Test of ALTER TABLE IF [NOT] EXISTS
#
diff --git a/mysql-test/main/create_or_replace.result b/mysql-test/main/create_or_replace.result
index ab8e8f27f4a..54bec5c3f9d 100644
--- a/mysql-test/main/create_or_replace.result
+++ b/mysql-test/main/create_or_replace.result
@@ -503,12 +503,12 @@ CREATE TABLE t3(a INT);
LOCK TABLE t2 WRITE;
SELECT * FROM t2;
a
-CREATE OR REPLACE TEMPORARY TABLE t1(a INT) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
-ERROR HY000: CREATE TEMPORARY TABLE is not allowed with ROW_FORMAT=COMPRESSED or KEY_BLOCK_SIZE.
+CREATE OR REPLACE TEMPORARY TABLE t1(c INT DEFAULT '');
+ERROR 42000: Invalid default value for 'c'
SELECT * FROM t3;
ERROR HY000: Table 't3' was not locked with LOCK TABLES
-CREATE OR REPLACE TEMPORARY TABLE t2(a INT) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
-ERROR HY000: CREATE TEMPORARY TABLE is not allowed with ROW_FORMAT=COMPRESSED or KEY_BLOCK_SIZE.
+CREATE OR REPLACE TEMPORARY TABLE t2(c INT DEFAULT '');
+ERROR 42000: Invalid default value for 'c'
SELECT * FROM t3;
ERROR HY000: Table 't3' was not locked with LOCK TABLES
UNLOCK TABLES;
diff --git a/mysql-test/main/create_or_replace.test b/mysql-test/main/create_or_replace.test
index 9f718ab88ce..4b167663742 100644
--- a/mysql-test/main/create_or_replace.test
+++ b/mysql-test/main/create_or_replace.test
@@ -453,14 +453,14 @@ CREATE TABLE t3(a INT);
LOCK TABLE t2 WRITE;
SELECT * FROM t2;
# drops t2
---error ER_UNSUPPORT_COMPRESSED_TEMPORARY_TABLE
-CREATE OR REPLACE TEMPORARY TABLE t1(a INT) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
+--error ER_INVALID_DEFAULT
+CREATE OR REPLACE TEMPORARY TABLE t1(c INT DEFAULT '');
# make sure we didn't leave locked tables mode
--error ER_TABLE_NOT_LOCKED
SELECT * FROM t3;
# drops t1
---error ER_UNSUPPORT_COMPRESSED_TEMPORARY_TABLE
-CREATE OR REPLACE TEMPORARY TABLE t2(a INT) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
+--error ER_INVALID_DEFAULT
+CREATE OR REPLACE TEMPORARY TABLE t2(c INT DEFAULT '');
# make sure we didn't leave locked tables mode
--error ER_TABLE_NOT_LOCKED
SELECT * FROM t3;
diff --git a/mysql-test/main/ctype_latin1.result b/mysql-test/main/ctype_latin1.result
index 43a84275629..233fd85a2c4 100644
--- a/mysql-test/main/ctype_latin1.result
+++ b/mysql-test/main/ctype_latin1.result
@@ -8046,6 +8046,15 @@ ABCDEFGHI-ABCDEFGHI
DROP TABLE t1;
SET optimizer_switch=@save_optimizer_switch;
#
+# MDEV-17298 ASAN unknown-crash / READ of size 1 in my_strntoul_8bit upon INSERT .. SELECT
+#
+SET NAMES latin1;
+CREATE TABLE t1 (a CHAR);
+CREATE TABLE t2 (b ENUM('foo','bar'));
+INSERT INTO t1 VALUES ('1');
+INSERT INTO t2 SELECT * FROM t1;
+DROP TABLE t1, t2;
+#
# End of 10.0 tests
#
#
diff --git a/mysql-test/main/ctype_latin1.test b/mysql-test/main/ctype_latin1.test
index 61df80e2186..a556c86c016 100644
--- a/mysql-test/main/ctype_latin1.test
+++ b/mysql-test/main/ctype_latin1.test
@@ -267,6 +267,18 @@ SET NAMES latin1;
--echo #
+--echo # MDEV-17298 ASAN unknown-crash / READ of size 1 in my_strntoul_8bit upon INSERT .. SELECT
+--echo #
+
+SET NAMES latin1;
+CREATE TABLE t1 (a CHAR);
+CREATE TABLE t2 (b ENUM('foo','bar'));
+INSERT INTO t1 VALUES ('1');
+INSERT INTO t2 SELECT * FROM t1;
+DROP TABLE t1, t2;
+
+
+--echo #
--echo # End of 10.0 tests
--echo #
diff --git a/mysql-test/main/ctype_uca.result b/mysql-test/main/ctype_uca.result
index 725e744c44e..88fba0b3973 100644
--- a/mysql-test/main/ctype_uca.result
+++ b/mysql-test/main/ctype_uca.result
@@ -13940,6 +13940,27 @@ Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = 'oe' and `test`.`t1`.`a` = 'oe'
DROP TABLE t1;
#
+# MDEV-17064 LIKE function has error behavior on the fields in which the collation is xxx_unicode_xx
+#
+CREATE TABLE t1 (name VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci);
+INSERT INTO t1 VALUES ('radio! test');
+SELECT * FROM t1 WHERE name LIKE '%!!%' ESCAPE '!';
+name
+radio! test
+ALTER TABLE t1 CHANGE COLUMN name name VARCHAR(20) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
+SELECT * FROM t1 WHERE name LIKE '%!!%' ESCAPE '!';
+name
+radio! test
+DROP TABLE t1;
+CREATE TABLE t1 (name VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci);
+INSERT INTO t1 VALUES ('radio! test');
+SELECT name LIKE '%!!%' ESCAPE '!' AS c1,
+name LIKE '%!!%' COLLATE utf8_general_ci ESCAPE '!' AS c2
+FROM t1;
+c1 c2
+1 1
+DROP TABLE t1;
+#
# End of MariaDB-10.0 tests
#
#
diff --git a/mysql-test/main/ctype_uca.test b/mysql-test/main/ctype_uca.test
index 15a945fde6d..82be0305f07 100644
--- a/mysql-test/main/ctype_uca.test
+++ b/mysql-test/main/ctype_uca.test
@@ -619,6 +619,24 @@ EXPLAIN EXTENDED SELECT * FROM t1 WHERE a='oe' COLLATE utf8_german2_ci AND a='oe
DROP TABLE t1;
--echo #
+--echo # MDEV-17064 LIKE function has error behavior on the fields in which the collation is xxx_unicode_xx
+--echo #
+
+CREATE TABLE t1 (name VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci);
+INSERT INTO t1 VALUES ('radio! test');
+SELECT * FROM t1 WHERE name LIKE '%!!%' ESCAPE '!';
+ALTER TABLE t1 CHANGE COLUMN name name VARCHAR(20) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
+SELECT * FROM t1 WHERE name LIKE '%!!%' ESCAPE '!';
+DROP TABLE t1;
+
+CREATE TABLE t1 (name VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci);
+INSERT INTO t1 VALUES ('radio! test');
+SELECT name LIKE '%!!%' ESCAPE '!' AS c1,
+ name LIKE '%!!%' COLLATE utf8_general_ci ESCAPE '!' AS c2
+FROM t1;
+DROP TABLE t1;
+
+--echo #
--echo # End of MariaDB-10.0 tests
--echo #
diff --git a/mysql-test/main/derived_cond_pushdown.result b/mysql-test/main/derived_cond_pushdown.result
index 4d160c3d31d..4f9de9670f8 100644
--- a/mysql-test/main/derived_cond_pushdown.result
+++ b/mysql-test/main/derived_cond_pushdown.result
@@ -1,23 +1,23 @@
create table t1 (a int, b int, c int);
create table t2 (a int, b int, c int, d decimal);
-insert into t1 values
+insert into t1 values
(1,21,345), (1,33,7), (8,33,114), (1,21,500), (1,19,107), (5,14,787),
(8,33,123), (9,10,211), (5,16,207), (1,33,988), (5,27,132), (1,21,104),
(6,20,309), (6,20,315), (1,21,101), (8,33,404), (9,10,800), (1,21,123),
(7,11,708), (6,20,214);
insert into t2 values
-(2,3,207,207.0000), (1,21,909,12.0000), (7,13,312,406.0000),
+(2,3,207,207.0000), (1,21,909,12.0000), (7,13,312,406.0000),
(8,64,248,107.0000), (6,20,315,279.3333), (1,19,203,107.0000),
(8,80,800,314.0000), (3,12,231,190.0000), (6,23,303,909.0000);
Warnings:
Note 1265 Data truncated for column 'd' at row 5
create table t1_double(a int, b double, c double);
-insert into t1_double values
+insert into t1_double values
(1,23.4,14.3333), (1,12.5,18.9), (3,12.5,18.9),
(4,33.4,14.3333), (4,14.3333,13.65), (5,17.89,7.22),
(6,33.4,14.3), (10,33.4,13.65), (11,33.4,13.65);
create table t2_double(a int, b double, c double);
-insert into t2_double values
+insert into t2_double values
(1,22.4,14.3333), (1,12.5,18.9), (2,22.4,18.9),
(4,33.4,14.3333), (5,22.4,13.65), (7,17.89,18.9),
(6,33.4,14.3333), (10,31.4,13.65), (12,33.4,13.65);
@@ -41,22 +41,22 @@ insert into t2_decimal values
(2,1,13),(2,2,11),(3,3,16),
(1,3,22),(1,3,14),(2,2,15),
(2,1,43),(2,3,11),(2,3,16);
-create view v1 as select a, b, max(c) as max_c, avg(c) as avg_c from t1
+create view v1 as select a, b, max(c) as max_c, avg(c) as avg_c from t1
group by a,b having max_c < 707;
-create view v2 as select a, b, max(c) as max_c, avg(c) as avg_c from t1
+create view v2 as select a, b, max(c) as max_c, avg(c) as avg_c from t1
where t1.a>5 group by a,b having max_c < 707;
create view v3 as select a, b, min(c) as min_c from t1
where t1.a<10 group by a,b having min_c > 109;
create view v4 as
select a, b, min(max_c) as min_c from v1
where (v1.a<15) group by a,b;
-create view v_union as
+create view v_union as
select a, b, min(c) as c from t1
where t1.a<10 group by a,b having c > 109
union
select a, b, max(c) as c from t1
where t1.b>10 group by a,b having c < 300;
-create view v2_union as
+create view v2_union as
select a, b, min(c) as c from t1
where t1.a<10 group by a,b having c > 109
union
@@ -65,13 +65,13 @@ where t1.b>10 group by a,b having c < 300
union
select a, b, avg(c) as c from t1
where t1.c>300 group by a,b having c < 707;
-create view v3_union as
+create view v3_union as
select a, b, (a+1) as c from t1
where t1.a<10
union
select a, b, c from t1
where t1.b>10 and t1.c>100;
-create view v4_union as
+create view v4_union as
select a, b, max(c)-100 as c from t1
where t1.a<10 group by a,b having c > 109
union
@@ -80,13 +80,13 @@ where t1.b>10;
create view v_double as
select a, avg(a/4) as avg_a, b, c from t1_double
where (b>12.2) group by b,c having (avg_a<22.333);
-create view v_char as
-select a, b, max(c) as max_c from t1_char
+create view v_char as
+select a, b, max(c) as max_c from t1_char
group by a,b having max_c < 9;
create view v_decimal as
select a, b, avg(c) as avg_c from t1_decimal
group by a,b having (avg_c>12);
-# conjunctive subformula : pushing into HAVING
+# conjunctive subformula : pushing into HAVING
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (v1.max_c>214) and (t2.a>v1.a);
a b max_c avg_c a b c d
1 21 500 234.6000 2 3 207 207
@@ -161,7 +161,7 @@ EXPLAIN
}
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
-group by a,b having max_c < 707) v1,
+group by a,b having max_c < 707) v1,
t2 where (v1.a=t2.a) and (v1.max_c>300);
a b max_c avg_c a b c d
1 21 500 234.6000 1 21 909 12
@@ -172,7 +172,7 @@ a b max_c avg_c a b c d
6 20 315 279.3333 6 23 303 909
select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
-group by a,b having max_c < 707) v1,
+group by a,b having max_c < 707) v1,
t2 where (v1.a=t2.a) and (v1.max_c>300);
a b max_c avg_c a b c d
1 21 500 234.6000 1 21 909 12
@@ -183,7 +183,7 @@ a b max_c avg_c a b c d
6 20 315 279.3333 6 23 303 909
explain select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
-group by a,b having max_c < 707) v1,
+group by a,b having max_c < 707) v1,
t2 where (v1.a=t2.a) and (v1.max_c>300);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
@@ -191,7 +191,7 @@ id select_type table type possible_keys key key_len ref rows Extra
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
explain format=json select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
-group by a,b having max_c < 707) v1,
+group by a,b having max_c < 707) v1,
t2 where (v1.a=t2.a) and (v1.max_c>300);
EXPLAIN
{
@@ -235,8 +235,8 @@ EXPLAIN
}
}
}
-# extracted or formula : pushing into HAVING
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
+# extracted or formula : pushing into HAVING
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));
a b max_c avg_c a b c d
1 21 500 234.6000 2 3 207 207
@@ -250,7 +250,7 @@ a b max_c avg_c a b c d
5 27 132 132.0000 1 21 909 12
5 27 132 132.0000 1 19 203 107
5 27 132 132.0000 3 12 231 190
-select * from v1,t2 where
+select * from v1,t2 where
((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));
a b max_c avg_c a b c d
1 21 500 234.6000 2 3 207 207
@@ -264,13 +264,13 @@ a b max_c avg_c a b c d
5 27 132 132.0000 1 21 909 12
5 27 132 132.0000 1 19 203 107
5 27 132 132.0000 3 12 231 190
-explain select * from v1,t2 where
+explain select * from v1,t2 where
((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
-explain format=json select * from v1,t2 where
+explain format=json select * from v1,t2 where
((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));
EXPLAIN
{
@@ -315,7 +315,7 @@ EXPLAIN
}
}
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
-((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
+((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));
a b max_c avg_c a b c d
1 19 107 107.0000 1 21 909 12
@@ -323,7 +323,7 @@ a b max_c avg_c a b c d
1 21 500 234.6000 1 21 909 12
6 20 315 279.3333 6 20 315 279
select * from v1,t2 where
-((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
+((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));
a b max_c avg_c a b c d
1 19 107 107.0000 1 21 909 12
@@ -331,14 +331,14 @@ a b max_c avg_c a b c d
1 21 500 234.6000 1 21 909 12
6 20 315 279.3333 6 20 315 279
explain select * from v1,t2 where
-((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
+((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
explain format=json select * from v1,t2 where
-((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
+((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));
EXPLAIN
{
@@ -508,7 +508,7 @@ EXPLAIN
}
}
# extracted or formula : pushing into WHERE
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
((v1.a>7) and (t2.c<v1.max_c)) or ((v1.a<2) and (t2.b<v1.b));
a b max_c avg_c a b c d
1 19 107 107.0000 2 3 207 207
@@ -526,7 +526,7 @@ a b max_c avg_c a b c d
8 33 404 213.6667 1 19 203 107
8 33 404 213.6667 3 12 231 190
8 33 404 213.6667 6 23 303 909
-select * from v1,t2 where
+select * from v1,t2 where
((v1.a>7) and (t2.c<v1.max_c)) or ((v1.a<2) and (t2.b<v1.b));
a b max_c avg_c a b c d
1 19 107 107.0000 2 3 207 207
@@ -544,13 +544,13 @@ a b max_c avg_c a b c d
8 33 404 213.6667 1 19 203 107
8 33 404 213.6667 3 12 231 190
8 33 404 213.6667 6 23 303 909
-explain select * from v1,t2 where
+explain select * from v1,t2 where
((v1.a>7) and (t2.c<v1.max_c)) or ((v1.a<2) and (t2.b<v1.b));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
-explain format=json select * from v1,t2 where
+explain format=json select * from v1,t2 where
((v1.a>7) and (t2.c<v1.max_c)) or ((v1.a<2) and (t2.b<v1.b));
EXPLAIN
{
@@ -595,7 +595,7 @@ EXPLAIN
}
}
}
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v2,t2 where
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v2,t2 where
((v2.a>7) and (t2.c<v2.max_c)) or ((v2.a>5) and (t2.b<v2.b));
a b max_c avg_c a b c d
6 20 315 279.3333 2 3 207 207
@@ -610,7 +610,7 @@ a b max_c avg_c a b c d
8 33 404 213.6667 1 19 203 107
8 33 404 213.6667 3 12 231 190
8 33 404 213.6667 6 23 303 909
-select * from v2,t2 where
+select * from v2,t2 where
((v2.a>7) and (t2.c<v2.max_c)) or ((v2.a>5) and (t2.b<v2.b));
a b max_c avg_c a b c d
6 20 315 279.3333 2 3 207 207
@@ -625,13 +625,13 @@ a b max_c avg_c a b c d
8 33 404 213.6667 1 19 203 107
8 33 404 213.6667 3 12 231 190
8 33 404 213.6667 6 23 303 909
-explain select * from v2,t2 where
+explain select * from v2,t2 where
((v2.a>7) and (t2.c<v2.max_c)) or ((v2.a>5) and (t2.b<v2.b));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
-explain format=json select * from v2,t2 where
+explain format=json select * from v2,t2 where
((v2.a>7) and (t2.c<v2.max_c)) or ((v2.a>5) and (t2.b<v2.b));
EXPLAIN
{
@@ -676,29 +676,29 @@ EXPLAIN
}
}
}
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
-((v1.a>4) and (v1.b>t2.b) and (v1.max_c=t2.d)) or
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
+((v1.a>4) and (v1.b>t2.b) and (v1.max_c=t2.d)) or
((v1.a<2) and (v1.max_c<t2.c) and (v1.max_c=t2.d));
a b max_c avg_c a b c d
1 19 107 107.0000 8 64 248 107
1 19 107 107.0000 1 19 203 107
5 16 207 207.0000 2 3 207 207
-select * from v1,t2 where
-((v1.a>4) and (v1.b>t2.b) and (v1.max_c=t2.d)) or
+select * from v1,t2 where
+((v1.a>4) and (v1.b>t2.b) and (v1.max_c=t2.d)) or
((v1.a<2) and (v1.max_c<t2.c) and (v1.max_c=t2.d));
a b max_c avg_c a b c d
1 19 107 107.0000 8 64 248 107
1 19 107 107.0000 1 19 203 107
5 16 207 207.0000 2 3 207 207
-explain select * from v1,t2 where
-((v1.a>4) and (v1.b>t2.b) and (v1.max_c=t2.d)) or
+explain select * from v1,t2 where
+((v1.a>4) and (v1.b>t2.b) and (v1.max_c=t2.d)) or
((v1.a<2) and (v1.max_c<t2.c) and (v1.max_c=t2.d));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
-explain format=json select * from v1,t2 where
-((v1.a>4) and (v1.b>t2.b) and (v1.max_c=t2.d)) or
+explain format=json select * from v1,t2 where
+((v1.a>4) and (v1.b>t2.b) and (v1.max_c=t2.d)) or
((v1.a<2) and (v1.max_c<t2.c) and (v1.max_c=t2.d));
EXPLAIN
{
@@ -934,8 +934,8 @@ EXPLAIN
}
}
# extracted or formula : pushing into HAVING and WHERE
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
-((v1.a>7) and (v1.max_c>300) and (t2.c<v1.max_c)) or
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
+((v1.a>7) and (v1.max_c>300) and (t2.c<v1.max_c)) or
((v1.a<4) and (v1.max_c<500) and (t2.b<v1.b));
a b max_c avg_c a b c d
1 19 107 107.0000 2 3 207 207
@@ -948,8 +948,8 @@ a b max_c avg_c a b c d
8 33 404 213.6667 1 19 203 107
8 33 404 213.6667 3 12 231 190
8 33 404 213.6667 6 23 303 909
-select * from v1,t2 where
-((v1.a>7) and (v1.max_c>300) and (t2.c<v1.max_c)) or
+select * from v1,t2 where
+((v1.a>7) and (v1.max_c>300) and (t2.c<v1.max_c)) or
((v1.a<4) and (v1.max_c<500) and (t2.b<v1.b));
a b max_c avg_c a b c d
1 19 107 107.0000 2 3 207 207
@@ -962,15 +962,15 @@ a b max_c avg_c a b c d
8 33 404 213.6667 1 19 203 107
8 33 404 213.6667 3 12 231 190
8 33 404 213.6667 6 23 303 909
-explain select * from v1,t2 where
-((v1.a>7) and (v1.max_c>300) and (t2.c<v1.max_c)) or
+explain select * from v1,t2 where
+((v1.a>7) and (v1.max_c>300) and (t2.c<v1.max_c)) or
((v1.a<4) and (v1.max_c<500) and (t2.b<v1.b));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
-explain format=json select * from v1,t2 where
-((v1.a>7) and (v1.max_c>300) and (t2.c<v1.max_c)) or
+explain format=json select * from v1,t2 where
+((v1.a>7) and (v1.max_c>300) and (t2.c<v1.max_c)) or
((v1.a<4) and (v1.max_c<500) and (t2.b<v1.b));
EXPLAIN
{
@@ -1104,8 +1104,8 @@ EXPLAIN
}
}
}
-# extracted or formulas : pushing into WHERE and HAVING
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
+# extracted or formulas : pushing into WHERE and HAVING
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
((v1.a<2) and (v1.max_c>120) and (v1.b=t2.b)) or (v1.a>7);
a b max_c avg_c a b c d
1 21 500 234.6000 1 21 909 12
@@ -1118,7 +1118,7 @@ a b max_c avg_c a b c d
8 33 404 213.6667 8 80 800 314
8 33 404 213.6667 3 12 231 190
8 33 404 213.6667 6 23 303 909
-select * from v1,t2 where
+select * from v1,t2 where
((v1.a<2) and (v1.max_c>120) and (v1.b=t2.b)) or (v1.a>7);
a b max_c avg_c a b c d
1 21 500 234.6000 1 21 909 12
@@ -1131,13 +1131,13 @@ a b max_c avg_c a b c d
8 33 404 213.6667 8 80 800 314
8 33 404 213.6667 3 12 231 190
8 33 404 213.6667 6 23 303 909
-explain select * from v1,t2 where
+explain select * from v1,t2 where
((v1.a<2) and (v1.max_c>120) and (v1.b=t2.b)) or (v1.a>7);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
-explain format=json select * from v1,t2 where
+explain format=json select * from v1,t2 where
((v1.a<2) and (v1.max_c>120) and (v1.b=t2.b)) or (v1.a>7);
EXPLAIN
{
@@ -1250,7 +1250,7 @@ EXPLAIN
}
}
# prepare of a query containing extracted or formula
-prepare stmt from "select * from v1,t2 where
+prepare stmt from "select * from v1,t2 where
((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));";
execute stmt;
a b max_c avg_c a b c d
@@ -1279,8 +1279,8 @@ a b max_c avg_c a b c d
5 27 132 132.0000 1 19 203 107
5 27 132 132.0000 3 12 231 190
deallocate prepare stmt;
-prepare stmt from
-"explain format=json select * from v1,t2 where
+prepare stmt from
+"explain format=json select * from v1,t2 where
((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));";
execute stmt;
EXPLAIN
@@ -1652,7 +1652,7 @@ EXPLAIN
}
}
}
-# extracted and formula : pushing into WHERE
+# extracted and formula : pushing into WHERE
# pushing equalities
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (v1.a=v1.b) and (v1.a=t2.a) and (v1.a=3);
a b max_c avg_c a b c d
@@ -1752,23 +1752,23 @@ EXPLAIN
}
}
}
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_char as v,t2_char as t where
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_char as v,t2_char as t where
(v.a='c') and (v.b<'Hermes') and ((v.b=t.b) or (v.max_c>20));
a b max_c a b c
c Harry 4 d Harry 1
c Harry 4 b Harry 4
-select * from v_char as v,t2_char as t where
+select * from v_char as v,t2_char as t where
(v.a='c') and (v.b<'Hermes') and ((v.b=t.b) or (v.max_c>20));
a b max_c a b c
c Harry 4 d Harry 1
c Harry 4 b Harry 4
-explain select * from v_char as v,t2_char as t where
+explain select * from v_char as v,t2_char as t where
(v.a='c') and (v.b<'Hermes') and ((v.b=t.b) or (v.max_c>20));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 12 Using where
1 PRIMARY t ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1_char ALL NULL NULL NULL NULL 12 Using where; Using temporary; Using filesort
-explain format=json select * from v_char as v,t2_char as t where
+explain format=json select * from v_char as v,t2_char as t where
(v.a='c') and (v.b<'Hermes') and ((v.b=t.b) or (v.max_c>20));
EXPLAIN
{
@@ -1885,7 +1885,7 @@ EXPLAIN
}
}
}
-# extracted or formula : pushing into HAVING using equalities
+# extracted or formula : pushing into HAVING using equalities
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2
where ((t2.a<4) and (v1.a=t2.a)) or ((t2.c>150) and (v1.max_c=t2.c));
a b max_c avg_c a b c d
@@ -2014,24 +2014,24 @@ EXPLAIN
}
}
# conjunctive subformulas : pushing into WHERE and HAVING
-# pushing equalities
+# pushing equalities
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
-group by a,b having max_c < 707) v1,
+group by a,b having max_c < 707) v1,
t2 where (v1.a=8) and (v1.a=t2.a) and (v1.max_c=404);
a b max_c avg_c a b c d
8 33 404 213.6667 8 64 248 107
8 33 404 213.6667 8 80 800 314
select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
-group by a,b having max_c < 707) v1,
+group by a,b having max_c < 707) v1,
t2 where (v1.a=8) and (v1.a=t2.a) and (v1.max_c=404);
a b max_c avg_c a b c d
8 33 404 213.6667 8 64 248 107
8 33 404 213.6667 8 80 800 314
explain select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
-group by a,b having max_c < 707) v1,
+group by a,b having max_c < 707) v1,
t2 where (v1.a=8) and (v1.a=t2.a) and (v1.max_c=404);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
@@ -2039,7 +2039,7 @@ id select_type table type possible_keys key key_len ref rows Extra
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
explain format=json select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
-group by a,b having max_c < 707) v1,
+group by a,b having max_c < 707) v1,
t2 where (v1.a=8) and (v1.a=t2.a) and (v1.max_c=404);
EXPLAIN
{
@@ -2084,22 +2084,22 @@ EXPLAIN
}
}
}
-# conjunctive subformulas : pushing into WHERE and HAVING
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
+# conjunctive subformulas : pushing into WHERE and HAVING
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
(v1.a>3) and (v1.max_c>200) and (t2.b<v1.b) and (t2.d=v1.max_c);
a b max_c avg_c a b c d
5 16 207 207.0000 2 3 207 207
-select * from v1,t2 where
+select * from v1,t2 where
(v1.a>3) and (v1.max_c>200) and (t2.b<v1.b) and (t2.d=v1.max_c);
a b max_c avg_c a b c d
5 16 207 207.0000 2 3 207 207
-explain select * from v1,t2 where
+explain select * from v1,t2 where
(v1.a>3) and (v1.max_c>200) and (t2.b<v1.b) and (t2.d=v1.max_c);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
1 PRIMARY <derived2> ref key0 key0 5 test.t2.d 2 Using where
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
-explain format=json select * from v1,t2 where
+explain format=json select * from v1,t2 where
(v1.a>3) and (v1.max_c>200) and (t2.b<v1.b) and (t2.d=v1.max_c);
EXPLAIN
{
@@ -2205,7 +2205,7 @@ EXPLAIN
}
}
# conjunctive subformula : pushing into WHERE
-# extracted or formula : pushing into HAVING using equalities
+# extracted or formula : pushing into HAVING using equalities
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_double as v,t2_double as t where
(((v.a>0.2) or (v.b<17)) or (t.c>17)) and (t.c=v.c) and (v.c>18);
a avg_a b c a b c
@@ -2366,17 +2366,17 @@ EXPLAIN
}
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
-where t1.a>5 group by a,b having max_c < 707) v1,
+where t1.a>5 group by a,b having max_c < 707) v1,
t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.a=v1.b);
a b max_c avg_c a b c d
select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
-where t1.a>5 group by a,b having max_c < 707) v1,
+where t1.a>5 group by a,b having max_c < 707) v1,
t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.a=v1.b);
a b max_c avg_c a b c d
explain select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
-where t1.a>5 group by a,b having max_c < 707) v1,
+where t1.a>5 group by a,b having max_c < 707) v1,
t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.a=v1.b);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
@@ -2384,7 +2384,7 @@ id select_type table type possible_keys key key_len ref rows Extra
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
explain format=json select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
-where t1.a>5 group by a,b having max_c < 707) v1,
+where t1.a>5 group by a,b having max_c < 707) v1,
t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.a=v1.b);
EXPLAIN
{
@@ -2550,7 +2550,7 @@ EXPLAIN
}
}
}
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
(t2.a=v1.a) or (v1.b=t2.b) and ((v1.a=1) or (v1.a=6));
a b max_c avg_c a b c d
1 19 107 107.0000 1 21 909 12
@@ -2561,7 +2561,7 @@ a b max_c avg_c a b c d
6 20 315 279.3333 6 23 303 909
8 33 404 213.6667 8 64 248 107
8 33 404 213.6667 8 80 800 314
-select * from v1,t2 where
+select * from v1,t2 where
(t2.a=v1.a) or (v1.b=t2.b) and ((v1.a=1) or (v1.a=6));
a b max_c avg_c a b c d
1 19 107 107.0000 1 21 909 12
@@ -2572,13 +2572,13 @@ a b max_c avg_c a b c d
6 20 315 279.3333 6 23 303 909
8 33 404 213.6667 8 64 248 107
8 33 404 213.6667 8 80 800 314
-explain select * from v1,t2 where
+explain select * from v1,t2 where
(t2.a=v1.a) or (v1.b=t2.b) and ((v1.a=1) or (v1.a=6));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
-explain format=json select * from v1,t2 where
+explain format=json select * from v1,t2 where
(t2.a=v1.a) or (v1.b=t2.b) and ((v1.a=1) or (v1.a=6));
EXPLAIN
{
@@ -2716,7 +2716,7 @@ EXPLAIN
}
}
}
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
(t2.a<2) and (t2.c>900) and ((v1.a<t2.a) or (t2.a<11));
a b max_c avg_c a b c d
1 19 107 107.0000 1 21 909 12
@@ -2725,7 +2725,7 @@ a b max_c avg_c a b c d
5 27 132 132.0000 1 21 909 12
6 20 315 279.3333 1 21 909 12
8 33 404 213.6667 1 21 909 12
-select * from v1,t2 where
+select * from v1,t2 where
(t2.a<2) and (t2.c>900) and ((v1.a<t2.a) or (t2.a<11));
a b max_c avg_c a b c d
1 19 107 107.0000 1 21 909 12
@@ -2734,13 +2734,13 @@ a b max_c avg_c a b c d
5 27 132 132.0000 1 21 909 12
6 20 315 279.3333 1 21 909 12
8 33 404 213.6667 1 21 909 12
-explain select * from v1,t2 where
+explain select * from v1,t2 where
(t2.a<2) and (t2.c>900) and ((v1.a<t2.a) or (t2.a<11));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
-explain format=json select * from v1,t2 where
+explain format=json select * from v1,t2 where
(t2.a<2) and (t2.c>900) and ((v1.a<t2.a) or (t2.a<11));
EXPLAIN
{
@@ -2785,21 +2785,21 @@ EXPLAIN
}
}
# using several derived tables : nothing to push
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,v2,t2 where
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,v2,t2 where
(v1.a=v2.a) and (v1.a=t2.a) and (v2.b<50);
a b max_c avg_c a b max_c avg_c a b c d
8 33 404 213.6667 8 33 404 213.6667 8 64 248 107
6 20 315 279.3333 6 20 315 279.3333 6 20 315 279
8 33 404 213.6667 8 33 404 213.6667 8 80 800 314
6 20 315 279.3333 6 20 315 279.3333 6 23 303 909
-select * from v1,v2,t2 where
+select * from v1,v2,t2 where
(v1.a=v2.a) and (v1.a=t2.a) and (v2.b<50);
a b max_c avg_c a b max_c avg_c a b c d
8 33 404 213.6667 8 33 404 213.6667 8 64 248 107
6 20 315 279.3333 6 20 315 279.3333 6 20 315 279
8 33 404 213.6667 8 33 404 213.6667 8 80 800 314
6 20 315 279.3333 6 20 315 279.3333 6 23 303 909
-explain select * from v1,v2,t2 where
+explain select * from v1,v2,t2 where
(v1.a=v2.a) and (v1.a=t2.a) and (v2.b<50);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
@@ -2807,7 +2807,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived3> ref key0 key0 5 test.t2.a 2 Using where
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
-explain format=json select * from v1,v2,t2 where
+explain format=json select * from v1,v2,t2 where
(v1.a=v2.a) and (v1.a=t2.a) and (v2.b<50);
EXPLAIN
{
@@ -2880,7 +2880,7 @@ EXPLAIN
}
}
}
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,v2,t2 where
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,v2,t2 where
((v1.a=v2.a) or (v1.a=t2.a)) and (t2.b<50) and (v1.b=v2.b);
a b max_c avg_c a b max_c avg_c a b c d
6 20 315 279.3333 6 20 315 279.3333 2 3 207 207
@@ -2897,7 +2897,7 @@ a b max_c avg_c a b max_c avg_c a b c d
8 33 404 213.6667 8 33 404 213.6667 1 19 203 107
8 33 404 213.6667 8 33 404 213.6667 3 12 231 190
8 33 404 213.6667 8 33 404 213.6667 6 23 303 909
-select * from v1,v2,t2 where
+select * from v1,v2,t2 where
((v1.a=v2.a) or (v1.a=t2.a)) and (t2.b<50) and (v1.b=v2.b);
a b max_c avg_c a b max_c avg_c a b c d
6 20 315 279.3333 6 20 315 279.3333 2 3 207 207
@@ -2914,7 +2914,7 @@ a b max_c avg_c a b max_c avg_c a b c d
8 33 404 213.6667 8 33 404 213.6667 1 19 203 107
8 33 404 213.6667 8 33 404 213.6667 3 12 231 190
8 33 404 213.6667 8 33 404 213.6667 6 23 303 909
-explain select * from v1,v2,t2 where
+explain select * from v1,v2,t2 where
((v1.a=v2.a) or (v1.a=t2.a)) and (t2.b<50) and (v1.b=v2.b);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
@@ -2922,7 +2922,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived3> ref key0 key0 5 v1.b 2 Using where
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
-explain format=json select * from v1,v2,t2 where
+explain format=json select * from v1,v2,t2 where
((v1.a=v2.a) or (v1.a=t2.a)) and (t2.b<50) and (v1.b=v2.b);
EXPLAIN
{
@@ -2996,21 +2996,21 @@ EXPLAIN
}
}
}
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,v2,t2 where
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,v2,t2 where
((v1.a=v2.a) and (v1.a=t2.a)) or ((v2.b>13) and (t2.c<115));
a b max_c avg_c a b max_c avg_c a b c d
6 20 315 279.3333 6 20 315 279.3333 6 20 315 279
6 20 315 279.3333 6 20 315 279.3333 6 23 303 909
8 33 404 213.6667 8 33 404 213.6667 8 64 248 107
8 33 404 213.6667 8 33 404 213.6667 8 80 800 314
-select * from v1,v2,t2 where
+select * from v1,v2,t2 where
((v1.a=v2.a) and (v1.a=t2.a)) or ((v2.b>13) and (t2.c<115));
a b max_c avg_c a b max_c avg_c a b c d
6 20 315 279.3333 6 20 315 279.3333 6 20 315 279
6 20 315 279.3333 6 20 315 279.3333 6 23 303 909
8 33 404 213.6667 8 33 404 213.6667 8 64 248 107
8 33 404 213.6667 8 33 404 213.6667 8 80 800 314
-explain select * from v1,v2,t2 where
+explain select * from v1,v2,t2 where
((v1.a=v2.a) and (v1.a=t2.a)) or ((v2.b>13) and (t2.c<115));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
@@ -3018,7 +3018,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (incremental, BNL join)
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
-explain format=json select * from v1,v2,t2 where
+explain format=json select * from v1,v2,t2 where
((v1.a=v2.a) and (v1.a=t2.a)) or ((v2.b>13) and (t2.c<115));
EXPLAIN
{
@@ -3094,22 +3094,22 @@ EXPLAIN
# using several derived tables : pushing in all tables
# conjunctive subformula : pushing into HAVING
# extracted or formula : pushing into WHERE
-# pushing equalities
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,v2,t2 where ((v1.a=v2.a) or (v1.a=t2.a)) and
+# pushing equalities
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,v2,t2 where ((v1.a=v2.a) or (v1.a=t2.a)) and
((v2.b<50) or (v2.b=19)) and (v1.max_c<300);
a b max_c avg_c a b max_c avg_c a b c d
1 19 107 107.0000 6 20 315 279.3333 1 21 909 12
1 19 107 107.0000 6 20 315 279.3333 1 19 203 107
1 19 107 107.0000 8 33 404 213.6667 1 21 909 12
1 19 107 107.0000 8 33 404 213.6667 1 19 203 107
-select * from v1,v2,t2 where ((v1.a=v2.a) or (v1.a=t2.a)) and
+select * from v1,v2,t2 where ((v1.a=v2.a) or (v1.a=t2.a)) and
((v2.b<50) or (v2.b=19)) and (v1.max_c<300);
a b max_c avg_c a b max_c avg_c a b c d
1 19 107 107.0000 6 20 315 279.3333 1 21 909 12
1 19 107 107.0000 6 20 315 279.3333 1 19 203 107
1 19 107 107.0000 8 33 404 213.6667 1 21 909 12
1 19 107 107.0000 8 33 404 213.6667 1 19 203 107
-explain select * from v1,v2,t2 where ((v1.a=v2.a) or (v1.a=t2.a)) and
+explain select * from v1,v2,t2 where ((v1.a=v2.a) or (v1.a=t2.a)) and
((v2.b<50) or (v2.b=19)) and (v1.max_c<300);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
@@ -3117,7 +3117,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (incremental, BNL join)
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
-explain format=json select * from v1,v2,t2 where ((v1.a=v2.a) or (v1.a=t2.a)) and
+explain format=json select * from v1,v2,t2 where ((v1.a=v2.a) or (v1.a=t2.a)) and
((v2.b<50) or (v2.b=19)) and (v1.max_c<300);
EXPLAIN
{
@@ -3194,13 +3194,13 @@ EXPLAIN
# using several derived tables : pushing only in one table
# conjunctive subformula : pushing into WHERE
# pushing equalities
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,v2,t2 where
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,v2,t2 where
(v1.a=t2.a) and (v1.a=v1.b) and (v1.a=v2.a) and (v2.max_c<300);
a b max_c avg_c a b max_c avg_c a b c d
-select * from v1,v2,t2 where
+select * from v1,v2,t2 where
(v1.a=t2.a) and (v1.a=v1.b) and (v1.a=v2.a) and (v2.max_c<300);
a b max_c avg_c a b max_c avg_c a b c d
-explain select * from v1,v2,t2 where
+explain select * from v1,v2,t2 where
(v1.a=t2.a) and (v1.a=v1.b) and (v1.a=v2.a) and (v2.max_c<300);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
@@ -3208,7 +3208,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived3> ref key0 key0 5 test.t2.a 2 Using where
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
-explain format=json select * from v1,v2,t2 where
+explain format=json select * from v1,v2,t2 where
(v1.a=t2.a) and (v1.a=v1.b) and (v1.a=v2.a) and (v2.max_c<300);
EXPLAIN
{
@@ -3373,7 +3373,7 @@ EXPLAIN
# extracted or formula : pushing into WHERE
# conjunctive subformula : pushing into WHERE using equalities
# pushing equalities
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_char as v,t2_char as t where
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_char as v,t2_char as t where
(v.a=t.a) and (t.a='b') and ((v.b='Vika') or (v.b='Ali'));
a b max_c a b c
b Vika 2 b Ivan 1
@@ -3381,7 +3381,7 @@ b Vika 2 b Ali 6
b Vika 2 b Hermes 3
b Vika 2 b Ivan 11
b Vika 2 b Harry 4
-select * from v_char as v,t2_char as t where
+select * from v_char as v,t2_char as t where
(v.a=t.a) and (t.a='b') and ((v.b='Vika') or (v.b='Ali'));
a b max_c a b c
b Vika 2 b Ivan 1
@@ -3389,13 +3389,13 @@ b Vika 2 b Ali 6
b Vika 2 b Hermes 3
b Vika 2 b Ivan 11
b Vika 2 b Harry 4
-explain select * from v_char as v,t2_char as t where
+explain select * from v_char as v,t2_char as t where
(v.a=t.a) and (t.a='b') and ((v.b='Vika') or (v.b='Ali'));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 12 Using where
1 PRIMARY t ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
2 DERIVED t1_char ALL NULL NULL NULL NULL 12 Using where; Using temporary; Using filesort
-explain format=json select * from v_char as v,t2_char as t where
+explain format=json select * from v_char as v,t2_char as t where
(v.a=t.a) and (t.a='b') and ((v.b='Vika') or (v.b='Ali'));
EXPLAIN
{
@@ -3442,10 +3442,10 @@ EXPLAIN
}
# using several derived tables : pushing in all tables
# extracted or formula : pushing into WHERE
-# conjunctive subformulas : pushing into HAVING
+# conjunctive subformulas : pushing into HAVING
# pushing equalities
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,v2,v3,t2 where
-((v1.a=v2.a) or (v1.a=t2.a)) and ((v3.b<50) or (v3.b=33))
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,v2,v3,t2 where
+((v1.a=v2.a) or (v1.a=t2.a)) and ((v3.b<50) or (v3.b=33))
and (v1.max_c<500) and (v3.a=t2.a) and (v2.max_c>300);
a b max_c avg_c a b max_c avg_c a b min_c a b c d
6 20 315 279.3333 6 20 315 279.3333 7 11 708 7 13 312 406
@@ -3462,8 +3462,8 @@ a b max_c avg_c a b max_c avg_c a b min_c a b c d
8 33 404 213.6667 8 33 404 213.6667 6 20 214 6 20 315 279
8 33 404 213.6667 8 33 404 213.6667 8 33 114 8 80 800 314
8 33 404 213.6667 8 33 404 213.6667 6 20 214 6 23 303 909
-select * from v1,v2,v3,t2 where
-((v1.a=v2.a) or (v1.a=t2.a)) and ((v3.b<50) or (v3.b=33))
+select * from v1,v2,v3,t2 where
+((v1.a=v2.a) or (v1.a=t2.a)) and ((v3.b<50) or (v3.b=33))
and (v1.max_c<500) and (v3.a=t2.a) and (v2.max_c>300);
a b max_c avg_c a b max_c avg_c a b min_c a b c d
6 20 315 279.3333 6 20 315 279.3333 7 11 708 7 13 312 406
@@ -3480,8 +3480,8 @@ a b max_c avg_c a b max_c avg_c a b min_c a b c d
8 33 404 213.6667 8 33 404 213.6667 6 20 214 6 20 315 279
8 33 404 213.6667 8 33 404 213.6667 8 33 114 8 80 800 314
8 33 404 213.6667 8 33 404 213.6667 6 20 214 6 23 303 909
-explain select * from v1,v2,v3,t2 where
-((v1.a=v2.a) or (v1.a=t2.a)) and ((v3.b<50) or (v3.b=33))
+explain select * from v1,v2,v3,t2 where
+((v1.a=v2.a) or (v1.a=t2.a)) and ((v3.b<50) or (v3.b=33))
and (v1.max_c<500) and (v3.a=t2.a) and (v2.max_c>300);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
@@ -3491,8 +3491,8 @@ id select_type table type possible_keys key key_len ref rows Extra
4 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
-explain format=json select * from v1,v2,v3,t2 where
-((v1.a=v2.a) or (v1.a=t2.a)) and ((v3.b<50) or (v3.b=33))
+explain format=json select * from v1,v2,v3,t2 where
+((v1.a=v2.a) or (v1.a=t2.a)) and ((v3.b<50) or (v3.b=33))
and (v1.max_c<500) and (v3.a=t2.a) and (v2.max_c>300);
EXPLAIN
{
@@ -3598,7 +3598,7 @@ EXPLAIN
}
}
# using several derived tables : pushing in all tables
-# conjunctive subformulas : pushing into HAVING
+# conjunctive subformulas : pushing into HAVING
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
where t1.a>5 group by a,b having max_c < 707) v1,
@@ -3706,7 +3706,7 @@ EXPLAIN
}
# using several derived tables : pushing in all tables
# extracted or formulas : pushing into HAVING
-# conjunctive subformula : pushing into HAVING
+# conjunctive subformula : pushing into HAVING
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
where t1.a>5 group by a,b having max_c < 707) v1,
@@ -3875,10 +3875,10 @@ EXPLAIN
}
}
# extracted or formula : pushing into HAVING
-# conjunctive subformula : pushing into WHERE
+# conjunctive subformula : pushing into WHERE
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
-group by a,b having max_c < 707) v1,
+group by a,b having max_c < 707) v1,
t2 where ((v1.a=1) or (v1.max_c<300)) and (v1.b>25);
a b max_c avg_c a b c d
5 27 132 132.0000 2 3 207 207
@@ -3892,7 +3892,7 @@ a b max_c avg_c a b c d
5 27 132 132.0000 6 23 303 909
select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
-group by a,b having max_c < 707) v1,
+group by a,b having max_c < 707) v1,
t2 where ((v1.a=1) or (v1.max_c<300)) and (v1.b>25);
a b max_c avg_c a b c d
5 27 132 132.0000 2 3 207 207
@@ -3906,7 +3906,7 @@ a b max_c avg_c a b c d
5 27 132 132.0000 6 23 303 909
explain select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
-group by a,b having max_c < 707) v1,
+group by a,b having max_c < 707) v1,
t2 where ((v1.a=1) or (v1.max_c<300)) and (v1.b>25);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
@@ -3914,7 +3914,7 @@ id select_type table type possible_keys key key_len ref rows Extra
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
explain format=json select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
-group by a,b having max_c < 707) v1,
+group by a,b having max_c < 707) v1,
t2 where ((v1.a=1) or (v1.max_c<300)) and (v1.b>25);
EXPLAIN
{
@@ -3960,24 +3960,24 @@ EXPLAIN
}
}
# extracted and formula : pushing into WHERE
-# conjunctive subformula : pushing into HAVING
+# conjunctive subformula : pushing into HAVING
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
-where t1.a>5 group by a,b having max_c < 707) v1,
+where t1.a>5 group by a,b having max_c < 707) v1,
t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.b<30);
a b max_c avg_c a b c d
6 20 315 279.3333 6 20 315 279
6 20 315 279.3333 6 23 303 909
select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
-where t1.a>5 group by a,b having max_c < 707) v1,
+where t1.a>5 group by a,b having max_c < 707) v1,
t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.b<30);
a b max_c avg_c a b c d
6 20 315 279.3333 6 20 315 279
6 20 315 279.3333 6 23 303 909
explain select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
-where t1.a>5 group by a,b having max_c < 707) v1,
+where t1.a>5 group by a,b having max_c < 707) v1,
t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.b<30);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
@@ -3985,7 +3985,7 @@ id select_type table type possible_keys key key_len ref rows Extra
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
explain format=json select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
-where t1.a>5 group by a,b having max_c < 707) v1,
+where t1.a>5 group by a,b having max_c < 707) v1,
t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.b<30);
EXPLAIN
{
@@ -4156,11 +4156,11 @@ EXPLAIN
}
}
# using query with union
-# extracted and formula : pushing into WHERE
-# extracted or formula : pushing into HAVING
+# extracted and formula : pushing into WHERE
+# extracted or formula : pushing into HAVING
# pushing equalities
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (v1.a<5) and (v1.b=t2.b) and (v1.b=19)
-union
+union
select * from v1,t2 where ((v1.max_c>400) or (v1.avg_c>270)) and (v1.a<t2.a);
a b max_c avg_c a b c d
1 19 107 107.0000 1 19 203 107
@@ -4175,7 +4175,7 @@ a b max_c avg_c a b c d
6 20 315 279.3333 8 64 248 107
6 20 315 279.3333 8 80 800 314
select * from v1,t2 where (v1.a<5) and (v1.b=t2.b) and (v1.b=19)
-union
+union
select * from v1,t2 where ((v1.max_c>400) or (v1.avg_c>270)) and (v1.a<t2.a);
a b max_c avg_c a b c d
1 19 107 107.0000 1 19 203 107
@@ -4190,7 +4190,7 @@ a b max_c avg_c a b c d
6 20 315 279.3333 8 64 248 107
6 20 315 279.3333 8 80 800 314
explain select * from v1,t2 where (v1.a<5) and (v1.b=t2.b) and (v1.b=19)
-union
+union
select * from v1,t2 where ((v1.max_c>400) or (v1.avg_c>270)) and (v1.a<t2.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
@@ -4201,7 +4201,7 @@ id select_type table type possible_keys key key_len ref rows Extra
4 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL
explain format=json select * from v1,t2 where (v1.a<5) and (v1.b=t2.b) and (v1.b=19)
-union
+union
select * from v1,t2 where ((v1.max_c>400) or (v1.avg_c>270)) and (v1.a<t2.a);
EXPLAIN
{
@@ -4299,10 +4299,10 @@ EXPLAIN
}
}
# using query with union
-# extracted or formula : pushing into HAVING
+# extracted or formula : pushing into HAVING
# extracted or formula : pushing into WHERE
# pushing equalities
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
((t2.a=v1.a) or (v1.b=t2.b)) and ((v1.a=1) or (v1.a=6))
union
select * from v1,t2 where ((v1.a>3) and (v1.b>27)) or (v1.max_c>550);
@@ -4322,7 +4322,7 @@ a b max_c avg_c a b c d
8 33 404 213.6667 8 80 800 314
8 33 404 213.6667 3 12 231 190
8 33 404 213.6667 6 23 303 909
-select * from v1,t2 where
+select * from v1,t2 where
((t2.a=v1.a) or (v1.b=t2.b)) and ((v1.a=1) or (v1.a=6))
union
select * from v1,t2 where ((v1.a>3) and (v1.b>27)) or (v1.max_c>550);
@@ -4342,7 +4342,7 @@ a b max_c avg_c a b c d
8 33 404 213.6667 8 80 800 314
8 33 404 213.6667 3 12 231 190
8 33 404 213.6667 6 23 303 909
-explain select * from v1,t2 where
+explain select * from v1,t2 where
((t2.a=v1.a) or (v1.b=t2.b)) and ((v1.a=1) or (v1.a=6))
union
select * from v1,t2 where ((v1.a>3) and (v1.b>27)) or (v1.max_c>550);
@@ -4354,7 +4354,7 @@ id select_type table type possible_keys key key_len ref rows Extra
2 UNION <derived4> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
4 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL
-explain format=json select * from v1,t2 where
+explain format=json select * from v1,t2 where
((t2.a=v1.a) or (v1.b=t2.b)) and ((v1.a=1) or (v1.a=6))
union
select * from v1,t2 where ((v1.a>3) and (v1.b>27)) or (v1.max_c>550);
@@ -4454,10 +4454,10 @@ EXPLAIN
}
}
# using query with union
-# extracted or formula : pushing into HAVING
-# conjunctive subformulas : pushing into WHERE
+# extracted or formula : pushing into HAVING
+# conjunctive subformulas : pushing into WHERE
# pushing equalities
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
((v1.a=1) and (v1.a=t2.a)) and ((v1.max_c<500) or (v1.avg_c>500))
union
select * from v2,t2 where
@@ -4472,7 +4472,7 @@ a b max_c avg_c a b c d
6 20 315 279.3333 1 19 203 107
8 33 404 213.6667 1 21 909 12
8 33 404 213.6667 1 19 203 107
-select * from v1,t2 where
+select * from v1,t2 where
((v1.a=1) and (v1.a=t2.a)) and ((v1.max_c<500) or (v1.avg_c>500))
union
select * from v2,t2 where
@@ -4487,7 +4487,7 @@ a b max_c avg_c a b c d
6 20 315 279.3333 1 19 203 107
8 33 404 213.6667 1 21 909 12
8 33 404 213.6667 1 19 203 107
-explain select * from v1,t2 where
+explain select * from v1,t2 where
((v1.a=1) and (v1.a=t2.a)) and ((v1.max_c<500) or (v1.avg_c>500))
union
select * from v2,t2 where
@@ -4506,7 +4506,7 @@ id select_type table type possible_keys key key_len ref rows Extra
3 UNION <derived6> ref key0 key0 5 test.t2.c 2 Using where
6 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
NULL UNION RESULT <union1,2,3> ALL NULL NULL NULL NULL NULL
-explain format=json select * from v1,t2 where
+explain format=json select * from v1,t2 where
((v1.a=1) and (v1.a=t2.a)) and ((v1.max_c<500) or (v1.avg_c>500))
union
select * from v2,t2 where
@@ -4760,7 +4760,7 @@ EXPLAIN
}
# using derived table with union
# conjunctive subformula : pushing into WHERE
-# extracted or formula : pushing into HAVING
+# extracted or formula : pushing into HAVING
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_union,t2 where
((v_union.a<2) or (v_union.c>800)) and (v_union.b>12);
a b c a b c d
@@ -4963,27 +4963,27 @@ EXPLAIN
}
}
}
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_char as v,t2_char as t where
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_char as v,t2_char as t where
(v.a=t.a) and (v.b='Vika') and (v.max_c>2);
a b max_c a b c
c Vika 7 c Vinny 3
c Vika 7 c Inga 9
c Vika 7 c Ivan 2
c Vika 7 c Inga 2
-select * from v_char as v,t2_char as t where
+select * from v_char as v,t2_char as t where
(v.a=t.a) and (v.b='Vika') and (v.max_c>2);
a b max_c a b c
c Vika 7 c Vinny 3
c Vika 7 c Inga 9
c Vika 7 c Ivan 2
c Vika 7 c Inga 2
-explain select * from v_char as v,t2_char as t where
+explain select * from v_char as v,t2_char as t where
(v.a=t.a) and (v.b='Vika') and (v.max_c>2);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t ALL NULL NULL NULL NULL 12 Using where
1 PRIMARY <derived2> ref key0 key0 2 test.t.a 2 Using where
2 DERIVED t1_char ALL NULL NULL NULL NULL 12 Using where; Using temporary; Using filesort
-explain format=json select * from v_char as v,t2_char as t where
+explain format=json select * from v_char as v,t2_char as t where
(v.a=t.a) and (v.b='Vika') and (v.max_c>2);
EXPLAIN
{
@@ -5033,19 +5033,19 @@ EXPLAIN
# conjunctive subformula : pushing into WHERE using equalities
# pushing equalities
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_union,v1,t2 where
-(v_union.a=v1.a) and (v1.a=t2.a) and (t2.a=1)
+(v_union.a=v1.a) and (v1.a=t2.a) and (t2.a=1)
and ((v_union.c>800) or (v1.max_c>200));
a b c a b max_c avg_c a b c d
1 19 107 1 21 500 234.6000 1 21 909 12
1 19 107 1 21 500 234.6000 1 19 203 107
select * from v_union,v1,t2 where
-(v_union.a=v1.a) and (v1.a=t2.a) and (t2.a=1)
+(v_union.a=v1.a) and (v1.a=t2.a) and (t2.a=1)
and ((v_union.c>800) or (v1.max_c>200));
a b c a b max_c avg_c a b c d
1 19 107 1 21 500 234.6000 1 21 909 12
1 19 107 1 21 500 234.6000 1 19 203 107
explain select * from v_union,v1,t2 where
-(v_union.a=v1.a) and (v1.a=t2.a) and (t2.a=1)
+(v_union.a=v1.a) and (v1.a=t2.a) and (t2.a=1)
and ((v_union.c>800) or (v1.max_c>200));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
@@ -5056,7 +5056,7 @@ id select_type table type possible_keys key key_len ref rows Extra
3 UNION t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
explain format=json select * from v_union,v1,t2 where
-(v_union.a=v1.a) and (v1.a=t2.a) and (t2.a=1)
+(v_union.a=v1.a) and (v1.a=t2.a) and (t2.a=1)
and ((v_union.c>800) or (v1.max_c>200));
EXPLAIN
{
@@ -5161,11 +5161,11 @@ EXPLAIN
}
}
}
-# using derived table with union
-# extracted or formula : pushing into WHERE
+# using derived table with union
+# extracted or formula : pushing into WHERE
# conjunctive subformula : pushing into HAVING
# pushing equalities
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v2_union as v,t2 where
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v2_union as v,t2 where
((v.a=6) or (v.a=8)) and (v.c>200) and (v.a=t2.a);
a b c a b c d
8 33 404.0000 8 64 248 107
@@ -5174,7 +5174,7 @@ a b c a b c d
8 33 404.0000 8 80 800 314
6 20 312.0000 6 23 303 909
6 20 214.0000 6 23 303 909
-select * from v2_union as v,t2 where
+select * from v2_union as v,t2 where
((v.a=6) or (v.a=8)) and (v.c>200) and (v.a=t2.a);
a b c a b c d
8 33 404.0000 8 64 248 107
@@ -5183,7 +5183,7 @@ a b c a b c d
8 33 404.0000 8 80 800 314
6 20 312.0000 6 23 303 909
6 20 214.0000 6 23 303 909
-explain select * from v2_union as v,t2 where
+explain select * from v2_union as v,t2 where
((v.a=6) or (v.a=8)) and (v.c>200) and (v.a=t2.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
@@ -5192,7 +5192,7 @@ id select_type table type possible_keys key key_len ref rows Extra
3 UNION t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
4 UNION t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
NULL UNION RESULT <union2,3,4> ALL NULL NULL NULL NULL NULL
-explain format=json select * from v2_union as v,t2 where
+explain format=json select * from v2_union as v,t2 where
((v.a=6) or (v.a=8)) and (v.c>200) and (v.a=t2.a);
EXPLAIN
{
@@ -5543,21 +5543,21 @@ EXPLAIN
}
# using derived table with union of selects without aggregation
# extracted the whole condition: in WHERE of both selects
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v3_union as v,t2 where
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v3_union as v,t2 where
(v.a=t2.a) and ((v.b=19) or (v.b=21)) and ((v.c<3) or (v.c>600));
a b c a b c d
1 19 2 1 21 909 12
1 21 2 1 21 909 12
1 19 2 1 19 203 107
1 21 2 1 19 203 107
-select * from v3_union as v,t2 where
+select * from v3_union as v,t2 where
(v.a=t2.a) and ((v.b=19) or (v.b=21)) and ((v.c<3) or (v.c>600));
a b c a b c d
1 19 2 1 21 909 12
1 21 2 1 21 909 12
1 19 2 1 19 203 107
1 21 2 1 19 203 107
-explain select * from v3_union as v,t2 where
+explain select * from v3_union as v,t2 where
(v.a=t2.a) and ((v.b=19) or (v.b=21)) and ((v.c<3) or (v.c>600));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
@@ -5565,7 +5565,7 @@ id select_type table type possible_keys key key_len ref rows Extra
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where
3 UNION t1 ALL NULL NULL NULL NULL 20 Using where
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
-explain format=json select * from v3_union as v,t2 where
+explain format=json select * from v3_union as v,t2 where
(v.a=t2.a) and ((v.b=19) or (v.b=21)) and ((v.c<3) or (v.c>600));
EXPLAIN
{
@@ -5627,7 +5627,7 @@ EXPLAIN
}
}
}
-# using derived table with union of
+# using derived table with union of
# a select without aggregation and a select with aggregation
# extracted conjunctive predicate: pushing in WHERE of both selects
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v4_union as v,t2 where (v.a=t2.a) and (v.b<20);
@@ -5716,13 +5716,13 @@ EXPLAIN
}
}
}
-# using derived table with union of
+# using derived table with union of
# a select without aggregation and a select with aggregation
# extracted subformula: pushing in WHERE of one select
# extracted subformula: pushing in HAVING of the other select
# extracted sub-subformula: pushing in WHERE of the other select
# using an equality in all pushdowns
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v4_union as v,t2 where
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v4_union as v,t2 where
(v.a=t2.a) and ((t2.a<3) or (v.b<40)) and (v.c>500);
a b c a b c d
1 33 1088 1 21 909 12
@@ -5735,7 +5735,7 @@ a b c a b c d
1 21 600 1 19 203 107
1 33 888 1 19 203 107
8 33 504 8 80 800 314
-select * from v4_union as v,t2 where
+select * from v4_union as v,t2 where
(v.a=t2.a) and ((t2.a<3) or (v.b<40)) and (v.c>500);
a b c a b c d
1 33 1088 1 21 909 12
@@ -5748,7 +5748,7 @@ a b c a b c d
1 21 600 1 19 203 107
1 33 888 1 19 203 107
8 33 504 8 80 800 314
-explain select * from v4_union as v,t2 where
+explain select * from v4_union as v,t2 where
(v.a=t2.a) and ((t2.a<3) or (v.b<40)) and (v.c>500);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
@@ -5756,7 +5756,7 @@ id select_type table type possible_keys key key_len ref rows Extra
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
3 UNION t1 ALL NULL NULL NULL NULL 20 Using where
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
-explain format=json select * from v4_union as v,t2 where
+explain format=json select * from v4_union as v,t2 where
(v.a=t2.a) and ((t2.a<3) or (v.b<40)) and (v.c>500);
EXPLAIN
{
@@ -6773,7 +6773,7 @@ EXPLAIN
# using several derived tables : pushing in all tables
# extracted or formula : pushing into WHERE
# conjunctive subformula : pushing into WHERE
-# pushing equalities
+# pushing equalities
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v4,v2 where
(((v4.a<12) and (v4.b>13)) or (v4.a>10)) and
(v4.min_c=v2.max_c) and (v4.min_c>100);
@@ -6999,6 +6999,3412 @@ drop view v_union,v2_union,v3_union,v4_union;
drop view v_double,v_char,v_decimal;
drop table t1,t2,t1_double,t2_double,t1_char,t2_char,t1_decimal,t2_decimal;
#
+# MDEV-10782: condition extracted from a multiple equality
+# pushed into HAVING
+#
+CREATE TABLE t1 (i int);
+INSERT INTO t1 VALUES (1),(2);
+EXPLAIN EXTENDED
+SELECT *
+FROM ( SELECT * FROM ( SELECT MIN(i) as f FROM t1 ) sq1 ) AS sq2
+WHERE f = 8;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY <derived3> ALL NULL NULL NULL NULL 2 100.00 Using where
+3 DERIVED t1 ALL NULL NULL NULL NULL 2 100.00
+Warnings:
+Note 1003 /* select#1 */ select `sq1`.`f` AS `f` from (/* select#3 */ select min(`test`.`t1`.`i`) AS `f` from `test`.`t1` having `f` = 8) `sq1` where `sq1`.`f` = 8
+SELECT *
+FROM ( SELECT * FROM ( SELECT MIN(i) as f FROM t1 ) sq1 ) AS sq2
+WHERE f = 8;
+f
+SELECT *
+FROM ( SELECT * FROM ( SELECT MIN(i) as f FROM t1 ) sq1 ) AS sq2
+WHERE f = 1;
+f
+1
+DROP TABLE t1;
+#
+# MDEV-10783: pushdown into constant view
+#
+CREATE TABLE t1 (i int) ENGINE=MyISAM;
+CREATE VIEW v AS SELECT 5;
+SELECT * FROM t1 WHERE 1 IN ( SELECT * FROM v );
+i
+DROP VIEW v;
+DROP TABLE t1;
+#
+# MDEV-10785: second execution of a query with condition
+# pushed into view
+#
+CREATE TABLE t1 (i int);
+CREATE VIEW v1 AS SELECT i FROM t1 WHERE i < 5;
+CREATE FUNCTION f (in1 int) RETURNS int RETURN in1;
+CREATE VIEW v2 AS SELECT * FROM v1 GROUP BY i;
+PREPARE stmt FROM "SELECT * FROM v2 WHERE f(0) <> 2";
+EXECUTE stmt;
+i
+EXECUTE stmt;
+i
+DROP FUNCTION f;
+DROP VIEW v2,v1;
+DROP TABLE t1;
+#
+# MDEV-10884: condition pushdown into derived specified by
+# 1. unit with SELECT containing ORDER BY ... LIMIT
+# 2. unit containing global ORDER BY ... LIMIT
+#
+create table t1(a int);
+insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+select a from t1 order by a limit 5;
+a
+0
+1
+2
+3
+4
+set statement optimizer_switch='condition_pushdown_for_derived=off' for
+select * from (select a from t1 order by a limit 5) t where t.a not in (1,2,3);
+a
+0
+4
+set statement optimizer_switch='condition_pushdown_for_derived=on' for
+select * from (select a from t1 order by a limit 5) t where t.a not in (1,2,3);
+a
+0
+4
+select a from t1 where a < 4 union select a from t1 where a > 5
+order by a limit 5;
+a
+0
+1
+2
+3
+6
+set statement optimizer_switch='condition_pushdown_for_derived=off' for
+select * from
+(select a from t1 where a < 4 union select a from t1 where a > 5
+order by a limit 5) t where t.a not in (2,9);
+a
+0
+1
+3
+6
+set statement optimizer_switch='condition_pushdown_for_derived=on' for
+select * from
+(select a from t1 where a < 4 union select a from t1 where a > 5
+order by a limit 5) t where t.a not in (2,9);
+a
+0
+1
+3
+6
+drop table t1;
+#
+# MDEV-11072: pushdown of the condition obtained
+# after constant row substitution
+#
+CREATE TABLE t1 (a INT) ENGINE=MyISAM;
+CREATE TABLE t2 (b INT) ENGINE=MyISAM;
+CREATE OR REPLACE VIEW v2 AS SELECT * FROM t2;
+CREATE TABLE t3 (c INT) ENGINE=MyISAM;
+CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v3 AS SELECT * FROM t3;
+SELECT * FROM t1 WHERE a IN (
+SELECT b FROM v2 WHERE b < a OR b IN (
+SELECT c FROM v3 WHERE c = a
+)
+);
+a
+INSERT INTO t1 VALUES (2);
+INSERT INTO t2 VALUES (3), (2);
+INSERT INTO t3 VALUES (4), (1), (2), (7);
+SELECT * FROM t1 WHERE a IN (
+SELECT b FROM v2 WHERE b < a OR b IN (
+SELECT c FROM v3 WHERE c = a
+)
+);
+a
+2
+EXPLAIN FORMAT=JSON
+SELECT * FROM t1 WHERE a IN (
+SELECT b FROM v2 WHERE b < a OR b IN (
+SELECT c FROM v3 WHERE c = a
+)
+);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "const_condition": "0 or <in_optimizer>(2,<exists>(subquery#3))",
+ "table": {
+ "table_name": "t1",
+ "access_type": "system",
+ "rows": 1,
+ "filtered": 100
+ },
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "t2.b = 2",
+ "first_match": "t1"
+ },
+ "subqueries": [
+ {
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "table_name": "<derived5>",
+ "access_type": "index_subquery",
+ "possible_keys": ["key0"],
+ "key": "key0",
+ "key_length": "5",
+ "used_key_parts": ["c"],
+ "ref": ["func"],
+ "rows": 2,
+ "filtered": 100,
+ "materialized": {
+ "query_block": {
+ "select_id": 5,
+ "table": {
+ "table_name": "t3",
+ "access_type": "ALL",
+ "rows": 4,
+ "filtered": 100,
+ "attached_condition": "t3.c = 2"
+ }
+ }
+ }
+ }
+ }
+ }
+ ]
+ }
+}
+CREATE TABLE t4 (d INT, e INT) ENGINE=MyISAM;
+INSERT INTO t4 VALUES (1,10),(3,11),(2,10),(2,20),(3,21);
+CREATE OR REPLACE VIEW v4 AS
+SELECT d, sum(e) AS s FROM t4 GROUP BY d;
+set statement optimizer_switch='condition_pushdown_for_derived=off' for SELECT * FROM t1 WHERE a IN (
+SELECT b FROM v2 WHERE b < a OR b IN (
+SELECT d FROM v4 WHERE s > a
+)
+);
+a
+2
+SELECT * FROM t1 WHERE a IN (
+SELECT b FROM v2 WHERE b < a OR b IN (
+SELECT d FROM v4 WHERE s > a
+)
+);
+a
+2
+explain SELECT * FROM t1 WHERE a IN (
+SELECT b FROM v2 WHERE b < a OR b IN (
+SELECT d FROM v4 WHERE s > a
+)
+);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 system NULL NULL NULL NULL 1
+1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; FirstMatch(t1)
+3 DEPENDENT SUBQUERY <derived5> index_subquery key0 key0 5 func 2 Using where
+5 DERIVED t4 ALL NULL NULL NULL NULL 5 Using temporary; Using filesort
+explain format=json SELECT * FROM t1 WHERE a IN (
+SELECT b FROM v2 WHERE b < a OR b IN (
+SELECT d FROM v4 WHERE s > a
+)
+);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "const_condition": "0 or <in_optimizer>(2,<exists>(subquery#3))",
+ "table": {
+ "table_name": "t1",
+ "access_type": "system",
+ "rows": 1,
+ "filtered": 100
+ },
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "t2.b = 2",
+ "first_match": "t1"
+ },
+ "subqueries": [
+ {
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "table_name": "<derived5>",
+ "access_type": "index_subquery",
+ "possible_keys": ["key0"],
+ "key": "key0",
+ "key_length": "5",
+ "used_key_parts": ["d"],
+ "ref": ["func"],
+ "rows": 2,
+ "filtered": 100,
+ "materialized": {
+ "query_block": {
+ "select_id": 5,
+ "having_condition": "s > 2",
+ "filesort": {
+ "sort_key": "t4.d",
+ "temporary_table": {
+ "table": {
+ "table_name": "t4",
+ "access_type": "ALL",
+ "rows": 5,
+ "filtered": 100
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ ]
+ }
+}
+DROP VIEW v2,v3,v4;
+DROP TABLE t1,t2,t3,t4;
+#
+# MDEV-10800: pushdown of the condition obtained
+# after constant row substitution
+#
+CREATE TABLE t1 (a INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1);
+CREATE TABLE t2 (b INT) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (3),(4);
+CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2;
+SELECT * FROM
+( SELECT * FROM t1
+WHERE EXISTS ( SELECT * FROM v2 WHERE b = a ) ) AS sq;
+a
+EXPLAIN FORMAT=JSON
+SELECT * FROM
+( SELECT * FROM t1
+WHERE EXISTS ( SELECT * FROM v2 WHERE b = a ) ) AS sq;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "const_condition": "<in_optimizer>(1,exists(subquery#3))",
+ "table": {
+ "table_name": "t1",
+ "access_type": "system",
+ "rows": 1,
+ "filtered": 100
+ },
+ "subqueries": [
+ {
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "table_name": "<derived4>",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "v2.b = 1",
+ "materialized": {
+ "query_block": {
+ "select_id": 4,
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "t2.b = 1"
+ }
+ }
+ }
+ }
+ }
+ }
+ ]
+ }
+}
+DROP VIEW v2;
+DROP TABLE t1,t2;
+#
+# MDEV-11102: condition pushdown into materialized inner table
+# of outer join is not applied as not being valid
+#
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (0),(2);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1),(2);
+CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2;
+SELECT * FROM t1 LEFT JOIN t2 ON a = b WHERE b IS NULL;
+a b
+0 NULL
+SELECT * FROM t1 LEFT JOIN v2 ON a = b WHERE b IS NULL;
+a b
+0 NULL
+EXPLAIN FORMAT=JSON
+SELECT * FROM t1 LEFT JOIN v2 ON a = b WHERE b IS NULL;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100
+ },
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ref",
+ "possible_keys": ["key0"],
+ "key": "key0",
+ "key_length": "5",
+ "used_key_parts": ["b"],
+ "ref": ["test.t1.a"],
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "trigcond(v2.b is null) and trigcond(trigcond(t1.a is not null))",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100
+ }
+ }
+ }
+ }
+ }
+}
+DROP VIEW v2;
+DROP TABLE t1,t2;
+#
+# MDEV-11103: pushdown condition with ANY subquery
+#
+CREATE TABLE t1 (i INT);
+CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 VALUES (1),(2);
+EXPLAIN FORMAT=JSON
+SELECT * FROM v1 WHERE i <= ANY ( SELECT 3 );
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "<nop>(v1.i <= 3)",
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "<nop>(t1.i <= 3)"
+ }
+ }
+ }
+ }
+ }
+}
+Warnings:
+Note 1249 Select 2 was reduced during optimization
+SELECT * FROM v1 WHERE i <= ANY ( SELECT 3 );
+i
+1
+2
+DROP VIEW v1;
+DROP TABLE t1;
+#
+# MDEV-11315: condition with outer reference to mergeable derived
+#
+CREATE TABLE t1 (pk1 INT PRIMARY KEY, a INT, b INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (10,7,1),(11,0,2);
+CREATE TABLE t2 (pk2 INT PRIMARY KEY, c INT, d DATETIME) ENGINE=MyISAM;
+INSERT INTO t2 VALUES
+(1,4,'2008-09-27 00:34:58'),
+(2,5,'2007-05-28 00:00:00'),
+(3,6,'2009-07-25 09:21:20');
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2;
+SELECT * FROM v1 AS sq
+WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
+pk1 a b
+10 7 1
+11 0 2
+EXPLAIN FORMAT=JSON
+SELECT * FROM v1 AS sq
+WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "<in_optimizer>(t1.b,<exists>(subquery#2)) or t1.b = 100"
+ },
+ "subqueries": [
+ {
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "table_name": "<derived4>",
+ "access_type": "index_subquery",
+ "possible_keys": ["key0"],
+ "key": "key0",
+ "key_length": "4",
+ "used_key_parts": ["pk2"],
+ "ref": ["func"],
+ "rows": 2,
+ "filtered": 100,
+ "materialized": {
+ "query_block": {
+ "select_id": 4,
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100
+ }
+ }
+ }
+ }
+ }
+ }
+ ]
+ }
+}
+SELECT * FROM ( SELECT * FROM t1 ) AS sq
+WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
+pk1 a b
+10 7 1
+11 0 2
+EXPLAIN FORMAT=JSON
+SELECT * FROM ( SELECT * FROM t1 ) AS sq
+WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "<in_optimizer>(t1.b,<exists>(subquery#3)) or t1.b = 100"
+ },
+ "subqueries": [
+ {
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "table_name": "<derived4>",
+ "access_type": "index_subquery",
+ "possible_keys": ["key0"],
+ "key": "key0",
+ "key_length": "4",
+ "used_key_parts": ["pk2"],
+ "ref": ["func"],
+ "rows": 2,
+ "filtered": 100,
+ "materialized": {
+ "query_block": {
+ "select_id": 4,
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100
+ }
+ }
+ }
+ }
+ }
+ }
+ ]
+ }
+}
+DROP VIEW v1,v2;
+DROP TABLE t1,t2;
+#
+# MDEV-11313: pushdown of the condition obtained
+# after constant row substitution
+#
+CREATE TABLE t1 (a INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1),(2);
+CREATE TABLE t2 (b INT) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (50);
+CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
+SELECT ( SELECT COUNT(*) FROM v1 WHERE a = t2.b ) AS f FROM t2 GROUP BY f;
+f
+0
+EXPLAIN FORMAT=JSON
+SELECT ( SELECT COUNT(*) FROM v1 WHERE a = t2.b ) AS f FROM t2 GROUP BY f;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "t2",
+ "access_type": "system",
+ "rows": 1,
+ "filtered": 100
+ },
+ "subqueries": [
+ {
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "v1.a = 50",
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "t1.a = 50"
+ }
+ }
+ }
+ }
+ }
+ }
+ ]
+ }
+}
+CREATE TABLE t3 (a INT, b INT) ENGINE=MYISAM;
+INSERT INTO t3 VALUES (1,10),(3,11),(2,10),(2,20),(3,21);
+CREATE VIEW v2 AS SELECT a, sum(b) AS s FROM t3 GROUP BY a ;
+SELECT ( SELECT COUNT(*) FROM v2 WHERE s < t2.b ) AS f FROM t2 GROUP BY f;
+f
+3
+EXPLAIN FORMAT=JSON
+SELECT ( SELECT COUNT(*) FROM v2 WHERE s < t2.b ) AS f FROM t2 GROUP BY f;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "t2",
+ "access_type": "system",
+ "rows": 1,
+ "filtered": 100
+ },
+ "subqueries": [
+ {
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ALL",
+ "rows": 5,
+ "filtered": 100,
+ "attached_condition": "v2.s < 50",
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "having_condition": "s < 50",
+ "filesort": {
+ "sort_key": "t3.a",
+ "temporary_table": {
+ "table": {
+ "table_name": "t3",
+ "access_type": "ALL",
+ "rows": 5,
+ "filtered": 100
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ ]
+ }
+}
+DROP VIEW v1,v2;
+DROP TABLE t1,t2,t3;
+#
+# MDEV-10882: pushdown of the predicate with cached value
+#
+CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL) ENGINE=MyISAM;
+CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 VALUES (1,2),(3,4);
+CREATE TABLE t2 (c INT NOT NULL) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (5),(6);
+SELECT a, GROUP_CONCAT(b) FROM v1
+WHERE b IN ( SELECT COUNT(c) FROM t2 ) GROUP BY a;
+a GROUP_CONCAT(b)
+1 2
+EXPLAIN FORMAT=JSON
+SELECT a, GROUP_CONCAT(b) FROM v1
+WHERE b IN ( SELECT COUNT(c) FROM t2 ) GROUP BY a;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<subquery2>",
+ "access_type": "system",
+ "rows": 1,
+ "filtered": 100,
+ "materialized": {
+ "unique": 1,
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "message": "Select tables optimized away"
+ }
+ }
+ }
+ },
+ "read_sorted_file": {
+ "filesort": {
+ "sort_key": "v1.a",
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "v1.b = 2",
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "t1.b = 2"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+DROP VIEW v1;
+DROP TABLE t1,t2;
+#
+# MDEV-10836: pushdown of the predicate with cached value
+#
+CREATE TABLE t (pk INT PRIMARY KEY, f INT) ENGINE=MyISAM;
+CREATE ALGORITHM=TEMPTABLE VIEW v AS SELECT * FROM t;
+INSERT INTO t VALUES (1,1),(3,2);
+SELECT * FROM v AS v1, v AS v2
+WHERE v2.pk > v1.f AND v1.f IN ( SELECT COUNT(pk) FROM t );
+pk f pk f
+3 2 3 2
+EXPLAIN FORMAT=JSON
+SELECT * FROM v AS v1, v AS v2
+WHERE v2.pk > v1.f AND v1.f IN ( SELECT COUNT(pk) FROM t );
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<subquery2>",
+ "access_type": "system",
+ "rows": 1,
+ "filtered": 100,
+ "materialized": {
+ "unique": 1,
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "message": "Select tables optimized away"
+ }
+ }
+ }
+ },
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "v1.f = 2",
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "table_name": "t",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "t.f = 2"
+ }
+ }
+ }
+ },
+ "block-nl-join": {
+ "table": {
+ "table_name": "<derived4>",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "v2.pk > 2"
+ },
+ "buffer_type": "flat",
+ "buffer_size": "256Kb",
+ "join_type": "BNL",
+ "materialized": {
+ "query_block": {
+ "select_id": 4,
+ "table": {
+ "table_name": "t",
+ "access_type": "range",
+ "possible_keys": ["PRIMARY"],
+ "key": "PRIMARY",
+ "key_length": "4",
+ "used_key_parts": ["pk"],
+ "rows": 2,
+ "filtered": 100,
+ "index_condition": "t.pk > 2"
+ }
+ }
+ }
+ }
+ }
+}
+DROP VIEW v;
+DROP TABLE t;
+#
+# MDEV-11488: pushdown of the predicate with cached value
+#
+CREATE TABLE t1 (i INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1),(3),(2);
+CREATE TABLE t2 (j INT, KEY(j)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (3),(4);
+SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
+WHERE i IN ( SELECT MIN(j) FROM t2 );
+i
+3
+EXPLAIN FORMAT=JSON
+SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
+WHERE i IN ( SELECT MIN(j) FROM t2 );
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<subquery3>",
+ "access_type": "system",
+ "rows": 1,
+ "filtered": 100,
+ "materialized": {
+ "unique": 1,
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "message": "Select tables optimized away"
+ }
+ }
+ }
+ },
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "sq.i = 3",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "t1.i = 3"
+ }
+ }
+ }
+ }
+ }
+}
+UPDATE t2 SET j = 2 WHERE j = 3;
+SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
+WHERE i IN ( SELECT MIN(j) FROM t2 );
+i
+2
+DROP TABLE t1,t2;
+CREATE TABLE t1 (i FLOAT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1.5),(3.2),(2.71);
+CREATE TABLE t2 (j FLOAT, KEY(j)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (3.2),(2.71);
+SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
+WHERE i IN ( SELECT MIN(j) FROM t2 );
+i
+2.71
+EXPLAIN FORMAT=JSON
+SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
+WHERE i IN ( SELECT MIN(j) FROM t2 );
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<subquery3>",
+ "access_type": "system",
+ "rows": 1,
+ "filtered": 100,
+ "materialized": {
+ "unique": 1,
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "message": "Select tables optimized away"
+ }
+ }
+ }
+ },
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "sq.i = 2.7100000381469727",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "t1.i = 2.7100000381469727"
+ }
+ }
+ }
+ }
+ }
+}
+DROP TABLE t1,t2;
+CREATE TABLE t1 (i DECIMAL(10,2)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1.5),(3.21),(2.47);
+CREATE TABLE t2 (j DECIMAL(10,2), KEY(j)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (3.21),(4.55);
+SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
+WHERE i IN ( SELECT MIN(j) FROM t2 );
+i
+3.21
+EXPLAIN FORMAT=JSON
+SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
+WHERE i IN ( SELECT MIN(j) FROM t2 );
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<subquery3>",
+ "access_type": "system",
+ "rows": 1,
+ "filtered": 100,
+ "materialized": {
+ "unique": 1,
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "message": "Select tables optimized away"
+ }
+ }
+ }
+ },
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "sq.i = 3.21",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "t1.i = 3.21"
+ }
+ }
+ }
+ }
+ }
+}
+DROP TABLE t1,t2;
+CREATE TABLE t1 (i VARCHAR(32)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES ('cc'),('aa'),('ddd');
+CREATE TABLE t2 (j VARCHAR(16), KEY(j)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES ('bbb'),('aa');
+SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
+WHERE i IN ( SELECT MIN(j) FROM t2 );
+i
+aa
+EXPLAIN FORMAT=JSON
+SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
+WHERE i IN ( SELECT MIN(j) FROM t2 );
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<subquery3>",
+ "access_type": "system",
+ "rows": 1,
+ "filtered": 100,
+ "materialized": {
+ "unique": 1,
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "message": "Select tables optimized away"
+ }
+ }
+ }
+ },
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "sq.i = 'aa'",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "t1.i = 'aa'"
+ }
+ }
+ }
+ }
+ }
+}
+DROP TABLE t1,t2;
+CREATE TABLE t1 (i DATETIME) ENGINE=MyISAM;
+INSERT INTO t1 VALUES
+('2008-09-27 00:34:58'),('2007-05-28 00:00:00'), ('2009-07-25 09:21:20');
+CREATE TABLE t2 (j DATETIME, KEY(j)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES
+('2007-05-28 00:00:00'), ('2010-08-25 00:00:00');
+SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
+WHERE i IN ( SELECT MIN(j) FROM t2 );
+i
+2007-05-28 00:00:00
+EXPLAIN FORMAT=JSON
+SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
+WHERE i IN ( SELECT MIN(j) FROM t2 );
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<subquery3>",
+ "access_type": "system",
+ "rows": 1,
+ "filtered": 100,
+ "materialized": {
+ "unique": 1,
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "message": "Select tables optimized away"
+ }
+ }
+ }
+ },
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "sq.i = '2007-05-28 00:00:00'",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "t1.i = TIMESTAMP'2007-05-28 00:00:00'"
+ }
+ }
+ }
+ }
+ }
+}
+DROP TABLE t1,t2;
+CREATE TABLE t1 (i DATE) ENGINE=MyISAM;
+INSERT INTO t1 VALUES ('2008-09-27'),('2007-05-28'), ('2009-07-25');
+CREATE TABLE t2 (j DATE, KEY(j)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES ('2007-05-28'), ('2010-08-25');
+SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
+WHERE i IN ( SELECT MIN(j) FROM t2 );
+i
+2007-05-28
+EXPLAIN FORMAT=JSON
+SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
+WHERE i IN ( SELECT MIN(j) FROM t2 );
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<subquery3>",
+ "access_type": "system",
+ "rows": 1,
+ "filtered": 100,
+ "materialized": {
+ "unique": 1,
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "message": "Select tables optimized away"
+ }
+ }
+ }
+ },
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "sq.i = '2007-05-28'",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "t1.i = DATE'2007-05-28'"
+ }
+ }
+ }
+ }
+ }
+}
+DROP TABLE t1,t2;
+CREATE TABLE t1 (i TIME) ENGINE=MyISAM;
+INSERT INTO t1 VALUES ('00:34:58'),('10:00:02'), ('09:21:20');
+CREATE TABLE t2 (j TIME, KEY(j)) ENGINE=MyISAM;
+INSERT INTO t2 VALUES ('10:00:02'), ('11:00:10');
+SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
+WHERE i IN ( SELECT MIN(j) FROM t2 );
+i
+10:00:02
+EXPLAIN FORMAT=JSON
+SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
+WHERE i IN ( SELECT MIN(j) FROM t2 );
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<subquery3>",
+ "access_type": "system",
+ "rows": 1,
+ "filtered": 100,
+ "materialized": {
+ "unique": 1,
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "message": "Select tables optimized away"
+ }
+ }
+ }
+ },
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "sq.i = '10:00:02'",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "t1.i = TIME'10:00:02'"
+ }
+ }
+ }
+ }
+ }
+}
+DROP TABLE t1,t2;
+#
+# MDEV-11593: pushdown of condition with NULLIF
+#
+CREATE TABLE t1 (i INT);
+CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 VALUES (2), (1);
+SELECT * FROM v1 WHERE NULLIF(1, i);
+i
+2
+EXPLAIN FORMAT=JSON
+SELECT * FROM v1 WHERE NULLIF(1, i);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "nullif(1,v1.i)",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "nullif(1,t1.i)"
+ }
+ }
+ }
+ }
+ }
+}
+DROP VIEW v1;
+DROP TABLE t1;
+#
+# MDEV-11608: pushdown of the predicate with cached null value
+#
+CREATE TABLE t1 (c VARCHAR(3));
+CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 VALUES ('foo'),('bar');
+CREATE TABLE t2 (c VARCHAR(3));
+INSERT INTO t2 VALUES ('foo'),('xyz');
+SELECT * FROM v1 WHERE v1.c IN ( SELECT MIN(c) FROM t2 WHERE 0 );
+c
+EXPLAIN FORMAT=JSON
+SELECT * FROM v1 WHERE v1.c IN ( SELECT MIN(c) FROM t2 WHERE 0 );
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<subquery2>",
+ "access_type": "system",
+ "rows": 1,
+ "filtered": 100,
+ "materialized": {
+ "unique": 1,
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "message": "Impossible WHERE"
+ }
+ }
+ }
+ },
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "v1.c = NULL",
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "t1.c = NULL"
+ }
+ }
+ }
+ }
+ }
+}
+DROP VIEW v1;
+DROP TABLE t1,t2;
+CREATE TABLE t1 (d DECIMAL(10,2));
+CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 VALUES (5.37),(1.1);
+CREATE TABLE t2 (d DECIMAL(10,2));
+INSERT INTO t2 VALUES ('1.1'),('2.23');
+SELECT * FROM v1 WHERE v1.d IN ( SELECT MIN(d) FROM t2 WHERE 0 );
+d
+DROP VIEW v1;
+DROP TABLE t1,t2;
+#
+# MDEV-11820: second execution of PS for query
+# with false subquery predicate in WHERE
+#
+CREATE TABLE t1 (c VARCHAR(3)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES ('foo'),('bar');
+CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (a INT);
+INSERT INTO t2 VALUES (3), (4);
+PREPARE stmt1 FROM
+" SELECT * FROM v1 WHERE 1 IN (SELECT a FROM t2) OR c = 'foo'";
+PREPARE stmt2 FROM
+"EXPLAIN FORMAT=JSON
+ SELECT * FROM v1 WHERE 1 IN (SELECT a FROM t2) OR c = 'foo'";
+EXECUTE stmt1;
+c
+foo
+EXECUTE stmt2;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "v1.c = 'foo'",
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "t1.c = 'foo'"
+ }
+ }
+ }
+ },
+ "subqueries": [
+ {
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "1 = t2.a"
+ }
+ }
+ }
+ ]
+ }
+}
+INSERT INTO t2 SELECT a+1 FROM t2;
+INSERT INTO t2 SELECT a+1 FROM t2;
+INSERT INTO t2 SELECT a+1 FROM t2;
+INSERT INTO t2 SELECT a+1 FROM t2;
+INSERT INTO t2 SELECT a+1 FROM t2;
+INSERT INTO t2 SELECT a+1 FROM t2;
+EXECUTE stmt1;
+c
+foo
+EXECUTE stmt2;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "<cache>(<in_optimizer>(1,<exists>(subquery#2))) or v1.c = 'foo'",
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100
+ }
+ }
+ }
+ },
+ "subqueries": [
+ {
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 128,
+ "filtered": 100,
+ "attached_condition": "1 = t2.a"
+ }
+ }
+ }
+ ]
+ }
+}
+DEALLOCATE PREPARE stmt1;
+DEALLOCATE PREPARE stmt2;
+DROP VIEW v1;
+DROP TABLE t1,t2;
+#
+# MDEV-12373: pushdown into derived with side effects is prohibited
+#
+CREATE TABLE sales_documents (
+id int NOT NULL AUTO_INCREMENT,
+sale_id int NULL DEFAULT NULL,
+type tinyint unsigned NULL DEFAULT NULL,
+data text NULL DEFAULT NULL COLLATE 'utf8_unicode_ci',
+date date NULL DEFAULT NULL,
+order_number int unsigned NULL DEFAULT NULL,
+created_at int NULL DEFAULT NULL,
+updated_at int NULL DEFAULT NULL,
+generated tinyint NOT NULL DEFAULT '0',
+synced_at int NOT NULL DEFAULT '0',
+sum decimal(13,2) NOT NULL DEFAULT '0',
+PRIMARY KEY (id)
+);
+INSERT INTO sales_documents
+(id, sale_id, type, order_number, data, created_at,
+updated_at, date, generated, synced_at, sum)
+VALUES
+(555, 165, 3, 5, '{}', 1486538300, 1486722835, '2017-02-17', 0, 1486538313, 2320.00),
+(556, 165, 2, 3, '{}', 1486538304, 1486563125, '2017-02-08', 1, 1486538302, 2320.00),
+(557, 158, 2, 2, '{}', 1486538661, 1486538661, '2017-02-08', 0, 1486538660, 2320.00),
+(558, 171, 1, 3, '{}', 1486539104, 1488203405, '2017-02-08', 1, 1486539102, 23230.00),
+(559, 171, 2, 5, '{}', 1486549233, 1487146010, '2017-02-08', 1, 1486549225, 37690.00),
+(560, 172, 1, 1, '{}', 1486658260, 1488203409, '2017-02-09', 1, 1486658256, 40312.00),
+(561, 172, 2, 1, '{}', 1486711997, 1486711997, '2017-02-10', 1, 1486711996, 40312.00),
+(562, 172, 3, 1, '{}', 1486712104, 1486721395, '2017-02-10', 1, 1486712101, 40312.00),
+(563, 171, 3, 2, '{}', 1486712953, 1486720244, '2017-02-10', 1, 1486712910, 23230.00),
+(564, 170, 1, 2, '{}', 1486715948, 1488203410, '2017-02-10', 1, 1486715930, 28873.00),
+(565, 170, 3, 3, '{}', 1486716782, 1486717426, '2017-02-10', 1, 1486716779, 61948.00),
+(566, 166, 3, 4, '{}', 1486720947, 1486720947, '2017-02-10', 1, 1486720945, 4640.00),
+(567, 167, 3, 5, '{}', 1486722741, 1486722783, '2017-02-26', 0, 1486722738, 14755.00),
+(568, 165, 1, 4, '{}', 1486722849, 1486722849, '2017-02-10', 0, 1486722846, 2320.00),
+(569, 173, 2, 2, '{}', 1486723073, 1487071275, '2017-02-10', 1, 1486723071, 14282.00),
+(570, 173, 1, 4, '{}', 1486723100, 1488203412, '2017-02-10', 1, 1486723099, 14282.00),
+(571, 167, 2, 4, '{}', 1486730859, 1486730859, '2017-02-10', 1, 1486730856, 18655.00),
+(572, 167, 1, 5, '{}', 1486730883, 1488203412, '2017-02-10', 1, 1486730877, 18655.00),
+(573, 174, 2, 51, '{}', 1486731622, 1487060259, '2017-02-10', 1, 1486731620, 7140.00),
+(574, 174, 3, 5, '{}', 1486993472, 1486993472, '2017-02-13', 1, 1488216147, 28020.00),
+(575, 174, 1, 6, '{}', 1486993530, 1488203412, '2017-02-13', 1, 1486993505, 7140.00),
+(576, 173, 3, 6, '{}', 1487071425, 1487071425, '2017-02-14', 0, 1487071422, 14282.00),
+(577, 178, 2, 6, '{}', 1487327372, 1487327372, '2017-02-17', 1, 1487327370, 12321.00),
+(578, 177, 2, 7, '{}', 1487327394, 1487327394, '2017-02-17', 0, 1487327391, 4270.00),
+(579, 182, 3, 6, '{}', 1487750589, 1487751693, '2017-02-22', 1, 1487751688, 4270.00),
+(580, 182, 2, 7, '{}', 1487750601, 1487750663, '2017-02-22', 1, 1487750598, 4270.00),
+(581, 182, 1, 7, '{}', 1487750694, 1488203412, '2017-02-22', 1, 1487750692, 4270.00),
+(582, 185, 3, 7, '{}', 1487774051, 1487774051, '2017-02-22', 0, 1487774043, 8913.00),
+(583, 184, 3, 7, '{}', 1487774071, 1487774235, '2017-02-22', 0, 1487774093, 3285.00),
+(584, 184, 2, 8, '{}', 1487774074, 1487774074, '2017-02-22', 0, 1487774073, 3285.00),
+(585, 184, 1, 8, '{}', 1487774081, 1487774081, '2017-02-22', 0, 1487774075, 3285.00),
+(586, 193, 2, 8, '{}', 1487955294, 1487955318, '2017-02-24', 0, 1487955311, 4270.00),
+(587, 193, 1, 8, '{}', 1487955324, 1487955324, '2017-02-24', 0, 1487955320, 4270.00),
+(588, 193, 3, 7, '{}', 1487955341, 1487955341, '2017-02-24', 0, 1487955325, 4270.00),
+(589, 186, 1, 8, '{}', 1487957291, 1487957464, '2017-02-24', 0, 1487957459, 6960.00),
+(590, 186, 2, 8, '{}', 1487957308, 1487957468, '2017-02-24', 0, 1487957465, 6960.00),
+(591, 186, 3, 7, '{}', 1487957312, 1487957473, '2017-02-24', 0, 1487957469, 6960.00),
+(592, 194, 1, 8, '{}', 1488193293, 1488203412, '2017-02-27', 1, 1488193280, 2320.00),
+(593, 194, 2, 8, '{}', 1488193304, 1488193304, '2017-02-27', 1, 1488193303, 2320.00),
+(594, 210, 1, 9, '{}', 1488198896, 1488198896, '2017-02-27', 0, 1488198885, 4270.00),
+(595, 210, 2, 12, '{}', 1488198901, 1488198901, '2017-02-27', 1, 1488532585, 4270.00),
+(596, 210, 3, 10, '{}', 1488198904, 1488198904, '2017-02-27', 1, 1488532565, 4270.00),
+(597, 209, 2, 9, '{}', 1488200016, 1488450772, '2017-02-27', 1, 1488450449, 4270.00),
+(598, 209, 1, 9, '{}', 1488200020, 1488200063, '2017-02-27', 1, 1488200017, 4271.00),
+(599, 209, 3, 7, '{}', 1488200053, 1488200053, '2017-02-27', 0, 1488200021, 4271.00),
+(600, 211, 2, 10, '{}', 1488216265, 1489402027, '2017-02-27', 1, 1488216264, 2320.00),
+(601, 211, 3, 7, '{}', 1488216281, 1488216281, '2017-02-27', 1, 1488216276, 2320.00),
+(602, 211, 1, 10, '{}', 1488216283, 1488216283, '2017-02-27', 1, 1488216282, 2320.00),
+(603, 198, 2, 11, '{}', 1488280125, 1488280125, '2017-02-28', 0, 1488280095, 4270.00),
+(604, 198, 1, 11, '{}', 1488280160, 1488280160, '2017-02-28', 0, 1488280126, 4270.00),
+(605, 198, 3, 8, '{}', 1488280440, 1488280440, '2017-02-28', 0, 1488280435, 4270.00),
+(606, 212, 1, 12, '{}', 1488286301, 1489402168, '2017-02-28', 1, 1488286295, 13825.00),
+(607, 212, 3, 8, '{}', 1488289644, 1488289690, '2017-02-28', 1, 1488289642, 25295.00),
+(608, 212, 2, 13, '{}', 1488290350, 1488290431, '2017-02-28', 1, 1488290347, 13133.75),
+(609, 213, 1, 11, '{}', 1488529470, 1488529470, '2017-03-03', 1, 1488529461, 5660.00),
+(610, 213, 2, 11, '{}', 1488529484, 1488529484, '2017-03-03', 1, 1488529479, 5660.00),
+(611, 213, 3, 9, '{}', 1488529493, 1488529493, '2017-03-03', 1, 1488529489, 5660.00),
+(612, 197, 2, 13, '{}', 1489400715, 1489400715, '2017-03-13', 0, 1489398959, 4270.00),
+(613, 219, 3, 11, '{}', 1490084337, 1490181958, '2017-03-21', 1, 1490084334, 73526.00),
+(614, 216, 3, 11, '{}', 1490085757, 1490086717, '2017-03-21', 0, 1490085755, 5377.00);
+SELECT * FROM
+(SELECT @row := @row + 1 as row, a.* from (
+SELECT t.order_number
+FROM sales_documents t
+WHERE
+t.type = 2 AND
+t.date >= '2017-01-01' AND
+t.date <= '2017-12-31' AND
+t.order_number IS NOT NULL AND
+t.generated = 1
+GROUP BY t.order_number
+) a, (SELECT @row := 0) r) t
+WHERE row <> order_number;
+row order_number
+14 51
+DROP TABLE sales_documents;
+#
+# MDEV-12845: pushdown from merged derived using equalities
+#
+create table t1 (a int);
+insert into t1 values
+(4), (8), (5), (3), (10), (2), (7);
+create table t2 (b int, c int);
+insert into t2 values
+(2,1), (5,2), (2,2), (4,1), (4,3),
+(5,3), (2,4), (4,6), (2,1);
+create view v1 as
+select b, sum(c) as s from t2 group by b;
+create view v2 as
+select distinct b, c from t2;
+create view v3 as
+select b, max(c) as m from t2 group by b;
+select b
+from ( select t1.a, v1.b, v1.s from t1, v1 where t1.a = v1.b ) as t
+where b > 2;
+b
+4
+5
+explain format=json select b
+from ( select t1.a, v1.b, v1.s from t1, v1 where t1.a = v1.b ) as t
+where b > 2;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 7,
+ "filtered": 100,
+ "attached_condition": "t1.a > 2 and t1.a is not null"
+ },
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ref",
+ "possible_keys": ["key0"],
+ "key": "key0",
+ "key_length": "5",
+ "used_key_parts": ["b"],
+ "ref": ["test.t1.a"],
+ "rows": 2,
+ "filtered": 100,
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "filesort": {
+ "sort_key": "t2.b",
+ "temporary_table": {
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 9,
+ "filtered": 100,
+ "attached_condition": "t2.b > 2"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+select a
+from ( select t1.a, v1.b, v1.s from t1, v1 where t1.a = v1.b ) as t
+where a > 2;
+a
+4
+5
+explain format=json select a
+from ( select t1.a, v1.b, v1.s from t1, v1 where t1.a = v1.b ) as t
+where a > 2;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 7,
+ "filtered": 100,
+ "attached_condition": "t1.a > 2 and t1.a is not null"
+ },
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ref",
+ "possible_keys": ["key0"],
+ "key": "key0",
+ "key_length": "5",
+ "used_key_parts": ["b"],
+ "ref": ["test.t1.a"],
+ "rows": 2,
+ "filtered": 100,
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "filesort": {
+ "sort_key": "t2.b",
+ "temporary_table": {
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 9,
+ "filtered": 100,
+ "attached_condition": "t2.b > 2"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+select a
+from ( select t1.a, v2.b, v2.c from t1, v2 where t1.a = v2.b ) as t
+where a > 2;
+a
+4
+4
+4
+5
+5
+explain format=json select a
+from ( select t1.a, v2.b, v2.c from t1, v2 where t1.a = v2.b ) as t
+where a > 2;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 7,
+ "filtered": 100,
+ "attached_condition": "t1.a > 2 and t1.a is not null"
+ },
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ref",
+ "possible_keys": ["key0"],
+ "key": "key0",
+ "key_length": "5",
+ "used_key_parts": ["b"],
+ "ref": ["test.t1.a"],
+ "rows": 2,
+ "filtered": 100,
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "temporary_table": {
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 9,
+ "filtered": 100,
+ "attached_condition": "t2.b > 2"
+ }
+ }
+ }
+ }
+ }
+ }
+}
+select a
+from ( select t1.a, v3.b, v3.m from t1, v3 where t1.a = v3.m ) as t
+where a > 2;
+a
+4
+3
+explain format=json select a
+from ( select t1.a, v3.b, v3.m from t1, v3 where t1.a = v3.m ) as t
+where a > 2;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 7,
+ "filtered": 100,
+ "attached_condition": "t1.a > 2 and t1.a is not null"
+ },
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ref",
+ "possible_keys": ["key0"],
+ "key": "key0",
+ "key_length": "5",
+ "used_key_parts": ["m"],
+ "ref": ["test.t1.a"],
+ "rows": 2,
+ "filtered": 100,
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "having_condition": "m > 2",
+ "filesort": {
+ "sort_key": "t2.b",
+ "temporary_table": {
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 9,
+ "filtered": 100
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+drop view v1,v2,v3;
+drop table t1,t2;
+#
+# MDEV-13166: pushdown from merged derived
+#
+CREATE TABLE t1 (i int) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1),(2);
+CREATE VIEW v1 AS SELECT MAX(i) AS f FROM t1;
+SELECT * FROM ( SELECT * FROM v1 ) AS sq WHERE f > 0;
+f
+2
+explain format=json SELECT * FROM ( SELECT * FROM v1 ) AS sq WHERE f > 0;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "v1.f > 0",
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "having_condition": "f > 0",
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100
+ }
+ }
+ }
+ }
+ }
+}
+DROP VIEW v1;
+DROP TABLE t1;
+#
+# MDEV-13193: pushdown of equality extracted from multiple equality
+#
+CREATE TABLE t1 (i1 int, KEY(i1)) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1),(2);
+CREATE TABLE t2 (i2 int) ENGINE=MyISAM;
+INSERT INTO t2 VALUES (2),(4);
+CREATE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2;
+SELECT * FROM t1, ( SELECT * FROM v2 ) AS sq
+WHERE i1 = 1 AND ( i1 = i2 OR i1 = 2 );
+i1 i2
+explain format=json SELECT * FROM t1, ( SELECT * FROM v2 ) AS sq
+WHERE i1 = 1 AND ( i1 = i2 OR i1 = 2 );
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ref",
+ "possible_keys": ["i1"],
+ "key": "i1",
+ "key_length": "5",
+ "used_key_parts": ["i1"],
+ "ref": ["const"],
+ "rows": 1,
+ "filtered": 100,
+ "using_index": true
+ },
+ "block-nl-join": {
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "v2.i2 = 1"
+ },
+ "buffer_type": "flat",
+ "buffer_size": "256Kb",
+ "join_type": "BNL",
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "t2.i2 = 1"
+ }
+ }
+ }
+ }
+ }
+}
+DROP VIEW v2;
+DROP TABLE t1,t2;
+#
+# MDEV-14237: derived with regexp_substr() in select list
+#
+create table t1 (a char(8));
+insert into t1 values ('b'), ('a'), ('xx');
+select *
+from ( select distinct regexp_substr(t1.a,'^[A-Za-z]+') as f from t1) as t
+where t.f = 'a' or t.f = 'b';
+f
+b
+a
+explain format=json select *
+from ( select distinct regexp_substr(t1.a,'^[A-Za-z]+') as f from t1) as t
+where t.f = 'a' or t.f = 'b';
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "t.f = 'a' or t.f = 'b'",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "temporary_table": {
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100
+ }
+ }
+ }
+ }
+ }
+ }
+}
+drop table t1;
+#
+# MDEV-13454: consequence of mdev-14368 fixed for 5.5
+#
+SET sql_mode = 'ONLY_FULL_GROUP_BY';
+create table t1 (id int, id2 int);
+insert into t1 values (1,1),(2,3),(3,4),(7,2);
+create table t2(id2 int);
+insert t2 values (1),(2),(3);
+SELECT * FROM t1
+LEFT OUTER JOIN
+(SELECT id2, COUNT(*) as ct FROM t2 GROUP BY id2) vc USING (id2)
+WHERE (vc.ct>0);
+id2 id ct
+1 1 1
+3 2 1
+2 7 1
+EXPLAIN FORMAT=JSON SELECT * FROM t1
+LEFT OUTER JOIN
+(SELECT id2, COUNT(*) as ct FROM t2 GROUP BY id2) vc USING (id2)
+WHERE (vc.ct>0);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "vc.ct > 0",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "having_condition": "ct > 0",
+ "filesort": {
+ "sort_key": "t2.id2",
+ "temporary_table": {
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100
+ }
+ }
+ }
+ }
+ }
+ },
+ "block-nl-join": {
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 4,
+ "filtered": 100
+ },
+ "buffer_type": "flat",
+ "buffer_size": "256Kb",
+ "join_type": "BNL",
+ "attached_condition": "t1.id2 = vc.id2"
+ }
+ }
+}
+DROP TABLE t1,t2;
+SET sql_mode = DEFAULT;
+#
+# MDEV-15579: incorrect removal of sub-formulas to be pushed
+# into WHERE of materialized derived with GROUP BY
+#
+CREATE TABLE t1 (a INT, b INT, c INT, d INT);
+CREATE TABLE t2 (x INT, y INT, z INT);
+INSERT INTO t1 VALUES (1,1,66,1), (1,1,56,2), (3,2,42,3);
+INSERT INTO t2 VALUES (1,1,66), (1,12,32);
+SELECT *
+FROM t2,
+(
+SELECT a, b, max(c) AS max_c
+FROM t1
+GROUP BY a
+HAVING max_c > 37
+) AS v1
+WHERE (v1.a=1) AND (v1.b=v1.a) AND
+(v1.a=t2.x) AND (v1.max_c>30);
+x y z a b max_c
+1 1 66 1 1 66
+1 12 32 1 1 66
+EXPLAIN SELECT *
+FROM t2,
+(
+SELECT a, b, max(c) AS max_c
+FROM t1
+GROUP BY a
+HAVING max_c > 37
+) AS v1
+WHERE (v1.a=1) AND (v1.b=v1.a) AND
+(v1.a=t2.x) AND (v1.max_c>30);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
+2 DERIVED t1 ALL NULL NULL NULL NULL 3 Using where
+EXPLAIN FORMAT=JSON SELECT *
+FROM t2,
+(
+SELECT a, b, max(c) AS max_c
+FROM t1
+GROUP BY a
+HAVING max_c > 37
+) AS v1
+WHERE (v1.a=1) AND (v1.b=v1.a) AND
+(v1.a=t2.x) AND (v1.max_c>30);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "t2.x = 1"
+ },
+ "block-nl-join": {
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "v1.a = 1 and v1.b = 1 and v1.max_c > 30"
+ },
+ "buffer_type": "flat",
+ "buffer_size": "256Kb",
+ "join_type": "BNL",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "having_condition": "max_c > 37 and max_c > 30 and t1.b = 1",
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "t1.a = 1"
+ }
+ }
+ }
+ }
+ }
+}
+SELECT *
+FROM t2,
+(
+SELECT a, b, d, max(c) AS max_c
+FROM t1
+GROUP BY a,d
+HAVING max_c > 37
+) AS v1
+WHERE (v1.a=1) AND (v1.b=v1.a) AND (v1.b=v1.d) AND
+(v1.a=t2.x) AND (v1.max_c>30);
+x y z a b d max_c
+1 1 66 1 1 1 66
+1 12 32 1 1 1 66
+EXPLAIN SELECT *
+FROM t2,
+(
+SELECT a, b, d, max(c) AS max_c
+FROM t1
+GROUP BY a,d
+HAVING max_c > 37
+) AS v1
+WHERE (v1.a=1) AND (v1.b=v1.a) AND (v1.b=v1.d) AND
+(v1.a=t2.x) AND (v1.max_c>30);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
+2 DERIVED t1 ALL NULL NULL NULL NULL 3 Using where
+EXPLAIN FORMAT=JSON SELECT *
+FROM t2,
+(
+SELECT a, b, d, max(c) AS max_c
+FROM t1
+GROUP BY a,d
+HAVING max_c > 37
+) AS v1
+WHERE (v1.a=1) AND (v1.b=v1.a) AND (v1.b=v1.d) AND
+(v1.a=t2.x) AND (v1.max_c>30);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "t2.x = 1"
+ },
+ "block-nl-join": {
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "v1.a = 1 and v1.b = 1 and v1.d = 1 and v1.max_c > 30"
+ },
+ "buffer_type": "flat",
+ "buffer_size": "256Kb",
+ "join_type": "BNL",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "having_condition": "max_c > 37 and max_c > 30 and t1.b = 1",
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "t1.a = 1 and t1.d = 1"
+ }
+ }
+ }
+ }
+ }
+}
+DROP TABLE t1,t2;
+#
+# MDEV-15765: pushing condition with temporal constants
+# into constant tables
+#
+select * from (select date('2018-01-01') as d
+union all
+select date('2018-01-01') as d) as t
+where t.d between date ('2017-01-01') and date ('2019-01-01');
+d
+2018-01-01
+2018-01-01
+select * from (select date('2018-01-01') as d) as t
+where t.d between date ('2017-01-01') and date ('2019-01-01');
+d
+2018-01-01
+#
+# MDEV-16088: pushdown into derived defined in the IN subquery
+#
+CREATE TABLE t1 (a INT, b INT);
+CREATE TABLE t2 (e INT, f INT, g INT);
+INSERT INTO t1 VALUES (1,14),(2,13),(1,19),(2,32),(3,24);
+INSERT INTO t2 VALUES (1,19,2),(3,24,1),(1,12,2),(3,11,3),(2,32,1);
+SELECT * FROM t1
+WHERE (t1.a,t1.b) IN
+(
+SELECT d_tab.e,d_tab.max_f
+FROM (
+SELECT t2.e, MAX(t2.f) AS max_f
+FROM t2
+GROUP BY t2.e
+HAVING max_f>18
+) as d_tab
+WHERE d_tab.e>1
+)
+;
+a b
+2 32
+3 24
+EXPLAIN SELECT * FROM t1
+WHERE (t1.a,t1.b) IN
+(
+SELECT d_tab.e,d_tab.max_f
+FROM (
+SELECT t2.e, MAX(t2.f) AS max_f
+FROM t2
+GROUP BY t2.e
+HAVING max_f>18
+) as d_tab
+WHERE d_tab.e>1
+)
+;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 5
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1
+2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 5 Using where
+3 DERIVED t2 ALL NULL NULL NULL NULL 5 Using where; Using temporary; Using filesort
+EXPLAIN FORMAT=JSON SELECT * FROM t1
+WHERE (t1.a,t1.b) IN
+(
+SELECT d_tab.e,d_tab.max_f
+FROM (
+SELECT t2.e, MAX(t2.f) AS max_f
+FROM t2
+GROUP BY t2.e
+HAVING max_f>18
+) as d_tab
+WHERE d_tab.e>1
+)
+;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 5,
+ "filtered": 100
+ },
+ "table": {
+ "table_name": "<subquery2>",
+ "access_type": "eq_ref",
+ "possible_keys": ["distinct_key"],
+ "key": "distinct_key",
+ "key_length": "8",
+ "used_key_parts": ["e", "max_f"],
+ "ref": ["func", "func"],
+ "rows": 1,
+ "filtered": 100,
+ "materialized": {
+ "unique": 1,
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ALL",
+ "rows": 5,
+ "filtered": 100,
+ "attached_condition": "d_tab.e > 1",
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "having_condition": "max_f > 18",
+ "filesort": {
+ "sort_key": "t2.e",
+ "temporary_table": {
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 5,
+ "filtered": 100,
+ "attached_condition": "t2.e > 1"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+SELECT * FROM t1
+WHERE (t1.a,t1.b) IN
+(
+SELECT d_tab.e,d_tab.max_f
+FROM (
+SELECT t2.e, MAX(t2.f) AS max_f
+FROM t2
+GROUP BY t2.e
+HAVING max_f>18
+) as d_tab
+WHERE d_tab.max_f<25
+)
+;
+a b
+1 19
+3 24
+EXPLAIN SELECT * FROM t1
+WHERE (t1.a,t1.b) IN
+(
+SELECT d_tab.e,d_tab.max_f
+FROM (
+SELECT t2.e, MAX(t2.f) AS max_f
+FROM t2
+GROUP BY t2.e
+HAVING max_f>18
+) as d_tab
+WHERE d_tab.max_f<25
+)
+;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 5
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1
+2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 5 Using where
+3 DERIVED t2 ALL NULL NULL NULL NULL 5 Using temporary; Using filesort
+EXPLAIN FORMAT=JSON SELECT * FROM t1
+WHERE (t1.a,t1.b) IN
+(
+SELECT d_tab.e,d_tab.max_f
+FROM (
+SELECT t2.e, MAX(t2.f) AS max_f
+FROM t2
+GROUP BY t2.e
+HAVING max_f>18
+) as d_tab
+WHERE d_tab.max_f<25
+)
+;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 5,
+ "filtered": 100
+ },
+ "table": {
+ "table_name": "<subquery2>",
+ "access_type": "eq_ref",
+ "possible_keys": ["distinct_key"],
+ "key": "distinct_key",
+ "key_length": "8",
+ "used_key_parts": ["e", "max_f"],
+ "ref": ["func", "func"],
+ "rows": 1,
+ "filtered": 100,
+ "materialized": {
+ "unique": 1,
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ALL",
+ "rows": 5,
+ "filtered": 100,
+ "attached_condition": "d_tab.max_f < 25",
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "having_condition": "max_f > 18 and max_f < 25",
+ "filesort": {
+ "sort_key": "t2.e",
+ "temporary_table": {
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 5,
+ "filtered": 100
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+SELECT * FROM t1
+WHERE (t1.a,t1.b) IN
+(
+SELECT d_tab.e, MAX(d_tab.max_f) AS max_f
+FROM (
+SELECT t2.e, MAX(t2.f) as max_f, t2.g
+FROM t2
+GROUP BY t2.e
+) as d_tab
+WHERE d_tab.e>1
+GROUP BY d_tab.g
+)
+;
+a b
+2 32
+EXPLAIN SELECT * FROM t1
+WHERE (t1.a,t1.b) IN
+(
+SELECT d_tab.e, MAX(d_tab.max_f) AS max_f
+FROM (
+SELECT t2.e, MAX(t2.f) as max_f, t2.g
+FROM t2
+GROUP BY t2.e
+) as d_tab
+WHERE d_tab.e>1
+GROUP BY d_tab.g
+)
+;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.b 1
+2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 5 Using where; Using temporary
+3 DERIVED t2 ALL NULL NULL NULL NULL 5 Using where; Using temporary; Using filesort
+EXPLAIN FORMAT=JSON SELECT * FROM t1
+WHERE (t1.a,t1.b) IN
+(
+SELECT d_tab.e, MAX(d_tab.max_f) AS max_f
+FROM (
+SELECT t2.e, MAX(t2.f) as max_f, t2.g
+FROM t2
+GROUP BY t2.e
+) as d_tab
+WHERE d_tab.e>1
+GROUP BY d_tab.g
+)
+;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 5,
+ "filtered": 100,
+ "attached_condition": "t1.a is not null and t1.b is not null"
+ },
+ "table": {
+ "table_name": "<subquery2>",
+ "access_type": "eq_ref",
+ "possible_keys": ["distinct_key"],
+ "key": "distinct_key",
+ "key_length": "8",
+ "used_key_parts": ["e", "max_f"],
+ "ref": ["test.t1.a", "test.t1.b"],
+ "rows": 1,
+ "filtered": 100,
+ "materialized": {
+ "unique": 1,
+ "query_block": {
+ "select_id": 2,
+ "temporary_table": {
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ALL",
+ "rows": 5,
+ "filtered": 100,
+ "attached_condition": "d_tab.e > 1",
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "filesort": {
+ "sort_key": "t2.e",
+ "temporary_table": {
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 5,
+ "filtered": 100,
+ "attached_condition": "t2.e > 1"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+SELECT * FROM t1
+WHERE (t1.a,t1.b) IN
+(
+SELECT d_tab.e, MAX(d_tab.max_f) AS max_f
+FROM (
+SELECT t2.e, MAX(t2.f) as max_f, t2.g
+FROM t2
+GROUP BY t2.e
+) as d_tab
+WHERE d_tab.max_f>20
+GROUP BY d_tab.g
+)
+;
+a b
+2 32
+EXPLAIN SELECT * FROM t1
+WHERE (t1.a,t1.b) IN
+(
+SELECT d_tab.e, MAX(d_tab.max_f) AS max_f
+FROM (
+SELECT t2.e, MAX(t2.f) as max_f, t2.g
+FROM t2
+GROUP BY t2.e
+) as d_tab
+WHERE d_tab.max_f>20
+GROUP BY d_tab.g
+)
+;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.b 1
+2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 5 Using where; Using temporary
+3 DERIVED t2 ALL NULL NULL NULL NULL 5 Using temporary; Using filesort
+EXPLAIN FORMAT=JSON SELECT * FROM t1
+WHERE (t1.a,t1.b) IN
+(
+SELECT d_tab.e, MAX(d_tab.max_f) AS max_f
+FROM (
+SELECT t2.e, MAX(t2.f) as max_f, t2.g
+FROM t2
+GROUP BY t2.e
+) as d_tab
+WHERE d_tab.max_f>20
+GROUP BY d_tab.g
+)
+;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 5,
+ "filtered": 100,
+ "attached_condition": "t1.a is not null and t1.b is not null"
+ },
+ "table": {
+ "table_name": "<subquery2>",
+ "access_type": "eq_ref",
+ "possible_keys": ["distinct_key"],
+ "key": "distinct_key",
+ "key_length": "8",
+ "used_key_parts": ["e", "max_f"],
+ "ref": ["test.t1.a", "test.t1.b"],
+ "rows": 1,
+ "filtered": 100,
+ "materialized": {
+ "unique": 1,
+ "query_block": {
+ "select_id": 2,
+ "temporary_table": {
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ALL",
+ "rows": 5,
+ "filtered": 100,
+ "attached_condition": "d_tab.max_f > 20",
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "having_condition": "max_f > 20",
+ "filesort": {
+ "sort_key": "t2.e",
+ "temporary_table": {
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 5,
+ "filtered": 100
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+DROP TABLE t1,t2;
+#
+# MDEV-15765: pushing condition with IN subquery defined with constants
+# using substitution
+#
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2);
+SELECT * FROM
+(
+SELECT DISTINCT * FROM t1
+) der_tab
+WHERE (a>0 AND a<2 OR a IN (2,3)) AND
+(a=2 OR 0);
+a
+2
+DROP TABLE t1;
+#
+# MDEV-16386: pushing condition into the HAVING clause when ambiguous
+# fields warning appears
+#
+CREATE TABLE t1 (a INT, b INT);
+INSERT INTO t1 VALUES (1,2),(2,3),(3,4);
+SELECT * FROM
+(
+SELECT t1.b AS a
+FROM t1
+GROUP BY t1.a
+) dt
+WHERE (dt.a=2);
+a
+2
+EXPLAIN FORMAT=JSON SELECT * FROM
+(
+SELECT t1.b AS a
+FROM t1
+GROUP BY t1.a
+) dt
+WHERE (dt.a=2);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "dt.a = 2",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "having_condition": "a = 2",
+ "filesort": {
+ "sort_key": "t1.a",
+ "temporary_table": {
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+SELECT * FROM
+(
+SELECT t1.b AS a
+FROM t1
+GROUP BY t1.a
+HAVING (t1.a<3)
+) dt
+WHERE (dt.a>1);
+a
+2
+3
+EXPLAIN FORMAT=JSON SELECT * FROM
+(
+SELECT t1.b AS a
+FROM t1
+GROUP BY t1.a
+HAVING (t1.a<3)
+) dt
+WHERE (dt.a>1);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "dt.a > 1",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "having_condition": "t1.a < 3 and a > 1",
+ "filesort": {
+ "sort_key": "t1.a",
+ "temporary_table": {
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+SELECT * FROM
+(
+SELECT 'ab' AS a
+FROM t1
+GROUP BY t1.a
+) dt
+WHERE (dt.a='ab');
+a
+ab
+ab
+ab
+EXPLAIN FORMAT=JSON SELECT * FROM
+(
+SELECT 'ab' AS a
+FROM t1
+GROUP BY t1.a
+) dt
+WHERE (dt.a='ab');
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "dt.a = 'ab'",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "filesort": {
+ "sort_key": "t1.a",
+ "temporary_table": {
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+SELECT * FROM
+(
+SELECT 1 AS a
+FROM t1
+GROUP BY t1.a
+) dt
+WHERE (dt.a=1);
+a
+1
+1
+1
+EXPLAIN FORMAT=JSON SELECT * FROM
+(
+SELECT 1 AS a
+FROM t1
+GROUP BY t1.a
+) dt
+WHERE (dt.a=1);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "dt.a = 1",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "filesort": {
+ "sort_key": "t1.a",
+ "temporary_table": {
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+DROP TABLE t1;
+#
+# MDEV-16517: pushdown condition with the IN predicate defined
+# with non-constant values
+#
+CREATE TABLE t1 (a INT, b INT);
+INSERT INTO t1 VALUES (1,2),(1,3);
+SELECT * FROM
+(
+SELECT t1.a
+FROM t1
+WHERE 1 IN (0,t1.a)
+GROUP BY t1.a
+) AS dt1
+JOIN
+(
+SELECT t1.a
+FROM t1
+WHERE 1 IN (0,t1.a)
+) AS dt2
+ON dt1.a = dt2.a;
+a a
+1 1
+1 1
+EXPLAIN FORMAT=JSON SELECT * FROM
+(
+SELECT t1.a
+FROM t1
+WHERE 1 IN (0,t1.a)
+GROUP BY t1.a
+) AS dt1
+JOIN
+(
+SELECT t1.a
+FROM t1
+WHERE 1 IN (0,t1.a)
+) AS dt2
+ON dt1.a = dt2.a;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "1 in (0,dt1.a)",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "filesort": {
+ "sort_key": "t1.a",
+ "temporary_table": {
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "1 in (0,t1.a) and 1 in (0,t1.a)"
+ }
+ }
+ }
+ }
+ }
+ },
+ "block-nl-join": {
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100
+ },
+ "buffer_type": "flat",
+ "buffer_size": "256Kb",
+ "join_type": "BNL",
+ "attached_condition": "t1.a = dt1.a"
+ }
+ }
+}
+SELECT * FROM
+(
+SELECT t1.a,MAX(t1.b)
+FROM t1
+GROUP BY t1.a
+) AS dt, t1
+WHERE dt.a=t1.a AND dt.a IN (1,t1.a);
+a MAX(t1.b) a b
+1 3 1 2
+1 3 1 3
+EXPLAIN FORMAT=JSON SELECT * FROM
+(
+SELECT t1.a,MAX(t1.b)
+FROM t1
+GROUP BY t1.a
+) AS dt, t1
+WHERE dt.a=t1.a AND dt.a IN (1,t1.a);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "dt.a in (1,dt.a)",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "filesort": {
+ "sort_key": "t1.a",
+ "temporary_table": {
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "t1.a in (1,t1.a)"
+ }
+ }
+ }
+ }
+ }
+ },
+ "block-nl-join": {
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 2,
+ "filtered": 100
+ },
+ "buffer_type": "flat",
+ "buffer_size": "256Kb",
+ "join_type": "BNL",
+ "attached_condition": "t1.a = dt.a"
+ }
+ }
+}
+DROP TABLE t1;
+#
+# MDEV-15087: error from inexpensive subquery before check
+# for condition pushdown into derived
+#
+CREATE TABLE t1 (i1 int, v1 varchar(1));
+INSERT INTO t1 VALUES (7,'x');
+CREATE TABLE t2 (i1 int);
+INSERT INTO t2 VALUES (8);
+CREATE TABLE t3 (i1 int ,v1 varchar(1), v2 varchar(1));
+INSERT INTO t3 VALUES (4, 'v','v'),(62,'v','k'),(7, 'n', NULL);
+SELECT 1
+FROM (t1 AS a1
+JOIN (((SELECT DISTINCT t3.*
+FROM t3) AS a2
+JOIN t1 ON (t1.v1 = a2.v2))) ON (t1.v1 = a2.v1))
+WHERE (SELECT BIT_COUNT(t2.i1)
+FROM (t2 JOIN t3)) IS NULL;
+ERROR 21000: Subquery returns more than 1 row
+DROP TABLE t1, t2, t3;
+#
+# MDEV-16614 signal 7 after calling stored procedure, that uses regexp
+#
+CREATE PROCEDURE p1(m1 varchar(5), m2 varchar(5))
+BEGIN
+SELECT a FROM
+(SELECT "aa" a) t
+JOIN (SELECT "aa" b) t1 on t.a=t1.b
+WHERE t.a regexp m1 and t1.b regexp m2
+GROUP BY a;
+END$$
+CALL p1('a','a');
+a
+aa
+DROP PROCEDURE p1;
+CREATE PROCEDURE p1(m1 varchar(5))
+BEGIN
+SELECT a FROM (SELECT "aa" a) t WHERE t.a regexp m1;
+END$$
+CALL p1('a');
+a
+aa
+DROP PROCEDURE p1;
+SELECT a FROM (SELECT "aa" a) t WHERE REGEXP_INSTR(t.a, (SELECT MAX('aa') FROM DUAL LIMIT 1));
+a
+aa
+CREATE OR REPLACE FUNCTION f1(a VARCHAR(10), b VARCHAR(10)) RETURNS INT
+BEGIN
+RETURN 1;
+END;$$
+CREATE OR REPLACE PROCEDURE p1(m1 varchar(5))
+BEGIN
+SELECT a FROM (SELECT "aa" a) t WHERE f1(t.a, m1);
+END$$
+CALL p1('a');
+a
+aa
+DROP PROCEDURE p1;
+DROP FUNCTION f1;
+CREATE OR REPLACE FUNCTION f1(a VARCHAR(10), b VARCHAR(10)) RETURNS INT
+BEGIN
+RETURN 1;
+END;$$
+SELECT a FROM (SELECT "aa" a) t WHERE f1(t.a, (SELECT MAX('aa') FROM DUAL LIMIT 1));
+a
+aa
+DROP FUNCTION f1;
+#
+# MDEV-17011: condition pushdown into materialized derived used
+# in INSERT SELECT, multi-table UPDATE and DELETE
+#
+CREATE TABLE t1 (a int ,b int) ENGINE=MyISAM;
+INSERT INTO t1 VALUES
+(1, 1), (1, 2), (2, 1), (2, 2), (3,1), (3,3), (4,2);
+CREATE TABLE t2 (a int) ENGINE MYISAM;
+INSERT INTO t2 VALUES
+(3), (7), (1), (4), (1);
+CREATE TABLE t3 (a int, b int) ENGINE MYISAM;
+EXPLAIN FORMAT=JSON INSERT INTO t3
+SELECT * FROM (SELECT a, count(*) as c FROM t1 GROUP BY a) t WHERE a<=2;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 7,
+ "filtered": 100,
+ "attached_condition": "t.a <= 2",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "filesort": {
+ "sort_key": "t1.a",
+ "temporary_table": {
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 7,
+ "filtered": 100,
+ "attached_condition": "t1.a <= 2"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+INSERT INTO t3
+SELECT * FROM (SELECT a, count(*) as c FROM t1 GROUP BY a) t WHERE a<=2;
+SELECT * FROM t3;
+a b
+1 2
+2 2
+EXPLAIN FORMAT=JSON UPDATE t2, (SELECT a, count(*) as c FROM t1 GROUP BY a) t SET t2.a=t.c+10
+WHERE t2.a= t.c and t.a>=3;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 5,
+ "filtered": 100,
+ "attached_condition": "t2.a is not null"
+ },
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ref",
+ "possible_keys": ["key0"],
+ "key": "key0",
+ "key_length": "8",
+ "used_key_parts": ["c"],
+ "ref": ["test.t2.a"],
+ "rows": 2,
+ "filtered": 100,
+ "attached_condition": "t2.a = t.c and t.a >= 3",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "filesort": {
+ "sort_key": "t1.a",
+ "temporary_table": {
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 7,
+ "filtered": 100,
+ "attached_condition": "t1.a >= 3"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+UPDATE t2, (SELECT a, count(*) as c FROM t1 GROUP BY a) t SET t2.a=t.c+10
+WHERE t2.a= t.c and t.a>=3;
+SELECT * FROM t2;
+a
+3
+7
+11
+4
+11
+EXPLAIN FORMAT=JSON DELETE t2 FROM t2, (SELECT a, count(*) as c FROM t1 GROUP BY a) t
+WHERE t2.a= t.c+9 and t.a=2;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 5,
+ "filtered": 100
+ },
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 7,
+ "filtered": 100,
+ "attached_condition": "t.a = 2 and t2.a = t.c + 9",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 7,
+ "filtered": 100,
+ "attached_condition": "t1.a = 2"
+ }
+ }
+ }
+ }
+ }
+}
+DELETE t2 FROM t2, (SELECT a, count(*) as c FROM t1 GROUP BY a) t
+WHERE t2.a= t.c+9 and t.a=2;
+SELECT * FROM t2;
+a
+3
+7
+4
+DROP TABLE t1,t2,t3;
+#
+# MDEV-16765: pushdown condition with the CASE structure
+# defined with Item_cond item
+#
+CREATE TABLE t1(a INT, b INT);
+INSERT INTO t1 VALUES (1,2), (3,4), (2,3);
+SELECT *
+FROM
+(
+SELECT CASE WHEN ((tab2.max_a=1) OR (tab2.max_a=2))
+THEN 1 ELSE 0 END AS max_a,b
+FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
+) AS tab1
+WHERE (tab1.max_a=1);
+max_a b
+1 2
+1 3
+EXPLAIN FORMAT=JSON SELECT *
+FROM
+(
+SELECT CASE WHEN ((tab2.max_a=1) OR (tab2.max_a=2))
+THEN 1 ELSE 0 END AS max_a,b
+FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
+) AS tab1
+WHERE (tab1.max_a=1);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "case when (tab2.max_a = 1 or tab2.max_a = 2) then 1 else 0 end = 1",
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "having_condition": "case when (max_a = 1 or max_a = 2) then 1 else 0 end = 1",
+ "filesort": {
+ "sort_key": "t1.b",
+ "temporary_table": {
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+SELECT *
+FROM
+(
+SELECT CASE WHEN ((tab2.max_a=1) OR ((tab2.max_a>2) AND (tab2.max_a<4)))
+THEN 1 ELSE 0 END AS max_a,b
+FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
+) AS tab1
+WHERE (tab1.max_a=1);
+max_a b
+1 2
+1 4
+EXPLAIN FORMAT=JSON SELECT *
+FROM
+(
+SELECT CASE WHEN ((tab2.max_a=1) OR ((tab2.max_a>2) AND (tab2.max_a<4)))
+THEN 1 ELSE 0 END AS max_a,b
+FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
+) AS tab1
+WHERE (tab1.max_a=1);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "case when (tab2.max_a = 1 or tab2.max_a > 2 and tab2.max_a < 4) then 1 else 0 end = 1",
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "having_condition": "case when (max_a = 1 or max_a > 2 and max_a < 4) then 1 else 0 end = 1",
+ "filesort": {
+ "sort_key": "t1.b",
+ "temporary_table": {
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+SELECT *
+FROM
+(
+SELECT CASE WHEN ((tab2.max_a>1) AND ((tab2.max_a=2) OR (tab2.max_a>2)))
+THEN 1 ELSE 0 END AS max_a,b
+FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
+) AS tab1
+WHERE (tab1.max_a=1);
+max_a b
+1 3
+1 4
+EXPLAIN FORMAT=JSON SELECT *
+FROM
+(
+SELECT CASE WHEN ((tab2.max_a>1) AND ((tab2.max_a=2) OR (tab2.max_a>2)))
+THEN 1 ELSE 0 END AS max_a,b
+FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
+) AS tab1
+WHERE (tab1.max_a=1);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "case when (tab2.max_a > 1 and (tab2.max_a = 2 or tab2.max_a > 2)) then 1 else 0 end = 1",
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "having_condition": "case when (max_a > 1 and (max_a = 2 or max_a > 2)) then 1 else 0 end = 1",
+ "filesort": {
+ "sort_key": "t1.b",
+ "temporary_table": {
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+SELECT *
+FROM
+(
+SELECT CASE WHEN ((tab2.b=2) OR (tab2.b=4))
+THEN 1 ELSE 0 END AS max_a,b
+FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
+) AS tab1
+WHERE (tab1.max_a=1);
+max_a b
+1 2
+1 4
+EXPLAIN FORMAT=JSON SELECT *
+FROM
+(
+SELECT CASE WHEN ((tab2.b=2) OR (tab2.b=4))
+THEN 1 ELSE 0 END AS max_a,b
+FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
+) AS tab1
+WHERE (tab1.max_a=1);
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "case when (tab2.b = 2 or tab2.b = 4) then 1 else 0 end = 1",
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "filesort": {
+ "sort_key": "t1.b",
+ "temporary_table": {
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 3,
+ "filtered": 100,
+ "attached_condition": "case when (t1.b = 2 or t1.b = 4) then 1 else 0 end = 1"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+DROP TABLE t1;
+#
+# MDEV-16803: pushdown condition with IN predicate in the derived table
+# defined with several SELECT statements
+#
+CREATE TABLE t1 (a INT, b INT);
+INSERT INTO t1 VALUES (1,2),(3,2),(1,1);
+SELECT * FROM
+(
+SELECT a,b,1 as c
+FROM t1
+UNION ALL
+SELECT a,b,2 as c
+FROM t1
+) AS tab
+WHERE ((a,b) IN ((1,2),(3,2)));
+a b c
+1 2 1
+3 2 1
+1 2 2
+3 2 2
+DROP TABLE t1;
+#
+# MDEV-17354: INSERT SELECT with condition pushdown into derived
+#
+CREATE TABLE t1 (f INT NOT NULL);
+INSERT INTO t1 VALUES (3), (7), (3);
+CREATE ALGORITHM= TEMPTABLE VIEW v1 AS SELECT * FROM ( SELECT * FROM t1 ) AS sq;
+INSERT INTO t1
+SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ) AS t WHERE f IS NOT NULL;
+EXPLAIN INSERT INTO t1
+SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ) AS t WHERE f IS NOT NULL;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL 144 Using where
+2 DERIVED <derived3> ALL NULL NULL NULL NULL 12
+2 DERIVED t1 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
+3 DERIVED t1 ALL NULL NULL NULL NULL 12
+EXPLAIN FORMAT=JSON INSERT INTO t1
+SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ) AS t WHERE f IS NOT NULL;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 144,
+ "filtered": 100,
+ "attached_condition": "t.f is not null",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ALL",
+ "rows": 12,
+ "filtered": 100,
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 12,
+ "filtered": 100
+ }
+ }
+ }
+ },
+ "block-nl-join": {
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 12,
+ "filtered": 100,
+ "attached_condition": "t1.f is not null"
+ },
+ "buffer_type": "flat",
+ "buffer_size": "256Kb",
+ "join_type": "BNL"
+ }
+ }
+ }
+ }
+ }
+}
+SELECT * FROM t1;
+f
+3
+7
+3
+3
+3
+3
+7
+7
+7
+3
+3
+3
+DELETE FROM t1;
+INSERT INTO t1 VALUES (3), (7), (3);
+INSERT INTO t1
+SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ON v1.f=t1.f) AS t
+WHERE f IS NOT NULL;
+EXPLAIN FORMAT=JSON INSERT INTO t1
+SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ON v1.f=t1.f) AS t
+WHERE f IS NOT NULL;
+EXPLAIN
+{
+ "query_block": {
+ "select_id": 1,
+ "table": {
+ "table_name": "<derived2>",
+ "access_type": "ALL",
+ "rows": 16,
+ "filtered": 100,
+ "attached_condition": "t.f is not null",
+ "materialized": {
+ "query_block": {
+ "select_id": 2,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 8,
+ "filtered": 100,
+ "attached_condition": "t1.f is not null"
+ },
+ "table": {
+ "table_name": "<derived3>",
+ "access_type": "ref",
+ "possible_keys": ["key0"],
+ "key": "key0",
+ "key_length": "4",
+ "used_key_parts": ["f"],
+ "ref": ["test.t1.f"],
+ "rows": 2,
+ "filtered": 100,
+ "materialized": {
+ "query_block": {
+ "select_id": 3,
+ "table": {
+ "table_name": "t1",
+ "access_type": "ALL",
+ "rows": 8,
+ "filtered": 100,
+ "attached_condition": "t1.f is not null"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+SELECT * FROM t1;
+f
+3
+7
+3
+3
+3
+7
+3
+3
+DROP VIEW v1;
+DROP TABLE t1;
+# End of 10.2 tests
+#
# MDEV-14579: pushdown conditions into materialized views/derived tables
# that are defined with EXIST or/and INTERSECT
#
@@ -10715,2833 +14121,7 @@ drop view v1;
alter table t3 drop index i1;
drop table t1,t2,t3;
#
-# MDEV-10782: condition extracted from a multiple equality
-# pushed into HAVING
-#
-CREATE TABLE t1 (i int);
-INSERT INTO t1 VALUES (1),(2);
-EXPLAIN EXTENDED
-SELECT *
-FROM ( SELECT * FROM ( SELECT MIN(i) as f FROM t1 ) sq1 ) AS sq2
-WHERE f = 8;
-id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY <derived3> ALL NULL NULL NULL NULL 2 100.00 Using where
-3 DERIVED t1 ALL NULL NULL NULL NULL 2 100.00
-Warnings:
-Note 1003 /* select#1 */ select `sq1`.`f` AS `f` from (/* select#3 */ select min(`test`.`t1`.`i`) AS `f` from `test`.`t1` having `f` = 8) `sq1` where `sq1`.`f` = 8
-SELECT *
-FROM ( SELECT * FROM ( SELECT MIN(i) as f FROM t1 ) sq1 ) AS sq2
-WHERE f = 8;
-f
-SELECT *
-FROM ( SELECT * FROM ( SELECT MIN(i) as f FROM t1 ) sq1 ) AS sq2
-WHERE f = 1;
-f
-1
-DROP TABLE t1;
-#
-# MDEV-10783: pushdown into constant view
-#
-CREATE TABLE t1 (i int) ENGINE=MyISAM;
-CREATE VIEW v AS SELECT 5;
-SELECT * FROM t1 WHERE 1 IN ( SELECT * FROM v );
-i
-DROP VIEW v;
-DROP TABLE t1;
-#
-# MDEV-10785: second execution of a query with condition
-# pushed into view
-#
-CREATE TABLE t1 (i int);
-CREATE VIEW v1 AS SELECT i FROM t1 WHERE i < 5;
-CREATE FUNCTION f (in1 int) RETURNS int RETURN in1;
-CREATE VIEW v2 AS SELECT * FROM v1 GROUP BY i;
-PREPARE stmt FROM "SELECT * FROM v2 WHERE f(0) <> 2";
-EXECUTE stmt;
-i
-EXECUTE stmt;
-i
-DROP FUNCTION f;
-DROP VIEW v2,v1;
-DROP TABLE t1;
-#
-# MDEV-10884: condition pushdown into derived specified by
-# 1. unit with SELECT containing ORDER BY ... LIMIT
-# 2. unit containing global ORDER BY ... LIMIT
-#
-create table t1(a int);
-insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
-select a from t1 order by a limit 5;
-a
-0
-1
-2
-3
-4
-set statement optimizer_switch='condition_pushdown_for_derived=off' for
-select * from (select a from t1 order by a limit 5) t where t.a not in (1,2,3);
-a
-0
-4
-set statement optimizer_switch='condition_pushdown_for_derived=on' for
-select * from (select a from t1 order by a limit 5) t where t.a not in (1,2,3);
-a
-0
-4
-select a from t1 where a < 4 union select a from t1 where a > 5
-order by a limit 5;
-a
-0
-1
-2
-3
-6
-set statement optimizer_switch='condition_pushdown_for_derived=off' for
-select * from
-(select a from t1 where a < 4 union select a from t1 where a > 5
-order by a limit 5) t where t.a not in (2,9);
-a
-0
-1
-3
-6
-set statement optimizer_switch='condition_pushdown_for_derived=on' for
-select * from
-(select a from t1 where a < 4 union select a from t1 where a > 5
-order by a limit 5) t where t.a not in (2,9);
-a
-0
-1
-3
-6
-drop table t1;
-#
-# MDEV-11072: pushdown of the condition obtained
-# after constant row substitution
-#
-CREATE TABLE t1 (a INT) ENGINE=MyISAM;
-CREATE TABLE t2 (b INT) ENGINE=MyISAM;
-CREATE OR REPLACE VIEW v2 AS SELECT * FROM t2;
-CREATE TABLE t3 (c INT) ENGINE=MyISAM;
-CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v3 AS SELECT * FROM t3;
-SELECT * FROM t1 WHERE a IN (
-SELECT b FROM v2 WHERE b < a OR b IN (
-SELECT c FROM v3 WHERE c = a
-)
-);
-a
-INSERT INTO t1 VALUES (2);
-INSERT INTO t2 VALUES (3), (2);
-INSERT INTO t3 VALUES (4), (1), (2), (7);
-SELECT * FROM t1 WHERE a IN (
-SELECT b FROM v2 WHERE b < a OR b IN (
-SELECT c FROM v3 WHERE c = a
-)
-);
-a
-2
-EXPLAIN FORMAT=JSON
-SELECT * FROM t1 WHERE a IN (
-SELECT b FROM v2 WHERE b < a OR b IN (
-SELECT c FROM v3 WHERE c = a
-)
-);
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "const_condition": "0 or <in_optimizer>(2,<exists>(subquery#3))",
- "table": {
- "table_name": "t1",
- "access_type": "system",
- "rows": 1,
- "filtered": 100
- },
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "t2.b = 2",
- "first_match": "t1"
- },
- "subqueries": [
- {
- "query_block": {
- "select_id": 3,
- "table": {
- "table_name": "<derived5>",
- "access_type": "index_subquery",
- "possible_keys": ["key0"],
- "key": "key0",
- "key_length": "5",
- "used_key_parts": ["c"],
- "ref": ["func"],
- "rows": 2,
- "filtered": 100,
- "materialized": {
- "query_block": {
- "select_id": 5,
- "table": {
- "table_name": "t3",
- "access_type": "ALL",
- "rows": 4,
- "filtered": 100,
- "attached_condition": "t3.c = 2"
- }
- }
- }
- }
- }
- }
- ]
- }
-}
-CREATE TABLE t4 (d INT, e INT) ENGINE=MyISAM;
-INSERT INTO t4 VALUES (1,10),(3,11),(2,10),(2,20),(3,21);
-CREATE OR REPLACE VIEW v4 AS
-SELECT d, sum(e) AS s FROM t4 GROUP BY d;
-set statement optimizer_switch='condition_pushdown_for_derived=off' for SELECT * FROM t1 WHERE a IN (
-SELECT b FROM v2 WHERE b < a OR b IN (
-SELECT d FROM v4 WHERE s > a
-)
-);
-a
-2
-SELECT * FROM t1 WHERE a IN (
-SELECT b FROM v2 WHERE b < a OR b IN (
-SELECT d FROM v4 WHERE s > a
-)
-);
-a
-2
-explain SELECT * FROM t1 WHERE a IN (
-SELECT b FROM v2 WHERE b < a OR b IN (
-SELECT d FROM v4 WHERE s > a
-)
-);
-id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 system NULL NULL NULL NULL 1
-1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; FirstMatch(t1)
-3 DEPENDENT SUBQUERY <derived5> index_subquery key0 key0 5 func 2 Using where
-5 DERIVED t4 ALL NULL NULL NULL NULL 5 Using temporary; Using filesort
-explain format=json SELECT * FROM t1 WHERE a IN (
-SELECT b FROM v2 WHERE b < a OR b IN (
-SELECT d FROM v4 WHERE s > a
-)
-);
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "const_condition": "0 or <in_optimizer>(2,<exists>(subquery#3))",
- "table": {
- "table_name": "t1",
- "access_type": "system",
- "rows": 1,
- "filtered": 100
- },
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "t2.b = 2",
- "first_match": "t1"
- },
- "subqueries": [
- {
- "query_block": {
- "select_id": 3,
- "table": {
- "table_name": "<derived5>",
- "access_type": "index_subquery",
- "possible_keys": ["key0"],
- "key": "key0",
- "key_length": "5",
- "used_key_parts": ["d"],
- "ref": ["func"],
- "rows": 2,
- "filtered": 100,
- "materialized": {
- "query_block": {
- "select_id": 5,
- "having_condition": "s > 2",
- "filesort": {
- "sort_key": "t4.d",
- "temporary_table": {
- "table": {
- "table_name": "t4",
- "access_type": "ALL",
- "rows": 5,
- "filtered": 100
- }
- }
- }
- }
- }
- }
- }
- }
- ]
- }
-}
-DROP VIEW v2,v3,v4;
-DROP TABLE t1,t2,t3,t4;
-#
-# MDEV-10800: pushdown of the condition obtained
-# after constant row substitution
-#
-CREATE TABLE t1 (a INT) ENGINE=MyISAM;
-INSERT INTO t1 VALUES (1);
-CREATE TABLE t2 (b INT) ENGINE=MyISAM;
-INSERT INTO t2 VALUES (3),(4);
-CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2;
-SELECT * FROM
-( SELECT * FROM t1
-WHERE EXISTS ( SELECT * FROM v2 WHERE b = a ) ) AS sq;
-a
-EXPLAIN FORMAT=JSON
-SELECT * FROM
-( SELECT * FROM t1
-WHERE EXISTS ( SELECT * FROM v2 WHERE b = a ) ) AS sq;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "const_condition": "<in_optimizer>(1,exists(subquery#3))",
- "table": {
- "table_name": "t1",
- "access_type": "system",
- "rows": 1,
- "filtered": 100
- },
- "subqueries": [
- {
- "query_block": {
- "select_id": 3,
- "table": {
- "table_name": "<derived4>",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "v2.b = 1",
- "materialized": {
- "query_block": {
- "select_id": 4,
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "t2.b = 1"
- }
- }
- }
- }
- }
- }
- ]
- }
-}
-DROP VIEW v2;
-DROP TABLE t1,t2;
-#
-# MDEV-11102: condition pushdown into materialized inner table
-# of outer join is not applied as not being valid
-#
-CREATE TABLE t1 (a INT);
-INSERT INTO t1 VALUES (0),(2);
-CREATE TABLE t2 (b INT);
-INSERT INTO t2 VALUES (1),(2);
-CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2;
-SELECT * FROM t1 LEFT JOIN t2 ON a = b WHERE b IS NULL;
-a b
-0 NULL
-SELECT * FROM t1 LEFT JOIN v2 ON a = b WHERE b IS NULL;
-a b
-0 NULL
-EXPLAIN FORMAT=JSON
-SELECT * FROM t1 LEFT JOIN v2 ON a = b WHERE b IS NULL;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100
- },
- "table": {
- "table_name": "<derived2>",
- "access_type": "ref",
- "possible_keys": ["key0"],
- "key": "key0",
- "key_length": "5",
- "used_key_parts": ["b"],
- "ref": ["test.t1.a"],
- "rows": 2,
- "filtered": 100,
- "attached_condition": "trigcond(v2.b is null) and trigcond(trigcond(t1.a is not null))",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100
- }
- }
- }
- }
- }
-}
-DROP VIEW v2;
-DROP TABLE t1,t2;
-#
-# MDEV-11103: pushdown condition with ANY subquery
-#
-CREATE TABLE t1 (i INT);
-CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
-INSERT INTO t1 VALUES (1),(2);
-EXPLAIN FORMAT=JSON
-SELECT * FROM v1 WHERE i <= ANY ( SELECT 3 );
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<derived3>",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "<nop>(v1.i <= 3)",
- "materialized": {
- "query_block": {
- "select_id": 3,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "<nop>(t1.i <= 3)"
- }
- }
- }
- }
- }
-}
-Warnings:
-Note 1249 Select 2 was reduced during optimization
-SELECT * FROM v1 WHERE i <= ANY ( SELECT 3 );
-i
-1
-2
-DROP VIEW v1;
-DROP TABLE t1;
-#
-# MDEV-11315: condition with outer reference to mergeable derived
-#
-CREATE TABLE t1 (pk1 INT PRIMARY KEY, a INT, b INT) ENGINE=MyISAM;
-INSERT INTO t1 VALUES (10,7,1),(11,0,2);
-CREATE TABLE t2 (pk2 INT PRIMARY KEY, c INT, d DATETIME) ENGINE=MyISAM;
-INSERT INTO t2 VALUES
-(1,4,'2008-09-27 00:34:58'),
-(2,5,'2007-05-28 00:00:00'),
-(3,6,'2009-07-25 09:21:20');
-CREATE VIEW v1 AS SELECT * FROM t1;
-CREATE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2;
-SELECT * FROM v1 AS sq
-WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
-pk1 a b
-10 7 1
-11 0 2
-EXPLAIN FORMAT=JSON
-SELECT * FROM v1 AS sq
-WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "<in_optimizer>(t1.b,<exists>(subquery#2)) or t1.b = 100"
- },
- "subqueries": [
- {
- "query_block": {
- "select_id": 2,
- "table": {
- "table_name": "<derived4>",
- "access_type": "index_subquery",
- "possible_keys": ["key0"],
- "key": "key0",
- "key_length": "4",
- "used_key_parts": ["pk2"],
- "ref": ["func"],
- "rows": 2,
- "filtered": 100,
- "materialized": {
- "query_block": {
- "select_id": 4,
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100
- }
- }
- }
- }
- }
- }
- ]
- }
-}
-SELECT * FROM ( SELECT * FROM t1 ) AS sq
-WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
-pk1 a b
-10 7 1
-11 0 2
-EXPLAIN FORMAT=JSON
-SELECT * FROM ( SELECT * FROM t1 ) AS sq
-WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "<in_optimizer>(t1.b,<exists>(subquery#3)) or t1.b = 100"
- },
- "subqueries": [
- {
- "query_block": {
- "select_id": 3,
- "table": {
- "table_name": "<derived4>",
- "access_type": "index_subquery",
- "possible_keys": ["key0"],
- "key": "key0",
- "key_length": "4",
- "used_key_parts": ["pk2"],
- "ref": ["func"],
- "rows": 2,
- "filtered": 100,
- "materialized": {
- "query_block": {
- "select_id": 4,
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100
- }
- }
- }
- }
- }
- }
- ]
- }
-}
-DROP VIEW v1,v2;
-DROP TABLE t1,t2;
-#
-# MDEV-11313: pushdown of the condition obtained
-# after constant row substitution
-#
-CREATE TABLE t1 (a INT) ENGINE=MyISAM;
-INSERT INTO t1 VALUES (1),(2);
-CREATE TABLE t2 (b INT) ENGINE=MyISAM;
-INSERT INTO t2 VALUES (50);
-CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
-SELECT ( SELECT COUNT(*) FROM v1 WHERE a = t2.b ) AS f FROM t2 GROUP BY f;
-f
-0
-EXPLAIN FORMAT=JSON
-SELECT ( SELECT COUNT(*) FROM v1 WHERE a = t2.b ) AS f FROM t2 GROUP BY f;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "t2",
- "access_type": "system",
- "rows": 1,
- "filtered": 100
- },
- "subqueries": [
- {
- "query_block": {
- "select_id": 2,
- "table": {
- "table_name": "<derived3>",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "v1.a = 50",
- "materialized": {
- "query_block": {
- "select_id": 3,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "t1.a = 50"
- }
- }
- }
- }
- }
- }
- ]
- }
-}
-CREATE TABLE t3 (a INT, b INT) ENGINE=MYISAM;
-INSERT INTO t3 VALUES (1,10),(3,11),(2,10),(2,20),(3,21);
-CREATE VIEW v2 AS SELECT a, sum(b) AS s FROM t3 GROUP BY a ;
-SELECT ( SELECT COUNT(*) FROM v2 WHERE s < t2.b ) AS f FROM t2 GROUP BY f;
-f
-3
-EXPLAIN FORMAT=JSON
-SELECT ( SELECT COUNT(*) FROM v2 WHERE s < t2.b ) AS f FROM t2 GROUP BY f;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "t2",
- "access_type": "system",
- "rows": 1,
- "filtered": 100
- },
- "subqueries": [
- {
- "query_block": {
- "select_id": 2,
- "table": {
- "table_name": "<derived3>",
- "access_type": "ALL",
- "rows": 5,
- "filtered": 100,
- "attached_condition": "v2.s < 50",
- "materialized": {
- "query_block": {
- "select_id": 3,
- "having_condition": "s < 50",
- "filesort": {
- "sort_key": "t3.a",
- "temporary_table": {
- "table": {
- "table_name": "t3",
- "access_type": "ALL",
- "rows": 5,
- "filtered": 100
- }
- }
- }
- }
- }
- }
- }
- }
- ]
- }
-}
-DROP VIEW v1,v2;
-DROP TABLE t1,t2,t3;
-#
-# MDEV-10882: pushdown of the predicate with cached value
-#
-CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL) ENGINE=MyISAM;
-CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
-INSERT INTO t1 VALUES (1,2),(3,4);
-CREATE TABLE t2 (c INT NOT NULL) ENGINE=MyISAM;
-INSERT INTO t2 VALUES (5),(6);
-SELECT a, GROUP_CONCAT(b) FROM v1
-WHERE b IN ( SELECT COUNT(c) FROM t2 ) GROUP BY a;
-a GROUP_CONCAT(b)
-1 2
-EXPLAIN FORMAT=JSON
-SELECT a, GROUP_CONCAT(b) FROM v1
-WHERE b IN ( SELECT COUNT(c) FROM t2 ) GROUP BY a;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<subquery2>",
- "access_type": "system",
- "rows": 1,
- "filtered": 100,
- "materialized": {
- "unique": 1,
- "query_block": {
- "select_id": 2,
- "table": {
- "message": "Select tables optimized away"
- }
- }
- }
- },
- "read_sorted_file": {
- "filesort": {
- "sort_key": "v1.a",
- "table": {
- "table_name": "<derived3>",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "v1.b = 2",
- "materialized": {
- "query_block": {
- "select_id": 3,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "t1.b = 2"
- }
- }
- }
- }
- }
- }
- }
-}
-DROP VIEW v1;
-DROP TABLE t1,t2;
-#
-# MDEV-10836: pushdown of the predicate with cached value
-#
-CREATE TABLE t (pk INT PRIMARY KEY, f INT) ENGINE=MyISAM;
-CREATE ALGORITHM=TEMPTABLE VIEW v AS SELECT * FROM t;
-INSERT INTO t VALUES (1,1),(3,2);
-SELECT * FROM v AS v1, v AS v2
-WHERE v2.pk > v1.f AND v1.f IN ( SELECT COUNT(pk) FROM t );
-pk f pk f
-3 2 3 2
-EXPLAIN FORMAT=JSON
-SELECT * FROM v AS v1, v AS v2
-WHERE v2.pk > v1.f AND v1.f IN ( SELECT COUNT(pk) FROM t );
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<subquery2>",
- "access_type": "system",
- "rows": 1,
- "filtered": 100,
- "materialized": {
- "unique": 1,
- "query_block": {
- "select_id": 2,
- "table": {
- "message": "Select tables optimized away"
- }
- }
- }
- },
- "table": {
- "table_name": "<derived3>",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "v1.f = 2",
- "materialized": {
- "query_block": {
- "select_id": 3,
- "table": {
- "table_name": "t",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "t.f = 2"
- }
- }
- }
- },
- "block-nl-join": {
- "table": {
- "table_name": "<derived4>",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "v2.pk > 2"
- },
- "buffer_type": "flat",
- "buffer_size": "256Kb",
- "join_type": "BNL",
- "materialized": {
- "query_block": {
- "select_id": 4,
- "table": {
- "table_name": "t",
- "access_type": "range",
- "possible_keys": ["PRIMARY"],
- "key": "PRIMARY",
- "key_length": "4",
- "used_key_parts": ["pk"],
- "rows": 2,
- "filtered": 100,
- "index_condition": "t.pk > 2"
- }
- }
- }
- }
- }
-}
-DROP VIEW v;
-DROP TABLE t;
-#
-# MDEV-11488: pushdown of the predicate with cached value
-#
-CREATE TABLE t1 (i INT) ENGINE=MyISAM;
-INSERT INTO t1 VALUES (1),(3),(2);
-CREATE TABLE t2 (j INT, KEY(j)) ENGINE=MyISAM;
-INSERT INTO t2 VALUES (3),(4);
-SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
-WHERE i IN ( SELECT MIN(j) FROM t2 );
-i
-3
-EXPLAIN FORMAT=JSON
-SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
-WHERE i IN ( SELECT MIN(j) FROM t2 );
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<subquery3>",
- "access_type": "system",
- "rows": 1,
- "filtered": 100,
- "materialized": {
- "unique": 1,
- "query_block": {
- "select_id": 3,
- "table": {
- "message": "Select tables optimized away"
- }
- }
- }
- },
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "sq.i = 3",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "t1.i = 3"
- }
- }
- }
- }
- }
-}
-UPDATE t2 SET j = 2 WHERE j = 3;
-SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
-WHERE i IN ( SELECT MIN(j) FROM t2 );
-i
-2
-DROP TABLE t1,t2;
-CREATE TABLE t1 (i FLOAT) ENGINE=MyISAM;
-INSERT INTO t1 VALUES (1.5),(3.2),(2.71);
-CREATE TABLE t2 (j FLOAT, KEY(j)) ENGINE=MyISAM;
-INSERT INTO t2 VALUES (3.2),(2.71);
-SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
-WHERE i IN ( SELECT MIN(j) FROM t2 );
-i
-2.71
-EXPLAIN FORMAT=JSON
-SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
-WHERE i IN ( SELECT MIN(j) FROM t2 );
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<subquery3>",
- "access_type": "system",
- "rows": 1,
- "filtered": 100,
- "materialized": {
- "unique": 1,
- "query_block": {
- "select_id": 3,
- "table": {
- "message": "Select tables optimized away"
- }
- }
- }
- },
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "sq.i = 2.7100000381469727",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "t1.i = 2.7100000381469727"
- }
- }
- }
- }
- }
-}
-DROP TABLE t1,t2;
-CREATE TABLE t1 (i DECIMAL(10,2)) ENGINE=MyISAM;
-INSERT INTO t1 VALUES (1.5),(3.21),(2.47);
-CREATE TABLE t2 (j DECIMAL(10,2), KEY(j)) ENGINE=MyISAM;
-INSERT INTO t2 VALUES (3.21),(4.55);
-SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
-WHERE i IN ( SELECT MIN(j) FROM t2 );
-i
-3.21
-EXPLAIN FORMAT=JSON
-SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
-WHERE i IN ( SELECT MIN(j) FROM t2 );
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<subquery3>",
- "access_type": "system",
- "rows": 1,
- "filtered": 100,
- "materialized": {
- "unique": 1,
- "query_block": {
- "select_id": 3,
- "table": {
- "message": "Select tables optimized away"
- }
- }
- }
- },
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "sq.i = 3.21",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "t1.i = 3.21"
- }
- }
- }
- }
- }
-}
-DROP TABLE t1,t2;
-CREATE TABLE t1 (i VARCHAR(32)) ENGINE=MyISAM;
-INSERT INTO t1 VALUES ('cc'),('aa'),('ddd');
-CREATE TABLE t2 (j VARCHAR(16), KEY(j)) ENGINE=MyISAM;
-INSERT INTO t2 VALUES ('bbb'),('aa');
-SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
-WHERE i IN ( SELECT MIN(j) FROM t2 );
-i
-aa
-EXPLAIN FORMAT=JSON
-SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
-WHERE i IN ( SELECT MIN(j) FROM t2 );
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<subquery3>",
- "access_type": "system",
- "rows": 1,
- "filtered": 100,
- "materialized": {
- "unique": 1,
- "query_block": {
- "select_id": 3,
- "table": {
- "message": "Select tables optimized away"
- }
- }
- }
- },
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "sq.i = 'aa'",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "t1.i = 'aa'"
- }
- }
- }
- }
- }
-}
-DROP TABLE t1,t2;
-CREATE TABLE t1 (i DATETIME) ENGINE=MyISAM;
-INSERT INTO t1 VALUES
-('2008-09-27 00:34:58'),('2007-05-28 00:00:00'), ('2009-07-25 09:21:20');
-CREATE TABLE t2 (j DATETIME, KEY(j)) ENGINE=MyISAM;
-INSERT INTO t2 VALUES
-('2007-05-28 00:00:00'), ('2010-08-25 00:00:00');
-SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
-WHERE i IN ( SELECT MIN(j) FROM t2 );
-i
-2007-05-28 00:00:00
-EXPLAIN FORMAT=JSON
-SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
-WHERE i IN ( SELECT MIN(j) FROM t2 );
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<subquery3>",
- "access_type": "system",
- "rows": 1,
- "filtered": 100,
- "materialized": {
- "unique": 1,
- "query_block": {
- "select_id": 3,
- "table": {
- "message": "Select tables optimized away"
- }
- }
- }
- },
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "sq.i = '2007-05-28 00:00:00'",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "t1.i = TIMESTAMP'2007-05-28 00:00:00'"
- }
- }
- }
- }
- }
-}
-DROP TABLE t1,t2;
-CREATE TABLE t1 (i DATE) ENGINE=MyISAM;
-INSERT INTO t1 VALUES ('2008-09-27'),('2007-05-28'), ('2009-07-25');
-CREATE TABLE t2 (j DATE, KEY(j)) ENGINE=MyISAM;
-INSERT INTO t2 VALUES ('2007-05-28'), ('2010-08-25');
-SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
-WHERE i IN ( SELECT MIN(j) FROM t2 );
-i
-2007-05-28
-EXPLAIN FORMAT=JSON
-SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
-WHERE i IN ( SELECT MIN(j) FROM t2 );
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<subquery3>",
- "access_type": "system",
- "rows": 1,
- "filtered": 100,
- "materialized": {
- "unique": 1,
- "query_block": {
- "select_id": 3,
- "table": {
- "message": "Select tables optimized away"
- }
- }
- }
- },
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "sq.i = '2007-05-28'",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "t1.i = DATE'2007-05-28'"
- }
- }
- }
- }
- }
-}
-DROP TABLE t1,t2;
-CREATE TABLE t1 (i TIME) ENGINE=MyISAM;
-INSERT INTO t1 VALUES ('00:34:58'),('10:00:02'), ('09:21:20');
-CREATE TABLE t2 (j TIME, KEY(j)) ENGINE=MyISAM;
-INSERT INTO t2 VALUES ('10:00:02'), ('11:00:10');
-SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
-WHERE i IN ( SELECT MIN(j) FROM t2 );
-i
-10:00:02
-EXPLAIN FORMAT=JSON
-SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq
-WHERE i IN ( SELECT MIN(j) FROM t2 );
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<subquery3>",
- "access_type": "system",
- "rows": 1,
- "filtered": 100,
- "materialized": {
- "unique": 1,
- "query_block": {
- "select_id": 3,
- "table": {
- "message": "Select tables optimized away"
- }
- }
- }
- },
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "sq.i = '10:00:02'",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "t1.i = TIME'10:00:02'"
- }
- }
- }
- }
- }
-}
-DROP TABLE t1,t2;
-#
-# MDEV-11593: pushdown of condition with NULLIF
-#
-CREATE TABLE t1 (i INT);
-CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
-INSERT INTO t1 VALUES (2), (1);
-SELECT * FROM v1 WHERE NULLIF(1, i);
-i
-2
-EXPLAIN FORMAT=JSON
-SELECT * FROM v1 WHERE NULLIF(1, i);
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "nullif(1,v1.i)",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "nullif(1,t1.i)"
- }
- }
- }
- }
- }
-}
-DROP VIEW v1;
-DROP TABLE t1;
-#
-# MDEV-11608: pushdown of the predicate with cached null value
-#
-CREATE TABLE t1 (c VARCHAR(3));
-CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
-INSERT INTO t1 VALUES ('foo'),('bar');
-CREATE TABLE t2 (c VARCHAR(3));
-INSERT INTO t2 VALUES ('foo'),('xyz');
-SELECT * FROM v1 WHERE v1.c IN ( SELECT MIN(c) FROM t2 WHERE 0 );
-c
-EXPLAIN FORMAT=JSON
-SELECT * FROM v1 WHERE v1.c IN ( SELECT MIN(c) FROM t2 WHERE 0 );
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<subquery2>",
- "access_type": "system",
- "rows": 1,
- "filtered": 100,
- "materialized": {
- "unique": 1,
- "query_block": {
- "select_id": 2,
- "table": {
- "message": "Impossible WHERE"
- }
- }
- }
- },
- "table": {
- "table_name": "<derived3>",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "v1.c = NULL",
- "materialized": {
- "query_block": {
- "select_id": 3,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "t1.c = NULL"
- }
- }
- }
- }
- }
-}
-DROP VIEW v1;
-DROP TABLE t1,t2;
-CREATE TABLE t1 (d DECIMAL(10,2));
-CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
-INSERT INTO t1 VALUES (5.37),(1.1);
-CREATE TABLE t2 (d DECIMAL(10,2));
-INSERT INTO t2 VALUES ('1.1'),('2.23');
-SELECT * FROM v1 WHERE v1.d IN ( SELECT MIN(d) FROM t2 WHERE 0 );
-d
-DROP VIEW v1;
-DROP TABLE t1,t2;
-#
-# MDEV-11820: second execution of PS for query
-# with false subquery predicate in WHERE
-#
-CREATE TABLE t1 (c VARCHAR(3)) ENGINE=MyISAM;
-INSERT INTO t1 VALUES ('foo'),('bar');
-CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
-CREATE TABLE t2 (a INT);
-INSERT INTO t2 VALUES (3), (4);
-PREPARE stmt1 FROM
-" SELECT * FROM v1 WHERE 1 IN (SELECT a FROM t2) OR c = 'foo'";
-PREPARE stmt2 FROM
-"EXPLAIN FORMAT=JSON
- SELECT * FROM v1 WHERE 1 IN (SELECT a FROM t2) OR c = 'foo'";
-EXECUTE stmt1;
-c
-foo
-EXECUTE stmt2;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<derived3>",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "v1.c = 'foo'",
- "materialized": {
- "query_block": {
- "select_id": 3,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "t1.c = 'foo'"
- }
- }
- }
- },
- "subqueries": [
- {
- "query_block": {
- "select_id": 2,
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "1 = t2.a"
- }
- }
- }
- ]
- }
-}
-INSERT INTO t2 SELECT a+1 FROM t2;
-INSERT INTO t2 SELECT a+1 FROM t2;
-INSERT INTO t2 SELECT a+1 FROM t2;
-INSERT INTO t2 SELECT a+1 FROM t2;
-INSERT INTO t2 SELECT a+1 FROM t2;
-INSERT INTO t2 SELECT a+1 FROM t2;
-EXECUTE stmt1;
-c
-foo
-EXECUTE stmt2;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<derived3>",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "<cache>(<in_optimizer>(1,<exists>(subquery#2))) or v1.c = 'foo'",
- "materialized": {
- "query_block": {
- "select_id": 3,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100
- }
- }
- }
- },
- "subqueries": [
- {
- "query_block": {
- "select_id": 2,
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 128,
- "filtered": 100,
- "attached_condition": "1 = t2.a"
- }
- }
- }
- ]
- }
-}
-DEALLOCATE PREPARE stmt1;
-DEALLOCATE PREPARE stmt2;
-DROP VIEW v1;
-DROP TABLE t1,t2;
-#
-# MDEV-12373: pushdown into derived with side effects is prohibited
-#
-CREATE TABLE sales_documents (
-id int NOT NULL AUTO_INCREMENT,
-sale_id int NULL DEFAULT NULL,
-type tinyint unsigned NULL DEFAULT NULL,
-data text NULL DEFAULT NULL COLLATE 'utf8_unicode_ci',
-date date NULL DEFAULT NULL,
-order_number int unsigned NULL DEFAULT NULL,
-created_at int NULL DEFAULT NULL,
-updated_at int NULL DEFAULT NULL,
-generated tinyint NOT NULL DEFAULT '0',
-synced_at int NOT NULL DEFAULT '0',
-sum decimal(13,2) NOT NULL DEFAULT '0',
-PRIMARY KEY (id)
-);
-INSERT INTO sales_documents
-(id, sale_id, type, order_number, data, created_at,
-updated_at, date, generated, synced_at, sum)
-VALUES
-(555, 165, 3, 5, '{}', 1486538300, 1486722835, '2017-02-17', 0, 1486538313, 2320.00),
-(556, 165, 2, 3, '{}', 1486538304, 1486563125, '2017-02-08', 1, 1486538302, 2320.00),
-(557, 158, 2, 2, '{}', 1486538661, 1486538661, '2017-02-08', 0, 1486538660, 2320.00),
-(558, 171, 1, 3, '{}', 1486539104, 1488203405, '2017-02-08', 1, 1486539102, 23230.00),
-(559, 171, 2, 5, '{}', 1486549233, 1487146010, '2017-02-08', 1, 1486549225, 37690.00),
-(560, 172, 1, 1, '{}', 1486658260, 1488203409, '2017-02-09', 1, 1486658256, 40312.00),
-(561, 172, 2, 1, '{}', 1486711997, 1486711997, '2017-02-10', 1, 1486711996, 40312.00),
-(562, 172, 3, 1, '{}', 1486712104, 1486721395, '2017-02-10', 1, 1486712101, 40312.00),
-(563, 171, 3, 2, '{}', 1486712953, 1486720244, '2017-02-10', 1, 1486712910, 23230.00),
-(564, 170, 1, 2, '{}', 1486715948, 1488203410, '2017-02-10', 1, 1486715930, 28873.00),
-(565, 170, 3, 3, '{}', 1486716782, 1486717426, '2017-02-10', 1, 1486716779, 61948.00),
-(566, 166, 3, 4, '{}', 1486720947, 1486720947, '2017-02-10', 1, 1486720945, 4640.00),
-(567, 167, 3, 5, '{}', 1486722741, 1486722783, '2017-02-26', 0, 1486722738, 14755.00),
-(568, 165, 1, 4, '{}', 1486722849, 1486722849, '2017-02-10', 0, 1486722846, 2320.00),
-(569, 173, 2, 2, '{}', 1486723073, 1487071275, '2017-02-10', 1, 1486723071, 14282.00),
-(570, 173, 1, 4, '{}', 1486723100, 1488203412, '2017-02-10', 1, 1486723099, 14282.00),
-(571, 167, 2, 4, '{}', 1486730859, 1486730859, '2017-02-10', 1, 1486730856, 18655.00),
-(572, 167, 1, 5, '{}', 1486730883, 1488203412, '2017-02-10', 1, 1486730877, 18655.00),
-(573, 174, 2, 51, '{}', 1486731622, 1487060259, '2017-02-10', 1, 1486731620, 7140.00),
-(574, 174, 3, 5, '{}', 1486993472, 1486993472, '2017-02-13', 1, 1488216147, 28020.00),
-(575, 174, 1, 6, '{}', 1486993530, 1488203412, '2017-02-13', 1, 1486993505, 7140.00),
-(576, 173, 3, 6, '{}', 1487071425, 1487071425, '2017-02-14', 0, 1487071422, 14282.00),
-(577, 178, 2, 6, '{}', 1487327372, 1487327372, '2017-02-17', 1, 1487327370, 12321.00),
-(578, 177, 2, 7, '{}', 1487327394, 1487327394, '2017-02-17', 0, 1487327391, 4270.00),
-(579, 182, 3, 6, '{}', 1487750589, 1487751693, '2017-02-22', 1, 1487751688, 4270.00),
-(580, 182, 2, 7, '{}', 1487750601, 1487750663, '2017-02-22', 1, 1487750598, 4270.00),
-(581, 182, 1, 7, '{}', 1487750694, 1488203412, '2017-02-22', 1, 1487750692, 4270.00),
-(582, 185, 3, 7, '{}', 1487774051, 1487774051, '2017-02-22', 0, 1487774043, 8913.00),
-(583, 184, 3, 7, '{}', 1487774071, 1487774235, '2017-02-22', 0, 1487774093, 3285.00),
-(584, 184, 2, 8, '{}', 1487774074, 1487774074, '2017-02-22', 0, 1487774073, 3285.00),
-(585, 184, 1, 8, '{}', 1487774081, 1487774081, '2017-02-22', 0, 1487774075, 3285.00),
-(586, 193, 2, 8, '{}', 1487955294, 1487955318, '2017-02-24', 0, 1487955311, 4270.00),
-(587, 193, 1, 8, '{}', 1487955324, 1487955324, '2017-02-24', 0, 1487955320, 4270.00),
-(588, 193, 3, 7, '{}', 1487955341, 1487955341, '2017-02-24', 0, 1487955325, 4270.00),
-(589, 186, 1, 8, '{}', 1487957291, 1487957464, '2017-02-24', 0, 1487957459, 6960.00),
-(590, 186, 2, 8, '{}', 1487957308, 1487957468, '2017-02-24', 0, 1487957465, 6960.00),
-(591, 186, 3, 7, '{}', 1487957312, 1487957473, '2017-02-24', 0, 1487957469, 6960.00),
-(592, 194, 1, 8, '{}', 1488193293, 1488203412, '2017-02-27', 1, 1488193280, 2320.00),
-(593, 194, 2, 8, '{}', 1488193304, 1488193304, '2017-02-27', 1, 1488193303, 2320.00),
-(594, 210, 1, 9, '{}', 1488198896, 1488198896, '2017-02-27', 0, 1488198885, 4270.00),
-(595, 210, 2, 12, '{}', 1488198901, 1488198901, '2017-02-27', 1, 1488532585, 4270.00),
-(596, 210, 3, 10, '{}', 1488198904, 1488198904, '2017-02-27', 1, 1488532565, 4270.00),
-(597, 209, 2, 9, '{}', 1488200016, 1488450772, '2017-02-27', 1, 1488450449, 4270.00),
-(598, 209, 1, 9, '{}', 1488200020, 1488200063, '2017-02-27', 1, 1488200017, 4271.00),
-(599, 209, 3, 7, '{}', 1488200053, 1488200053, '2017-02-27', 0, 1488200021, 4271.00),
-(600, 211, 2, 10, '{}', 1488216265, 1489402027, '2017-02-27', 1, 1488216264, 2320.00),
-(601, 211, 3, 7, '{}', 1488216281, 1488216281, '2017-02-27', 1, 1488216276, 2320.00),
-(602, 211, 1, 10, '{}', 1488216283, 1488216283, '2017-02-27', 1, 1488216282, 2320.00),
-(603, 198, 2, 11, '{}', 1488280125, 1488280125, '2017-02-28', 0, 1488280095, 4270.00),
-(604, 198, 1, 11, '{}', 1488280160, 1488280160, '2017-02-28', 0, 1488280126, 4270.00),
-(605, 198, 3, 8, '{}', 1488280440, 1488280440, '2017-02-28', 0, 1488280435, 4270.00),
-(606, 212, 1, 12, '{}', 1488286301, 1489402168, '2017-02-28', 1, 1488286295, 13825.00),
-(607, 212, 3, 8, '{}', 1488289644, 1488289690, '2017-02-28', 1, 1488289642, 25295.00),
-(608, 212, 2, 13, '{}', 1488290350, 1488290431, '2017-02-28', 1, 1488290347, 13133.75),
-(609, 213, 1, 11, '{}', 1488529470, 1488529470, '2017-03-03', 1, 1488529461, 5660.00),
-(610, 213, 2, 11, '{}', 1488529484, 1488529484, '2017-03-03', 1, 1488529479, 5660.00),
-(611, 213, 3, 9, '{}', 1488529493, 1488529493, '2017-03-03', 1, 1488529489, 5660.00),
-(612, 197, 2, 13, '{}', 1489400715, 1489400715, '2017-03-13', 0, 1489398959, 4270.00),
-(613, 219, 3, 11, '{}', 1490084337, 1490181958, '2017-03-21', 1, 1490084334, 73526.00),
-(614, 216, 3, 11, '{}', 1490085757, 1490086717, '2017-03-21', 0, 1490085755, 5377.00);
-SELECT * FROM
-(SELECT @row := @row + 1 as row, a.* from (
-SELECT t.order_number
-FROM sales_documents t
-WHERE
-t.type = 2 AND
-t.date >= '2017-01-01' AND
-t.date <= '2017-12-31' AND
-t.order_number IS NOT NULL AND
-t.generated = 1
-GROUP BY t.order_number
-) a, (SELECT @row := 0) r) t
-WHERE row <> order_number;
-row order_number
-14 51
-DROP TABLE sales_documents;
-#
-# MDEV-12845: pushdown from merged derived using equalities
-#
-create table t1 (a int);
-insert into t1 values
-(4), (8), (5), (3), (10), (2), (7);
-create table t2 (b int, c int);
-insert into t2 values
-(2,1), (5,2), (2,2), (4,1), (4,3),
-(5,3), (2,4), (4,6), (2,1);
-create view v1 as
-select b, sum(c) as s from t2 group by b;
-create view v2 as
-select distinct b, c from t2;
-create view v3 as
-select b, max(c) as m from t2 group by b;
-select b
-from ( select t1.a, v1.b, v1.s from t1, v1 where t1.a = v1.b ) as t
-where b > 2;
-b
-4
-5
-explain format=json select b
-from ( select t1.a, v1.b, v1.s from t1, v1 where t1.a = v1.b ) as t
-where b > 2;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 7,
- "filtered": 100,
- "attached_condition": "t1.a > 2 and t1.a is not null"
- },
- "table": {
- "table_name": "<derived3>",
- "access_type": "ref",
- "possible_keys": ["key0"],
- "key": "key0",
- "key_length": "5",
- "used_key_parts": ["b"],
- "ref": ["test.t1.a"],
- "rows": 2,
- "filtered": 100,
- "materialized": {
- "query_block": {
- "select_id": 3,
- "filesort": {
- "sort_key": "t2.b",
- "temporary_table": {
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 9,
- "filtered": 100,
- "attached_condition": "t2.b > 2"
- }
- }
- }
- }
- }
- }
- }
-}
-select a
-from ( select t1.a, v1.b, v1.s from t1, v1 where t1.a = v1.b ) as t
-where a > 2;
-a
-4
-5
-explain format=json select a
-from ( select t1.a, v1.b, v1.s from t1, v1 where t1.a = v1.b ) as t
-where a > 2;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 7,
- "filtered": 100,
- "attached_condition": "t1.a > 2 and t1.a is not null"
- },
- "table": {
- "table_name": "<derived3>",
- "access_type": "ref",
- "possible_keys": ["key0"],
- "key": "key0",
- "key_length": "5",
- "used_key_parts": ["b"],
- "ref": ["test.t1.a"],
- "rows": 2,
- "filtered": 100,
- "materialized": {
- "query_block": {
- "select_id": 3,
- "filesort": {
- "sort_key": "t2.b",
- "temporary_table": {
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 9,
- "filtered": 100,
- "attached_condition": "t2.b > 2"
- }
- }
- }
- }
- }
- }
- }
-}
-select a
-from ( select t1.a, v2.b, v2.c from t1, v2 where t1.a = v2.b ) as t
-where a > 2;
-a
-4
-4
-4
-5
-5
-explain format=json select a
-from ( select t1.a, v2.b, v2.c from t1, v2 where t1.a = v2.b ) as t
-where a > 2;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 7,
- "filtered": 100,
- "attached_condition": "t1.a > 2 and t1.a is not null"
- },
- "table": {
- "table_name": "<derived3>",
- "access_type": "ref",
- "possible_keys": ["key0"],
- "key": "key0",
- "key_length": "5",
- "used_key_parts": ["b"],
- "ref": ["test.t1.a"],
- "rows": 2,
- "filtered": 100,
- "materialized": {
- "query_block": {
- "select_id": 3,
- "temporary_table": {
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 9,
- "filtered": 100,
- "attached_condition": "t2.b > 2"
- }
- }
- }
- }
- }
- }
-}
-select a
-from ( select t1.a, v3.b, v3.m from t1, v3 where t1.a = v3.m ) as t
-where a > 2;
-a
-4
-3
-explain format=json select a
-from ( select t1.a, v3.b, v3.m from t1, v3 where t1.a = v3.m ) as t
-where a > 2;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 7,
- "filtered": 100,
- "attached_condition": "t1.a > 2 and t1.a is not null"
- },
- "table": {
- "table_name": "<derived3>",
- "access_type": "ref",
- "possible_keys": ["key0"],
- "key": "key0",
- "key_length": "5",
- "used_key_parts": ["m"],
- "ref": ["test.t1.a"],
- "rows": 2,
- "filtered": 100,
- "materialized": {
- "query_block": {
- "select_id": 3,
- "having_condition": "m > 2",
- "filesort": {
- "sort_key": "t2.b",
- "temporary_table": {
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 9,
- "filtered": 100
- }
- }
- }
- }
- }
- }
- }
-}
-drop view v1,v2,v3;
-drop table t1,t2;
-#
-# MDEV-13166: pushdown from merged derived
-#
-CREATE TABLE t1 (i int) ENGINE=MyISAM;
-INSERT INTO t1 VALUES (1),(2);
-CREATE VIEW v1 AS SELECT MAX(i) AS f FROM t1;
-SELECT * FROM ( SELECT * FROM v1 ) AS sq WHERE f > 0;
-f
-2
-explain format=json SELECT * FROM ( SELECT * FROM v1 ) AS sq WHERE f > 0;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<derived3>",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "v1.f > 0",
- "materialized": {
- "query_block": {
- "select_id": 3,
- "having_condition": "f > 0",
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100
- }
- }
- }
- }
- }
-}
-DROP VIEW v1;
-DROP TABLE t1;
-#
-# MDEV-13193: pushdown of equality extracted from multiple equality
-#
-CREATE TABLE t1 (i1 int, KEY(i1)) ENGINE=MyISAM;
-INSERT INTO t1 VALUES (1),(2);
-CREATE TABLE t2 (i2 int) ENGINE=MyISAM;
-INSERT INTO t2 VALUES (2),(4);
-CREATE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2;
-SELECT * FROM t1, ( SELECT * FROM v2 ) AS sq
-WHERE i1 = 1 AND ( i1 = i2 OR i1 = 2 );
-i1 i2
-explain format=json SELECT * FROM t1, ( SELECT * FROM v2 ) AS sq
-WHERE i1 = 1 AND ( i1 = i2 OR i1 = 2 );
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "t1",
- "access_type": "ref",
- "possible_keys": ["i1"],
- "key": "i1",
- "key_length": "5",
- "used_key_parts": ["i1"],
- "ref": ["const"],
- "rows": 1,
- "filtered": 100,
- "using_index": true
- },
- "block-nl-join": {
- "table": {
- "table_name": "<derived3>",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "v2.i2 = 1"
- },
- "buffer_type": "flat",
- "buffer_size": "256Kb",
- "join_type": "BNL",
- "materialized": {
- "query_block": {
- "select_id": 3,
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "t2.i2 = 1"
- }
- }
- }
- }
- }
-}
-DROP VIEW v2;
-DROP TABLE t1,t2;
-#
-# MDEV-14237: derived with regexp_substr() in select list
-#
-create table t1 (a char(8));
-insert into t1 values ('b'), ('a'), ('xx');
-select *
-from ( select distinct regexp_substr(t1.a,'^[A-Za-z]+') as f from t1) as t
-where t.f = 'a' or t.f = 'b';
-f
-b
-a
-explain format=json select *
-from ( select distinct regexp_substr(t1.a,'^[A-Za-z]+') as f from t1) as t
-where t.f = 'a' or t.f = 'b';
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "t.f = 'a' or t.f = 'b'",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "temporary_table": {
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100
- }
- }
- }
- }
- }
- }
-}
-drop table t1;
-#
-# MDEV-13454: consequence of mdev-14368 fixed for 5.5
-#
-SET sql_mode = 'ONLY_FULL_GROUP_BY';
-create table t1 (id int, id2 int);
-insert into t1 values (1,1),(2,3),(3,4),(7,2);
-create table t2(id2 int);
-insert t2 values (1),(2),(3);
-SELECT * FROM t1
-LEFT OUTER JOIN
-(SELECT id2, COUNT(*) as ct FROM t2 GROUP BY id2) vc USING (id2)
-WHERE (vc.ct>0);
-id2 id ct
-1 1 1
-3 2 1
-2 7 1
-EXPLAIN FORMAT=JSON SELECT * FROM t1
-LEFT OUTER JOIN
-(SELECT id2, COUNT(*) as ct FROM t2 GROUP BY id2) vc USING (id2)
-WHERE (vc.ct>0);
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "vc.ct > 0",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "having_condition": "ct > 0",
- "filesort": {
- "sort_key": "t2.id2",
- "temporary_table": {
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100
- }
- }
- }
- }
- }
- },
- "block-nl-join": {
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 4,
- "filtered": 100
- },
- "buffer_type": "flat",
- "buffer_size": "256Kb",
- "join_type": "BNL",
- "attached_condition": "t1.id2 = vc.id2"
- }
- }
-}
-DROP TABLE t1,t2;
-SET sql_mode = DEFAULT;
-#
-# MDEV-15579: incorrect removal of sub-formulas to be pushed
-# into WHERE of materialized derived with GROUP BY
-#
-CREATE TABLE t1 (a INT, b INT, c INT, d INT);
-CREATE TABLE t2 (x INT, y INT, z INT);
-INSERT INTO t1 VALUES (1,1,66,1), (1,1,56,2), (3,2,42,3);
-INSERT INTO t2 VALUES (1,1,66), (1,12,32);
-SELECT *
-FROM t2,
-(
-SELECT a, b, max(c) AS max_c
-FROM t1
-GROUP BY a
-HAVING max_c > 37
-) AS v1
-WHERE (v1.a=1) AND (v1.b=v1.a) AND
-(v1.a=t2.x) AND (v1.max_c>30);
-x y z a b max_c
-1 1 66 1 1 66
-1 12 32 1 1 66
-EXPLAIN SELECT *
-FROM t2,
-(
-SELECT a, b, max(c) AS max_c
-FROM t1
-GROUP BY a
-HAVING max_c > 37
-) AS v1
-WHERE (v1.a=1) AND (v1.b=v1.a) AND
-(v1.a=t2.x) AND (v1.max_c>30);
-id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
-1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
-2 DERIVED t1 ALL NULL NULL NULL NULL 3 Using where
-EXPLAIN FORMAT=JSON SELECT *
-FROM t2,
-(
-SELECT a, b, max(c) AS max_c
-FROM t1
-GROUP BY a
-HAVING max_c > 37
-) AS v1
-WHERE (v1.a=1) AND (v1.b=v1.a) AND
-(v1.a=t2.x) AND (v1.max_c>30);
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "t2.x = 1"
- },
- "block-nl-join": {
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "v1.a = 1 and v1.b = 1 and v1.max_c > 30"
- },
- "buffer_type": "flat",
- "buffer_size": "256Kb",
- "join_type": "BNL",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "having_condition": "max_c > 37 and max_c > 30 and t1.b = 1",
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "t1.a = 1"
- }
- }
- }
- }
- }
-}
-SELECT *
-FROM t2,
-(
-SELECT a, b, d, max(c) AS max_c
-FROM t1
-GROUP BY a,d
-HAVING max_c > 37
-) AS v1
-WHERE (v1.a=1) AND (v1.b=v1.a) AND (v1.b=v1.d) AND
-(v1.a=t2.x) AND (v1.max_c>30);
-x y z a b d max_c
-1 1 66 1 1 1 66
-1 12 32 1 1 1 66
-EXPLAIN SELECT *
-FROM t2,
-(
-SELECT a, b, d, max(c) AS max_c
-FROM t1
-GROUP BY a,d
-HAVING max_c > 37
-) AS v1
-WHERE (v1.a=1) AND (v1.b=v1.a) AND (v1.b=v1.d) AND
-(v1.a=t2.x) AND (v1.max_c>30);
-id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
-1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
-2 DERIVED t1 ALL NULL NULL NULL NULL 3 Using where
-EXPLAIN FORMAT=JSON SELECT *
-FROM t2,
-(
-SELECT a, b, d, max(c) AS max_c
-FROM t1
-GROUP BY a,d
-HAVING max_c > 37
-) AS v1
-WHERE (v1.a=1) AND (v1.b=v1.a) AND (v1.b=v1.d) AND
-(v1.a=t2.x) AND (v1.max_c>30);
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "t2.x = 1"
- },
- "block-nl-join": {
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "v1.a = 1 and v1.b = 1 and v1.d = 1 and v1.max_c > 30"
- },
- "buffer_type": "flat",
- "buffer_size": "256Kb",
- "join_type": "BNL",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "having_condition": "max_c > 37 and max_c > 30 and t1.b = 1",
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "t1.a = 1 and t1.d = 1"
- }
- }
- }
- }
- }
-}
-DROP TABLE t1,t2;
-#
-# MDEV-15765: pushing condition with temporal constants
-# into constant tables
-#
-select * from (select date('2018-01-01') as d
-union all
-select date('2018-01-01') as d) as t
-where t.d between date ('2017-01-01') and date ('2019-01-01');
-d
-2018-01-01
-2018-01-01
-select * from (select date('2018-01-01') as d) as t
-where t.d between date ('2017-01-01') and date ('2019-01-01');
-d
-2018-01-01
-#
-# MDEV-16088: pushdown into derived defined in the IN subquery
-#
-CREATE TABLE t1 (a INT, b INT);
-CREATE TABLE t2 (e INT, f INT, g INT);
-INSERT INTO t1 VALUES (1,14),(2,13),(1,19),(2,32),(3,24);
-INSERT INTO t2 VALUES (1,19,2),(3,24,1),(1,12,2),(3,11,3),(2,32,1);
-SELECT * FROM t1
-WHERE (t1.a,t1.b) IN
-(
-SELECT d_tab.e,d_tab.max_f
-FROM (
-SELECT t2.e, MAX(t2.f) AS max_f
-FROM t2
-GROUP BY t2.e
-HAVING max_f>18
-) as d_tab
-WHERE d_tab.e>1
-)
-;
-a b
-2 32
-3 24
-EXPLAIN SELECT * FROM t1
-WHERE (t1.a,t1.b) IN
-(
-SELECT d_tab.e,d_tab.max_f
-FROM (
-SELECT t2.e, MAX(t2.f) AS max_f
-FROM t2
-GROUP BY t2.e
-HAVING max_f>18
-) as d_tab
-WHERE d_tab.e>1
-)
-;
-id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 5
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1
-2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 5 Using where
-3 DERIVED t2 ALL NULL NULL NULL NULL 5 Using where; Using temporary; Using filesort
-EXPLAIN FORMAT=JSON SELECT * FROM t1
-WHERE (t1.a,t1.b) IN
-(
-SELECT d_tab.e,d_tab.max_f
-FROM (
-SELECT t2.e, MAX(t2.f) AS max_f
-FROM t2
-GROUP BY t2.e
-HAVING max_f>18
-) as d_tab
-WHERE d_tab.e>1
-)
-;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 5,
- "filtered": 100
- },
- "table": {
- "table_name": "<subquery2>",
- "access_type": "eq_ref",
- "possible_keys": ["distinct_key"],
- "key": "distinct_key",
- "key_length": "8",
- "used_key_parts": ["e", "max_f"],
- "ref": ["func", "func"],
- "rows": 1,
- "filtered": 100,
- "materialized": {
- "unique": 1,
- "query_block": {
- "select_id": 2,
- "table": {
- "table_name": "<derived3>",
- "access_type": "ALL",
- "rows": 5,
- "filtered": 100,
- "attached_condition": "d_tab.e > 1",
- "materialized": {
- "query_block": {
- "select_id": 3,
- "having_condition": "max_f > 18",
- "filesort": {
- "sort_key": "t2.e",
- "temporary_table": {
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 5,
- "filtered": 100,
- "attached_condition": "t2.e > 1"
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
-}
-SELECT * FROM t1
-WHERE (t1.a,t1.b) IN
-(
-SELECT d_tab.e,d_tab.max_f
-FROM (
-SELECT t2.e, MAX(t2.f) AS max_f
-FROM t2
-GROUP BY t2.e
-HAVING max_f>18
-) as d_tab
-WHERE d_tab.max_f<25
-)
-;
-a b
-1 19
-3 24
-EXPLAIN SELECT * FROM t1
-WHERE (t1.a,t1.b) IN
-(
-SELECT d_tab.e,d_tab.max_f
-FROM (
-SELECT t2.e, MAX(t2.f) AS max_f
-FROM t2
-GROUP BY t2.e
-HAVING max_f>18
-) as d_tab
-WHERE d_tab.max_f<25
-)
-;
-id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 5
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1
-2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 5 Using where
-3 DERIVED t2 ALL NULL NULL NULL NULL 5 Using temporary; Using filesort
-EXPLAIN FORMAT=JSON SELECT * FROM t1
-WHERE (t1.a,t1.b) IN
-(
-SELECT d_tab.e,d_tab.max_f
-FROM (
-SELECT t2.e, MAX(t2.f) AS max_f
-FROM t2
-GROUP BY t2.e
-HAVING max_f>18
-) as d_tab
-WHERE d_tab.max_f<25
-)
-;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 5,
- "filtered": 100
- },
- "table": {
- "table_name": "<subquery2>",
- "access_type": "eq_ref",
- "possible_keys": ["distinct_key"],
- "key": "distinct_key",
- "key_length": "8",
- "used_key_parts": ["e", "max_f"],
- "ref": ["func", "func"],
- "rows": 1,
- "filtered": 100,
- "materialized": {
- "unique": 1,
- "query_block": {
- "select_id": 2,
- "table": {
- "table_name": "<derived3>",
- "access_type": "ALL",
- "rows": 5,
- "filtered": 100,
- "attached_condition": "d_tab.max_f < 25",
- "materialized": {
- "query_block": {
- "select_id": 3,
- "having_condition": "max_f > 18 and max_f < 25",
- "filesort": {
- "sort_key": "t2.e",
- "temporary_table": {
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 5,
- "filtered": 100
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
-}
-SELECT * FROM t1
-WHERE (t1.a,t1.b) IN
-(
-SELECT d_tab.e, MAX(d_tab.max_f) AS max_f
-FROM (
-SELECT t2.e, MAX(t2.f) as max_f, t2.g
-FROM t2
-GROUP BY t2.e
-) as d_tab
-WHERE d_tab.e>1
-GROUP BY d_tab.g
-)
-;
-a b
-2 32
-EXPLAIN SELECT * FROM t1
-WHERE (t1.a,t1.b) IN
-(
-SELECT d_tab.e, MAX(d_tab.max_f) AS max_f
-FROM (
-SELECT t2.e, MAX(t2.f) as max_f, t2.g
-FROM t2
-GROUP BY t2.e
-) as d_tab
-WHERE d_tab.e>1
-GROUP BY d_tab.g
-)
-;
-id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.b 1
-2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 5 Using where; Using temporary
-3 DERIVED t2 ALL NULL NULL NULL NULL 5 Using where; Using temporary; Using filesort
-EXPLAIN FORMAT=JSON SELECT * FROM t1
-WHERE (t1.a,t1.b) IN
-(
-SELECT d_tab.e, MAX(d_tab.max_f) AS max_f
-FROM (
-SELECT t2.e, MAX(t2.f) as max_f, t2.g
-FROM t2
-GROUP BY t2.e
-) as d_tab
-WHERE d_tab.e>1
-GROUP BY d_tab.g
-)
-;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 5,
- "filtered": 100,
- "attached_condition": "t1.a is not null and t1.b is not null"
- },
- "table": {
- "table_name": "<subquery2>",
- "access_type": "eq_ref",
- "possible_keys": ["distinct_key"],
- "key": "distinct_key",
- "key_length": "8",
- "used_key_parts": ["e", "max_f"],
- "ref": ["test.t1.a", "test.t1.b"],
- "rows": 1,
- "filtered": 100,
- "materialized": {
- "unique": 1,
- "query_block": {
- "select_id": 2,
- "temporary_table": {
- "table": {
- "table_name": "<derived3>",
- "access_type": "ALL",
- "rows": 5,
- "filtered": 100,
- "attached_condition": "d_tab.e > 1",
- "materialized": {
- "query_block": {
- "select_id": 3,
- "filesort": {
- "sort_key": "t2.e",
- "temporary_table": {
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 5,
- "filtered": 100,
- "attached_condition": "t2.e > 1"
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
-}
-SELECT * FROM t1
-WHERE (t1.a,t1.b) IN
-(
-SELECT d_tab.e, MAX(d_tab.max_f) AS max_f
-FROM (
-SELECT t2.e, MAX(t2.f) as max_f, t2.g
-FROM t2
-GROUP BY t2.e
-) as d_tab
-WHERE d_tab.max_f>20
-GROUP BY d_tab.g
-)
-;
-a b
-2 32
-EXPLAIN SELECT * FROM t1
-WHERE (t1.a,t1.b) IN
-(
-SELECT d_tab.e, MAX(d_tab.max_f) AS max_f
-FROM (
-SELECT t2.e, MAX(t2.f) as max_f, t2.g
-FROM t2
-GROUP BY t2.e
-) as d_tab
-WHERE d_tab.max_f>20
-GROUP BY d_tab.g
-)
-;
-id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.b 1
-2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 5 Using where; Using temporary
-3 DERIVED t2 ALL NULL NULL NULL NULL 5 Using temporary; Using filesort
-EXPLAIN FORMAT=JSON SELECT * FROM t1
-WHERE (t1.a,t1.b) IN
-(
-SELECT d_tab.e, MAX(d_tab.max_f) AS max_f
-FROM (
-SELECT t2.e, MAX(t2.f) as max_f, t2.g
-FROM t2
-GROUP BY t2.e
-) as d_tab
-WHERE d_tab.max_f>20
-GROUP BY d_tab.g
-)
-;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 5,
- "filtered": 100,
- "attached_condition": "t1.a is not null and t1.b is not null"
- },
- "table": {
- "table_name": "<subquery2>",
- "access_type": "eq_ref",
- "possible_keys": ["distinct_key"],
- "key": "distinct_key",
- "key_length": "8",
- "used_key_parts": ["e", "max_f"],
- "ref": ["test.t1.a", "test.t1.b"],
- "rows": 1,
- "filtered": 100,
- "materialized": {
- "unique": 1,
- "query_block": {
- "select_id": 2,
- "temporary_table": {
- "table": {
- "table_name": "<derived3>",
- "access_type": "ALL",
- "rows": 5,
- "filtered": 100,
- "attached_condition": "d_tab.max_f > 20",
- "materialized": {
- "query_block": {
- "select_id": 3,
- "having_condition": "max_f > 20",
- "filesort": {
- "sort_key": "t2.e",
- "temporary_table": {
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 5,
- "filtered": 100
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
-}
-DROP TABLE t1,t2;
-#
-# MDEV-15765: pushing condition with IN subquery defined with constants
-# using substitution
-#
-CREATE TABLE t1 (a INT);
-INSERT INTO t1 VALUES (1),(2);
-SELECT * FROM
-(
-SELECT DISTINCT * FROM t1
-) der_tab
-WHERE (a>0 AND a<2 OR a IN (2,3)) AND
-(a=2 OR 0);
-a
-2
-DROP TABLE t1;
-#
-# MDEV-16386: pushing condition into the HAVING clause when ambiguous
-# fields warning appears
-#
-CREATE TABLE t1 (a INT, b INT);
-INSERT INTO t1 VALUES (1,2),(2,3),(3,4);
-SELECT * FROM
-(
-SELECT t1.b AS a
-FROM t1
-GROUP BY t1.a
-) dt
-WHERE (dt.a=2);
-a
-2
-EXPLAIN FORMAT=JSON SELECT * FROM
-(
-SELECT t1.b AS a
-FROM t1
-GROUP BY t1.a
-) dt
-WHERE (dt.a=2);
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "dt.a = 2",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "having_condition": "a = 2",
- "filesort": {
- "sort_key": "t1.a",
- "temporary_table": {
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100
- }
- }
- }
- }
- }
- }
- }
-}
-SELECT * FROM
-(
-SELECT t1.b AS a
-FROM t1
-GROUP BY t1.a
-HAVING (t1.a<3)
-) dt
-WHERE (dt.a>1);
-a
-2
-3
-EXPLAIN FORMAT=JSON SELECT * FROM
-(
-SELECT t1.b AS a
-FROM t1
-GROUP BY t1.a
-HAVING (t1.a<3)
-) dt
-WHERE (dt.a>1);
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "dt.a > 1",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "having_condition": "t1.a < 3 and a > 1",
- "filesort": {
- "sort_key": "t1.a",
- "temporary_table": {
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100
- }
- }
- }
- }
- }
- }
- }
-}
-SELECT * FROM
-(
-SELECT 'ab' AS a
-FROM t1
-GROUP BY t1.a
-) dt
-WHERE (dt.a='ab');
-a
-ab
-ab
-ab
-EXPLAIN FORMAT=JSON SELECT * FROM
-(
-SELECT 'ab' AS a
-FROM t1
-GROUP BY t1.a
-) dt
-WHERE (dt.a='ab');
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "dt.a = 'ab'",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "filesort": {
- "sort_key": "t1.a",
- "temporary_table": {
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100
- }
- }
- }
- }
- }
- }
- }
-}
-SELECT * FROM
-(
-SELECT 1 AS a
-FROM t1
-GROUP BY t1.a
-) dt
-WHERE (dt.a=1);
-a
-1
-1
-1
-EXPLAIN FORMAT=JSON SELECT * FROM
-(
-SELECT 1 AS a
-FROM t1
-GROUP BY t1.a
-) dt
-WHERE (dt.a=1);
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "dt.a = 1",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "filesort": {
- "sort_key": "t1.a",
- "temporary_table": {
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100
- }
- }
- }
- }
- }
- }
- }
-}
-DROP TABLE t1;
-#
-# MDEV-16517: pushdown condition with the IN predicate defined
-# with non-constant values
-#
-CREATE TABLE t1 (a INT, b INT);
-INSERT INTO t1 VALUES (1,2),(1,3);
-SELECT * FROM
-(
-SELECT t1.a
-FROM t1
-WHERE 1 IN (0,t1.a)
-GROUP BY t1.a
-) AS dt1
-JOIN
-(
-SELECT t1.a
-FROM t1
-WHERE 1 IN (0,t1.a)
-) AS dt2
-ON dt1.a = dt2.a;
-a a
-1 1
-1 1
-EXPLAIN FORMAT=JSON SELECT * FROM
-(
-SELECT t1.a
-FROM t1
-WHERE 1 IN (0,t1.a)
-GROUP BY t1.a
-) AS dt1
-JOIN
-(
-SELECT t1.a
-FROM t1
-WHERE 1 IN (0,t1.a)
-) AS dt2
-ON dt1.a = dt2.a;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "1 in (0,dt1.a)",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "filesort": {
- "sort_key": "t1.a",
- "temporary_table": {
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "1 in (0,t1.a) and 1 in (0,t1.a)"
- }
- }
- }
- }
- }
- },
- "block-nl-join": {
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100
- },
- "buffer_type": "flat",
- "buffer_size": "256Kb",
- "join_type": "BNL",
- "attached_condition": "t1.a = dt1.a"
- }
- }
-}
-SELECT * FROM
-(
-SELECT t1.a,MAX(t1.b)
-FROM t1
-GROUP BY t1.a
-) AS dt, t1
-WHERE dt.a=t1.a AND dt.a IN (1,t1.a);
-a MAX(t1.b) a b
-1 3 1 2
-1 3 1 3
-EXPLAIN FORMAT=JSON SELECT * FROM
-(
-SELECT t1.a,MAX(t1.b)
-FROM t1
-GROUP BY t1.a
-) AS dt, t1
-WHERE dt.a=t1.a AND dt.a IN (1,t1.a);
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "dt.a in (1,dt.a)",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "filesort": {
- "sort_key": "t1.a",
- "temporary_table": {
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100,
- "attached_condition": "t1.a in (1,t1.a)"
- }
- }
- }
- }
- }
- },
- "block-nl-join": {
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 2,
- "filtered": 100
- },
- "buffer_type": "flat",
- "buffer_size": "256Kb",
- "join_type": "BNL",
- "attached_condition": "t1.a = dt.a"
- }
- }
-}
-DROP TABLE t1;
-#
-# MDEV-10855: Pushdown into derived with window functions
+# MDEV-10855: Pushdown into derived with window functions
#
set @save_optimizer_switch= @@optimizer_switch;
set optimizer_switch='split_materialized=off';
@@ -13558,27 +14138,27 @@ insert into t2 values
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from (select a, c, sum(b) over (partition by a,c) from t2) as t
where t.a > 2 and t.c in ('aa','bb','cc');
a c sum(b) over (partition by a,c)
-7 cc 28
-7 cc 28
3 aa 92
-7 bb 126
+3 aa 92
+3 bb 40
4 aa 15
7 bb 126
7 bb 126
-3 bb 40
-3 aa 92
+7 bb 126
+7 cc 28
+7 cc 28
select * from (select a, c, sum(b) over (partition by a,c) from t2) as t
where t.a > 2 and t.c in ('aa','bb','cc');
a c sum(b) over (partition by a,c)
-7 cc 28
-7 cc 28
3 aa 92
-7 bb 126
+3 aa 92
+3 bb 40
4 aa 15
7 bb 126
7 bb 126
-3 bb 40
-3 aa 92
+7 bb 126
+7 cc 28
+7 cc 28
explain select * from (select a, c, sum(b) over (partition by a,c) from t2) as t
where t.a > 2 and t.c in ('aa','bb','cc');
id select_type table type possible_keys key key_len ref rows Extra
@@ -13622,59 +14202,59 @@ EXPLAIN
}
}
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from
-(
+(
select 1 as n, a, c, sum(b) over (partition by a,c) as s from t2
union all
select 2 as n, a, c, sum(b) over (partition by a) as s from t2
) as t
where t.a > 2 and t.c in ('aa','bb','cc');
n a c s
-1 7 cc 28
-1 7 cc 28
1 3 aa 92
-1 7 bb 126
+1 3 aa 92
+1 3 bb 40
1 4 aa 15
1 7 bb 126
1 7 bb 126
-1 3 bb 40
-1 3 aa 92
-2 7 cc 154
-2 7 cc 154
+1 7 bb 126
+1 7 cc 28
+1 7 cc 28
2 3 aa 132
-2 7 bb 154
+2 3 aa 132
+2 3 bb 132
2 4 aa 139
2 7 bb 154
2 7 bb 154
-2 3 bb 132
-2 3 aa 132
+2 7 bb 154
+2 7 cc 154
+2 7 cc 154
select * from
-(
+(
select 1 as n, a, c, sum(b) over (partition by a,c) as s from t2
union all
select 2 as n, a, c, sum(b) over (partition by a) as s from t2
) as t
where t.a > 2 and t.c in ('aa','bb','cc');
n a c s
-1 7 cc 28
-1 7 cc 28
1 3 aa 92
-1 7 bb 126
+1 3 aa 92
+1 3 bb 40
1 4 aa 15
1 7 bb 126
1 7 bb 126
-1 3 bb 40
-1 3 aa 92
-2 7 cc 154
-2 7 cc 154
+1 7 bb 126
+1 7 cc 28
+1 7 cc 28
2 3 aa 132
-2 7 bb 154
+2 3 aa 132
+2 3 bb 132
2 4 aa 139
2 7 bb 154
2 7 bb 154
-2 3 bb 132
-2 3 aa 132
+2 7 bb 154
+2 7 cc 154
+2 7 cc 154
explain select * from
-(
+(
select 1 as n, a, c, sum(b) over (partition by a,c) as s from t2
union all
select 2 as n, a, c, sum(b) over (partition by a) as s from t2
@@ -13685,7 +14265,7 @@ id select_type table type possible_keys key key_len ref rows Extra
2 DERIVED t2 ALL idx NULL NULL NULL 20 Using where; Using temporary
3 UNION t2 ALL idx NULL NULL NULL 20 Using where; Using temporary
explain format=json select * from
-(
+(
select 1 as n, a, c, sum(b) over (partition by a,c) as s from t2
union all
select 2 as n, a, c, sum(b) over (partition by a) as s from t2
@@ -13759,7 +14339,7 @@ EXPLAIN
}
}
}
-set statement optimizer_switch='condition_pushdown_for_derived=off' for select *
+set statement optimizer_switch='condition_pushdown_for_derived=off' for select *
from (select a, c, sum(b) over (partition by a,c) as s from t2) as t, t1
where t1.a=t.a and t1.c=t.c and t1.c in ('aa','bb','cc');
a c s a c
@@ -13767,7 +14347,7 @@ a c s a c
7 bb 126 7 bb
7 bb 126 7 bb
7 bb 126 7 bb
-select *
+select *
from (select a, c, sum(b) over (partition by a,c) as s from t2) as t, t1
where t1.a=t.a and t1.c=t.c and t1.c in ('aa','bb','cc');
a c s a c
@@ -13775,14 +14355,14 @@ a c s a c
7 bb 126 7 bb
7 bb 126 7 bb
7 bb 126 7 bb
-explain select *
+explain select *
from (select a, c, sum(b) over (partition by a,c) as s from t2) as t, t1
where t1.a=t.a and t1.c=t.c and t1.c in ('aa','bb','cc');
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where
1 PRIMARY <derived2> ref key0 key0 24 test.t1.a,test.t1.c 2
2 DERIVED t2 ALL NULL NULL NULL NULL 20 Using where; Using temporary
-explain format=json select *
+explain format=json select *
from (select a, c, sum(b) over (partition by a,c) as s from t2) as t, t1
where t1.a=t.a and t1.c=t.c and t1.c in ('aa','bb','cc');
EXPLAIN
@@ -13831,7 +14411,7 @@ EXPLAIN
}
}
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from
-(
+(
select 1 as n, a, c, sum(b) over (partition by a,c) as s from t2
union all
select 2 as n, a, c, sum(b) over (partition by a) as s from t2
@@ -13840,28 +14420,28 @@ select 3 as n, a, c, sum(b) as s from t2 group by a
) as t
where t.a > 2 and t.c in ('aa','bb','cc');
n a c s
-1 7 cc 28
-1 7 cc 28
1 3 aa 92
-1 7 bb 126
+1 3 aa 92
+1 3 bb 40
1 4 aa 15
1 7 bb 126
1 7 bb 126
-1 3 bb 40
-1 3 aa 92
-2 7 cc 154
-2 7 cc 154
+1 7 bb 126
+1 7 cc 28
+1 7 cc 28
2 3 aa 132
-2 7 bb 154
+2 3 aa 132
+2 3 bb 132
2 4 aa 139
2 7 bb 154
2 7 bb 154
-2 3 bb 132
-2 3 aa 132
+2 7 bb 154
+2 7 cc 154
+2 7 cc 154
3 3 aa 132
3 7 cc 154
select * from
-(
+(
select 1 as n, a, c, sum(b) over (partition by a,c) as s from t2
union all
select 2 as n, a, c, sum(b) over (partition by a) as s from t2
@@ -13870,28 +14450,28 @@ select 3 as n, a, c, sum(b) as s from t2 group by a
) as t
where t.a > 2 and t.c in ('aa','bb','cc');
n a c s
-1 7 cc 28
-1 7 cc 28
1 3 aa 92
-1 7 bb 126
+1 3 aa 92
+1 3 bb 40
1 4 aa 15
1 7 bb 126
1 7 bb 126
-1 3 bb 40
-1 3 aa 92
-2 7 cc 154
-2 7 cc 154
+1 7 bb 126
+1 7 cc 28
+1 7 cc 28
2 3 aa 132
-2 7 bb 154
+2 3 aa 132
+2 3 bb 132
2 4 aa 139
2 7 bb 154
2 7 bb 154
-2 3 bb 132
-2 3 aa 132
+2 7 bb 154
+2 7 cc 154
+2 7 cc 154
3 3 aa 132
3 7 cc 154
explain select * from
-(
+(
select 1 as n, a, c, sum(b) over (partition by a,c) as s from t2
union all
select 2 as n, a, c, sum(b) over (partition by a) as s from t2
@@ -13905,7 +14485,7 @@ id select_type table type possible_keys key key_len ref rows Extra
3 UNION t2 ALL idx NULL NULL NULL 20 Using where; Using temporary
4 UNION t2 ALL idx NULL NULL NULL 20 Using where; Using temporary; Using filesort
explain format=json select * from
-(
+(
select 1 as n, a, c, sum(b) over (partition by a,c) as s from t2
union all
select 2 as n, a, c, sum(b) over (partition by a) as s from t2
@@ -14007,30 +14587,30 @@ avg(b) over (partition by a,c) as avg_b
from t2 ) as t
where t.a > 2 and t.c in ('aa','bb','cc');
a c sum_b avg_b
-7 cc 28 14.0000
-7 cc 28 14.0000
3 aa 92 46.0000
-7 bb 126 42.0000
+3 aa 92 46.0000
+3 bb 40 40.0000
4 aa 15 15.0000
7 bb 126 42.0000
7 bb 126 42.0000
-3 bb 40 40.0000
-3 aa 92 46.0000
+7 bb 126 42.0000
+7 cc 28 14.0000
+7 cc 28 14.0000
select * from (select a, c,
sum(b) over (partition by a,c) as sum_b,
avg(b) over (partition by a,c) as avg_b
from t2 ) as t
where t.a > 2 and t.c in ('aa','bb','cc');
a c sum_b avg_b
-7 cc 28 14.0000
-7 cc 28 14.0000
3 aa 92 46.0000
-7 bb 126 42.0000
+3 aa 92 46.0000
+3 bb 40 40.0000
4 aa 15 15.0000
7 bb 126 42.0000
7 bb 126 42.0000
-3 bb 40 40.0000
-3 aa 92 46.0000
+7 bb 126 42.0000
+7 cc 28 14.0000
+7 cc 28 14.0000
explain select * from (select a, c,
sum(b) over (partition by a,c) as sum_b,
avg(b) over (partition by a,c) as avg_b
@@ -14085,30 +14665,30 @@ avg(b) over (partition by a) as avg_b
from t2 ) as t
where t.a > 2 and t.c in ('aa','bb','cc');
a c sum_b avg_b
-7 cc 28 30.8000
-7 cc 28 30.8000
3 aa 92 44.0000
-7 bb 126 30.8000
+3 aa 92 44.0000
+3 bb 40 44.0000
4 aa 15 46.3333
7 bb 126 30.8000
7 bb 126 30.8000
-3 bb 40 44.0000
-3 aa 92 44.0000
+7 bb 126 30.8000
+7 cc 28 30.8000
+7 cc 28 30.8000
select * from (select a, c,
sum(b) over (partition by a,c) as sum_b,
avg(b) over (partition by a) as avg_b
from t2 ) as t
where t.a > 2 and t.c in ('aa','bb','cc');
a c sum_b avg_b
-7 cc 28 30.8000
-7 cc 28 30.8000
3 aa 92 44.0000
-7 bb 126 30.8000
+3 aa 92 44.0000
+3 bb 40 44.0000
4 aa 15 46.3333
7 bb 126 30.8000
7 bb 126 30.8000
-3 bb 40 44.0000
-3 aa 92 44.0000
+7 bb 126 30.8000
+7 cc 28 30.8000
+7 cc 28 30.8000
explain select * from (select a, c,
sum(b) over (partition by a,c) as sum_b,
avg(b) over (partition by a) as avg_b
@@ -14163,30 +14743,30 @@ avg(b) over (partition by c) as avg_b
from t2 ) as t
where t.a > 2 and t.c in ('aa','bb','cc');
a c sum_b avg_b
-7 cc 28 14.0000
-7 cc 28 14.0000
3 aa 92 35.4000
-7 bb 126 36.5000
+3 aa 92 35.4000
+3 bb 40 36.5000
4 aa 15 35.4000
7 bb 126 36.5000
7 bb 126 36.5000
-3 bb 40 36.5000
-3 aa 92 35.4000
+7 bb 126 36.5000
+7 cc 28 14.0000
+7 cc 28 14.0000
select * from (select a, c,
sum(b) over (partition by a,c) as sum_b,
avg(b) over (partition by c) as avg_b
from t2 ) as t
where t.a > 2 and t.c in ('aa','bb','cc');
a c sum_b avg_b
-7 cc 28 14.0000
-7 cc 28 14.0000
3 aa 92 35.4000
-7 bb 126 36.5000
+3 aa 92 35.4000
+3 bb 40 36.5000
4 aa 15 35.4000
7 bb 126 36.5000
7 bb 126 36.5000
-3 bb 40 36.5000
-3 aa 92 35.4000
+7 bb 126 36.5000
+7 cc 28 14.0000
+7 cc 28 14.0000
explain select * from (select a, c,
sum(b) over (partition by a,c) as sum_b,
avg(b) over (partition by c) as avg_b
@@ -14240,7 +14820,7 @@ EXPLAIN
drop table t1,t2;
set optimizer_switch= @save_optimizer_switch;
#
-# MDEV-13369: Optimization for equi-joins of grouping derived tables
+# MDEV-13369: Optimization for equi-joins of grouping derived tables
# (Splitting derived tables / views with GROUP BY)
# MDEV-13389: Optimization for equi-joins of derived tables with WF
# (Splitting derived tables / views with window functions)
@@ -14893,16 +15473,16 @@ set statement optimizer_switch='split_materialized=off' for select t2.a,t2.b,t2.
from t2, t3, (select c, max(b) max, min(b) min from t4 group by c) t
where t2.b between 80 and 85 and t2.c in ('y','z') and t2.a=t3.a and t3.c=t.c;
a b c t_c max min
-7 82 y cc 18 10
7 82 y aa 82 15
7 82 y bb 40 23
+7 82 y cc 18 10
select t2.a,t2.b,t2.c,t.c as t_c,t.max,t.min
from t2, t3, (select c, max(b) max, min(b) min from t4 group by c) t
where t2.b between 80 and 85 and t2.c in ('y','z') and t2.a=t3.a and t3.c=t.c;
a b c t_c max min
-7 82 y cc 18 10
7 82 y aa 82 15
7 82 y bb 40 23
+7 82 y cc 18 10
explain extended select t2.a,t2.b,t2.c,t.c as t_c,t.max,t.min
from t2, t3, (select c, max(b) max, min(b) min from t4 group by c) t
where t2.b between 80 and 85 and t2.c in ('y','z') and t2.a=t3.a and t3.c=t.c;
@@ -15120,36 +15700,36 @@ set statement optimizer_switch='split_materialized=off' for select *
from t2, t3, (select c, b, sum(b) over (partition by c) from t4 ) t
where t2.b between 80 and 85 and t2.c in ('y','z') and t2.a=t3.a and t3.c=t.c;
a b c a b c c b sum(b) over (partition by c)
+7 82 y 7 10 bb bb 23 125
+7 82 y 7 10 bb bb 30 125
+7 82 y 7 10 bb bb 32 125
+7 82 y 7 10 bb bb 40 125
+7 82 y 7 17 cc cc 10 40
7 82 y 7 17 cc cc 12 40
7 82 y 7 17 cc cc 18 40
-7 82 y 7 17 cc cc 10 40
-7 82 y 7 18 aa aa 77 259
-7 82 y 7 18 aa aa 50 259
7 82 y 7 18 aa aa 15 259
-7 82 y 7 18 aa aa 82 259
7 82 y 7 18 aa aa 15 259
7 82 y 7 18 aa aa 20 259
-7 82 y 7 10 bb bb 40 125
-7 82 y 7 10 bb bb 32 125
-7 82 y 7 10 bb bb 30 125
-7 82 y 7 10 bb bb 23 125
+7 82 y 7 18 aa aa 50 259
+7 82 y 7 18 aa aa 77 259
+7 82 y 7 18 aa aa 82 259
select *
from t2, t3, (select c, b, sum(b) over (partition by c) from t4 ) t
where t2.b between 80 and 85 and t2.c in ('y','z') and t2.a=t3.a and t3.c=t.c;
a b c a b c c b sum(b) over (partition by c)
+7 82 y 7 10 bb bb 23 125
+7 82 y 7 10 bb bb 30 125
+7 82 y 7 10 bb bb 32 125
+7 82 y 7 10 bb bb 40 125
+7 82 y 7 17 cc cc 10 40
7 82 y 7 17 cc cc 12 40
7 82 y 7 17 cc cc 18 40
-7 82 y 7 17 cc cc 10 40
-7 82 y 7 18 aa aa 77 259
-7 82 y 7 18 aa aa 50 259
7 82 y 7 18 aa aa 15 259
-7 82 y 7 18 aa aa 82 259
7 82 y 7 18 aa aa 15 259
7 82 y 7 18 aa aa 20 259
-7 82 y 7 10 bb bb 40 125
-7 82 y 7 10 bb bb 32 125
-7 82 y 7 10 bb bb 30 125
-7 82 y 7 10 bb bb 23 125
+7 82 y 7 18 aa aa 50 259
+7 82 y 7 18 aa aa 77 259
+7 82 y 7 18 aa aa 82 259
explain extended select *
from t2, t3, (select c, b, sum(b) over (partition by c) from t4 ) t
where t2.b between 80 and 85 and t2.c in ('y','z') and t2.a=t3.a and t3.c=t.c;
@@ -15234,318 +15814,318 @@ set statement optimizer_switch='split_materialized=off' for select *
from t2, t3, (select c, b, sum(b) over (partition by c) from t4 ) t
where t2.b < 40 and t2.a=t3.a and t3.c=t.c;
a b c a b c c b sum(b) over (partition by c)
-7 10 x 7 17 cc cc 12 40
-7 10 x 7 17 cc cc 18 40
-7 10 x 7 17 cc cc 10 40
-7 10 x 7 18 aa aa 77 259
-7 10 x 7 18 aa aa 50 259
-7 10 x 7 18 aa aa 15 259
-7 10 x 7 18 aa aa 82 259
-7 10 x 7 18 aa aa 15 259
-7 10 x 7 18 aa aa 20 259
-7 10 x 7 10 bb bb 40 125
-7 10 x 7 10 bb bb 32 125
-7 10 x 7 10 bb bb 30 125
-7 10 x 7 10 bb bb 23 125
-1 20 a 1 14 bb bb 40 125
-1 20 a 1 14 bb bb 32 125
-1 20 a 1 14 bb bb 30 125
1 20 a 1 14 bb bb 23 125
-2 23 b 2 12 aa aa 77 259
-2 23 b 2 12 aa aa 50 259
-2 23 b 2 12 aa aa 15 259
-2 23 b 2 12 aa aa 82 259
-2 23 b 2 12 aa aa 15 259
-2 23 b 2 12 aa aa 20 259
-2 23 b 2 11 aa aa 77 259
-2 23 b 2 11 aa aa 50 259
-2 23 b 2 11 aa aa 15 259
-2 23 b 2 11 aa aa 82 259
-2 23 b 2 11 aa aa 15 259
-2 23 b 2 11 aa aa 20 259
-7 18 z 7 17 cc cc 12 40
-7 18 z 7 17 cc cc 18 40
-7 18 z 7 17 cc cc 10 40
-7 18 z 7 18 aa aa 77 259
-7 18 z 7 18 aa aa 50 259
-7 18 z 7 18 aa aa 15 259
-7 18 z 7 18 aa aa 82 259
-7 18 z 7 18 aa aa 15 259
-7 18 z 7 18 aa aa 20 259
-7 18 z 7 10 bb bb 40 125
-7 18 z 7 10 bb bb 32 125
-7 18 z 7 10 bb bb 30 125
-7 18 z 7 10 bb bb 23 125
-1 30 c 1 14 bb bb 40 125
-1 30 c 1 14 bb bb 32 125
-1 30 c 1 14 bb bb 30 125
+1 20 a 1 14 bb bb 30 125
+1 20 a 1 14 bb bb 32 125
+1 20 a 1 14 bb bb 40 125
1 30 c 1 14 bb bb 23 125
-3 15 x 3 11 dd dd 20 32
-3 15 x 3 11 dd dd 12 32
-8 12 t 8 11 aa aa 77 259
-8 12 t 8 11 aa aa 50 259
-8 12 t 8 11 aa aa 15 259
-8 12 t 8 11 aa aa 82 259
-8 12 t 8 11 aa aa 15 259
-8 12 t 8 11 aa aa 20 259
-11 33 a 11 24 bbf bbf 50 165
-11 33 a 11 24 bbf bbf 42 165
-11 33 a 11 24 bbf bbf 40 165
+1 30 c 1 14 bb bb 30 125
+1 30 c 1 14 bb bb 32 125
+1 30 c 1 14 bb bb 40 125
+11 20 v 11 24 bbf bbf 33 165
+11 20 v 11 24 bbf bbf 40 165
+11 20 v 11 24 bbf bbf 42 165
+11 20 v 11 24 bbf bbf 50 165
+11 30 af 11 24 bbf bbf 33 165
+11 30 af 11 24 bbf bbf 40 165
+11 30 af 11 24 bbf bbf 42 165
+11 30 af 11 24 bbf bbf 50 165
+11 30 d 11 24 bbf bbf 33 165
+11 30 d 11 24 bbf bbf 40 165
+11 30 d 11 24 bbf bbf 42 165
+11 30 d 11 24 bbf bbf 50 165
11 33 a 11 24 bbf bbf 33 165
+11 33 a 11 24 bbf bbf 40 165
+11 33 a 11 24 bbf bbf 42 165
+11 33 a 11 24 bbf bbf 50 165
+12 23 y 12 21 aaf aaf 25 319
+12 23 y 12 21 aaf aaf 25 319
+12 23 y 12 21 aaf aaf 30 319
+12 23 y 12 21 aaf aaf 60 319
+12 23 y 12 21 aaf aaf 87 319
+12 23 y 12 21 aaf aaf 92 319
+12 23 y 12 22 aaf aaf 25 319
+12 23 y 12 22 aaf aaf 25 319
+12 23 y 12 22 aaf aaf 30 319
+12 23 y 12 22 aaf aaf 60 319
+12 23 y 12 22 aaf aaf 87 319
+12 23 y 12 22 aaf aaf 92 319
+12 33 bf 12 21 aaf aaf 25 319
+12 33 bf 12 21 aaf aaf 25 319
+12 33 bf 12 21 aaf aaf 30 319
+12 33 bf 12 21 aaf aaf 60 319
+12 33 bf 12 21 aaf aaf 87 319
+12 33 bf 12 21 aaf aaf 92 319
+12 33 bf 12 22 aaf aaf 25 319
+12 33 bf 12 22 aaf aaf 25 319
+12 33 bf 12 22 aaf aaf 30 319
+12 33 bf 12 22 aaf aaf 60 319
+12 33 bf 12 22 aaf aaf 87 319
+12 33 bf 12 22 aaf aaf 92 319
+13 25 xf 13 21 ddf ddf 22 52
+13 25 xf 13 21 ddf ddf 30 52
+17 10 s 17 20 bbf bbf 33 165
+17 10 s 17 20 bbf bbf 40 165
+17 10 s 17 20 bbf bbf 42 165
+17 10 s 17 20 bbf bbf 50 165
+17 10 s 17 27 ccf ccf 20 70
17 10 s 17 27 ccf ccf 22 70
17 10 s 17 27 ccf ccf 28 70
-17 10 s 17 27 ccf ccf 20 70
-17 10 s 17 28 aaf aaf 87 319
-17 10 s 17 28 aaf aaf 60 319
17 10 s 17 28 aaf aaf 25 319
-17 10 s 17 28 aaf aaf 92 319
17 10 s 17 28 aaf aaf 25 319
17 10 s 17 28 aaf aaf 30 319
-17 10 s 17 20 bbf bbf 50 165
-17 10 s 17 20 bbf bbf 42 165
-17 10 s 17 20 bbf bbf 40 165
-17 10 s 17 20 bbf bbf 33 165
-11 20 v 11 24 bbf bbf 50 165
-11 20 v 11 24 bbf bbf 42 165
-11 20 v 11 24 bbf bbf 40 165
-11 20 v 11 24 bbf bbf 33 165
-12 23 y 12 22 aaf aaf 87 319
-12 23 y 12 22 aaf aaf 60 319
-12 23 y 12 22 aaf aaf 25 319
-12 23 y 12 22 aaf aaf 92 319
-12 23 y 12 22 aaf aaf 25 319
-12 23 y 12 22 aaf aaf 30 319
-12 23 y 12 21 aaf aaf 87 319
-12 23 y 12 21 aaf aaf 60 319
-12 23 y 12 21 aaf aaf 25 319
-12 23 y 12 21 aaf aaf 92 319
-12 23 y 12 21 aaf aaf 25 319
-12 23 y 12 21 aaf aaf 30 319
+17 10 s 17 28 aaf aaf 60 319
+17 10 s 17 28 aaf aaf 87 319
+17 10 s 17 28 aaf aaf 92 319
+17 18 a 17 20 bbf bbf 33 165
+17 18 a 17 20 bbf bbf 40 165
+17 18 a 17 20 bbf bbf 42 165
+17 18 a 17 20 bbf bbf 50 165
+17 18 a 17 27 ccf ccf 20 70
17 18 a 17 27 ccf ccf 22 70
17 18 a 17 27 ccf ccf 28 70
-17 18 a 17 27 ccf ccf 20 70
-17 18 a 17 28 aaf aaf 87 319
-17 18 a 17 28 aaf aaf 60 319
17 18 a 17 28 aaf aaf 25 319
-17 18 a 17 28 aaf aaf 92 319
17 18 a 17 28 aaf aaf 25 319
17 18 a 17 28 aaf aaf 30 319
-17 18 a 17 20 bbf bbf 50 165
-17 18 a 17 20 bbf bbf 42 165
-17 18 a 17 20 bbf bbf 40 165
-17 18 a 17 20 bbf bbf 33 165
-11 30 d 11 24 bbf bbf 50 165
-11 30 d 11 24 bbf bbf 42 165
-11 30 d 11 24 bbf bbf 40 165
-11 30 d 11 24 bbf bbf 33 165
+17 18 a 17 28 aaf aaf 60 319
+17 18 a 17 28 aaf aaf 87 319
+17 18 a 17 28 aaf aaf 92 319
+17 20 xf 17 20 bbf bbf 33 165
+17 20 xf 17 20 bbf bbf 40 165
+17 20 xf 17 20 bbf bbf 42 165
+17 20 xf 17 20 bbf bbf 50 165
+17 20 xf 17 27 ccf ccf 20 70
17 20 xf 17 27 ccf ccf 22 70
17 20 xf 17 27 ccf ccf 28 70
-17 20 xf 17 27 ccf ccf 20 70
-17 20 xf 17 28 aaf aaf 87 319
-17 20 xf 17 28 aaf aaf 60 319
17 20 xf 17 28 aaf aaf 25 319
-17 20 xf 17 28 aaf aaf 92 319
17 20 xf 17 28 aaf aaf 25 319
17 20 xf 17 28 aaf aaf 30 319
-17 20 xf 17 20 bbf bbf 50 165
-17 20 xf 17 20 bbf bbf 42 165
-17 20 xf 17 20 bbf bbf 40 165
-17 20 xf 17 20 bbf bbf 33 165
-11 30 af 11 24 bbf bbf 50 165
-11 30 af 11 24 bbf bbf 42 165
-11 30 af 11 24 bbf bbf 40 165
-11 30 af 11 24 bbf bbf 33 165
-12 33 bf 12 22 aaf aaf 87 319
-12 33 bf 12 22 aaf aaf 60 319
-12 33 bf 12 22 aaf aaf 25 319
-12 33 bf 12 22 aaf aaf 92 319
-12 33 bf 12 22 aaf aaf 25 319
-12 33 bf 12 22 aaf aaf 30 319
-12 33 bf 12 21 aaf aaf 87 319
-12 33 bf 12 21 aaf aaf 60 319
-12 33 bf 12 21 aaf aaf 25 319
-12 33 bf 12 21 aaf aaf 92 319
-12 33 bf 12 21 aaf aaf 25 319
-12 33 bf 12 21 aaf aaf 30 319
+17 20 xf 17 28 aaf aaf 60 319
+17 20 xf 17 28 aaf aaf 87 319
+17 20 xf 17 28 aaf aaf 92 319
+17 28 zf 17 20 bbf bbf 33 165
+17 28 zf 17 20 bbf bbf 40 165
+17 28 zf 17 20 bbf bbf 42 165
+17 28 zf 17 20 bbf bbf 50 165
+17 28 zf 17 27 ccf ccf 20 70
17 28 zf 17 27 ccf ccf 22 70
17 28 zf 17 27 ccf ccf 28 70
-17 28 zf 17 27 ccf ccf 20 70
-17 28 zf 17 28 aaf aaf 87 319
-17 28 zf 17 28 aaf aaf 60 319
17 28 zf 17 28 aaf aaf 25 319
-17 28 zf 17 28 aaf aaf 92 319
17 28 zf 17 28 aaf aaf 25 319
17 28 zf 17 28 aaf aaf 30 319
-17 28 zf 17 20 bbf bbf 50 165
-17 28 zf 17 20 bbf bbf 42 165
-17 28 zf 17 20 bbf bbf 40 165
-17 28 zf 17 20 bbf bbf 33 165
-13 25 xf 13 21 ddf ddf 30 52
-13 25 xf 13 21 ddf ddf 22 52
-18 22 tf 18 21 aaf aaf 87 319
-18 22 tf 18 21 aaf aaf 60 319
+17 28 zf 17 28 aaf aaf 60 319
+17 28 zf 17 28 aaf aaf 87 319
+17 28 zf 17 28 aaf aaf 92 319
18 22 tf 18 21 aaf aaf 25 319
-18 22 tf 18 21 aaf aaf 92 319
18 22 tf 18 21 aaf aaf 25 319
18 22 tf 18 21 aaf aaf 30 319
-select *
-from t2, t3, (select c, b, sum(b) over (partition by c) from t4 ) t
-where t2.b < 40 and t2.a=t3.a and t3.c=t.c;
-a b c a b c c b sum(b) over (partition by c)
+18 22 tf 18 21 aaf aaf 60 319
+18 22 tf 18 21 aaf aaf 87 319
+18 22 tf 18 21 aaf aaf 92 319
+2 23 b 2 11 aa aa 15 259
+2 23 b 2 11 aa aa 15 259
+2 23 b 2 11 aa aa 20 259
+2 23 b 2 11 aa aa 50 259
+2 23 b 2 11 aa aa 77 259
+2 23 b 2 11 aa aa 82 259
+2 23 b 2 12 aa aa 15 259
+2 23 b 2 12 aa aa 15 259
+2 23 b 2 12 aa aa 20 259
+2 23 b 2 12 aa aa 50 259
+2 23 b 2 12 aa aa 77 259
+2 23 b 2 12 aa aa 82 259
+3 15 x 3 11 dd dd 12 32
+3 15 x 3 11 dd dd 20 32
+7 10 x 7 10 bb bb 23 125
+7 10 x 7 10 bb bb 30 125
+7 10 x 7 10 bb bb 32 125
+7 10 x 7 10 bb bb 40 125
+7 10 x 7 17 cc cc 10 40
7 10 x 7 17 cc cc 12 40
7 10 x 7 17 cc cc 18 40
-7 10 x 7 17 cc cc 10 40
-7 10 x 7 18 aa aa 77 259
-7 10 x 7 18 aa aa 50 259
7 10 x 7 18 aa aa 15 259
-7 10 x 7 18 aa aa 82 259
7 10 x 7 18 aa aa 15 259
7 10 x 7 18 aa aa 20 259
-7 10 x 7 10 bb bb 40 125
-7 10 x 7 10 bb bb 32 125
-7 10 x 7 10 bb bb 30 125
-7 10 x 7 10 bb bb 23 125
-1 20 a 1 14 bb bb 40 125
-1 20 a 1 14 bb bb 32 125
-1 20 a 1 14 bb bb 30 125
-1 20 a 1 14 bb bb 23 125
-2 23 b 2 12 aa aa 77 259
-2 23 b 2 12 aa aa 50 259
-2 23 b 2 12 aa aa 15 259
-2 23 b 2 12 aa aa 82 259
-2 23 b 2 12 aa aa 15 259
-2 23 b 2 12 aa aa 20 259
-2 23 b 2 11 aa aa 77 259
-2 23 b 2 11 aa aa 50 259
-2 23 b 2 11 aa aa 15 259
-2 23 b 2 11 aa aa 82 259
-2 23 b 2 11 aa aa 15 259
-2 23 b 2 11 aa aa 20 259
+7 10 x 7 18 aa aa 50 259
+7 10 x 7 18 aa aa 77 259
+7 10 x 7 18 aa aa 82 259
+7 18 z 7 10 bb bb 23 125
+7 18 z 7 10 bb bb 30 125
+7 18 z 7 10 bb bb 32 125
+7 18 z 7 10 bb bb 40 125
+7 18 z 7 17 cc cc 10 40
7 18 z 7 17 cc cc 12 40
7 18 z 7 17 cc cc 18 40
-7 18 z 7 17 cc cc 10 40
-7 18 z 7 18 aa aa 77 259
-7 18 z 7 18 aa aa 50 259
7 18 z 7 18 aa aa 15 259
-7 18 z 7 18 aa aa 82 259
7 18 z 7 18 aa aa 15 259
7 18 z 7 18 aa aa 20 259
-7 18 z 7 10 bb bb 40 125
-7 18 z 7 10 bb bb 32 125
-7 18 z 7 10 bb bb 30 125
-7 18 z 7 10 bb bb 23 125
-1 30 c 1 14 bb bb 40 125
-1 30 c 1 14 bb bb 32 125
-1 30 c 1 14 bb bb 30 125
-1 30 c 1 14 bb bb 23 125
-3 15 x 3 11 dd dd 20 32
-3 15 x 3 11 dd dd 12 32
-8 12 t 8 11 aa aa 77 259
-8 12 t 8 11 aa aa 50 259
+7 18 z 7 18 aa aa 50 259
+7 18 z 7 18 aa aa 77 259
+7 18 z 7 18 aa aa 82 259
8 12 t 8 11 aa aa 15 259
-8 12 t 8 11 aa aa 82 259
8 12 t 8 11 aa aa 15 259
8 12 t 8 11 aa aa 20 259
-11 33 a 11 24 bbf bbf 50 165
-11 33 a 11 24 bbf bbf 42 165
-11 33 a 11 24 bbf bbf 40 165
+8 12 t 8 11 aa aa 50 259
+8 12 t 8 11 aa aa 77 259
+8 12 t 8 11 aa aa 82 259
+select *
+from t2, t3, (select c, b, sum(b) over (partition by c) from t4 ) t
+where t2.b < 40 and t2.a=t3.a and t3.c=t.c;
+a b c a b c c b sum(b) over (partition by c)
+1 20 a 1 14 bb bb 23 125
+1 20 a 1 14 bb bb 30 125
+1 20 a 1 14 bb bb 32 125
+1 20 a 1 14 bb bb 40 125
+1 30 c 1 14 bb bb 23 125
+1 30 c 1 14 bb bb 30 125
+1 30 c 1 14 bb bb 32 125
+1 30 c 1 14 bb bb 40 125
+11 20 v 11 24 bbf bbf 33 165
+11 20 v 11 24 bbf bbf 40 165
+11 20 v 11 24 bbf bbf 42 165
+11 20 v 11 24 bbf bbf 50 165
+11 30 af 11 24 bbf bbf 33 165
+11 30 af 11 24 bbf bbf 40 165
+11 30 af 11 24 bbf bbf 42 165
+11 30 af 11 24 bbf bbf 50 165
+11 30 d 11 24 bbf bbf 33 165
+11 30 d 11 24 bbf bbf 40 165
+11 30 d 11 24 bbf bbf 42 165
+11 30 d 11 24 bbf bbf 50 165
11 33 a 11 24 bbf bbf 33 165
+11 33 a 11 24 bbf bbf 40 165
+11 33 a 11 24 bbf bbf 42 165
+11 33 a 11 24 bbf bbf 50 165
+12 23 y 12 21 aaf aaf 25 319
+12 23 y 12 21 aaf aaf 25 319
+12 23 y 12 21 aaf aaf 30 319
+12 23 y 12 21 aaf aaf 60 319
+12 23 y 12 21 aaf aaf 87 319
+12 23 y 12 21 aaf aaf 92 319
+12 23 y 12 22 aaf aaf 25 319
+12 23 y 12 22 aaf aaf 25 319
+12 23 y 12 22 aaf aaf 30 319
+12 23 y 12 22 aaf aaf 60 319
+12 23 y 12 22 aaf aaf 87 319
+12 23 y 12 22 aaf aaf 92 319
+12 33 bf 12 21 aaf aaf 25 319
+12 33 bf 12 21 aaf aaf 25 319
+12 33 bf 12 21 aaf aaf 30 319
+12 33 bf 12 21 aaf aaf 60 319
+12 33 bf 12 21 aaf aaf 87 319
+12 33 bf 12 21 aaf aaf 92 319
+12 33 bf 12 22 aaf aaf 25 319
+12 33 bf 12 22 aaf aaf 25 319
+12 33 bf 12 22 aaf aaf 30 319
+12 33 bf 12 22 aaf aaf 60 319
+12 33 bf 12 22 aaf aaf 87 319
+12 33 bf 12 22 aaf aaf 92 319
+13 25 xf 13 21 ddf ddf 22 52
+13 25 xf 13 21 ddf ddf 30 52
+17 10 s 17 20 bbf bbf 33 165
+17 10 s 17 20 bbf bbf 40 165
+17 10 s 17 20 bbf bbf 42 165
+17 10 s 17 20 bbf bbf 50 165
+17 10 s 17 27 ccf ccf 20 70
17 10 s 17 27 ccf ccf 22 70
17 10 s 17 27 ccf ccf 28 70
-17 10 s 17 27 ccf ccf 20 70
-17 10 s 17 28 aaf aaf 87 319
-17 10 s 17 28 aaf aaf 60 319
17 10 s 17 28 aaf aaf 25 319
-17 10 s 17 28 aaf aaf 92 319
17 10 s 17 28 aaf aaf 25 319
17 10 s 17 28 aaf aaf 30 319
-17 10 s 17 20 bbf bbf 50 165
-17 10 s 17 20 bbf bbf 42 165
-17 10 s 17 20 bbf bbf 40 165
-17 10 s 17 20 bbf bbf 33 165
-11 20 v 11 24 bbf bbf 50 165
-11 20 v 11 24 bbf bbf 42 165
-11 20 v 11 24 bbf bbf 40 165
-11 20 v 11 24 bbf bbf 33 165
-12 23 y 12 22 aaf aaf 87 319
-12 23 y 12 22 aaf aaf 60 319
-12 23 y 12 22 aaf aaf 25 319
-12 23 y 12 22 aaf aaf 92 319
-12 23 y 12 22 aaf aaf 25 319
-12 23 y 12 22 aaf aaf 30 319
-12 23 y 12 21 aaf aaf 87 319
-12 23 y 12 21 aaf aaf 60 319
-12 23 y 12 21 aaf aaf 25 319
-12 23 y 12 21 aaf aaf 92 319
-12 23 y 12 21 aaf aaf 25 319
-12 23 y 12 21 aaf aaf 30 319
+17 10 s 17 28 aaf aaf 60 319
+17 10 s 17 28 aaf aaf 87 319
+17 10 s 17 28 aaf aaf 92 319
+17 18 a 17 20 bbf bbf 33 165
+17 18 a 17 20 bbf bbf 40 165
+17 18 a 17 20 bbf bbf 42 165
+17 18 a 17 20 bbf bbf 50 165
+17 18 a 17 27 ccf ccf 20 70
17 18 a 17 27 ccf ccf 22 70
17 18 a 17 27 ccf ccf 28 70
-17 18 a 17 27 ccf ccf 20 70
-17 18 a 17 28 aaf aaf 87 319
-17 18 a 17 28 aaf aaf 60 319
17 18 a 17 28 aaf aaf 25 319
-17 18 a 17 28 aaf aaf 92 319
17 18 a 17 28 aaf aaf 25 319
17 18 a 17 28 aaf aaf 30 319
-17 18 a 17 20 bbf bbf 50 165
-17 18 a 17 20 bbf bbf 42 165
-17 18 a 17 20 bbf bbf 40 165
-17 18 a 17 20 bbf bbf 33 165
-11 30 d 11 24 bbf bbf 50 165
-11 30 d 11 24 bbf bbf 42 165
-11 30 d 11 24 bbf bbf 40 165
-11 30 d 11 24 bbf bbf 33 165
+17 18 a 17 28 aaf aaf 60 319
+17 18 a 17 28 aaf aaf 87 319
+17 18 a 17 28 aaf aaf 92 319
+17 20 xf 17 20 bbf bbf 33 165
+17 20 xf 17 20 bbf bbf 40 165
+17 20 xf 17 20 bbf bbf 42 165
+17 20 xf 17 20 bbf bbf 50 165
+17 20 xf 17 27 ccf ccf 20 70
17 20 xf 17 27 ccf ccf 22 70
17 20 xf 17 27 ccf ccf 28 70
-17 20 xf 17 27 ccf ccf 20 70
-17 20 xf 17 28 aaf aaf 87 319
-17 20 xf 17 28 aaf aaf 60 319
17 20 xf 17 28 aaf aaf 25 319
-17 20 xf 17 28 aaf aaf 92 319
17 20 xf 17 28 aaf aaf 25 319
17 20 xf 17 28 aaf aaf 30 319
-17 20 xf 17 20 bbf bbf 50 165
-17 20 xf 17 20 bbf bbf 42 165
-17 20 xf 17 20 bbf bbf 40 165
-17 20 xf 17 20 bbf bbf 33 165
-11 30 af 11 24 bbf bbf 50 165
-11 30 af 11 24 bbf bbf 42 165
-11 30 af 11 24 bbf bbf 40 165
-11 30 af 11 24 bbf bbf 33 165
-12 33 bf 12 22 aaf aaf 87 319
-12 33 bf 12 22 aaf aaf 60 319
-12 33 bf 12 22 aaf aaf 25 319
-12 33 bf 12 22 aaf aaf 92 319
-12 33 bf 12 22 aaf aaf 25 319
-12 33 bf 12 22 aaf aaf 30 319
-12 33 bf 12 21 aaf aaf 87 319
-12 33 bf 12 21 aaf aaf 60 319
-12 33 bf 12 21 aaf aaf 25 319
-12 33 bf 12 21 aaf aaf 92 319
-12 33 bf 12 21 aaf aaf 25 319
-12 33 bf 12 21 aaf aaf 30 319
+17 20 xf 17 28 aaf aaf 60 319
+17 20 xf 17 28 aaf aaf 87 319
+17 20 xf 17 28 aaf aaf 92 319
+17 28 zf 17 20 bbf bbf 33 165
+17 28 zf 17 20 bbf bbf 40 165
+17 28 zf 17 20 bbf bbf 42 165
+17 28 zf 17 20 bbf bbf 50 165
+17 28 zf 17 27 ccf ccf 20 70
17 28 zf 17 27 ccf ccf 22 70
17 28 zf 17 27 ccf ccf 28 70
-17 28 zf 17 27 ccf ccf 20 70
-17 28 zf 17 28 aaf aaf 87 319
-17 28 zf 17 28 aaf aaf 60 319
17 28 zf 17 28 aaf aaf 25 319
-17 28 zf 17 28 aaf aaf 92 319
17 28 zf 17 28 aaf aaf 25 319
17 28 zf 17 28 aaf aaf 30 319
-17 28 zf 17 20 bbf bbf 50 165
-17 28 zf 17 20 bbf bbf 42 165
-17 28 zf 17 20 bbf bbf 40 165
-17 28 zf 17 20 bbf bbf 33 165
-13 25 xf 13 21 ddf ddf 30 52
-13 25 xf 13 21 ddf ddf 22 52
-18 22 tf 18 21 aaf aaf 87 319
-18 22 tf 18 21 aaf aaf 60 319
+17 28 zf 17 28 aaf aaf 60 319
+17 28 zf 17 28 aaf aaf 87 319
+17 28 zf 17 28 aaf aaf 92 319
18 22 tf 18 21 aaf aaf 25 319
-18 22 tf 18 21 aaf aaf 92 319
18 22 tf 18 21 aaf aaf 25 319
18 22 tf 18 21 aaf aaf 30 319
+18 22 tf 18 21 aaf aaf 60 319
+18 22 tf 18 21 aaf aaf 87 319
+18 22 tf 18 21 aaf aaf 92 319
+2 23 b 2 11 aa aa 15 259
+2 23 b 2 11 aa aa 15 259
+2 23 b 2 11 aa aa 20 259
+2 23 b 2 11 aa aa 50 259
+2 23 b 2 11 aa aa 77 259
+2 23 b 2 11 aa aa 82 259
+2 23 b 2 12 aa aa 15 259
+2 23 b 2 12 aa aa 15 259
+2 23 b 2 12 aa aa 20 259
+2 23 b 2 12 aa aa 50 259
+2 23 b 2 12 aa aa 77 259
+2 23 b 2 12 aa aa 82 259
+3 15 x 3 11 dd dd 12 32
+3 15 x 3 11 dd dd 20 32
+7 10 x 7 10 bb bb 23 125
+7 10 x 7 10 bb bb 30 125
+7 10 x 7 10 bb bb 32 125
+7 10 x 7 10 bb bb 40 125
+7 10 x 7 17 cc cc 10 40
+7 10 x 7 17 cc cc 12 40
+7 10 x 7 17 cc cc 18 40
+7 10 x 7 18 aa aa 15 259
+7 10 x 7 18 aa aa 15 259
+7 10 x 7 18 aa aa 20 259
+7 10 x 7 18 aa aa 50 259
+7 10 x 7 18 aa aa 77 259
+7 10 x 7 18 aa aa 82 259
+7 18 z 7 10 bb bb 23 125
+7 18 z 7 10 bb bb 30 125
+7 18 z 7 10 bb bb 32 125
+7 18 z 7 10 bb bb 40 125
+7 18 z 7 17 cc cc 10 40
+7 18 z 7 17 cc cc 12 40
+7 18 z 7 17 cc cc 18 40
+7 18 z 7 18 aa aa 15 259
+7 18 z 7 18 aa aa 15 259
+7 18 z 7 18 aa aa 20 259
+7 18 z 7 18 aa aa 50 259
+7 18 z 7 18 aa aa 77 259
+7 18 z 7 18 aa aa 82 259
+8 12 t 8 11 aa aa 15 259
+8 12 t 8 11 aa aa 15 259
+8 12 t 8 11 aa aa 20 259
+8 12 t 8 11 aa aa 50 259
+8 12 t 8 11 aa aa 77 259
+8 12 t 8 11 aa aa 82 259
explain extended select *
from t2, t3, (select c, b, sum(b) over (partition by c) from t4 ) t
where t2.b < 40 and t2.a=t3.a and t3.c=t.c;
@@ -15892,31 +16472,31 @@ cte as (select median(f2) over (partition by f1) as k1 from t1 order by f1),
cte1 as (select median(f4) over (partition by f1) as k2 from t1)
select k1,k2 from cte1, cte;
k1 k2
-1.0000000000 9.0000000000
-1.0000000000 9.0000000000
-1.0000000000 8.0000000000
-1.0000000000 0.0000000000
-1.0000000000 9.0000000000
+0.0000000000 0.0000000000
+0.0000000000 0.0000000000
+0.0000000000 0.0000000000
+0.0000000000 0.0000000000
+0.0000000000 8.0000000000
+0.0000000000 8.0000000000
+0.0000000000 8.0000000000
+0.0000000000 8.0000000000
0.0000000000 9.0000000000
0.0000000000 9.0000000000
-0.0000000000 8.0000000000
-0.0000000000 0.0000000000
0.0000000000 9.0000000000
0.0000000000 9.0000000000
0.0000000000 9.0000000000
-0.0000000000 8.0000000000
-0.0000000000 0.0000000000
0.0000000000 9.0000000000
0.0000000000 9.0000000000
0.0000000000 9.0000000000
-0.0000000000 8.0000000000
-0.0000000000 0.0000000000
0.0000000000 9.0000000000
0.0000000000 9.0000000000
0.0000000000 9.0000000000
-0.0000000000 8.0000000000
-0.0000000000 0.0000000000
0.0000000000 9.0000000000
+1.0000000000 0.0000000000
+1.0000000000 8.0000000000
+1.0000000000 9.0000000000
+1.0000000000 9.0000000000
+1.0000000000 9.0000000000
explain with
cte as (select median(f2) over (partition by f1) as k1 from t1 order by f1),
cte1 as (select median(f4) over (partition by f1) as k2 from t1)
@@ -15961,586 +16541,6 @@ f c
DROP VIEW v1;
DROP TABLE t1;
#
-# MDEV-15087: error from inexpensive subquery before check
-# for condition pushdown into derived
-#
-CREATE TABLE t1 (i1 int, v1 varchar(1));
-INSERT INTO t1 VALUES (7,'x');
-CREATE TABLE t2 (i1 int);
-INSERT INTO t2 VALUES (8);
-CREATE TABLE t3 (i1 int ,v1 varchar(1), v2 varchar(1));
-INSERT INTO t3 VALUES (4, 'v','v'),(62,'v','k'),(7, 'n', NULL);
-SELECT 1
-FROM (t1 AS a1
-JOIN (((SELECT DISTINCT t3.*
-FROM t3) AS a2
-JOIN t1 ON (t1.v1 = a2.v2))) ON (t1.v1 = a2.v1))
-WHERE (SELECT BIT_COUNT(t2.i1)
-FROM (t2 JOIN t3)) IS NULL;
-ERROR 21000: Subquery returns more than 1 row
-DROP TABLE t1, t2, t3;
-#
-# MDEV-16614 signal 7 after calling stored procedure, that uses regexp
-#
-CREATE PROCEDURE p1(m1 varchar(5), m2 varchar(5))
-BEGIN
-SELECT a FROM
-(SELECT "aa" a) t
-JOIN (SELECT "aa" b) t1 on t.a=t1.b
-WHERE t.a regexp m1 and t1.b regexp m2
-GROUP BY a;
-END$$
-CALL p1('a','a');
-a
-aa
-DROP PROCEDURE p1;
-CREATE PROCEDURE p1(m1 varchar(5))
-BEGIN
-SELECT a FROM (SELECT "aa" a) t WHERE t.a regexp m1;
-END$$
-CALL p1('a');
-a
-aa
-DROP PROCEDURE p1;
-SELECT a FROM (SELECT "aa" a) t WHERE REGEXP_INSTR(t.a, (SELECT MAX('aa') FROM DUAL LIMIT 1));
-a
-aa
-CREATE OR REPLACE FUNCTION f1(a VARCHAR(10), b VARCHAR(10)) RETURNS INT
-BEGIN
-RETURN 1;
-END;$$
-CREATE OR REPLACE PROCEDURE p1(m1 varchar(5))
-BEGIN
-SELECT a FROM (SELECT "aa" a) t WHERE f1(t.a, m1);
-END$$
-CALL p1('a');
-a
-aa
-DROP PROCEDURE p1;
-DROP FUNCTION f1;
-CREATE OR REPLACE FUNCTION f1(a VARCHAR(10), b VARCHAR(10)) RETURNS INT
-BEGIN
-RETURN 1;
-END;$$
-SELECT a FROM (SELECT "aa" a) t WHERE f1(t.a, (SELECT MAX('aa') FROM DUAL LIMIT 1));
-a
-aa
-DROP FUNCTION f1;
-#
-# MDEV-17011: condition pushdown into materialized derived used
-# in INSERT SELECT, multi-table UPDATE and DELETE
-#
-CREATE TABLE t1 (a int ,b int) ENGINE=MyISAM;
-INSERT INTO t1 VALUES
-(1, 1), (1, 2), (2, 1), (2, 2), (3,1), (3,3), (4,2);
-CREATE TABLE t2 (a int) ENGINE MYISAM;
-INSERT INTO t2 VALUES
-(3), (7), (1), (4), (1);
-CREATE TABLE t3 (a int, b int) ENGINE MYISAM;
-EXPLAIN FORMAT=JSON INSERT INTO t3
-SELECT * FROM (SELECT a, count(*) as c FROM t1 GROUP BY a) t WHERE a<=2;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 7,
- "filtered": 100,
- "attached_condition": "t.a <= 2",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "filesort": {
- "sort_key": "t1.a",
- "temporary_table": {
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 7,
- "filtered": 100,
- "attached_condition": "t1.a <= 2"
- }
- }
- }
- }
- }
- }
- }
-}
-INSERT INTO t3
-SELECT * FROM (SELECT a, count(*) as c FROM t1 GROUP BY a) t WHERE a<=2;
-SELECT * FROM t3;
-a b
-1 2
-2 2
-EXPLAIN FORMAT=JSON UPDATE t2, (SELECT a, count(*) as c FROM t1 GROUP BY a) t SET t2.a=t.c+10
-WHERE t2.a= t.c and t.a>=3;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 5,
- "filtered": 100,
- "attached_condition": "t2.a is not null"
- },
- "table": {
- "table_name": "<derived2>",
- "access_type": "ref",
- "possible_keys": ["key0"],
- "key": "key0",
- "key_length": "8",
- "used_key_parts": ["c"],
- "ref": ["test.t2.a"],
- "rows": 2,
- "filtered": 100,
- "attached_condition": "t2.a = t.c and t.a >= 3",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "filesort": {
- "sort_key": "t1.a",
- "temporary_table": {
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 7,
- "filtered": 100,
- "attached_condition": "t1.a >= 3"
- }
- }
- }
- }
- }
- }
- }
-}
-UPDATE t2, (SELECT a, count(*) as c FROM t1 GROUP BY a) t SET t2.a=t.c+10
-WHERE t2.a= t.c and t.a>=3;
-SELECT * FROM t2;
-a
-3
-7
-11
-4
-11
-EXPLAIN FORMAT=JSON DELETE t2 FROM t2, (SELECT a, count(*) as c FROM t1 GROUP BY a) t
-WHERE t2.a= t.c+9 and t.a=2;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 5,
- "filtered": 100
- },
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 7,
- "filtered": 100,
- "attached_condition": "t.a = 2 and t2.a = t.c + 9",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 7,
- "filtered": 100,
- "attached_condition": "t1.a = 2"
- }
- }
- }
- }
- }
-}
-DELETE t2 FROM t2, (SELECT a, count(*) as c FROM t1 GROUP BY a) t
-WHERE t2.a= t.c+9 and t.a=2;
-SELECT * FROM t2;
-a
-3
-7
-4
-DROP TABLE t1,t2,t3;
-#
-# MDEV-16765: pushdown condition with the CASE structure
-# defined with Item_cond item
-#
-CREATE TABLE t1(a INT, b INT);
-INSERT INTO t1 VALUES (1,2), (3,4), (2,3);
-SELECT *
-FROM
-(
-SELECT CASE WHEN ((tab2.max_a=1) OR (tab2.max_a=2))
-THEN 1 ELSE 0 END AS max_a,b
-FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
-) AS tab1
-WHERE (tab1.max_a=1);
-max_a b
-1 2
-1 3
-EXPLAIN FORMAT=JSON SELECT *
-FROM
-(
-SELECT CASE WHEN ((tab2.max_a=1) OR (tab2.max_a=2))
-THEN 1 ELSE 0 END AS max_a,b
-FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
-) AS tab1
-WHERE (tab1.max_a=1);
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<derived3>",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "case when (tab2.max_a = 1 or tab2.max_a = 2) then 1 else 0 end = 1",
- "materialized": {
- "query_block": {
- "select_id": 3,
- "having_condition": "case when (max_a = 1 or max_a = 2) then 1 else 0 end = 1",
- "filesort": {
- "sort_key": "t1.b",
- "temporary_table": {
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100
- }
- }
- }
- }
- }
- }
- }
-}
-SELECT *
-FROM
-(
-SELECT CASE WHEN ((tab2.max_a=1) OR ((tab2.max_a>2) AND (tab2.max_a<4)))
-THEN 1 ELSE 0 END AS max_a,b
-FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
-) AS tab1
-WHERE (tab1.max_a=1);
-max_a b
-1 2
-1 4
-EXPLAIN FORMAT=JSON SELECT *
-FROM
-(
-SELECT CASE WHEN ((tab2.max_a=1) OR ((tab2.max_a>2) AND (tab2.max_a<4)))
-THEN 1 ELSE 0 END AS max_a,b
-FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
-) AS tab1
-WHERE (tab1.max_a=1);
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<derived3>",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "case when (tab2.max_a = 1 or tab2.max_a > 2 and tab2.max_a < 4) then 1 else 0 end = 1",
- "materialized": {
- "query_block": {
- "select_id": 3,
- "having_condition": "case when (max_a = 1 or max_a > 2 and max_a < 4) then 1 else 0 end = 1",
- "filesort": {
- "sort_key": "t1.b",
- "temporary_table": {
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100
- }
- }
- }
- }
- }
- }
- }
-}
-SELECT *
-FROM
-(
-SELECT CASE WHEN ((tab2.max_a>1) AND ((tab2.max_a=2) OR (tab2.max_a>2)))
-THEN 1 ELSE 0 END AS max_a,b
-FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
-) AS tab1
-WHERE (tab1.max_a=1);
-max_a b
-1 3
-1 4
-EXPLAIN FORMAT=JSON SELECT *
-FROM
-(
-SELECT CASE WHEN ((tab2.max_a>1) AND ((tab2.max_a=2) OR (tab2.max_a>2)))
-THEN 1 ELSE 0 END AS max_a,b
-FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
-) AS tab1
-WHERE (tab1.max_a=1);
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<derived3>",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "case when (tab2.max_a > 1 and (tab2.max_a = 2 or tab2.max_a > 2)) then 1 else 0 end = 1",
- "materialized": {
- "query_block": {
- "select_id": 3,
- "having_condition": "case when (max_a > 1 and (max_a = 2 or max_a > 2)) then 1 else 0 end = 1",
- "filesort": {
- "sort_key": "t1.b",
- "temporary_table": {
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100
- }
- }
- }
- }
- }
- }
- }
-}
-SELECT *
-FROM
-(
-SELECT CASE WHEN ((tab2.b=2) OR (tab2.b=4))
-THEN 1 ELSE 0 END AS max_a,b
-FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
-) AS tab1
-WHERE (tab1.max_a=1);
-max_a b
-1 2
-1 4
-EXPLAIN FORMAT=JSON SELECT *
-FROM
-(
-SELECT CASE WHEN ((tab2.b=2) OR (tab2.b=4))
-THEN 1 ELSE 0 END AS max_a,b
-FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
-) AS tab1
-WHERE (tab1.max_a=1);
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<derived3>",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "case when (tab2.b = 2 or tab2.b = 4) then 1 else 0 end = 1",
- "materialized": {
- "query_block": {
- "select_id": 3,
- "filesort": {
- "sort_key": "t1.b",
- "temporary_table": {
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 3,
- "filtered": 100,
- "attached_condition": "case when (t1.b = 2 or t1.b = 4) then 1 else 0 end = 1"
- }
- }
- }
- }
- }
- }
- }
-}
-DROP TABLE t1;
-#
-# MDEV-16803: pushdown condition with IN predicate in the derived table
-# defined with several SELECT statements
-#
-CREATE TABLE t1 (a INT, b INT);
-INSERT INTO t1 VALUES (1,2),(3,2),(1,1);
-SELECT * FROM
-(
-SELECT a,b,1 as c
-FROM t1
-UNION ALL
-SELECT a,b,2 as c
-FROM t1
-) AS tab
-WHERE ((a,b) IN ((1,2),(3,2)));
-a b c
-1 2 1
-3 2 1
-1 2 2
-3 2 2
-DROP TABLE t1;
-#
-# MDEV-17354: INSERT SELECT with condition pushdown into derived
-#
-CREATE TABLE t1 (f INT NOT NULL);
-INSERT INTO t1 VALUES (3), (7), (3);
-CREATE ALGORITHM= TEMPTABLE VIEW v1 AS SELECT * FROM ( SELECT * FROM t1 ) AS sq;
-INSERT INTO t1
-SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ) AS t WHERE f IS NOT NULL;
-EXPLAIN INSERT INTO t1
-SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ) AS t WHERE f IS NOT NULL;
-id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <derived2> ALL NULL NULL NULL NULL 144 Using where
-2 DERIVED <derived3> ALL NULL NULL NULL NULL 12
-2 DERIVED t1 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
-3 DERIVED t1 ALL NULL NULL NULL NULL 12
-EXPLAIN FORMAT=JSON INSERT INTO t1
-SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ) AS t WHERE f IS NOT NULL;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 144,
- "filtered": 100,
- "attached_condition": "t.f is not null",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "table": {
- "table_name": "<derived3>",
- "access_type": "ALL",
- "rows": 12,
- "filtered": 100,
- "materialized": {
- "query_block": {
- "select_id": 3,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 12,
- "filtered": 100
- }
- }
- }
- },
- "block-nl-join": {
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 12,
- "filtered": 100,
- "attached_condition": "t1.f is not null"
- },
- "buffer_type": "flat",
- "buffer_size": "256Kb",
- "join_type": "BNL"
- }
- }
- }
- }
- }
-}
-SELECT * FROM t1;
-f
-3
-7
-3
-3
-3
-3
-7
-7
-7
-3
-3
-3
-DELETE FROM t1;
-INSERT INTO t1 VALUES (3), (7), (3);
-INSERT INTO t1
-SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ON v1.f=t1.f) AS t
-WHERE f IS NOT NULL;
-EXPLAIN FORMAT=JSON INSERT INTO t1
-SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ON v1.f=t1.f) AS t
-WHERE f IS NOT NULL;
-EXPLAIN
-{
- "query_block": {
- "select_id": 1,
- "table": {
- "table_name": "<derived2>",
- "access_type": "ALL",
- "rows": 16,
- "filtered": 100,
- "attached_condition": "t.f is not null",
- "materialized": {
- "query_block": {
- "select_id": 2,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 8,
- "filtered": 100,
- "attached_condition": "t1.f is not null"
- },
- "table": {
- "table_name": "<derived3>",
- "access_type": "ref",
- "possible_keys": ["key0"],
- "key": "key0",
- "key_length": "4",
- "used_key_parts": ["f"],
- "ref": ["test.t1.f"],
- "rows": 2,
- "filtered": 100,
- "materialized": {
- "query_block": {
- "select_id": 3,
- "table": {
- "table_name": "t1",
- "access_type": "ALL",
- "rows": 8,
- "filtered": 100,
- "attached_condition": "t1.f is not null"
- }
- }
- }
- }
- }
- }
- }
- }
-}
-SELECT * FROM t1;
-f
-3
-7
-3
-3
-3
-7
-3
-3
-DROP VIEW v1;
-DROP TABLE t1;
-# Start of 10.3 tests
-#
# MDEV-16801: splittable materialized derived/views with
# one grouping field from table without keys
#
@@ -16634,3 +16634,4 @@ id username id userid logindate
2 user2 3 2 2017-06-19 12:17:02
set join_cache_level=default;
DROP TABLE t1,t2;
+# End of 10.3 tests
diff --git a/mysql-test/main/derived_cond_pushdown.test b/mysql-test/main/derived_cond_pushdown.test
index 340aa1f5a54..659bc2026ff 100644
--- a/mysql-test/main/derived_cond_pushdown.test
+++ b/mysql-test/main/derived_cond_pushdown.test
@@ -1,46 +1,46 @@
-let $no_pushdown= set statement optimizer_switch='condition_pushdown_for_derived=off' for;
+let $no_pushdown= set statement optimizer_switch='condition_pushdown_for_derived=off' for;
create table t1 (a int, b int, c int);
create table t2 (a int, b int, c int, d decimal);
-insert into t1 values
+insert into t1 values
(1,21,345), (1,33,7), (8,33,114), (1,21,500), (1,19,107), (5,14,787),
(8,33,123), (9,10,211), (5,16,207), (1,33,988), (5,27,132), (1,21,104),
(6,20,309), (6,20,315), (1,21,101), (8,33,404), (9,10,800), (1,21,123),
(7,11,708), (6,20,214);
insert into t2 values
- (2,3,207,207.0000), (1,21,909,12.0000), (7,13,312,406.0000),
+ (2,3,207,207.0000), (1,21,909,12.0000), (7,13,312,406.0000),
(8,64,248,107.0000), (6,20,315,279.3333), (1,19,203,107.0000),
(8,80,800,314.0000), (3,12,231,190.0000), (6,23,303,909.0000);
-
+
create table t1_double(a int, b double, c double);
-insert into t1_double values
+insert into t1_double values
(1,23.4,14.3333), (1,12.5,18.9), (3,12.5,18.9),
(4,33.4,14.3333), (4,14.3333,13.65), (5,17.89,7.22),
(6,33.4,14.3), (10,33.4,13.65), (11,33.4,13.65);
-
+
create table t2_double(a int, b double, c double);
-insert into t2_double values
+insert into t2_double values
(1,22.4,14.3333), (1,12.5,18.9), (2,22.4,18.9),
(4,33.4,14.3333), (5,22.4,13.65), (7,17.89,18.9),
- (6,33.4,14.3333), (10,31.4,13.65), (12,33.4,13.65);
-
+ (6,33.4,14.3333), (10,31.4,13.65), (12,33.4,13.65);
+
create table t1_char(a char, b char(8), c int);
insert into t1_char values
('a','Ivan',1), ('b','Vika',2), ('b','Inga',6), ('c','Vika',7),
('b','Ivan',7), ('a','Alex',6), ('b','Inga',5), ('d','Ron',9),
- ('d','Harry',2), ('d','Hermione',3), ('c','Ivan',3), ('c','Harry',4);
-
+ ('d','Harry',2), ('d','Hermione',3), ('c','Ivan',3), ('c','Harry',4);
+
create table t2_char(a char, b char(8), c int);
insert into t2_char values
('b','Ivan',1), ('c','Vinny',3), ('c','Inga',9), ('a','Vika',1),
('c','Ivan',2), ('b','Ali',6), ('c','Inga',2), ('a','Ron',9),
('d','Harry',1), ('b','Hermes',3), ('b','Ivan',11), ('b','Harry',4);
-
+
create table t1_decimal (a decimal(3,1), b decimal(3,1), c int);
insert into t1_decimal values
(1,1,23),(2,2,11),(3,3,16),
(1,1,12),(1,1,14),(2,3,15),
- (2,1,13),(2,3,11),(3,3,16);
+ (2,1,13),(2,3,11),(3,3,16);
create table t2_decimal (a decimal(3,1), b decimal(3,1), c int);
insert into t2_decimal values
@@ -48,27 +48,27 @@ insert into t2_decimal values
(1,3,22),(1,3,14),(2,2,15),
(2,1,43),(2,3,11),(2,3,16);
-create view v1 as select a, b, max(c) as max_c, avg(c) as avg_c from t1
+create view v1 as select a, b, max(c) as max_c, avg(c) as avg_c from t1
group by a,b having max_c < 707;
-
-create view v2 as select a, b, max(c) as max_c, avg(c) as avg_c from t1
- where t1.a>5 group by a,b having max_c < 707;
-
+
+create view v2 as select a, b, max(c) as max_c, avg(c) as avg_c from t1
+ where t1.a>5 group by a,b having max_c < 707;
+
create view v3 as select a, b, min(c) as min_c from t1
where t1.a<10 group by a,b having min_c > 109;
-
+
create view v4 as
select a, b, min(max_c) as min_c from v1
- where (v1.a<15) group by a,b;
-
-create view v_union as
+ where (v1.a<15) group by a,b;
+
+create view v_union as
select a, b, min(c) as c from t1
where t1.a<10 group by a,b having c > 109
union
select a, b, max(c) as c from t1
- where t1.b>10 group by a,b having c < 300;
-
-create view v2_union as
+ where t1.b>10 group by a,b having c < 300;
+
+create view v2_union as
select a, b, min(c) as c from t1
where t1.a<10 group by a,b having c > 109
union
@@ -76,117 +76,117 @@ create view v2_union as
where t1.b>10 group by a,b having c < 300
union
select a, b, avg(c) as c from t1
- where t1.c>300 group by a,b having c < 707;
+ where t1.c>300 group by a,b having c < 707;
-create view v3_union as
+create view v3_union as
select a, b, (a+1) as c from t1
where t1.a<10
union
select a, b, c from t1
- where t1.b>10 and t1.c>100;
-
-create view v4_union as
+ where t1.b>10 and t1.c>100;
+
+create view v4_union as
select a, b, max(c)-100 as c from t1
where t1.a<10 group by a,b having c > 109
union
select a, b, (c+100) as c from t1
- where t1.b>10;
+ where t1.b>10;
create view v_double as
select a, avg(a/4) as avg_a, b, c from t1_double
- where (b>12.2) group by b,c having (avg_a<22.333);
-
-create view v_char as
- select a, b, max(c) as max_c from t1_char
- group by a,b having max_c < 9;
-
+ where (b>12.2) group by b,c having (avg_a<22.333);
+
+create view v_char as
+ select a, b, max(c) as max_c from t1_char
+ group by a,b having max_c < 9;
+
create view v_decimal as
select a, b, avg(c) as avg_c from t1_decimal
- group by a,b having (avg_c>12);
+ group by a,b having (avg_c>12);
---echo # conjunctive subformula : pushing into HAVING
+--echo # conjunctive subformula : pushing into HAVING
let $query= select * from v1,t2 where (v1.max_c>214) and (t2.a>v1.a);
eval $no_pushdown $query;
eval $query;
eval explain $query;
eval explain format=json $query;
-let $query=
+let $query=
select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
- group by a,b having max_c < 707) v1,
+ group by a,b having max_c < 707) v1,
t2 where (v1.a=t2.a) and (v1.max_c>300);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
---echo # extracted or formula : pushing into HAVING
-let $query=
- select * from v1,t2 where
+--echo # extracted or formula : pushing into HAVING
+let $query=
+ select * from v1,t2 where
((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
-
-let $query=
+eval explain format=json $query;
+
+let $query=
select * from v1,t2 where
- ((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
+ ((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # conjunctive subformula : pushing into WHERE
let $query= select * from v1,t2 where (v1.a>6) and (t2.b>v1.b);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
let $query= select * from v2,t2 where (v2.b>25) and (t2.a<v2.a);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # extracted or formula : pushing into WHERE
-let $query=
- select * from v1,t2 where
+let $query=
+ select * from v1,t2 where
((v1.a>7) and (t2.c<v1.max_c)) or ((v1.a<2) and (t2.b<v1.b));
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
-
-let $query=
- select * from v2,t2 where
+eval explain format=json $query;
+
+let $query=
+ select * from v2,t2 where
((v2.a>7) and (t2.c<v2.max_c)) or ((v2.a>5) and (t2.b<v2.b));
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
-
-let $query=
- select * from v1,t2 where
- ((v1.a>4) and (v1.b>t2.b) and (v1.max_c=t2.d)) or
+eval explain format=json $query;
+
+let $query=
+ select * from v1,t2 where
+ ((v1.a>4) and (v1.b>t2.b) and (v1.max_c=t2.d)) or
((v1.a<2) and (v1.max_c<t2.c) and (v1.max_c=t2.d));
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # conjunctive subformulas : pushing into HAVING and WHERE
-let $query=
- select * from v1,t2 where (v1.a<2) and (v1.max_c>400) and (t2.b>v1.b);
+let $query=
+ select * from v1,t2 where (v1.a<2) and (v1.max_c>400) and (t2.b>v1.b);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
-let $query=
+let $query=
select * from v_double as v,t2_double as t where
(v.a=t.a) and (v.avg_a>0.45) and (v.b>10);
eval $no_pushdown $query;
@@ -194,57 +194,57 @@ eval $query;
eval explain $query;
eval explain format=json $query;
-let $query=
+let $query=
select * from v_decimal as v,t2_decimal as t where
(v.a=t.a) and (v.avg_c>15) and (v.b>1);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
-
+eval explain format=json $query;
+
--echo # extracted or formula : pushing into HAVING and WHERE
-let $query=
- select * from v1,t2 where
- ((v1.a>7) and (v1.max_c>300) and (t2.c<v1.max_c)) or
- ((v1.a<4) and (v1.max_c<500) and (t2.b<v1.b));
+let $query=
+ select * from v1,t2 where
+ ((v1.a>7) and (v1.max_c>300) and (t2.c<v1.max_c)) or
+ ((v1.a<4) and (v1.max_c<500) and (t2.b<v1.b));
eval $no_pushdown $query;
eval $query;
eval explain $query;
eval explain format=json $query;
-
-let $query=
+
+let $query=
select * from v1,t2 where ((v1.a<2) and (v1.max_c>120)) or (v1.a>7);
eval $no_pushdown $query;
eval $query;
eval explain $query;
eval explain format=json $query;
-
---echo # extracted or formulas : pushing into WHERE and HAVING
-let $query=
- select * from v1,t2 where
+
+--echo # extracted or formulas : pushing into WHERE and HAVING
+let $query=
+ select * from v1,t2 where
((v1.a<2) and (v1.max_c>120) and (v1.b=t2.b)) or (v1.a>7);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
-
-let $query=
+eval explain format=json $query;
+
+let $query=
select * from v1,t2 where
((v1.a<2) and (v1.max_c<200) and (t2.c>v1.max_c) and (v1.max_c=t2.d)) or
- ((v1.a>4) and (v1.max_c<500) and (t2.b<v1.b) and (v1.max_c=t2.c));
+ ((v1.a>4) and (v1.max_c<500) and (t2.b<v1.b) and (v1.max_c=t2.c));
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
-
+eval explain format=json $query;
+
--echo # prepare of a query containing extracted or formula
-prepare stmt from "select * from v1,t2 where
+prepare stmt from "select * from v1,t2 where
((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));";
execute stmt;
execute stmt;
deallocate prepare stmt;
-prepare stmt from
- "explain format=json select * from v1,t2 where
+prepare stmt from
+ "explain format=json select * from v1,t2 where
((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));";
execute stmt;
execute stmt;
@@ -252,12 +252,12 @@ deallocate prepare stmt;
--echo # conjunctive subformula : pushing into WHERE
--echo # pushing equalities
-let $query=
+let $query=
select * from v1,t2 where (t2.a=v1.a) and (v1.b=t2.b) and (v1.a=1);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
let $query= select * from v1,t2 where (v1.a=5) and (v1.max_c=t2.d);
eval $no_pushdown $query;
@@ -270,15 +270,15 @@ let $query= select * from v1,t2 where (t2.a<5) and (v1.a=t2.a);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
-
-let $query=
+eval explain format=json $query;
+
+let $query=
select * from v1,t2 where (v1.a=v1.b) and (v1.a=t2.a);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
-
+eval explain format=json $query;
+
--echo # conjunctive subformula : pushing into HAVING using equalities
let $query= select * from v1,t2 where (t2.c>150) and (v1.max_c=t2.c);
eval $no_pushdown $query;
@@ -286,73 +286,73 @@ eval $query;
eval explain $query;
eval explain format=json $query;
---echo # extracted and formula : pushing into WHERE
+--echo # extracted and formula : pushing into WHERE
--echo # pushing equalities
-let $query=
+let $query=
select * from v1,t2 where (v1.a=v1.b) and (v1.a=t2.a) and (v1.a=3);
eval $no_pushdown $query;
eval $query;
eval explain $query;
eval explain format=json $query;
-
-let $query=
+
+let $query=
select * from v1,t2 where (v1.a=1) and (v1.b=21) and (t2.a=2);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
-let $query=
- select * from v_char as v,t2_char as t where
- (v.a='c') and (v.b<'Hermes') and ((v.b=t.b) or (v.max_c>20));
+let $query=
+ select * from v_char as v,t2_char as t where
+ (v.a='c') and (v.b<'Hermes') and ((v.b=t.b) or (v.max_c>20));
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # extracted and formula : pushing into WHERE using equalities
--echo # pushing equalities
-let $query=
+let $query=
select * from v_decimal as v,t2_decimal as t where
(v.a=v.b) and (v.b=t.b) and ((t.b>1) or (v.a=1));
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
---echo # extracted or formula : pushing into HAVING using equalities
-let $query=
+--echo # extracted or formula : pushing into HAVING using equalities
+let $query=
select * from v1,t2
- where ((t2.a<4) and (v1.a=t2.a)) or ((t2.c>150) and (v1.max_c=t2.c));
+ where ((t2.a<4) and (v1.a=t2.a)) or ((t2.c>150) and (v1.max_c=t2.c));
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # conjunctive subformulas : pushing into WHERE and HAVING using equalities
-let $query=
+let $query=
select * from v1,t2
where ((t2.a>5) and (v1.a=t2.a)) and ((t2.c>250) and (v1.max_c=t2.c));
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # conjunctive subformulas : pushing into WHERE and HAVING
---echo # pushing equalities
-let $query=
+--echo # pushing equalities
+let $query=
select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
- group by a,b having max_c < 707) v1,
+ group by a,b having max_c < 707) v1,
t2 where (v1.a=8) and (v1.a=t2.a) and (v1.max_c=404);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
-
---echo # conjunctive subformulas : pushing into WHERE and HAVING
-let $query=
- select * from v1,t2 where
+eval explain format=json $query;
+
+--echo # conjunctive subformulas : pushing into WHERE and HAVING
+let $query=
+ select * from v1,t2 where
(v1.a>3) and (v1.max_c>200) and (t2.b<v1.b) and (t2.d=v1.max_c);
eval $no_pushdown $query;
eval $query;
@@ -362,17 +362,17 @@ eval explain format=json $query;
--echo # conjunctive subformula : pushing into WHERE
--echo # extracted or formula : pushing into HAVING using equalities
--echo # pushing equalities
-let $query=
+let $query=
select * from v_double as v,t2_double as t where
(v.b=v.c) and (v.c=t.c) and ((t.c>10) or (v.a=1));
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # conjunctive subformula : pushing into WHERE
---echo # extracted or formula : pushing into HAVING using equalities
-let $query=
+--echo # extracted or formula : pushing into HAVING using equalities
+let $query=
select * from v_double as v,t2_double as t where
(((v.a>0.2) or (v.b<17)) or (t.c>17)) and (t.c=v.c) and (v.c>18);
eval $no_pushdown $query;
@@ -383,146 +383,146 @@ eval explain format=json $query;
--echo # extracted or formula : pushing into WHERE
--echo # conjunctive subformula : pushing into HAVING
--echo # pushing equalities
-let $query=
+let $query=
select * from v_decimal as v,t2_decimal as t where
- (((v.a>4) or (v.a=2)) or (v.b>3)) and (v.avg_c=13);
+ (((v.a>4) or (v.a=2)) or (v.b>3)) and (v.avg_c=13);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
-let $query=
+let $query=
select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
- where t1.a>5 group by a,b having max_c < 707) v1,
+ where t1.a>5 group by a,b having max_c < 707) v1,
t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.a=v1.b);
eval $no_pushdown $query;
eval $query;
eval explain $query;
eval explain format=json $query;
-
+
--echo # nothing to push
-let $query=
+let $query=
select * from v1,t2 where (t2.a<2) and (t2.c>900);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.b=t2.b);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
-
-let $query=
- select * from v1,t2 where
- (t2.a=v1.a) or (v1.b=t2.b) and ((v1.a=1) or (v1.a=6));
+eval explain format=json $query;
+
+let $query=
+ select * from v1,t2 where
+ (t2.a=v1.a) or (v1.b=t2.b) and ((v1.a=1) or (v1.a=6));
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
-
-let $query=
+eval explain format=json $query;
+
+let $query=
select * from v1,t2 where (v1.a=1) or (v1.b=21) or (t2.a=2);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
-let $query=
- select * from v1,t2 where
+let $query=
+ select * from v1,t2 where
(t2.a<2) and (t2.c>900) and ((v1.a<t2.a) or (t2.a<11));
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # using several derived tables : nothing to push
-let $query= select * from v1,v2,t2 where
+let $query= select * from v1,v2,t2 where
(v1.a=v2.a) and (v1.a=t2.a) and (v2.b<50);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
-let $query=
- select * from v1,v2,t2 where
+let $query=
+ select * from v1,v2,t2 where
((v1.a=v2.a) or (v1.a=t2.a)) and (t2.b<50) and (v1.b=v2.b);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
-let $query=
- select * from v1,v2,t2 where
+let $query=
+ select * from v1,v2,t2 where
((v1.a=v2.a) and (v1.a=t2.a)) or ((v2.b>13) and (t2.c<115));
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # using several derived tables : pushing in all tables
--echo # conjunctive subformula : pushing into HAVING
--echo # extracted or formula : pushing into WHERE
---echo # pushing equalities
-let $query=
- select * from v1,v2,t2 where ((v1.a=v2.a) or (v1.a=t2.a)) and
+--echo # pushing equalities
+let $query=
+ select * from v1,v2,t2 where ((v1.a=v2.a) or (v1.a=t2.a)) and
((v2.b<50) or (v2.b=19)) and (v1.max_c<300);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
-
+eval explain format=json $query;
+
--echo # using several derived tables : pushing only in one table
--echo # conjunctive subformula : pushing into WHERE
--echo # pushing equalities
-let $query=
- select * from v1,v2,t2 where
- (v1.a=t2.a) and (v1.a=v1.b) and (v1.a=v2.a) and (v2.max_c<300);
+let $query=
+ select * from v1,v2,t2 where
+ (v1.a=t2.a) and (v1.a=v1.b) and (v1.a=v2.a) and (v2.max_c<300);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # using several derived tables : pushing only in one table
--echo # extracted and formula : pushing into WHERE
--echo # conjunctive subformula : pushing into WHERE using equalities
--echo # pushing equalities
-let $query=
+let $query=
select * from v1,v2,t2 where (v1.a=1) and (v1.b>10) and (v1.b=v2.b);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # extracted or formula : pushing into WHERE
--echo # conjunctive subformula : pushing into WHERE using equalities
--echo # pushing equalities
-let $query=
- select * from v_char as v,t2_char as t where
+let $query=
+ select * from v_char as v,t2_char as t where
(v.a=t.a) and (t.a='b') and ((v.b='Vika') or (v.b='Ali'));
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # using several derived tables : pushing in all tables
--echo # extracted or formula : pushing into WHERE
---echo # conjunctive subformulas : pushing into HAVING
+--echo # conjunctive subformulas : pushing into HAVING
--echo # pushing equalities
-let $query=
- select * from v1,v2,v3,t2 where
- ((v1.a=v2.a) or (v1.a=t2.a)) and ((v3.b<50) or (v3.b=33))
+let $query=
+ select * from v1,v2,v3,t2 where
+ ((v1.a=v2.a) or (v1.a=t2.a)) and ((v3.b<50) or (v3.b=33))
and (v1.max_c<500) and (v3.a=t2.a) and (v2.max_c>300);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # using several derived tables : pushing in all tables
---echo # conjunctive subformulas : pushing into HAVING
-let $query=
+--echo # conjunctive subformulas : pushing into HAVING
+let $query=
select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
where t1.a>5 group by a,b having max_c < 707) v1,
@@ -532,11 +532,11 @@ let $query=
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # using several derived tables : pushing in all tables
--echo # extracted or formulas : pushing into HAVING
---echo # conjunctive subformula : pushing into HAVING
+--echo # conjunctive subformula : pushing into HAVING
let $query=
select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
@@ -550,51 +550,51 @@ let $query=
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
-
+eval explain format=json $query;
+
--echo # extracted or formula : pushing into HAVING
---echo # conjunctive subformula : pushing into WHERE
-let $query=
+--echo # conjunctive subformula : pushing into WHERE
+let $query=
select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
- group by a,b having max_c < 707) v1,
- t2 where ((v1.a=1) or (v1.max_c<300)) and (v1.b>25);
+ group by a,b having max_c < 707) v1,
+ t2 where ((v1.a=1) or (v1.max_c<300)) and (v1.b>25);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
-
+eval explain format=json $query;
+
--echo # extracted and formula : pushing into WHERE
---echo # conjunctive subformula : pushing into HAVING
-let $query=
+--echo # conjunctive subformula : pushing into HAVING
+let $query=
select * from
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
- where t1.a>5 group by a,b having max_c < 707) v1,
- t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.b<30);
+ where t1.a>5 group by a,b having max_c < 707) v1,
+ t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.b<30);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # using query with union
--echo # conjunctive subformula : pushing into WHERE
--echo # conjunctive subformulas : pushing into HAVING and WHERE
-let $query=
+let $query=
select * from v1,t2 where (v1.a<5) and (v1.b=t2.b) and (t2.c>800)
union
- select * from v1,t2 where (v1.max_c>100) and (v1.a>7) and (t2.d>800);
+ select * from v1,t2 where (v1.max_c>100) and (v1.a>7) and (t2.d>800);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # using query with union
---echo # extracted and formula : pushing into WHERE
---echo # extracted or formula : pushing into HAVING
+--echo # extracted and formula : pushing into WHERE
+--echo # extracted or formula : pushing into HAVING
--echo # pushing equalities
-let $query=
+let $query=
select * from v1,t2 where (v1.a<5) and (v1.b=t2.b) and (v1.b=19)
- union
+ union
select * from v1,t2 where ((v1.max_c>400) or (v1.avg_c>270)) and (v1.a<t2.a);
eval $no_pushdown $query;
eval $query;
@@ -602,25 +602,25 @@ eval explain $query;
eval explain format=json $query;
--echo # using query with union
---echo # extracted or formula : pushing into HAVING
+--echo # extracted or formula : pushing into HAVING
--echo # extracted or formula : pushing into WHERE
--echo # pushing equalities
-let $query=
- select * from v1,t2 where
+let $query=
+ select * from v1,t2 where
((t2.a=v1.a) or (v1.b=t2.b)) and ((v1.a=1) or (v1.a=6))
union
- select * from v1,t2 where ((v1.a>3) and (v1.b>27)) or (v1.max_c>550);
+ select * from v1,t2 where ((v1.a>3) and (v1.b>27)) or (v1.max_c>550);
eval $no_pushdown $query;
eval $query;
eval explain $query;
eval explain format=json $query;
--echo # using query with union
---echo # extracted or formula : pushing into HAVING
---echo # conjunctive subformulas : pushing into WHERE
+--echo # extracted or formula : pushing into HAVING
+--echo # conjunctive subformulas : pushing into WHERE
--echo # pushing equalities
-let $query=
- select * from v1,t2 where
+let $query=
+ select * from v1,t2 where
((v1.a=1) and (v1.a=t2.a)) and ((v1.max_c<500) or (v1.avg_c>500))
union
select * from v2,t2 where
@@ -643,8 +643,8 @@ eval explain format=json $query;
--echo # using derived table with union
--echo # conjunctive subformula : pushing into WHERE
---echo # extracted or formula : pushing into HAVING
-let $query=
+--echo # extracted or formula : pushing into HAVING
+let $query=
select * from v_union,t2 where
((v_union.a<2) or (v_union.c>800)) and (v_union.b>12);
eval $no_pushdown $query;
@@ -656,7 +656,7 @@ eval explain format=json $query;
--echo # conjunctive subformula : pushing into HAVING
--echo # conjunctive subformula : pushing into WHERE
--echo # pushing equalities
-let $query=
+let $query=
select * from v_union,t2 where
(v_union.a=1) and (v_union.a=t2.a) and (v_union.c<200);
eval $no_pushdown $query;
@@ -664,215 +664,215 @@ eval $query;
eval explain $query;
eval explain format=json $query;
-let $query=
- select * from v_char as v,t2_char as t where
+let $query=
+ select * from v_char as v,t2_char as t where
(v.a=t.a) and (v.b='Vika') and (v.max_c>2);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # using derived table with union
--echo # using several derived tables : pushing in all tables
--echo # conjunctive subformula : pushing into WHERE using equalities
--echo # pushing equalities
-let $query=
+let $query=
select * from v_union,v1,t2 where
- (v_union.a=v1.a) and (v1.a=t2.a) and (t2.a=1)
- and ((v_union.c>800) or (v1.max_c>200));
+ (v_union.a=v1.a) and (v1.a=t2.a) and (t2.a=1)
+ and ((v_union.c>800) or (v1.max_c>200));
eval $no_pushdown $query;
eval $query;
eval explain $query;
eval explain format=json $query;
---echo # using derived table with union
---echo # extracted or formula : pushing into WHERE
+--echo # using derived table with union
+--echo # extracted or formula : pushing into WHERE
--echo # conjunctive subformula : pushing into HAVING
--echo # pushing equalities
-let $query=
- select * from v2_union as v,t2 where
+let $query=
+ select * from v2_union as v,t2 where
((v.a=6) or (v.a=8)) and (v.c>200) and (v.a=t2.a);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # using derived table with union of selects without aggregation
--echo # extracted conjunctive predicate: pushing in WHERE of both selects
-let $query=
+let $query=
select * from v3_union as v,t2 where (v.a=t2.a) and (v.c>6);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # using derived table with union of selects without aggregation
--echo # extracted conjunctive OR subformula: pushing in WHERE using equalities
-let $query=
+let $query=
select * from v3_union as v,t2 where (v.a=t2.a) and ((t2.a>1) or (v.b<20));
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # using derived table with union of selects without aggregation
--echo # extracted the whole condition: in WHERE of both selects
-let $query=
- select * from v3_union as v,t2 where
+let $query=
+ select * from v3_union as v,t2 where
(v.a=t2.a) and ((v.b=19) or (v.b=21)) and ((v.c<3) or (v.c>600));
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
---echo # using derived table with union of
+--echo # using derived table with union of
--echo # a select without aggregation and a select with aggregation
--echo # extracted conjunctive predicate: pushing in WHERE of both selects
-let $query=
+let $query=
select * from v4_union as v,t2 where (v.a=t2.a) and (v.b<20);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
---echo # using derived table with union of
+--echo # using derived table with union of
--echo # a select without aggregation and a select with aggregation
--echo # extracted subformula: pushing in WHERE of one select
--echo # extracted subformula: pushing in HAVING of the other select
--echo # extracted sub-subformula: pushing in WHERE of the other select
--echo # using an equality in all pushdowns
-let $query=
- select * from v4_union as v,t2 where
+let $query=
+ select * from v4_union as v,t2 where
(v.a=t2.a) and ((t2.a<3) or (v.b<40)) and (v.c>500);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # using embedded derived table : pushing the same conditions
--echo # using several derived tables : pushing in all tables
--echo # conjunctive subformula : pushing into WHERE
--echo # extracted and formula : pushing into WHERE
-let $query=
+let $query=
select * from v4,v1 where
- (v4.a<13) and (v1.a>5) and (v1.b>12);
+ (v4.a<13) and (v1.a>5) and (v1.b>12);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # using embedded view : nothing to push
--echo # using several derived tables : pushing only in one table
--echo # conjunctive subformula : pushing into WHERE
-let $query=
+let $query=
select * from v4,v1,t2 where
(v4.a=t2.a) and (v4.a=v1.a) and (v1.b>30);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # using embedded view : pushing different conditions
--echo # using several derived tables : pushing in all tables
--echo # conjunctive subformula : pushing into WHERE using equalities
--echo # extracted and formula : pushing into WHERE using equalities
--echo # conjunctive subformula : pushing into HAVING
-let $query=
+let $query=
select * from v4,v1,t2 where
- (v4.a=t2.a) and (v4.a>1) and (v4.a=v1.a) and (v4.min_c>100) and (v1.b<30);
+ (v4.a=t2.a) and (v4.a>1) and (v4.a=v1.a) and (v4.min_c>100) and (v1.b<30);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # using embedded view : pushing different conditions
--echo # using several derived tables : pushing in all tables
--echo # extracted or formula : pushing into WHERE
--echo # conjunctive subformula : pushing into HAVING
-let $query=
+let $query=
select * from v4,v1,t2 where
(((v4.b>10) and (v4.a>1)) or (v4.b<20)) and (v1.max_c>200) and (v1.a=v4.a);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
-
+eval explain format=json $query;
+
--echo # using embedded view : pushing different conditions
--echo # using several derived tables : pushing only in one table
--echo # extracted or formula : pushing into WHERE
--echo # extracted or formula : pushing into HAVING
-let $query=
+let $query=
select * from v4,v2 where
((v4.a>12) and (v4.min_c<300) and (v4.b>13)) or (v4.a<1);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
-
+eval explain format=json $query;
+
--echo # using embedded view : pushing different conditions
--echo # using several derived tables : pushing only in one table
--echo # conjunctive subformula : pushing into WHERE
--echo # conjunctive subformula : pushing into HAVING
--echo # pushing equalities
-let $query=
+let $query=
select * from v4,v2 where
- (v4.a=v2.b) and (v4.a=v4.b) and (v4.min_c<100);
+ (v4.a=v2.b) and (v4.a=v4.b) and (v4.min_c<100);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
-
+eval explain format=json $query;
+
--echo # using embedded view : pushing the same conditions
--echo # using several derived tables : pushing in all tables
--echo # extracted and formula : pushing into WHERE using equalities
--echo # conjunctive subformula : pushing into WHERE
--echo # pushing equalities
-let $query=
+let $query=
select * from v4,v2 where
- (v4.a=v2.b) and (v4.a=v4.b) and (v2.b<30);
+ (v4.a=v2.b) and (v4.a=v4.b) and (v2.b<30);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # using embedded view : pushing the same conditions
--echo # using several derived tables : pushing in all tables
--echo # extracted or formula : pushing into WHERE using equalities
--echo # extracted and formula : pushing into WHERE using equalities
--echo # pushing equalities
-let $query=
+let $query=
select * from v4,v2 where
(v4.a=v2.b) and (v4.a=v4.b) and ((v2.b<30) or (v4.a>2));
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
-
+eval explain format=json $query;
+
--echo # using embedded view : pushing the same conditions
--echo # using several derived tables : pushing in all tables
--echo # extracted or formula : pushing into WHERE
--echo # conjunctive subformula : pushing into WHERE
---echo # pushing equalities
-let $query=
+--echo # pushing equalities
+let $query=
select * from v4,v2 where
(((v4.a<12) and (v4.b>13)) or (v4.a>10)) and
(v4.min_c=v2.max_c) and (v4.min_c>100);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
--echo # using embedded view : pushing the same conditions
--echo # using several derived tables : pushing only in one table
--echo # extracted or formula : pushing into WHERE
-let $query=
+let $query=
select * from v4,v2,t2 where
(((v4.a<12) and (t2.b>13)) or (v4.a>10)) and
(v4.min_c=t2.c) and (t2.c>100);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
drop view v1,v2,v3,v4;
drop view v_union,v2_union,v3_union,v4_union;
@@ -880,580 +880,6 @@ drop view v_double,v_char,v_decimal;
drop table t1,t2,t1_double,t2_double,t1_char,t2_char,t1_decimal,t2_decimal;
--echo #
---echo # MDEV-14579: pushdown conditions into materialized views/derived tables
---echo # that are defined with EXIST or/and INTERSECT
---echo #
-
-create table t1 (a int, b int, c int);
-create table t2 (a int, b int, c int);
-
-insert into t1 values
- (1,21,345), (1,33,7), (8,33,114), (1,21,500), (1,19,117), (5,14,787),
- (8,33,123), (9,10,211), (5,16,207), (1,33,988), (5,27,132), (1,21,104),
- (6,20,309), (6,20,315), (1,21,101), (4,33,404), (9,10,800), (1,21,123);
-
-insert into t2 values
- (2,3,207), (1,16,909), (5,14,312),
- (5,33,207), (6,20,211), (1,19,132),
- (8,33,117), (3,21,231), (6,23,303);
-
-create view v1 as
- select a, b, min(c) as c from t1
- where t1.a<9 group by a,b having c < 300
- intersect
- select a, b, min(c) as c from t1
- where t1.b>10 group by a,b having c > 100;
-
---echo # using intersect in view definition
---echo # conjunctive subformulas : pushing into WHERE
-let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a<5);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
---echo # using intersect in view definition
---echo # conjunctive subformulas : pushing into WHERE
---echo # pushing equalities
-let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a=8);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
---echo # using intersect in view definition
---echo # conjunctive subformulas : pushing into WHERE using equalities
-let $query= select * from v1,t2 where (v1.a=t2.a) and (t2.a=8);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
---echo # using intersect in view definition
---echo # conjunctive subformulas : pushing into HAVING
-let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.c>200);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
---echo # using intersect in view definition
---echo # conjunctive subformulas : pushing into WHERE
---echo # conjunctive subformulas : pushing into HAVING
-let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a<5) and (v1.c>110);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
---echo # using intersect in view definition
---echo # extracted or formula : pushing into WHERE
-let $query=
- select * from v1,t2 where (v1.a=t2.a) and ((v1.b>27) or (v1.b<19));
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
---echo # using intersect in view definition
---echo # extracted or formula : pushing into HAVING
-let $query=
- select * from v1,t2 where
- (v1.a=t2.a) and ((v1.c>200) or (v1.c<105));
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
---echo # using intersect in view definition
---echo # extracted or formula : pushing into WHERE
---echo # extracted or formula : pushing into HAVING using equalities
---echo # pushing equalities
-let $query=
- select * from v1,t2 where
- ((v1.a>3) and (t2.c>110) and (v1.c=t2.c)) or
- ((v1.a=1) and (v1.c<110));
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
---echo # using intersect in view definition
---echo # prepare of a query
---echo # conjunctive subformulas : pushing into WHERE
---echo # conjunctive subformulas : pushing into HAVING
-prepare stmt from "select * from v1,t2
- where (v1.a=t2.a) and (v1.a<5) and (v1.c>110);";
-execute stmt;
-execute stmt;
-deallocate prepare stmt;
-
---echo # using intersect in derived table definition
---echo # extracted or formula : pushing into WHERE using equalities
---echo # extracted or formula : pushing into HAVING
---echo # pushing equalities
-let $query=
- select *
- from t2,
- (select a, b, min(c) as c from t1
- where t1.a<9 group by a,b having c < 300
- intersect
- select a, b, min(c) as c from t1
- where t1.b>10 group by a,b having c > 100) as d1
- where
- (d1.b=t2.b) and
- (((t2.b>13) and (t2.c=909)) or
- ((d1.a<4) and (d1.c<200)));
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
-drop view v1;
-
-create view v1 as
- select a, b, max(c) as c from t1
- where t1.a<9 group by a,b having c > 200
- except
- select a, b, max(c) as c from t1
- where t1.b>10 group by a,b having c < 300;
-
---echo # using except in view definition
---echo # conjunctive subformulas : pushing into WHERE
-let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a<5);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
---echo # using except in view definition
---echo # conjunctive subformulas : pushing into WHERE
---echo # pushing equalities
-let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a=6);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
---echo # using except in view definition
---echo # conjunctive subformulas : pushing into WHERE using equalities
-let $query= select * from v1,t2 where (v1.a=t2.a) and (t2.a=6);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
---echo # using except in view definition
---echo # conjunctive subformulas : pushing into HAVING
-let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.c>500);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
---echo # using except in view definition
---echo # conjunctive subformulas : pushing into WHERE
---echo # conjunctive subformulas : pushing into HAVING
-let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a<5) and (v1.c>500);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
---echo # using except in view definition
---echo # extracted or formula : pushing into WHERE
-let $query=
- select * from v1,t2 where (v1.a=t2.a) and ((v1.b>27) or (v1.b<19));
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
---echo # using except in view definition
---echo # extracted or formula : pushing into HAVING
-let $query=
- select * from v1,t2 where
- (v1.a=t2.a) and ((v1.c<400) or (v1.c>800));
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
---echo # using except in view definition
---echo # extracted or formula : pushing into WHERE
---echo # extracted or formula : pushing into HAVING using equalities
---echo # pushing equalities
-let $query=
- select * from v1,t2 where
- (v1.c=t2.c) and
- ((v1.a>1) and (t2.c<500)) or
- ((v1.a=1) and (v1.c>500));
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
---echo # using except in view definition
---echo # prepare of a query
---echo # conjunctive subformulas : pushing into WHERE
---echo # conjunctive subformulas : pushing into HAVING
-prepare stmt from "select * from v1,t2
- where (v1.a=t2.a) and (v1.a<5) and (v1.c>500);";
-execute stmt;
-execute stmt;
-deallocate prepare stmt;
-
---echo # using except in view definition
---echo # extracted or formula : pushing into WHERE using equalities
---echo # extracted or formula : pushing into HAVING
---echo # pushing equalities
-let $query=
- select *
- from t2,
- (select a, b, max(c) as c from t1
- where t1.a<9 group by a,b having c > 200
- except
- select a, b, max(c) as c from t1
- where t1.b>10 group by a,b having c < 300) as d1
- where
- (d1.b=t2.b) and
- (((t2.b>13) and (t2.c=988)) or
- ((d1.a>4) and (d1.c>500)));
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
-drop view v1;
-
---echo # using union and intersect in view definition
---echo # conjunctive subformulas : pushing into WHERE and HAVING
-create view v1 as
- select a, b, min(c) as c from t1
- where t1.a<9 group by a,b having c > 200
- union
- select a, b, max(c) as c from t1
- where t1.b>10 group by a,b having c < 300
- intersect
- select a, b, max(c) as c from t1
- where t1.a>3 group by a,b having c < 530;
-
-let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a>5) and (v1.c>200);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
-drop view v1;
-
---echo # using union and intersect in view definition
---echo # conjunctive subformulas : pushing into WHERE and HAVING
-create view v1 as
- select a, b, min(c) as c from t1
- where t1.a<9 group by a,b having c > 200
- intersect
- select a, b, max(c) as c from t1
- where t1.a>3 group by a,b having c < 500
- union
- select a, b, max(c) as c from t1
- where t1.b>10 group by a,b having c < 300;
-
-let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a>4) and (v1.c<200);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
-drop view v1;
-
---echo # using union and except in view definition
---echo # conjunctive subformulas : pushing into WHERE and HAVING
-create view v1 as
- select a, b, min(c) as c from t1
- where t1.a<9 group by a,b having c > 200
- union
- select a, b, max(c) as c from t1
- where t1.b>10 group by a,b having c < 300
- except
- select a, b, max(c) as c from t1
- where t1.a>3 group by a,b having c < 530;
-
-let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a>5) and (v1.c>200);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
-drop view v1;
-
---echo # using union and except in view definition
---echo # conjunctive subformulas : pushing into WHERE and HAVING
-create view v1 as
- select a, b, min(c) as c from t1
- where t1.a<9 group by a,b having c > 200
- except
- select a, b, max(c) as c from t1
- where t1.a>3 group by a,b having c < 500
- union
- select a, b, max(c) as c from t1
- where t1.b>10 group by a,b having c < 300;
-
-let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a>4) and (v1.c<200);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
-drop view v1;
-
---echo # using except and intersect in view definition
---echo # conjunctive subformulas : pushing into WHERE and HAVING
-create view v1 as
- select a, b, max(c) as c from t1
- where t1.b>10 group by a,b having c < 300
- intersect
- select a, b, max(c) as c from t1
- where t1.a<7 group by a,b having c < 500
- except
- select a, b, max(c) as c from t1
- where t1.a<9 group by a,b having c > 150;
-
-let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a>4) and (v1.c<150);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
-drop view v1;
-
---echo # using except and intersect in view definition
---echo # conjunctive subformulas : pushing into WHERE and HAVING
-create view v1 as
- select a, b, max(c) as c from t1
- where t1.b>10 group by a,b having c < 300
- except
- select a, b, max(c) as c from t1
- where t1.a<9 group by a,b having c > 150
- intersect
- select a, b, max(c) as c from t1
- where t1.a<7 group by a,b having c < 500;
-
-let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a>4) and (v1.c<130);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
-drop view v1;
-
---echo # using except, intersect and union in view definition
---echo # conjunctive subformulas : pushing into WHERE and HAVING
-create view v1 as
- select a, b, max(c) as c from t1
- where t1.b>10 group by a,b having c < 300
- except
- select a, b, max(c) as c from t1
- where t1.a<9 group by a,b having c > 150
- intersect
- select a, b, max(c) as c from t1
- where t1.a<7 group by a,b having c < 500
- union
- select a, b, max(c) as c from t1
- where t1.a<7 group by a,b having c < 120;
-
-let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a>4) and (v1.c<130);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
-drop view v1;
-
---echo # using intersect in view definition
---echo # using embedded view
---echo # conjunctive subformulas : pushing into WHERE and HAVING
-create view v1 as
- select a, b, max(c) as c from t1
- where t1.b>10 group by a,b having c < 300
- intersect
- select a, b, max(c) as c from t1
- where t1.a<9 group by a,b having c > 120;
-
-create view v2 as
- select a, b, max(c) as c from v1
- where v1.a<7 group by a,b;
-
-let $query= select * from v2,t2 where (v2.a=t2.a) and (v2.a>4) and (v2.c<150);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
-drop view v1,v2;
-
---echo # using except in view definition
---echo # using embedded view
---echo # conjunctive subformulas : pushing into WHERE and HAVING
-create view v1 as
- select a, b, max(c) as c from t1
- where t1.b>10 group by a,b having c < 300
- except
- select a, b, max(c) as c from t1
- where t1.a<9 group by a,b having c > 150;
-
-create view v2 as
- select a, b, max(c) as c from v1
- where v1.a<7 group by a,b;
-
-let $query= select * from v2,t2 where (v2.a=t2.a) and (v2.a>4) and (v2.c<150);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
-drop view v1,v2;
-
---echo # using intersect in view definition
---echo # conditions are pushed in different parts of selects
---echo # conjunctive subformulas : pushing into WHERE and HAVING
-create view v1 as
- select a, b, max(c) as c from t1
- where t1.a<9 group by a having c > 300
- intersect
- select a, b, max(c) as c from t1
- where t1.b<21 group by b having c > 200;
-
-let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a>4) and (v1.b>12) and (v1.c<450);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
-drop view v1;
-
---echo # using except in view definition
---echo # conditions are pushed in different parts of selects
---echo # conjunctive subformulas : pushing into WHERE and HAVING
-create view v1 as
- select a, b, max(c) as c from t1
- where t1.b>20 group by a having c > 300
- except
- select a, b, max(c) as c from t1
- where t1.a<7 group by b having c > 150;
-
-let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a<2) and (v1.b<30) and (v1.c>450);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
-drop view v1;
-
---echo # using except and union in view definition
---echo # conditions are pushed in different parts of selects
---echo # conjunctive subformulas : pushing into HAVING
---echo # extracted or formula : pushing into WHERE
---echo # extracted or formula : pushing into HAVING
-create view v1 as
- select a, b, max(c) as c from t1
- where t1.b>20 group by a having c > 300
- except
- select a, b, max(c) as c from t1
- where t1.a<7 group by b having c > 150;
-
-let $query= select * from v1,t2 where (v1.a=t2.a) and ((v1.a<2) or (v1.a<5)) and (v1.c>450);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
-drop view v1;
-
---echo # using union and intersect in view definition
---echo # conditions are pushed in different parts of selects
---echo # conjunctive subformulas : pushing into WHERE and HAVING
-create view v1 as
- select a, b, max(c) as c from t1
- where t1.a<9 group by a having c > 100
- intersect
- select a, b, max(c) as c from t1
- where t1.a>3 group by b having c < 800
- union
- select a, b, max(c) as c from t1
- where t1.b>10 group by a,b having c > 300;
-
-let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a>1) and (v1.b > 12) and (v1.c>400);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
-drop view v1;
-
-create table t3 (a int, b int, c int);
-insert into t3 values
- (1,21,345), (2,33,7), (8,33,114), (3,21,500), (1,19,107), (5,14,787),
- (4,33,123), (9,10,211), (11,16,207), (10,33,988), (5,27,132), (12,21,104),
- (6,20,309), (16,20,315), (16,21,101), (18,33,404), (19,10,800), (10,21,123),
- (17,11,708), (6,20,214);
-
-create index i1 on t3(a);
-
---echo # conjunctive subformulas : pushing into WHERE
---echo # pushed condition gives range access
-create view v1 as
- select a, b, max(c) as max_c from t3
- where a>0 group by a;
-
-let $query= select * from v1,t2 where (v1.b=t2.b) and (v1.a<5);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
-drop view v1;
-
---echo # using union in view definition
---echo # conjunctive subformulas : pushing into WHERE
---echo # pushed condition gives range access
-create view v1 as
- select a, b, max(c) as c from t3
- where t3.a>1 group by a
- union
- select a, b, max(c) as c from t3
- where t3.a>2 group by a;
-
-let $query= select * from v1,t2 where (v1.b=t2.b) and (v1.a<4);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
-drop view v1;
-
---echo # using union in view definition
---echo # conjunctive subformulas : pushing into WHERE
---echo # pushed condition gives range access in one of the selects
-create view v1 as
- select a, b, max(c) as c from t3
- where t3.a>1 group by a
- union
- select a, b, max(c) as c from t3
- where t3.b<21 group by b;
-
-let $query= select * from v1,t2 where (v1.b=t2.b) and (v1.a<3);
-eval $no_pushdown $query;
-eval $query;
-eval explain $query;
-eval explain format=json $query;
-
-drop view v1;
-
-alter table t3 drop index i1;
-
-drop table t1,t2,t3;
-
---echo #
--echo # MDEV-10782: condition extracted from a multiple equality
--echo # pushed into HAVING
--echo #
@@ -1480,8 +906,8 @@ CREATE TABLE t1 (i int) ENGINE=MyISAM;
CREATE VIEW v AS SELECT 5;
SELECT * FROM t1 WHERE 1 IN ( SELECT * FROM v );
DROP VIEW v;
-DROP TABLE t1;
-
+DROP TABLE t1;
+
--echo #
--echo # MDEV-10785: second execution of a query with condition
--echo # pushed into view
@@ -1510,17 +936,17 @@ select a from t1 order by a limit 5;
set statement optimizer_switch='condition_pushdown_for_derived=off' for
select * from (select a from t1 order by a limit 5) t where t.a not in (1,2,3);
-set statement optimizer_switch='condition_pushdown_for_derived=on' for
+set statement optimizer_switch='condition_pushdown_for_derived=on' for
select * from (select a from t1 order by a limit 5) t where t.a not in (1,2,3);
select a from t1 where a < 4 union select a from t1 where a > 5
order by a limit 5;
set statement optimizer_switch='condition_pushdown_for_derived=off' for
-select * from
+select * from
(select a from t1 where a < 4 union select a from t1 where a > 5
order by a limit 5) t where t.a not in (2,9);
-set statement optimizer_switch='condition_pushdown_for_derived=on' for
-select * from
+set statement optimizer_switch='condition_pushdown_for_derived=on' for
+select * from
(select a from t1 where a < 4 union select a from t1 where a > 5
order by a limit 5) t where t.a not in (2,9);
@@ -1537,45 +963,45 @@ CREATE OR REPLACE VIEW v2 AS SELECT * FROM t2;
CREATE TABLE t3 (c INT) ENGINE=MyISAM;
CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v3 AS SELECT * FROM t3;
-SELECT * FROM t1 WHERE a IN (
- SELECT b FROM v2 WHERE b < a OR b IN (
- SELECT c FROM v3 WHERE c = a
- )
+SELECT * FROM t1 WHERE a IN (
+ SELECT b FROM v2 WHERE b < a OR b IN (
+ SELECT c FROM v3 WHERE c = a
+ )
);
INSERT INTO t1 VALUES (2);
INSERT INTO t2 VALUES (3), (2);
INSERT INTO t3 VALUES (4), (1), (2), (7);
-SELECT * FROM t1 WHERE a IN (
- SELECT b FROM v2 WHERE b < a OR b IN (
- SELECT c FROM v3 WHERE c = a
- )
+SELECT * FROM t1 WHERE a IN (
+ SELECT b FROM v2 WHERE b < a OR b IN (
+ SELECT c FROM v3 WHERE c = a
+ )
);
EXPLAIN FORMAT=JSON
-SELECT * FROM t1 WHERE a IN (
- SELECT b FROM v2 WHERE b < a OR b IN (
- SELECT c FROM v3 WHERE c = a
- )
+SELECT * FROM t1 WHERE a IN (
+ SELECT b FROM v2 WHERE b < a OR b IN (
+ SELECT c FROM v3 WHERE c = a
+ )
);
CREATE TABLE t4 (d INT, e INT) ENGINE=MyISAM;
INSERT INTO t4 VALUES (1,10),(3,11),(2,10),(2,20),(3,21);
-CREATE OR REPLACE VIEW v4 AS
+CREATE OR REPLACE VIEW v4 AS
SELECT d, sum(e) AS s FROM t4 GROUP BY d;
-let $query =
-SELECT * FROM t1 WHERE a IN (
- SELECT b FROM v2 WHERE b < a OR b IN (
- SELECT d FROM v4 WHERE s > a
- )
+let $query =
+SELECT * FROM t1 WHERE a IN (
+ SELECT b FROM v2 WHERE b < a OR b IN (
+ SELECT d FROM v4 WHERE s > a
+ )
);
eval $no_pushdown $query;
eval $query;
eval explain $query;
-eval explain format=json $query;
+eval explain format=json $query;
DROP VIEW v2,v3,v4;
DROP TABLE t1,t2,t3,t4;
@@ -1588,17 +1014,17 @@ DROP TABLE t1,t2,t3,t4;
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1);
-
+
CREATE TABLE t2 (b INT) ENGINE=MyISAM;
INSERT INTO t2 VALUES (3),(4);
CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2;
-
-SELECT * FROM
+
+SELECT * FROM
( SELECT * FROM t1
WHERE EXISTS ( SELECT * FROM v2 WHERE b = a ) ) AS sq;
EXPLAIN FORMAT=JSON
-SELECT * FROM
+SELECT * FROM
( SELECT * FROM t1
WHERE EXISTS ( SELECT * FROM v2 WHERE b = a ) ) AS sq;
@@ -1606,18 +1032,18 @@ DROP VIEW v2;
DROP TABLE t1,t2;
--echo #
---echo # MDEV-11102: condition pushdown into materialized inner table
---echo # of outer join is not applied as not being valid
+--echo # MDEV-11102: condition pushdown into materialized inner table
+--echo # of outer join is not applied as not being valid
--echo #
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (0),(2);
-
+
CREATE TABLE t2 (b INT);
INSERT INTO t2 VALUES (1),(2);
-
+
CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2;
-
+
SELECT * FROM t1 LEFT JOIN t2 ON a = b WHERE b IS NULL;
SELECT * FROM t1 LEFT JOIN v2 ON a = b WHERE b IS NULL;
@@ -1650,26 +1076,26 @@ DROP TABLE t1;
CREATE TABLE t1 (pk1 INT PRIMARY KEY, a INT, b INT) ENGINE=MyISAM;
INSERT INTO t1 VALUES (10,7,1),(11,0,2);
-
+
CREATE TABLE t2 (pk2 INT PRIMARY KEY, c INT, d DATETIME) ENGINE=MyISAM;
-INSERT INTO t2 VALUES
+INSERT INTO t2 VALUES
(1,4,'2008-09-27 00:34:58'),
(2,5,'2007-05-28 00:00:00'),
(3,6,'2009-07-25 09:21:20');
-
+
CREATE VIEW v1 AS SELECT * FROM t1;
CREATE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2;
-SELECT * FROM v1 AS sq
+SELECT * FROM v1 AS sq
WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
EXPLAIN FORMAT=JSON
-SELECT * FROM v1 AS sq
+SELECT * FROM v1 AS sq
WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
-SELECT * FROM ( SELECT * FROM t1 ) AS sq
+SELECT * FROM ( SELECT * FROM t1 ) AS sq
WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
EXPLAIN FORMAT=JSON
-SELECT * FROM ( SELECT * FROM t1 ) AS sq
+SELECT * FROM ( SELECT * FROM t1 ) AS sq
WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
DROP VIEW v1,v2;
@@ -1729,7 +1155,7 @@ DROP TABLE t1,t2;
CREATE TABLE t (pk INT PRIMARY KEY, f INT) ENGINE=MyISAM;
CREATE ALGORITHM=TEMPTABLE VIEW v AS SELECT * FROM t;
INSERT INTO t VALUES (1,1),(3,2);
-
+
SELECT * FROM v AS v1, v AS v2
WHERE v2.pk > v1.f AND v1.f IN ( SELECT COUNT(pk) FROM t );
@@ -1871,10 +1297,10 @@ DROP TABLE t1;
CREATE TABLE t1 (c VARCHAR(3));
CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
INSERT INTO t1 VALUES ('foo'),('bar');
-
+
CREATE TABLE t2 (c VARCHAR(3));
INSERT INTO t2 VALUES ('foo'),('xyz');
-
+
SELECT * FROM v1 WHERE v1.c IN ( SELECT MIN(c) FROM t2 WHERE 0 );
EXPLAIN FORMAT=JSON
SELECT * FROM v1 WHERE v1.c IN ( SELECT MIN(c) FROM t2 WHERE 0 );
@@ -1885,18 +1311,18 @@ DROP TABLE t1,t2;
CREATE TABLE t1 (d DECIMAL(10,2));
CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
INSERT INTO t1 VALUES (5.37),(1.1);
-
+
CREATE TABLE t2 (d DECIMAL(10,2));
INSERT INTO t2 VALUES ('1.1'),('2.23');
-
+
SELECT * FROM v1 WHERE v1.d IN ( SELECT MIN(d) FROM t2 WHERE 0 );
DROP VIEW v1;
DROP TABLE t1,t2;
--echo #
---echo # MDEV-11820: second execution of PS for query
---echo # with false subquery predicate in WHERE
+--echo # MDEV-11820: second execution of PS for query
+--echo # with false subquery predicate in WHERE
--echo #
CREATE TABLE t1 (c VARCHAR(3)) ENGINE=MyISAM;
@@ -1905,10 +1331,10 @@ CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
CREATE TABLE t2 (a INT);
INSERT INTO t2 VALUES (3), (4);
-PREPARE stmt1 FROM
+PREPARE stmt1 FROM
" SELECT * FROM v1 WHERE 1 IN (SELECT a FROM t2) OR c = 'foo'";
-PREPARE stmt2 FROM
-"EXPLAIN FORMAT=JSON
+PREPARE stmt2 FROM
+"EXPLAIN FORMAT=JSON
SELECT * FROM v1 WHERE 1 IN (SELECT a FROM t2) OR c = 'foo'";
EXECUTE stmt1;
EXECUTE stmt2;
@@ -1921,14 +1347,14 @@ INSERT INTO t2 SELECT a+1 FROM t2;
EXECUTE stmt1;
EXECUTE stmt2;
DEALLOCATE PREPARE stmt1;
-# the result here will change after the merge with the fix for mdev-11859
+# the result here will change after the merge with the fix for mdev-11859
DEALLOCATE PREPARE stmt2;
DROP VIEW v1;
DROP TABLE t1,t2;
--echo #
---echo # MDEV-12373: pushdown into derived with side effects is prohibited
+--echo # MDEV-12373: pushdown into derived with side effects is prohibited
--echo #
CREATE TABLE sales_documents (
@@ -1946,9 +1372,9 @@ CREATE TABLE sales_documents (
PRIMARY KEY (id)
);
-INSERT INTO sales_documents
-(id, sale_id, type, order_number, data, created_at,
- updated_at, date, generated, synced_at, sum)
+INSERT INTO sales_documents
+(id, sale_id, type, order_number, data, created_at,
+ updated_at, date, generated, synced_at, sum)
VALUES
(555, 165, 3, 5, '{}', 1486538300, 1486722835, '2017-02-17', 0, 1486538313, 2320.00),
(556, 165, 2, 3, '{}', 1486538304, 1486563125, '2017-02-08', 1, 1486538302, 2320.00),
@@ -2024,11 +1450,11 @@ SELECT * FROM
GROUP BY t.order_number
) a, (SELECT @row := 0) r) t
WHERE row <> order_number;
-
+
DROP TABLE sales_documents;
--echo #
---echo # MDEV-12845: pushdown from merged derived using equalities
+--echo # MDEV-12845: pushdown from merged derived using equalities
--echo #
create table t1 (a int);
@@ -2414,20 +1840,829 @@ eval $query;
eval EXPLAIN FORMAT=JSON $query;
DROP TABLE t1;
-# Start of 10.3 tests
+--echo #
+--echo # MDEV-15087: error from inexpensive subquery before check
+--echo # for condition pushdown into derived
+--echo #
+
+CREATE TABLE t1 (i1 int, v1 varchar(1));
+INSERT INTO t1 VALUES (7,'x');
+
+CREATE TABLE t2 (i1 int);
+INSERT INTO t2 VALUES (8);
+
+CREATE TABLE t3 (i1 int ,v1 varchar(1), v2 varchar(1));
+INSERT INTO t3 VALUES (4, 'v','v'),(62,'v','k'),(7, 'n', NULL);
+
+--error ER_SUBQUERY_NO_1_ROW
+SELECT 1
+FROM (t1 AS a1
+ JOIN (((SELECT DISTINCT t3.*
+ FROM t3) AS a2
+ JOIN t1 ON (t1.v1 = a2.v2))) ON (t1.v1 = a2.v1))
+WHERE (SELECT BIT_COUNT(t2.i1)
+ FROM (t2 JOIN t3)) IS NULL;
+
+DROP TABLE t1, t2, t3;
--echo #
---echo # MDEV-10855: Pushdown into derived with window functions
+--echo # MDEV-16614 signal 7 after calling stored procedure, that uses regexp
+--echo #
+
+DELIMITER $$;
+CREATE PROCEDURE p1(m1 varchar(5), m2 varchar(5))
+BEGIN
+SELECT a FROM
+ (SELECT "aa" a) t
+ JOIN (SELECT "aa" b) t1 on t.a=t1.b
+WHERE t.a regexp m1 and t1.b regexp m2
+GROUP BY a;
+END$$
+DELIMITER ;$$
+CALL p1('a','a');
+DROP PROCEDURE p1;
+
+
+DELIMITER $$;
+CREATE PROCEDURE p1(m1 varchar(5))
+BEGIN
+ SELECT a FROM (SELECT "aa" a) t WHERE t.a regexp m1;
+END$$
+DELIMITER ;$$
+CALL p1('a');
+DROP PROCEDURE p1;
+
+
+SELECT a FROM (SELECT "aa" a) t WHERE REGEXP_INSTR(t.a, (SELECT MAX('aa') FROM DUAL LIMIT 1));
+
+
+DELIMITER $$;
+CREATE OR REPLACE FUNCTION f1(a VARCHAR(10), b VARCHAR(10)) RETURNS INT
+BEGIN
+ RETURN 1;
+END;$$
+CREATE OR REPLACE PROCEDURE p1(m1 varchar(5))
+BEGIN
+ SELECT a FROM (SELECT "aa" a) t WHERE f1(t.a, m1);
+END$$
+DELIMITER ;$$
+CALL p1('a');
+DROP PROCEDURE p1;
+DROP FUNCTION f1;
+
+
+DELIMITER $$;
+CREATE OR REPLACE FUNCTION f1(a VARCHAR(10), b VARCHAR(10)) RETURNS INT
+BEGIN
+ RETURN 1;
+END;$$
+DELIMITER ;$$
+SELECT a FROM (SELECT "aa" a) t WHERE f1(t.a, (SELECT MAX('aa') FROM DUAL LIMIT 1));
+DROP FUNCTION f1;
+
+--echo #
+--echo # MDEV-17011: condition pushdown into materialized derived used
+--echo # in INSERT SELECT, multi-table UPDATE and DELETE
+--echo #
+
+CREATE TABLE t1 (a int ,b int) ENGINE=MyISAM;
+INSERT INTO t1 VALUES
+ (1, 1), (1, 2), (2, 1), (2, 2), (3,1), (3,3), (4,2);
+
+CREATE TABLE t2 (a int) ENGINE MYISAM;
+INSERT INTO t2 VALUES
+ (3), (7), (1), (4), (1);
+
+CREATE TABLE t3 (a int, b int) ENGINE MYISAM;
+
+let $q1=
+INSERT INTO t3
+SELECT * FROM (SELECT a, count(*) as c FROM t1 GROUP BY a) t WHERE a<=2;
+
+eval EXPLAIN FORMAT=JSON $q1;
+eval $q1;
+
+SELECT * FROM t3;
+
+let $q2=
+UPDATE t2, (SELECT a, count(*) as c FROM t1 GROUP BY a) t SET t2.a=t.c+10
+ WHERE t2.a= t.c and t.a>=3;
+
+eval EXPLAIN FORMAT=JSON $q2;
+eval $q2;
+
+SELECT * FROM t2;
+
+let $q3=
+DELETE t2 FROM t2, (SELECT a, count(*) as c FROM t1 GROUP BY a) t
+ WHERE t2.a= t.c+9 and t.a=2;
+
+eval EXPLAIN FORMAT=JSON $q3;
+eval $q3;
+
+SELECT * FROM t2;
+
+DROP TABLE t1,t2,t3;
+
+--echo #
+--echo # MDEV-16765: pushdown condition with the CASE structure
+--echo # defined with Item_cond item
+--echo #
+
+CREATE TABLE t1(a INT, b INT);
+INSERT INTO t1 VALUES (1,2), (3,4), (2,3);
+
+LET $query=
+SELECT *
+FROM
+(
+ SELECT CASE WHEN ((tab2.max_a=1) OR (tab2.max_a=2))
+ THEN 1 ELSE 0 END AS max_a,b
+ FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
+) AS tab1
+WHERE (tab1.max_a=1);
+EVAL $query;
+EVAL EXPLAIN FORMAT=JSON $query;
+
+LET $query=
+SELECT *
+FROM
+(
+ SELECT CASE WHEN ((tab2.max_a=1) OR ((tab2.max_a>2) AND (tab2.max_a<4)))
+ THEN 1 ELSE 0 END AS max_a,b
+ FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
+) AS tab1
+WHERE (tab1.max_a=1);
+EVAL $query;
+EVAL EXPLAIN FORMAT=JSON $query;
+
+LET $query=
+SELECT *
+FROM
+(
+ SELECT CASE WHEN ((tab2.max_a>1) AND ((tab2.max_a=2) OR (tab2.max_a>2)))
+ THEN 1 ELSE 0 END AS max_a,b
+ FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
+) AS tab1
+WHERE (tab1.max_a=1);
+EVAL $query;
+EVAL EXPLAIN FORMAT=JSON $query;
+
+LET $query=
+SELECT *
+FROM
+(
+ SELECT CASE WHEN ((tab2.b=2) OR (tab2.b=4))
+ THEN 1 ELSE 0 END AS max_a,b
+ FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
+) AS tab1
+WHERE (tab1.max_a=1);
+EVAL $query;
+EVAL EXPLAIN FORMAT=JSON $query;
+
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-16803: pushdown condition with IN predicate in the derived table
+--echo # defined with several SELECT statements
+--echo #
+
+CREATE TABLE t1 (a INT, b INT);
+INSERT INTO t1 VALUES (1,2),(3,2),(1,1);
+
+SELECT * FROM
+(
+ SELECT a,b,1 as c
+ FROM t1
+ UNION ALL
+ SELECT a,b,2 as c
+ FROM t1
+) AS tab
+WHERE ((a,b) IN ((1,2),(3,2)));
+
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-17354: INSERT SELECT with condition pushdown into derived
+--echo #
+
+CREATE TABLE t1 (f INT NOT NULL);
+INSERT INTO t1 VALUES (3), (7), (3);
+
+CREATE ALGORITHM= TEMPTABLE VIEW v1 AS SELECT * FROM ( SELECT * FROM t1 ) AS sq;
+
+let $q1=
+INSERT INTO t1
+SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ) AS t WHERE f IS NOT NULL;
+
+eval $q1;
+eval EXPLAIN $q1;
+eval EXPLAIN FORMAT=JSON $q1;
+SELECT * FROM t1;
+
+DELETE FROM t1;
+INSERT INTO t1 VALUES (3), (7), (3);
+
+let $q2=
+INSERT INTO t1
+SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ON v1.f=t1.f) AS t
+ WHERE f IS NOT NULL;
+
+eval $q2;
+eval EXPLAIN FORMAT=JSON $q2;
+SELECT * FROM t1;
+
+DROP VIEW v1;
+DROP TABLE t1;
+
+--echo # End of 10.2 tests
+
+--echo #
+--echo # MDEV-14579: pushdown conditions into materialized views/derived tables
+--echo # that are defined with EXIST or/and INTERSECT
+--echo #
+
+create table t1 (a int, b int, c int);
+create table t2 (a int, b int, c int);
+
+insert into t1 values
+ (1,21,345), (1,33,7), (8,33,114), (1,21,500), (1,19,117), (5,14,787),
+ (8,33,123), (9,10,211), (5,16,207), (1,33,988), (5,27,132), (1,21,104),
+ (6,20,309), (6,20,315), (1,21,101), (4,33,404), (9,10,800), (1,21,123);
+
+insert into t2 values
+ (2,3,207), (1,16,909), (5,14,312),
+ (5,33,207), (6,20,211), (1,19,132),
+ (8,33,117), (3,21,231), (6,23,303);
+
+create view v1 as
+ select a, b, min(c) as c from t1
+ where t1.a<9 group by a,b having c < 300
+ intersect
+ select a, b, min(c) as c from t1
+ where t1.b>10 group by a,b having c > 100;
+
+--echo # using intersect in view definition
+--echo # conjunctive subformulas : pushing into WHERE
+let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a<5);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+--echo # using intersect in view definition
+--echo # conjunctive subformulas : pushing into WHERE
+--echo # pushing equalities
+let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a=8);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+--echo # using intersect in view definition
+--echo # conjunctive subformulas : pushing into WHERE using equalities
+let $query= select * from v1,t2 where (v1.a=t2.a) and (t2.a=8);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+--echo # using intersect in view definition
+--echo # conjunctive subformulas : pushing into HAVING
+let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.c>200);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+--echo # using intersect in view definition
+--echo # conjunctive subformulas : pushing into WHERE
+--echo # conjunctive subformulas : pushing into HAVING
+let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a<5) and (v1.c>110);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+--echo # using intersect in view definition
+--echo # extracted or formula : pushing into WHERE
+let $query=
+ select * from v1,t2 where (v1.a=t2.a) and ((v1.b>27) or (v1.b<19));
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+--echo # using intersect in view definition
+--echo # extracted or formula : pushing into HAVING
+let $query=
+ select * from v1,t2 where
+ (v1.a=t2.a) and ((v1.c>200) or (v1.c<105));
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+--echo # using intersect in view definition
+--echo # extracted or formula : pushing into WHERE
+--echo # extracted or formula : pushing into HAVING using equalities
+--echo # pushing equalities
+let $query=
+ select * from v1,t2 where
+ ((v1.a>3) and (t2.c>110) and (v1.c=t2.c)) or
+ ((v1.a=1) and (v1.c<110));
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+--echo # using intersect in view definition
+--echo # prepare of a query
+--echo # conjunctive subformulas : pushing into WHERE
+--echo # conjunctive subformulas : pushing into HAVING
+prepare stmt from "select * from v1,t2
+ where (v1.a=t2.a) and (v1.a<5) and (v1.c>110);";
+execute stmt;
+execute stmt;
+deallocate prepare stmt;
+
+--echo # using intersect in derived table definition
+--echo # extracted or formula : pushing into WHERE using equalities
+--echo # extracted or formula : pushing into HAVING
+--echo # pushing equalities
+let $query=
+ select *
+ from t2,
+ (select a, b, min(c) as c from t1
+ where t1.a<9 group by a,b having c < 300
+ intersect
+ select a, b, min(c) as c from t1
+ where t1.b>10 group by a,b having c > 100) as d1
+ where
+ (d1.b=t2.b) and
+ (((t2.b>13) and (t2.c=909)) or
+ ((d1.a<4) and (d1.c<200)));
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+drop view v1;
+
+create view v1 as
+ select a, b, max(c) as c from t1
+ where t1.a<9 group by a,b having c > 200
+ except
+ select a, b, max(c) as c from t1
+ where t1.b>10 group by a,b having c < 300;
+
+--echo # using except in view definition
+--echo # conjunctive subformulas : pushing into WHERE
+let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a<5);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+--echo # using except in view definition
+--echo # conjunctive subformulas : pushing into WHERE
+--echo # pushing equalities
+let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a=6);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+--echo # using except in view definition
+--echo # conjunctive subformulas : pushing into WHERE using equalities
+let $query= select * from v1,t2 where (v1.a=t2.a) and (t2.a=6);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+--echo # using except in view definition
+--echo # conjunctive subformulas : pushing into HAVING
+let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.c>500);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+--echo # using except in view definition
+--echo # conjunctive subformulas : pushing into WHERE
+--echo # conjunctive subformulas : pushing into HAVING
+let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a<5) and (v1.c>500);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+--echo # using except in view definition
+--echo # extracted or formula : pushing into WHERE
+let $query=
+ select * from v1,t2 where (v1.a=t2.a) and ((v1.b>27) or (v1.b<19));
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+--echo # using except in view definition
+--echo # extracted or formula : pushing into HAVING
+let $query=
+ select * from v1,t2 where
+ (v1.a=t2.a) and ((v1.c<400) or (v1.c>800));
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+--echo # using except in view definition
+--echo # extracted or formula : pushing into WHERE
+--echo # extracted or formula : pushing into HAVING using equalities
+--echo # pushing equalities
+let $query=
+ select * from v1,t2 where
+ (v1.c=t2.c) and
+ ((v1.a>1) and (t2.c<500)) or
+ ((v1.a=1) and (v1.c>500));
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+--echo # using except in view definition
+--echo # prepare of a query
+--echo # conjunctive subformulas : pushing into WHERE
+--echo # conjunctive subformulas : pushing into HAVING
+prepare stmt from "select * from v1,t2
+ where (v1.a=t2.a) and (v1.a<5) and (v1.c>500);";
+execute stmt;
+execute stmt;
+deallocate prepare stmt;
+
+--echo # using except in view definition
+--echo # extracted or formula : pushing into WHERE using equalities
+--echo # extracted or formula : pushing into HAVING
+--echo # pushing equalities
+let $query=
+ select *
+ from t2,
+ (select a, b, max(c) as c from t1
+ where t1.a<9 group by a,b having c > 200
+ except
+ select a, b, max(c) as c from t1
+ where t1.b>10 group by a,b having c < 300) as d1
+ where
+ (d1.b=t2.b) and
+ (((t2.b>13) and (t2.c=988)) or
+ ((d1.a>4) and (d1.c>500)));
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+drop view v1;
+
+--echo # using union and intersect in view definition
+--echo # conjunctive subformulas : pushing into WHERE and HAVING
+create view v1 as
+ select a, b, min(c) as c from t1
+ where t1.a<9 group by a,b having c > 200
+ union
+ select a, b, max(c) as c from t1
+ where t1.b>10 group by a,b having c < 300
+ intersect
+ select a, b, max(c) as c from t1
+ where t1.a>3 group by a,b having c < 530;
+
+let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a>5) and (v1.c>200);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+drop view v1;
+
+--echo # using union and intersect in view definition
+--echo # conjunctive subformulas : pushing into WHERE and HAVING
+create view v1 as
+ select a, b, min(c) as c from t1
+ where t1.a<9 group by a,b having c > 200
+ intersect
+ select a, b, max(c) as c from t1
+ where t1.a>3 group by a,b having c < 500
+ union
+ select a, b, max(c) as c from t1
+ where t1.b>10 group by a,b having c < 300;
+
+let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a>4) and (v1.c<200);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+drop view v1;
+
+--echo # using union and except in view definition
+--echo # conjunctive subformulas : pushing into WHERE and HAVING
+create view v1 as
+ select a, b, min(c) as c from t1
+ where t1.a<9 group by a,b having c > 200
+ union
+ select a, b, max(c) as c from t1
+ where t1.b>10 group by a,b having c < 300
+ except
+ select a, b, max(c) as c from t1
+ where t1.a>3 group by a,b having c < 530;
+
+let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a>5) and (v1.c>200);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+drop view v1;
+
+--echo # using union and except in view definition
+--echo # conjunctive subformulas : pushing into WHERE and HAVING
+create view v1 as
+ select a, b, min(c) as c from t1
+ where t1.a<9 group by a,b having c > 200
+ except
+ select a, b, max(c) as c from t1
+ where t1.a>3 group by a,b having c < 500
+ union
+ select a, b, max(c) as c from t1
+ where t1.b>10 group by a,b having c < 300;
+
+let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a>4) and (v1.c<200);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+drop view v1;
+
+--echo # using except and intersect in view definition
+--echo # conjunctive subformulas : pushing into WHERE and HAVING
+create view v1 as
+ select a, b, max(c) as c from t1
+ where t1.b>10 group by a,b having c < 300
+ intersect
+ select a, b, max(c) as c from t1
+ where t1.a<7 group by a,b having c < 500
+ except
+ select a, b, max(c) as c from t1
+ where t1.a<9 group by a,b having c > 150;
+
+let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a>4) and (v1.c<150);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+drop view v1;
+
+--echo # using except and intersect in view definition
+--echo # conjunctive subformulas : pushing into WHERE and HAVING
+create view v1 as
+ select a, b, max(c) as c from t1
+ where t1.b>10 group by a,b having c < 300
+ except
+ select a, b, max(c) as c from t1
+ where t1.a<9 group by a,b having c > 150
+ intersect
+ select a, b, max(c) as c from t1
+ where t1.a<7 group by a,b having c < 500;
+
+let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a>4) and (v1.c<130);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+drop view v1;
+
+--echo # using except, intersect and union in view definition
+--echo # conjunctive subformulas : pushing into WHERE and HAVING
+create view v1 as
+ select a, b, max(c) as c from t1
+ where t1.b>10 group by a,b having c < 300
+ except
+ select a, b, max(c) as c from t1
+ where t1.a<9 group by a,b having c > 150
+ intersect
+ select a, b, max(c) as c from t1
+ where t1.a<7 group by a,b having c < 500
+ union
+ select a, b, max(c) as c from t1
+ where t1.a<7 group by a,b having c < 120;
+
+let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a>4) and (v1.c<130);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+drop view v1;
+
+--echo # using intersect in view definition
+--echo # using embedded view
+--echo # conjunctive subformulas : pushing into WHERE and HAVING
+create view v1 as
+ select a, b, max(c) as c from t1
+ where t1.b>10 group by a,b having c < 300
+ intersect
+ select a, b, max(c) as c from t1
+ where t1.a<9 group by a,b having c > 120;
+
+create view v2 as
+ select a, b, max(c) as c from v1
+ where v1.a<7 group by a,b;
+
+let $query= select * from v2,t2 where (v2.a=t2.a) and (v2.a>4) and (v2.c<150);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+drop view v1,v2;
+
+--echo # using except in view definition
+--echo # using embedded view
+--echo # conjunctive subformulas : pushing into WHERE and HAVING
+create view v1 as
+ select a, b, max(c) as c from t1
+ where t1.b>10 group by a,b having c < 300
+ except
+ select a, b, max(c) as c from t1
+ where t1.a<9 group by a,b having c > 150;
+
+create view v2 as
+ select a, b, max(c) as c from v1
+ where v1.a<7 group by a,b;
+
+let $query= select * from v2,t2 where (v2.a=t2.a) and (v2.a>4) and (v2.c<150);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+drop view v1,v2;
+
+--echo # using intersect in view definition
+--echo # conditions are pushed in different parts of selects
+--echo # conjunctive subformulas : pushing into WHERE and HAVING
+create view v1 as
+ select a, b, max(c) as c from t1
+ where t1.a<9 group by a having c > 300
+ intersect
+ select a, b, max(c) as c from t1
+ where t1.b<21 group by b having c > 200;
+
+let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a>4) and (v1.b>12) and (v1.c<450);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+drop view v1;
+
+--echo # using except in view definition
+--echo # conditions are pushed in different parts of selects
+--echo # conjunctive subformulas : pushing into WHERE and HAVING
+create view v1 as
+ select a, b, max(c) as c from t1
+ where t1.b>20 group by a having c > 300
+ except
+ select a, b, max(c) as c from t1
+ where t1.a<7 group by b having c > 150;
+
+let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a<2) and (v1.b<30) and (v1.c>450);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+drop view v1;
+
+--echo # using except and union in view definition
+--echo # conditions are pushed in different parts of selects
+--echo # conjunctive subformulas : pushing into HAVING
+--echo # extracted or formula : pushing into WHERE
+--echo # extracted or formula : pushing into HAVING
+create view v1 as
+ select a, b, max(c) as c from t1
+ where t1.b>20 group by a having c > 300
+ except
+ select a, b, max(c) as c from t1
+ where t1.a<7 group by b having c > 150;
+
+let $query= select * from v1,t2 where (v1.a=t2.a) and ((v1.a<2) or (v1.a<5)) and (v1.c>450);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+drop view v1;
+
+--echo # using union and intersect in view definition
+--echo # conditions are pushed in different parts of selects
+--echo # conjunctive subformulas : pushing into WHERE and HAVING
+create view v1 as
+ select a, b, max(c) as c from t1
+ where t1.a<9 group by a having c > 100
+ intersect
+ select a, b, max(c) as c from t1
+ where t1.a>3 group by b having c < 800
+ union
+ select a, b, max(c) as c from t1
+ where t1.b>10 group by a,b having c > 300;
+
+let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.a>1) and (v1.b > 12) and (v1.c>400);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+drop view v1;
+
+create table t3 (a int, b int, c int);
+insert into t3 values
+ (1,21,345), (2,33,7), (8,33,114), (3,21,500), (1,19,107), (5,14,787),
+ (4,33,123), (9,10,211), (11,16,207), (10,33,988), (5,27,132), (12,21,104),
+ (6,20,309), (16,20,315), (16,21,101), (18,33,404), (19,10,800), (10,21,123),
+ (17,11,708), (6,20,214);
+
+create index i1 on t3(a);
+
+--echo # conjunctive subformulas : pushing into WHERE
+--echo # pushed condition gives range access
+create view v1 as
+ select a, b, max(c) as max_c from t3
+ where a>0 group by a;
+
+let $query= select * from v1,t2 where (v1.b=t2.b) and (v1.a<5);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+drop view v1;
+
+--echo # using union in view definition
+--echo # conjunctive subformulas : pushing into WHERE
+--echo # pushed condition gives range access
+create view v1 as
+ select a, b, max(c) as c from t3
+ where t3.a>1 group by a
+ union
+ select a, b, max(c) as c from t3
+ where t3.a>2 group by a;
+
+let $query= select * from v1,t2 where (v1.b=t2.b) and (v1.a<4);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+drop view v1;
+
+--echo # using union in view definition
+--echo # conjunctive subformulas : pushing into WHERE
+--echo # pushed condition gives range access in one of the selects
+create view v1 as
+ select a, b, max(c) as c from t3
+ where t3.a>1 group by a
+ union
+ select a, b, max(c) as c from t3
+ where t3.b<21 group by b;
+
+let $query= select * from v1,t2 where (v1.b=t2.b) and (v1.a<3);
+eval $no_pushdown $query;
+eval $query;
+eval explain $query;
+eval explain format=json $query;
+
+drop view v1;
+
+alter table t3 drop index i1;
+
+drop table t1,t2,t3;
+
+--echo #
+--echo # MDEV-10855: Pushdown into derived with window functions
--echo #
set @save_optimizer_switch= @@optimizer_switch;
set optimizer_switch='split_materialized=off';
-
+
create table t1 (a int, c varchar(16));
insert into t1 values
(8,'aa'), (5,'cc'), (1,'bb'), (2,'aa'), (9,'cc'),
(7,'aa'), (2,'aa'), (7,'bb');
-
+
create table t2 (a int, b int, c varchar(16), index idx(a,c));
insert into t2 values
(7,10,'cc'), (1,20,'aa'), (2,23,'bb'), (7,18,'cc'), (1,30,'bb'),
@@ -2439,27 +2674,31 @@ let $q1=
select * from (select a, c, sum(b) over (partition by a,c) from t2) as t
where t.a > 2 and t.c in ('aa','bb','cc');
+--sorted_result
eval $no_pushdown $q1;
+--sorted_result
eval $q1;
eval explain $q1;
eval explain format=json $q1;
let $q2=
select * from
-(
+(
select 1 as n, a, c, sum(b) over (partition by a,c) as s from t2
union all
select 2 as n, a, c, sum(b) over (partition by a) as s from t2
) as t
where t.a > 2 and t.c in ('aa','bb','cc');
+--sorted_result
eval $no_pushdown $q2;
+--sorted_result
eval $q2;
eval explain $q2;
eval explain format=json $q2;
let $q3=
-select *
+select *
from (select a, c, sum(b) over (partition by a,c) as s from t2) as t, t1
where t1.a=t.a and t1.c=t.c and t1.c in ('aa','bb','cc');
@@ -2467,10 +2706,10 @@ eval $no_pushdown $q3;
eval $q3;
eval explain $q3;
eval explain format=json $q3;
-
+
let $q4=
select * from
-(
+(
select 1 as n, a, c, sum(b) over (partition by a,c) as s from t2
union all
select 2 as n, a, c, sum(b) over (partition by a) as s from t2
@@ -2479,7 +2718,9 @@ select * from
) as t
where t.a > 2 and t.c in ('aa','bb','cc');
+--sorted_result
eval $no_pushdown $q4;
+--sorted_result
eval $q4;
eval explain $q4;
eval explain format=json $q4;
@@ -2491,7 +2732,9 @@ select * from (select a, c,
from t2 ) as t
where t.a > 2 and t.c in ('aa','bb','cc');
+--sorted_result
eval $no_pushdown $q5;
+--sorted_result
eval $q5;
eval explain $q5;
eval explain format=json $q5;
@@ -2503,7 +2746,9 @@ select * from (select a, c,
from t2 ) as t
where t.a > 2 and t.c in ('aa','bb','cc');
+--sorted_result
eval $no_pushdown $q6;
+--sorted_result
eval $q6;
eval explain $q6;
eval explain format=json $q6;
@@ -2515,7 +2760,9 @@ select * from (select a, c,
from t2 ) as t
where t.a > 2 and t.c in ('aa','bb','cc');
+--sorted_result
eval $no_pushdown $q7;
+--sorted_result
eval $q7;
eval explain $q7;
eval explain format=json $q7;
@@ -2525,14 +2772,14 @@ drop table t1,t2;
set optimizer_switch= @save_optimizer_switch;
--echo #
---echo # MDEV-13369: Optimization for equi-joins of grouping derived tables
+--echo # MDEV-13369: Optimization for equi-joins of grouping derived tables
--echo # (Splitting derived tables / views with GROUP BY)
--echo # MDEV-13389: Optimization for equi-joins of derived tables with WF
--echo # (Splitting derived tables / views with window functions)
--echo #
let
-$no_splitting= set statement optimizer_switch='split_materialized=off' for;
+$no_splitting= set statement optimizer_switch='split_materialized=off' for;
create table t1 (a int, b int, index idx_b(b)) engine=myisam;
insert into t1 values
@@ -2605,7 +2852,7 @@ insert into t3 values
(8,11,'aa'), (5,15,'cc'), (1,14,'bb'), (2,12,'aa'), (7,17,'cc'),
(7,18,'aa'), (2,11,'aa'), (7,10,'bb'), (3,11,'dd'), (4,12,'ee'),
(5,14,'dd'), (9,12,'ee');
-
+
create table t4 (a int, b int, c char(127), index idx(a,c)) engine=myisam;
insert into t4 values
(7,10,'cc'), (1,20,'aa'), (2,23,'bb'), (7,18,'cc'), (1,30,'bb'),
@@ -2627,7 +2874,7 @@ where t3.b > 15;
eval $no_splitting $q3;
eval $q3;
eval explain extended $q3;
-eval explain format=json $q3;
+eval explain format=json $q3;
let $q30=
select t3.a,t3.c,t.max,t.min
@@ -2639,7 +2886,7 @@ where t3.b <= 15;
eval $no_splitting $q30;
eval $q30;
eval explain extended $q30;
-eval explain format=json $q30;
+eval explain format=json $q30;
let $q4=
select t3.a,t3.c,t.max,t.min
@@ -2651,7 +2898,7 @@ where t3.b > 15;
eval $no_splitting $q4;
eval $q4;
eval explain extended $q4;
-eval explain format=json $q4;
+eval explain format=json $q4;
let $q40=
select t3.a,t3.c,t.max,t.min
@@ -2663,7 +2910,7 @@ where t3.b <= 15;
eval $no_splitting $q40;
eval $q40;
eval explain extended $q40;
-eval explain format=json $q40;
+eval explain format=json $q40;
drop index idx_a on t2;
create index idx on t2(c,b);
@@ -2681,7 +2928,9 @@ select t2.a,t2.b,t2.c,t.c as t_c,t.max,t.min
from t2, t3, (select c, max(b) max, min(b) min from t4 group by c) t
where t2.b between 80 and 85 and t2.c in ('y','z') and t2.a=t3.a and t3.c=t.c;
+--sorted_result
eval $no_splitting $q5;
+--sorted_result
eval $q5;
eval explain extended $q5;
eval explain format=json $q5;
@@ -2701,7 +2950,9 @@ select *
from t2, t3, (select c, b, sum(b) over (partition by c) from t4 ) t
where t2.b between 80 and 85 and t2.c in ('y','z') and t2.a=t3.a and t3.c=t.c;
+--sorted_result
eval $no_splitting $q6;
+--sorted_result
eval $q6;
eval explain extended $q6;
eval explain format=json $q6;
@@ -2711,7 +2962,9 @@ select *
from t2, t3, (select c, b, sum(b) over (partition by c) from t4 ) t
where t2.b < 40 and t2.a=t3.a and t3.c=t.c;
+--sorted_result
eval $no_splitting $q60;
+--sorted_result
eval $q60;
eval explain extended $q60;
eval explain format=json $q60;
@@ -2879,6 +3132,7 @@ cte as (select median(f2) over (partition by f1) as k1 from t1 order by f1),
cte1 as (select median(f4) over (partition by f1) as k2 from t1)
select k1,k2 from cte1, cte;
+--sorted_result
eval $q;
eval explain $q;
@@ -2908,244 +3162,6 @@ DROP VIEW v1;
DROP TABLE t1;
--echo #
---echo # MDEV-15087: error from inexpensive subquery before check
---echo # for condition pushdown into derived
---echo #
-
-CREATE TABLE t1 (i1 int, v1 varchar(1));
-INSERT INTO t1 VALUES (7,'x');
-
-CREATE TABLE t2 (i1 int);
-INSERT INTO t2 VALUES (8);
-
-CREATE TABLE t3 (i1 int ,v1 varchar(1), v2 varchar(1));
-INSERT INTO t3 VALUES (4, 'v','v'),(62,'v','k'),(7, 'n', NULL);
-
---error ER_SUBQUERY_NO_1_ROW
-SELECT 1
-FROM (t1 AS a1
- JOIN (((SELECT DISTINCT t3.*
- FROM t3) AS a2
- JOIN t1 ON (t1.v1 = a2.v2))) ON (t1.v1 = a2.v1))
-WHERE (SELECT BIT_COUNT(t2.i1)
- FROM (t2 JOIN t3)) IS NULL;
-
-DROP TABLE t1, t2, t3;
-
---echo #
---echo # MDEV-16614 signal 7 after calling stored procedure, that uses regexp
---echo #
-
-DELIMITER $$;
-CREATE PROCEDURE p1(m1 varchar(5), m2 varchar(5))
-BEGIN
-SELECT a FROM
- (SELECT "aa" a) t
- JOIN (SELECT "aa" b) t1 on t.a=t1.b
-WHERE t.a regexp m1 and t1.b regexp m2
-GROUP BY a;
-END$$
-DELIMITER ;$$
-CALL p1('a','a');
-DROP PROCEDURE p1;
-
-
-DELIMITER $$;
-CREATE PROCEDURE p1(m1 varchar(5))
-BEGIN
- SELECT a FROM (SELECT "aa" a) t WHERE t.a regexp m1;
-END$$
-DELIMITER ;$$
-CALL p1('a');
-DROP PROCEDURE p1;
-
-
-SELECT a FROM (SELECT "aa" a) t WHERE REGEXP_INSTR(t.a, (SELECT MAX('aa') FROM DUAL LIMIT 1));
-
-
-DELIMITER $$;
-CREATE OR REPLACE FUNCTION f1(a VARCHAR(10), b VARCHAR(10)) RETURNS INT
-BEGIN
- RETURN 1;
-END;$$
-CREATE OR REPLACE PROCEDURE p1(m1 varchar(5))
-BEGIN
- SELECT a FROM (SELECT "aa" a) t WHERE f1(t.a, m1);
-END$$
-DELIMITER ;$$
-CALL p1('a');
-DROP PROCEDURE p1;
-DROP FUNCTION f1;
-
-
-DELIMITER $$;
-CREATE OR REPLACE FUNCTION f1(a VARCHAR(10), b VARCHAR(10)) RETURNS INT
-BEGIN
- RETURN 1;
-END;$$
-DELIMITER ;$$
-SELECT a FROM (SELECT "aa" a) t WHERE f1(t.a, (SELECT MAX('aa') FROM DUAL LIMIT 1));
-DROP FUNCTION f1;
-
---echo #
---echo # MDEV-17011: condition pushdown into materialized derived used
---echo # in INSERT SELECT, multi-table UPDATE and DELETE
---echo #
-
-CREATE TABLE t1 (a int ,b int) ENGINE=MyISAM;
-INSERT INTO t1 VALUES
- (1, 1), (1, 2), (2, 1), (2, 2), (3,1), (3,3), (4,2);
-
-CREATE TABLE t2 (a int) ENGINE MYISAM;
-INSERT INTO t2 VALUES
- (3), (7), (1), (4), (1);
-
-CREATE TABLE t3 (a int, b int) ENGINE MYISAM;
-
-let $q1=
-INSERT INTO t3
-SELECT * FROM (SELECT a, count(*) as c FROM t1 GROUP BY a) t WHERE a<=2;
-
-eval EXPLAIN FORMAT=JSON $q1;
-eval $q1;
-
-SELECT * FROM t3;
-
-let $q2=
-UPDATE t2, (SELECT a, count(*) as c FROM t1 GROUP BY a) t SET t2.a=t.c+10
- WHERE t2.a= t.c and t.a>=3;
-
-eval EXPLAIN FORMAT=JSON $q2;
-eval $q2;
-
-SELECT * FROM t2;
-
-let $q3=
-DELETE t2 FROM t2, (SELECT a, count(*) as c FROM t1 GROUP BY a) t
- WHERE t2.a= t.c+9 and t.a=2;
-
-eval EXPLAIN FORMAT=JSON $q3;
-eval $q3;
-
-SELECT * FROM t2;
-
-DROP TABLE t1,t2,t3;
-
---echo #
---echo # MDEV-16765: pushdown condition with the CASE structure
---echo # defined with Item_cond item
---echo #
-
-CREATE TABLE t1(a INT, b INT);
-INSERT INTO t1 VALUES (1,2), (3,4), (2,3);
-
-LET $query=
-SELECT *
-FROM
-(
- SELECT CASE WHEN ((tab2.max_a=1) OR (tab2.max_a=2))
- THEN 1 ELSE 0 END AS max_a,b
- FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
-) AS tab1
-WHERE (tab1.max_a=1);
-EVAL $query;
-EVAL EXPLAIN FORMAT=JSON $query;
-
-LET $query=
-SELECT *
-FROM
-(
- SELECT CASE WHEN ((tab2.max_a=1) OR ((tab2.max_a>2) AND (tab2.max_a<4)))
- THEN 1 ELSE 0 END AS max_a,b
- FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
-) AS tab1
-WHERE (tab1.max_a=1);
-EVAL $query;
-EVAL EXPLAIN FORMAT=JSON $query;
-
-LET $query=
-SELECT *
-FROM
-(
- SELECT CASE WHEN ((tab2.max_a>1) AND ((tab2.max_a=2) OR (tab2.max_a>2)))
- THEN 1 ELSE 0 END AS max_a,b
- FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
-) AS tab1
-WHERE (tab1.max_a=1);
-EVAL $query;
-EVAL EXPLAIN FORMAT=JSON $query;
-
-LET $query=
-SELECT *
-FROM
-(
- SELECT CASE WHEN ((tab2.b=2) OR (tab2.b=4))
- THEN 1 ELSE 0 END AS max_a,b
- FROM (SELECT MAX(a) as max_a,b FROM t1 GROUP BY t1.b) AS tab2
-) AS tab1
-WHERE (tab1.max_a=1);
-EVAL $query;
-EVAL EXPLAIN FORMAT=JSON $query;
-
-DROP TABLE t1;
-
---echo #
---echo # MDEV-16803: pushdown condition with IN predicate in the derived table
---echo # defined with several SELECT statements
---echo #
-
-CREATE TABLE t1 (a INT, b INT);
-INSERT INTO t1 VALUES (1,2),(3,2),(1,1);
-
-SELECT * FROM
-(
- SELECT a,b,1 as c
- FROM t1
- UNION ALL
- SELECT a,b,2 as c
- FROM t1
-) AS tab
-WHERE ((a,b) IN ((1,2),(3,2)));
-
-DROP TABLE t1;
-
-
---echo #
---echo # MDEV-17354: INSERT SELECT with condition pushdown into derived
---echo #
-
-CREATE TABLE t1 (f INT NOT NULL);
-INSERT INTO t1 VALUES (3), (7), (3);
-
-CREATE ALGORITHM= TEMPTABLE VIEW v1 AS SELECT * FROM ( SELECT * FROM t1 ) AS sq;
-
-let $q1=
-INSERT INTO t1
-SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ) AS t WHERE f IS NOT NULL;
-
-eval $q1;
-eval EXPLAIN $q1;
-eval EXPLAIN FORMAT=JSON $q1;
-SELECT * FROM t1;
-
-DELETE FROM t1;
-INSERT INTO t1 VALUES (3), (7), (3);
-
-let $q2=
-INSERT INTO t1
-SELECT * FROM ( SELECT t1.f FROM v1 JOIN t1 ON v1.f=t1.f) AS t
- WHERE f IS NOT NULL;
-
-eval $q2;
-eval EXPLAIN FORMAT=JSON $q2;
-SELECT * FROM t1;
-
-DROP VIEW v1;
-DROP TABLE t1;
-
---echo # Start of 10.3 tests
-
---echo #
--echo # MDEV-16801: splittable materialized derived/views with
--echo # one grouping field from table without keys
--echo #
@@ -3218,3 +3234,5 @@ eval $q;
set join_cache_level=default;
DROP TABLE t1,t2;
+
+--echo # End of 10.3 tests
diff --git a/mysql-test/main/flush.result b/mysql-test/main/flush.result
index 0336c10c92d..af8e327657b 100644
--- a/mysql-test/main/flush.result
+++ b/mysql-test/main/flush.result
@@ -554,7 +554,6 @@ ERROR HY000: Table 't1' was locked with a READ lock and can't be updated
UNLOCK TABLES;
LOCK TABLES v1 WRITE;
FLUSH TABLES v1;
-ERROR HY000: Table 't1' was locked with a READ lock and can't be updated
UNLOCK TABLES;
LOCK TABLES v1 READ;
FLUSH TABLES t1;
diff --git a/mysql-test/main/flush.test b/mysql-test/main/flush.test
index 03332c06b08..51b5c48c137 100644
--- a/mysql-test/main/flush.test
+++ b/mysql-test/main/flush.test
@@ -688,7 +688,6 @@ FLUSH TABLES v1;
UNLOCK TABLES;
LOCK TABLES v1 WRITE;
---error ER_TABLE_NOT_LOCKED_FOR_WRITE
FLUSH TABLES v1;
UNLOCK TABLES;
diff --git a/mysql-test/main/func_concat.result b/mysql-test/main/func_concat.result
index 9ab6f74653e..acde1be051b 100644
--- a/mysql-test/main/func_concat.result
+++ b/mysql-test/main/func_concat.result
@@ -268,3 +268,23 @@ SET optimizer_switch=@save_optimizer_switch;
SELECT UNHEX(CONCAT('414C2', HEX(8 + ROUND(RAND()*7)), SUBSTR(SHA(UUID()),6,33),HEX(2+ROUND(RAND()*8)))) IS NULL AS c1;
c1
0
+#
+# MDEV-13119 Wrong results with CAST(AS CHAR) and subquery
+#
+SET optimizer_switch=_utf8'derived_merge=on';
+CREATE TABLE t1 (t VARCHAR(10) CHARSET latin1);
+INSERT INTO t1 VALUES('abcdefghi');
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT CAST(t AS CHAR CHARACTER SET utf8) t2 FROM t1) sub;
+c2
+abcdefghi-abcdefghi
+DROP TABLE t1;
+SET optimizer_switch=@save_optimizer_switch;
+#
+# MDEV-13120 Wrong results with MAKE_SET() and subquery
+#
+CREATE TABLE t1 (t VARCHAR(10) CHARSET latin1);
+INSERT INTO t1 VALUES('abcdefghi');
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT MAKE_SET(3,t,t) t2 FROM t1) sub;
+c2
+abcdefghi,abcdefghi-abcdefghi,abcdefghi
+DROP TABLE t1;
diff --git a/mysql-test/main/func_concat.test b/mysql-test/main/func_concat.test
index 69dd2c4063e..e1bda4be29e 100644
--- a/mysql-test/main/func_concat.test
+++ b/mysql-test/main/func_concat.test
@@ -242,3 +242,25 @@ SET optimizer_switch=@save_optimizer_switch;
--echo #
SELECT UNHEX(CONCAT('414C2', HEX(8 + ROUND(RAND()*7)), SUBSTR(SHA(UUID()),6,33),HEX(2+ROUND(RAND()*8)))) IS NULL AS c1;
+
+
+--echo #
+--echo # MDEV-13119 Wrong results with CAST(AS CHAR) and subquery
+--echo #
+
+SET optimizer_switch=_utf8'derived_merge=on';
+CREATE TABLE t1 (t VARCHAR(10) CHARSET latin1);
+INSERT INTO t1 VALUES('abcdefghi');
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT CAST(t AS CHAR CHARACTER SET utf8) t2 FROM t1) sub;
+DROP TABLE t1;
+SET optimizer_switch=@save_optimizer_switch;
+
+
+--echo #
+--echo # MDEV-13120 Wrong results with MAKE_SET() and subquery
+--echo #
+
+CREATE TABLE t1 (t VARCHAR(10) CHARSET latin1);
+INSERT INTO t1 VALUES('abcdefghi');
+SELECT CONCAT(t2,'-',t2) c2 FROM (SELECT MAKE_SET(3,t,t) t2 FROM t1) sub;
+DROP TABLE t1;
diff --git a/mysql-test/main/index_merge_myisam.result b/mysql-test/main/index_merge_myisam.result
index 992e1d831b5..725a888c914 100644
--- a/mysql-test/main/index_merge_myisam.result
+++ b/mysql-test/main/index_merge_myisam.result
@@ -1715,3 +1715,53 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY,c1,i,c2 NULL NULL NULL 69 Using where
DROP TABLE t1;
set optimizer_switch= @optimizer_switch_save;
+#
+# MDEV-16695: Estimate for rows of derived tables is very high when we are using index_merge union
+#
+create table t0
+(
+key1 int not null,
+INDEX i1(key1)
+);
+insert into t0 values (1),(2),(3),(4),(5),(6),(7),(8);
+set @d=8;
+insert into t0 select key1+ @d from t0;
+set @d=@d*2;
+insert into t0 select key1+ @d from t0;
+set @d=@d*2;
+insert into t0 select key1+ @d from t0;
+set @d=@d*2;
+insert into t0 select key1+ @d from t0;
+set @d=@d*2;
+insert into t0 select key1+ @d from t0;
+set @d=@d*2;
+insert into t0 select key1+ @d from t0;
+set @d=@d*2;
+insert into t0 select key1+ @d from t0;
+set @d=@d*2;
+alter table t0 add key2 int not null, add index i2(key2);
+alter table t0 add key3 int not null, add index i3(key3);
+alter table t0 add key8 int not null, add index i8(key8);
+update t0 set key2=key1,key3=key1,key8=1024-key1;
+analyze table t0;
+Table Op Msg_type Msg_text
+test.t0 analyze status OK
+set @optimizer_switch_save=@@optimizer_switch;
+set optimizer_switch='derived_merge=off,derived_with_keys=off';
+explain select * from (select * from t0 where key1 = 3 or key2 =3) as Z where Z.key8 > 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 Using where
+2 DERIVED t0 index_merge i1,i2,i8 i1,i2 4,4 NULL 2 Using union(i1,i2); Using where
+select * from (select * from t0 where key1 = 3 or key2 =3) as Z where Z.key8 > 5;
+key1 key2 key3 key8
+3 3 3 1021
+set optimizer_use_condition_selectivity=2;
+explain select * from (select * from t0 where key1 = 3 or key2 =3) as Z where Z.key8 > 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 Using where
+2 DERIVED t0 index_merge i1,i2,i8 i1,i2 4,4 NULL 2 Using union(i1,i2); Using where
+select * from (select * from t0 where key1 = 3 or key2 =3) as Z where Z.key8 > 5;
+key1 key2 key3 key8
+3 3 3 1021
+set @@optimizer_switch= @optimizer_switch_save;
+drop table t0;
diff --git a/mysql-test/main/index_merge_myisam.test b/mysql-test/main/index_merge_myisam.test
index d265007431e..75beb9bd883 100644
--- a/mysql-test/main/index_merge_myisam.test
+++ b/mysql-test/main/index_merge_myisam.test
@@ -243,3 +243,38 @@ DROP TABLE t1;
set optimizer_switch= @optimizer_switch_save;
+--echo #
+--echo # MDEV-16695: Estimate for rows of derived tables is very high when we are using index_merge union
+--echo #
+
+create table t0
+(
+ key1 int not null,
+ INDEX i1(key1)
+);
+
+insert into t0 values (1),(2),(3),(4),(5),(6),(7),(8);
+let $1=7;
+set @d=8;
+while ($1)
+{
+ eval insert into t0 select key1+ @d from t0;
+ eval set @d=@d*2;
+ dec $1;
+}
+alter table t0 add key2 int not null, add index i2(key2);
+alter table t0 add key3 int not null, add index i3(key3);
+alter table t0 add key8 int not null, add index i8(key8);
+
+update t0 set key2=key1,key3=key1,key8=1024-key1;
+analyze table t0;
+
+set @optimizer_switch_save=@@optimizer_switch;
+set optimizer_switch='derived_merge=off,derived_with_keys=off';
+explain select * from (select * from t0 where key1 = 3 or key2 =3) as Z where Z.key8 > 5;
+select * from (select * from t0 where key1 = 3 or key2 =3) as Z where Z.key8 > 5;
+set optimizer_use_condition_selectivity=2;
+explain select * from (select * from t0 where key1 = 3 or key2 =3) as Z where Z.key8 > 5;
+select * from (select * from t0 where key1 = 3 or key2 =3) as Z where Z.key8 > 5;
+set @@optimizer_switch= @optimizer_switch_save;
+drop table t0;
diff --git a/mysql-test/main/lock.result b/mysql-test/main/lock.result
index 0805fd45864..339cfcaa441 100644
--- a/mysql-test/main/lock.result
+++ b/mysql-test/main/lock.result
@@ -136,7 +136,7 @@ select * from t1;
ERROR HY000: Table 't1' was not locked with LOCK TABLES
unlock tables;
create or replace view v_bug5719 as select * from t1;
-lock tables v_bug5719 write;
+lock tables v_bug5719 read;
select * from v_bug5719;
a
@@ -303,7 +303,7 @@ create table t2 (j int);
#
# Try to perform DDL on table which is locked through view.
create view v1 as select * from t2;
-lock tables t1 write, v1 write;
+lock tables t1 write, v1 read;
flush table t2;
ERROR HY000: Table 't2' was locked with a READ lock and can't be updated
drop table t2;
diff --git a/mysql-test/main/lock.test b/mysql-test/main/lock.test
index 92ab8294273..ff77b4991c0 100644
--- a/mysql-test/main/lock.test
+++ b/mysql-test/main/lock.test
@@ -192,7 +192,7 @@ drop view v_bug5719;
select * from t1;
unlock tables;
create or replace view v_bug5719 as select * from t1;
-lock tables v_bug5719 write;
+lock tables v_bug5719 read;
select * from v_bug5719;
--echo
--echo Allowed to use an underlying table under LOCK TABLES <view>
@@ -368,7 +368,7 @@ create table t2 (j int);
--echo #
--echo # Try to perform DDL on table which is locked through view.
create view v1 as select * from t2;
-lock tables t1 write, v1 write;
+lock tables t1 write, v1 read;
--error ER_TABLE_NOT_LOCKED_FOR_WRITE
flush table t2;
--error ER_TABLE_NOT_LOCKED_FOR_WRITE
diff --git a/mysql-test/main/lock_multi.result b/mysql-test/main/lock_multi.result
index d4e0edaf1c2..e702c458c0c 100644
--- a/mysql-test/main/lock_multi.result
+++ b/mysql-test/main/lock_multi.result
@@ -395,15 +395,17 @@ DROP VIEW IF EXISTS v1;
#
# Test 1: LOCK TABLES v1 WRITE, t1 READ;
#
-# Thanks to the fact that we no longer allow DDL on tables
-# which are locked for write implicitly, the exact scenario
-# in which assert was failing is no longer repeatable.
CREATE TABLE t1 ( f1 integer );
CREATE VIEW v1 AS SELECT f1 FROM t1 ;
+# Connection 2
+connect con2,localhost,root;
LOCK TABLES v1 WRITE, t1 READ;
FLUSH TABLE t1;
-ERROR HY000: Table 't1' was locked with a READ lock and can't be updated
-UNLOCK TABLES;
+disconnect con2;
+# Connection 1
+connection default;
+LOCK TABLES t1 WRITE;
+FLUSH TABLE t1;
DROP TABLE t1;
DROP VIEW v1;
#
diff --git a/mysql-test/main/lock_multi.test b/mysql-test/main/lock_multi.test
index 51cc4a50233..a945bcdbb74 100644
--- a/mysql-test/main/lock_multi.test
+++ b/mysql-test/main/lock_multi.test
@@ -734,17 +734,21 @@ DROP VIEW IF EXISTS v1;
--echo #
--echo # Test 1: LOCK TABLES v1 WRITE, t1 READ;
--echo #
---echo # Thanks to the fact that we no longer allow DDL on tables
---echo # which are locked for write implicitly, the exact scenario
---echo # in which assert was failing is no longer repeatable.
CREATE TABLE t1 ( f1 integer );
CREATE VIEW v1 AS SELECT f1 FROM t1 ;
+--echo # Connection 2
+connect (con2,localhost,root);
LOCK TABLES v1 WRITE, t1 READ;
---error ER_TABLE_NOT_LOCKED_FOR_WRITE
FLUSH TABLE t1;
-UNLOCK TABLES;
+disconnect con2;
+--source include/wait_until_disconnected.inc
+
+--echo # Connection 1
+connection default;
+LOCK TABLES t1 WRITE;
+FLUSH TABLE t1; # Assertion happened here
# Cleanup
DROP TABLE t1;
diff --git a/mysql-test/main/lowercase_fs_off.result b/mysql-test/main/lowercase_fs_off.result
index 91bd2924096..f2a8ec14641 100644
--- a/mysql-test/main/lowercase_fs_off.result
+++ b/mysql-test/main/lowercase_fs_off.result
@@ -83,6 +83,75 @@ CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW SET new.a= 1;
RENAME TABLE t1 TO T1;
ALTER TABLE T1 RENAME t1;
DROP TABLE t1;
+create database TEST;
+create procedure TEST.pr() begin end;
+create procedure test.pr() begin end;
+Phase 1/7: Checking and upgrading mysql database
+Processing databases
+mysql
+mysql.column_stats OK
+mysql.columns_priv OK
+mysql.db OK
+mysql.event OK
+mysql.func OK
+mysql.gtid_slave_pos OK
+mysql.help_category OK
+mysql.help_keyword OK
+mysql.help_relation OK
+mysql.help_topic OK
+mysql.host OK
+mysql.index_stats OK
+mysql.innodb_index_stats
+Error : Unknown storage engine 'InnoDB'
+error : Corrupt
+mysql.innodb_table_stats
+Error : Unknown storage engine 'InnoDB'
+error : Corrupt
+mysql.plugin OK
+mysql.proc OK
+mysql.procs_priv OK
+mysql.proxies_priv OK
+mysql.roles_mapping OK
+mysql.servers OK
+mysql.table_stats OK
+mysql.tables_priv OK
+mysql.time_zone OK
+mysql.time_zone_leap_second OK
+mysql.time_zone_name OK
+mysql.time_zone_transition OK
+mysql.time_zone_transition_type OK
+mysql.transaction_registry
+Error : Unknown storage engine 'InnoDB'
+error : Corrupt
+mysql.user OK
+
+Repairing tables
+mysql.innodb_index_stats
+Error : Unknown storage engine 'InnoDB'
+error : Corrupt
+mysql.innodb_table_stats
+Error : Unknown storage engine 'InnoDB'
+error : Corrupt
+mysql.transaction_registry
+Error : Unknown storage engine 'InnoDB'
+error : Corrupt
+Phase 2/7: Installing used storage engines... Skipped
+Phase 3/7: Fixing views
+Phase 4/7: Running 'mysql_fix_privilege_tables'
+Phase 5/7: Fixing table and database names
+Phase 6/7: Checking and upgrading tables
+Processing databases
+TEST
+information_schema
+mtr
+mtr.global_suppressions OK
+mtr.test_suppressions OK
+performance_schema
+test
+Phase 7/7: Running 'FLUSH PRIVILEGES'
+OK
+drop procedure test.pr;
+drop database TEST;
create table t1 (a int);
create trigger t1_bi before insert on t1 for each row set new.a= 1;
show triggers like '%T1%';
diff --git a/mysql-test/main/lowercase_fs_off.test b/mysql-test/main/lowercase_fs_off.test
index b8a9795db9a..7c5811f9cc3 100644
--- a/mysql-test/main/lowercase_fs_off.test
+++ b/mysql-test/main/lowercase_fs_off.test
@@ -106,6 +106,18 @@ ALTER TABLE T1 RENAME t1;
DROP TABLE t1;
#
+# MDEV-13912 mysql_upgrade: case (in)sensitivity for stored procedures
+#
+create database TEST;
+create procedure TEST.pr() begin end;
+create procedure test.pr() begin end;
+--exec $MYSQL_UPGRADE --force 2>&1
+drop procedure test.pr;
+drop database TEST;
+
+# End of 5.5 tests
+
+#
# MDEV-9014 SHOW TRIGGERS not case sensitive
#
create table t1 (a int);
@@ -113,4 +125,7 @@ create trigger t1_bi before insert on t1 for each row set new.a= 1;
show triggers like '%T1%';
drop table t1;
+let $datadir= `select @@datadir`;
+remove_file $datadir/mysql_upgrade_info;
+
set GLOBAL sql_mode=default;
diff --git a/mysql-test/main/order_by_zerolength-4285.result b/mysql-test/main/order_by_zerolength-4285.result
index e6902105f20..95b4224f5a2 100644
--- a/mysql-test/main/order_by_zerolength-4285.result
+++ b/mysql-test/main/order_by_zerolength-4285.result
@@ -25,3 +25,23 @@ Warning 1292 Truncated incorrect CHAR(0) value: '8'
Warning 1292 Truncated incorrect CHAR(0) value: '9'
Warning 1292 Truncated incorrect CHAR(0) value: '10'
drop table t1;
+#
+# MDEV-17020: Assertion `length > 0' failed in ptr_compare upon ORDER BY with bad conversion
+#
+set @save_sql_mode= @@sql_mode;
+SET @@sql_mode= '';
+CREATE TABLE t1 (pk INT PRIMARY KEY);
+INSERT INTO t1 VALUES (1),(2);
+explain
+SELECT * FROM t1 ORDER BY 'foo', CONVERT(pk, CHAR(0)) LIMIT 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index NULL PRIMARY 4 NULL 2 Using index; Using filesort
+SELECT * FROM t1 ORDER BY 'foo', Cast(pk as CHAR(0)) LIMIT 2;
+pk
+1
+2
+Warnings:
+Warning 1292 Truncated incorrect CHAR(0) value: '1'
+Warning 1292 Truncated incorrect CHAR(0) value: '2'
+set @@sql_mode= @save_sql_mode;
+drop table t1;
diff --git a/mysql-test/main/order_by_zerolength-4285.test b/mysql-test/main/order_by_zerolength-4285.test
index 079ce8da71e..52672aa4595 100644
--- a/mysql-test/main/order_by_zerolength-4285.test
+++ b/mysql-test/main/order_by_zerolength-4285.test
@@ -13,3 +13,17 @@ select * from t1 order by now(), cast(pk as char(0));
--enable_warnings
show warnings;
drop table t1;
+
+--echo #
+--echo # MDEV-17020: Assertion `length > 0' failed in ptr_compare upon ORDER BY with bad conversion
+--echo #
+
+set @save_sql_mode= @@sql_mode;
+SET @@sql_mode= '';
+CREATE TABLE t1 (pk INT PRIMARY KEY);
+INSERT INTO t1 VALUES (1),(2);
+explain
+SELECT * FROM t1 ORDER BY 'foo', CONVERT(pk, CHAR(0)) LIMIT 2;
+SELECT * FROM t1 ORDER BY 'foo', Cast(pk as CHAR(0)) LIMIT 2;
+set @@sql_mode= @save_sql_mode;
+drop table t1;
diff --git a/mysql-test/main/partition_explicit_prune.result b/mysql-test/main/partition_explicit_prune.result
index bfcfe7deef6..951b21db3e1 100644
--- a/mysql-test/main/partition_explicit_prune.result
+++ b/mysql-test/main/partition_explicit_prune.result
@@ -1870,3 +1870,22 @@ CREATE TABLE t2 LIKE t1 PARTITION (p0, p2);
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 'PARTITION (p0, p2)' at line 1
DROP TABLE t1;
SET @@default_storage_engine = @old_default_storage_engine;
+#
+# MDEV-14815 - Server crash or AddressSanitizer errors or valgrind warnings in thr_lock / has_old_lock upon FLUSH TABLES
+#
+CREATE TABLE t1 (i INT) ENGINE=MEMORY PARTITION BY RANGE (i) (PARTITION p0 VALUES LESS THAN (4), PARTITION pm VALUES LESS THAN MAXVALUE);
+CREATE TABLE t2 (i INT) ENGINE=MEMORY;
+LOCK TABLE t1 WRITE, t2 WRITE;
+SELECT * FROM t1 PARTITION (p0);
+i
+FLUSH TABLES;
+SELECT * FROM t1 PARTITION (p0);
+i
+ALTER TABLE t1 TRUNCATE PARTITION p0;
+SELECT * FROM t1 PARTITION (p0);
+i
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+SELECT * FROM t1 PARTITION (p0);
+i
+UNLOCK TABLES;
+DROP TABLE t1, t2;
diff --git a/mysql-test/main/partition_explicit_prune.test b/mysql-test/main/partition_explicit_prune.test
index 68b829fbcc3..b8b6e480ce9 100644
--- a/mysql-test/main/partition_explicit_prune.test
+++ b/mysql-test/main/partition_explicit_prune.test
@@ -858,3 +858,22 @@ CREATE TABLE t2 LIKE t1 PARTITION (p0, p2);
DROP TABLE t1;
SET @@default_storage_engine = @old_default_storage_engine;
+
+
+--echo #
+--echo # MDEV-14815 - Server crash or AddressSanitizer errors or valgrind warnings in thr_lock / has_old_lock upon FLUSH TABLES
+--echo #
+CREATE TABLE t1 (i INT) ENGINE=MEMORY PARTITION BY RANGE (i) (PARTITION p0 VALUES LESS THAN (4), PARTITION pm VALUES LESS THAN MAXVALUE);
+CREATE TABLE t2 (i INT) ENGINE=MEMORY;
+LOCK TABLE t1 WRITE, t2 WRITE;
+SELECT * FROM t1 PARTITION (p0);
+FLUSH TABLES;
+SELECT * FROM t1 PARTITION (p0);
+ALTER TABLE t1 TRUNCATE PARTITION p0;
+SELECT * FROM t1 PARTITION (p0);
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+SELECT * FROM t1 PARTITION (p0);
+UNLOCK TABLES;
+
+# Cleanup
+DROP TABLE t1, t2;
diff --git a/mysql-test/main/set_password.result b/mysql-test/main/set_password.result
index 315d0bef9fb..733d9c96187 100644
--- a/mysql-test/main/set_password.result
+++ b/mysql-test/main/set_password.result
@@ -11,10 +11,10 @@ select user, host, password, plugin, authentication_string from mysql.user where
user host password plugin authentication_string
natauth localhost *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29
newpass localhost *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29
-newpassnat localhost mysql_native_password *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29
+newpassnat localhost *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29 mysql_native_password *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29
oldauth localhost 378b243e220ca493
oldpass localhost 378b243e220ca493
-oldpassold localhost mysql_old_password 378b243e220ca493
+oldpassold localhost 378b243e220ca493 mysql_old_password 378b243e220ca493
connect con,localhost,natauth,test,;
select current_user();
current_user()
@@ -86,12 +86,12 @@ set password for oldpass@localhost = PASSWORD('test2');
set password for oldpassold@localhost = PASSWORD('test2');
select user, host, password, plugin, authentication_string from mysql.user where user != 'root';
user host password plugin authentication_string
-natauth localhost mysql_native_password *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E
-newpass localhost mysql_native_password *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E
-newpassnat localhost mysql_native_password *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E
-oldauth localhost mysql_native_password *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E
-oldpass localhost mysql_native_password *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E
-oldpassold localhost mysql_native_password *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E
+natauth localhost *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E mysql_native_password *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E
+newpass localhost *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E mysql_native_password *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E
+newpassnat localhost *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E mysql_native_password *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E
+oldauth localhost *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E mysql_native_password *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E
+oldpass localhost *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E mysql_native_password *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E
+oldpassold localhost *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E mysql_native_password *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E
connect con,localhost,natauth,test2,;
select current_user();
current_user()
@@ -173,7 +173,7 @@ disconnect foo;
connection default;
select user,host,password,plugin,authentication_string from mysql.user where user='foo';
user host password plugin authentication_string
-foo localhost mysql_native_password *E8D46CE25265E545D225A8A6F1BAF642FEBEE5CB
+foo localhost *E8D46CE25265E545D225A8A6F1BAF642FEBEE5CB mysql_native_password *E8D46CE25265E545D225A8A6F1BAF642FEBEE5CB
set password for 'foo'@'localhost' = '';
select user,host,password,plugin,authentication_string from mysql.user where user='foo';
user host password plugin authentication_string
diff --git a/mysql-test/main/show_grants_with_plugin-7985.result b/mysql-test/main/show_grants_with_plugin-7985.result
index 0f8e1e39969..bb475b7cba9 100644
--- a/mysql-test/main/show_grants_with_plugin-7985.result
+++ b/mysql-test/main/show_grants_with_plugin-7985.result
@@ -71,7 +71,7 @@ connection default;
set password for u1 = PASSWORD('SOMETHINGELSE');
select user, host, password, plugin, authentication_string from mysql.user where user = 'u1';
user host password plugin authentication_string
-u1 % mysql_native_password *054B7BBD2B9A553DA560520DCD3F76DA2D81B7C6
+u1 % *054B7BBD2B9A553DA560520DCD3F76DA2D81B7C6 mysql_native_password *054B7BBD2B9A553DA560520DCD3F76DA2D81B7C6
#
# Here we should use the password field, as that primes over
# the authentication_string field.
diff --git a/mysql-test/main/type_datetime.test b/mysql-test/main/type_datetime.test
index dafa9f9456e..7ed723fb4aa 100644
--- a/mysql-test/main/type_datetime.test
+++ b/mysql-test/main/type_datetime.test
@@ -175,12 +175,12 @@ set @@sql_mode= @org_mode;
## ( Bug#29290 type_datetime.test failure in 5.1 )
## Therefore we sleep a bit if we are too close to midnight.
## The complete test itself needs around 1 second.
-## Therefore a time_distance to midnight of 5 seconds should be sufficient.
-if (`SELECT CURTIME() > SEC_TO_TIME(24 * 3600 - 5)`)
+## Therefore a time_distance to midnight of 10 seconds should be sufficient.
+if (`SELECT CURTIME() > SEC_TO_TIME(24 * 3600 - 10)`)
{
- # We are here when CURTIME() is between '23:59:56' and '23:59:59'.
- # So a sleep time of 5 seconds brings us between '00:00:01' and '00:00:04'.
- --real_sleep 5
+ # We are here when CURTIME() is between '23:59:51' and '23:59:59'.
+ # So a sleep time of 10 seconds brings us between '00:00:01' and '00:00:09'.
+ --real_sleep 10
}
create table t1 (f1 date, f2 datetime, f3 timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
insert into t1(f1) values(curdate());
diff --git a/mysql-test/main/type_newdecimal.result b/mysql-test/main/type_newdecimal.result
index ba84ff50504..140f36b1261 100644
--- a/mysql-test/main/type_newdecimal.result
+++ b/mysql-test/main/type_newdecimal.result
@@ -1995,8 +1995,50 @@ select 0.0000000001 mod 1;
select 0.01 mod 1;
0.01 mod 1
0.01
+CREATE TABLE t1 (
+`FLD1` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD2` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD3` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD4` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD5` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD6` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD7` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD8` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD9` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD10` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD11` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD12` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD13` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD14` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD15` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD16` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD17` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD18` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD19` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD20` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD21` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD22` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+`FLD23` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000
+);
+INSERT INTO t1 VALUES (001.0760,000.9500,001.0000,001.0000,001.0000,
+001.0000,001.0000,001.0000,001.0000,001.0000,001.0000,000.5949,001.0194,
+001.0000,001.0000,001.0000,001.0000,001.0000,001.0000,000.9220,001.1890,001.2130,327.2690);
+select FLD1*FLD2*FLD3*FLD4*FLD5*FLD6*FLD7*FLD8*FLD9*FLD10*FLD11*FLD12*FLD13*FLD14*FLD15*FLD16*FLD17*FLD18*FLD19*FLD20*FLD21*FLD22*FLD23 as calc1 from t1;
+calc1
+269.77575757644053032218703200000000000000
+select FLD23*FLD2*FLD1*FLD4*FLD5*FLD11*FLD12*FLD13*FLD3*FLD15*FLD16*FLD17*FLD18*FLD19*FLD20*FLD21*FLD22*FLD14*FLD6*FLD7*FLD8*FLD9*FLD10 as calc2 from t1;
+calc2
+269.77575757644053032218703200000000000000
+DROP TABLE t1;
+CREATE TABLE t1 AS SELECT 1.0 * 2.000;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `1.0 * 2.000` decimal(6,4) NOT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
#
-# Start of 10.0 tests
+# End of 5.5 tests
#
#
# MDEV-6950 Bad results with joins comparing DATE and INT/ENUM/VARCHAR columns
diff --git a/mysql-test/main/type_newdecimal.test b/mysql-test/main/type_newdecimal.test
index dd5311e4be3..d2d64b0baee 100644
--- a/mysql-test/main/type_newdecimal.test
+++ b/mysql-test/main/type_newdecimal.test
@@ -1583,8 +1583,51 @@ select 0.000000000000000000000000000000000000000000000000001 mod 1;
select 0.0000000001 mod 1;
select 0.01 mod 1;
+#
+# MDEV-17256 Decimal field multiplication bug
+#
+
+CREATE TABLE t1 (
+ `FLD1` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD2` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD3` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD4` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD5` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD6` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD7` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD8` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD9` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD10` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD11` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD12` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD13` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD14` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD15` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD16` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD17` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD18` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD19` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD20` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD21` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD22` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000,
+ `FLD23` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000
+);
+
+INSERT INTO t1 VALUES (001.0760,000.9500,001.0000,001.0000,001.0000,
+ 001.0000,001.0000,001.0000,001.0000,001.0000,001.0000,000.5949,001.0194,
+ 001.0000,001.0000,001.0000,001.0000,001.0000,001.0000,000.9220,001.1890,001.2130,327.2690);
+
+select FLD1*FLD2*FLD3*FLD4*FLD5*FLD6*FLD7*FLD8*FLD9*FLD10*FLD11*FLD12*FLD13*FLD14*FLD15*FLD16*FLD17*FLD18*FLD19*FLD20*FLD21*FLD22*FLD23 as calc1 from t1;
+select FLD23*FLD2*FLD1*FLD4*FLD5*FLD11*FLD12*FLD13*FLD3*FLD15*FLD16*FLD17*FLD18*FLD19*FLD20*FLD21*FLD22*FLD14*FLD6*FLD7*FLD8*FLD9*FLD10 as calc2 from t1;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 AS SELECT 1.0 * 2.000;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
--echo #
---echo # Start of 10.0 tests
+--echo # End of 5.5 tests
--echo #
--echo #
diff --git a/mysql-test/main/type_year.result b/mysql-test/main/type_year.result
index 8d58659769e..c4b72483c99 100644
--- a/mysql-test/main/type_year.result
+++ b/mysql-test/main/type_year.result
@@ -396,7 +396,14 @@ a
drop table t1;
drop function y2k;
#
-# Start of 10.1 tests
+# MDEV-17257 Server crashes in Item::field_type_for_temporal_comparison or in get_datetime_value on SELECT with YEAR field and IN
+#
+CREATE TABLE t1 (y YEAR);
+SELECT * FROM t1 WHERE y IN ( CAST( '1993-03-26 10:14:20' AS DATE ), NULL );
+y
+DROP TABLE t1;
+#
+# End of 10.0 tests
#
#
# MDEV-8741 Equal field propagation leaves some remainders after simplifying WHERE zerofill_column=2010 AND zerofill_column>=2010
diff --git a/mysql-test/main/type_year.test b/mysql-test/main/type_year.test
index 117906fd889..5a02c038caa 100644
--- a/mysql-test/main/type_year.test
+++ b/mysql-test/main/type_year.test
@@ -187,9 +187,16 @@ select a from t1 where a=b; # not a constant
drop table t1;
drop function y2k;
+--echo #
+--echo # MDEV-17257 Server crashes in Item::field_type_for_temporal_comparison or in get_datetime_value on SELECT with YEAR field and IN
+--echo #
+
+CREATE TABLE t1 (y YEAR);
+SELECT * FROM t1 WHERE y IN ( CAST( '1993-03-26 10:14:20' AS DATE ), NULL );
+DROP TABLE t1;
--echo #
---echo # Start of 10.1 tests
+--echo # End of 10.0 tests
--echo #
--echo #
diff --git a/mysql-test/main/win.result b/mysql-test/main/win.result
index 46a5eaea9f8..37858981a64 100644
--- a/mysql-test/main/win.result
+++ b/mysql-test/main/win.result
@@ -38,10 +38,10 @@ a row_number() over (partition by a order by b)
select a, b, x, row_number() over (partition by a order by x) from t1;
a b x row_number() over (partition by a order by x)
2 10 xx 1
-2 10 zz 3
2 20 yy 2
-3 10 xxx 2
+2 10 zz 3
3 20 vvv 1
+3 10 xxx 2
drop table t1;
create table t1 (pk int primary key, a int, b int);
insert into t1 values
@@ -54,13 +54,14 @@ select
pk, a, b,
row_number() over (order by a),
row_number() over (order by b)
-from t1;
+from t1
+order by b;
pk a b row_number() over (order by a) row_number() over (order by b)
-1 10 22 1 5
-2 11 21 2 4
-3 12 20 3 3
-4 13 19 4 2
5 14 18 5 1
+4 13 19 4 2
+3 12 20 3 3
+2 11 21 2 4
+1 10 22 1 5
drop table t1;
#
# Try RANK() function
@@ -228,16 +229,16 @@ count(*) over (partition by c order by pk desc
rows between 2 preceding and 2 following) as CNT
from t1;
pk c CNT
-1 1 3
-2 1 4
-3 1 4
4 1 3
-5 2 3
-6 2 4
-7 2 5
-8 2 5
-9 2 4
+3 1 4
+2 1 4
+1 1 3
10 2 3
+9 2 4
+8 2 5
+7 2 5
+6 2 4
+5 2 3
drop table t0,t1;
#
# Resolution of window names
@@ -535,42 +536,40 @@ insert into t3 values
(5, 2),
(6, 2);
select
-pk,
val,
count(val) over (order by val
range between current row and
current row)
as CNT
from t3;
-pk val CNT
-0 1 3
-1 1 3
-2 1 3
-3 2 4
-4 2 4
-5 2 4
-6 2 4
+val CNT
+1 3
+1 3
+1 3
+2 4
+2 4
+2 4
+2 4
insert into t3 values
(7, 3),
(8, 3);
select
-pk,
val,
count(val) over (order by val
range between current row and
current row)
as CNT
from t3;
-pk val CNT
-0 1 3
-1 1 3
-2 1 3
-3 2 4
-4 2 4
-5 2 4
-6 2 4
-7 3 2
-8 3 2
+val CNT
+1 3
+1 3
+1 3
+2 4
+2 4
+2 4
+2 4
+3 2
+3 2
drop table t3;
# Now, check with PARTITION BY
create table t4 (
@@ -599,7 +598,6 @@ insert into t4 values
(5678, 208, 3);
select
part_id,
-pk,
val,
count(val) over (partition by part_id
order by val
@@ -607,31 +605,30 @@ range between current row and
current row)
as CNT
from t4;
-part_id pk val CNT
-1234 100 1 3
-1234 101 1 3
-1234 102 1 3
-1234 103 2 4
-1234 104 2 4
-1234 105 2 4
-1234 106 2 4
-1234 107 3 2
-1234 108 3 2
-5678 200 1 3
-5678 201 1 3
-5678 202 1 3
-5678 203 2 4
-5678 204 2 4
-5678 205 2 4
-5678 206 2 4
-5678 207 3 2
-5678 208 3 2
+part_id val CNT
+1234 1 3
+1234 1 3
+1234 1 3
+1234 2 4
+1234 2 4
+1234 2 4
+1234 2 4
+1234 3 2
+1234 3 2
+5678 1 3
+5678 1 3
+5678 1 3
+5678 2 4
+5678 2 4
+5678 2 4
+5678 2 4
+5678 3 2
+5678 3 2
#
# Try RANGE UNBOUNDED PRECEDING | FOLLOWING
#
select
part_id,
-pk,
val,
count(val) over (partition by part_id
order by val
@@ -639,28 +636,27 @@ range between unbounded preceding and
current row)
as CNT
from t4;
-part_id pk val CNT
-1234 100 1 3
-1234 101 1 3
-1234 102 1 3
-1234 103 2 7
-1234 104 2 7
-1234 105 2 7
-1234 106 2 7
-1234 107 3 9
-1234 108 3 9
-5678 200 1 3
-5678 201 1 3
-5678 202 1 3
-5678 203 2 7
-5678 204 2 7
-5678 205 2 7
-5678 206 2 7
-5678 207 3 9
-5678 208 3 9
+part_id val CNT
+1234 1 3
+1234 1 3
+1234 1 3
+1234 2 7
+1234 2 7
+1234 2 7
+1234 2 7
+1234 3 9
+1234 3 9
+5678 1 3
+5678 1 3
+5678 1 3
+5678 2 7
+5678 2 7
+5678 2 7
+5678 2 7
+5678 3 9
+5678 3 9
select
part_id,
-pk,
val,
count(val) over (partition by part_id
order by val
@@ -668,28 +664,27 @@ range between current row and
unbounded following)
as CNT
from t4;
-part_id pk val CNT
-1234 100 1 9
-1234 101 1 9
-1234 102 1 9
-1234 103 2 6
-1234 104 2 6
-1234 105 2 6
-1234 106 2 6
-1234 107 3 2
-1234 108 3 2
-5678 200 1 9
-5678 201 1 9
-5678 202 1 9
-5678 203 2 6
-5678 204 2 6
-5678 205 2 6
-5678 206 2 6
-5678 207 3 2
-5678 208 3 2
+part_id val CNT
+1234 1 9
+1234 1 9
+1234 1 9
+1234 2 6
+1234 2 6
+1234 2 6
+1234 2 6
+1234 3 2
+1234 3 2
+5678 1 9
+5678 1 9
+5678 1 9
+5678 2 6
+5678 2 6
+5678 2 6
+5678 2 6
+5678 3 2
+5678 3 2
select
part_id,
-pk,
val,
count(val) over (partition by part_id
order by val
@@ -697,25 +692,25 @@ range between unbounded preceding and
unbounded following)
as CNT
from t4;
-part_id pk val CNT
-1234 100 1 9
-1234 101 1 9
-1234 102 1 9
-1234 103 2 9
-1234 104 2 9
-1234 105 2 9
-1234 106 2 9
-1234 107 3 9
-1234 108 3 9
-5678 200 1 9
-5678 201 1 9
-5678 202 1 9
-5678 203 2 9
-5678 204 2 9
-5678 205 2 9
-5678 206 2 9
-5678 207 3 9
-5678 208 3 9
+part_id val CNT
+1234 1 9
+1234 1 9
+1234 1 9
+1234 2 9
+1234 2 9
+1234 2 9
+1234 2 9
+1234 3 9
+1234 3 9
+5678 1 9
+5678 1 9
+5678 1 9
+5678 2 9
+5678 2 9
+5678 2 9
+5678 2 9
+5678 3 9
+5678 3 9
drop table t4;
#
# MDEV-9695: Wrong window frame when using RANGE BETWEEN N FOLLOWING AND PRECEDING
@@ -881,15 +876,15 @@ RANGE BETWEEN UNBOUNDED PRECEDING
AND 10 FOLLOWING) as cnt
from t1;
pk a cnt
-1 1 9
-2 2 9
-3 4 9
-4 8 9
-5 26 5
-6 27 5
-7 40 3
-8 71 2
9 72 2
+8 71 2
+7 40 3
+6 27 5
+5 26 5
+4 8 9
+3 4 9
+2 2 9
+1 1 9
select
pk, a,
count(a) over (ORDER BY a
@@ -929,15 +924,15 @@ RANGE BETWEEN UNBOUNDED PRECEDING
AND 10 PRECEDING) as cnt
from t1;
pk a cnt
-1 1 5
-2 2 5
-3 4 5
-4 8 5
-5 26 3
-6 27 3
-7 40 2
-8 71 0
9 72 0
+8 71 0
+7 40 2
+6 27 3
+5 26 3
+4 8 5
+3 4 5
+2 2 5
+1 1 5
select
pk, a,
count(a) over (ORDER BY a
@@ -977,15 +972,15 @@ RANGE BETWEEN 1 PRECEDING
AND CURRENT ROW) as cnt
from t1;
pk a cnt
-1 1 2
-2 2 1
-3 4 1
-4 8 1
-5 26 2
-6 27 1
-7 40 1
-8 71 2
9 72 1
+8 71 2
+7 40 1
+6 27 1
+5 26 2
+4 8 1
+3 4 1
+2 2 1
+1 1 2
select
pk, a,
count(a) over (ORDER BY a
@@ -1026,15 +1021,15 @@ range between current row
and 1 following) as cnt
from t1;
pk a cnt
-1 1 1
-2 2 2
-3 4 1
-4 8 1
-5 26 1
-6 27 2
-7 40 1
-8 71 1
9 72 2
+8 71 1
+7 40 1
+6 27 2
+5 26 1
+4 8 1
+3 4 1
+2 2 2
+1 1 1
insert into t1 select 22, pk, a from t1;
select
part_id, pk, a,
@@ -1137,7 +1132,8 @@ pk, a,
count(b) over (order by a
range between 2 preceding
and 2 following) as CNT
-from t1;
+from t1
+order by a, pk;
pk a CNT
1 NULL 3
2 NULL 3
@@ -1969,12 +1965,12 @@ ROW_NUMBER() OVER (order by s1),
CUME_DIST() OVER (order by -s1)
from t1;
s1 s2 ROW_NUMBER() OVER (order by s1) CUME_DIST() OVER (order by -s1)
+-1 2 1.0000000000
1 a 3 0.8333333333
-NULL NULL 1 0.1666666667
+2 b 4 0.6666666667
3 NULL 5 0.5000000000
4 a 6 0.3333333333
-2 b 4 0.6666666667
--1 2 1.0000000000
+NULL NULL 1 0.1666666667
drop table t1;
#
# MDEV-9925: Wrong result with aggregate function as a window function
@@ -2012,8 +2008,8 @@ o_custkey avg(o_custkey) OVER (PARTITION BY abs(o_custkey)
ORDER BY o_custkey
RANGE BETWEEN 15 FOLLOWING
AND 15 FOLLOWING)
-242 NULL
238 NULL
+242 NULL
DROP table orders;
#
# MDEV-10842: window functions with the same order column
@@ -2042,20 +2038,20 @@ row_number() over (order by pk desc) as r_desc,
row_number() over (order by pk asc) as r_asc
from t1;
pk r_desc r_asc
-1 11 1
-2 10 2
-3 9 3
-4 8 4
-5 7 5
-6 6 6
-7 5 7
-8 4 8
-9 3 9
-10 2 10
11 1 11
+10 2 10
+9 3 9
+8 4 8
+7 5 7
+6 6 6
+5 7 5
+4 8 4
+3 9 3
+2 10 2
+1 11 1
drop table t1;
#
-# MDEV-10874: two window functions with ccompatible sorting
+# MDEV-10874: two window functions with compatible sorting
#
create table t1 (
pk int primary key,
@@ -2130,17 +2126,17 @@ sum(d) over (order by a
ROWS BETWEEN 1 preceding and 2 following) as sum_2
from t1;
pk a d sum_1 sum_2
-1 0 0.100 0.300 1.400
-2 0 0.200 0.500 1.200
3 0 0.300 0.300 0.600
-4 1 0.400 0.900 2.600
-5 1 0.500 1.100 2.400
+2 0 0.200 0.500 1.200
+1 0 0.100 0.300 1.400
6 1 0.600 0.600 1.600
-7 2 0.500 0.500 0.500
-8 2 NULL 0.700 1.200
-9 2 0.700 1.500 2.000
-10 2 0.800 1.700 2.400
+5 1 0.500 1.100 2.400
+4 1 0.400 0.900 2.600
11 2 0.900 0.900 2.800
+10 2 0.800 1.700 2.400
+9 2 0.700 1.500 2.000
+8 2 NULL 0.700 1.200
+7 2 0.500 0.500 0.500
drop table t1;
#
# MDEV-9941: two window functions with compatible partitions
@@ -2232,9 +2228,9 @@ SELECT sum(t.a) over (partition by t.b order by a),
sqrt(ifnull((sum(t.a) over (partition by t.b order by a)), 0))
from t;
sum(t.a) over (partition by t.b order by a) sqrt(ifnull((sum(t.a) over (partition by t.b order by a)), 0))
+0.0000000000 0
1.0000000000 1
3.0000000000 1.7320508075688772
-0.0000000000 0
drop table t;
#
# MDEV-10868: view definitions with window functions
@@ -2391,9 +2387,9 @@ CREATE TABLE t2 (c VARCHAR(8));
INSERT INTO t2 VALUES ('foo'),('bar'),('foo');
SELECT COUNT(*) OVER (PARTITION BY c) FROM t2;
COUNT(*) OVER (PARTITION BY c)
-2
1
2
+2
SELECT * FROM t1 WHERE i IN ( SELECT COUNT(*) OVER (PARTITION BY c) FROM t2 );
i
1
@@ -2511,14 +2507,14 @@ select id, rank() over (order by id) from t1;
id rank() over (order by id)
1 1
2 2
-3 4
2 2
+3 4
select * from v1;
id rnk
1 1
2 2
-3 4
2 2
+3 4
drop view v1;
drop table t1;
#
@@ -2879,64 +2875,64 @@ CDEC min(TDEC.CDEC) over ()
NULL -1
-1 -1
0 -1
-1 -1
0 -1
+1 -1
10 -1
select VDEC.CDEC, min(VDEC.CDEC) over () from VDEC;
CDEC min(VDEC.CDEC) over ()
NULL -1
-1 -1
0 -1
-1 -1
0 -1
+1 -1
10 -1
select TDEC.CDEC, max(TDEC.CDEC) over () from TDEC;
CDEC max(TDEC.CDEC) over ()
NULL 10
-1 10
0 10
-1 10
0 10
+1 10
10 10
select VDEC.CDEC, max(VDEC.CDEC) over () from VDEC;
CDEC max(VDEC.CDEC) over ()
NULL 10
-1 10
0 10
-1 10
0 10
+1 10
10 10
select TDEC.CDEC, min(distinct TDEC.CDEC) over () from TDEC;
CDEC min(distinct TDEC.CDEC) over ()
NULL -1
-1 -1
0 -1
-1 -1
0 -1
+1 -1
10 -1
select VDEC.CDEC, min(distinct VDEC.CDEC) over () from VDEC;
CDEC min(distinct VDEC.CDEC) over ()
NULL -1
-1 -1
0 -1
-1 -1
0 -1
+1 -1
10 -1
select TDEC.CDEC, max(distinct TDEC.CDEC) over () from TDEC;
CDEC max(distinct TDEC.CDEC) over ()
NULL 10
-1 10
0 10
-1 10
0 10
+1 10
10 10
select VDEC.CDEC, max(distinct VDEC.CDEC) over () from VDEC;
CDEC max(distinct VDEC.CDEC) over ()
NULL 10
-1 10
0 10
-1 10
0 10
+1 10
10 10
#
# These should be removed once support for them is added.
@@ -3327,6 +3323,45 @@ BIT_AND(0) OVER () MAX(1)
0 1
drop table t1;
#
+# MDEV-17525: Window functions not working in ONLY_FULL_GROUP_BY mode
+#
+CREATE TABLE t1 (name CHAR(10), test CHAR(10), score TINYINT);
+INSERT INTO t1 VALUES
+('Chun', 'SQL', 75), ('Chun', 'Tuning', 73),
+('Esben', 'SQL', 43), ('Esben', 'Tuning', 31),
+('Kaolin', 'SQL', 56), ('Kaolin', 'Tuning', 88),
+('Tatiana', 'SQL', 87), ('Tatiana', 'Tuning', 83);
+SET @save_sql_mode= @@sql_mode;
+SET sql_mode = 'ONLY_FULL_GROUP_BY';
+SELECT name, test, score,
+AVG(score) OVER (PARTITION BY test) AS average_by_test
+FROM t1
+ORDER BY test, name;
+name test score average_by_test
+Chun SQL 75 65.2500
+Esben SQL 43 65.2500
+Kaolin SQL 56 65.2500
+Tatiana SQL 87 65.2500
+Chun Tuning 73 68.7500
+Esben Tuning 31 68.7500
+Kaolin Tuning 88 68.7500
+Tatiana Tuning 83 68.7500
+set @@sql_mode= @save_sql_mode;
+SELECT name, test, score,
+AVG(score) OVER (PARTITION BY test) AS average_by_test
+FROM t1
+ORDER BY test, name;
+name test score average_by_test
+Chun SQL 75 65.2500
+Esben SQL 43 65.2500
+Kaolin SQL 56 65.2500
+Tatiana SQL 87 65.2500
+Chun Tuning 73 68.7500
+Esben Tuning 31 68.7500
+Kaolin Tuning 88 68.7500
+Tatiana Tuning 83 68.7500
+drop table t1;
+#
# Start of 10.3 tests
#
#
diff --git a/mysql-test/main/win.test b/mysql-test/main/win.test
index efc8c712526..77c7d9d35be 100644
--- a/mysql-test/main/win.test
+++ b/mysql-test/main/win.test
@@ -58,7 +58,8 @@ select
pk, a, b,
row_number() over (order by a),
row_number() over (order by b)
-from t1;
+from t1
+order by b;
drop table t1;
@@ -391,7 +392,6 @@ insert into t3 values
(6, 2);
select
- pk,
val,
count(val) over (order by val
range between current row and
@@ -404,7 +404,6 @@ insert into t3 values
(8, 3);
select
- pk,
val,
count(val) over (order by val
range between current row and
@@ -444,7 +443,6 @@ insert into t4 values
select
part_id,
- pk,
val,
count(val) over (partition by part_id
order by val
@@ -458,7 +456,6 @@ from t4;
--echo #
select
part_id,
- pk,
val,
count(val) over (partition by part_id
order by val
@@ -469,7 +466,6 @@ from t4;
select
part_id,
- pk,
val,
count(val) over (partition by part_id
order by val
@@ -480,7 +476,6 @@ from t4;
select
part_id,
- pk,
val,
count(val) over (partition by part_id
order by val
@@ -723,7 +718,8 @@ select
count(b) over (order by a
range between 2 preceding
and 2 following) as CNT
-from t1;
+from t1
+order by a, pk;
drop table t1;
--echo #
@@ -1023,6 +1019,7 @@ insert into t1 values
--echo # Check using counters
flush status;
+--sorted_result
select
rank() over (partition by c order by a),
rank() over (partition by c order by b)
@@ -1030,6 +1027,7 @@ from t1;
show status like '%sort%';
flush status;
+--sorted_result
select
rank() over (partition by c order by a),
rank() over (partition by c order by a)
@@ -1101,6 +1099,7 @@ insert into t1 values
(2,2),
(3,1);
+--sorted_result
select
a, b,
rank() over (order by a), rank() over (order by b),
@@ -1192,6 +1191,7 @@ insert into t1 values (4,'a');
insert into t1 values (2,'b');
insert into t1 values (-1,'');
+--sorted_result
select
*,
ROW_NUMBER() OVER (order by s1),
@@ -1267,7 +1267,7 @@ from t1;
drop table t1;
--echo #
---echo # MDEV-10874: two window functions with ccompatible sorting
+--echo # MDEV-10874: two window functions with compatible sorting
--echo #
create table t1 (
@@ -2094,6 +2094,33 @@ SELECT DISTINCT BIT_AND(0) OVER (), MAX(1) FROM t1;
drop table t1;
--echo #
+--echo # MDEV-17525: Window functions not working in ONLY_FULL_GROUP_BY mode
+--echo #
+
+CREATE TABLE t1 (name CHAR(10), test CHAR(10), score TINYINT);
+
+INSERT INTO t1 VALUES
+('Chun', 'SQL', 75), ('Chun', 'Tuning', 73),
+('Esben', 'SQL', 43), ('Esben', 'Tuning', 31),
+('Kaolin', 'SQL', 56), ('Kaolin', 'Tuning', 88),
+('Tatiana', 'SQL', 87), ('Tatiana', 'Tuning', 83);
+
+SET @save_sql_mode= @@sql_mode;
+SET sql_mode = 'ONLY_FULL_GROUP_BY';
+
+SELECT name, test, score,
+ AVG(score) OVER (PARTITION BY test) AS average_by_test
+FROM t1
+ORDER BY test, name;
+
+set @@sql_mode= @save_sql_mode;
+SELECT name, test, score,
+ AVG(score) OVER (PARTITION BY test) AS average_by_test
+FROM t1
+ORDER BY test, name;
+drop table t1;
+
+--echo #
--echo # Start of 10.3 tests
--echo #
diff --git a/mysql-test/main/win_first_last_value.result b/mysql-test/main/win_first_last_value.result
index 9de394ef9e0..4c3aa6a7161 100644
--- a/mysql-test/main/win_first_last_value.result
+++ b/mysql-test/main/win_first_last_value.result
@@ -68,17 +68,17 @@ first_value(pk) over (order by pk desc),
last_value(pk) over (order by pk desc)
from t1;
pk first_value(pk) over (order by pk desc) last_value(pk) over (order by pk desc)
-1 11 1
-2 11 2
-3 11 3
-4 11 4
-5 11 5
-6 11 6
-7 11 7
-8 11 8
-9 11 9
-10 11 10
11 11 11
+10 11 10
+9 11 9
+8 11 8
+7 11 7
+6 11 6
+5 11 5
+4 11 4
+3 11 3
+2 11 2
+1 11 1
select pk, a, b, c, d, e,
first_value(b) over (partition by a order by pk) as fst_b,
last_value(b) over (partition by a order by pk) as lst_b,
diff --git a/mysql-test/main/win_percent_cume.result b/mysql-test/main/win_percent_cume.result
index d38c95c9ea7..bc2a4182e30 100644
--- a/mysql-test/main/win_percent_cume.result
+++ b/mysql-test/main/win_percent_cume.result
@@ -14,49 +14,49 @@ insert into t1 values
( 7 , 2, 20),
( 9 , 4, 20),
(10 , 4, 20);
-select pk, a, b,
+select a,
percent_rank() over (order by a),
cume_dist() over (order by a)
from t1;
-pk a b percent_rank() over (order by a) cume_dist() over (order by a)
-1 0 10 0.0000000000 0.2000000000
-2 0 10 0.0000000000 0.2000000000
-3 1 10 0.2222222222 0.4000000000
-4 1 10 0.2222222222 0.4000000000
-8 2 10 0.4444444444 0.8000000000
-5 2 20 0.4444444444 0.8000000000
-6 2 20 0.4444444444 0.8000000000
-7 2 20 0.4444444444 0.8000000000
-9 4 20 0.8888888889 1.0000000000
-10 4 20 0.8888888889 1.0000000000
-select pk, a, b,
+a percent_rank() over (order by a) cume_dist() over (order by a)
+0 0.0000000000 0.2000000000
+0 0.0000000000 0.2000000000
+1 0.2222222222 0.4000000000
+1 0.2222222222 0.4000000000
+2 0.4444444444 0.8000000000
+2 0.4444444444 0.8000000000
+2 0.4444444444 0.8000000000
+2 0.4444444444 0.8000000000
+4 0.8888888889 1.0000000000
+4 0.8888888889 1.0000000000
+select pk,
percent_rank() over (order by pk),
cume_dist() over (order by pk)
from t1 order by pk;
-pk a b percent_rank() over (order by pk) cume_dist() over (order by pk)
-1 0 10 0.0000000000 0.1000000000
-2 0 10 0.1111111111 0.2000000000
-3 1 10 0.2222222222 0.3000000000
-4 1 10 0.3333333333 0.4000000000
-5 2 20 0.4444444444 0.5000000000
-6 2 20 0.5555555556 0.6000000000
-7 2 20 0.6666666667 0.7000000000
-8 2 10 0.7777777778 0.8000000000
-9 4 20 0.8888888889 0.9000000000
-10 4 20 1.0000000000 1.0000000000
-select pk, a, b,
+pk percent_rank() over (order by pk) cume_dist() over (order by pk)
+1 0.0000000000 0.1000000000
+2 0.1111111111 0.2000000000
+3 0.2222222222 0.3000000000
+4 0.3333333333 0.4000000000
+5 0.4444444444 0.5000000000
+6 0.5555555556 0.6000000000
+7 0.6666666667 0.7000000000
+8 0.7777777778 0.8000000000
+9 0.8888888889 0.9000000000
+10 1.0000000000 1.0000000000
+select a,
percent_rank() over (partition by a order by a),
cume_dist() over (partition by a order by a)
from t1;
-pk a b percent_rank() over (partition by a order by a) cume_dist() over (partition by a order by a)
-1 0 10 0.0000000000 1.0000000000
-2 0 10 0.0000000000 1.0000000000
-3 1 10 0.0000000000 1.0000000000
-4 1 10 0.0000000000 1.0000000000
-8 2 10 0.0000000000 1.0000000000
-5 2 20 0.0000000000 1.0000000000
-6 2 20 0.0000000000 1.0000000000
-7 2 20 0.0000000000 1.0000000000
-9 4 20 0.0000000000 1.0000000000
-10 4 20 0.0000000000 1.0000000000
+a percent_rank() over (partition by a order by a) cume_dist() over (partition by a order by a)
+0 0.0000000000 1.0000000000
+0 0.0000000000 1.0000000000
+1 0.0000000000 1.0000000000
+1 0.0000000000 1.0000000000
+2 0.0000000000 1.0000000000
+2 0.0000000000 1.0000000000
+2 0.0000000000 1.0000000000
+2 0.0000000000 1.0000000000
+4 0.0000000000 1.0000000000
+4 0.0000000000 1.0000000000
drop table t1;
diff --git a/mysql-test/main/win_percent_cume.test b/mysql-test/main/win_percent_cume.test
index b851185cb32..05ace95d571 100644
--- a/mysql-test/main/win_percent_cume.test
+++ b/mysql-test/main/win_percent_cume.test
@@ -17,17 +17,17 @@ insert into t1 values
( 9 , 4, 20),
(10 , 4, 20);
-select pk, a, b,
+select a,
percent_rank() over (order by a),
cume_dist() over (order by a)
from t1;
-select pk, a, b,
+select pk,
percent_rank() over (order by pk),
cume_dist() over (order by pk)
from t1 order by pk;
-select pk, a, b,
+select a,
percent_rank() over (partition by a order by a),
cume_dist() over (partition by a order by a)
from t1;
diff --git a/mysql-test/main/win_percentile.result b/mysql-test/main/win_percentile.result
index 6ae18488697..4a918bad17f 100644
--- a/mysql-test/main/win_percentile.result
+++ b/mysql-test/main/win_percentile.result
@@ -32,8 +32,8 @@ Chun 5.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
-Tatiana 4.0000000000
Tata 4.0000000000
+Tatiana 4.0000000000
select name, percentile_disc(0.5) within group(order by score) over (partition by name) as c from t1;
name c
Chun 3.0000000000
@@ -41,8 +41,8 @@ Chun 3.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
-Tatiana 4.0000000000
Tata 4.0000000000
+Tatiana 4.0000000000
# no partition clause
select name, percentile_disc(0.5) within group(order by score) over () from t1;
name percentile_disc(0.5) within group(order by score) over ()
@@ -51,8 +51,8 @@ Chun 4.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
-Tatiana 4.0000000000
Tata 4.0000000000
+Tatiana 4.0000000000
select name, percentile_cont(0.5) within group(order by score) over () from t1;
name percentile_cont(0.5) within group(order by score) over ()
Chun 4.0000000000
@@ -60,8 +60,8 @@ Chun 4.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
-Tatiana 4.0000000000
Tata 4.0000000000
+Tatiana 4.0000000000
# argument set to null
select name, percentile_cont(null) within group(order by score) over (partition by name) from t1;
ERROR HY000: percentile_cont function only accepts arguments that can be converted to numerical types
@@ -75,8 +75,8 @@ Chun 5.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
-Tatiana 4.0000000000
Tata 4.0000000000
+Tatiana 4.0000000000
select * from ( select name , percentile_disc(0.5) within group ( order by score) over (partition by name ) from t1 ) as t;
name percentile_disc(0.5) within group ( order by score) over (partition by name )
Chun 3.0000000000
@@ -84,8 +84,8 @@ Chun 3.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
-Tatiana 4.0000000000
Tata 4.0000000000
+Tatiana 4.0000000000
select name from t1 a where (select percentile_disc(0.5) within group (order by score) over (partition by name) from t1 b limit 1) >= 0.5;
name
Chun
@@ -93,8 +93,8 @@ Chun
Kaolin
Kaolin
Kaolin
-Tatiana
Tata
+Tatiana
#disallowed fields in order by
select score, percentile_cont(0.5) within group(order by name) over (partition by score) from t1;
ERROR HY000: Numeric datatype is required for percentile_cont function
@@ -121,10 +121,10 @@ name cume_dist() over (partition by name order by score) c
Chun 0.5000000000 3.0000000000
Chun 1.0000000000 3.0000000000
Kaolin 0.3333333333 4.0000000000
-Kaolin 1.0000000000 4.0000000000
Kaolin 0.6666666667 4.0000000000
-Tatiana 1.0000000000 4.0000000000
+Kaolin 1.0000000000 4.0000000000
Tata 1.0000000000 4.0000000000
+Tatiana 1.0000000000 4.0000000000
select name, percentile_cont(0.5) within group(order by score) over (partition by name) as c from t1;
name c
Chun 5.0000000000
@@ -132,98 +132,98 @@ Chun 5.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
Kaolin 4.0000000000
-Tatiana 4.0000000000
Tata 4.0000000000
+Tatiana 4.0000000000
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.1) within group(order by score) over (partition by name) as c from t1;
name b c
Chun 0.5000000000 3.0000000000
Chun 1.0000000000 3.0000000000
Kaolin 0.3333333333 3.0000000000
-Kaolin 1.0000000000 3.0000000000
Kaolin 0.6666666667 3.0000000000
-Tatiana 1.0000000000 4.0000000000
+Kaolin 1.0000000000 3.0000000000
Tata 1.0000000000 4.0000000000
+Tatiana 1.0000000000 4.0000000000
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.2) within group(order by score) over (partition by name) as c from t1;
name b c
Chun 0.5000000000 3.0000000000
Chun 1.0000000000 3.0000000000
Kaolin 0.3333333333 3.0000000000
-Kaolin 1.0000000000 3.0000000000
Kaolin 0.6666666667 3.0000000000
-Tatiana 1.0000000000 4.0000000000
+Kaolin 1.0000000000 3.0000000000
Tata 1.0000000000 4.0000000000
+Tatiana 1.0000000000 4.0000000000
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.3) within group(order by score) over (partition by name) as c from t1;
name b c
Chun 0.5000000000 3.0000000000
Chun 1.0000000000 3.0000000000
Kaolin 0.3333333333 3.0000000000
-Kaolin 1.0000000000 3.0000000000
Kaolin 0.6666666667 3.0000000000
-Tatiana 1.0000000000 4.0000000000
+Kaolin 1.0000000000 3.0000000000
Tata 1.0000000000 4.0000000000
+Tatiana 1.0000000000 4.0000000000
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.4) within group(order by score) over (partition by name) as c from t1;
name b c
Chun 0.5000000000 3.0000000000
Chun 1.0000000000 3.0000000000
Kaolin 0.3333333333 4.0000000000
-Kaolin 1.0000000000 4.0000000000
Kaolin 0.6666666667 4.0000000000
-Tatiana 1.0000000000 4.0000000000
+Kaolin 1.0000000000 4.0000000000
Tata 1.0000000000 4.0000000000
+Tatiana 1.0000000000 4.0000000000
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.5) within group(order by score) over (partition by name) as c from t1;
name b c
Chun 0.5000000000 3.0000000000
Chun 1.0000000000 3.0000000000
Kaolin 0.3333333333 4.0000000000
-Kaolin 1.0000000000 4.0000000000
Kaolin 0.6666666667 4.0000000000
-Tatiana 1.0000000000 4.0000000000
+Kaolin 1.0000000000 4.0000000000
Tata 1.0000000000 4.0000000000
+Tatiana 1.0000000000 4.0000000000
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.6) within group(order by score) over (partition by name) as c from t1;
name b c
Chun 0.5000000000 7.0000000000
Chun 1.0000000000 7.0000000000
Kaolin 0.3333333333 4.0000000000
-Kaolin 1.0000000000 4.0000000000
Kaolin 0.6666666667 4.0000000000
-Tatiana 1.0000000000 4.0000000000
+Kaolin 1.0000000000 4.0000000000
Tata 1.0000000000 4.0000000000
+Tatiana 1.0000000000 4.0000000000
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.7) within group(order by score) over (partition by name) as c from t1;
name b c
Chun 0.5000000000 7.0000000000
Chun 1.0000000000 7.0000000000
Kaolin 0.3333333333 7.0000000000
-Kaolin 1.0000000000 7.0000000000
Kaolin 0.6666666667 7.0000000000
-Tatiana 1.0000000000 4.0000000000
+Kaolin 1.0000000000 7.0000000000
Tata 1.0000000000 4.0000000000
+Tatiana 1.0000000000 4.0000000000
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.8) within group(order by score) over (partition by name) as c from t1;
name b c
Chun 0.5000000000 7.0000000000
Chun 1.0000000000 7.0000000000
Kaolin 0.3333333333 7.0000000000
-Kaolin 1.0000000000 7.0000000000
Kaolin 0.6666666667 7.0000000000
-Tatiana 1.0000000000 4.0000000000
+Kaolin 1.0000000000 7.0000000000
Tata 1.0000000000 4.0000000000
+Tatiana 1.0000000000 4.0000000000
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.9) within group(order by score) over (partition by name) as c from t1;
name b c
Chun 0.5000000000 7.0000000000
Chun 1.0000000000 7.0000000000
Kaolin 0.3333333333 7.0000000000
-Kaolin 1.0000000000 7.0000000000
Kaolin 0.6666666667 7.0000000000
-Tatiana 1.0000000000 4.0000000000
+Kaolin 1.0000000000 7.0000000000
Tata 1.0000000000 4.0000000000
+Tatiana 1.0000000000 4.0000000000
select name,cume_dist() over (partition by name order by score) as b, percentile_disc(1) within group(order by score) over (partition by name) as c from t1;
name b c
Chun 0.5000000000 7.0000000000
Chun 1.0000000000 7.0000000000
Kaolin 0.3333333333 7.0000000000
-Kaolin 1.0000000000 7.0000000000
Kaolin 0.6666666667 7.0000000000
-Tatiana 1.0000000000 4.0000000000
+Kaolin 1.0000000000 7.0000000000
Tata 1.0000000000 4.0000000000
+Tatiana 1.0000000000 4.0000000000
select median(score) over (partition by name), percentile_cont(0) within group(order by score) over (partition by name) as c from t1;
median(score) over (partition by name) c
5.0000000000 3.0000000000
diff --git a/mysql-test/main/win_percentile.test b/mysql-test/main/win_percentile.test
index a709b38d2e6..d36b365dd9b 100644
--- a/mysql-test/main/win_percentile.test
+++ b/mysql-test/main/win_percentile.test
@@ -33,11 +33,15 @@ select percentile_cont() within group() over (partition by name) from t1;
--echo # Test simple syntax
--echo #
+--sorted_result
select name, percentile_cont(0.5) within group(order by score) over (partition by name) as c from t1;
+--sorted_result
select name, percentile_disc(0.5) within group(order by score) over (partition by name) as c from t1;
--echo # no partition clause
+--sorted_result
select name, percentile_disc(0.5) within group(order by score) over () from t1;
+--sorted_result
select name, percentile_cont(0.5) within group(order by score) over () from t1;
--echo # argument set to null
@@ -47,8 +51,11 @@ select name, percentile_cont(null) within group(order by score) over (partition
select name, percentile_disc(null) within group(order by score) over (partition by name) from t1;
--echo #subqueries having percentile functions
+--sorted_result
select * from ( select name , percentile_cont(0.5) within group ( order by score) over (partition by name ) from t1 ) as t;
+--sorted_result
select * from ( select name , percentile_disc(0.5) within group ( order by score) over (partition by name ) from t1 ) as t;
+--sorted_result
select name from t1 a where (select percentile_disc(0.5) within group (order by score) over (partition by name) from t1 b limit 1) >= 0.5;
--echo #disallowed fields in order by
diff --git a/mysql-test/main/win_rank.result b/mysql-test/main/win_rank.result
index 725683d3869..e74c2edd662 100644
--- a/mysql-test/main/win_rank.result
+++ b/mysql-test/main/win_rank.result
@@ -17,34 +17,34 @@ insert into t1 values
( 7 , 2, 20),
( 9 , 4, 20),
(10 , 4, 20);
-select pk, a, b, rank() over (order by a) as rank,
+select a, rank() over (order by a) as rank,
dense_rank() over (order by a) as dense_rank
from t1;
-pk a b rank dense_rank
-1 0 10 1 1
-2 0 10 1 1
-3 1 10 3 2
-4 1 10 3 2
-8 2 10 5 3
-5 2 20 5 3
-6 2 20 5 3
-7 2 20 5 3
-9 4 20 9 4
-10 4 20 9 4
-select pk, a, b, rank() over (partition by b order by a) as rank,
+a rank dense_rank
+0 1 1
+0 1 1
+1 3 2
+1 3 2
+2 5 3
+2 5 3
+2 5 3
+2 5 3
+4 9 4
+4 9 4
+select a, b, rank() over (partition by b order by a) as rank,
dense_rank() over (partition by b order by a) as dense_rank
from t1;
-pk a b rank dense_rank
-1 0 10 1 1
-2 0 10 1 1
-3 1 10 3 2
-4 1 10 3 2
-8 2 10 5 3
-5 2 20 1 1
-6 2 20 1 1
-7 2 20 1 1
-9 4 20 4 2
-10 4 20 4 2
+a b rank dense_rank
+0 10 1 1
+0 10 1 1
+1 10 3 2
+1 10 3 2
+2 10 5 3
+2 20 1 1
+2 20 1 1
+2 20 1 1
+4 20 4 2
+4 20 4 2
drop table t1;
#
# Test with null values in the table.
@@ -59,46 +59,49 @@ insert into t2 values (2,'b');
insert into t2 values (-1,'');
select *, rank() over (order by s1) as rank,
dense_rank() over (order by s1) as dense_rank
-from t2;
+from t2
+order by s1, s2;
s1 s2 rank dense_rank
-1 a 5 3
NULL NULL 1 1
-1 NULL 5 3
NULL a 1 1
NULL c 1 1
-2 b 7 4
-1 4 2
+1 NULL 5 3
+1 a 5 3
+2 b 7 4
select *, rank() over (partition by s2 order by s1) as rank,
dense_rank() over (partition by s2 order by s1) as dense_rank
-from t2;
+from t2
+order by s1, s2;
s1 s2 rank dense_rank
-1 a 2 2
NULL NULL 1 1
-1 NULL 2 2
NULL a 1 1
NULL c 1 1
-2 b 1 1
-1 1 1
+1 NULL 2 2
+1 a 2 2
+2 b 1 1
select *, rank() over (order by s2) as rank,
dense_rank() over (order by s2) as dense_rank
-from t2;
+from t2
+order by s2, s1;
s1 s2 rank dense_rank
-1 a 4 3
NULL NULL 1 1
1 NULL 1 1
+-1 3 2
NULL a 4 3
-NULL c 7 5
+1 a 4 3
2 b 6 4
--1 3 2
+NULL c 7 5
select *, rank() over (partition by s1 order by s2) as rank,
dense_rank() over (partition by s1 order by s2) as dense_rank
from t2;
s1 s2 rank dense_rank
-1 a 2 2
NULL NULL 1 1
-1 NULL 1 1
NULL a 2 2
NULL c 3 3
-2 b 1 1
-1 1 1
+1 NULL 1 1
+1 a 2 2
+2 b 1 1
drop table t2;
diff --git a/mysql-test/main/win_rank.test b/mysql-test/main/win_rank.test
index eda1f458205..c58ff054117 100644
--- a/mysql-test/main/win_rank.test
+++ b/mysql-test/main/win_rank.test
@@ -20,11 +20,11 @@ insert into t1 values
( 9 , 4, 20),
(10 , 4, 20);
-select pk, a, b, rank() over (order by a) as rank,
- dense_rank() over (order by a) as dense_rank
+select a, rank() over (order by a) as rank,
+ dense_rank() over (order by a) as dense_rank
from t1;
-select pk, a, b, rank() over (partition by b order by a) as rank,
- dense_rank() over (partition by b order by a) as dense_rank
+select a, b, rank() over (partition by b order by a) as rank,
+ dense_rank() over (partition by b order by a) as dense_rank
from t1;
drop table t1;
@@ -44,13 +44,16 @@ insert into t2 values (-1,'');
select *, rank() over (order by s1) as rank,
dense_rank() over (order by s1) as dense_rank
-from t2;
+from t2
+order by s1, s2;
select *, rank() over (partition by s2 order by s1) as rank,
dense_rank() over (partition by s2 order by s1) as dense_rank
-from t2;
+from t2
+order by s1, s2;
select *, rank() over (order by s2) as rank,
dense_rank() over (order by s2) as dense_rank
-from t2;
+from t2
+order by s2, s1;
select *, rank() over (partition by s1 order by s2) as rank,
dense_rank() over (partition by s1 order by s2) as dense_rank
from t2;
diff --git a/mysql-test/main/win_std.test b/mysql-test/main/win_std.test
index 5ed999431c0..c1964ecac98 100644
--- a/mysql-test/main/win_std.test
+++ b/mysql-test/main/win_std.test
@@ -80,9 +80,11 @@ select std(b) over (order by a rows between current row and 0 following)
from t2;
--echo # Only peers frame.
+--sorted_result
select a, b, std(b) over (order by a range between 0 preceding and 0 preceding)
from t2;
+--sorted_result
select a, b, std(b) over (order by a range between 0 preceding and current row)
from t2;
@@ -90,9 +92,11 @@ from t2;
select a, b, std(b) over (order by a range between current row and 0 preceding)
from t2;
+--sorted_result
select a, b, std(b) over (order by a range between current row and 0 following)
from t2;
+--sorted_result
select a, b, std(b) over (order by a range between 0 following and 0 following)
from t2;