From 8ccef67aef61a1200fcde2685018f795c64b63b6 Mon Sep 17 00:00:00 2001 From: Rex Johnston Date: Wed, 13 Aug 2025 14:33:49 +1100 Subject: [PATCH 1/3] MDEV-30073 Wrong result on 2nd execution of PS for query with NOT EXISTS Summary: Items of type Item_direct_view_ref which are reverted with the change_item_tree mechanism are involved in permanent optimizer transformations. This commit ensures that items involved in these permanent transformations are created during the first execution and re-used for subsequent executions. Queries affected by this bug are numerous, but will always involve 1) 2nd execution of a prepared statement or procedure 2) a permanent transformation, such as a semi-join optimization Detail: Consider this run as a prepared statement SELECT * FROM t1 WHERE EXISTS ( SELECT dt.a FROM ( SELECT t2a as a, t2b as b FROM t2 ) dt WHERE dt.b = t1a ) During name resolution of field dt.b (in the where clause) we end up calling find_field_in_view()/.../create_view_field(). This is responsible for creating a wrapper around the found Item (Item_field*)`test`.`t2`.`t2b` While this Item_direct_view_ref representing 'dt.b' is allocated on Statement (permanent) memory the change is registered to be reversed at the end of statement execution. This is odd and contrary to the permanent nature of this transformation. Item::exists2in_processor() is called during the preparation in the first execution. We transform the query from select * from t1 where exists ( select `test`.`t2`.`t2b` from ( select `test`.`t2`.`t2a` AS `a`,`test`.`t2`.`t2b` AS `b` from `test`.`t2` ) `dt` where `test`.`t2`.`t2b` = `test`.`t1`.`t1a` limit 1 ) select * from t1 where `test`.`t1`.`t1a` in ( select `test`.`t2`.`t2b` from ( select `test`.`t2`.`t2a` AS `a`,`test`.`t2`.`t2b` AS `b` from `test`.`t2` ) `dt` where 1 ) later, the optimizer merges the derived table dt into it's parent select * from t1 where `test`.`t1`.`t1a` in ( select `test`.`t2`.`t2b` from t2 where 1 ) then this is transformed into a semi-join select t1.* from t1 semi join t2 on t1a = t2b At the end of the first execution, the item t2b above is reverted to dt.b. During the subsequent name resolution of dt.b, it is resolved t2a, and the semi-join executed corresponds to select t1.* from t1 semi join t2 on t1a = t2a causing a different result set. Initial Author: Igor Babaev Reformatted and refactored by: Rex Johnston (rex.johnston@mariadb.com) Add assert to ensure Item_direct_view_refs are not allocated on the 2nd execution. --- mysql-test/main/derived_cond_pushdown.test | 2 - mysql-test/main/having_cond_pushdown.test | 4 +- mysql-test/main/opt_trace.test | 72 ------- mysql-test/main/ps.result | 93 ++++++++- mysql-test/main/ps.test | 85 +++++++- mysql-test/main/view.test | 3 - .../federatedx_create_handlers.result | 6 +- .../federated/federatedx_create_handlers.test | 1 + sql/item.cc | 185 ++++++++++++++---- sql/item.h | 9 +- sql/item_subselect.cc | 106 ++++++---- sql/item_subselect.h | 11 +- sql/item_sum.cc | 17 +- sql/item_sum.h | 4 +- sql/opt_subselect.cc | 21 +- sql/sql_base.cc | 29 ++- sql/sql_base.h | 20 -- sql/sql_class.h | 8 + sql/sql_lex.cc | 2 + sql/sql_lex.h | 2 + sql/sql_parse.cc | 4 + sql/sql_select.cc | 162 ++++++++++++--- sql/sql_union.cc | 3 +- sql/table.cc | 3 + sql/table.h | 24 +++ 25 files changed, 634 insertions(+), 242 deletions(-) diff --git a/mysql-test/main/derived_cond_pushdown.test b/mysql-test/main/derived_cond_pushdown.test index 8a5a7266e0733..7a77f833264b3 100644 --- a/mysql-test/main/derived_cond_pushdown.test +++ b/mysql-test/main/derived_cond_pushdown.test @@ -1896,9 +1896,7 @@ DELIMITER ;$$ CALL p1('a'); DROP PROCEDURE p1; ---disable_ps2_protocol SELECT a FROM (SELECT "aa" a) t WHERE REGEXP_INSTR(t.a, (SELECT MAX('aa') FROM DUAL LIMIT 1)); ---enable_ps2_protocol DELIMITER $$; CREATE OR REPLACE FUNCTION f1(a VARCHAR(10), b VARCHAR(10)) RETURNS INT diff --git a/mysql-test/main/having_cond_pushdown.test b/mysql-test/main/having_cond_pushdown.test index 507c5f15bfbf2..17b80bf4c8181 100644 --- a/mysql-test/main/having_cond_pushdown.test +++ b/mysql-test/main/having_cond_pushdown.test @@ -1451,11 +1451,9 @@ DROP TABLE t1,t2; CREATE TABLE t1 (i int NOT NULL); SELECT * FROM t1 GROUP BY i HAVING i IN ( i IS NULL); -#dublicate warning ---disable_view_protocol +#duplicate warning SELECT * FROM t1 GROUP BY i HAVING i IN ( i IS NULL AND 'x' = 0); SELECT * FROM t1 GROUP BY i HAVING i='1' IN ( i IS NULL AND 'x' = 0); ---enable_view_protocol DROP TABLE t1; --echo # diff --git a/mysql-test/main/opt_trace.test b/mysql-test/main/opt_trace.test index a23bef4b26a3c..7f80b0fcd4f11 100644 --- a/mysql-test/main/opt_trace.test +++ b/mysql-test/main/opt_trace.test @@ -441,14 +441,11 @@ create table t1 ( a int, b int, key a_b(a,b)); insert into t1 select a,a from one_k; set optimizer_trace='enabled=on'; -#Enable after fix MDEV-32034 ---disable_view_protocol explain select * from t1 force index (a_b) where a=2 and b=4; select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) AS JS from INFORMATION_SCHEMA.OPTIMIZER_TRACE; explain select * from t1 where a >= 900 and b between 10 and 20; select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) AS JS from INFORMATION_SCHEMA.OPTIMIZER_TRACE; ---enable_view_protocol drop table t0,t1; @@ -457,10 +454,7 @@ create table t1 (start_date date, end_date date, filler char(100), key(start_dat insert into t1 select date_add(now(), interval a day), date_add(now(), interval (a+7) day), 'data' from one_k; --enable_warnings explain select * from t1 force index(start_date) where start_date >= '2019-02-10' and end_date <'2019-04-01'; -#Enable after fix MDEV-32034 ---disable_view_protocol select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) AS JS from INFORMATION_SCHEMA.OPTIMIZER_TRACE; ---enable_view_protocol drop table t1,one_k; create table ten(a int); @@ -475,10 +469,7 @@ create table t1 ( insert into t1 select a,a, a,a from ten; explain select * from t1 force index(a_b_c) where a between 1 and 4 and b < 50; -#Enable after fix MDEV-32034 ---disable_view_protocol select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) AS JS from INFORMATION_SCHEMA.OPTIMIZER_TRACE; ---enable_view_protocol drop table ten,t1; --echo # Ported test from MYSQL for ranges involving Binary column @@ -487,14 +478,11 @@ CREATE TABLE t1(i INT PRIMARY KEY, b BINARY(16), INDEX i_b(b)); INSERT INTO t1 VALUES (1, x'D95B94336A9946A39CF5B58CFE772D8C'); INSERT INTO t1 VALUES (2, NULL); -#Enable after fix MDEV-32034 ---disable_view_protocol EXPLAIN SELECT * FROM t1 WHERE b IN (0xD95B94336A9946A39CF5B58CFE772D8C); select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) AS JS from INFORMATION_SCHEMA.OPTIMIZER_TRACE; EXPLAIN SELECT * FROM t1 WHERE b IS NULL; select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) AS JS from INFORMATION_SCHEMA.OPTIMIZER_TRACE; ---enable_view_protocol drop table t1; @@ -507,8 +495,6 @@ INSERT INTO t1 VALUES (1, 'ab\n'); INSERT INTO t1 VALUES (2, NULL); set optimizer_trace=1; EXPLAIN SELECT * FROM t1 WHERE b='ab\n'; -#Enable after fix MDEV-32034 ---disable_view_protocol select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) AS JS from INFORMATION_SCHEMA.OPTIMIZER_TRACE; ALTER TABLE t1 modify column b BINARY(10) AFTER i; @@ -552,7 +538,6 @@ insert into t1 select date_add(now(), interval a day), date_add(now(), interval --enable_warnings explain format=json select * from t1 force index(start_date) where start_date >= '2019-02-10' and end_date <'2019-04-01'; select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) AS JS from INFORMATION_SCHEMA.OPTIMIZER_TRACE; ---enable_view_protocol drop table t1, t0, one_k; --echo # @@ -584,19 +569,13 @@ set optimizer_trace=1; --echo # but for joins using condition selectivity it is not as trivial. So, --echo # now we are printing it) explain select * from t0 A, one_k B where A.a<5 and B.a<800; -#Enable after fix MDEV-32034 ---disable_view_protocol select JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) AS JS from INFORMATION_SCHEMA.OPTIMIZER_TRACE; ---enable_view_protocol set join_cache_level=@tmp_jcl; --echo # This shows post-join selectivity explain select * from t0 A, one_k B where A.a=B.b and B.a<800; -#Enable after fix MDEV-32034 ---disable_view_protocol select JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) AS JS from INFORMATION_SCHEMA.OPTIMIZER_TRACE; ---enable_view_protocol drop table t0, one_k; --echo # @@ -608,10 +587,7 @@ insert into t1 values ('foo'), ('bar'); EXPLAIN SELECT * FROM t1 WHERE a= REPEAT('a', 0); SELECT * FROM t1 WHERE a= REPEAT('a', 0); -#Enable after fix MDEV-32034 ---disable_view_protocol select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) AS JS from INFORMATION_SCHEMA.OPTIMIZER_TRACE; ---enable_view_protocol DROP TABLE t1; --echo # @@ -629,10 +605,7 @@ insert into t3 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); explain select * from t3 where (a,a) in (select t1.a, t2.a from t1, t2 where t1.b=t2.b); -#Enable after fix MDEV-32034 ---disable_view_protocol select JSON_DETAILED(JSON_EXTRACT(trace, '$**.semijoin_table_pullout')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE; ---enable_view_protocol drop table t1,t2,t3; @@ -644,10 +617,7 @@ create table t1 (kp1 int, kp2 int, key(kp1, kp2)); insert into t1 values (1,1),(1,5),(5,1),(5,5); set optimizer_trace=1; select * from t1 force index(kp1) where (kp1=2 and kp2 >=4); -#Enable after fix MDEV-32034 ---disable_view_protocol select JSON_DETAILED(JSON_EXTRACT(trace, '$**.range_scan_alternatives')) AS JS from INFORMATION_SCHEMA.OPTIMIZER_TRACE; ---enable_view_protocol drop table t1; --echo # @@ -661,10 +631,7 @@ INSERT INTO t2 SELECT seq, seq from seq_1_to_100; SET OPTIMIZER_TRACE=1; EXPLAIN SELECT * FROM t1, t2 WHERE t1.a=t2.a ORDER BY t2.b; -#Enable after fix MDEV-32034 ---disable_view_protocol select JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) AS JS from INFORMATION_SCHEMA.OPTIMIZER_TRACE; ---enable_view_protocol DROP TABLE t1,t2; --echo # @@ -676,15 +643,12 @@ CREATE TABLE t1(a INT, b INT); INSERT INTO t1 SELECT seq, seq from seq_1_to_100; SET optimizer_trace=1; ANALYZE TABLE t1 PERSISTENT FOR ALL; -#Enable after fix MDEV-32034 ---disable_view_protocol EXPLAIN EXTENDED SELECT * from t1 WHERE a between 1 and 5 and b <= 5; select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_columns')) AS JS from INFORMATION_SCHEMA.OPTIMIZER_TRACE; EXPLAIN EXTENDED SELECT * from t1 WHERE a != 5; select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_columns')) AS JS from INFORMATION_SCHEMA.OPTIMIZER_TRACE; EXPLAIN EXTENDED SELECT * from t1 WHERE b >= 10 and b < 25; select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_columns')) AS JS from INFORMATION_SCHEMA.OPTIMIZER_TRACE; ---enable_view_protocol drop table t1; --echo # @@ -695,10 +659,7 @@ drop table t1; CREATE TABLE t1( a INT, b INT, PRIMARY KEY( a ) ); SELECT sum(b), row_number() OVER (order by b) FROM t1 WHERE a = 101; UPDATE t1 SET b=10 WHERE a=1; -#Enable after fix MDEV-32034 ---disable_view_protocol SELECT JSON_DETAILED(JSON_EXTRACT(trace, '$**.range_scan_alternatives')) AS JS from INFORMATION_SCHEMA.OPTIMIZER_TRACE; ---enable_view_protocol DROP TABLE t1; set optimizer_trace='enabled=off'; @@ -759,13 +720,10 @@ where c5 in (1,2,3,4,5,6,7,8,9,10) and c6 in (1,2,3,4); -#Enable after fix MDEV-32034 ---disable_view_protocol select json_detailed(json_extract(trace, '$**.setup_range_conditions')) from information_schema.optimizer_trace; ---enable_view_protocol drop table t1; @@ -874,14 +832,11 @@ set optimizer_trace=DEFAULT; --echo # MDEV-29179 Condition pushdown from HAVING into WHERE is not shown in optimizer trace --echo # -#Enable after fix MDEV-32034 ---disable_view_protocol CREATE TABLE t1 (a INT, b VARCHAR(1), KEY (a), KEY(b,a)) ENGINE=MEMORY; INSERT INTO t1 VALUES (4,'n'),(1,'h'),(NULL,'w'); SET optimizer_trace= 'enabled=on'; SELECT b, a FROM t1 WHERE b <> 'p' OR a = 4 GROUP BY b, a HAVING a <= 7; SELECT json_detailed(json_extract(trace, '$**.steps[*].join_optimization.steps[*].condition_pushdown_from_having') ) exp1, JSON_VALID(trace) exp2 FROM information_schema.optimizer_trace; DROP TABLE t1; ---enable_view_protocol --echo # --echo # MDEV-30334 Optimizer trace produces invalid JSON with WHERE subquery @@ -933,11 +888,8 @@ insert into t3 select a,a from t0; explain select * from t1 left join (t2 join t3 on t3.pk=1000) on t2.a=t1.a and t2.pk is null; -#Enable after fix MDEV-32034 ---disable_view_protocol select JSON_DETAILED(JSON_EXTRACT(trace, '$**.mark_join_nest_as_const')) as jd from information_schema.optimizer_trace; ---disable_view_protocol drop table t0, t1, t2, t3; @@ -953,27 +905,18 @@ set in_predicate_conversion_threshold=3; explain select * from t0 where a in (1,2,3,4,5,6); -#Enable after fix MDEV-32034 ---disable_view_protocol select json_detailed(json_extract(trace, '$**.in_to_subquery_conversion')) as jd from information_schema.optimizer_trace; ---enable_view_protocol explain select * from t0 where a in (1,2,3,4,5,a+1); -#Enable after fix MDEV-32034 ---disable_view_protocol select json_detailed(json_extract(trace, '$**.in_to_subquery_conversion')) as jd from information_schema.optimizer_trace; ---enable_view_protocol explain select * from t0 where a in ('1','2','3','4','5','6'); -#Enable after fix MDEV-32034 ---disable_view_protocol select json_detailed(json_extract(trace, '$**.in_to_subquery_conversion')) as jd from information_schema.optimizer_trace; ---enable_view_protocol set in_predicate_conversion_threshold=@tmp; drop table t0; @@ -1081,13 +1024,10 @@ where a=3 group by b,b having a+b < 10; -#Enable after fix MDEV-32034 ---disable_view_protocol select json_detailed(json_extract(trace, '$**.substitute_best_equal')) from information_schema.optimizer_trace; ---enable_view_protocol --echo # Check ON expression explain @@ -1097,13 +1037,10 @@ from t1 left join t2 on t2.a=t1.a and t2.a<3 where t1.b > 5555; -#Enable after fix MDEV-32034 ---disable_view_protocol select json_detailed(json_extract(trace, '$**.substitute_best_equal')) from information_schema.optimizer_trace; ---enable_view_protocol --echo # Check nested ON expression explain @@ -1119,12 +1056,9 @@ select json_detailed(json_extract(trace, '$**.substitute_best_equal')) from information_schema.optimizer_trace; ---enable_view_protocol --echo # The next query is test for: --echo # MDEV-23646: Optimizer trace: optimize_cond() should show ON expression processing -#Enable after fix MDEV-32034 ---disable_view_protocol select json_detailed(json_extract(trace, '$**.condition_processing')) from @@ -1169,13 +1103,10 @@ where t1.b < 3; # Just show that choose_best_splitting function has coverage in the # optimizer trace and re-optmization of child select inside it is distinct # from the rest of join optimization. -#Check after fix MDEV-32034 ---disable_view_protocol select json_detailed(json_extract(trace, '$**.choose_best_splitting')) from information_schema.optimizer_trace; ---enable_view_protocol drop table t1,t2; @@ -1193,11 +1124,8 @@ SELECT * FROM t1 WHERE id IN JSON_TABLE(f1, "$" COLUMNS (jf FOR ORDINALITY)) AS tbl); --enable_view_protocol -#Enable after fix MDEV-32034 ---disable_view_protocol select json_detailed(json_extract(trace, '$**.best_join_order')) from information_schema.OPTIMIZER_TRACE; ---enable_view_protocol DROP TABLE t1; diff --git a/mysql-test/main/ps.result b/mysql-test/main/ps.result index cd4b708a96cd6..fbe8f3b2e3c6b 100644 --- a/mysql-test/main/ps.result +++ b/mysql-test/main/ps.result @@ -6058,4 +6058,95 @@ ALTER TABLE t FORCE; EXECUTE stmt USING DEFAULT; ERROR HY000: Default/ignore value is not supported for such parameter usage DROP TABLE t; -# End of 10.11 test +# +# MDEV-30073 Wrong result on 2nd execution of PS for query with NOT EXISTS +# +CREATE TABLE t1 ( +product_key int, +dealerid int +); +INSERT INTO t1 VALUES +(3569, 4), +(3569, 112); +CREATE TABLE t2 ( +id int, +product_key int +); +INSERT INTO t2 VALUES +(16494, 3569), +(16494, 3569); +CREATE TABLE t3 ( +dealerid int +); +INSERT INTO t3 VALUES (4), (5); +set optimizer_switch='subquery_cache=off'; +EXPLAIN EXTENDED +SELECT * FROM t1 +WHERE +! EXISTS +( +SELECT dt.id +FROM (SELECT id, product_key FROM t2) dt, t3 +WHERE +dt.product_key = t1.product_key AND +t3.dealerid = t1.dealerid +); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00 Using where +2 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join) +Warnings: +Note 1276 Field or reference 'test.t1.product_key' of SELECT #2 was resolved in SELECT #1 +Note 1276 Field or reference 'test.t1.dealerid' of SELECT #2 was resolved in SELECT #1 +Note 1003 /* select#1 */ select `test`.`t1`.`product_key` AS `product_key`,`test`.`t1`.`dealerid` AS `dealerid` from `test`.`t1` where !(((`test`.`t1`.`product_key`,`test`.`t1`.`dealerid`),(`test`.`t1`.`product_key`,`test`.`t1`.`dealerid`) in ( (/* select#2 */ select `test`.`t2`.`product_key`,`test`.`t3`.`dealerid` from `test`.`t2` join `test`.`t3` where `test`.`t2`.`product_key` is not null and `test`.`t3`.`dealerid` is not null ), (`test`.`t1`.`product_key` in on distinct_key where `test`.`t1`.`product_key` = ``.`product_key` and `test`.`t1`.`dealerid` = ``.`dealerid`))) and `test`.`t1`.`dealerid` is not null and `test`.`t1`.`product_key` is not null) +SELECT * FROM t1 +WHERE +! EXISTS +( +SELECT dt.id +FROM (SELECT id, product_key FROM t2) dt, t3 +WHERE +dt.product_key = t1.product_key AND +t3.dealerid = t1.dealerid +); +product_key dealerid +3569 112 +PREPARE stmt FROM " +SELECT * FROM t1 +WHERE +! EXISTS +( + SELECT dt.id + FROM (SELECT id, product_key FROM t2) dt, t3 + WHERE + dt.product_key = t1.product_key AND + t3.dealerid = t1.dealerid +)"; +EXECUTE stmt; +product_key dealerid +3569 112 +EXECUTE stmt; +product_key dealerid +3569 112 +DEALLOCATE PREPARE stmt; +DROP TABLE t1,t2,t3; +CREATE TABLE t1 (a int, b int); +INSERT INTO t1 VALUES (3569, 4), (3569, 112); +CREATE TABLE t2 (c int, a int); +INSERT INTO t2 VALUES (16494, 3569), (16494, 3569); +PREPARE stmt FROM " +SELECT * FROM t1 +WHERE EXISTS (SELECT dt.c FROM (SELECT c, a FROM t2) dt WHERE dt.a = t1.a) +"; +EXECUTE stmt; +a b +3569 4 +3569 112 +EXECUTE stmt; +a b +3569 4 +3569 112 +DROP TABLE t1,t2; +# +# End of 10.11 tests +# diff --git a/mysql-test/main/ps.test b/mysql-test/main/ps.test index 185cd065aeaff..21ac0be7eee65 100644 --- a/mysql-test/main/ps.test +++ b/mysql-test/main/ps.test @@ -5514,4 +5514,87 @@ EXECUTE stmt USING DEFAULT; DROP TABLE t; ---echo # End of 10.11 test +--echo # +--echo # MDEV-30073 Wrong result on 2nd execution of PS for query with NOT EXISTS +--echo # + +CREATE TABLE t1 ( + product_key int, + dealerid int +); +INSERT INTO t1 VALUES +(3569, 4), +(3569, 112); + +CREATE TABLE t2 ( + id int, + product_key int +); +INSERT INTO t2 VALUES +(16494, 3569), +(16494, 3569); + +CREATE TABLE t3 ( + dealerid int +); +INSERT INTO t3 VALUES (4), (5); + +set optimizer_switch='subquery_cache=off'; + +EXPLAIN EXTENDED +SELECT * FROM t1 +WHERE +! EXISTS +( + SELECT dt.id + FROM (SELECT id, product_key FROM t2) dt, t3 + WHERE + dt.product_key = t1.product_key AND + t3.dealerid = t1.dealerid +); + +SELECT * FROM t1 +WHERE +! EXISTS +( + SELECT dt.id + FROM (SELECT id, product_key FROM t2) dt, t3 + WHERE + dt.product_key = t1.product_key AND + t3.dealerid = t1.dealerid +); + +PREPARE stmt FROM " +SELECT * FROM t1 +WHERE +! EXISTS +( + SELECT dt.id + FROM (SELECT id, product_key FROM t2) dt, t3 + WHERE + dt.product_key = t1.product_key AND + t3.dealerid = t1.dealerid +)"; + +EXECUTE stmt; +EXECUTE stmt; + +DEALLOCATE PREPARE stmt; + +DROP TABLE t1,t2,t3; +CREATE TABLE t1 (a int, b int); +INSERT INTO t1 VALUES (3569, 4), (3569, 112); + +CREATE TABLE t2 (c int, a int); +INSERT INTO t2 VALUES (16494, 3569), (16494, 3569); +PREPARE stmt FROM " +SELECT * FROM t1 +WHERE EXISTS (SELECT dt.c FROM (SELECT c, a FROM t2) dt WHERE dt.a = t1.a) +"; +EXECUTE stmt; +EXECUTE stmt; +DROP TABLE t1,t2; + +--echo # +--echo # End of 10.11 tests +--echo # diff --git a/mysql-test/main/view.test b/mysql-test/main/view.test index cb120bb26adca..9282ccaeef918 100644 --- a/mysql-test/main/view.test +++ b/mysql-test/main/view.test @@ -6506,8 +6506,6 @@ DROP TABLE t1, t2; --echo # MDEV-23291: SUM column from a derived table returns invalid values --echo # -#Enable ps2 protocol after fix MDEV-31175 ---disable_ps2_protocol CREATE TABLE t1(a INT, b INT); INSERT INTO t1 VALUES (1,1), (2,2); @@ -6519,7 +6517,6 @@ SELECT sum(z) FROM v1; DROP TABLE t1; DROP VIEW v1; ---enable_ps2_protocol --echo # --echo # MDEV-26299: Some views force server (and mysqldump) to generate diff --git a/mysql-test/suite/federated/federatedx_create_handlers.result b/mysql-test/suite/federated/federatedx_create_handlers.result index 4c8f2ac68bb43..5d37472e754e7 100644 --- a/mysql-test/suite/federated/federatedx_create_handlers.result +++ b/mysql-test/suite/federated/federatedx_create_handlers.result @@ -137,13 +137,13 @@ SELECT * FROM federated.t3, (SELECT * FROM federated.t1 WHERE id > 3) t WHERE federated.t3.name=t.name; name id name +xxx 4 xxx yyy 5 yyy -yyy 7 yyy yyy 5 yyy -yyy 7 yyy -xxx 4 xxx yyy 5 yyy yyy 7 yyy +yyy 7 yyy +yyy 7 yyy EXPLAIN SELECT * FROM federated.t3, (SELECT * FROM federated.t1 WHERE id > 3) t diff --git a/mysql-test/suite/federated/federatedx_create_handlers.test b/mysql-test/suite/federated/federatedx_create_handlers.test index 0b3167b2ae1ab..6fbd29208e20e 100644 --- a/mysql-test/suite/federated/federatedx_create_handlers.test +++ b/mysql-test/suite/federated/federatedx_create_handlers.test @@ -94,6 +94,7 @@ DEFAULT CHARSET=latin1; INSERT INTO federated.t3 VALUES ('yyy'), ('www'), ('yyy'), ('xxx'), ('www'), ('yyy'), ('www'); +--sorted_result SELECT * FROM federated.t3, (SELECT * FROM federated.t1 WHERE id > 3) t WHERE federated.t3.name=t.name; diff --git a/sql/item.cc b/sql/item.cc index 338de4a46f37a..61cdc08dd5aa3 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -6074,22 +6074,49 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference) select->group_list.elements && (place == SELECT_LIST || place == IN_HAVING)) { - Item_outer_ref *rf; /* - If an outer field is resolved in a grouping select then it - is replaced for an Item_outer_ref object. Otherwise an - Item_field object is used. - The new Item_outer_ref object is saved in the inner_refs_list of - the outer select. Here it is only created. It can be fixed only - after the original field has been fixed and this is done in the - fix_inner_refs() function. - */ - ; - if (!(rf= new (thd->mem_root) Item_outer_ref(thd, context, this))) - return -1; - thd->change_item_tree(reference, rf); - select->inner_refs_list.push_back(rf, thd->mem_root); - rf->in_sum_func= thd->lex->in_sum_func; + This Item_field represents a reference to a column in some + outer select. Wrap this Item_field item into an Item_outer_ref + object if we are at the first execution of the query or at + processing the prepare command for it. Make this wrapping + permanent for the first query execution so that it could be used + for next executions of the query. + Add the wrapper item to the list st_select_lex::inner_refs_list + of the select against which this Item_field has been resolved. + */ + Query_arena::enum_state ps_state= thd->stmt_arena->state; + if (ps_state != Query_arena::STMT_EXECUTED) + { + Query_arena *arena= 0, backup; + Item_outer_ref *rf; + bool is_first_execution= + (ps_state != Query_arena::STMT_INITIALIZED); + if (is_first_execution && + !thd->stmt_arena->is_conventional()) + arena= thd->activate_stmt_arena_if_needed(&backup); + /* + If an outer field is resolved in a grouping select then it + is replaced for an Item_outer_ref object. Otherwise an + Item_field object is used. + The new Item_outer_ref object is saved in the inner_refs_list of + the outer select. Here it is only created. It can be fixed only + after the original field has been fixed and this is done in the + fix_inner_refs() function. + */ + if ((rf= new (thd->mem_root) Item_outer_ref(thd, context, this))) + { + select->inner_refs_list.push_back(rf, thd->mem_root); + if (is_first_execution) + *reference= rf; + else + thd->change_item_tree(reference, rf); + } + if (arena) + thd->restore_active_arena(arena, &backup); + if (!rf) + return -1; + rf->in_sum_func= thd->lex->in_sum_func; + } } /* A reference is resolved to a nest level that's outer or the same as @@ -6209,18 +6236,42 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference) } else if (ref != not_found_item) { + Query_arena *arena= 0, backup; + bool is_first_execution= thd->is_first_query_execution(); Item *save; - Item_ref *rf; + Item_ref *rf= 0; DBUG_ASSERT(*ref); + + /* + This Item_field represents a reference to a column in some outer select. + Wrap this Item_field item into an object of the Item_ref class or a class + derived from Item_ref we are at the first execution of the query or at + processing the prepare command for it. Make this wrapping permanent for + the first query execution so that it could be used for next executions + of the query. The type of the wrapper depends on the place where this + item field occurs or on type of the query. If it is in the the having + clause we use a wrapper of the Item_ref type. Otherwise we use a wrapper + either of Item_direct_ref type or of Item_outer_ref. The latter is used + for grouping queries. Such a wrapper is always added to the list + inner_refs_list for the select against which the outer reference has been + resolved. + */ + + DBUG_ASSERT(thd->stmt_arena->state != Query_arena::STMT_EXECUTED); + /* Here, a subset of actions performed by Item_ref::set_properties is not enough. So we pass ptr to NULL into Item_[direct]_ref - constructor, so no initialization is performed, and call + constructor, so no initialization is performed, and call fix_fields() below. */ save= *ref; *ref= NULL; // Don't call set_properties() + + if (is_first_execution && + !thd->stmt_arena->is_conventional()) + arena= thd->activate_stmt_arena_if_needed(&backup); rf= (place == IN_HAVING ? new (thd->mem_root) Item_ref(thd, context, ref, table_name, @@ -6233,16 +6284,28 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference) Item_outer_ref(thd, context, ref, table_name, field_name, alias_name_used))); *ref= save; - if (!rf) - return -1; - - if (place != IN_HAVING && select->group_list.elements) + if (rf) { - outer_context->select_lex->inner_refs_list.push_back((Item_outer_ref*)rf, - thd->mem_root); - ((Item_outer_ref*)rf)->in_sum_func= thd->lex->in_sum_func; + if (place != IN_HAVING && select->group_list.elements) + { + outer_context->select_lex->inner_refs_list.push_back( + (Item_outer_ref*)rf, thd->mem_root); + ((Item_outer_ref*)rf)->in_sum_func= thd->lex->in_sum_func; + } + /* + Reverse this change if we are running a prepare statement. + Revert any change back to the object allocated during the + first execution if we are running any subsequent execution + */ + if (is_first_execution) + *reference= rf; + else + thd->change_item_tree(reference, rf); } - thd->change_item_tree(reference, rf); + if (arena) + thd->restore_active_arena(arena, &backup); + if (!rf) + return -1; /* rf is Item_ref => never substitute other items (in this case) during fix_fields() => we can use rf after fix_fields() @@ -6274,22 +6337,43 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference) this, (Item_ident*)*reference, false); if (last_checked_context->select_lex->having_fix_field) { - Item_ref *rf; - rf= new (thd->mem_root) Item_ref(thd, context, - (*from_field)->table->s->db, - Lex_cstring_strlen((*from_field)-> - table->alias.c_ptr()), - field_name); - if (!rf) - return -1; - thd->change_item_tree(reference, rf); /* - rf is Item_ref => never substitute other items (in this case) - during fix_fields() => we can use rf after fix_fields() + This Item_field represents a reference to a column in having clause + of some outer select. Wrap this Item_field item into an Item_ref object + if we are at the first execution of the query or at processing the + prepare command for it. Make this wrapping permanent for the first query + execution so that it could be used for next executions of the query. */ - DBUG_ASSERT(!rf->fixed()); // Assured by Item_ref() - if (rf->fix_fields(thd, reference) || rf->check_cols(1)) - return -1; + Item_ref *rf; + if (thd->stmt_arena->state != Query_arena::STMT_EXECUTED) + { + Query_arena *arena= 0, backup; + bool is_first_execution= thd->is_first_query_execution(); + if (is_first_execution && !thd->stmt_arena->is_conventional()) + arena= thd->activate_stmt_arena_if_needed(&backup); + if ((rf= new (thd->mem_root) Item_ref(thd, context, + (*from_field)->table->s->db, + Lex_cstring_strlen((*from_field)-> + table->alias.c_ptr()), + field_name))) + { + if (is_first_execution) + *reference= rf; + else + thd->change_item_tree(reference, rf); + } + if (arena) + thd->restore_active_arena(arena, &backup); + if (!rf) + return -1; + /* + rf is Item_ref => never substitute other items (in this case) + during fix_fields() => we can use rf after fix_fields() + */ + DBUG_ASSERT(!rf->fixed()); // Assured by Item_ref() + if (rf->fix_fields(thd, reference) || rf->check_cols(1)) + return -1; + } return 0; } } @@ -8659,6 +8743,14 @@ bool Item_ref::fix_fields(THD *thd, Item **reference) goto error; } + /* + We need fix_fields() for the second execution when on the first execution + Item_outer_ref was used. + Populate (*ref)->field before we call Item_direct_ref::fix_fields() + */ + if ((*ref)->fix_fields_if_needed(thd, ref)) + goto error; + set_properties(); if ((*ref)->check_cols(1)) @@ -9869,6 +9961,21 @@ Item_field::excl_dep_on_grouping_fields(st_select_lex *sel) return find_matching_field_pair(this, sel->grouping_tmp_fields) != NULL; } +Item_direct_view_ref::Item_direct_view_ref(THD *thd, Name_resolution_context *context_arg, + Item **item, + LEX_CSTRING &table_name_arg, + LEX_CSTRING &field_name_arg, + TABLE_LIST *view_arg): + Item_direct_ref(thd, context_arg, item, table_name_arg, field_name_arg), + item_equal(0), view(view_arg), + null_ref_table(NULL) + { + DBUG_ASSERT(thd->stmt_arena->state != Query_arena::STMT_EXECUTED); + if (fixed()) + set_null_ref_table(); + } + + bool Item_direct_view_ref::excl_dep_on_table(table_map tab_map) { diff --git a/sql/item.h b/sql/item.h index 55ff46c7af80a..a05d3c4d892dd 100644 --- a/sql/item.h +++ b/sql/item.h @@ -6410,14 +6410,7 @@ class Item_direct_view_ref :public Item_direct_ref Item **item, LEX_CSTRING &table_name_arg, LEX_CSTRING &field_name_arg, - TABLE_LIST *view_arg): - Item_direct_ref(thd, context_arg, item, table_name_arg, field_name_arg), - item_equal(0), view(view_arg), - null_ref_table(NULL) - { - if (fixed()) - set_null_ref_table(); - } + TABLE_LIST *view_arg); bool fix_fields(THD *, Item **) override; bool eq(const Item *item, const Eq_config &config) const override; diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 6da58c20d6f3b..a5c13276693c6 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -99,8 +99,15 @@ void Item_subselect::init(st_select_lex *select_lex, { engine= unit->item->engine; parsing_place= unit->item->parsing_place; - if (unit->item->substype() == EXISTS_SUBS && - ((Item_exists_subselect *)unit->item)->exists_transformed) + + enum subs_type substype= unit->item->substype(); + if ((substype == EXISTS_SUBS && + ((Item_exists_subselect *)unit->item)->exists_transformed) || + ((substype == ALL_SUBS || substype == ANY_SUBS) && + (((Item_in_subselect *)(unit->item))-> + test_set_strategy(SUBS_MAXMIN_INJECTED) || + ((Item_in_subselect *)(unit->item))-> + test_set_strategy(SUBS_MAXMIN_ENGINE)))) { /* it is permanent transformation of EXISTS to IN */ unit->item= this; @@ -166,6 +173,7 @@ void Item_subselect::cleanup() value_assigned= 0; expr_cache= 0; forced_const= FALSE; + const_item_cache= TRUE; DBUG_PRINT("info", ("exec_counter: %d", exec_counter)); #ifndef DBUG_OFF exec_counter= 0; @@ -204,21 +212,6 @@ void Item_in_subselect::cleanup() } -void Item_allany_subselect::cleanup() -{ - /* - The MAX/MIN transformation through injection is reverted through the - change_item_tree() mechanism. Revert the select_lex object of the - query to its initial state. - */ - for (SELECT_LEX *sl= unit->first_select(); - sl; sl= sl->next_select()) - if (test_set_strategy(SUBS_MAXMIN_INJECTED)) - sl->with_sum_func= false; - Item_in_subselect::cleanup(); -} - - Item_subselect::~Item_subselect() { DBUG_ENTER("Item_subselect::~Item_subselect"); @@ -1045,6 +1038,12 @@ void Item_subselect::update_used_tables() { if (!forced_const) { + /* + upper_refs not built on 2nd execution, so for the moment, do not + recalculate our used_tables_cache + */ + if (!unit->thd->is_first_query_execution()) + return; recalc_used_tables(parent_select, FALSE); if (!(engine->uncacheable() & ~UNCACHEABLE_EXPLAIN)) { @@ -1097,6 +1096,7 @@ Item_singlerow_subselect::Item_singlerow_subselect(THD *thd, st_select_lex *sele init(select_lex, new (thd->mem_root) select_singlerow_subselect(thd, this)); set_maybe_null(); max_columns= UINT_MAX; + strategy= 0; DBUG_VOID_RETURN; } @@ -1722,17 +1722,24 @@ bool Item_exists_subselect::fix_length_and_dec() (unit->global_parameters()->limit_params.select_limit->basic_const_item() && unit->global_parameters()->limit_params.select_limit->val_int() > 1)) { - /* - We need only 1 row to determine existence (i.e. any EXISTS that is not - an IN always requires LIMIT 1) - */ - Item *item= new (thd->mem_root) Item_int(thd, (int32) 1); - if (!item) - DBUG_RETURN(TRUE); - thd->change_item_tree(&unit->global_parameters()->limit_params.select_limit, - item); - unit->global_parameters()->limit_params.explicit_limit= 1; // we set the limit - DBUG_PRINT("info", ("Set limit to 1")); + if (thd->is_first_query_execution()) + { + /* + We need only 1 row to determine existence (i.e. any EXISTS that is not + an IN always requires LIMIT 1) + This is a permanent transformation and should be allocated on statement + memory and not reversed. + */ + Query_arena backup, *arena= thd->activate_stmt_arena_if_needed(&backup); + Item *item= new (thd->mem_root) Item_int(thd, (int32) 1); + if (arena) + thd->restore_active_arena(arena, &backup); + if (!item) + DBUG_RETURN(TRUE); + unit->global_parameters()->limit_params.select_limit= item; + unit->global_parameters()->limit_params.explicit_limit= 1; // we set the limit + DBUG_PRINT("info", ("Set limit to 1")); + } } DBUG_RETURN(FALSE); } @@ -2114,8 +2121,7 @@ Item_in_subselect::single_value_transformer(JOIN *join) /** - Apply transformation max/min transwormation to ALL/ANY subquery if it is - possible. + Permanently transform ALL/ANY subquery to min/max if it is possible. @param join Join object of the subquery (i.e. 'child' join). @@ -2184,13 +2190,16 @@ bool Item_allany_subselect::transform_into_max_min(JOIN *join) item= new (thd->mem_root) Item_sum_min(thd, select_lex->ref_pointer_array[0]); } + if (!item) + DBUG_RETURN(TRUE); + if (upper_item) upper_item->set_sum_test(item); - thd->change_item_tree(&select_lex->ref_pointer_array[0], item); + select_lex->ref_pointer_array[0]= item; { List_iterator it(select_lex->item_list); it++; - thd->change_item_tree(it.ref(), item); + it.replace(item); } DBUG_EXECUTE("where", @@ -2211,32 +2220,35 @@ bool Item_allany_subselect::transform_into_max_min(JOIN *join) 0); if (join->prepare_stage2()) DBUG_RETURN(true); - subs= new (thd->mem_root) Item_singlerow_subselect(thd, select_lex); /* Remove other strategies if any (we already changed the query and can't apply other strategy). */ set_strategy(SUBS_MAXMIN_INJECTED); + subs= new (thd->mem_root) Item_singlerow_subselect(thd, select_lex); + ((Item_singlerow_subselect *)subs)->set_strategy(SUBS_MAXMIN_INJECTED); } else { Item_maxmin_subselect *item; - subs= item= new (thd->mem_root) Item_maxmin_subselect(thd, this, select_lex, func->l_op()); - if (upper_item) - upper_item->set_sub_test(item); /* Remove other strategies if any (we already changed the query and can't apply other strategy). */ set_strategy(SUBS_MAXMIN_ENGINE); + subs= item= new (thd->mem_root) Item_maxmin_subselect(thd, this, select_lex, + func->l_op()); + ((Item_maxmin_subselect *)subs)->set_strategy(SUBS_MAXMIN_ENGINE); + if (upper_item) + upper_item->set_sub_test(item); } /* The swap is needed for expressions of type 'f1 < ALL ( SELECT ....)' where we want to evaluate the sub query even if f1 would be null. */ subs= func->create_swap(thd, expr, subs); - thd->change_item_tree(place, subs); + *place= subs; if (subs->fix_fields(thd, &subs)) DBUG_RETURN(true); DBUG_ASSERT(subs == (*place)); // There was no substitutions @@ -7170,4 +7182,22 @@ Item_subselect::subselect_table_finder_processor(void *arg) } } return FALSE; -}; +} + + +bool Item_singlerow_subselect::test_set_strategy(uchar strategy_arg) +{ + DBUG_ASSERT(strategy_arg && + !(strategy_arg & ~(SUBS_MAXMIN_INJECTED | SUBS_MAXMIN_ENGINE))); + return ((strategy & SUBS_STRATEGY_CHOSEN) && (strategy & strategy_arg)); +} + + +void Item_singlerow_subselect::set_strategy(uchar strategy_arg) +{ + DBUG_ENTER("Item_singlerow_subselect::set_strategy"); + DBUG_ASSERT(strategy_arg == SUBS_MAXMIN_INJECTED || + strategy_arg == SUBS_MAXMIN_ENGINE); + strategy= (SUBS_STRATEGY_CHOSEN | strategy_arg); + DBUG_VOID_RETURN; +} diff --git a/sql/item_subselect.h b/sql/item_subselect.h index b3b5e0ff3cc60..a2b93a10e5962 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -206,7 +206,7 @@ class Item_subselect :public Item_result_field, void make_const() { used_tables_cache= 0; - const_item_cache= 0; + const_item_cache= TRUE; forced_const= TRUE; } virtual bool fix_length_and_dec(); @@ -301,6 +301,8 @@ class Item_subselect :public Item_result_field, class Item_cache; class Item_singlerow_subselect :public Item_subselect { +private: + uint16 strategy; protected: Item_cache *value, **row; public: @@ -308,6 +310,8 @@ class Item_singlerow_subselect :public Item_subselect Item_singlerow_subselect(THD *thd_arg): Item_subselect(thd_arg), value(0), row (0) {} + uint16 get_strategy() { return strategy; } + void cleanup() override; subs_type substype() override { return SINGLEROW_SUBS; } @@ -349,6 +353,10 @@ class Item_singlerow_subselect :public Item_subselect Item* expr_cache_insert_transformer(THD *thd, uchar *unused) override; + bool test_set_strategy(uchar strategy_arg); + + void set_strategy(uchar strategy_arg); + friend class select_singlerow_subselect; }; @@ -806,7 +814,6 @@ class Item_allany_subselect :public Item_in_subselect chooser_compare_func_creator fc, st_select_lex *select_lex, bool all); - void cleanup() override; // only ALL subquery has upper not subs_type substype() override { return all?ALL_SUBS:ANY_SUBS; } bool select_transformer(JOIN *join) override; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 580a13e1c5445..cc1abe10d502a 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -111,11 +111,16 @@ bool Item_sum::init_sum_func_check(THD *thd) /* Save a pointer to object to be used in items for nested set functions */ thd->lex->in_sum_func= this; nest_level= thd->lex->current_select->nest_level; - ref_by= 0; - aggr_level= -1; - aggr_sel= NULL; - max_arg_level= -1; - max_sum_func_level= -1; + if ((thd->stmt_arena->state != Query_arena::STMT_EXECUTED) || + (thd->active_stmt_arena_to_use()->state == + Query_arena::STMT_SP_QUERY_ARGUMENTS)) + { + ref_by= NULL; + aggr_level= -1; + aggr_sel= NULL; + max_arg_level= -1; + max_sum_func_level= -1; + } outer_fields.empty(); return FALSE; } @@ -432,7 +437,7 @@ bool Item_sum::register_sum_func(THD *thd, Item **ref) sl= sl->master_unit()->outer_select() ) sl->master_unit()->item->with_flags|= item_with_t::SUM_FUNC; } - if (aggr_sel) + if (aggr_sel && aggr_sel != thd->lex->current_select) thd->lex->current_select->mark_as_dependent(thd, aggr_sel, NULL); if ((thd->lex->describe & DESCRIBE_EXTENDED) && aggr_sel) diff --git a/sql/item_sum.h b/sql/item_sum.h index 77e02cac30f1c..0f8d03f1ee884 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -361,8 +361,8 @@ class Item_sum :public Item_func_or_sum Item **ref_by; /* pointer to a ref to the object used to register it */ Item_sum *next; /* next in the circular chain of registered objects */ - Item_sum *in_sum_func; /* embedding set function if any */ - st_select_lex * aggr_sel; /* select where the function is aggregated */ + Item_sum *in_sum_func; /* embedding set function if any */ + st_select_lex * aggr_sel; /* select where the function is aggregated */ int8 nest_level; /* number of the nesting level of the set function */ int8 aggr_level; /* nesting level of the aggregating subquery */ int8 max_arg_level; /* max level of unbound column references */ diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index d02a7678073af..afd79b98eb6c4 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -964,8 +964,14 @@ bool JOIN::transform_max_min_subquery() if (!subselect || (subselect->substype() != Item_subselect::ALL_SUBS && subselect->substype() != Item_subselect::ANY_SUBS)) DBUG_RETURN(0); - DBUG_RETURN(((Item_allany_subselect *) subselect)-> - transform_into_max_min(this)); + + bool rc= false; + Query_arena *arena, backup; + arena= thd->activate_stmt_arena_if_needed(&backup); + rc= (((Item_allany_subselect *) subselect)->transform_into_max_min(this)); + if (arena) + thd->restore_active_arena(arena, &backup); + DBUG_RETURN(rc); } @@ -1909,7 +1915,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred) if (!item_eq) goto restore_tl_and_exit; if (left_exp_orig != left_exp) - thd->change_item_tree(item_eq->arguments(), left_exp); + *item_eq->arguments()= left_exp; item_eq->in_equality_no= 0; sj_nest->sj_on_expr= and_items(thd, sj_nest->sj_on_expr, item_eq); } @@ -1932,8 +1938,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred) DBUG_ASSERT(left_exp->element_index(i)->fixed()); if (left_exp_orig->element_index(i) != left_exp->element_index(i)) - thd->change_item_tree(item_eq->arguments(), - left_exp->element_index(i)); + *item_eq->arguments()= left_exp->element_index(i); item_eq->in_equality_no= i; sj_nest->sj_on_expr= and_items(thd, sj_nest->sj_on_expr, item_eq); } @@ -1957,7 +1962,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred) for (uint i= 0; i < row->cols(); i++) { if (row->element_index(i) != subq_lex->ref_pointer_array[i]) - thd->change_item_tree(row->addr(i), subq_lex->ref_pointer_array[i]); + *row->addr(i)= subq_lex->ref_pointer_array[i]; } item_eq->in_equality_no= 0; sj_nest->sj_on_expr= and_items(thd, sj_nest->sj_on_expr, item_eq); @@ -6548,6 +6553,10 @@ bool JOIN::choose_subquery_plan(table_map join_tables) if (is_in_subquery()) { in_subs= unit->item->get_IN_subquery(); + if (in_subs->test_set_strategy(SUBS_MAXMIN_INJECTED)) + return false; + if (in_subs->test_set_strategy(SUBS_MAXMIN_ENGINE)) + return false; if (in_subs->create_in_to_exists_cond(this)) return true; } diff --git a/sql/sql_base.cc b/sql/sql_base.cc index bfa787107c516..037451f292441 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -6319,10 +6319,11 @@ find_field_in_view(THD *thd, TABLE_LIST *table_list, { if (!my_strcasecmp(system_charset_info, field_it.name()->str, name)) { - // in PS use own arena or data will be freed after prepare - if (register_tree_change && - thd->stmt_arena->is_stmt_prepare_or_first_stmt_execute()) - arena= thd->activate_stmt_arena_if_needed(&backup); + /* + This must be allocated on statement memory to be preserved across + executions by find_order_in_list + */ + arena= thd->activate_stmt_arena_if_needed(&backup); /* create_item() may, or may not create a new Item, depending on the column reference. See create_view_field() for details. @@ -6342,16 +6343,26 @@ find_field_in_view(THD *thd, TABLE_LIST *table_list, */ if (*ref && (*ref)->is_explicit_name()) { - if (arena) // We've activated and deactivated stmt arena above + // allocate any name on same mem_root as item above + arena=0; + if (thd->is_first_query_execution()) arena= thd->activate_stmt_arena_if_needed(&backup); item->set_name(thd, (*ref)->name); if (arena) thd->restore_active_arena(arena, &backup); } - if (register_tree_change) - thd->change_item_tree(ref, item); - else - *ref= item; + if (item != *ref) + { + /* + During the prepare phase, roll back any change + During 1st execution, make the change permanent + Subsequent executions never call this function (item is resolved) + */ + if (thd->stmt_arena->state == Query_arena::STMT_INITIALIZED) + thd->change_item_tree(ref, item); + else + *ref= item; + } DBUG_RETURN((Field*) view_ref_found); } } diff --git a/sql/sql_base.h b/sql/sql_base.h index f05a94afe719e..cbb6990e752da 100644 --- a/sql/sql_base.h +++ b/sql/sql_base.h @@ -37,26 +37,6 @@ typedef class st_select_lex SELECT_LEX; typedef struct st_lock_param_type ALTER_PARTITION_PARAM_TYPE; -/* - This enumeration type is used only by the function find_item_in_list - to return the info on how an item has been resolved against a list - of possibly aliased items. - The item can be resolved: - - against an alias name of the list's element (RESOLVED_AGAINST_ALIAS) - - against non-aliased field name of the list (RESOLVED_WITH_NO_ALIAS) - - against an aliased field name of the list (RESOLVED_BEHIND_ALIAS) - - ignoring the alias name in cases when SQL requires to ignore aliases - (e.g. when the resolved field reference contains a table name or - when the resolved item is an expression) (RESOLVED_IGNORING_ALIAS) -*/ -enum enum_resolution_type { - NOT_RESOLVED=0, - RESOLVED_IGNORING_ALIAS, - RESOLVED_BEHIND_ALIAS, - RESOLVED_WITH_NO_ALIAS, - RESOLVED_AGAINST_ALIAS -}; - /* Argument to flush_tables() of what to flush */ enum flush_tables_type { FLUSH_ALL, diff --git a/sql/sql_class.h b/sql/sql_class.h index 2c5abcbe062cc..563d58ac9b0f4 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -2939,6 +2939,14 @@ class THD: public THD_count, /* this must be first */ return static_cast(my_atomic_loadptr((void*volatile*)&m_psi)); } + /* True only during the first execution of the statement */ + inline bool is_first_query_execution() + { + return + stmt_arena->state != Query_arena::STMT_EXECUTED && + stmt_arena->state != Query_arena::STMT_INITIALIZED; // needed for PS + } + private: unsigned int m_current_stage_key; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 8a5b1a14bcca7..c3ce8dae3909b 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -3100,6 +3100,8 @@ void st_select_lex::init_query() hidden_bit_fields= 0; fields_in_window_functions= 0; changed_elements= 0; + save_uncacheable= 0; + save_master_uncacheable= 0; parsing_place= NO_MATTER; save_parsing_place= NO_MATTER; context_analysis_place= NO_MATTER; diff --git a/sql/sql_lex.h b/sql/sql_lex.h index f838ee1d34781..fd914177e3195 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1394,6 +1394,8 @@ class st_select_lex: public st_select_lex_node case of an error during prepare the PS is not created. */ uint8 changed_elements; // see TOUCHED_SEL_* + uint8 save_uncacheable; + uint8 save_master_uncacheable; /** The set of those tables whose fields are referenced in the select list of diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index ab563a54e2df5..bec9ddeef79ba 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -8328,6 +8328,10 @@ bool add_to_list(THD *thd, SQL_I_List &list, Item *item,bool asc) order->item= &order->item_ptr; order->direction= (asc ? ORDER::ORDER_ASC : ORDER::ORDER_DESC); order->used=0; + order->view_ref= 0; // may be read in find_order_in_list() before being set + order->resolution= NOT_RESOLVED; + order->select_item= nullptr; + order->from_field= nullptr; order->counter_used= 0; order->fast_field_copier_setup= 0; if (thd->lex->clause_winfuncs.is_empty()) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 70785f531bb00..cef2fda34474c 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -703,6 +703,43 @@ fix_inner_refs(THD *thd, List &all_fields, SELECT_LEX *select, the found_in_group_by field of the references from the list. */ List_iterator_fast ref_it(select->inner_refs_list); + + /* + For subsequent executions, we need added fields pushed into + all_fields so they are subsequently added to ref_pointer_array + for join execution + */ + if (thd->stmt_arena->state == Query_arena::STMT_EXECUTED) + { + while ((ref= ref_it++)) + { + if (ref->found_in_select_list) + continue; + int el= all_fields.elements; +#ifndef DBUG_OFF + /* + On the first execution this ref was wired into ref_pointer_array[el]: + fix_inner_refs() set new_ref->ref = &ref_pointer_array[el] and + ref->outer_ref = new_ref. ref_pointer_array is allocated once, on the + statement arena (setup_ref_array()), so that slot address is stable + across executions. Re-deriving el here must therefore land on exactly + the same slot; if not, the all_fields/ref_pointer_array baseline drifted + between executions and we would otherwise push the wrong column silently + (the MDEV-30073 class of bug). This is strictly stronger than checking + that the element count matches. + */ + DBUG_ASSERT(!ref_pointer_array.is_null()); + DBUG_ASSERT(ref->outer_ref && + ref->outer_ref->type() == Item::REF_ITEM); + DBUG_ASSERT(((Item_ref *) ref->outer_ref)->ref == + &ref_pointer_array[el]); +#endif + all_fields.push_front(ref_pointer_array[el], thd->mem_root); + } + return false; + } + + for (ORDER *group= select->join->group_list; group; group= group->next) { (*group->item)->walk(&Item::check_inner_refs_processor, TRUE, &ref_it); @@ -755,16 +792,37 @@ fix_inner_refs(THD *thd, List &all_fields, SELECT_LEX *select, else if (ref->found_in_group_by) direct_ref= TRUE; - new_ref= direct_ref ? - new (thd->mem_root) Item_direct_ref(thd, ref->context, item_ref, ref->table_name, - ref->field_name, ref->alias_name_used) : - new (thd->mem_root) Item_ref(thd, ref->context, item_ref, ref->table_name, - ref->field_name, ref->alias_name_used); - if (!new_ref) - return TRUE; - ref->outer_ref= new_ref; - ref->ref= &ref->outer_ref; - + /* + These late fixed items need to be allocated on statement memory during the + first execution, if this is the 2nd execution, they need to be reversed + */ + bool is_first_execution= thd->is_first_query_execution(); + if (is_first_execution || + thd->stmt_arena->is_stmt_prepare()) + { + Query_arena *arena, backup; + arena= 0; + if (is_first_execution) + arena= thd->activate_stmt_arena_if_needed(&backup); + new_ref= direct_ref ? + new (thd->mem_root) Item_direct_ref(thd, ref->context, + item_ref, ref->table_name, + ref->field_name, + ref->alias_name_used) : + new (thd->mem_root) Item_ref(thd, ref->context, + item_ref, ref->table_name, + ref->field_name, + ref->alias_name_used); + if (arena) + thd->restore_active_arena(arena, &backup); + if (!new_ref) + return TRUE; + if (is_first_execution) + ref->outer_ref= new_ref; + else + thd->change_item_tree(&ref->outer_ref, new_ref); + ref->ref= &ref->outer_ref; + } if (ref->fix_fields_if_needed(thd, 0)) return TRUE; thd->lex->used_tables|= item->used_tables(); @@ -1660,6 +1718,13 @@ JOIN::prepare(TABLE_LIST *tables_init, COND *conds_init, uint og_num, if (res) DBUG_RETURN(res); + if (!thd->is_first_query_execution() && + !thd->lex->is_ps_or_view_context_analysis()) + { + select_lex->uncacheable= select_lex->save_uncacheable; + select_lex->master_unit()->uncacheable= select_lex->save_master_uncacheable; + } + if (order) { bool requires_sorting= FALSE; @@ -1765,17 +1830,19 @@ JOIN::prepare(TABLE_LIST *tables_init, COND *conds_init, uint og_num, Check if there are references to un-aggregated columns when computing aggregate functions with implicit grouping (there is no GROUP BY). */ - if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY && !group_list && - !(select_lex->master_unit()->item && - select_lex->master_unit()->item->is_in_predicate() && - select_lex->master_unit()->item->get_IN_subquery()-> - test_set_strategy(SUBS_MAXMIN_INJECTED)) && - select_lex->non_agg_field_used() && - select_lex->agg_func_used()) - { - my_message(ER_MIX_OF_GROUP_FUNC_AND_FIELDS, - ER_THD(thd, ER_MIX_OF_GROUP_FUNC_AND_FIELDS), MYF(0)); - DBUG_RETURN(-1); + if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY && !group_list) + { + Item_subselect *subs= select_lex->master_unit()->item; + if (!(subs && subs->substype() == Item_subselect::SINGLEROW_SUBS && + ((Item_singlerow_subselect *) subs)-> + test_set_strategy(SUBS_MAXMIN_INJECTED)) && + select_lex->non_agg_field_used() && + select_lex->agg_func_used()) + { + my_message(ER_MIX_OF_GROUP_FUNC_AND_FIELDS, + ER_THD(thd, ER_MIX_OF_GROUP_FUNC_AND_FIELDS), MYF(0)); + DBUG_RETURN(-1); + } } { /* Caclulate the number of groups */ @@ -2320,6 +2387,9 @@ JOIN::optimize_inner() if (arena) thd->restore_active_arena(arena, &backup); + + select_lex->save_uncacheable= select_lex->uncacheable; + select_lex->save_master_uncacheable= select_lex->master_unit()->uncacheable; } if (!allowed_top_level_tables) @@ -27227,8 +27297,24 @@ find_order_in_list(THD *thd, Ref_ptr_array ref_pointer_array, return FALSE; } /* Lookup the current GROUP/ORDER field in the SELECT clause. */ - select_item= find_item_in_list(order_item, fields, &counter, - REPORT_EXCEPT_NOT_FOUND, &resolution); + + // if this is the first real execution + if (thd->stmt_arena->state != Query_arena::STMT_EXECUTED) + { + select_item= find_item_in_list(order_item, + fields, &counter, + REPORT_EXCEPT_NOT_FOUND, &resolution); + order->resolution= resolution; + order->select_item= select_item; + order->counter= counter; + } + else + { + resolution= order->resolution; + select_item= order->select_item; + counter= order->counter; + } + if (!select_item) return TRUE; /* The item is not unique, or some other error occurred. */ @@ -27256,9 +27342,33 @@ find_order_in_list(THD *thd, Ref_ptr_array ref_pointer_array, if ((is_group_field && order_item_type == Item::FIELD_ITEM) || order_item_type == Item::REF_ITEM) { - from_field= find_field_in_tables(thd, (Item_ident*) order_item, tables, - NULL, ignored_tables_list_t(NULL), - &view_ref, IGNORE_ERRORS, FALSE, FALSE); + if (thd->stmt_arena->state != Query_arena::STMT_EXECUTED) + { + from_field= find_field_in_tables(thd, (Item_ident*) order_item, + tables, NULL, + ignored_tables_list_t(NULL), + &view_ref, IGNORE_ERRORS, FALSE, + FALSE); + order->view_ref= view_ref; // save for next execution + order->from_field= from_field; + } + else + { + if (order->view_ref) + { + view_ref= order->view_ref; + from_field= order->from_field; + } + else + { + from_field= find_field_in_tables(thd, (Item_ident*) order_item, + tables, NULL, + ignored_tables_list_t(NULL), + &view_ref, IGNORE_ERRORS, FALSE, + FALSE); + } + } + if (!from_field) from_field= (Field*) not_found_field; } diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 0d87c830adf38..f781b2ee72c70 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -2819,6 +2819,8 @@ bool st_select_lex::cleanup() if (join) { + if (join->thd->stmt_arena->is_stmt_prepare()) + inner_refs_list.empty(); List_iterator ti(leaf_tables); TABLE_LIST *tbl; while ((tbl= ti++)) @@ -2848,7 +2850,6 @@ bool st_select_lex::cleanup() continue; error= (bool) ((uint) error | (uint) lex_unit->cleanup()); } - inner_refs_list.empty(); exclude_from_table_unique_test= FALSE; hidden_bit_fields= 0; DBUG_RETURN(error); diff --git a/sql/table.cc b/sql/table.cc index 2b283fd93e1b8..fa0ca2cf58362 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -7198,6 +7198,8 @@ Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref, Item *field= *field_ref; DBUG_ENTER("create_view_field"); + DBUG_ASSERT(thd->stmt_arena->state != Query_arena::STMT_EXECUTED); + if (view->schema_table_reformed) { /* @@ -7225,6 +7227,7 @@ Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref, { DBUG_RETURN(field); } + Name_resolution_context *context= (view->view ? &view->view->first_select_lex()->context: &thd->lex->first_select_lex()->context); diff --git a/sql/table.h b/sql/table.h index 46e76c5e419aa..27ff4dbb88a27 100644 --- a/sql/table.h +++ b/sql/table.h @@ -233,6 +233,26 @@ class View_creation_ctx : public Default_object_creation_ctx, typedef int (*fast_field_copier)(Field *to, Field *from); class Item_window_func; +/* + This enumeration type is used only by the function find_item_in_list + to return the info on how an item has been resolved against a list + of possibly aliased items. + The item can be resolved: + - against an alias name of the list's element (RESOLVED_AGAINST_ALIAS) + - against non-aliased field name of the list (RESOLVED_WITH_NO_ALIAS) + - against an aliased field name of the list (RESOLVED_BEHIND_ALIAS) + - ignoring the alias name in cases when SQL requires to ignore aliases + (e.g. when the resolved field reference contains a table name or + when the resolved item is an expression) (RESOLVED_IGNORING_ALIAS) +*/ + +enum enum_resolution_type { + NOT_RESOLVED=0, + RESOLVED_IGNORING_ALIAS, + RESOLVED_BEHIND_ALIAS, + RESOLVED_WITH_NO_ALIAS, + RESOLVED_AGAINST_ALIAS +}; typedef struct st_order { struct st_order *next; @@ -261,6 +281,10 @@ typedef struct st_order { table_map used; /* NOTE: the below is only set to 0 but is still used by eq_ref_table */ table_map depend_map; List window_funcs; + enum_resolution_type resolution; + Item **select_item; /* copy of *item for find_order_in_list */ + Item *view_ref; // these 2 saved across executions in find_order_in_list + Field *from_field; } ORDER; /** From 48e56c1d1537a11f2983577fb13b2c4ac3cef5a7 Mon Sep 17 00:00:00 2001 From: Rex Date: Thu, 16 Jul 2026 11:51:24 +1200 Subject: [PATCH 2/3] MDEV-35673 Item_subselect::used_tables_cache: outer-reference name resolution and query-merge maintenance (part 1/2) Split from MDEV-32294, discovered while inspecting how Item_subselect::used_tables_cache is recalculated across the 1st and 2nd executions of a prepared statement. Core name-resolution / used_tables rework: - Maintain SELECT_LEX::outer_references_resolved_here, a statement-memory list of the outer references resolved in each select_lex (relies on MDEV-30073 so these are not freed at end of PS execution), and rewrite Item_subselect::recalc_used_tables() to compute used_tables_cache from it (Item_belongs_to + Field_fixer). - Preserve Item_field::depended_from across executions and use it in fix_fields/fix_outer_field instead of re-running fix_outer_field, so 2nd-execution resolution is stable. - Maintain nest_level/nest_level_base and merged_into during derived and semi-join merges, and update outer_references_resolved_here when a subquery is merged into its parent. find_field_in_tables: wrap a HAVING outer reference in an Item_ref during name resolution (previously done only in Item_field::fix_outer_field), fixing a marked_for_read() assertion on queries such as SELECT 1 FROM (SELECT a FROM t1) b HAVING (SELECT b.a)=1 create_view_field: resolve view-field substitutions against current_select and allocate them on statement memory. Ban EXPLAIN EXTENDED under the mtr --ps-protocol (warning output differs because some select_transformers do not run during PREPARE). Tests: introduce main.outer_reference with ~90 labelled cases and the execute_various_ways.inc harness, which runs each query six ways (direct, prepare+execute twice, derived table, view, CTE, stored procedure) and, via include/evw_capture.inc, cross-checks that all six return identical rows. Split and documentation by Claude Opus 4.8 --- client/mysqltest.cc | 1 + mysql-test/include/evw_capture.inc | 57 + mysql-test/main/execute_various_ways.inc | 53 + mysql-test/main/features.test | 2 +- mysql-test/main/outer_reference.result | 10277 ++++++++++++++++ mysql-test/main/outer_reference.test | 1612 +++ mysql-test/main/ps.result | 6 +- mysql-test/main/table_elim.result | 4 +- .../suite/compat/oracle/r/sp-code.result | 2 +- sql/item.cc | 227 +- sql/item.h | 12 + sql/item_subselect.cc | 212 +- sql/item_subselect.h | 1 + sql/opt_subselect.cc | 54 + sql/sql_base.cc | 31 +- sql/sql_lex.cc | 168 +- sql/sql_lex.h | 10 +- sql/sql_tvc.cc | 2 + sql/table.cc | 5 +- 19 files changed, 12523 insertions(+), 213 deletions(-) create mode 100644 mysql-test/include/evw_capture.inc create mode 100644 mysql-test/main/execute_various_ways.inc create mode 100644 mysql-test/main/outer_reference.result create mode 100644 mysql-test/main/outer_reference.test diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 6677e23152d78..5cba2683c213e 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -12549,6 +12549,7 @@ void init_re(void) "^(" "[[:space:]]*PREPARE[[:space:]]|" "[[:space:]]*EXECUTE[[:space:]]|" + "[[:space:]]*EXPLAIN[[:space:]]+EXTENDED[[:space:]]|" "[[:space:]]*DEALLOCATE[[:space:]]+PREPARE[[:space:]]|" "[[:space:]]*DROP[[:space:]]+PREPARE[[:space:]]|" "(SET[[:space:]]+STATEMENT[[:space:]]+.+[[:space:]]+FOR[[:space:]]+)?" diff --git a/mysql-test/include/evw_capture.inc b/mysql-test/include/evw_capture.inc new file mode 100644 index 0000000000000..f7964c75b3487 --- /dev/null +++ b/mysql-test/include/evw_capture.inc @@ -0,0 +1,57 @@ +# Capture one execution method of $EVW_QRY into the file $EVW_OUT. +# +# Used by main/execute_various_ways.inc to cross-check that a query run +# several different ways returns the same rows. +# +# The statements are piped through a fresh mysql client session (so the +# real PREPARE/EXECUTE and CALL paths are exercised, unlike a backtick +# capture which only returns the first row, or a CREATE/INSERT ... SELECT +# sink which would change sql_command away from SQLCOM_SELECT). +# +# A marker row is emitted immediately before the row-producing statement; +# only the lines after the LAST marker are kept. For the prepared +# statement and stored procedure methods this isolates the *2nd* execution +# (the one MDEV-35673 is about). Kept rows are sorted, so row order does +# not need to be deterministic in $EVW_QRY. +# +# In (environment variables, set with `--let NAME= value`): +# MYSQL - the mysql client command (exported by mtr) +# EVW_DB - database to run in +# EVW_QRY - the query under test. It is interpolated into SQL built +# here (e.g. prepare s from '$q'), so it must contain no +# interior ';' and no single quote ('). +# EVW_METHOD - 0..5, selects the execution method +# EVW_MARKER - marker string separating discarded from kept output +# EVW_OUT - output file for the normalised rows + +perl; + my ($mysql,$db,$q,$m,$mark,$out) = + @ENV{qw(MYSQL EVW_DB EVW_QRY EVW_METHOD EVW_MARKER EVW_OUT)}; + + my $sel; + if ($m==0){ $sel="select '$mark'; $q"; } + elsif ($m==1){ $sel="prepare s from '$q'; execute s; select '$mark'; execute s; deallocate prepare s"; } + elsif ($m==2){ $sel="select '$mark'; select * from ($q) dt"; } + elsif ($m==3){ $sel="create view evw_v as $q; select '$mark'; select * from evw_v; drop view evw_v"; } + elsif ($m==4){ $sel="select '$mark'; with cte as ($q) select * from cte"; } + elsif ($m==5){ $sel="create procedure evw_p() $q; call evw_p(); select '$mark'; call evw_p(); drop procedure evw_p"; } + else { die "evw_capture.inc: bad EVW_METHOD '$m'"; } + + my $raw="$out.raw"; + # stderr is folded into the capture (2>&1); a method that errors *before* + # the marker would yield empty output, so this relies on the visible + # section of execute_various_ways.inc running first and aborting the test + # on any unexpected error. + open(P,"| $mysql --batch --skip-column-names $db > $raw 2>&1") + or die "evw_capture.inc: pipe to mysql: $!"; + print P "$sel;\n" or die "evw_capture.inc: write to mysql: $!"; + close(P) or die "evw_capture.inc: mysql client failed (exit $?) for method $m"; + + open(R,"<",$raw) or die "evw_capture.inc: read $raw: $!"; + my @l=; close(R); unlink $raw; + my $start=0; + for my $i (0..$#l){ $start=$i+1 if $l[$i]=~/\Q$mark\E/; } + my @rows= sort @l[$start..$#l]; + open(W,">",$out) or die "evw_capture.inc: write $out: $!"; + print W @rows; close(W); +EOF diff --git a/mysql-test/main/execute_various_ways.inc b/mysql-test/main/execute_various_ways.inc new file mode 100644 index 0000000000000..a825c54ddf201 --- /dev/null +++ b/mysql-test/main/execute_various_ways.inc @@ -0,0 +1,53 @@ +# Run $qry six different ways, echo each to the result log (as before), +# then capture each method's result set and assert they are all +# row-for-row identical. See include/evw_capture.inc for how/why the +# capture is done through the mysql client rather than backticks or a +# table sink. +# +# In: $ver - label for this group +# $qry - the query under test (no interior ';') + +# ---- visible executions: unchanged, still populate the .result file ---- +echo test $ver.0; +eval $qry; +echo test $ver.1; +eval prepare s from '$qry'; +execute s; +execute s; +deallocate prepare s; +echo test $ver.2; +eval select * from ($qry) dt; +echo test $ver.3; +eval create view v as $qry; +select * from v; +select * from v; +drop view v; +echo test $ver.4; +eval with cte as ($qry) select * from cte; +echo test $ver.5; +eval create procedure p() $qry; +call p(); +call p(); +drop procedure p; + +# ---- cross-check: every method must return the same rows as method 0 ---- +--let EVW_MARKER= __EVW_ROWS__ +--let EVW_QRY= $qry +--let EVW_DB= `select database()` + +--let $m= 0 +while ($m <= 5) +{ + --let EVW_METHOD= $m + --let EVW_OUT= $MYSQLTEST_VARDIR/tmp/evw_$m.tsv + --source include/evw_capture.inc + --inc $m +} + +--diff_files $MYSQLTEST_VARDIR/tmp/evw_0.tsv $MYSQLTEST_VARDIR/tmp/evw_1.tsv +--diff_files $MYSQLTEST_VARDIR/tmp/evw_0.tsv $MYSQLTEST_VARDIR/tmp/evw_2.tsv +--diff_files $MYSQLTEST_VARDIR/tmp/evw_0.tsv $MYSQLTEST_VARDIR/tmp/evw_3.tsv +--diff_files $MYSQLTEST_VARDIR/tmp/evw_0.tsv $MYSQLTEST_VARDIR/tmp/evw_4.tsv +--diff_files $MYSQLTEST_VARDIR/tmp/evw_0.tsv $MYSQLTEST_VARDIR/tmp/evw_5.tsv + +echo "END GROUP"; diff --git a/mysql-test/main/features.test b/mysql-test/main/features.test index 054d8f323f093..c7be9164a991e 100644 --- a/mysql-test/main/features.test +++ b/mysql-test/main/features.test @@ -77,7 +77,7 @@ create table t1 (a int); insert into t1 values (2); select (select a from t1 where t1.a=t2.a), a from t1 as t2; drop table t1; ---replace_result 8 4 +--replace_result 8 5 show status like "feature_subquery"; --echo # diff --git a/mysql-test/main/outer_reference.result b/mysql-test/main/outer_reference.result new file mode 100644 index 0000000000000..233884f216a7c --- /dev/null +++ b/mysql-test/main/outer_reference.result @@ -0,0 +1,10277 @@ +/* index to characterization test +[1st digit, Class, see below]. +[# of outer references to a parent]. +[# of outer references to a subquery]. +[# of outer references to parent from subquery]. +[# of item subselects]. +[# references to expressions]. +[# degenerated selects]. +[Execution method, see below]. +Class 0, not mergeable +Class 1, view mergeable +Class 1a, derived table mergeable +Class 1b, cte mergeable +Class 2, subquery mergeable +Class 3, multiple outer_select paths +Class 4, unions +Class 5, subqueries in group by & order by with references to parent select_lex +Class 6, subquery merge into derived merge +Class 7, odds and ends +Execution method, +0 normal +1 prepared statement +2 wrapped in a derived table +3 wrapped in a view +4 wrapped in a CTE +5 as a procedure +*/ +create table t1 (t1a int, t1b int, t1c int) engine=myisam; +insert into t1 values (1,1,1),(2,2,2); +create table t2 (t2a int, t2b int, t2c int) engine=myisam; +insert into t2 values (1,1,1),(2,2,2),(3,3,3); +create table t3 (t3a int, t3b int, t3c int) engine=myisam; +insert into t3 values (1,1,1),(2,2,2),(3,3,3),(4,4,4); +create table t4 (t4a int, t4b int, t4c int) engine=myisam; +insert into t4 values (1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5); +create table t5 (t5a int, t5b int, t5c int) engine=myisam; +insert into t5 values (1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),(6,6,6); +create table t6 (t6a int, t6b int, t6c int) engine=myisam; +insert into t6 values (1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),(6,6,6),(7,7,7); +create table t7 (t7a int, t7b int, t7c int) engine=myisam; +insert into t7 values (1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),(6,6,6),(7,7,7), +(8,8,8); +create table ambiguous like t1; +insert into ambiguous values (1, 1, 1); +create view v1 (v1a, v1b) as select t7a, t7b from t7 where t7c > 4; +create view v2 (v2a, v2b) as +select t7a*t5c, t7b*t5c from t7, t5 where t7a = t5a and t7c > 4; +create view v3 (v3a) as select t1a from t1 where exists +( +select t2a from t2 where t2a = t1a +); +create view v4 (v4a) as select t1a from t1 where exists +( +select t2a from t2 where t2a = t1a and t2b = t1b +); +create view v5 (v5a, v5b, v5c) as select * from t5 limit 100; +create view v6 as select t1a as c1, (select c1) as c2, +(select c2) as c3 from t1; +test 0.1.0.0.1.0.0.0.0 +select * from t1, t6 where t6a=t1a or -- select 1 +( +select max(t4a) from t4 where t4c < t1b -- select 2 +) <> 0; +t1a t1b t1c t6a t6b t6c +1 1 1 1 1 1 +2 2 2 1 1 1 +2 2 2 2 2 2 +2 2 2 3 3 3 +2 2 2 4 4 4 +2 2 2 5 5 5 +2 2 2 6 6 6 +2 2 2 7 7 7 +test 0.1.0.0.1.0.0.0.1 +prepare s from 'select * from t1, t6 where t6a=t1a or -- select 1 +( +select max(t4a) from t4 where t4c < t1b -- select 2 +) <> 0'; +execute s; +t1a t1b t1c t6a t6b t6c +1 1 1 1 1 1 +2 2 2 1 1 1 +2 2 2 2 2 2 +2 2 2 3 3 3 +2 2 2 4 4 4 +2 2 2 5 5 5 +2 2 2 6 6 6 +2 2 2 7 7 7 +execute s; +t1a t1b t1c t6a t6b t6c +1 1 1 1 1 1 +2 2 2 1 1 1 +2 2 2 2 2 2 +2 2 2 3 3 3 +2 2 2 4 4 4 +2 2 2 5 5 5 +2 2 2 6 6 6 +2 2 2 7 7 7 +deallocate prepare s; +test 0.1.0.0.1.0.0.0.2 +select * from (select * from t1, t6 where t6a=t1a or -- select 1 +( +select max(t4a) from t4 where t4c < t1b -- select 2 +) <> 0) dt; +t1a t1b t1c t6a t6b t6c +1 1 1 1 1 1 +2 2 2 1 1 1 +2 2 2 2 2 2 +2 2 2 3 3 3 +2 2 2 4 4 4 +2 2 2 5 5 5 +2 2 2 6 6 6 +2 2 2 7 7 7 +test 0.1.0.0.1.0.0.0.3 +create view v as select * from t1, t6 where t6a=t1a or -- select 1 +( +select max(t4a) from t4 where t4c < t1b -- select 2 +) <> 0; +select * from v; +t1a t1b t1c t6a t6b t6c +1 1 1 1 1 1 +2 2 2 1 1 1 +2 2 2 2 2 2 +2 2 2 3 3 3 +2 2 2 4 4 4 +2 2 2 5 5 5 +2 2 2 6 6 6 +2 2 2 7 7 7 +select * from v; +t1a t1b t1c t6a t6b t6c +1 1 1 1 1 1 +2 2 2 1 1 1 +2 2 2 2 2 2 +2 2 2 3 3 3 +2 2 2 4 4 4 +2 2 2 5 5 5 +2 2 2 6 6 6 +2 2 2 7 7 7 +drop view v; +test 0.1.0.0.1.0.0.0.4 +with cte as (select * from t1, t6 where t6a=t1a or -- select 1 +( +select max(t4a) from t4 where t4c < t1b -- select 2 +) <> 0) select * from cte; +t1a t1b t1c t6a t6b t6c +1 1 1 1 1 1 +2 2 2 1 1 1 +2 2 2 2 2 2 +2 2 2 3 3 3 +2 2 2 4 4 4 +2 2 2 5 5 5 +2 2 2 6 6 6 +2 2 2 7 7 7 +test 0.1.0.0.1.0.0.0.5 +create procedure p() select * from t1, t6 where t6a=t1a or -- select 1 +( +select max(t4a) from t4 where t4c < t1b -- select 2 +) <> 0; +call p(); +t1a t1b t1c t6a t6b t6c +1 1 1 1 1 1 +2 2 2 1 1 1 +2 2 2 2 2 2 +2 2 2 3 3 3 +2 2 2 4 4 4 +2 2 2 5 5 5 +2 2 2 6 6 6 +2 2 2 7 7 7 +call p(); +t1a t1b t1c t6a t6b t6c +1 1 1 1 1 1 +2 2 2 1 1 1 +2 2 2 2 2 2 +2 2 2 3 3 3 +2 2 2 4 4 4 +2 2 2 5 5 5 +2 2 2 6 6 6 +2 2 2 7 7 7 +drop procedure p; +"END GROUP" +test 0a.1.0.0.1.0.0.0.0 +select * from v1 where v1a >= any +( +select t4a from t4 where t4b >= v1b +); +v1a v1b +5 5 +test 0a.1.0.0.1.0.0.0.1 +prepare s from 'select * from v1 where v1a >= any +( +select t4a from t4 where t4b >= v1b +)'; +execute s; +v1a v1b +5 5 +execute s; +v1a v1b +5 5 +deallocate prepare s; +test 0a.1.0.0.1.0.0.0.2 +select * from (select * from v1 where v1a >= any +( +select t4a from t4 where t4b >= v1b +)) dt; +v1a v1b +5 5 +test 0a.1.0.0.1.0.0.0.3 +create view v as select * from v1 where v1a >= any +( +select t4a from t4 where t4b >= v1b +); +select * from v; +v1a v1b +5 5 +select * from v; +v1a v1b +5 5 +drop view v; +test 0a.1.0.0.1.0.0.0.4 +with cte as (select * from v1 where v1a >= any +( +select t4a from t4 where t4b >= v1b +)) select * from cte; +v1a v1b +5 5 +test 0a.1.0.0.1.0.0.0.5 +create procedure p() select * from v1 where v1a >= any +( +select t4a from t4 where t4b >= v1b +); +call p(); +v1a v1b +5 5 +call p(); +v1a v1b +5 5 +drop procedure p; +"END GROUP" +test 0.1.1.0.2.0.1.0 +select * from t1, t2 where t2b in +( +select +( +select t1a from t1 order by t1b, t2b limit 1 +) as d +from t1 group by +( +select d +) +); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +test 0.1.1.0.2.0.1.1 +prepare s from 'select * from t1, t2 where t2b in +( +select +( +select t1a from t1 order by t1b, t2b limit 1 +) as d +from t1 group by +( +select d +) +)'; +execute s; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +execute s; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +deallocate prepare s; +test 0.1.1.0.2.0.1.2 +select * from (select * from t1, t2 where t2b in +( +select +( +select t1a from t1 order by t1b, t2b limit 1 +) as d +from t1 group by +( +select d +) +)) dt; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +test 0.1.1.0.2.0.1.3 +create view v as select * from t1, t2 where t2b in +( +select +( +select t1a from t1 order by t1b, t2b limit 1 +) as d +from t1 group by +( +select d +) +); +select * from v; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +select * from v; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +drop view v; +test 0.1.1.0.2.0.1.4 +with cte as (select * from t1, t2 where t2b in +( +select +( +select t1a from t1 order by t1b, t2b limit 1 +) as d +from t1 group by +( +select d +) +)) select * from cte; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +test 0.1.1.0.2.0.1.5 +create procedure p() select * from t1, t2 where t2b in +( +select +( +select t1a from t1 order by t1b, t2b limit 1 +) as d +from t1 group by +( +select d +) +); +call p(); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +call p(); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +drop procedure p; +"END GROUP" +test 1a.1.0.0.1.0.0.0.0 +select * from t6, v1 where t6a=v1a and -- select 1 +( +select max(t4a) from t4 where t4c < v1b -- select 2 +) <> 0; +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1a.1.0.0.1.0.0.0.1 +prepare s from 'select * from t6, v1 where t6a=v1a and -- select 1 +( +select max(t4a) from t4 where t4c < v1b -- select 2 +) <> 0'; +execute s; +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +execute s; +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +deallocate prepare s; +test 1a.1.0.0.1.0.0.0.2 +select * from (select * from t6, v1 where t6a=v1a and -- select 1 +( +select max(t4a) from t4 where t4c < v1b -- select 2 +) <> 0) dt; +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1a.1.0.0.1.0.0.0.3 +create view v as select * from t6, v1 where t6a=v1a and -- select 1 +( +select max(t4a) from t4 where t4c < v1b -- select 2 +) <> 0; +select * from v; +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +select * from v; +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +drop view v; +test 1a.1.0.0.1.0.0.0.4 +with cte as (select * from t6, v1 where t6a=v1a and -- select 1 +( +select max(t4a) from t4 where t4c < v1b -- select 2 +) <> 0) select * from cte; +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1a.1.0.0.1.0.0.0.5 +create procedure p() select * from t6, v1 where t6a=v1a and -- select 1 +( +select max(t4a) from t4 where t4c < v1b -- select 2 +) <> 0; +call p(); +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +call p(); +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +drop procedure p; +"END GROUP" +test 1a.1.0.0.1.0.1.0.0 +select * from t6, v1 where t6a=v1a and -- select 1 +( +select max(t4a) from t4 where -- select 2 +( +select t4c < v1b -- select 3 +) +) <> 0; +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1a.1.0.0.1.0.1.0.1 +prepare s from 'select * from t6, v1 where t6a=v1a and -- select 1 +( +select max(t4a) from t4 where -- select 2 +( +select t4c < v1b -- select 3 +) +) <> 0'; +execute s; +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +execute s; +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +deallocate prepare s; +test 1a.1.0.0.1.0.1.0.2 +select * from (select * from t6, v1 where t6a=v1a and -- select 1 +( +select max(t4a) from t4 where -- select 2 +( +select t4c < v1b -- select 3 +) +) <> 0) dt; +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1a.1.0.0.1.0.1.0.3 +create view v as select * from t6, v1 where t6a=v1a and -- select 1 +( +select max(t4a) from t4 where -- select 2 +( +select t4c < v1b -- select 3 +) +) <> 0; +select * from v; +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +select * from v; +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +drop view v; +test 1a.1.0.0.1.0.1.0.4 +with cte as (select * from t6, v1 where t6a=v1a and -- select 1 +( +select max(t4a) from t4 where -- select 2 +( +select t4c < v1b -- select 3 +) +) <> 0) select * from cte; +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1a.1.0.0.1.0.1.0.5 +create procedure p() select * from t6, v1 where t6a=v1a and -- select 1 +( +select max(t4a) from t4 where -- select 2 +( +select t4c < v1b -- select 3 +) +) <> 0; +call p(); +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +call p(); +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +drop procedure p; +"END GROUP" +test 1b.1.0.0.1.0.0.0.0 +select * from v1 where v1a in +( +select t7a from t7 where t7b >= v1b +); +v1a v1b +5 5 +6 6 +7 7 +8 8 +test 1b.1.0.0.1.0.0.0.1 +prepare s from 'select * from v1 where v1a in +( +select t7a from t7 where t7b >= v1b +)'; +execute s; +v1a v1b +5 5 +6 6 +7 7 +8 8 +execute s; +v1a v1b +5 5 +6 6 +7 7 +8 8 +deallocate prepare s; +test 1b.1.0.0.1.0.0.0.2 +select * from (select * from v1 where v1a in +( +select t7a from t7 where t7b >= v1b +)) dt; +v1a v1b +5 5 +6 6 +7 7 +8 8 +test 1b.1.0.0.1.0.0.0.3 +create view v as select * from v1 where v1a in +( +select t7a from t7 where t7b >= v1b +); +select * from v; +v1a v1b +5 5 +6 6 +7 7 +8 8 +select * from v; +v1a v1b +5 5 +6 6 +7 7 +8 8 +drop view v; +test 1b.1.0.0.1.0.0.0.4 +with cte as (select * from v1 where v1a in +( +select t7a from t7 where t7b >= v1b +)) select * from cte; +v1a v1b +5 5 +6 6 +7 7 +8 8 +test 1b.1.0.0.1.0.0.0.5 +create procedure p() select * from v1 where v1a in +( +select t7a from t7 where t7b >= v1b +); +call p(); +v1a v1b +5 5 +6 6 +7 7 +8 8 +call p(); +v1a v1b +5 5 +6 6 +7 7 +8 8 +drop procedure p; +"END GROUP" +test 1b.1.0.0.1.0.1.0.0 +select * from v1 where v1a in +( +select t7a from t7 where +( +select t7b >= v1b +) +); +v1a v1b +5 5 +6 6 +7 7 +8 8 +test 1b.1.0.0.1.0.1.0.1 +prepare s from 'select * from v1 where v1a in +( +select t7a from t7 where +( +select t7b >= v1b +) +)'; +execute s; +v1a v1b +5 5 +6 6 +7 7 +8 8 +execute s; +v1a v1b +5 5 +6 6 +7 7 +8 8 +deallocate prepare s; +test 1b.1.0.0.1.0.1.0.2 +select * from (select * from v1 where v1a in +( +select t7a from t7 where +( +select t7b >= v1b +) +)) dt; +v1a v1b +5 5 +6 6 +7 7 +8 8 +test 1b.1.0.0.1.0.1.0.3 +create view v as select * from v1 where v1a in +( +select t7a from t7 where +( +select t7b >= v1b +) +); +select * from v; +v1a v1b +5 5 +6 6 +7 7 +8 8 +select * from v; +v1a v1b +5 5 +6 6 +7 7 +8 8 +drop view v; +test 1b.1.0.0.1.0.1.0.4 +with cte as (select * from v1 where v1a in +( +select t7a from t7 where +( +select t7b >= v1b +) +)) select * from cte; +v1a v1b +5 5 +6 6 +7 7 +8 8 +test 1b.1.0.0.1.0.1.0.5 +create procedure p() select * from v1 where v1a in +( +select t7a from t7 where +( +select t7b >= v1b +) +); +call p(); +v1a v1b +5 5 +6 6 +7 7 +8 8 +call p(); +v1a v1b +5 5 +6 6 +7 7 +8 8 +drop procedure p; +"END GROUP" +test 1c.1.0.0.1.0.0.0.0 +select * from t7 where t7a in +( +select avg(t7b) from t1 where t1b = t7b-5 +); +t7a t7b t7c +6 6 6 +7 7 7 +test 1c.1.0.0.1.0.0.0.1 +prepare s from 'select * from t7 where t7a in +( +select avg(t7b) from t1 where t1b = t7b-5 +)'; +execute s; +t7a t7b t7c +6 6 6 +7 7 7 +execute s; +t7a t7b t7c +6 6 6 +7 7 7 +deallocate prepare s; +test 1c.1.0.0.1.0.0.0.2 +select * from (select * from t7 where t7a in +( +select avg(t7b) from t1 where t1b = t7b-5 +)) dt; +t7a t7b t7c +6 6 6 +7 7 7 +test 1c.1.0.0.1.0.0.0.3 +create view v as select * from t7 where t7a in +( +select avg(t7b) from t1 where t1b = t7b-5 +); +select * from v; +t7a t7b t7c +6 6 6 +7 7 7 +select * from v; +t7a t7b t7c +6 6 6 +7 7 7 +drop view v; +test 1c.1.0.0.1.0.0.0.4 +with cte as (select * from t7 where t7a in +( +select avg(t7b) from t1 where t1b = t7b-5 +)) select * from cte; +t7a t7b t7c +6 6 6 +7 7 7 +test 1c.1.0.0.1.0.0.0.5 +create procedure p() select * from t7 where t7a in +( +select avg(t7b) from t1 where t1b = t7b-5 +); +call p(); +t7a t7b t7c +6 6 6 +7 7 7 +call p(); +t7a t7b t7c +6 6 6 +7 7 7 +drop procedure p; +"END GROUP" +test 1c.1.0.0.1.0.1.0.0 +select * from t7 where t7a in +( +select avg(t7b) from t1 where +( +select t1b = t7b-5 +) +); +t7a t7b t7c +6 6 6 +7 7 7 +test 1c.1.0.0.1.0.1.0.1 +prepare s from 'select * from t7 where t7a in +( +select avg(t7b) from t1 where +( +select t1b = t7b-5 +) +)'; +execute s; +t7a t7b t7c +6 6 6 +7 7 7 +execute s; +t7a t7b t7c +6 6 6 +7 7 7 +deallocate prepare s; +test 1c.1.0.0.1.0.1.0.2 +select * from (select * from t7 where t7a in +( +select avg(t7b) from t1 where +( +select t1b = t7b-5 +) +)) dt; +t7a t7b t7c +6 6 6 +7 7 7 +test 1c.1.0.0.1.0.1.0.3 +create view v as select * from t7 where t7a in +( +select avg(t7b) from t1 where +( +select t1b = t7b-5 +) +); +select * from v; +t7a t7b t7c +6 6 6 +7 7 7 +select * from v; +t7a t7b t7c +6 6 6 +7 7 7 +drop view v; +test 1c.1.0.0.1.0.1.0.4 +with cte as (select * from t7 where t7a in +( +select avg(t7b) from t1 where +( +select t1b = t7b-5 +) +)) select * from cte; +t7a t7b t7c +6 6 6 +7 7 7 +test 1c.1.0.0.1.0.1.0.5 +create procedure p() select * from t7 where t7a in +( +select avg(t7b) from t1 where +( +select t1b = t7b-5 +) +); +call p(); +t7a t7b t7c +6 6 6 +7 7 7 +call p(); +t7a t7b t7c +6 6 6 +7 7 7 +drop procedure p; +"END GROUP" +test 1d.1.0.0.1.0.0.0.0 +select * from v1 where v1a in +( +select avg(v1b) from t1 where t1b = v1b-5 +); +v1a v1b +6 6 +7 7 +test 1d.1.0.0.1.0.0.0.1 +prepare s from 'select * from v1 where v1a in +( +select avg(v1b) from t1 where t1b = v1b-5 +)'; +execute s; +v1a v1b +6 6 +7 7 +execute s; +v1a v1b +6 6 +7 7 +deallocate prepare s; +test 1d.1.0.0.1.0.0.0.2 +select * from (select * from v1 where v1a in +( +select avg(v1b) from t1 where t1b = v1b-5 +)) dt; +v1a v1b +6 6 +7 7 +test 1d.1.0.0.1.0.0.0.3 +create view v as select * from v1 where v1a in +( +select avg(v1b) from t1 where t1b = v1b-5 +); +select * from v; +v1a v1b +6 6 +7 7 +select * from v; +v1a v1b +6 6 +7 7 +drop view v; +test 1d.1.0.0.1.0.0.0.4 +with cte as (select * from v1 where v1a in +( +select avg(v1b) from t1 where t1b = v1b-5 +)) select * from cte; +v1a v1b +6 6 +7 7 +test 1d.1.0.0.1.0.0.0.5 +create procedure p() select * from v1 where v1a in +( +select avg(v1b) from t1 where t1b = v1b-5 +); +call p(); +v1a v1b +6 6 +7 7 +call p(); +v1a v1b +6 6 +7 7 +drop procedure p; +"END GROUP" +test 1e.1.0.0.1.0.0.0.0 +select * from v5 where v5a in +( +select avg(v5b) from t1 where t1b = v5b-5 +); +v5a v5b v5c +6 6 6 +test 1e.1.0.0.1.0.0.0.1 +prepare s from 'select * from v5 where v5a in +( +select avg(v5b) from t1 where t1b = v5b-5 +)'; +execute s; +v5a v5b v5c +6 6 6 +execute s; +v5a v5b v5c +6 6 6 +deallocate prepare s; +test 1e.1.0.0.1.0.0.0.2 +select * from (select * from v5 where v5a in +( +select avg(v5b) from t1 where t1b = v5b-5 +)) dt; +v5a v5b v5c +6 6 6 +test 1e.1.0.0.1.0.0.0.3 +create view v as select * from v5 where v5a in +( +select avg(v5b) from t1 where t1b = v5b-5 +); +select * from v; +v5a v5b v5c +6 6 6 +select * from v; +v5a v5b v5c +6 6 6 +drop view v; +test 1e.1.0.0.1.0.0.0.4 +with cte as (select * from v5 where v5a in +( +select avg(v5b) from t1 where t1b = v5b-5 +)) select * from cte; +v5a v5b v5c +6 6 6 +test 1e.1.0.0.1.0.0.0.5 +create procedure p() select * from v5 where v5a in +( +select avg(v5b) from t1 where t1b = v5b-5 +); +call p(); +v5a v5b v5c +6 6 6 +call p(); +v5a v5b v5c +6 6 6 +drop procedure p; +"END GROUP" +test 1.1.0.0.1.1.0.0.0 +select * from t6, v2 where t6a*t6b=v2a and -- select 1 +( +select max(t4a) from t4 where t4c < v2b -- select 2 +) <> 0; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +test 1.1.0.0.1.1.0.0.1 +prepare s from 'select * from t6, v2 where t6a*t6b=v2a and -- select 1 +( +select max(t4a) from t4 where t4c < v2b -- select 2 +) <> 0'; +execute s; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +execute s; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +deallocate prepare s; +test 1.1.0.0.1.1.0.0.2 +select * from (select * from t6, v2 where t6a*t6b=v2a and -- select 1 +( +select max(t4a) from t4 where t4c < v2b -- select 2 +) <> 0) dt; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +test 1.1.0.0.1.1.0.0.3 +create view v as select * from t6, v2 where t6a*t6b=v2a and -- select 1 +( +select max(t4a) from t4 where t4c < v2b -- select 2 +) <> 0; +select * from v; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +select * from v; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +drop view v; +test 1.1.0.0.1.1.0.0.4 +with cte as (select * from t6, v2 where t6a*t6b=v2a and -- select 1 +( +select max(t4a) from t4 where t4c < v2b -- select 2 +) <> 0) select * from cte; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +test 1.1.0.0.1.1.0.0.5 +create procedure p() select * from t6, v2 where t6a*t6b=v2a and -- select 1 +( +select max(t4a) from t4 where t4c < v2b -- select 2 +) <> 0; +call p(); +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +call p(); +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +drop procedure p; +"END GROUP" +test 1.1.0.0.1.1.1.0.0 +select * from t6, v2 where t6a*t6b=v2a and -- select 1 +( +select max(t4a) from t4 where -- select 2 +( +select t4c < v2b -- select 3 +) +) <> 0; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +test 1.1.0.0.1.1.1.0.1 +prepare s from 'select * from t6, v2 where t6a*t6b=v2a and -- select 1 +( +select max(t4a) from t4 where -- select 2 +( +select t4c < v2b -- select 3 +) +) <> 0'; +execute s; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +execute s; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +deallocate prepare s; +test 1.1.0.0.1.1.1.0.2 +select * from (select * from t6, v2 where t6a*t6b=v2a and -- select 1 +( +select max(t4a) from t4 where -- select 2 +( +select t4c < v2b -- select 3 +) +) <> 0) dt; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +test 1.1.0.0.1.1.1.0.3 +create view v as select * from t6, v2 where t6a*t6b=v2a and -- select 1 +( +select max(t4a) from t4 where -- select 2 +( +select t4c < v2b -- select 3 +) +) <> 0; +select * from v; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +select * from v; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +drop view v; +test 1.1.0.0.1.1.1.0.4 +with cte as (select * from t6, v2 where t6a*t6b=v2a and -- select 1 +( +select max(t4a) from t4 where -- select 2 +( +select t4c < v2b -- select 3 +) +) <> 0) select * from cte; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +test 1.1.0.0.1.1.1.0.5 +create procedure p() select * from t6, v2 where t6a*t6b=v2a and -- select 1 +( +select max(t4a) from t4 where -- select 2 +( +select t4c < v2b -- select 3 +) +) <> 0; +call p(); +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +call p(); +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +drop procedure p; +"END GROUP" +test 1.1.0.0.1.1.2.0.0 +select * from t6, v2 where -- select 1 +( +select t6a*t6b=v2a -- select 2 +) +and +( +select max(t4a) from t4 where -- select 3 +( +select t4c < v2b -- select 4 +) +) <> 0; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +test 1.1.0.0.1.1.2.0.1 +prepare s from 'select * from t6, v2 where -- select 1 +( +select t6a*t6b=v2a -- select 2 +) +and +( +select max(t4a) from t4 where -- select 3 +( +select t4c < v2b -- select 4 +) +) <> 0'; +execute s; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +execute s; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +deallocate prepare s; +test 1.1.0.0.1.1.2.0.2 +select * from (select * from t6, v2 where -- select 1 +( +select t6a*t6b=v2a -- select 2 +) +and +( +select max(t4a) from t4 where -- select 3 +( +select t4c < v2b -- select 4 +) +) <> 0) dt; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +test 1.1.0.0.1.1.2.0.3 +create view v as select * from t6, v2 where -- select 1 +( +select t6a*t6b=v2a -- select 2 +) +and +( +select max(t4a) from t4 where -- select 3 +( +select t4c < v2b -- select 4 +) +) <> 0; +select * from v; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +select * from v; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +drop view v; +test 1.1.0.0.1.1.2.0.4 +with cte as (select * from t6, v2 where -- select 1 +( +select t6a*t6b=v2a -- select 2 +) +and +( +select max(t4a) from t4 where -- select 3 +( +select t4c < v2b -- select 4 +) +) <> 0) select * from cte; +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +test 1.1.0.0.1.1.2.0.5 +create procedure p() select * from t6, v2 where -- select 1 +( +select t6a*t6b=v2a -- select 2 +) +and +( +select max(t4a) from t4 where -- select 3 +( +select t4c < v2b -- select 4 +) +) <> 0; +call p(); +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +call p(); +t6a t6b t6c v2a v2b +5 5 5 25 25 +6 6 6 36 36 +drop procedure p; +"END GROUP" +test 1.2.0.0.1.1.0.0 +select * from t6, v1, v2 where t6a=v1a and t6b * t6a = v2b and -- select 1 +( +select max(t4a) from t4, t5 -- select 2 +where t5a = t4a and t4c < v1b and t5b < v2b +) <> 0; +t6a t6b t6c v1a v1b v2a v2b +5 5 5 5 5 25 25 +6 6 6 6 6 36 36 +test 1.2.0.0.1.1.0.1 +prepare s from 'select * from t6, v1, v2 where t6a=v1a and t6b * t6a = v2b and -- select 1 +( +select max(t4a) from t4, t5 -- select 2 +where t5a = t4a and t4c < v1b and t5b < v2b +) <> 0'; +execute s; +t6a t6b t6c v1a v1b v2a v2b +5 5 5 5 5 25 25 +6 6 6 6 6 36 36 +execute s; +t6a t6b t6c v1a v1b v2a v2b +5 5 5 5 5 25 25 +6 6 6 6 6 36 36 +deallocate prepare s; +test 1.2.0.0.1.1.0.2 +select * from (select * from t6, v1, v2 where t6a=v1a and t6b * t6a = v2b and -- select 1 +( +select max(t4a) from t4, t5 -- select 2 +where t5a = t4a and t4c < v1b and t5b < v2b +) <> 0) dt; +t6a t6b t6c v1a v1b v2a v2b +5 5 5 5 5 25 25 +6 6 6 6 6 36 36 +test 1.2.0.0.1.1.0.3 +create view v as select * from t6, v1, v2 where t6a=v1a and t6b * t6a = v2b and -- select 1 +( +select max(t4a) from t4, t5 -- select 2 +where t5a = t4a and t4c < v1b and t5b < v2b +) <> 0; +select * from v; +t6a t6b t6c v1a v1b v2a v2b +5 5 5 5 5 25 25 +6 6 6 6 6 36 36 +select * from v; +t6a t6b t6c v1a v1b v2a v2b +5 5 5 5 5 25 25 +6 6 6 6 6 36 36 +drop view v; +test 1.2.0.0.1.1.0.4 +with cte as (select * from t6, v1, v2 where t6a=v1a and t6b * t6a = v2b and -- select 1 +( +select max(t4a) from t4, t5 -- select 2 +where t5a = t4a and t4c < v1b and t5b < v2b +) <> 0) select * from cte; +t6a t6b t6c v1a v1b v2a v2b +5 5 5 5 5 25 25 +6 6 6 6 6 36 36 +test 1.2.0.0.1.1.0.5 +create procedure p() select * from t6, v1, v2 where t6a=v1a and t6b * t6a = v2b and -- select 1 +( +select max(t4a) from t4, t5 -- select 2 +where t5a = t4a and t4c < v1b and t5b < v2b +) <> 0; +call p(); +t6a t6b t6c v1a v1b v2a v2b +5 5 5 5 5 25 25 +6 6 6 6 6 36 36 +call p(); +t6a t6b t6c v1a v1b v2a v2b +5 5 5 5 5 25 25 +6 6 6 6 6 36 36 +drop procedure p; +"END GROUP" +test 1.1.1.0.2.1.0.0.0 +select * from t6, v1 where t6a=v1a and t6b in -- select 1 +( +select sqrt(v2b) from v2 where -- select 2 +( +select max(t4a) from t4, t5 -- select 3 +where t5a = t4a and t4c < v1b and t5b < v2b +) <> 0 +); +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +test 1.1.1.0.2.1.0.0.1 +prepare s from 'select * from t6, v1 where t6a=v1a and t6b in -- select 1 +( +select sqrt(v2b) from v2 where -- select 2 +( +select max(t4a) from t4, t5 -- select 3 +where t5a = t4a and t4c < v1b and t5b < v2b +) <> 0 +)'; +execute s; +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +execute s; +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +deallocate prepare s; +test 1.1.1.0.2.1.0.0.2 +select * from (select * from t6, v1 where t6a=v1a and t6b in -- select 1 +( +select sqrt(v2b) from v2 where -- select 2 +( +select max(t4a) from t4, t5 -- select 3 +where t5a = t4a and t4c < v1b and t5b < v2b +) <> 0 +)) dt; +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +test 1.1.1.0.2.1.0.0.3 +create view v as select * from t6, v1 where t6a=v1a and t6b in -- select 1 +( +select sqrt(v2b) from v2 where -- select 2 +( +select max(t4a) from t4, t5 -- select 3 +where t5a = t4a and t4c < v1b and t5b < v2b +) <> 0 +); +select * from v; +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +select * from v; +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +drop view v; +test 1.1.1.0.2.1.0.0.4 +with cte as (select * from t6, v1 where t6a=v1a and t6b in -- select 1 +( +select sqrt(v2b) from v2 where -- select 2 +( +select max(t4a) from t4, t5 -- select 3 +where t5a = t4a and t4c < v1b and t5b < v2b +) <> 0 +)) select * from cte; +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +test 1.1.1.0.2.1.0.0.5 +create procedure p() select * from t6, v1 where t6a=v1a and t6b in -- select 1 +( +select sqrt(v2b) from v2 where -- select 2 +( +select max(t4a) from t4, t5 -- select 3 +where t5a = t4a and t4c < v1b and t5b < v2b +) <> 0 +); +call p(); +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +call p(); +t6a t6b t6c v1a v1b +5 5 5 5 5 +6 6 6 6 6 +drop procedure p; +"END GROUP" +test 1.1.1.1.2.0.0.0 +select t1a from t1 join t4 on t1c = t4c -- select 1 parent +where t1a in +( +select t2a from t2 -- select 2 child +where t2b >= any +( +select t3b from t3 where t3c >= t1b -- select 3 +) +and t2b >= t4c +); +t1a +1 +2 +test 1.1.1.1.2.0.0.1 +prepare s from 'select t1a from t1 join t4 on t1c = t4c -- select 1 parent +where t1a in +( +select t2a from t2 -- select 2 child +where t2b >= any +( +select t3b from t3 where t3c >= t1b -- select 3 +) +and t2b >= t4c +)'; +execute s; +t1a +1 +2 +execute s; +t1a +1 +2 +deallocate prepare s; +test 1.1.1.1.2.0.0.2 +select * from (select t1a from t1 join t4 on t1c = t4c -- select 1 parent +where t1a in +( +select t2a from t2 -- select 2 child +where t2b >= any +( +select t3b from t3 where t3c >= t1b -- select 3 +) +and t2b >= t4c +)) dt; +t1a +1 +2 +test 1.1.1.1.2.0.0.3 +create view v as select t1a from t1 join t4 on t1c = t4c -- select 1 parent +where t1a in +( +select t2a from t2 -- select 2 child +where t2b >= any +( +select t3b from t3 where t3c >= t1b -- select 3 +) +and t2b >= t4c +); +select * from v; +t1a +1 +2 +select * from v; +t1a +1 +2 +drop view v; +test 1.1.1.1.2.0.0.4 +with cte as (select t1a from t1 join t4 on t1c = t4c -- select 1 parent +where t1a in +( +select t2a from t2 -- select 2 child +where t2b >= any +( +select t3b from t3 where t3c >= t1b -- select 3 +) +and t2b >= t4c +)) select * from cte; +t1a +1 +2 +test 1.1.1.1.2.0.0.5 +create procedure p() select t1a from t1 join t4 on t1c = t4c -- select 1 parent +where t1a in +( +select t2a from t2 -- select 2 child +where t2b >= any +( +select t3b from t3 where t3c >= t1b -- select 3 +) +and t2b >= t4c +); +call p(); +t1a +1 +2 +call p(); +t1a +1 +2 +drop procedure p; +"END GROUP" +test 1.1.1.1.2.1.0.0 +select t1a from t1 join t4 on t1c = t4c -- select 1 parent +where t1a in +( +select t2a from t2 -- select 2 child +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c >= t1b -- select 4 +) +) +and t2b >= t4c +); +t1a +1 +2 +test 1.1.1.1.2.1.0.1 +prepare s from 'select t1a from t1 join t4 on t1c = t4c -- select 1 parent +where t1a in +( +select t2a from t2 -- select 2 child +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c >= t1b -- select 4 +) +) +and t2b >= t4c +)'; +execute s; +t1a +1 +2 +execute s; +t1a +1 +2 +deallocate prepare s; +test 1.1.1.1.2.1.0.2 +select * from (select t1a from t1 join t4 on t1c = t4c -- select 1 parent +where t1a in +( +select t2a from t2 -- select 2 child +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c >= t1b -- select 4 +) +) +and t2b >= t4c +)) dt; +t1a +1 +2 +test 1.1.1.1.2.1.0.3 +create view v as select t1a from t1 join t4 on t1c = t4c -- select 1 parent +where t1a in +( +select t2a from t2 -- select 2 child +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c >= t1b -- select 4 +) +) +and t2b >= t4c +); +select * from v; +t1a +1 +2 +select * from v; +t1a +1 +2 +drop view v; +test 1.1.1.1.2.1.0.4 +with cte as (select t1a from t1 join t4 on t1c = t4c -- select 1 parent +where t1a in +( +select t2a from t2 -- select 2 child +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c >= t1b -- select 4 +) +) +and t2b >= t4c +)) select * from cte; +t1a +1 +2 +test 1.1.1.1.2.1.0.5 +create procedure p() select t1a from t1 join t4 on t1c = t4c -- select 1 parent +where t1a in +( +select t2a from t2 -- select 2 child +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c >= t1b -- select 4 +) +) +and t2b >= t4c +); +call p(); +t1a +1 +2 +call p(); +t1a +1 +2 +drop procedure p; +"END GROUP" +test 1.3.2.2.2.0.0.0.0 +select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( +select t2a from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c >= t1b -- select 3 +and t3a >= t1c and t3b >= t1a +) +and t2b >= t4c and t2a >= t4a +); +t1a +1 +2 +test 1.3.2.2.2.0.0.0.1 +prepare s from 'select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( +select t2a from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c >= t1b -- select 3 +and t3a >= t1c and t3b >= t1a +) +and t2b >= t4c and t2a >= t4a +)'; +execute s; +t1a +1 +2 +execute s; +t1a +1 +2 +deallocate prepare s; +test 1.3.2.2.2.0.0.0.2 +select * from (select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( +select t2a from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c >= t1b -- select 3 +and t3a >= t1c and t3b >= t1a +) +and t2b >= t4c and t2a >= t4a +)) dt; +t1a +1 +2 +test 1.3.2.2.2.0.0.0.3 +create view v as select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( +select t2a from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c >= t1b -- select 3 +and t3a >= t1c and t3b >= t1a +) +and t2b >= t4c and t2a >= t4a +); +select * from v; +t1a +1 +2 +select * from v; +t1a +1 +2 +drop view v; +test 1.3.2.2.2.0.0.0.4 +with cte as (select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( +select t2a from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c >= t1b -- select 3 +and t3a >= t1c and t3b >= t1a +) +and t2b >= t4c and t2a >= t4a +)) select * from cte; +t1a +1 +2 +test 1.3.2.2.2.0.0.0.5 +create procedure p() select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( +select t2a from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c >= t1b -- select 3 +and t3a >= t1c and t3b >= t1a +) +and t2b >= t4c and t2a >= t4a +); +call p(); +t1a +1 +2 +call p(); +t1a +1 +2 +drop procedure p; +"END GROUP" +test 1.3.2.2.2.0.1.0.0 +select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( +select t2a from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c >= t1b -- select 3 +and +( +select t3a >= t1c and t3b >= t1a -- select 4 +) +) +and t2b >= t4c and t2a >= t4a +); +t1a +1 +2 +test 1.3.2.2.2.0.1.0.1 +prepare s from 'select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( +select t2a from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c >= t1b -- select 3 +and +( +select t3a >= t1c and t3b >= t1a -- select 4 +) +) +and t2b >= t4c and t2a >= t4a +)'; +execute s; +t1a +1 +2 +execute s; +t1a +1 +2 +deallocate prepare s; +test 1.3.2.2.2.0.1.0.2 +select * from (select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( +select t2a from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c >= t1b -- select 3 +and +( +select t3a >= t1c and t3b >= t1a -- select 4 +) +) +and t2b >= t4c and t2a >= t4a +)) dt; +t1a +1 +2 +test 1.3.2.2.2.0.1.0.3 +create view v as select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( +select t2a from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c >= t1b -- select 3 +and +( +select t3a >= t1c and t3b >= t1a -- select 4 +) +) +and t2b >= t4c and t2a >= t4a +); +select * from v; +t1a +1 +2 +select * from v; +t1a +1 +2 +drop view v; +test 1.3.2.2.2.0.1.0.4 +with cte as (select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( +select t2a from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c >= t1b -- select 3 +and +( +select t3a >= t1c and t3b >= t1a -- select 4 +) +) +and t2b >= t4c and t2a >= t4a +)) select * from cte; +t1a +1 +2 +test 1.3.2.2.2.0.1.0.5 +create procedure p() select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( +select t2a from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c >= t1b -- select 3 +and +( +select t3a >= t1c and t3b >= t1a -- select 4 +) +) +and t2b >= t4c and t2a >= t4a +); +call p(); +t1a +1 +2 +call p(); +t1a +1 +2 +drop procedure p; +"END GROUP" +test 1.3.2.2.2.0.2.0.0 +select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( +select t2a from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c >= t1b -- select 4 +) +and +( +select t3a >= t1c and t3b >= t1a -- select 5 +) +) +and t2b >= t4c and t2a >= t4a +); +t1a +1 +2 +test 1.3.2.2.2.0.2.0.1 +prepare s from 'select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( +select t2a from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c >= t1b -- select 4 +) +and +( +select t3a >= t1c and t3b >= t1a -- select 5 +) +) +and t2b >= t4c and t2a >= t4a +)'; +execute s; +t1a +1 +2 +execute s; +t1a +1 +2 +deallocate prepare s; +test 1.3.2.2.2.0.2.0.2 +select * from (select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( +select t2a from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c >= t1b -- select 4 +) +and +( +select t3a >= t1c and t3b >= t1a -- select 5 +) +) +and t2b >= t4c and t2a >= t4a +)) dt; +t1a +1 +2 +test 1.3.2.2.2.0.2.0.3 +create view v as select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( +select t2a from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c >= t1b -- select 4 +) +and +( +select t3a >= t1c and t3b >= t1a -- select 5 +) +) +and t2b >= t4c and t2a >= t4a +); +select * from v; +t1a +1 +2 +select * from v; +t1a +1 +2 +drop view v; +test 1.3.2.2.2.0.2.0.4 +with cte as (select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( +select t2a from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c >= t1b -- select 4 +) +and +( +select t3a >= t1c and t3b >= t1a -- select 5 +) +) +and t2b >= t4c and t2a >= t4a +)) select * from cte; +t1a +1 +2 +test 1.3.2.2.2.0.2.0.5 +create procedure p() select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( +select t2a from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c >= t1b -- select 4 +) +and +( +select t3a >= t1c and t3b >= t1a -- select 5 +) +) +and t2b >= t4c and t2a >= t4a +); +call p(); +t1a +1 +2 +call p(); +t1a +1 +2 +drop procedure p; +"END GROUP" +test 1.3.1.1.2.1.0.0.0 +select t7a from t7 join v2 on t7b*t7c = v2b -- select 1 +where t7a in +( +select t6a from t6 -- select 2 +where t6b >= any +( +select t3b*t3c from t3 where t3c <= t7b -- select 3 +and t3a <= t7c and t3b <= t7a +) +and t6b <= v2b +); +t7a +5 +6 +test 1.3.1.1.2.1.0.0.1 +prepare s from 'select t7a from t7 join v2 on t7b*t7c = v2b -- select 1 +where t7a in +( +select t6a from t6 -- select 2 +where t6b >= any +( +select t3b*t3c from t3 where t3c <= t7b -- select 3 +and t3a <= t7c and t3b <= t7a +) +and t6b <= v2b +)'; +execute s; +t7a +5 +6 +execute s; +t7a +5 +6 +deallocate prepare s; +test 1.3.1.1.2.1.0.0.2 +select * from (select t7a from t7 join v2 on t7b*t7c = v2b -- select 1 +where t7a in +( +select t6a from t6 -- select 2 +where t6b >= any +( +select t3b*t3c from t3 where t3c <= t7b -- select 3 +and t3a <= t7c and t3b <= t7a +) +and t6b <= v2b +)) dt; +t7a +5 +6 +test 1.3.1.1.2.1.0.0.3 +create view v as select t7a from t7 join v2 on t7b*t7c = v2b -- select 1 +where t7a in +( +select t6a from t6 -- select 2 +where t6b >= any +( +select t3b*t3c from t3 where t3c <= t7b -- select 3 +and t3a <= t7c and t3b <= t7a +) +and t6b <= v2b +); +select * from v; +t7a +5 +6 +select * from v; +t7a +5 +6 +drop view v; +test 1.3.1.1.2.1.0.0.4 +with cte as (select t7a from t7 join v2 on t7b*t7c = v2b -- select 1 +where t7a in +( +select t6a from t6 -- select 2 +where t6b >= any +( +select t3b*t3c from t3 where t3c <= t7b -- select 3 +and t3a <= t7c and t3b <= t7a +) +and t6b <= v2b +)) select * from cte; +t7a +5 +6 +test 1.3.1.1.2.1.0.0.5 +create procedure p() select t7a from t7 join v2 on t7b*t7c = v2b -- select 1 +where t7a in +( +select t6a from t6 -- select 2 +where t6b >= any +( +select t3b*t3c from t3 where t3c <= t7b -- select 3 +and t3a <= t7c and t3b <= t7a +) +and t6b <= v2b +); +call p(); +t7a +5 +6 +call p(); +t7a +5 +6 +drop procedure p; +"END GROUP" +test 1.3.2.2.2.2.0.0.0 +select t7a from t7 join v2 on t7b*t7c = v2b -- select 1 +where t7a in +( +select t6a from t6 -- select 2 +where t6b >= any +( +select t3b*t3c from t3 where t3c <= t7b -- select 3 +and t3a <= t7c and t3b <= t7a +) +and t6b <= v2b and t6a <= v2a +); +t7a +5 +6 +test 1.3.2.2.2.2.0.0.1 +prepare s from 'select t7a from t7 join v2 on t7b*t7c = v2b -- select 1 +where t7a in +( +select t6a from t6 -- select 2 +where t6b >= any +( +select t3b*t3c from t3 where t3c <= t7b -- select 3 +and t3a <= t7c and t3b <= t7a +) +and t6b <= v2b and t6a <= v2a +)'; +execute s; +t7a +5 +6 +execute s; +t7a +5 +6 +deallocate prepare s; +test 1.3.2.2.2.2.0.0.2 +select * from (select t7a from t7 join v2 on t7b*t7c = v2b -- select 1 +where t7a in +( +select t6a from t6 -- select 2 +where t6b >= any +( +select t3b*t3c from t3 where t3c <= t7b -- select 3 +and t3a <= t7c and t3b <= t7a +) +and t6b <= v2b and t6a <= v2a +)) dt; +t7a +5 +6 +test 1.3.2.2.2.2.0.0.3 +create view v as select t7a from t7 join v2 on t7b*t7c = v2b -- select 1 +where t7a in +( +select t6a from t6 -- select 2 +where t6b >= any +( +select t3b*t3c from t3 where t3c <= t7b -- select 3 +and t3a <= t7c and t3b <= t7a +) +and t6b <= v2b and t6a <= v2a +); +select * from v; +t7a +5 +6 +select * from v; +t7a +5 +6 +drop view v; +test 1.3.2.2.2.2.0.0.4 +with cte as (select t7a from t7 join v2 on t7b*t7c = v2b -- select 1 +where t7a in +( +select t6a from t6 -- select 2 +where t6b >= any +( +select t3b*t3c from t3 where t3c <= t7b -- select 3 +and t3a <= t7c and t3b <= t7a +) +and t6b <= v2b and t6a <= v2a +)) select * from cte; +t7a +5 +6 +test 1.3.2.2.2.2.0.0.5 +create procedure p() select t7a from t7 join v2 on t7b*t7c = v2b -- select 1 +where t7a in +( +select t6a from t6 -- select 2 +where t6b >= any +( +select t3b*t3c from t3 where t3c <= t7b -- select 3 +and t3a <= t7c and t3b <= t7a +) +and t6b <= v2b and t6a <= v2a +); +call p(); +t7a +5 +6 +call p(); +t7a +5 +6 +drop procedure p; +"END GROUP" +test 1a.2.0.0.1.0.0.0.0 +select * from t6, -- select 1 +( +select t7a as dt1a, t7b as dt1b from t7 where t7c > 4 -- select 2 +) dt1 +where t6a=dt1a and +( +select max(t4a) from t4 where t4c <= dt1b -- select 3 +) <> 0; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1a.2.0.0.1.0.0.0.1 +prepare s from 'select * from t6, -- select 1 +( +select t7a as dt1a, t7b as dt1b from t7 where t7c > 4 -- select 2 +) dt1 +where t6a=dt1a and +( +select max(t4a) from t4 where t4c <= dt1b -- select 3 +) <> 0'; +execute s; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +execute s; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +deallocate prepare s; +test 1a.2.0.0.1.0.0.0.2 +select * from (select * from t6, -- select 1 +( +select t7a as dt1a, t7b as dt1b from t7 where t7c > 4 -- select 2 +) dt1 +where t6a=dt1a and +( +select max(t4a) from t4 where t4c <= dt1b -- select 3 +) <> 0) dt; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1a.2.0.0.1.0.0.0.3 +create view v as select * from t6, -- select 1 +( +select t7a as dt1a, t7b as dt1b from t7 where t7c > 4 -- select 2 +) dt1 +where t6a=dt1a and +( +select max(t4a) from t4 where t4c <= dt1b -- select 3 +) <> 0; +select * from v; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +select * from v; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +drop view v; +test 1a.2.0.0.1.0.0.0.4 +with cte as (select * from t6, -- select 1 +( +select t7a as dt1a, t7b as dt1b from t7 where t7c > 4 -- select 2 +) dt1 +where t6a=dt1a and +( +select max(t4a) from t4 where t4c <= dt1b -- select 3 +) <> 0) select * from cte; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1a.2.0.0.1.0.0.0.5 +create procedure p() select * from t6, -- select 1 +( +select t7a as dt1a, t7b as dt1b from t7 where t7c > 4 -- select 2 +) dt1 +where t6a=dt1a and +( +select max(t4a) from t4 where t4c <= dt1b -- select 3 +) <> 0; +call p(); +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +call p(); +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +drop procedure p; +"END GROUP" +test 1a.2.0.0.1.0.1.0.0 +select * from t6, -- select 1 +( +select t7a as dt1a, t7b as dt1b from t7 where -- select 2 +( +select t7c > 4 -- select 3 +) +) dt1 +where t6a=dt1a and +( +select max(t4a) from t4 where t4c <= dt1b -- select 4 +) <> 0; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1a.2.0.0.1.0.1.0.1 +prepare s from 'select * from t6, -- select 1 +( +select t7a as dt1a, t7b as dt1b from t7 where -- select 2 +( +select t7c > 4 -- select 3 +) +) dt1 +where t6a=dt1a and +( +select max(t4a) from t4 where t4c <= dt1b -- select 4 +) <> 0'; +execute s; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +execute s; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +deallocate prepare s; +test 1a.2.0.0.1.0.1.0.2 +select * from (select * from t6, -- select 1 +( +select t7a as dt1a, t7b as dt1b from t7 where -- select 2 +( +select t7c > 4 -- select 3 +) +) dt1 +where t6a=dt1a and +( +select max(t4a) from t4 where t4c <= dt1b -- select 4 +) <> 0) dt; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1a.2.0.0.1.0.1.0.3 +create view v as select * from t6, -- select 1 +( +select t7a as dt1a, t7b as dt1b from t7 where -- select 2 +( +select t7c > 4 -- select 3 +) +) dt1 +where t6a=dt1a and +( +select max(t4a) from t4 where t4c <= dt1b -- select 4 +) <> 0; +select * from v; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +select * from v; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +drop view v; +test 1a.2.0.0.1.0.1.0.4 +with cte as (select * from t6, -- select 1 +( +select t7a as dt1a, t7b as dt1b from t7 where -- select 2 +( +select t7c > 4 -- select 3 +) +) dt1 +where t6a=dt1a and +( +select max(t4a) from t4 where t4c <= dt1b -- select 4 +) <> 0) select * from cte; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1a.2.0.0.1.0.1.0.5 +create procedure p() select * from t6, -- select 1 +( +select t7a as dt1a, t7b as dt1b from t7 where -- select 2 +( +select t7c > 4 -- select 3 +) +) dt1 +where t6a=dt1a and +( +select max(t4a) from t4 where t4c <= dt1b -- select 4 +) <> 0; +call p(); +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +call p(); +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +drop procedure p; +"END GROUP" +test 1a.2.0.0.1.0.2.0.0 +select * from t6, -- select 1 +( +select t7a as dt1a, t7b as dt1b from t7 where -- select 2 +( +select t7c > 4 -- select 3 +) +) dt1 +where t6a=dt1a and +( +select max(t4a) from t4 where -- select 4 +( +select t4c <= dt1b -- select 5 +) +) <> 0; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1a.2.0.0.1.0.2.0.1 +prepare s from 'select * from t6, -- select 1 +( +select t7a as dt1a, t7b as dt1b from t7 where -- select 2 +( +select t7c > 4 -- select 3 +) +) dt1 +where t6a=dt1a and +( +select max(t4a) from t4 where -- select 4 +( +select t4c <= dt1b -- select 5 +) +) <> 0'; +execute s; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +execute s; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +deallocate prepare s; +test 1a.2.0.0.1.0.2.0.2 +select * from (select * from t6, -- select 1 +( +select t7a as dt1a, t7b as dt1b from t7 where -- select 2 +( +select t7c > 4 -- select 3 +) +) dt1 +where t6a=dt1a and +( +select max(t4a) from t4 where -- select 4 +( +select t4c <= dt1b -- select 5 +) +) <> 0) dt; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1a.2.0.0.1.0.2.0.3 +create view v as select * from t6, -- select 1 +( +select t7a as dt1a, t7b as dt1b from t7 where -- select 2 +( +select t7c > 4 -- select 3 +) +) dt1 +where t6a=dt1a and +( +select max(t4a) from t4 where -- select 4 +( +select t4c <= dt1b -- select 5 +) +) <> 0; +select * from v; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +select * from v; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +drop view v; +test 1a.2.0.0.1.0.2.0.4 +with cte as (select * from t6, -- select 1 +( +select t7a as dt1a, t7b as dt1b from t7 where -- select 2 +( +select t7c > 4 -- select 3 +) +) dt1 +where t6a=dt1a and +( +select max(t4a) from t4 where -- select 4 +( +select t4c <= dt1b -- select 5 +) +) <> 0) select * from cte; +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1a.2.0.0.1.0.2.0.5 +create procedure p() select * from t6, -- select 1 +( +select t7a as dt1a, t7b as dt1b from t7 where -- select 2 +( +select t7c > 4 -- select 3 +) +) dt1 +where t6a=dt1a and +( +select max(t4a) from t4 where -- select 4 +( +select t4c <= dt1b -- select 5 +) +) <> 0; +call p(); +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +call p(); +t6a t6b t6c dt1a dt1b +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +drop procedure p; +"END GROUP" +test 1a.3.1.1.2.1.0.0.0 +select t6a from t6 -- select 1 +join +( +select t7a as dt1a, t7b*t7c as dt1b from t7 where t7c > 4 +) dt1 on t6c = dt1a +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +and t2b <= dt1b +); +t6a +5 +6 +test 1a.3.1.1.2.1.0.0.1 +prepare s from 'select t6a from t6 -- select 1 +join +( +select t7a as dt1a, t7b*t7c as dt1b from t7 where t7c > 4 +) dt1 on t6c = dt1a +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +and t2b <= dt1b +)'; +execute s; +t6a +5 +6 +execute s; +t6a +5 +6 +deallocate prepare s; +test 1a.3.1.1.2.1.0.0.2 +select * from (select t6a from t6 -- select 1 +join +( +select t7a as dt1a, t7b*t7c as dt1b from t7 where t7c > 4 +) dt1 on t6c = dt1a +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +and t2b <= dt1b +)) dt; +t6a +5 +6 +test 1a.3.1.1.2.1.0.0.3 +create view v as select t6a from t6 -- select 1 +join +( +select t7a as dt1a, t7b*t7c as dt1b from t7 where t7c > 4 +) dt1 on t6c = dt1a +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +and t2b <= dt1b +); +select * from v; +t6a +5 +6 +select * from v; +t6a +5 +6 +drop view v; +test 1a.3.1.1.2.1.0.0.4 +with cte as (select t6a from t6 -- select 1 +join +( +select t7a as dt1a, t7b*t7c as dt1b from t7 where t7c > 4 +) dt1 on t6c = dt1a +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +and t2b <= dt1b +)) select * from cte; +t6a +5 +6 +test 1a.3.1.1.2.1.0.0.5 +create procedure p() select t6a from t6 -- select 1 +join +( +select t7a as dt1a, t7b*t7c as dt1b from t7 where t7c > 4 +) dt1 on t6c = dt1a +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +and t2b <= dt1b +); +call p(); +t6a +5 +6 +call p(); +t6a +5 +6 +drop procedure p; +"END GROUP" +test 1a.3.1.1.2.2.0.0.0 +select t6a from t6 -- select 1 +join (select t7a as dt1a, t7b*t7c as dt1b, t7b*2 as dt1c from t7 +where t7c > 4) dt1 +on t6c = dt1a +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= dt1c +) +and t2b <= dt1b +); +t6a +5 +6 +test 1a.3.1.1.2.2.0.0.1 +prepare s from 'select t6a from t6 -- select 1 +join (select t7a as dt1a, t7b*t7c as dt1b, t7b*2 as dt1c from t7 +where t7c > 4) dt1 +on t6c = dt1a +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= dt1c +) +and t2b <= dt1b +)'; +execute s; +t6a +5 +6 +execute s; +t6a +5 +6 +deallocate prepare s; +test 1a.3.1.1.2.2.0.0.2 +select * from (select t6a from t6 -- select 1 +join (select t7a as dt1a, t7b*t7c as dt1b, t7b*2 as dt1c from t7 +where t7c > 4) dt1 +on t6c = dt1a +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= dt1c +) +and t2b <= dt1b +)) dt; +t6a +5 +6 +test 1a.3.1.1.2.2.0.0.3 +create view v as select t6a from t6 -- select 1 +join (select t7a as dt1a, t7b*t7c as dt1b, t7b*2 as dt1c from t7 +where t7c > 4) dt1 +on t6c = dt1a +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= dt1c +) +and t2b <= dt1b +); +select * from v; +t6a +5 +6 +select * from v; +t6a +5 +6 +drop view v; +test 1a.3.1.1.2.2.0.0.4 +with cte as (select t6a from t6 -- select 1 +join (select t7a as dt1a, t7b*t7c as dt1b, t7b*2 as dt1c from t7 +where t7c > 4) dt1 +on t6c = dt1a +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= dt1c +) +and t2b <= dt1b +)) select * from cte; +t6a +5 +6 +test 1a.3.1.1.2.2.0.0.5 +create procedure p() select t6a from t6 -- select 1 +join (select t7a as dt1a, t7b*t7c as dt1b, t7b*2 as dt1c from t7 +where t7c > 4) dt1 +on t6c = dt1a +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= dt1c +) +and t2b <= dt1b +); +call p(); +t6a +5 +6 +call p(); +t6a +5 +6 +drop procedure p; +"END GROUP" +test 1b.2.0.0.1.0.0.0 +with cte1 (c1, c2) as (select t7a, t7b from t7 where t7c > 4) +select * from t6, cte1 +where t6a=c1 and -- select 1 +( +select max(t4a) from t4 where t4c <= c2 -- select 2 +) <> 0; +t6a t6b t6c c1 c2 +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1b.2.0.0.1.0.0.1 +prepare s from 'with cte1 (c1, c2) as (select t7a, t7b from t7 where t7c > 4) +select * from t6, cte1 +where t6a=c1 and -- select 1 +( +select max(t4a) from t4 where t4c <= c2 -- select 2 +) <> 0'; +execute s; +t6a t6b t6c c1 c2 +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +execute s; +t6a t6b t6c c1 c2 +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +deallocate prepare s; +test 1b.2.0.0.1.0.0.2 +select * from (with cte1 (c1, c2) as (select t7a, t7b from t7 where t7c > 4) +select * from t6, cte1 +where t6a=c1 and -- select 1 +( +select max(t4a) from t4 where t4c <= c2 -- select 2 +) <> 0) dt; +t6a t6b t6c c1 c2 +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1b.2.0.0.1.0.0.3 +create view v as with cte1 (c1, c2) as (select t7a, t7b from t7 where t7c > 4) +select * from t6, cte1 +where t6a=c1 and -- select 1 +( +select max(t4a) from t4 where t4c <= c2 -- select 2 +) <> 0; +select * from v; +t6a t6b t6c c1 c2 +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +select * from v; +t6a t6b t6c c1 c2 +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +drop view v; +test 1b.2.0.0.1.0.0.4 +with cte as (with cte1 (c1, c2) as (select t7a, t7b from t7 where t7c > 4) +select * from t6, cte1 +where t6a=c1 and -- select 1 +( +select max(t4a) from t4 where t4c <= c2 -- select 2 +) <> 0) select * from cte; +t6a t6b t6c c1 c2 +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1b.2.0.0.1.0.0.5 +create procedure p() with cte1 (c1, c2) as (select t7a, t7b from t7 where t7c > 4) +select * from t6, cte1 +where t6a=c1 and -- select 1 +( +select max(t4a) from t4 where t4c <= c2 -- select 2 +) <> 0; +call p(); +t6a t6b t6c c1 c2 +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +call p(); +t6a t6b t6c c1 c2 +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +drop procedure p; +"END GROUP" +test 1b.2.0.0.1.0.1.0 +with cte1 (c1, c2) as (select t7a, t7b from t7 where t7c > 4) +select * from t6, cte1 +where t6a=c1 and -- select 1 +( +select max(t4a) from t4 where -- select 2 +( +select t4c <= c2 -- select 3 +) +) <> 0; +t6a t6b t6c c1 c2 +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1b.2.0.0.1.0.1.1 +prepare s from 'with cte1 (c1, c2) as (select t7a, t7b from t7 where t7c > 4) +select * from t6, cte1 +where t6a=c1 and -- select 1 +( +select max(t4a) from t4 where -- select 2 +( +select t4c <= c2 -- select 3 +) +) <> 0'; +execute s; +t6a t6b t6c c1 c2 +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +execute s; +t6a t6b t6c c1 c2 +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +deallocate prepare s; +test 1b.2.0.0.1.0.1.2 +select * from (with cte1 (c1, c2) as (select t7a, t7b from t7 where t7c > 4) +select * from t6, cte1 +where t6a=c1 and -- select 1 +( +select max(t4a) from t4 where -- select 2 +( +select t4c <= c2 -- select 3 +) +) <> 0) dt; +t6a t6b t6c c1 c2 +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1b.2.0.0.1.0.1.3 +create view v as with cte1 (c1, c2) as (select t7a, t7b from t7 where t7c > 4) +select * from t6, cte1 +where t6a=c1 and -- select 1 +( +select max(t4a) from t4 where -- select 2 +( +select t4c <= c2 -- select 3 +) +) <> 0; +select * from v; +t6a t6b t6c c1 c2 +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +select * from v; +t6a t6b t6c c1 c2 +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +drop view v; +test 1b.2.0.0.1.0.1.4 +with cte as (with cte1 (c1, c2) as (select t7a, t7b from t7 where t7c > 4) +select * from t6, cte1 +where t6a=c1 and -- select 1 +( +select max(t4a) from t4 where -- select 2 +( +select t4c <= c2 -- select 3 +) +) <> 0) select * from cte; +t6a t6b t6c c1 c2 +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +test 1b.2.0.0.1.0.1.5 +create procedure p() with cte1 (c1, c2) as (select t7a, t7b from t7 where t7c > 4) +select * from t6, cte1 +where t6a=c1 and -- select 1 +( +select max(t4a) from t4 where -- select 2 +( +select t4c <= c2 -- select 3 +) +) <> 0; +call p(); +t6a t6b t6c c1 c2 +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +call p(); +t6a t6b t6c c1 c2 +5 5 5 5 5 +6 6 6 6 6 +7 7 7 7 7 +drop procedure p; +"END GROUP" +test 1b.3.1.1.2.1.0.0 +with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 where t7c > 4) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +and t2b <= c2 +); +t6a +5 +6 +test 1b.3.1.1.2.1.0.1 +prepare s from 'with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 where t7c > 4) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +and t2b <= c2 +)'; +execute s; +t6a +5 +6 +execute s; +t6a +5 +6 +deallocate prepare s; +test 1b.3.1.1.2.1.0.2 +select * from (with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 where t7c > 4) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +and t2b <= c2 +)) dt; +t6a +5 +6 +test 1b.3.1.1.2.1.0.3 +create view v as with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 where t7c > 4) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +and t2b <= c2 +); +select * from v; +t6a +5 +6 +select * from v; +t6a +5 +6 +drop view v; +test 1b.3.1.1.2.1.0.4 +with cte as (with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 where t7c > 4) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +and t2b <= c2 +)) select * from cte; +t6a +5 +6 +test 1b.3.1.1.2.1.0.5 +create procedure p() with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 where t7c > 4) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +and t2b <= c2 +); +call p(); +t6a +5 +6 +call p(); +t6a +5 +6 +drop procedure p; +"END GROUP" +test 1b.3.1.1.2.1.1.0 +with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +and t2b <= c2 +); +t6a +5 +6 +test 1b.3.1.1.2.1.1.1 +prepare s from 'with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +and t2b <= c2 +)'; +execute s; +t6a +5 +6 +execute s; +t6a +5 +6 +deallocate prepare s; +test 1b.3.1.1.2.1.1.2 +select * from (with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +and t2b <= c2 +)) dt; +t6a +5 +6 +test 1b.3.1.1.2.1.1.3 +create view v as with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +and t2b <= c2 +); +select * from v; +t6a +5 +6 +select * from v; +t6a +5 +6 +drop view v; +test 1b.3.1.1.2.1.1.4 +with cte as (with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +and t2b <= c2 +)) select * from cte; +t6a +5 +6 +test 1b.3.1.1.2.1.1.5 +create procedure p() with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +and t2b <= c2 +); +call p(); +t6a +5 +6 +call p(); +t6a +5 +6 +drop procedure p; +"END GROUP" +test 1b.3.1.1.2.1.2.0 +with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +) +and t2b <= c2 +); +t6a +5 +6 +test 1b.3.1.1.2.1.2.1 +prepare s from 'with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +) +and t2b <= c2 +)'; +execute s; +t6a +5 +6 +execute s; +t6a +5 +6 +deallocate prepare s; +test 1b.3.1.1.2.1.2.2 +select * from (with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +) +and t2b <= c2 +)) dt; +t6a +5 +6 +test 1b.3.1.1.2.1.2.3 +create view v as with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +) +and t2b <= c2 +); +select * from v; +t6a +5 +6 +select * from v; +t6a +5 +6 +drop view v; +test 1b.3.1.1.2.1.2.4 +with cte as (with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +) +and t2b <= c2 +)) select * from cte; +t6a +5 +6 +test 1b.3.1.1.2.1.2.5 +create procedure p() with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +) +and t2b <= c2 +); +call p(); +t6a +5 +6 +call p(); +t6a +5 +6 +drop procedure p; +"END GROUP" +test 2.1.0.0.1.0: +let with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +) +and t2b <= c2 +)= select * from t1, t2 where t1a=t2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= t2b +).0 +with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +) +and t2b <= c2 +); +t6a +5 +6 +test 2.1.0.0.1.0: +let with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +) +and t2b <= c2 +)= select * from t1, t2 where t1a=t2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= t2b +).1 +prepare s from 'with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +) +and t2b <= c2 +)'; +execute s; +t6a +5 +6 +execute s; +t6a +5 +6 +deallocate prepare s; +test 2.1.0.0.1.0: +let with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +) +and t2b <= c2 +)= select * from t1, t2 where t1a=t2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= t2b +).2 +select * from (with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +) +and t2b <= c2 +)) dt; +t6a +5 +6 +test 2.1.0.0.1.0: +let with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +) +and t2b <= c2 +)= select * from t1, t2 where t1a=t2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= t2b +).3 +create view v as with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +) +and t2b <= c2 +); +select * from v; +t6a +5 +6 +select * from v; +t6a +5 +6 +drop view v; +test 2.1.0.0.1.0: +let with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +) +and t2b <= c2 +)= select * from t1, t2 where t1a=t2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= t2b +).4 +with cte as (with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +) +and t2b <= c2 +)) select * from cte; +t6a +5 +6 +test 2.1.0.0.1.0: +let with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +) +and t2b <= c2 +)= select * from t1, t2 where t1a=t2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= t2b +).5 +create procedure p() with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 +where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 +on t6c = c1 +where t6a in +( +select t2a+3 from t2 -- select 2 +where t2b >= any +( +select t3b from t3 where -- select 3 +( +select t3c <= t6b -- select 3 +and t3a <= t6c and t3b <= t6a +) +) +and t2b <= c2 +); +call p(); +t6a +5 +6 +call p(); +t6a +5 +6 +drop procedure p; +"END GROUP" +test 2.1.0.0.1.1.0.0.0 +select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= v2b +); +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +test 2.1.0.0.1.1.0.0.1 +prepare s from 'select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= v2b +)'; +execute s; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +execute s; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +deallocate prepare s; +test 2.1.0.0.1.1.0.0.2 +select * from (select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= v2b +)) dt; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +test 2.1.0.0.1.1.0.0.3 +create view v as select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= v2b +); +select * from v; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +select * from v; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +drop view v; +test 2.1.0.0.1.1.0.0.4 +with cte as (select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= v2b +)) select * from cte; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +test 2.1.0.0.1.1.0.0.5 +create procedure p() select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= v2b +); +call p(); +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +call p(); +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +drop procedure p; +"END GROUP" +test 2.1.0.0.1.1.0.1.0 +select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where +( +select t3b <= v2b +) +); +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +test 2.1.0.0.1.1.0.1.1 +prepare s from 'select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where +( +select t3b <= v2b +) +)'; +execute s; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +execute s; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +deallocate prepare s; +test 2.1.0.0.1.1.0.1.2 +select * from (select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where +( +select t3b <= v2b +) +)) dt; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +test 2.1.0.0.1.1.0.1.3 +create view v as select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where +( +select t3b <= v2b +) +); +select * from v; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +select * from v; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +drop view v; +test 2.1.0.0.1.1.0.1.4 +with cte as (select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where +( +select t3b <= v2b +) +)) select * from cte; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +test 2.1.0.0.1.1.0.1.5 +create procedure p() select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where +( +select t3b <= v2b +) +); +call p(); +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +call p(); +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +drop procedure p; +"END GROUP" +test 2.1.0.0.1.1.0.2.0 +select * from t1, v2 where -- select 1 +( +select t1a<=v2a -- select 2 +) +and t1b in +( +select t3b from t3 -- select 3 +where +( +select t3b <= v2b +) +); +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +test 2.1.0.0.1.1.0.2.1 +prepare s from 'select * from t1, v2 where -- select 1 +( +select t1a<=v2a -- select 2 +) +and t1b in +( +select t3b from t3 -- select 3 +where +( +select t3b <= v2b +) +)'; +execute s; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +execute s; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +deallocate prepare s; +test 2.1.0.0.1.1.0.2.2 +select * from (select * from t1, v2 where -- select 1 +( +select t1a<=v2a -- select 2 +) +and t1b in +( +select t3b from t3 -- select 3 +where +( +select t3b <= v2b +) +)) dt; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +test 2.1.0.0.1.1.0.2.3 +create view v as select * from t1, v2 where -- select 1 +( +select t1a<=v2a -- select 2 +) +and t1b in +( +select t3b from t3 -- select 3 +where +( +select t3b <= v2b +) +); +select * from v; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +select * from v; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +drop view v; +test 2.1.0.0.1.1.0.2.4 +with cte as (select * from t1, v2 where -- select 1 +( +select t1a<=v2a -- select 2 +) +and t1b in +( +select t3b from t3 -- select 3 +where +( +select t3b <= v2b +) +)) select * from cte; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +test 2.1.0.0.1.1.0.2.5 +create procedure p() select * from t1, v2 where -- select 1 +( +select t1a<=v2a -- select 2 +) +and t1b in +( +select t3b from t3 -- select 3 +where +( +select t3b <= v2b +) +); +call p(); +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +call p(); +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +drop procedure p; +"END GROUP" +test 2.0.1.1.1.0.0.0.0 +select * from t1 -- select 2 +where t1c in +( +select t2a from t2 -- select 3 +where t2b in (select t3b from t3 where t3a >= t2c) -- select 4 +); +t1a t1b t1c +1 1 1 +2 2 2 +test 2.0.1.1.1.0.0.0.1 +prepare s from 'select * from t1 -- select 2 +where t1c in +( +select t2a from t2 -- select 3 +where t2b in (select t3b from t3 where t3a >= t2c) -- select 4 +)'; +execute s; +t1a t1b t1c +1 1 1 +2 2 2 +execute s; +t1a t1b t1c +1 1 1 +2 2 2 +deallocate prepare s; +test 2.0.1.1.1.0.0.0.2 +select * from (select * from t1 -- select 2 +where t1c in +( +select t2a from t2 -- select 3 +where t2b in (select t3b from t3 where t3a >= t2c) -- select 4 +)) dt; +t1a t1b t1c +1 1 1 +2 2 2 +test 2.0.1.1.1.0.0.0.3 +create view v as select * from t1 -- select 2 +where t1c in +( +select t2a from t2 -- select 3 +where t2b in (select t3b from t3 where t3a >= t2c) -- select 4 +); +select * from v; +t1a t1b t1c +1 1 1 +2 2 2 +select * from v; +t1a t1b t1c +1 1 1 +2 2 2 +drop view v; +test 2.0.1.1.1.0.0.0.4 +with cte as (select * from t1 -- select 2 +where t1c in +( +select t2a from t2 -- select 3 +where t2b in (select t3b from t3 where t3a >= t2c) -- select 4 +)) select * from cte; +t1a t1b t1c +1 1 1 +2 2 2 +test 2.0.1.1.1.0.0.0.5 +create procedure p() select * from t1 -- select 2 +where t1c in +( +select t2a from t2 -- select 3 +where t2b in (select t3b from t3 where t3a >= t2c) -- select 4 +); +call p(); +t1a t1b t1c +1 1 1 +2 2 2 +call p(); +t1a t1b t1c +1 1 1 +2 2 2 +drop procedure p; +"END GROUP" +test 2.0.1.1.1.0.0.1.0 +select * from t1 +where t1c in +( +select t2a from t2 +where t2b in +( +select t3b from t3 where +( +select t3a >= t2c +) +) +); +t1a t1b t1c +1 1 1 +2 2 2 +test 2.0.1.1.1.0.0.1.1 +prepare s from 'select * from t1 +where t1c in +( +select t2a from t2 +where t2b in +( +select t3b from t3 where +( +select t3a >= t2c +) +) +)'; +execute s; +t1a t1b t1c +1 1 1 +2 2 2 +execute s; +t1a t1b t1c +1 1 1 +2 2 2 +deallocate prepare s; +test 2.0.1.1.1.0.0.1.2 +select * from (select * from t1 +where t1c in +( +select t2a from t2 +where t2b in +( +select t3b from t3 where +( +select t3a >= t2c +) +) +)) dt; +t1a t1b t1c +1 1 1 +2 2 2 +test 2.0.1.1.1.0.0.1.3 +create view v as select * from t1 +where t1c in +( +select t2a from t2 +where t2b in +( +select t3b from t3 where +( +select t3a >= t2c +) +) +); +select * from v; +t1a t1b t1c +1 1 1 +2 2 2 +select * from v; +t1a t1b t1c +1 1 1 +2 2 2 +drop view v; +test 2.0.1.1.1.0.0.1.4 +with cte as (select * from t1 +where t1c in +( +select t2a from t2 +where t2b in +( +select t3b from t3 where +( +select t3a >= t2c +) +) +)) select * from cte; +t1a t1b t1c +1 1 1 +2 2 2 +test 2.0.1.1.1.0.0.1.5 +create procedure p() select * from t1 +where t1c in +( +select t2a from t2 +where t2b in +( +select t3b from t3 where +( +select t3a >= t2c +) +) +); +call p(); +t1a t1b t1c +1 1 1 +2 2 2 +call p(); +t1a t1b t1c +1 1 1 +2 2 2 +drop procedure p; +"END GROUP" +test 2.1.0.0.1.2.0.0.0 +select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= v2b and t3a <= v2a +); +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +test 2.1.0.0.1.2.0.0.1 +prepare s from 'select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= v2b and t3a <= v2a +)'; +execute s; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +execute s; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +deallocate prepare s; +test 2.1.0.0.1.2.0.0.2 +select * from (select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= v2b and t3a <= v2a +)) dt; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +test 2.1.0.0.1.2.0.0.3 +create view v as select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= v2b and t3a <= v2a +); +select * from v; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +select * from v; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +drop view v; +test 2.1.0.0.1.2.0.0.4 +with cte as (select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= v2b and t3a <= v2a +)) select * from cte; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +test 2.1.0.0.1.2.0.0.5 +create procedure p() select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= v2b and t3a <= v2a +); +call p(); +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +call p(); +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +drop procedure p; +"END GROUP" +test 2.1.0.0.1.2.0.1.0 +select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where +( +select t3b <= v2b and t3a <= v2a +) +); +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +test 2.1.0.0.1.2.0.1.1 +prepare s from 'select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where +( +select t3b <= v2b and t3a <= v2a +) +)'; +execute s; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +execute s; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +deallocate prepare s; +test 2.1.0.0.1.2.0.1.2 +select * from (select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where +( +select t3b <= v2b and t3a <= v2a +) +)) dt; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +test 2.1.0.0.1.2.0.1.3 +create view v as select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where +( +select t3b <= v2b and t3a <= v2a +) +); +select * from v; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +select * from v; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +drop view v; +test 2.1.0.0.1.2.0.1.4 +with cte as (select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where +( +select t3b <= v2b and t3a <= v2a +) +)) select * from cte; +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +test 2.1.0.0.1.2.0.1.5 +create procedure p() select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where +( +select t3b <= v2b and t3a <= v2a +) +); +call p(); +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +call p(); +t1a t1b t1c v2a v2b +1 1 1 25 25 +1 1 1 36 36 +2 2 2 25 25 +2 2 2 36 36 +drop procedure p; +"END GROUP" +test 2.2.0.0.1.0.0.0.0 +select * from t1, t2 where t1a=t2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= t1a*t2a +); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 2 2 2 +test 2.2.0.0.1.0.0.0.1 +prepare s from 'select * from t1, t2 where t1a=t2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= t1a*t2a +)'; +execute s; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 2 2 2 +execute s; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 2 2 2 +deallocate prepare s; +test 2.2.0.0.1.0.0.0.2 +select * from (select * from t1, t2 where t1a=t2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= t1a*t2a +)) dt; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 2 2 2 +test 2.2.0.0.1.0.0.0.3 +create view v as select * from t1, t2 where t1a=t2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= t1a*t2a +); +select * from v; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 2 2 2 +select * from v; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 2 2 2 +drop view v; +test 2.2.0.0.1.0.0.0.4 +with cte as (select * from t1, t2 where t1a=t2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= t1a*t2a +)) select * from cte; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 2 2 2 +test 2.2.0.0.1.0.0.0.5 +create procedure p() select * from t1, t2 where t1a=t2a and t1b in -- select 1 +( +select t3b from t3 -- select 2 +where t3b <= t1a*t2a +); +call p(); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 2 2 2 +call p(); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 2 2 2 +drop procedure p; +"END GROUP" +test 2.1.1.0.2.0.0.0.0 +select * from t6, t7 where t6a=t7a and t6b in -- select 1 +( +select t2b from t2 where -- select 2 +( +select max(t4a) from t4, t5 -- select 3 +where t5a = t4a and t4c < t7b and t5b < t2b +) <> 0 +); +t6a t6b t6c t7a t7b t7c +2 2 2 2 2 2 +3 3 3 3 3 3 +test 2.1.1.0.2.0.0.0.1 +prepare s from 'select * from t6, t7 where t6a=t7a and t6b in -- select 1 +( +select t2b from t2 where -- select 2 +( +select max(t4a) from t4, t5 -- select 3 +where t5a = t4a and t4c < t7b and t5b < t2b +) <> 0 +)'; +execute s; +t6a t6b t6c t7a t7b t7c +2 2 2 2 2 2 +3 3 3 3 3 3 +execute s; +t6a t6b t6c t7a t7b t7c +2 2 2 2 2 2 +3 3 3 3 3 3 +deallocate prepare s; +test 2.1.1.0.2.0.0.0.2 +select * from (select * from t6, t7 where t6a=t7a and t6b in -- select 1 +( +select t2b from t2 where -- select 2 +( +select max(t4a) from t4, t5 -- select 3 +where t5a = t4a and t4c < t7b and t5b < t2b +) <> 0 +)) dt; +t6a t6b t6c t7a t7b t7c +2 2 2 2 2 2 +3 3 3 3 3 3 +test 2.1.1.0.2.0.0.0.3 +create view v as select * from t6, t7 where t6a=t7a and t6b in -- select 1 +( +select t2b from t2 where -- select 2 +( +select max(t4a) from t4, t5 -- select 3 +where t5a = t4a and t4c < t7b and t5b < t2b +) <> 0 +); +select * from v; +t6a t6b t6c t7a t7b t7c +2 2 2 2 2 2 +3 3 3 3 3 3 +select * from v; +t6a t6b t6c t7a t7b t7c +2 2 2 2 2 2 +3 3 3 3 3 3 +drop view v; +test 2.1.1.0.2.0.0.0.4 +with cte as (select * from t6, t7 where t6a=t7a and t6b in -- select 1 +( +select t2b from t2 where -- select 2 +( +select max(t4a) from t4, t5 -- select 3 +where t5a = t4a and t4c < t7b and t5b < t2b +) <> 0 +)) select * from cte; +t6a t6b t6c t7a t7b t7c +2 2 2 2 2 2 +3 3 3 3 3 3 +test 2.1.1.0.2.0.0.0.5 +create procedure p() select * from t6, t7 where t6a=t7a and t6b in -- select 1 +( +select t2b from t2 where -- select 2 +( +select max(t4a) from t4, t5 -- select 3 +where t5a = t4a and t4c < t7b and t5b < t2b +) <> 0 +); +call p(); +t6a t6b t6c t7a t7b t7c +2 2 2 2 2 2 +3 3 3 3 3 3 +call p(); +t6a t6b t6c t7a t7b t7c +2 2 2 2 2 2 +3 3 3 3 3 3 +drop procedure p; +"END GROUP" +test 2.2.1.0.2.0.0.0.0 +select * from t6, t7 where t6a=t7a and t6b in -- select 1 +( +select t2b from t2 where -- select 2 +( +select max(t4a) from t4, t5 -- select 3 +where t5a = t4a and t4c < t7b and t5b < t2b*t6a +) <> 0 +); +t6a t6b t6c t7a t7b t7c +2 2 2 2 2 2 +3 3 3 3 3 3 +test 2.2.1.0.2.0.0.0.1 +prepare s from 'select * from t6, t7 where t6a=t7a and t6b in -- select 1 +( +select t2b from t2 where -- select 2 +( +select max(t4a) from t4, t5 -- select 3 +where t5a = t4a and t4c < t7b and t5b < t2b*t6a +) <> 0 +)'; +execute s; +t6a t6b t6c t7a t7b t7c +2 2 2 2 2 2 +3 3 3 3 3 3 +execute s; +t6a t6b t6c t7a t7b t7c +2 2 2 2 2 2 +3 3 3 3 3 3 +deallocate prepare s; +test 2.2.1.0.2.0.0.0.2 +select * from (select * from t6, t7 where t6a=t7a and t6b in -- select 1 +( +select t2b from t2 where -- select 2 +( +select max(t4a) from t4, t5 -- select 3 +where t5a = t4a and t4c < t7b and t5b < t2b*t6a +) <> 0 +)) dt; +t6a t6b t6c t7a t7b t7c +2 2 2 2 2 2 +3 3 3 3 3 3 +test 2.2.1.0.2.0.0.0.3 +create view v as select * from t6, t7 where t6a=t7a and t6b in -- select 1 +( +select t2b from t2 where -- select 2 +( +select max(t4a) from t4, t5 -- select 3 +where t5a = t4a and t4c < t7b and t5b < t2b*t6a +) <> 0 +); +select * from v; +t6a t6b t6c t7a t7b t7c +2 2 2 2 2 2 +3 3 3 3 3 3 +select * from v; +t6a t6b t6c t7a t7b t7c +2 2 2 2 2 2 +3 3 3 3 3 3 +drop view v; +test 2.2.1.0.2.0.0.0.4 +with cte as (select * from t6, t7 where t6a=t7a and t6b in -- select 1 +( +select t2b from t2 where -- select 2 +( +select max(t4a) from t4, t5 -- select 3 +where t5a = t4a and t4c < t7b and t5b < t2b*t6a +) <> 0 +)) select * from cte; +t6a t6b t6c t7a t7b t7c +2 2 2 2 2 2 +3 3 3 3 3 3 +test 2.2.1.0.2.0.0.0.5 +create procedure p() select * from t6, t7 where t6a=t7a and t6b in -- select 1 +( +select t2b from t2 where -- select 2 +( +select max(t4a) from t4, t5 -- select 3 +where t5a = t4a and t4c < t7b and t5b < t2b*t6a +) <> 0 +); +call p(); +t6a t6b t6c t7a t7b t7c +2 2 2 2 2 2 +3 3 3 3 3 3 +call p(); +t6a t6b t6c t7a t7b t7c +2 2 2 2 2 2 +3 3 3 3 3 3 +drop procedure p; +"END GROUP" +test 3.2.0.0.2.0.0.0.0 +select * from t1, t2 -- select #1, parent +where +t1a in +( +select t3b from t3 -- select #2, merged +where 10 > +( +select count(*) from t4 where t4b < t1a -- select #3 +) +) +and +t2a in +( +select t5c from t5 -- select #4, merged +where 10 > +( +select count(*) from t6 where t6b < t2a -- select #5 +) +); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +test 3.2.0.0.2.0.0.0.1 +prepare s from 'select * from t1, t2 -- select #1, parent +where +t1a in +( +select t3b from t3 -- select #2, merged +where 10 > +( +select count(*) from t4 where t4b < t1a -- select #3 +) +) +and +t2a in +( +select t5c from t5 -- select #4, merged +where 10 > +( +select count(*) from t6 where t6b < t2a -- select #5 +) +)'; +execute s; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +execute s; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +deallocate prepare s; +test 3.2.0.0.2.0.0.0.2 +select * from (select * from t1, t2 -- select #1, parent +where +t1a in +( +select t3b from t3 -- select #2, merged +where 10 > +( +select count(*) from t4 where t4b < t1a -- select #3 +) +) +and +t2a in +( +select t5c from t5 -- select #4, merged +where 10 > +( +select count(*) from t6 where t6b < t2a -- select #5 +) +)) dt; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +test 3.2.0.0.2.0.0.0.3 +create view v as select * from t1, t2 -- select #1, parent +where +t1a in +( +select t3b from t3 -- select #2, merged +where 10 > +( +select count(*) from t4 where t4b < t1a -- select #3 +) +) +and +t2a in +( +select t5c from t5 -- select #4, merged +where 10 > +( +select count(*) from t6 where t6b < t2a -- select #5 +) +); +select * from v; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +select * from v; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +drop view v; +test 3.2.0.0.2.0.0.0.4 +with cte as (select * from t1, t2 -- select #1, parent +where +t1a in +( +select t3b from t3 -- select #2, merged +where 10 > +( +select count(*) from t4 where t4b < t1a -- select #3 +) +) +and +t2a in +( +select t5c from t5 -- select #4, merged +where 10 > +( +select count(*) from t6 where t6b < t2a -- select #5 +) +)) select * from cte; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +test 3.2.0.0.2.0.0.0.5 +create procedure p() select * from t1, t2 -- select #1, parent +where +t1a in +( +select t3b from t3 -- select #2, merged +where 10 > +( +select count(*) from t4 where t4b < t1a -- select #3 +) +) +and +t2a in +( +select t5c from t5 -- select #4, merged +where 10 > +( +select count(*) from t6 where t6b < t2a -- select #5 +) +); +call p(); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +call p(); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +drop procedure p; +"END GROUP" +test 3.2.0.0.2.0.0.2.0 +select * from t1, t2 -- select #1, parent +where +t1a in +( +select t3b from t3 -- select #2, merged +where 10 > +( +select count(*) from t4 where -- select #3 +( +select t4b < t1a -- select #4 +) +) +) +and +t2a in +( +select t5c from t5 -- select #5, merged +where 10 > +( +select count(*) from t6 where -- select #5 +( +select t6b < t2a -- select #6 +) +) +); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +test 3.2.0.0.2.0.0.2.1 +prepare s from 'select * from t1, t2 -- select #1, parent +where +t1a in +( +select t3b from t3 -- select #2, merged +where 10 > +( +select count(*) from t4 where -- select #3 +( +select t4b < t1a -- select #4 +) +) +) +and +t2a in +( +select t5c from t5 -- select #5, merged +where 10 > +( +select count(*) from t6 where -- select #5 +( +select t6b < t2a -- select #6 +) +) +)'; +execute s; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +execute s; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +deallocate prepare s; +test 3.2.0.0.2.0.0.2.2 +select * from (select * from t1, t2 -- select #1, parent +where +t1a in +( +select t3b from t3 -- select #2, merged +where 10 > +( +select count(*) from t4 where -- select #3 +( +select t4b < t1a -- select #4 +) +) +) +and +t2a in +( +select t5c from t5 -- select #5, merged +where 10 > +( +select count(*) from t6 where -- select #5 +( +select t6b < t2a -- select #6 +) +) +)) dt; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +test 3.2.0.0.2.0.0.2.3 +create view v as select * from t1, t2 -- select #1, parent +where +t1a in +( +select t3b from t3 -- select #2, merged +where 10 > +( +select count(*) from t4 where -- select #3 +( +select t4b < t1a -- select #4 +) +) +) +and +t2a in +( +select t5c from t5 -- select #5, merged +where 10 > +( +select count(*) from t6 where -- select #5 +( +select t6b < t2a -- select #6 +) +) +); +select * from v; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +select * from v; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +drop view v; +test 3.2.0.0.2.0.0.2.4 +with cte as (select * from t1, t2 -- select #1, parent +where +t1a in +( +select t3b from t3 -- select #2, merged +where 10 > +( +select count(*) from t4 where -- select #3 +( +select t4b < t1a -- select #4 +) +) +) +and +t2a in +( +select t5c from t5 -- select #5, merged +where 10 > +( +select count(*) from t6 where -- select #5 +( +select t6b < t2a -- select #6 +) +) +)) select * from cte; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +test 3.2.0.0.2.0.0.2.5 +create procedure p() select * from t1, t2 -- select #1, parent +where +t1a in +( +select t3b from t3 -- select #2, merged +where 10 > +( +select count(*) from t4 where -- select #3 +( +select t4b < t1a -- select #4 +) +) +) +and +t2a in +( +select t5c from t5 -- select #5, merged +where 10 > +( +select count(*) from t6 where -- select #5 +( +select t6b < t2a -- select #6 +) +) +); +call p(); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +call p(); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +drop procedure p; +"END GROUP" +test 3a.2.0.0.2.0.0.0.0 +select * from t1, t2 -- select #1, parent +where +t1a in +( +select t3b from t3 -- select #2, merged +where 10 > +( +select count(t3c) from t4 where t4b < t1a -- select #3 +) +) +and +t2a in +( +select t5c from t5 -- select #4, merged +where 10 > +( +select count(t5a) from t6 where t6b < t2a -- select #5 +) +); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +test 3a.2.0.0.2.0.0.0.1 +prepare s from 'select * from t1, t2 -- select #1, parent +where +t1a in +( +select t3b from t3 -- select #2, merged +where 10 > +( +select count(t3c) from t4 where t4b < t1a -- select #3 +) +) +and +t2a in +( +select t5c from t5 -- select #4, merged +where 10 > +( +select count(t5a) from t6 where t6b < t2a -- select #5 +) +)'; +execute s; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +execute s; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +deallocate prepare s; +test 3a.2.0.0.2.0.0.0.2 +select * from (select * from t1, t2 -- select #1, parent +where +t1a in +( +select t3b from t3 -- select #2, merged +where 10 > +( +select count(t3c) from t4 where t4b < t1a -- select #3 +) +) +and +t2a in +( +select t5c from t5 -- select #4, merged +where 10 > +( +select count(t5a) from t6 where t6b < t2a -- select #5 +) +)) dt; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +test 3a.2.0.0.2.0.0.0.3 +create view v as select * from t1, t2 -- select #1, parent +where +t1a in +( +select t3b from t3 -- select #2, merged +where 10 > +( +select count(t3c) from t4 where t4b < t1a -- select #3 +) +) +and +t2a in +( +select t5c from t5 -- select #4, merged +where 10 > +( +select count(t5a) from t6 where t6b < t2a -- select #5 +) +); +select * from v; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +select * from v; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +drop view v; +test 3a.2.0.0.2.0.0.0.4 +with cte as (select * from t1, t2 -- select #1, parent +where +t1a in +( +select t3b from t3 -- select #2, merged +where 10 > +( +select count(t3c) from t4 where t4b < t1a -- select #3 +) +) +and +t2a in +( +select t5c from t5 -- select #4, merged +where 10 > +( +select count(t5a) from t6 where t6b < t2a -- select #5 +) +)) select * from cte; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +test 3a.2.0.0.2.0.0.0.5 +create procedure p() select * from t1, t2 -- select #1, parent +where +t1a in +( +select t3b from t3 -- select #2, merged +where 10 > +( +select count(t3c) from t4 where t4b < t1a -- select #3 +) +) +and +t2a in +( +select t5c from t5 -- select #4, merged +where 10 > +( +select count(t5a) from t6 where t6b < t2a -- select #5 +) +); +call p(); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +call p(); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +drop procedure p; +"END GROUP" +test 3.2.0.0.2.2.0.0.0 +select * from v1, v2 -- select #1 +where +v1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where t4b < v1a -- select #3 +) +) +and +v2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(*) from t6 where t6b < v2a -- select #5 +) +); +v1a v1b v2a v2b +5 5 25 25 +6 6 25 25 +5 5 36 36 +6 6 36 36 +test 3.2.0.0.2.2.0.0.1 +prepare s from 'select * from v1, v2 -- select #1 +where +v1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where t4b < v1a -- select #3 +) +) +and +v2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(*) from t6 where t6b < v2a -- select #5 +) +)'; +execute s; +v1a v1b v2a v2b +5 5 25 25 +6 6 25 25 +5 5 36 36 +6 6 36 36 +execute s; +v1a v1b v2a v2b +5 5 25 25 +6 6 25 25 +5 5 36 36 +6 6 36 36 +deallocate prepare s; +test 3.2.0.0.2.2.0.0.2 +select * from (select * from v1, v2 -- select #1 +where +v1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where t4b < v1a -- select #3 +) +) +and +v2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(*) from t6 where t6b < v2a -- select #5 +) +)) dt; +v1a v1b v2a v2b +5 5 25 25 +6 6 25 25 +5 5 36 36 +6 6 36 36 +test 3.2.0.0.2.2.0.0.3 +create view v as select * from v1, v2 -- select #1 +where +v1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where t4b < v1a -- select #3 +) +) +and +v2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(*) from t6 where t6b < v2a -- select #5 +) +); +select * from v; +v1a v1b v2a v2b +5 5 25 25 +6 6 25 25 +5 5 36 36 +6 6 36 36 +select * from v; +v1a v1b v2a v2b +5 5 25 25 +6 6 25 25 +5 5 36 36 +6 6 36 36 +drop view v; +test 3.2.0.0.2.2.0.0.4 +with cte as (select * from v1, v2 -- select #1 +where +v1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where t4b < v1a -- select #3 +) +) +and +v2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(*) from t6 where t6b < v2a -- select #5 +) +)) select * from cte; +v1a v1b v2a v2b +5 5 25 25 +6 6 25 25 +5 5 36 36 +6 6 36 36 +test 3.2.0.0.2.2.0.0.5 +create procedure p() select * from v1, v2 -- select #1 +where +v1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where t4b < v1a -- select #3 +) +) +and +v2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(*) from t6 where t6b < v2a -- select #5 +) +); +call p(); +v1a v1b v2a v2b +5 5 25 25 +6 6 25 25 +5 5 36 36 +6 6 36 36 +call p(); +v1a v1b v2a v2b +5 5 25 25 +6 6 25 25 +5 5 36 36 +6 6 36 36 +drop procedure p; +"END GROUP" +test 3a.2.0.0.2.0.0.0.0 +select * from t1, t2 -- select #1 +where +t1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where t4b < t1a -- select #3 +) +) +or +t2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(*) from t6 where t6b < t2a -- select #5 +) +); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +test 3a.2.0.0.2.0.0.0.1 +prepare s from 'select * from t1, t2 -- select #1 +where +t1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where t4b < t1a -- select #3 +) +) +or +t2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(*) from t6 where t6b < t2a -- select #5 +) +)'; +execute s; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +execute s; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +deallocate prepare s; +test 3a.2.0.0.2.0.0.0.2 +select * from (select * from t1, t2 -- select #1 +where +t1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where t4b < t1a -- select #3 +) +) +or +t2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(*) from t6 where t6b < t2a -- select #5 +) +)) dt; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +test 3a.2.0.0.2.0.0.0.3 +create view v as select * from t1, t2 -- select #1 +where +t1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where t4b < t1a -- select #3 +) +) +or +t2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(*) from t6 where t6b < t2a -- select #5 +) +); +select * from v; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +select * from v; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +drop view v; +test 3a.2.0.0.2.0.0.0.4 +with cte as (select * from t1, t2 -- select #1 +where +t1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where t4b < t1a -- select #3 +) +) +or +t2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(*) from t6 where t6b < t2a -- select #5 +) +)) select * from cte; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +test 3a.2.0.0.2.0.0.0.5 +create procedure p() select * from t1, t2 -- select #1 +where +t1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where t4b < t1a -- select #3 +) +) +or +t2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(*) from t6 where t6b < t2a -- select #5 +) +); +call p(); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +call p(); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +drop procedure p; +"END GROUP" +test 3a.2.0.0.2.0.0.2.0 +select * from t1, t2 -- select #1 +where +t1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where -- select #3 +( +select t4b < t1a -- select #4 +) +) +) +or +t2a in +( +select t7c*t7a from t7 -- select #5 +where 100 > +( +select count(*) from t6 where -- select #6 +( +select t6b < t2a -- select #7 +) +) +); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +test 3a.2.0.0.2.0.0.2.1 +prepare s from 'select * from t1, t2 -- select #1 +where +t1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where -- select #3 +( +select t4b < t1a -- select #4 +) +) +) +or +t2a in +( +select t7c*t7a from t7 -- select #5 +where 100 > +( +select count(*) from t6 where -- select #6 +( +select t6b < t2a -- select #7 +) +) +)'; +execute s; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +execute s; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +deallocate prepare s; +test 3a.2.0.0.2.0.0.2.2 +select * from (select * from t1, t2 -- select #1 +where +t1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where -- select #3 +( +select t4b < t1a -- select #4 +) +) +) +or +t2a in +( +select t7c*t7a from t7 -- select #5 +where 100 > +( +select count(*) from t6 where -- select #6 +( +select t6b < t2a -- select #7 +) +) +)) dt; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +test 3a.2.0.0.2.0.0.2.3 +create view v as select * from t1, t2 -- select #1 +where +t1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where -- select #3 +( +select t4b < t1a -- select #4 +) +) +) +or +t2a in +( +select t7c*t7a from t7 -- select #5 +where 100 > +( +select count(*) from t6 where -- select #6 +( +select t6b < t2a -- select #7 +) +) +); +select * from v; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +select * from v; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +drop view v; +test 3a.2.0.0.2.0.0.2.4 +with cte as (select * from t1, t2 -- select #1 +where +t1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where -- select #3 +( +select t4b < t1a -- select #4 +) +) +) +or +t2a in +( +select t7c*t7a from t7 -- select #5 +where 100 > +( +select count(*) from t6 where -- select #6 +( +select t6b < t2a -- select #7 +) +) +)) select * from cte; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +test 3a.2.0.0.2.0.0.2.5 +create procedure p() select * from t1, t2 -- select #1 +where +t1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where -- select #3 +( +select t4b < t1a -- select #4 +) +) +) +or +t2a in +( +select t7c*t7a from t7 -- select #5 +where 100 > +( +select count(*) from t6 where -- select #6 +( +select t6b < t2a -- select #7 +) +) +); +call p(); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +call p(); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +drop procedure p; +"END GROUP" +test 3b.2.0.0.2.0.0.0.0 +select * from t1, t2 -- select #1 +where +t1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(t5a) from t4 where t4b < t1a -- select #3 +) +) +or +t2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(t7b) from t6 where t6b < t2a -- select #5 +) +); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +test 3b.2.0.0.2.0.0.0.1 +prepare s from 'select * from t1, t2 -- select #1 +where +t1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(t5a) from t4 where t4b < t1a -- select #3 +) +) +or +t2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(t7b) from t6 where t6b < t2a -- select #5 +) +)'; +execute s; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +execute s; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +deallocate prepare s; +test 3b.2.0.0.2.0.0.0.2 +select * from (select * from t1, t2 -- select #1 +where +t1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(t5a) from t4 where t4b < t1a -- select #3 +) +) +or +t2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(t7b) from t6 where t6b < t2a -- select #5 +) +)) dt; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +test 3b.2.0.0.2.0.0.0.3 +create view v as select * from t1, t2 -- select #1 +where +t1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(t5a) from t4 where t4b < t1a -- select #3 +) +) +or +t2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(t7b) from t6 where t6b < t2a -- select #5 +) +); +select * from v; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +select * from v; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +drop view v; +test 3b.2.0.0.2.0.0.0.4 +with cte as (select * from t1, t2 -- select #1 +where +t1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(t5a) from t4 where t4b < t1a -- select #3 +) +) +or +t2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(t7b) from t6 where t6b < t2a -- select #5 +) +)) select * from cte; +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +test 3b.2.0.0.2.0.0.0.5 +create procedure p() select * from t1, t2 -- select #1 +where +t1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(t5a) from t4 where t4b < t1a -- select #3 +) +) +or +t2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(t7b) from t6 where t6b < t2a -- select #5 +) +); +call p(); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +call p(); +t1a t1b t1c t2a t2b t2c +1 1 1 1 1 1 +2 2 2 1 1 1 +1 1 1 2 2 2 +2 2 2 2 2 2 +1 1 1 3 3 3 +2 2 2 3 3 3 +drop procedure p; +"END GROUP" +test 3a.2.0.0.2.2.0.0.0 +select * from v1, v2 -- select #1 +where +v1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where t4b < v1a -- select #3 +) +) +or +v2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(*) from t6 where t6b < v2a -- select #5 +) +); +v1a v1b v2a v2b +5 5 25 25 +6 6 25 25 +7 7 25 25 +8 8 25 25 +5 5 36 36 +6 6 36 36 +7 7 36 36 +8 8 36 36 +test 3a.2.0.0.2.2.0.0.1 +prepare s from 'select * from v1, v2 -- select #1 +where +v1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where t4b < v1a -- select #3 +) +) +or +v2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(*) from t6 where t6b < v2a -- select #5 +) +)'; +execute s; +v1a v1b v2a v2b +5 5 25 25 +6 6 25 25 +7 7 25 25 +8 8 25 25 +5 5 36 36 +6 6 36 36 +7 7 36 36 +8 8 36 36 +execute s; +v1a v1b v2a v2b +5 5 25 25 +6 6 25 25 +7 7 25 25 +8 8 25 25 +5 5 36 36 +6 6 36 36 +7 7 36 36 +8 8 36 36 +deallocate prepare s; +test 3a.2.0.0.2.2.0.0.2 +select * from (select * from v1, v2 -- select #1 +where +v1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where t4b < v1a -- select #3 +) +) +or +v2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(*) from t6 where t6b < v2a -- select #5 +) +)) dt; +v1a v1b v2a v2b +5 5 25 25 +6 6 25 25 +7 7 25 25 +8 8 25 25 +5 5 36 36 +6 6 36 36 +7 7 36 36 +8 8 36 36 +test 3a.2.0.0.2.2.0.0.3 +create view v as select * from v1, v2 -- select #1 +where +v1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where t4b < v1a -- select #3 +) +) +or +v2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(*) from t6 where t6b < v2a -- select #5 +) +); +select * from v; +v1a v1b v2a v2b +5 5 25 25 +6 6 25 25 +7 7 25 25 +8 8 25 25 +5 5 36 36 +6 6 36 36 +7 7 36 36 +8 8 36 36 +select * from v; +v1a v1b v2a v2b +5 5 25 25 +6 6 25 25 +7 7 25 25 +8 8 25 25 +5 5 36 36 +6 6 36 36 +7 7 36 36 +8 8 36 36 +drop view v; +test 3a.2.0.0.2.2.0.0.4 +with cte as (select * from v1, v2 -- select #1 +where +v1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where t4b < v1a -- select #3 +) +) +or +v2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(*) from t6 where t6b < v2a -- select #5 +) +)) select * from cte; +v1a v1b v2a v2b +5 5 25 25 +6 6 25 25 +7 7 25 25 +8 8 25 25 +5 5 36 36 +6 6 36 36 +7 7 36 36 +8 8 36 36 +test 3a.2.0.0.2.2.0.0.5 +create procedure p() select * from v1, v2 -- select #1 +where +v1a in +( +select t5b from t5 -- select #2 +where 100 > +( +select count(*) from t4 where t4b < v1a -- select #3 +) +) +or +v2a in +( +select t7c*t7a from t7 -- select #4 +where 100 > +( +select count(*) from t6 where t6b < v2a -- select #5 +) +); +call p(); +v1a v1b v2a v2b +5 5 25 25 +6 6 25 25 +7 7 25 25 +8 8 25 25 +5 5 36 36 +6 6 36 36 +7 7 36 36 +8 8 36 36 +call p(); +v1a v1b v2a v2b +5 5 25 25 +6 6 25 25 +7 7 25 25 +8 8 25 25 +5 5 36 36 +6 6 36 36 +7 7 36 36 +8 8 36 36 +drop procedure p; +"END GROUP" +test 4.1.1.0.4.0.0.0.0 +select t1a from t1 -- select 1, parent +where t1a in +( +select t2c from t2 where t2a >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, parent +( +select t4a from t4 where t4b > t2c -- select 4, child +) +union +select t5a from t5 where t5b in -- select 5, parent +( +select t6a from t6 where t6b in -- select 6, child, parent +( +select t7a from t7 where t7b >= t1c -- select 7, child +) +) +) +); +t1a +1 +2 +test 4.1.1.0.4.0.0.0.1 +prepare s from 'select t1a from t1 -- select 1, parent +where t1a in +( +select t2c from t2 where t2a >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, parent +( +select t4a from t4 where t4b > t2c -- select 4, child +) +union +select t5a from t5 where t5b in -- select 5, parent +( +select t6a from t6 where t6b in -- select 6, child, parent +( +select t7a from t7 where t7b >= t1c -- select 7, child +) +) +) +)'; +execute s; +t1a +1 +2 +execute s; +t1a +1 +2 +deallocate prepare s; +test 4.1.1.0.4.0.0.0.2 +select * from (select t1a from t1 -- select 1, parent +where t1a in +( +select t2c from t2 where t2a >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, parent +( +select t4a from t4 where t4b > t2c -- select 4, child +) +union +select t5a from t5 where t5b in -- select 5, parent +( +select t6a from t6 where t6b in -- select 6, child, parent +( +select t7a from t7 where t7b >= t1c -- select 7, child +) +) +) +)) dt; +t1a +1 +2 +test 4.1.1.0.4.0.0.0.3 +create view v as select t1a from t1 -- select 1, parent +where t1a in +( +select t2c from t2 where t2a >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, parent +( +select t4a from t4 where t4b > t2c -- select 4, child +) +union +select t5a from t5 where t5b in -- select 5, parent +( +select t6a from t6 where t6b in -- select 6, child, parent +( +select t7a from t7 where t7b >= t1c -- select 7, child +) +) +) +); +select * from v; +t1a +1 +2 +select * from v; +t1a +1 +2 +drop view v; +test 4.1.1.0.4.0.0.0.4 +with cte as (select t1a from t1 -- select 1, parent +where t1a in +( +select t2c from t2 where t2a >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, parent +( +select t4a from t4 where t4b > t2c -- select 4, child +) +union +select t5a from t5 where t5b in -- select 5, parent +( +select t6a from t6 where t6b in -- select 6, child, parent +( +select t7a from t7 where t7b >= t1c -- select 7, child +) +) +) +)) select * from cte; +t1a +1 +2 +test 4.1.1.0.4.0.0.0.5 +create procedure p() select t1a from t1 -- select 1, parent +where t1a in +( +select t2c from t2 where t2a >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, parent +( +select t4a from t4 where t4b > t2c -- select 4, child +) +union +select t5a from t5 where t5b in -- select 5, parent +( +select t6a from t6 where t6b in -- select 6, child, parent +( +select t7a from t7 where t7b >= t1c -- select 7, child +) +) +) +); +call p(); +t1a +1 +2 +call p(); +t1a +1 +2 +drop procedure p; +"END GROUP" +test 4.2.1.0.4.0.0.1.0 +select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where -- select 4 +( +select t4b >= t1a -- select 5 +) +and t4c in +( +select t6a from t6 where t6b >= t2b -- select 6, child +) +union +select t4a from t4 where t4a > t1a -- select 7 +) +) +); +t1a +1 +2 +test 4.2.1.0.4.0.0.1.1 +prepare s from 'select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where -- select 4 +( +select t4b >= t1a -- select 5 +) +and t4c in +( +select t6a from t6 where t6b >= t2b -- select 6, child +) +union +select t4a from t4 where t4a > t1a -- select 7 +) +) +)'; +execute s; +t1a +1 +2 +execute s; +t1a +1 +2 +deallocate prepare s; +test 4.2.1.0.4.0.0.1.2 +select * from (select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where -- select 4 +( +select t4b >= t1a -- select 5 +) +and t4c in +( +select t6a from t6 where t6b >= t2b -- select 6, child +) +union +select t4a from t4 where t4a > t1a -- select 7 +) +) +)) dt; +t1a +1 +2 +test 4.2.1.0.4.0.0.1.3 +create view v as select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where -- select 4 +( +select t4b >= t1a -- select 5 +) +and t4c in +( +select t6a from t6 where t6b >= t2b -- select 6, child +) +union +select t4a from t4 where t4a > t1a -- select 7 +) +) +); +select * from v; +t1a +1 +2 +select * from v; +t1a +1 +2 +drop view v; +test 4.2.1.0.4.0.0.1.4 +with cte as (select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where -- select 4 +( +select t4b >= t1a -- select 5 +) +and t4c in +( +select t6a from t6 where t6b >= t2b -- select 6, child +) +union +select t4a from t4 where t4a > t1a -- select 7 +) +) +)) select * from cte; +t1a +1 +2 +test 4.2.1.0.4.0.0.1.5 +create procedure p() select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where -- select 4 +( +select t4b >= t1a -- select 5 +) +and t4c in +( +select t6a from t6 where t6b >= t2b -- select 6, child +) +union +select t4a from t4 where t4a > t1a -- select 7 +) +) +); +call p(); +t1a +1 +2 +call p(); +t1a +1 +2 +drop procedure p; +"END GROUP" +test 4.2.1.0.4.0.0.2.0 +select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where -- select 4 +( +select t4b >= t1a -- select 5 +) +and t4c in +( +select t6a from t6 where -- select 6, child +( +select t6b >= t2b -- select 7 +) +) +union +select t4a from t4 where t4a > t1a -- select 8 +) +) +); +t1a +1 +2 +test 4.2.1.0.4.0.0.2.1 +prepare s from 'select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where -- select 4 +( +select t4b >= t1a -- select 5 +) +and t4c in +( +select t6a from t6 where -- select 6, child +( +select t6b >= t2b -- select 7 +) +) +union +select t4a from t4 where t4a > t1a -- select 8 +) +) +)'; +execute s; +t1a +1 +2 +execute s; +t1a +1 +2 +deallocate prepare s; +test 4.2.1.0.4.0.0.2.2 +select * from (select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where -- select 4 +( +select t4b >= t1a -- select 5 +) +and t4c in +( +select t6a from t6 where -- select 6, child +( +select t6b >= t2b -- select 7 +) +) +union +select t4a from t4 where t4a > t1a -- select 8 +) +) +)) dt; +t1a +1 +2 +test 4.2.1.0.4.0.0.2.3 +create view v as select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where -- select 4 +( +select t4b >= t1a -- select 5 +) +and t4c in +( +select t6a from t6 where -- select 6, child +( +select t6b >= t2b -- select 7 +) +) +union +select t4a from t4 where t4a > t1a -- select 8 +) +) +); +select * from v; +t1a +1 +2 +select * from v; +t1a +1 +2 +drop view v; +test 4.2.1.0.4.0.0.2.4 +with cte as (select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where -- select 4 +( +select t4b >= t1a -- select 5 +) +and t4c in +( +select t6a from t6 where -- select 6, child +( +select t6b >= t2b -- select 7 +) +) +union +select t4a from t4 where t4a > t1a -- select 8 +) +) +)) select * from cte; +t1a +1 +2 +test 4.2.1.0.4.0.0.2.5 +create procedure p() select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where -- select 4 +( +select t4b >= t1a -- select 5 +) +and t4c in +( +select t6a from t6 where -- select 6, child +( +select t6b >= t2b -- select 7 +) +) +union +select t4a from t4 where t4a > t1a -- select 8 +) +) +); +call p(); +t1a +1 +2 +call p(); +t1a +1 +2 +drop procedure p; +"END GROUP" +test 4a.2.1.0.4.0.0.0 +select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, +( +select t3a from t3 where t3b in -- select 3, +( +select t4a from t4 where t4b >= t1a and t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child O.R. +) +) +) +) +union +select t7a from t7 -- select 6 +where t7a in +( +select t4a from t4 where t4a > t7a -- select 7, O.R. +); +t1a +1 +2 +test 4a.2.1.0.4.0.0.1 +prepare s from 'select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, +( +select t3a from t3 where t3b in -- select 3, +( +select t4a from t4 where t4b >= t1a and t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child O.R. +) +) +) +) +union +select t7a from t7 -- select 6 +where t7a in +( +select t4a from t4 where t4a > t7a -- select 7, O.R. +)'; +execute s; +t1a +1 +2 +execute s; +t1a +1 +2 +deallocate prepare s; +test 4a.2.1.0.4.0.0.2 +select * from (select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, +( +select t3a from t3 where t3b in -- select 3, +( +select t4a from t4 where t4b >= t1a and t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child O.R. +) +) +) +) +union +select t7a from t7 -- select 6 +where t7a in +( +select t4a from t4 where t4a > t7a -- select 7, O.R. +)) dt; +t1a +1 +2 +test 4a.2.1.0.4.0.0.3 +create view v as select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, +( +select t3a from t3 where t3b in -- select 3, +( +select t4a from t4 where t4b >= t1a and t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child O.R. +) +) +) +) +union +select t7a from t7 -- select 6 +where t7a in +( +select t4a from t4 where t4a > t7a -- select 7, O.R. +); +select * from v; +t1a +1 +2 +select * from v; +t1a +1 +2 +drop view v; +test 4a.2.1.0.4.0.0.4 +with cte as (select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, +( +select t3a from t3 where t3b in -- select 3, +( +select t4a from t4 where t4b >= t1a and t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child O.R. +) +) +) +) +union +select t7a from t7 -- select 6 +where t7a in +( +select t4a from t4 where t4a > t7a -- select 7, O.R. +)) select * from cte; +t1a +1 +2 +test 4a.2.1.0.4.0.0.5 +create procedure p() select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, +( +select t3a from t3 where t3b in -- select 3, +( +select t4a from t4 where t4b >= t1a and t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child O.R. +) +) +) +) +union +select t7a from t7 -- select 6 +where t7a in +( +select t4a from t4 where t4a > t7a -- select 7, O.R. +); +call p(); +t1a +1 +2 +call p(); +t1a +1 +2 +drop procedure p; +"END GROUP" +test 4b.2.1.0.4.0.0.0.0 +select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, +( +select t3a from t3 where t3b in -- select 3, +( +select t4a from t4 where t4b >= t1a and t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child O.R. +) +) +) +union +select t7a from t7 -- select 6 +where t7a in +( +select t4a from t4 where t4a > t7a -- select 7, O.R. +) +); +t1a +1 +2 +test 4b.2.1.0.4.0.0.0.1 +prepare s from 'select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, +( +select t3a from t3 where t3b in -- select 3, +( +select t4a from t4 where t4b >= t1a and t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child O.R. +) +) +) +union +select t7a from t7 -- select 6 +where t7a in +( +select t4a from t4 where t4a > t7a -- select 7, O.R. +) +)'; +execute s; +t1a +1 +2 +execute s; +t1a +1 +2 +deallocate prepare s; +test 4b.2.1.0.4.0.0.0.2 +select * from (select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, +( +select t3a from t3 where t3b in -- select 3, +( +select t4a from t4 where t4b >= t1a and t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child O.R. +) +) +) +union +select t7a from t7 -- select 6 +where t7a in +( +select t4a from t4 where t4a > t7a -- select 7, O.R. +) +)) dt; +t1a +1 +2 +test 4b.2.1.0.4.0.0.0.3 +create view v as select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, +( +select t3a from t3 where t3b in -- select 3, +( +select t4a from t4 where t4b >= t1a and t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child O.R. +) +) +) +union +select t7a from t7 -- select 6 +where t7a in +( +select t4a from t4 where t4a > t7a -- select 7, O.R. +) +); +select * from v; +t1a +1 +2 +select * from v; +t1a +1 +2 +drop view v; +test 4b.2.1.0.4.0.0.0.4 +with cte as (select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, +( +select t3a from t3 where t3b in -- select 3, +( +select t4a from t4 where t4b >= t1a and t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child O.R. +) +) +) +union +select t7a from t7 -- select 6 +where t7a in +( +select t4a from t4 where t4a > t7a -- select 7, O.R. +) +)) select * from cte; +t1a +1 +2 +test 4b.2.1.0.4.0.0.0.5 +create procedure p() select t1a from t1 -- select 1, parent +where t1a in +( +select t2a from t2 where t2b >= some -- select 2, +( +select t3a from t3 where t3b in -- select 3, +( +select t4a from t4 where t4b >= t1a and t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child O.R. +) +) +) +union +select t7a from t7 -- select 6 +where t7a in +( +select t4a from t4 where t4a > t7a -- select 7, O.R. +) +); +call p(); +t1a +1 +2 +call p(); +t1a +1 +2 +drop procedure p; +"END GROUP" +test 4.0.1.0.3.0.0.0.0 +select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +union +select t4a from t4 -- select 6 +) +) +) dt +where t1a = t2a; +t1a +1 +2 +test 4.0.1.0.3.0.0.0.1 +prepare s from 'select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +union +select t4a from t4 -- select 6 +) +) +) dt +where t1a = t2a'; +execute s; +t1a +1 +2 +execute s; +t1a +1 +2 +deallocate prepare s; +test 4.0.1.0.3.0.0.0.2 +select * from (select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +union +select t4a from t4 -- select 6 +) +) +) dt +where t1a = t2a) dt; +t1a +1 +2 +test 4.0.1.0.3.0.0.0.3 +create view v as select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +union +select t4a from t4 -- select 6 +) +) +) dt +where t1a = t2a; +select * from v; +t1a +1 +2 +select * from v; +t1a +1 +2 +drop view v; +test 4.0.1.0.3.0.0.0.4 +with cte as (select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +union +select t4a from t4 -- select 6 +) +) +) dt +where t1a = t2a) select * from cte; +t1a +1 +2 +test 4.0.1.0.3.0.0.0.5 +create procedure p() select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +union +select t4a from t4 -- select 6 +) +) +) dt +where t1a = t2a; +call p(); +t1a +1 +2 +call p(); +t1a +1 +2 +drop procedure p; +"END GROUP" +test 4.0.1.0.3.0.0.1.0 +select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +union +select t2b -- select 6 +) +) +) dt +where t1a = t2a; +t1a +1 +2 +test 4.0.1.0.3.0.0.1.1 +prepare s from 'select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +union +select t2b -- select 6 +) +) +) dt +where t1a = t2a'; +execute s; +t1a +1 +2 +execute s; +t1a +1 +2 +deallocate prepare s; +test 4.0.1.0.3.0.0.1.2 +select * from (select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +union +select t2b -- select 6 +) +) +) dt +where t1a = t2a) dt; +t1a +1 +2 +test 4.0.1.0.3.0.0.1.3 +create view v as select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +union +select t2b -- select 6 +) +) +) dt +where t1a = t2a; +select * from v; +t1a +1 +2 +select * from v; +t1a +1 +2 +drop view v; +test 4.0.1.0.3.0.0.1.4 +with cte as (select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +union +select t2b -- select 6 +) +) +) dt +where t1a = t2a) select * from cte; +t1a +1 +2 +test 4.0.1.0.3.0.0.1.5 +create procedure p() select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +union +select t2b -- select 6 +) +) +) dt +where t1a = t2a; +call p(); +t1a +1 +2 +call p(); +t1a +1 +2 +drop procedure p; +"END GROUP" +test 4a.0.1.0.3.0.0.0.0 +select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +) +) +) dt +where t1a = t2a +union +select t5a from t5 where t5b in +( +select t7b from t7 where t7c < t5c +); +t1a +1 +2 +test 4a.0.1.0.3.0.0.0.1 +prepare s from 'select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +) +) +) dt +where t1a = t2a +union +select t5a from t5 where t5b in +( +select t7b from t7 where t7c < t5c +)'; +execute s; +t1a +1 +2 +execute s; +t1a +1 +2 +deallocate prepare s; +test 4a.0.1.0.3.0.0.0.2 +select * from (select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +) +) +) dt +where t1a = t2a +union +select t5a from t5 where t5b in +( +select t7b from t7 where t7c < t5c +)) dt; +t1a +1 +2 +test 4a.0.1.0.3.0.0.0.3 +create view v as select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +) +) +) dt +where t1a = t2a +union +select t5a from t5 where t5b in +( +select t7b from t7 where t7c < t5c +); +select * from v; +t1a +1 +2 +select * from v; +t1a +1 +2 +drop view v; +test 4a.0.1.0.3.0.0.0.4 +with cte as (select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +) +) +) dt +where t1a = t2a +union +select t5a from t5 where t5b in +( +select t7b from t7 where t7c < t5c +)) select * from cte; +t1a +1 +2 +test 4a.0.1.0.3.0.0.0.5 +create procedure p() select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +) +) +) dt +where t1a = t2a +union +select t5a from t5 where t5b in +( +select t7b from t7 where t7c < t5c +); +call p(); +t1a +1 +2 +call p(); +t1a +1 +2 +drop procedure p; +"END GROUP" +test 4a.0.1.0.3.0.0.1.0 +select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +) +) +) dt +where t1a = t2a +union +select t5a from t5 where t5b in +( +select t7b from t7 where +( +select t7c < t5c +) +); +t1a +1 +2 +test 4a.0.1.0.3.0.0.1.1 +prepare s from 'select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +) +) +) dt +where t1a = t2a +union +select t5a from t5 where t5b in +( +select t7b from t7 where +( +select t7c < t5c +) +)'; +execute s; +t1a +1 +2 +execute s; +t1a +1 +2 +deallocate prepare s; +test 4a.0.1.0.3.0.0.1.2 +select * from (select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +) +) +) dt +where t1a = t2a +union +select t5a from t5 where t5b in +( +select t7b from t7 where +( +select t7c < t5c +) +)) dt; +t1a +1 +2 +test 4a.0.1.0.3.0.0.1.3 +create view v as select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +) +) +) dt +where t1a = t2a +union +select t5a from t5 where t5b in +( +select t7b from t7 where +( +select t7c < t5c +) +); +select * from v; +t1a +1 +2 +select * from v; +t1a +1 +2 +drop view v; +test 4a.0.1.0.3.0.0.1.4 +with cte as (select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +) +) +) dt +where t1a = t2a +union +select t5a from t5 where t5b in +( +select t7b from t7 where +( +select t7c < t5c +) +)) select * from cte; +t1a +1 +2 +test 4a.0.1.0.3.0.0.1.5 +create procedure p() select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +) +) +) dt +where t1a = t2a +union +select t5a from t5 where t5b in +( +select t7b from t7 where +( +select t7c < t5c +) +); +call p(); +t1a +1 +2 +call p(); +t1a +1 +2 +drop procedure p; +"END GROUP" +test 4.0.1.0.3.0.0.0.0 +select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +union +select t4a from t4 -- select 6 +) +) +) dt +where t1a = t2a; +t1a +1 +2 +test 4.0.1.0.3.0.0.0.1 +prepare s from 'select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +union +select t4a from t4 -- select 6 +) +) +) dt +where t1a = t2a'; +execute s; +t1a +1 +2 +execute s; +t1a +1 +2 +deallocate prepare s; +test 4.0.1.0.3.0.0.0.2 +select * from (select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +union +select t4a from t4 -- select 6 +) +) +) dt +where t1a = t2a) dt; +t1a +1 +2 +test 4.0.1.0.3.0.0.0.3 +create view v as select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +union +select t4a from t4 -- select 6 +) +) +) dt +where t1a = t2a; +select * from v; +t1a +1 +2 +select * from v; +t1a +1 +2 +drop view v; +test 4.0.1.0.3.0.0.0.4 +with cte as (select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +union +select t4a from t4 -- select 6 +) +) +) dt +where t1a = t2a) select * from cte; +t1a +1 +2 +test 4.0.1.0.3.0.0.0.5 +create procedure p() select t1a from t1, -- select 1, parent +( +select t2a from t2 where t2b >= some -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t2b -- select 5, child +) +union +select t4a from t4 -- select 6 +) +) +) dt +where t1a = t2a; +call p(); +t1a +1 +2 +call p(); +t1a +1 +2 +drop procedure p; +"END GROUP" +test 5.1.0.0.1.0.0.0.0 +select t1a as col1, t1b as col2 from t1 +group by (select col1) order by col1; +col1 col2 +1 1 +2 2 +test 5.1.0.0.1.0.0.0.1 +prepare s from 'select t1a as col1, t1b as col2 from t1 +group by (select col1) order by col1'; +execute s; +col1 col2 +1 1 +2 2 +execute s; +col1 col2 +1 1 +2 2 +deallocate prepare s; +test 5.1.0.0.1.0.0.0.2 +select * from (select t1a as col1, t1b as col2 from t1 +group by (select col1) order by col1) dt; +col1 col2 +1 1 +2 2 +test 5.1.0.0.1.0.0.0.3 +create view v as select t1a as col1, t1b as col2 from t1 +group by (select col1) order by col1; +select * from v; +col1 col2 +1 1 +2 2 +select * from v; +col1 col2 +1 1 +2 2 +drop view v; +test 5.1.0.0.1.0.0.0.4 +with cte as (select t1a as col1, t1b as col2 from t1 +group by (select col1) order by col1) select * from cte; +col1 col2 +1 1 +2 2 +test 5.1.0.0.1.0.0.0.5 +create procedure p() select t1a as col1, t1b as col2 from t1 +group by (select col1) order by col1; +call p(); +col1 col2 +1 1 +2 2 +call p(); +col1 col2 +1 1 +2 2 +drop procedure p; +"END GROUP" +test 5.2.0.0.1.0.0.0.0 +select t1a as col1, t1b as col2 from t1 +group by (select col1 + col2) order by col1; +col1 col2 +1 1 +2 2 +test 5.2.0.0.1.0.0.0.1 +prepare s from 'select t1a as col1, t1b as col2 from t1 +group by (select col1 + col2) order by col1'; +execute s; +col1 col2 +1 1 +2 2 +execute s; +col1 col2 +1 1 +2 2 +deallocate prepare s; +test 5.2.0.0.1.0.0.0.2 +select * from (select t1a as col1, t1b as col2 from t1 +group by (select col1 + col2) order by col1) dt; +col1 col2 +1 1 +2 2 +test 5.2.0.0.1.0.0.0.3 +create view v as select t1a as col1, t1b as col2 from t1 +group by (select col1 + col2) order by col1; +select * from v; +col1 col2 +1 1 +2 2 +select * from v; +col1 col2 +1 1 +2 2 +drop view v; +test 5.2.0.0.1.0.0.0.4 +with cte as (select t1a as col1, t1b as col2 from t1 +group by (select col1 + col2) order by col1) select * from cte; +col1 col2 +1 1 +2 2 +test 5.2.0.0.1.0.0.0.5 +create procedure p() select t1a as col1, t1b as col2 from t1 +group by (select col1 + col2) order by col1; +call p(); +col1 col2 +1 1 +2 2 +call p(); +col1 col2 +1 1 +2 2 +drop procedure p; +"END GROUP" +test 5.1.0.0.1.1.0.0.0 +select t1a as col1, t1b+t1c as col2 from t1 +group by (select col1) order by col1; +col1 col2 +1 2 +2 4 +test 5.1.0.0.1.1.0.0.1 +prepare s from 'select t1a as col1, t1b+t1c as col2 from t1 +group by (select col1) order by col1'; +execute s; +col1 col2 +1 2 +2 4 +execute s; +col1 col2 +1 2 +2 4 +deallocate prepare s; +test 5.1.0.0.1.1.0.0.2 +select * from (select t1a as col1, t1b+t1c as col2 from t1 +group by (select col1) order by col1) dt; +col1 col2 +1 2 +2 4 +test 5.1.0.0.1.1.0.0.3 +create view v as select t1a as col1, t1b+t1c as col2 from t1 +group by (select col1) order by col1; +select * from v; +col1 col2 +1 2 +2 4 +select * from v; +col1 col2 +1 2 +2 4 +drop view v; +test 5.1.0.0.1.1.0.0.4 +with cte as (select t1a as col1, t1b+t1c as col2 from t1 +group by (select col1) order by col1) select * from cte; +col1 col2 +1 2 +2 4 +test 5.1.0.0.1.1.0.0.5 +create procedure p() select t1a as col1, t1b+t1c as col2 from t1 +group by (select col1) order by col1; +call p(); +col1 col2 +1 2 +2 4 +call p(); +col1 col2 +1 2 +2 4 +drop procedure p; +"END GROUP" +test 5.2.0.0.2.2.0.0 +select t1a+t2a as col1, t1b+t2b as col2 from t1 join t2 on t1c=t2c +group by (select col1 + col2) order by (select col1 + col2); +col1 col2 +2 2 +4 4 +test 5.2.0.0.2.2.0.1 +prepare s from 'select t1a+t2a as col1, t1b+t2b as col2 from t1 join t2 on t1c=t2c +group by (select col1 + col2) order by (select col1 + col2)'; +execute s; +col1 col2 +2 2 +4 4 +execute s; +col1 col2 +2 2 +4 4 +deallocate prepare s; +test 5.2.0.0.2.2.0.2 +select * from (select t1a+t2a as col1, t1b+t2b as col2 from t1 join t2 on t1c=t2c +group by (select col1 + col2) order by (select col1 + col2)) dt; +col1 col2 +2 2 +4 4 +test 5.2.0.0.2.2.0.3 +create view v as select t1a+t2a as col1, t1b+t2b as col2 from t1 join t2 on t1c=t2c +group by (select col1 + col2) order by (select col1 + col2); +select * from v; +col1 col2 +2 2 +4 4 +select * from v; +col1 col2 +2 2 +4 4 +drop view v; +test 5.2.0.0.2.2.0.4 +with cte as (select t1a+t2a as col1, t1b+t2b as col2 from t1 join t2 on t1c=t2c +group by (select col1 + col2) order by (select col1 + col2)) select * from cte; +col1 col2 +2 2 +4 4 +test 5.2.0.0.2.2.0.5 +create procedure p() select t1a+t2a as col1, t1b+t2b as col2 from t1 join t2 on t1c=t2c +group by (select col1 + col2) order by (select col1 + col2); +call p(); +col1 col2 +2 2 +4 4 +call p(); +col1 col2 +2 2 +4 4 +drop procedure p; +"END GROUP" +test 5.1.1.0.1.0.0.0.0 +select * from t2 where t2a in +( +select t1a from t1 +group by (select t1a > t2b) order by t1a +); +t2a t2b t2c +1 1 1 +2 2 2 +test 5.1.1.0.1.0.0.0.1 +prepare s from 'select * from t2 where t2a in +( +select t1a from t1 +group by (select t1a > t2b) order by t1a +)'; +execute s; +t2a t2b t2c +1 1 1 +2 2 2 +execute s; +t2a t2b t2c +1 1 1 +2 2 2 +deallocate prepare s; +test 5.1.1.0.1.0.0.0.2 +select * from (select * from t2 where t2a in +( +select t1a from t1 +group by (select t1a > t2b) order by t1a +)) dt; +t2a t2b t2c +1 1 1 +2 2 2 +test 5.1.1.0.1.0.0.0.3 +create view v as select * from t2 where t2a in +( +select t1a from t1 +group by (select t1a > t2b) order by t1a +); +select * from v; +t2a t2b t2c +1 1 1 +2 2 2 +select * from v; +t2a t2b t2c +1 1 1 +2 2 2 +drop view v; +test 5.1.1.0.1.0.0.0.4 +with cte as (select * from t2 where t2a in +( +select t1a from t1 +group by (select t1a > t2b) order by t1a +)) select * from cte; +t2a t2b t2c +1 1 1 +2 2 2 +test 5.1.1.0.1.0.0.0.5 +create procedure p() select * from t2 where t2a in +( +select t1a from t1 +group by (select t1a > t2b) order by t1a +); +call p(); +t2a t2b t2c +1 1 1 +2 2 2 +call p(); +t2a t2b t2c +1 1 1 +2 2 2 +drop procedure p; +"END GROUP" +test 5a.1.1.0.1.0.0.0.0 +select * from t2 where t2a in +( +select t1a as col1 from t1 +group by (select col1 > t2b) order by col1 +); +t2a t2b t2c +1 1 1 +2 2 2 +test 5a.1.1.0.1.0.0.0.1 +prepare s from 'select * from t2 where t2a in +( +select t1a as col1 from t1 +group by (select col1 > t2b) order by col1 +)'; +execute s; +t2a t2b t2c +1 1 1 +2 2 2 +execute s; +t2a t2b t2c +1 1 1 +2 2 2 +deallocate prepare s; +test 5a.1.1.0.1.0.0.0.2 +select * from (select * from t2 where t2a in +( +select t1a as col1 from t1 +group by (select col1 > t2b) order by col1 +)) dt; +t2a t2b t2c +1 1 1 +2 2 2 +test 5a.1.1.0.1.0.0.0.3 +create view v as select * from t2 where t2a in +( +select t1a as col1 from t1 +group by (select col1 > t2b) order by col1 +); +select * from v; +t2a t2b t2c +1 1 1 +2 2 2 +select * from v; +t2a t2b t2c +1 1 1 +2 2 2 +drop view v; +test 5a.1.1.0.1.0.0.0.4 +with cte as (select * from t2 where t2a in +( +select t1a as col1 from t1 +group by (select col1 > t2b) order by col1 +)) select * from cte; +t2a t2b t2c +1 1 1 +2 2 2 +test 5a.1.1.0.1.0.0.0.5 +create procedure p() select * from t2 where t2a in +( +select t1a as col1 from t1 +group by (select col1 > t2b) order by col1 +); +call p(); +t2a t2b t2c +1 1 1 +2 2 2 +call p(); +t2a t2b t2c +1 1 1 +2 2 2 +drop procedure p; +"END GROUP" +test 5.1.1.0.1.1.0.0.0 +select * from t2 where t2a*2 in +( +select t1a+t2a from t1 +group by (select t1a+t2a > t2b) order by t1a+t2a +); +t2a t2b t2c +1 1 1 +2 2 2 +test 5.1.1.0.1.1.0.0.1 +prepare s from 'select * from t2 where t2a*2 in +( +select t1a+t2a from t1 +group by (select t1a+t2a > t2b) order by t1a+t2a +)'; +execute s; +t2a t2b t2c +1 1 1 +2 2 2 +execute s; +t2a t2b t2c +1 1 1 +2 2 2 +deallocate prepare s; +test 5.1.1.0.1.1.0.0.2 +select * from (select * from t2 where t2a*2 in +( +select t1a+t2a from t1 +group by (select t1a+t2a > t2b) order by t1a+t2a +)) dt; +t2a t2b t2c +1 1 1 +2 2 2 +test 5.1.1.0.1.1.0.0.3 +create view v as select * from t2 where t2a*2 in +( +select t1a+t2a from t1 +group by (select t1a+t2a > t2b) order by t1a+t2a +); +select * from v; +t2a t2b t2c +1 1 1 +2 2 2 +select * from v; +t2a t2b t2c +1 1 1 +2 2 2 +drop view v; +test 5.1.1.0.1.1.0.0.4 +with cte as (select * from t2 where t2a*2 in +( +select t1a+t2a from t1 +group by (select t1a+t2a > t2b) order by t1a+t2a +)) select * from cte; +t2a t2b t2c +1 1 1 +2 2 2 +test 5.1.1.0.1.1.0.0.5 +create procedure p() select * from t2 where t2a*2 in +( +select t1a+t2a from t1 +group by (select t1a+t2a > t2b) order by t1a+t2a +); +call p(); +t2a t2b t2c +1 1 1 +2 2 2 +call p(); +t2a t2b t2c +1 1 1 +2 2 2 +drop procedure p; +"END GROUP" +test 5a.1.1.0.1.1.0.0.0 +select * from t2 where t2a*2 in +( +select t1a+t2a as col1 from t1 +group by (select col1 > t2b) order by col1 +); +t2a t2b t2c +1 1 1 +2 2 2 +test 5a.1.1.0.1.1.0.0.1 +prepare s from 'select * from t2 where t2a*2 in +( +select t1a+t2a as col1 from t1 +group by (select col1 > t2b) order by col1 +)'; +execute s; +t2a t2b t2c +1 1 1 +2 2 2 +execute s; +t2a t2b t2c +1 1 1 +2 2 2 +deallocate prepare s; +test 5a.1.1.0.1.1.0.0.2 +select * from (select * from t2 where t2a*2 in +( +select t1a+t2a as col1 from t1 +group by (select col1 > t2b) order by col1 +)) dt; +t2a t2b t2c +1 1 1 +2 2 2 +test 5a.1.1.0.1.1.0.0.3 +create view v as select * from t2 where t2a*2 in +( +select t1a+t2a as col1 from t1 +group by (select col1 > t2b) order by col1 +); +select * from v; +t2a t2b t2c +1 1 1 +2 2 2 +select * from v; +t2a t2b t2c +1 1 1 +2 2 2 +drop view v; +test 5a.1.1.0.1.1.0.0.4 +with cte as (select * from t2 where t2a*2 in +( +select t1a+t2a as col1 from t1 +group by (select col1 > t2b) order by col1 +)) select * from cte; +t2a t2b t2c +1 1 1 +2 2 2 +test 5a.1.1.0.1.1.0.0.5 +create procedure p() select * from t2 where t2a*2 in +( +select t1a+t2a as col1 from t1 +group by (select col1 > t2b) order by col1 +); +call p(); +t2a t2b t2c +1 1 1 +2 2 2 +call p(); +t2a t2b t2c +1 1 1 +2 2 2 +drop procedure p; +"END GROUP" +test 5.2.1.0.1.2.0.0.0 +select * from v5 where v5a in +( +select t1a from t1 +group by +( +select t1a*25 < v5a + v5b +) +order by t1a +); +v5a v5b v5c +1 1 1 +2 2 2 +test 5.2.1.0.1.2.0.0.1 +prepare s from 'select * from v5 where v5a in +( +select t1a from t1 +group by +( +select t1a*25 < v5a + v5b +) +order by t1a +)'; +execute s; +v5a v5b v5c +1 1 1 +2 2 2 +execute s; +v5a v5b v5c +1 1 1 +2 2 2 +deallocate prepare s; +test 5.2.1.0.1.2.0.0.2 +select * from (select * from v5 where v5a in +( +select t1a from t1 +group by +( +select t1a*25 < v5a + v5b +) +order by t1a +)) dt; +v5a v5b v5c +1 1 1 +2 2 2 +test 5.2.1.0.1.2.0.0.3 +create view v as select * from v5 where v5a in +( +select t1a from t1 +group by +( +select t1a*25 < v5a + v5b +) +order by t1a +); +select * from v; +v5a v5b v5c +1 1 1 +2 2 2 +select * from v; +v5a v5b v5c +1 1 1 +2 2 2 +drop view v; +test 5.2.1.0.1.2.0.0.4 +with cte as (select * from v5 where v5a in +( +select t1a from t1 +group by +( +select t1a*25 < v5a + v5b +) +order by t1a +)) select * from cte; +v5a v5b v5c +1 1 1 +2 2 2 +test 5.2.1.0.1.2.0.0.5 +create procedure p() select * from v5 where v5a in +( +select t1a from t1 +group by +( +select t1a*25 < v5a + v5b +) +order by t1a +); +call p(); +v5a v5b v5c +1 1 1 +2 2 2 +call p(); +v5a v5b v5c +1 1 1 +2 2 2 +drop procedure p; +"END GROUP" +test 5a.2.1.0.1.2.0.0.0 +select * from v2 where v2a in +( +select t1a*25 as col1 from t1 +group by (select col1 < v2a + v2b) order by t1a +); +v2a v2b +25 25 +test 5a.2.1.0.1.2.0.0.1 +prepare s from 'select * from v2 where v2a in +( +select t1a*25 as col1 from t1 +group by (select col1 < v2a + v2b) order by t1a +)'; +execute s; +v2a v2b +25 25 +execute s; +v2a v2b +25 25 +deallocate prepare s; +test 5a.2.1.0.1.2.0.0.2 +select * from (select * from v2 where v2a in +( +select t1a*25 as col1 from t1 +group by (select col1 < v2a + v2b) order by t1a +)) dt; +v2a v2b +25 25 +test 5a.2.1.0.1.2.0.0.3 +create view v as select * from v2 where v2a in +( +select t1a*25 as col1 from t1 +group by (select col1 < v2a + v2b) order by t1a +); +select * from v; +v2a v2b +25 25 +select * from v; +v2a v2b +25 25 +drop view v; +test 5a.2.1.0.1.2.0.0.4 +with cte as (select * from v2 where v2a in +( +select t1a*25 as col1 from t1 +group by (select col1 < v2a + v2b) order by t1a +)) select * from cte; +v2a v2b +25 25 +test 5a.2.1.0.1.2.0.0.5 +create procedure p() select * from v2 where v2a in +( +select t1a*25 as col1 from t1 +group by (select col1 < v2a + v2b) order by t1a +); +call p(); +v2a v2b +25 25 +call p(); +v2a v2b +25 25 +drop procedure p; +"END GROUP" +test 5a.2.2.0.1.2.0.0.0 +select * from v2 where v2a in +( +select t1a*25 as col1 from t1 +group by (select col1 < v2a + v2b) order by col1 +); +v2a v2b +25 25 +test 5a.2.2.0.1.2.0.0.1 +prepare s from 'select * from v2 where v2a in +( +select t1a*25 as col1 from t1 +group by (select col1 < v2a + v2b) order by col1 +)'; +execute s; +v2a v2b +25 25 +execute s; +v2a v2b +25 25 +deallocate prepare s; +test 5a.2.2.0.1.2.0.0.2 +select * from (select * from v2 where v2a in +( +select t1a*25 as col1 from t1 +group by (select col1 < v2a + v2b) order by col1 +)) dt; +v2a v2b +25 25 +test 5a.2.2.0.1.2.0.0.3 +create view v as select * from v2 where v2a in +( +select t1a*25 as col1 from t1 +group by (select col1 < v2a + v2b) order by col1 +); +select * from v; +v2a v2b +25 25 +select * from v; +v2a v2b +25 25 +drop view v; +test 5a.2.2.0.1.2.0.0.4 +with cte as (select * from v2 where v2a in +( +select t1a*25 as col1 from t1 +group by (select col1 < v2a + v2b) order by col1 +)) select * from cte; +v2a v2b +25 25 +test 5a.2.2.0.1.2.0.0.5 +create procedure p() select * from v2 where v2a in +( +select t1a*25 as col1 from t1 +group by (select col1 < v2a + v2b) order by col1 +); +call p(); +v2a v2b +25 25 +call p(); +v2a v2b +25 25 +drop procedure p; +"END GROUP" +test 5b.2.2.0.1.2.0.0.0 +select * from v2 where v2a in +( +select t1a*25 as col1 from t1 +group by (select col1 < v2a + v2b) order by (select col1 < v2b) +); +v2a v2b +25 25 +test 5b.2.2.0.1.2.0.0.1 +prepare s from 'select * from v2 where v2a in +( +select t1a*25 as col1 from t1 +group by (select col1 < v2a + v2b) order by (select col1 < v2b) +)'; +execute s; +v2a v2b +25 25 +execute s; +v2a v2b +25 25 +deallocate prepare s; +test 5b.2.2.0.1.2.0.0.2 +select * from (select * from v2 where v2a in +( +select t1a*25 as col1 from t1 +group by (select col1 < v2a + v2b) order by (select col1 < v2b) +)) dt; +v2a v2b +25 25 +test 5b.2.2.0.1.2.0.0.3 +create view v as select * from v2 where v2a in +( +select t1a*25 as col1 from t1 +group by (select col1 < v2a + v2b) order by (select col1 < v2b) +); +select * from v; +v2a v2b +25 25 +select * from v; +v2a v2b +25 25 +drop view v; +test 5b.2.2.0.1.2.0.0.4 +with cte as (select * from v2 where v2a in +( +select t1a*25 as col1 from t1 +group by (select col1 < v2a + v2b) order by (select col1 < v2b) +)) select * from cte; +v2a v2b +25 25 +test 5b.2.2.0.1.2.0.0.5 +create procedure p() select * from v2 where v2a in +( +select t1a*25 as col1 from t1 +group by (select col1 < v2a + v2b) order by (select col1 < v2b) +); +call p(); +v2a v2b +25 25 +call p(); +v2a v2b +25 25 +drop procedure p; +"END GROUP" +test 6.1.0.0.2.0.0.0.0 +select t1a from t1, -- select 1, parent +( +select t2a from t2, -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t3b -- select 5, child +) +) +) dt2 +where t2b = t3a +) dt +where t1a = t2a; +t1a +1 +2 +test 6.1.0.0.2.0.0.0.1 +prepare s from 'select t1a from t1, -- select 1, parent +( +select t2a from t2, -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t3b -- select 5, child +) +) +) dt2 +where t2b = t3a +) dt +where t1a = t2a'; +execute s; +t1a +1 +2 +execute s; +t1a +1 +2 +deallocate prepare s; +test 6.1.0.0.2.0.0.0.2 +select * from (select t1a from t1, -- select 1, parent +( +select t2a from t2, -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t3b -- select 5, child +) +) +) dt2 +where t2b = t3a +) dt +where t1a = t2a) dt; +t1a +1 +2 +test 6.1.0.0.2.0.0.0.3 +create view v as select t1a from t1, -- select 1, parent +( +select t2a from t2, -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t3b -- select 5, child +) +) +) dt2 +where t2b = t3a +) dt +where t1a = t2a; +select * from v; +t1a +1 +2 +select * from v; +t1a +1 +2 +drop view v; +test 6.1.0.0.2.0.0.0.4 +with cte as (select t1a from t1, -- select 1, parent +( +select t2a from t2, -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t3b -- select 5, child +) +) +) dt2 +where t2b = t3a +) dt +where t1a = t2a) select * from cte; +t1a +1 +2 +test 6.1.0.0.2.0.0.0.5 +create procedure p() select t1a from t1, -- select 1, parent +( +select t2a from t2, -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t3b -- select 5, child +) +) +) dt2 +where t2b = t3a +) dt +where t1a = t2a; +call p(); +t1a +1 +2 +call p(); +t1a +1 +2 +drop procedure p; +"END GROUP" +test 6.2.0.0.2.0.0.0.0 +select t1a from t1, -- select 1, parent +( +select t2a from t2, -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t3b -- select 5, child +and t6c >= t4c +) +) +) dt2 +where t2b = t3a +) dt +where t1a = t2a; +t1a +1 +2 +test 6.2.0.0.2.0.0.0.1 +prepare s from 'select t1a from t1, -- select 1, parent +( +select t2a from t2, -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t3b -- select 5, child +and t6c >= t4c +) +) +) dt2 +where t2b = t3a +) dt +where t1a = t2a'; +execute s; +t1a +1 +2 +execute s; +t1a +1 +2 +deallocate prepare s; +test 6.2.0.0.2.0.0.0.2 +select * from (select t1a from t1, -- select 1, parent +( +select t2a from t2, -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t3b -- select 5, child +and t6c >= t4c +) +) +) dt2 +where t2b = t3a +) dt +where t1a = t2a) dt; +t1a +1 +2 +test 6.2.0.0.2.0.0.0.3 +create view v as select t1a from t1, -- select 1, parent +( +select t2a from t2, -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t3b -- select 5, child +and t6c >= t4c +) +) +) dt2 +where t2b = t3a +) dt +where t1a = t2a; +select * from v; +t1a +1 +2 +select * from v; +t1a +1 +2 +drop view v; +test 6.2.0.0.2.0.0.0.4 +with cte as (select t1a from t1, -- select 1, parent +( +select t2a from t2, -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t3b -- select 5, child +and t6c >= t4c +) +) +) dt2 +where t2b = t3a +) dt +where t1a = t2a) select * from cte; +t1a +1 +2 +test 6.2.0.0.2.0.0.0.5 +create procedure p() select t1a from t1, -- select 1, parent +( +select t2a from t2, -- select 2, child +( +select t3a from t3 where t3b in -- select 3, non-mergable +( +select t4a from t4 where t4c in -- select 4, parent +( +select t6a from t6 where t6b >= t3b -- select 5, child +and t6c >= t4c +) +) +) dt2 +where t2b = t3a +) dt +where t1a = t2a; +call p(); +t1a +1 +2 +call p(); +t1a +1 +2 +drop procedure p; +"END GROUP" +test 7a.0.0 +select * from +( +select t1a as dt1a, t1b from t1 +) dt +where +dt1a in +( +select t2a from t2 where t2b >= t1b +); +dt1a t1b +1 1 +2 2 +test 7a.0.1 +prepare s from 'select * from +( +select t1a as dt1a, t1b from t1 +) dt +where +dt1a in +( +select t2a from t2 where t2b >= t1b +)'; +execute s; +dt1a t1b +1 1 +2 2 +execute s; +dt1a t1b +1 1 +2 2 +deallocate prepare s; +test 7a.0.2 +select * from (select * from +( +select t1a as dt1a, t1b from t1 +) dt +where +dt1a in +( +select t2a from t2 where t2b >= t1b +)) dt; +dt1a t1b +1 1 +2 2 +test 7a.0.3 +create view v as select * from +( +select t1a as dt1a, t1b from t1 +) dt +where +dt1a in +( +select t2a from t2 where t2b >= t1b +); +select * from v; +dt1a t1b +1 1 +2 2 +select * from v; +dt1a t1b +1 1 +2 2 +drop view v; +test 7a.0.4 +with cte as (select * from +( +select t1a as dt1a, t1b from t1 +) dt +where +dt1a in +( +select t2a from t2 where t2b >= t1b +)) select * from cte; +dt1a t1b +1 1 +2 2 +test 7a.0.5 +create procedure p() select * from +( +select t1a as dt1a, t1b from t1 +) dt +where +dt1a in +( +select t2a from t2 where t2b >= t1b +); +call p(); +dt1a t1b +1 1 +2 2 +call p(); +dt1a t1b +1 1 +2 2 +drop procedure p; +"END GROUP" +test 7b.1.0.0.0 +select +( +select sum(t2a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +t1b from t1; +col1 t1b +5 1 +3 2 +test 7b.1.0.0.1 +prepare s from 'select +( +select sum(t2a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +t1b from t1'; +execute s; +col1 t1b +5 1 +3 2 +execute s; +col1 t1b +5 1 +3 2 +deallocate prepare s; +test 7b.1.0.0.2 +select * from (select +( +select sum(t2a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +t1b from t1) dt; +col1 t1b +5 1 +3 2 +test 7b.1.0.0.3 +create view v as select +( +select sum(t2a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +t1b from t1; +select * from v; +col1 t1b +5 1 +3 2 +select * from v; +col1 t1b +5 1 +3 2 +drop view v; +test 7b.1.0.0.4 +with cte as (select +( +select sum(t2a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +t1b from t1) select * from cte; +col1 t1b +5 1 +3 2 +test 7b.1.0.0.5 +create procedure p() select +( +select sum(t2a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +t1b from t1; +call p(); +col1 t1b +5 1 +3 2 +call p(); +col1 t1b +5 1 +3 2 +drop procedure p; +"END GROUP" +test 7b.2.0.0.0 +select +( +select sum(t2a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +( +select sum(t3a) from t3 where t3b > t1a group by t3b limit 1 +) as col2, +t1b from t1; +col1 col2 t1b +5 2 1 +3 3 2 +test 7b.2.0.0.1 +prepare s from 'select +( +select sum(t2a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +( +select sum(t3a) from t3 where t3b > t1a group by t3b limit 1 +) as col2, +t1b from t1'; +execute s; +col1 col2 t1b +5 2 1 +3 3 2 +execute s; +col1 col2 t1b +5 2 1 +3 3 2 +deallocate prepare s; +test 7b.2.0.0.2 +select * from (select +( +select sum(t2a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +( +select sum(t3a) from t3 where t3b > t1a group by t3b limit 1 +) as col2, +t1b from t1) dt; +col1 col2 t1b +5 2 1 +3 3 2 +test 7b.2.0.0.3 +create view v as select +( +select sum(t2a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +( +select sum(t3a) from t3 where t3b > t1a group by t3b limit 1 +) as col2, +t1b from t1; +select * from v; +col1 col2 t1b +5 2 1 +3 3 2 +select * from v; +col1 col2 t1b +5 2 1 +3 3 2 +drop view v; +test 7b.2.0.0.4 +with cte as (select +( +select sum(t2a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +( +select sum(t3a) from t3 where t3b > t1a group by t3b limit 1 +) as col2, +t1b from t1) select * from cte; +col1 col2 t1b +5 2 1 +3 3 2 +test 7b.2.0.0.5 +create procedure p() select +( +select sum(t2a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +( +select sum(t3a) from t3 where t3b > t1a group by t3b limit 1 +) as col2, +t1b from t1; +call p(); +col1 col2 t1b +5 2 1 +3 3 2 +call p(); +col1 col2 t1b +5 2 1 +3 3 2 +drop procedure p; +"END GROUP" +test 7c.2.0.0.0 +select +( +select sum(t1a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +( +select sum(t1c) from t3 where t3b > t1a group by t3b limit 1 +) as col2, +t1b from t1; +col1 col2 t1b +3 3 1 +test 7c.2.0.0.1 +prepare s from 'select +( +select sum(t1a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +( +select sum(t1c) from t3 where t3b > t1a group by t3b limit 1 +) as col2, +t1b from t1'; +execute s; +col1 col2 t1b +3 3 1 +execute s; +col1 col2 t1b +3 3 1 +deallocate prepare s; +test 7c.2.0.0.2 +select * from (select +( +select sum(t1a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +( +select sum(t1c) from t3 where t3b > t1a group by t3b limit 1 +) as col2, +t1b from t1) dt; +col1 col2 t1b +3 3 1 +test 7c.2.0.0.3 +create view v as select +( +select sum(t1a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +( +select sum(t1c) from t3 where t3b > t1a group by t3b limit 1 +) as col2, +t1b from t1; +select * from v; +col1 col2 t1b +3 3 1 +select * from v; +col1 col2 t1b +3 3 1 +drop view v; +test 7c.2.0.0.4 +with cte as (select +( +select sum(t1a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +( +select sum(t1c) from t3 where t3b > t1a group by t3b limit 1 +) as col2, +t1b from t1) select * from cte; +col1 col2 t1b +3 3 1 +test 7c.2.0.0.5 +create procedure p() select +( +select sum(t1a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +( +select sum(t1c) from t3 where t3b > t1a group by t3b limit 1 +) as col2, +t1b from t1; +call p(); +col1 col2 t1b +3 3 1 +call p(); +col1 col2 t1b +3 3 1 +drop procedure p; +"END GROUP" +test 7c.0.0 +select t1a from t1 -- select 1 +where t1a in +( +select t1a from ambiguous where t1a >= some -- select 2 +( +select t3a from t3 where t1a=t3b -- select 3 +) +); +t1a +1 +test 7c.0.1 +prepare s from 'select t1a from t1 -- select 1 +where t1a in +( +select t1a from ambiguous where t1a >= some -- select 2 +( +select t3a from t3 where t1a=t3b -- select 3 +) +)'; +execute s; +t1a +1 +execute s; +t1a +1 +deallocate prepare s; +test 7c.0.2 +select * from (select t1a from t1 -- select 1 +where t1a in +( +select t1a from ambiguous where t1a >= some -- select 2 +( +select t3a from t3 where t1a=t3b -- select 3 +) +)) dt; +t1a +1 +test 7c.0.3 +create view v as select t1a from t1 -- select 1 +where t1a in +( +select t1a from ambiguous where t1a >= some -- select 2 +( +select t3a from t3 where t1a=t3b -- select 3 +) +); +select * from v; +t1a +1 +select * from v; +t1a +1 +drop view v; +test 7c.0.4 +with cte as (select t1a from t1 -- select 1 +where t1a in +( +select t1a from ambiguous where t1a >= some -- select 2 +( +select t3a from t3 where t1a=t3b -- select 3 +) +)) select * from cte; +t1a +1 +test 7c.0.5 +create procedure p() select t1a from t1 -- select 1 +where t1a in +( +select t1a from ambiguous where t1a >= some -- select 2 +( +select t3a from t3 where t1a=t3b -- select 3 +) +); +call p(); +t1a +1 +call p(); +t1a +1 +drop procedure p; +"END GROUP" +test 7d.1.0.0 +select * from t1 +where t1c in +( +select * from +( +select t2a from t2 +where t2a in +( +select t3a from (select * from t3) table3 +where t3a in +( +select t4a from t4 +where t4a < any(select t5c from t5 where t5a > t3a) +) +) +) dt +); +t1a t1b t1c +1 1 1 +2 2 2 +test 7d.1.0.1 +prepare s from 'select * from t1 +where t1c in +( +select * from +( +select t2a from t2 +where t2a in +( +select t3a from (select * from t3) table3 +where t3a in +( +select t4a from t4 +where t4a < any(select t5c from t5 where t5a > t3a) +) +) +) dt +)'; +execute s; +t1a t1b t1c +1 1 1 +2 2 2 +execute s; +t1a t1b t1c +1 1 1 +2 2 2 +deallocate prepare s; +test 7d.1.0.2 +select * from (select * from t1 +where t1c in +( +select * from +( +select t2a from t2 +where t2a in +( +select t3a from (select * from t3) table3 +where t3a in +( +select t4a from t4 +where t4a < any(select t5c from t5 where t5a > t3a) +) +) +) dt +)) dt; +t1a t1b t1c +1 1 1 +2 2 2 +test 7d.1.0.3 +create view v as select * from t1 +where t1c in +( +select * from +( +select t2a from t2 +where t2a in +( +select t3a from (select * from t3) table3 +where t3a in +( +select t4a from t4 +where t4a < any(select t5c from t5 where t5a > t3a) +) +) +) dt +); +select * from v; +t1a t1b t1c +1 1 1 +2 2 2 +select * from v; +t1a t1b t1c +1 1 1 +2 2 2 +drop view v; +test 7d.1.0.4 +with cte as (select * from t1 +where t1c in +( +select * from +( +select t2a from t2 +where t2a in +( +select t3a from (select * from t3) table3 +where t3a in +( +select t4a from t4 +where t4a < any(select t5c from t5 where t5a > t3a) +) +) +) dt +)) select * from cte; +t1a t1b t1c +1 1 1 +2 2 2 +test 7d.1.0.5 +create procedure p() select * from t1 +where t1c in +( +select * from +( +select t2a from t2 +where t2a in +( +select t3a from (select * from t3) table3 +where t3a in +( +select t4a from t4 +where t4a < any(select t5c from t5 where t5a > t3a) +) +) +) dt +); +call p(); +t1a t1b t1c +1 1 1 +2 2 2 +call p(); +t1a t1b t1c +1 1 1 +2 2 2 +drop procedure p; +"END GROUP" +test 7d.2.0.0 +select * from t1 +where t1c in +( +select * from +( +select t2a from t2 +where t2a in +( +select t3a from (select * from t3) table3 +where t3a in +( +select t4a from t4 +where t4a < any(select t5c from t5 where t5a < t3a + t3b) +) +) +) dt +); +t1a t1b t1c +2 2 2 +test 7d.2.0.1 +prepare s from 'select * from t1 +where t1c in +( +select * from +( +select t2a from t2 +where t2a in +( +select t3a from (select * from t3) table3 +where t3a in +( +select t4a from t4 +where t4a < any(select t5c from t5 where t5a < t3a + t3b) +) +) +) dt +)'; +execute s; +t1a t1b t1c +2 2 2 +execute s; +t1a t1b t1c +2 2 2 +deallocate prepare s; +test 7d.2.0.2 +select * from (select * from t1 +where t1c in +( +select * from +( +select t2a from t2 +where t2a in +( +select t3a from (select * from t3) table3 +where t3a in +( +select t4a from t4 +where t4a < any(select t5c from t5 where t5a < t3a + t3b) +) +) +) dt +)) dt; +t1a t1b t1c +2 2 2 +test 7d.2.0.3 +create view v as select * from t1 +where t1c in +( +select * from +( +select t2a from t2 +where t2a in +( +select t3a from (select * from t3) table3 +where t3a in +( +select t4a from t4 +where t4a < any(select t5c from t5 where t5a < t3a + t3b) +) +) +) dt +); +select * from v; +t1a t1b t1c +2 2 2 +select * from v; +t1a t1b t1c +2 2 2 +drop view v; +test 7d.2.0.4 +with cte as (select * from t1 +where t1c in +( +select * from +( +select t2a from t2 +where t2a in +( +select t3a from (select * from t3) table3 +where t3a in +( +select t4a from t4 +where t4a < any(select t5c from t5 where t5a < t3a + t3b) +) +) +) dt +)) select * from cte; +t1a t1b t1c +2 2 2 +test 7d.2.0.5 +create procedure p() select * from t1 +where t1c in +( +select * from +( +select t2a from t2 +where t2a in +( +select t3a from (select * from t3) table3 +where t3a in +( +select t4a from t4 +where t4a < any(select t5c from t5 where t5a < t3a + t3b) +) +) +) dt +); +call p(); +t1a t1b t1c +2 2 2 +call p(); +t1a t1b t1c +2 2 2 +drop procedure p; +"END GROUP" +test 7e.1.0.0.1.0.1.0 +select * from (select * from t1 limit 1) dt where (select t1a != 0); +t1a t1b t1c +1 1 1 +test 7e.1.0.0.1.0.1.1 +prepare s from 'select * from (select * from t1 limit 1) dt where (select t1a != 0)'; +execute s; +t1a t1b t1c +1 1 1 +execute s; +t1a t1b t1c +1 1 1 +deallocate prepare s; +test 7e.1.0.0.1.0.1.2 +select * from (select * from (select * from t1 limit 1) dt where (select t1a != 0)) dt; +t1a t1b t1c +1 1 1 +test 7e.1.0.0.1.0.1.3 +create view v as select * from (select * from t1 limit 1) dt where (select t1a != 0); +select * from v; +t1a t1b t1c +1 1 1 +select * from v; +t1a t1b t1c +1 1 1 +drop view v; +test 7e.1.0.0.1.0.1.4 +with cte as (select * from (select * from t1 limit 1) dt where (select t1a != 0)) select * from cte; +t1a t1b t1c +1 1 1 +test 7e.1.0.0.1.0.1.5 +create procedure p() select * from (select * from t1 limit 1) dt where (select t1a != 0); +call p(); +t1a t1b t1c +1 1 1 +call p(); +t1a t1b t1c +1 1 1 +drop procedure p; +"END GROUP" +test 7e.1.0.0.1.0.1.0 +select * from t1 AS ta where ta.t1a IN +( +select t2a from t2 AS tb where tb.t2b >= SOME +( +select SUM(t4b) from t4 as tc group by t4a having ta.t1a=tc.t4a +) +); +t1a t1b t1c +1 1 1 +2 2 2 +test 7e.1.0.0.1.0.1.1 +prepare s from 'select * from t1 AS ta where ta.t1a IN +( +select t2a from t2 AS tb where tb.t2b >= SOME +( +select SUM(t4b) from t4 as tc group by t4a having ta.t1a=tc.t4a +) +)'; +execute s; +t1a t1b t1c +1 1 1 +2 2 2 +execute s; +t1a t1b t1c +1 1 1 +2 2 2 +deallocate prepare s; +test 7e.1.0.0.1.0.1.2 +select * from (select * from t1 AS ta where ta.t1a IN +( +select t2a from t2 AS tb where tb.t2b >= SOME +( +select SUM(t4b) from t4 as tc group by t4a having ta.t1a=tc.t4a +) +)) dt; +t1a t1b t1c +1 1 1 +2 2 2 +test 7e.1.0.0.1.0.1.3 +create view v as select * from t1 AS ta where ta.t1a IN +( +select t2a from t2 AS tb where tb.t2b >= SOME +( +select SUM(t4b) from t4 as tc group by t4a having ta.t1a=tc.t4a +) +); +select * from v; +t1a t1b t1c +1 1 1 +2 2 2 +select * from v; +t1a t1b t1c +1 1 1 +2 2 2 +drop view v; +test 7e.1.0.0.1.0.1.4 +with cte as (select * from t1 AS ta where ta.t1a IN +( +select t2a from t2 AS tb where tb.t2b >= SOME +( +select SUM(t4b) from t4 as tc group by t4a having ta.t1a=tc.t4a +) +)) select * from cte; +t1a t1b t1c +1 1 1 +2 2 2 +test 7e.1.0.0.1.0.1.5 +create procedure p() select * from t1 AS ta where ta.t1a IN +( +select t2a from t2 AS tb where tb.t2b >= SOME +( +select SUM(t4b) from t4 as tc group by t4a having ta.t1a=tc.t4a +) +); +call p(); +t1a t1b t1c +1 1 1 +2 2 2 +call p(); +t1a t1b t1c +1 1 1 +2 2 2 +drop procedure p; +"END GROUP" +test 7f.1.0.0.1.0.1.0 +select sum(c1) from v6; +sum(c1) +3 +test 7f.1.0.0.1.0.1.1 +prepare s from 'select sum(c1) from v6'; +execute s; +sum(c1) +3 +execute s; +sum(c1) +3 +deallocate prepare s; +test 7f.1.0.0.1.0.1.2 +select * from (select sum(c1) from v6) dt; +sum(c1) +3 +test 7f.1.0.0.1.0.1.3 +create view v as select sum(c1) from v6; +select * from v; +sum(c1) +3 +select * from v; +sum(c1) +3 +drop view v; +test 7f.1.0.0.1.0.1.4 +with cte as (select sum(c1) from v6) select * from cte; +sum(c1) +3 +test 7f.1.0.0.1.0.1.5 +create procedure p() select sum(c1) from v6; +call p(); +sum(c1) +3 +call p(); +sum(c1) +3 +drop procedure p; +"END GROUP" +test MDEV-32297.0 +SELECT * FROM +( +SELECT * FROM +( +SELECT * FROM +(SELECT 1 as "x") dt2 +) dt1 +WHERE +( +SELECT x+1 ORDER BY +( +SELECT 1 GROUP BY +(1 IN (SELECT x)) +) +) +) dt +WHERE x = 1; +x +1 +test MDEV-32297.1 +prepare s from 'SELECT * FROM +( +SELECT * FROM +( +SELECT * FROM +(SELECT 1 as "x") dt2 +) dt1 +WHERE +( +SELECT x+1 ORDER BY +( +SELECT 1 GROUP BY +(1 IN (SELECT x)) +) +) +) dt +WHERE x = 1'; +execute s; +x +1 +execute s; +x +1 +deallocate prepare s; +test MDEV-32297.2 +select * from (SELECT * FROM +( +SELECT * FROM +( +SELECT * FROM +(SELECT 1 as "x") dt2 +) dt1 +WHERE +( +SELECT x+1 ORDER BY +( +SELECT 1 GROUP BY +(1 IN (SELECT x)) +) +) +) dt +WHERE x = 1) dt; +x +1 +test MDEV-32297.3 +create view v as SELECT * FROM +( +SELECT * FROM +( +SELECT * FROM +(SELECT 1 as "x") dt2 +) dt1 +WHERE +( +SELECT x+1 ORDER BY +( +SELECT 1 GROUP BY +(1 IN (SELECT x)) +) +) +) dt +WHERE x = 1; +select * from v; +x +1 +select * from v; +x +1 +drop view v; +test MDEV-32297.4 +with cte as (SELECT * FROM +( +SELECT * FROM +( +SELECT * FROM +(SELECT 1 as "x") dt2 +) dt1 +WHERE +( +SELECT x+1 ORDER BY +( +SELECT 1 GROUP BY +(1 IN (SELECT x)) +) +) +) dt +WHERE x = 1) select * from cte; +x +1 +test MDEV-32297.5 +create procedure p() SELECT * FROM +( +SELECT * FROM +( +SELECT * FROM +(SELECT 1 as "x") dt2 +) dt1 +WHERE +( +SELECT x+1 ORDER BY +( +SELECT 1 GROUP BY +(1 IN (SELECT x)) +) +) +) dt +WHERE x = 1; +call p(); +x +1 +call p(); +x +1 +drop procedure p; +"END GROUP" +test MDEV-6054.0 +SELECT * FROM +( +SELECT DISTINCT * FROM t1 +) AS sq +WHERE t1a in +( +SELECT t2c FROM t2 WHERE t2c <= sq.t1b +); +t1a t1b t1c +1 1 1 +2 2 2 +test MDEV-6054.1 +prepare s from 'SELECT * FROM +( +SELECT DISTINCT * FROM t1 +) AS sq +WHERE t1a in +( +SELECT t2c FROM t2 WHERE t2c <= sq.t1b +)'; +execute s; +t1a t1b t1c +1 1 1 +2 2 2 +execute s; +t1a t1b t1c +1 1 1 +2 2 2 +deallocate prepare s; +test MDEV-6054.2 +select * from (SELECT * FROM +( +SELECT DISTINCT * FROM t1 +) AS sq +WHERE t1a in +( +SELECT t2c FROM t2 WHERE t2c <= sq.t1b +)) dt; +t1a t1b t1c +1 1 1 +2 2 2 +test MDEV-6054.3 +create view v as SELECT * FROM +( +SELECT DISTINCT * FROM t1 +) AS sq +WHERE t1a in +( +SELECT t2c FROM t2 WHERE t2c <= sq.t1b +); +select * from v; +t1a t1b t1c +1 1 1 +2 2 2 +select * from v; +t1a t1b t1c +1 1 1 +2 2 2 +drop view v; +test MDEV-6054.4 +with cte as (SELECT * FROM +( +SELECT DISTINCT * FROM t1 +) AS sq +WHERE t1a in +( +SELECT t2c FROM t2 WHERE t2c <= sq.t1b +)) select * from cte; +t1a t1b t1c +1 1 1 +2 2 2 +test MDEV-6054.5 +create procedure p() SELECT * FROM +( +SELECT DISTINCT * FROM t1 +) AS sq +WHERE t1a in +( +SELECT t2c FROM t2 WHERE t2c <= sq.t1b +); +call p(); +t1a t1b t1c +1 1 1 +2 2 2 +call p(); +t1a t1b t1c +1 1 1 +2 2 2 +drop procedure p; +"END GROUP" +test MDEV-26944.0 +SELECT x FROM +( +SELECT t1a AS y, (SELECT y FROM t1 LIMIT 1 ) AS x FROM t1 a +) dt; +x +1 +2 +test MDEV-26944.1 +prepare s from 'SELECT x FROM +( +SELECT t1a AS y, (SELECT y FROM t1 LIMIT 1 ) AS x FROM t1 a +) dt'; +execute s; +x +1 +2 +execute s; +x +1 +2 +deallocate prepare s; +test MDEV-26944.2 +select * from (SELECT x FROM +( +SELECT t1a AS y, (SELECT y FROM t1 LIMIT 1 ) AS x FROM t1 a +) dt) dt; +x +1 +2 +test MDEV-26944.3 +create view v as SELECT x FROM +( +SELECT t1a AS y, (SELECT y FROM t1 LIMIT 1 ) AS x FROM t1 a +) dt; +select * from v; +x +1 +2 +select * from v; +x +1 +2 +drop view v; +test MDEV-26944.4 +with cte as (SELECT x FROM +( +SELECT t1a AS y, (SELECT y FROM t1 LIMIT 1 ) AS x FROM t1 a +) dt) select * from cte; +x +1 +2 +test MDEV-26944.5 +create procedure p() SELECT x FROM +( +SELECT t1a AS y, (SELECT y FROM t1 LIMIT 1 ) AS x FROM t1 a +) dt; +call p(); +x +1 +2 +call p(); +x +1 +2 +drop procedure p; +"END GROUP" +test MDEV-30756.0 +SELECT * FROM t1 k WHERE 1 IN +( +SELECT 1 FROM t1 WHERE EXISTS +( +SELECT t1a FROM +( +SELECT 1 FROM t1 limit 1 +) d GROUP BY +( +SELECT 1 FROM t1 dt HAVING t1a limit 1 +) BETWEEN 0 AND 10 HAVING 1 +) +); +t1a t1b t1c +1 1 1 +2 2 2 +test MDEV-30756.1 +prepare s from 'SELECT * FROM t1 k WHERE 1 IN +( +SELECT 1 FROM t1 WHERE EXISTS +( +SELECT t1a FROM +( +SELECT 1 FROM t1 limit 1 +) d GROUP BY +( +SELECT 1 FROM t1 dt HAVING t1a limit 1 +) BETWEEN 0 AND 10 HAVING 1 +) +)'; +execute s; +t1a t1b t1c +1 1 1 +2 2 2 +execute s; +t1a t1b t1c +1 1 1 +2 2 2 +deallocate prepare s; +test MDEV-30756.2 +select * from (SELECT * FROM t1 k WHERE 1 IN +( +SELECT 1 FROM t1 WHERE EXISTS +( +SELECT t1a FROM +( +SELECT 1 FROM t1 limit 1 +) d GROUP BY +( +SELECT 1 FROM t1 dt HAVING t1a limit 1 +) BETWEEN 0 AND 10 HAVING 1 +) +)) dt; +t1a t1b t1c +1 1 1 +2 2 2 +test MDEV-30756.3 +create view v as SELECT * FROM t1 k WHERE 1 IN +( +SELECT 1 FROM t1 WHERE EXISTS +( +SELECT t1a FROM +( +SELECT 1 FROM t1 limit 1 +) d GROUP BY +( +SELECT 1 FROM t1 dt HAVING t1a limit 1 +) BETWEEN 0 AND 10 HAVING 1 +) +); +select * from v; +t1a t1b t1c +1 1 1 +2 2 2 +select * from v; +t1a t1b t1c +1 1 1 +2 2 2 +drop view v; +test MDEV-30756.4 +with cte as (SELECT * FROM t1 k WHERE 1 IN +( +SELECT 1 FROM t1 WHERE EXISTS +( +SELECT t1a FROM +( +SELECT 1 FROM t1 limit 1 +) d GROUP BY +( +SELECT 1 FROM t1 dt HAVING t1a limit 1 +) BETWEEN 0 AND 10 HAVING 1 +) +)) select * from cte; +t1a t1b t1c +1 1 1 +2 2 2 +test MDEV-30756.5 +create procedure p() SELECT * FROM t1 k WHERE 1 IN +( +SELECT 1 FROM t1 WHERE EXISTS +( +SELECT t1a FROM +( +SELECT 1 FROM t1 limit 1 +) d GROUP BY +( +SELECT 1 FROM t1 dt HAVING t1a limit 1 +) BETWEEN 0 AND 10 HAVING 1 +) +); +call p(); +t1a t1b t1c +1 1 1 +2 2 2 +call p(); +t1a t1b t1c +1 1 1 +2 2 2 +drop procedure p; +"END GROUP" +drop view v1, v2, v3, v4, v5, v6; +drop table t1, t2, t3, t4, t5, t6, t7, ambiguous; +# +# MDEV-32766 +# +CREATE TABLE t0 (a int) ; +INSERT INTO `t0` VALUES (1),(2),(3); +( SELECT a c28 FROM t0 LIMIT 5 ) ORDER BY ( SELECT c28 FROM t0 limit 1); +c28 +1 +2 +3 +DROP TABLE t0; diff --git a/mysql-test/main/outer_reference.test b/mysql-test/main/outer_reference.test new file mode 100644 index 0000000000000..daa3b930c2fc0 --- /dev/null +++ b/mysql-test/main/outer_reference.test @@ -0,0 +1,1612 @@ +/* index to characterization test + +[1st digit, Class, see below]. +[# of outer references to a parent]. +[# of outer references to a subquery]. +[# of outer references to parent from subquery]. +[# of item subselects]. +[# references to expressions]. +[# degenerated selects]. +[Execution method, see below]. + +Class 0, not mergeable +Class 1, view mergeable +Class 1a, derived table mergeable +Class 1b, cte mergeable +Class 2, subquery mergeable +Class 3, multiple outer_select paths +Class 4, unions +Class 5, subqueries in group by & order by with references to parent select_lex +Class 6, subquery merge into derived merge +Class 7, odds and ends + +Execution method, + 0 normal + 1 prepared statement + 2 wrapped in a derived table + 3 wrapped in a view + 4 wrapped in a CTE + 5 as a procedure +*/ + +create table t1 (t1a int, t1b int, t1c int) engine=myisam; +insert into t1 values (1,1,1),(2,2,2); + +create table t2 (t2a int, t2b int, t2c int) engine=myisam; +insert into t2 values (1,1,1),(2,2,2),(3,3,3); + +create table t3 (t3a int, t3b int, t3c int) engine=myisam; +insert into t3 values (1,1,1),(2,2,2),(3,3,3),(4,4,4); + +create table t4 (t4a int, t4b int, t4c int) engine=myisam; +insert into t4 values (1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5); + +create table t5 (t5a int, t5b int, t5c int) engine=myisam; +insert into t5 values (1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),(6,6,6); + +create table t6 (t6a int, t6b int, t6c int) engine=myisam; +insert into t6 values (1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),(6,6,6),(7,7,7); + +create table t7 (t7a int, t7b int, t7c int) engine=myisam; +insert into t7 values (1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),(6,6,6),(7,7,7), +(8,8,8); + +create table ambiguous like t1; +# different data to t1 +insert into ambiguous values (1, 1, 1); + +create view v1 (v1a, v1b) as select t7a, t7b from t7 where t7c > 4; +create view v2 (v2a, v2b) as + select t7a*t5c, t7b*t5c from t7, t5 where t7a = t5a and t7c > 4; +create view v3 (v3a) as select t1a from t1 where exists +( + select t2a from t2 where t2a = t1a +); +create view v4 (v4a) as select t1a from t1 where exists +( + select t2a from t2 where t2a = t1a and t2b = t1b +); +create view v5 (v5a, v5b, v5c) as select * from t5 limit 100; +create view v6 as select t1a as c1, (select c1) as c2, + (select c2) as c3 from t1; + +# test case X.0.1.0.0.1.0 +# non mergeable with outer reference + +let $ver= 0.1.0.0.1.0.0.0; +let $qry= +select * from t1, t6 where t6a=t1a or -- select 1 +( + select max(t4a) from t4 where t4c < t1b -- select 2 +) <> 0; + +--source execute_various_ways.inc + +# reference to a view in where clause, non-mergeable + +let $ver= 0a.1.0.0.1.0.0.0; +let $qry= select * from v1 where v1a >= any +( + select t4a from t4 where t4b >= v1b +); + +--source execute_various_ways.inc + + +let $ver= 0.1.1.0.2.0.1; +let $qry= +select * from t1, t2 where t2b in +( + select + ( + select t1a from t1 order by t1b, t2b limit 1 + ) as d + from t1 group by + ( + select d + ) +); + + +--source execute_various_ways.inc + +# Class 1, view mergeable + +# mergeable view with outer reference to merged select inside a view +# note, reference is indirectly to table number 2 + +let $ver= 1a.1.0.0.1.0.0.0; +let $qry= select * from t6, v1 where t6a=v1a and -- select 1 +( + select max(t4a) from t4 where t4c < v1b -- select 2 +) <> 0; + +--source execute_various_ways.inc + +# include trivial degenerated select +let $ver= 1a.1.0.0.1.0.1.0; +let $qry= select * from t6, v1 where t6a=v1a and -- select 1 +( + select max(t4a) from t4 where -- select 2 + ( + select t4c < v1b -- select 3 + ) +) <> 0; + +--source execute_various_ways.inc + +# reference to a view in where clause, mergeable +let $ver= 1b.1.0.0.1.0.0.0; +let $qry= select * from v1 where v1a in +( + select t7a from t7 where t7b >= v1b +); + +--source execute_various_ways.inc + +# reference to a view in where clause, mergeable +let $ver= 1b.1.0.0.1.0.1.0; +let $qry= select * from v1 where v1a in +( + select t7a from t7 where + ( + select t7b >= v1b + ) +); + +--source execute_various_ways.inc + +# outer reference within aggregate function to table +let $ver= 1c.1.0.0.1.0.0.0; +let $qry= select * from t7 where t7a in +( + select avg(t7b) from t1 where t1b = t7b-5 +); + +--source execute_various_ways.inc + +let $ver= 1c.1.0.0.1.0.1.0; +let $qry= select * from t7 where t7a in +( + select avg(t7b) from t1 where + ( + select t1b = t7b-5 + ) +); + +--source execute_various_ways.inc + +# outer reference within aggregate function to mergable view +let $ver= 1d.1.0.0.1.0.0.0; +let $qry= select * from v1 where v1a in +( + select avg(v1b) from t1 where t1b = v1b-5 +); + +--source execute_various_ways.inc + +# outer reference within aggregate function to nonmergable view +let $ver= 1e.1.0.0.1.0.0.0; +let $qry= select * from v5 where v5a in +( + select avg(v5b) from t1 where t1b = v5b-5 +); + +--source execute_various_ways.inc + + +# mergeable view with outer reference to merged select inside a view +# note, reference is to an expression with 2 tables not a simple field + +let $ver= 1.1.0.0.1.1.0.0; +let $qry=select * from t6, v2 where t6a*t6b=v2a and -- select 1 +( + select max(t4a) from t4 where t4c < v2b -- select 2 +) <> 0; + +--source execute_various_ways.inc + +let $ver= 1.1.0.0.1.1.1.0; +let $qry=select * from t6, v2 where t6a*t6b=v2a and -- select 1 +( + select max(t4a) from t4 where -- select 2 + ( + select t4c < v2b -- select 3 + ) +) <> 0; + +--source execute_various_ways.inc + +let $ver= 1.1.0.0.1.1.2.0; +let $qry=select * from t6, v2 where -- select 1 +( + select t6a*t6b=v2a -- select 2 +) +and +( + select max(t4a) from t4 where -- select 3 + ( + select t4c < v2b -- select 4 + ) +) <> 0; + +--source execute_various_ways.inc + + +# mergeable view with two outer references to merged select inside a view +# not, reference is indirectly to table number 2 + +let $ver= 1.2.0.0.1.1.0; +let $qry= +select * from t6, v1, v2 where t6a=v1a and t6b * t6a = v2b and -- select 1 +( + select max(t4a) from t4, t5 -- select 2 + where t5a = t4a and t4c < v1b and t5b < v2b +) <> 0; + +--source execute_various_ways.inc + + +# mergeable view with two outer references to merged select inside a view +# references to different select levels + +let $ver= 1.1.1.0.2.1.0.0; +let $qry= select * from t6, v1 where t6a=v1a and t6b in -- select 1 +( + select sqrt(v2b) from v2 where -- select 2 + ( + select max(t4a) from t4, t5 -- select 3 + where t5a = t4a and t4c < v1b and t5b < v2b + ) <> 0 +); + +--source execute_various_ways.inc + + +# test remove_references_to() +# we need an outer reference that is resolved in the query that where it is +# defined is merged into. +# here t4c in select 2 is outer reference before merge of select 2 into select 1 +# not after + +let $ver= 1.1.1.1.2.0.0; +let $qry=select t1a from t1 join t4 on t1c = t4c -- select 1 parent +where t1a in +( + select t2a from t2 -- select 2 child + where t2b >= any + ( + select t3b from t3 where t3c >= t1b -- select 3 + ) + and t2b >= t4c +); + +--source execute_various_ways.inc + +let $ver= 1.1.1.1.2.1.0; +let $qry=select t1a from t1 join t4 on t1c = t4c -- select 1 parent +where t1a in +( + select t2a from t2 -- select 2 child + where t2b >= any + ( + select t3b from t3 where -- select 3 + ( + select t3c >= t1b -- select 4 + ) + ) + and t2b >= t4c +); + +--source execute_various_ways.inc + + +# test remove_references_to() +# we need an outer reference that is resolved in the query that where it is +# defined is merged into. +# here t4c in select 2 is outer reference before merge of select 2 into select 1 +# not after + +let $ver= 1.3.2.2.2.0.0.0; +let $qry= select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( + select t2a from t2 -- select 2 + where t2b >= any + ( + select t3b from t3 where t3c >= t1b -- select 3 + and t3a >= t1c and t3b >= t1a + ) + and t2b >= t4c and t2a >= t4a +); + +--source execute_various_ways.inc + + +let $ver= 1.3.2.2.2.0.1.0; +let $qry= select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( + select t2a from t2 -- select 2 + where t2b >= any + ( + select t3b from t3 where t3c >= t1b -- select 3 + and + ( + select t3a >= t1c and t3b >= t1a -- select 4 + ) + ) + and t2b >= t4c and t2a >= t4a +); + +--source execute_various_ways.inc + + +let $ver= 1.3.2.2.2.0.2.0; +let $qry= select t1a from t1 join t4 on t1c = t4c -- select 1 +where t1a in +( + select t2a from t2 -- select 2 + where t2b >= any + ( + select t3b from t3 where -- select 3 + ( + select t3c >= t1b -- select 4 + ) + and + ( + select t3a >= t1c and t3b >= t1a -- select 5 + ) + ) + and t2b >= t4c and t2a >= t4a +); + +--source execute_various_ways.inc + + +# test remove_references_to() + +let $ver= 1.3.1.1.2.1.0.0; +let $qry= select t7a from t7 join v2 on t7b*t7c = v2b -- select 1 +where t7a in +( + select t6a from t6 -- select 2 + where t6b >= any + ( + select t3b*t3c from t3 where t3c <= t7b -- select 3 + and t3a <= t7c and t3b <= t7a + ) + and t6b <= v2b +); + +--source execute_various_ways.inc + + +# test remove_references_to() + +let $ver= 1.3.2.2.2.2.0.0; +let $qry= select t7a from t7 join v2 on t7b*t7c = v2b -- select 1 +where t7a in +( + select t6a from t6 -- select 2 + where t6b >= any + ( + select t3b*t3c from t3 where t3c <= t7b -- select 3 + and t3a <= t7c and t3b <= t7a + ) + and t6b <= v2b and t6a <= v2a +); + +--source execute_various_ways.inc + + + +# Class 1a, derived mergeable +# mergeable derived table with outer reference to merged select + +let $ver= 1a.2.0.0.1.0.0.0; +let $qry= +select * from t6, -- select 1 +( + select t7a as dt1a, t7b as dt1b from t7 where t7c > 4 -- select 2 +) dt1 +where t6a=dt1a and +( + select max(t4a) from t4 where t4c <= dt1b -- select 3 +) <> 0; + +--source execute_various_ways.inc + + +let $ver= 1a.2.0.0.1.0.1.0; +let $qry= +select * from t6, -- select 1 +( + select t7a as dt1a, t7b as dt1b from t7 where -- select 2 + ( + select t7c > 4 -- select 3 + ) +) dt1 +where t6a=dt1a and +( + select max(t4a) from t4 where t4c <= dt1b -- select 4 +) <> 0; + +--source execute_various_ways.inc + + +let $ver= 1a.2.0.0.1.0.2.0; +let $qry= +select * from t6, -- select 1 +( + select t7a as dt1a, t7b as dt1b from t7 where -- select 2 + ( + select t7c > 4 -- select 3 + ) +) dt1 +where t6a=dt1a and +( + select max(t4a) from t4 where -- select 4 + ( + select t4c <= dt1b -- select 5 + ) +) <> 0; + +--source execute_various_ways.inc + + +let $ver= 1a.3.1.1.2.1.0.0; +let $qry= select t6a from t6 -- select 1 +join +( + select t7a as dt1a, t7b*t7c as dt1b from t7 where t7c > 4 +) dt1 on t6c = dt1a +where t6a in +( + select t2a+3 from t2 -- select 2 + where t2b >= any + ( + select t3b from t3 where t3c <= t6b -- select 3 + and t3a <= t6c and t3b <= t6a + ) + and t2b <= dt1b +); + +--source execute_various_ways.inc + + +let $ver= 1a.3.1.1.2.2.0.0; +let $qry= select t6a from t6 -- select 1 +join (select t7a as dt1a, t7b*t7c as dt1b, t7b*2 as dt1c from t7 + where t7c > 4) dt1 + on t6c = dt1a +where t6a in +( + select t2a+3 from t2 -- select 2 + where t2b >= any + ( + select t3b from t3 where t3c <= t6b -- select 3 + and t3a <= t6c and t3b <= dt1c + ) + and t2b <= dt1b +); + +--source execute_various_ways.inc + + +# Class 1b, cte mergeable +# mergeable derived table with outer reference to merged select + +let $ver= 1b.2.0.0.1.0.0; +let $qry= with cte1 (c1, c2) as (select t7a, t7b from t7 where t7c > 4) +select * from t6, cte1 +where t6a=c1 and -- select 1 +( + select max(t4a) from t4 where t4c <= c2 -- select 2 +) <> 0; + +--source execute_various_ways.inc + + +let $ver= 1b.2.0.0.1.0.1; +let $qry= with cte1 (c1, c2) as (select t7a, t7b from t7 where t7c > 4) +select * from t6, cte1 +where t6a=c1 and -- select 1 +( + select max(t4a) from t4 where -- select 2 + ( + select t4c <= c2 -- select 3 + ) +) <> 0; + +--source execute_various_ways.inc + + +let $ver= 1b.3.1.1.2.1.0; +let $qry= with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 where t7c > 4) +select t6a from t6 -- select 1 +join cte1 + on t6c = c1 +where t6a in +( + select t2a+3 from t2 -- select 2 + where t2b >= any + ( + select t3b from t3 where t3c <= t6b -- select 3 + and t3a <= t6c and t3b <= t6a + ) + and t2b <= c2 +); + +--source execute_various_ways.inc + + +let $ver= 1b.3.1.1.2.1.1; +let $qry= with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 + where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 + on t6c = c1 +where t6a in +( + select t2a+3 from t2 -- select 2 + where t2b >= any + ( + select t3b from t3 where t3c <= t6b -- select 3 + and t3a <= t6c and t3b <= t6a + ) + and t2b <= c2 +); + +--source execute_various_ways.inc + + +let $ver= 1b.3.1.1.2.1.2; +let $qry= with cte1 (c1, c2) as (select t7a, t7b*t7c from t7 + where (select t7c > 4)) +select t6a from t6 -- select 1 +join cte1 + on t6c = c1 +where t6a in +( + select t2a+3 from t2 -- select 2 + where t2b >= any + ( + select t3b from t3 where -- select 3 + ( + select t3c <= t6b -- select 3 + and t3a <= t6c and t3b <= t6a + ) + ) + and t2b <= c2 +); + +--source execute_various_ways.inc + + +# Class 2, mergeable subquery typically +# select ... col in (subquery) + +# mergeable subquery with two outer references to merged select +# references to different select levels +let $ver=2.1.0.0.1.0: +let $qry= select * from t1, t2 where t1a=t2a and t1b in -- select 1 +( + select t3b from t3 -- select 2 + where t3b <= t2b +); + +--source execute_various_ways.inc + + +# mergeable subquery with two outer references to merged select +# references to different select levels + +let $ver= 2.1.0.0.1.1.0.0; +let $qry= select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( + select t3b from t3 -- select 2 + where t3b <= v2b +); + +--source execute_various_ways.inc + +let $ver= 2.1.0.0.1.1.0.1; +let $qry= select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( + select t3b from t3 -- select 2 + where + ( + select t3b <= v2b + ) +); + +--source execute_various_ways.inc + + +let $ver= 2.1.0.0.1.1.0.2; +let $qry= select * from t1, v2 where -- select 1 +( + select t1a<=v2a -- select 2 +) +and t1b in +( + select t3b from t3 -- select 3 + where + ( + select t3b <= v2b + ) +); + +--source execute_various_ways.inc + + +# mergeable view with outer reference to merged select inside a view + +let $ver= 2.0.1.1.1.0.0.0; +let $qry= select * from t1 -- select 2 +where t1c in +( + select t2a from t2 -- select 3 + where t2b in (select t3b from t3 where t3a >= t2c) -- select 4 +); + +--source execute_various_ways.inc + + +let $ver= 2.0.1.1.1.0.0.1; +let $qry= select * from t1 +where t1c in +( + select t2a from t2 + where t2b in + ( + select t3b from t3 where + ( + select t3a >= t2c + ) + ) +); + +--source execute_various_ways.inc + + +# mergeable subquery with two outer references to merged select +# references to different select levels + +let $ver= 2.1.0.0.1.2.0.0; +let $qry= select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( + select t3b from t3 -- select 2 + where t3b <= v2b and t3a <= v2a +); + +--source execute_various_ways.inc + + +let $ver= 2.1.0.0.1.2.0.1; +let $qry= select * from t1, v2 where t1a<=v2a and t1b in -- select 1 +( + select t3b from t3 -- select 2 + where + ( + select t3b <= v2b and t3a <= v2a + ) +); + +--source execute_various_ways.inc + + +# mergeable subquery with two outer references to merged select +# references to different select levels + +let $ver= 2.2.0.0.1.0.0.0; +let $qry= select * from t1, t2 where t1a=t2a and t1b in -- select 1 +( + select t3b from t3 -- select 2 + where t3b <= t1a*t2a +); + +--source execute_various_ways.inc + + +# mergeable subquery with two outer references to merged select +# references to different select levels +let $ver= 2.1.1.0.2.0.0.0; +let $qry= select * from t6, t7 where t6a=t7a and t6b in -- select 1 +( + select t2b from t2 where -- select 2 + ( + select max(t4a) from t4, t5 -- select 3 + where t5a = t4a and t4c < t7b and t5b < t2b + ) <> 0 +); + +--source execute_various_ways.inc + + +# mergeable subquery with two outer references to merged select +# references to different select levels + +let $ver= 2.2.1.0.2.0.0.0; +let $qry= select * from t6, t7 where t6a=t7a and t6b in -- select 1 +( + select t2b from t2 where -- select 2 + ( + select max(t4a) from t4, t5 -- select 3 + where t5a = t4a and t4c < t7b and t5b < t2b*t6a + ) <> 0 +); + +--source execute_various_ways.inc + + +# Class 3, multiple outer_select paths + +# next we need to test Item_belongs_to by introducing an element that fails +# the test +# outer_reference t2a which is resolved in select 1 does not belong to +# Item_subselect t1a in (select #2). +# similarly, t1a, resolved in the same place, does not belong in +# Item_subselect t2a in (select #4). + +let $ver= 3.2.0.0.2.0.0.0; +let $qry= select * from t1, t2 -- select #1, parent +where +t1a in +( + select t3b from t3 -- select #2, merged + where 10 > + ( + select count(*) from t4 where t4b < t1a -- select #3 + ) +) +and +t2a in +( + select t5c from t5 -- select #4, merged + where 10 > + ( + select count(*) from t6 where t6b < t2a -- select #5 + ) +); + +--source execute_various_ways.inc + + +let $ver= 3.2.0.0.2.0.0.2; +let $qry= select * from t1, t2 -- select #1, parent +where +t1a in +( + select t3b from t3 -- select #2, merged + where 10 > + ( + select count(*) from t4 where -- select #3 + ( + select t4b < t1a -- select #4 + ) + ) +) +and +t2a in +( + select t5c from t5 -- select #5, merged + where 10 > + ( + select count(*) from t6 where -- select #5 + ( + select t6b < t2a -- select #6 + ) + ) +); + +--source execute_various_ways.inc + + + +# as above but with outer references in count aggregation function + +let $ver= 3a.2.0.0.2.0.0.0; +let $qry= select * from t1, t2 -- select #1, parent +where +t1a in +( + select t3b from t3 -- select #2, merged + where 10 > + ( + select count(t3c) from t4 where t4b < t1a -- select #3 + ) +) +and +t2a in +( + select t5c from t5 -- select #4, merged + where 10 > + ( + select count(t5a) from t6 where t6b < t2a -- select #5 + ) +); + +--source execute_various_ways.inc + + + +# next we need to test Item_belongs_to by introducing an element +# that fails the test. +# outer_reference t2a which is resolved in select 1 does not belong to +# Item_subselect t1a in (select #2). +# similarly, t1a, resolved in the same place, does not belong in +# Item_subselect t2a in (select #4). + +let $ver= 3.2.0.0.2.2.0.0; +let $qry= select * from v1, v2 -- select #1 +where +v1a in +( + select t5b from t5 -- select #2 + where 100 > + ( + select count(*) from t4 where t4b < v1a -- select #3 + ) +) +and +v2a in +( + select t7c*t7a from t7 -- select #4 + where 100 > + ( + select count(*) from t6 where t6b < v2a -- select #5 + ) +); + +--source execute_various_ways.inc + + +# as above but unable to do top level merge due to disjunction in where clause +let $ver= 3a.2.0.0.2.0.0.0; +let $qry= select * from t1, t2 -- select #1 +where +t1a in +( + select t5b from t5 -- select #2 + where 100 > + ( + select count(*) from t4 where t4b < t1a -- select #3 + ) +) +or +t2a in +( + select t7c*t7a from t7 -- select #4 + where 100 > + ( + select count(*) from t6 where t6b < t2a -- select #5 + ) +); + +--source execute_various_ways.inc + + +let $ver= 3a.2.0.0.2.0.0.2; +let $qry= select * from t1, t2 -- select #1 +where +t1a in +( + select t5b from t5 -- select #2 + where 100 > + ( + select count(*) from t4 where -- select #3 + ( + select t4b < t1a -- select #4 + ) + ) +) +or +t2a in +( + select t7c*t7a from t7 -- select #5 + where 100 > + ( + select count(*) from t6 where -- select #6 + ( + select t6b < t2a -- select #7 + ) + ) +); + +--source execute_various_ways.inc + + +# as above but unable to do top level merge due to disjunction in where clause +# and reference to outer column in aggregation function +let $ver= 3b.2.0.0.2.0.0.0; +let $qry= select * from t1, t2 -- select #1 +where +t1a in +( + select t5b from t5 -- select #2 + where 100 > + ( + select count(t5a) from t4 where t4b < t1a -- select #3 + ) +) +or +t2a in +( + select t7c*t7a from t7 -- select #4 + where 100 > + ( + select count(t7b) from t6 where t6b < t2a -- select #5 + ) +); + +--source execute_various_ways.inc + + +let $ver= 3a.2.0.0.2.2.0.0; +let $qry= select * from v1, v2 -- select #1 +where +v1a in +( + select t5b from t5 -- select #2 + where 100 > + ( + select count(*) from t4 where t4b < v1a -- select #3 + ) +) +or +v2a in +( + select t7c*t7a from t7 -- select #4 + where 100 > + ( + select count(*) from t6 where t6b < v2a -- select #5 + ) +); + +--source execute_various_ways.inc + + + + +# Class 4, unions +# unions will prevent merges, but for the sake of numbering, we will continue +# as if they don't + +let $ver= 4.1.1.0.4.0.0.0; +let $qry= select t1a from t1 -- select 1, parent +where t1a in +( + select t2c from t2 where t2a >= some -- select 2, child + ( + select t3a from t3 where t3b in -- select 3, parent + ( + select t4a from t4 where t4b > t2c -- select 4, child + ) + union + select t5a from t5 where t5b in -- select 5, parent + ( + select t6a from t6 where t6b in -- select 6, child, parent + ( + select t7a from t7 where t7b >= t1c -- select 7, child + ) + ) + ) +); + +--source execute_various_ways.inc + + +let $ver= 4.2.1.0.4.0.0.1; +let $qry= select t1a from t1 -- select 1, parent +where t1a in +( + select t2a from t2 where t2b >= some -- select 2, child + ( + select t3a from t3 where t3b in -- select 3, non-mergable + ( + select t4a from t4 where -- select 4 + ( + select t4b >= t1a -- select 5 + ) + and t4c in + ( + select t6a from t6 where t6b >= t2b -- select 6, child + ) + union + select t4a from t4 where t4a > t1a -- select 7 + ) + ) +); + +--source execute_various_ways.inc + + +let $ver= 4.2.1.0.4.0.0.2; +let $qry= select t1a from t1 -- select 1, parent +where t1a in +( + select t2a from t2 where t2b >= some -- select 2, child + ( + select t3a from t3 where t3b in -- select 3, non-mergable + ( + select t4a from t4 where -- select 4 + ( + select t4b >= t1a -- select 5 + ) + and t4c in + ( + select t6a from t6 where -- select 6, child + ( + select t6b >= t2b -- select 7 + ) + ) + union + select t4a from t4 where t4a > t1a -- select 8 + ) + ) +); + +--source execute_various_ways.inc + + +let $ver= 4a.2.1.0.4.0.0; +let $qry= select t1a from t1 -- select 1, parent +where t1a in +( + select t2a from t2 where t2b >= some -- select 2, + ( + select t3a from t3 where t3b in -- select 3, + ( + select t4a from t4 where t4b >= t1a and t4c in -- select 4, parent + ( + select t6a from t6 where t6b >= t2b -- select 5, child O.R. + ) + ) + ) +) +union +select t7a from t7 -- select 6 +where t7a in +( + select t4a from t4 where t4a > t7a -- select 7, O.R. +); + +--source execute_various_ways.inc + + +let $ver= 4b.2.1.0.4.0.0.0; +let $qry= select t1a from t1 -- select 1, parent +where t1a in +( + select t2a from t2 where t2b >= some -- select 2, + ( + select t3a from t3 where t3b in -- select 3, + ( + select t4a from t4 where t4b >= t1a and t4c in -- select 4, parent + ( + select t6a from t6 where t6b >= t2b -- select 5, child O.R. + ) + ) + ) + union + select t7a from t7 -- select 6 + where t7a in + ( + select t4a from t4 where t4a > t7a -- select 7, O.R. + ) +); + +--source execute_various_ways.inc + + +# swap to derived table instead of subquery +# Note: scope of search resolution cannot escape derived table. +# unable to parse test case 4.0.1.0.0.3.0 +let $ver= 4.0.1.0.3.0.0.0; +let $qry= select t1a from t1, -- select 1, parent +( + select t2a from t2 where t2b >= some -- select 2, child + ( + select t3a from t3 where t3b in -- select 3, non-mergable + ( + select t4a from t4 where t4c in -- select 4, parent + ( + select t6a from t6 where t6b >= t2b -- select 5, child + ) + union + select t4a from t4 -- select 6 + ) + ) +) dt +where t1a = t2a; + +--source execute_various_ways.inc + + +let $ver= 4.0.1.0.3.0.0.1; +let $qry= select t1a from t1, -- select 1, parent +( + select t2a from t2 where t2b >= some -- select 2, child + ( + select t3a from t3 where t3b in -- select 3, non-mergable + ( + select t4a from t4 where t4c in -- select 4, parent + ( + select t6a from t6 where t6b >= t2b -- select 5, child + ) + union + select t2b -- select 6 + ) + ) +) dt +where t1a = t2a; + +--source execute_various_ways.inc + + +let $ver= 4a.0.1.0.3.0.0.0; +let $qry= select t1a from t1, -- select 1, parent +( + select t2a from t2 where t2b >= some -- select 2, child + ( + select t3a from t3 where t3b in -- select 3, non-mergable + ( + select t4a from t4 where t4c in -- select 4, parent + ( + select t6a from t6 where t6b >= t2b -- select 5, child + ) + ) + ) +) dt +where t1a = t2a +union +select t5a from t5 where t5b in +( + select t7b from t7 where t7c < t5c +); + +--source execute_various_ways.inc + + +let $ver= 4a.0.1.0.3.0.0.1; +let $qry= select t1a from t1, -- select 1, parent +( + select t2a from t2 where t2b >= some -- select 2, child + ( + select t3a from t3 where t3b in -- select 3, non-mergable + ( + select t4a from t4 where t4c in -- select 4, parent + ( + select t6a from t6 where t6b >= t2b -- select 5, child + ) + ) + ) +) dt +where t1a = t2a +union +select t5a from t5 where t5b in +( + select t7b from t7 where + ( + select t7c < t5c + ) +); + +--source execute_various_ways.inc + + +# swap to derived table instead of subquery +let $ver= 4.0.1.0.3.0.0.0; +let $qry= select t1a from t1, -- select 1, parent +( + select t2a from t2 where t2b >= some -- select 2, child + ( + select t3a from t3 where t3b in -- select 3, non-mergable + ( + select t4a from t4 where t4c in -- select 4, parent + ( + select t6a from t6 where t6b >= t2b -- select 5, child + ) + union + select t4a from t4 -- select 6 + ) + ) +) dt +where t1a = t2a; + +--source execute_various_ways.inc + + +# Class 5 +# subqueries in group by and order by with references to parent select_lex + +let $ver= 5.1.0.0.1.0.0.0; +let $qry= select t1a as col1, t1b as col2 from t1 +group by (select col1) order by col1; + +--source execute_various_ways.inc + + +let $ver= 5.2.0.0.1.0.0.0; +let $qry= select t1a as col1, t1b as col2 from t1 +group by (select col1 + col2) order by col1; + +--source execute_various_ways.inc + + +let $ver= 5.1.0.0.1.1.0.0; +let $qry= select t1a as col1, t1b+t1c as col2 from t1 +group by (select col1) order by col1; + +--source execute_various_ways.inc + + +let $ver= 5.2.0.0.2.2.0; +let $qry=select t1a+t2a as col1, t1b+t2b as col2 from t1 join t2 on t1c=t2c +group by (select col1 + col2) order by (select col1 + col2); + +--source execute_various_ways.inc + + +# wrong results for the next few queries when NOT run as prepared statement +# or procedure, See MDEV-35859 +let $ver= 5.1.1.0.1.0.0.0; +let $qry= select * from t2 where t2a in +( + select t1a from t1 + group by (select t1a > t2b) order by t1a +); + +--source execute_various_ways.inc + + +let $ver= 5a.1.1.0.1.0.0.0; +let $qry= select * from t2 where t2a in +( + select t1a as col1 from t1 + group by (select col1 > t2b) order by col1 +); + +--source execute_various_ways.inc + + +let $ver= 5.1.1.0.1.1.0.0; +let $qry= select * from t2 where t2a*2 in +( + select t1a+t2a from t1 + group by (select t1a+t2a > t2b) order by t1a+t2a +); + +--source execute_various_ways.inc + + +let $ver= 5a.1.1.0.1.1.0.0; +let $qry= select * from t2 where t2a*2 in +( + select t1a+t2a as col1 from t1 + group by (select col1 > t2b) order by col1 +); + +--source execute_various_ways.inc + + +let $ver= 5.2.1.0.1.2.0.0; +let $qry= select * from v5 where v5a in +( + select t1a from t1 + group by + ( + select t1a*25 < v5a + v5b + ) + order by t1a +); + +--source execute_various_ways.inc + + +let $ver= 5a.2.1.0.1.2.0.0; +let $qry= select * from v2 where v2a in +( + select t1a*25 as col1 from t1 + group by (select col1 < v2a + v2b) order by t1a +); + +--source execute_various_ways.inc + + +let $ver= 5a.2.2.0.1.2.0.0; +let $qry= select * from v2 where v2a in +( + select t1a*25 as col1 from t1 + group by (select col1 < v2a + v2b) order by col1 +); + +--source execute_various_ways.inc + + +let $ver= 5b.2.2.0.1.2.0.0; +let $qry= select * from v2 where v2a in +( + select t1a*25 as col1 from t1 + group by (select col1 < v2a + v2b) order by (select col1 < v2b) +); + +--source execute_various_ways.inc + + +# Class 6 subquery merge into derived merge +# we have subqueries at the lowest level +# derived tables at the upper level, all mergeable. + +# swap to derived table instead of subquery +let $ver= 6.1.0.0.2.0.0.0; +let $qry= select t1a from t1, -- select 1, parent +( + select t2a from t2, -- select 2, child + ( + select t3a from t3 where t3b in -- select 3, non-mergable + ( + select t4a from t4 where t4c in -- select 4, parent + ( + select t6a from t6 where t6b >= t3b -- select 5, child + ) + ) + ) dt2 + where t2b = t3a +) dt +where t1a = t2a; + +--source execute_various_ways.inc + + +# swap to derived table instead of subquery +let $ver= 6.2.0.0.2.0.0.0; +let $qry= select t1a from t1, -- select 1, parent +( + select t2a from t2, -- select 2, child + ( + select t3a from t3 where t3b in -- select 3, non-mergable + ( + select t4a from t4 where t4c in -- select 4, parent + ( + select t6a from t6 where t6b >= t3b -- select 5, child + and t6c >= t4c + ) + ) + ) dt2 + where t2b = t3a +) dt +where t1a = t2a; + +--source execute_various_ways.inc + + +# reference to an implicitly named column in a derived table in where clause, +# mergeable subselect + +let $ver= 7a.0; +let $qry=select * from +( + select t1a as dt1a, t1b from t1 +) dt +where +dt1a in +( + select t2a from t2 where t2b >= t1b +); + +--source execute_various_ways.inc + + +# reference to outer table in select list +let $ver= 7b.1.0.0; +let $qry=select +( + select sum(t2a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +t1b from t1; + +--source execute_various_ways.inc + + +# multiple references to outer table in select list + +let $ver= 7b.2.0.0; +let $qry=select +( + select sum(t2a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +( + select sum(t3a) from t3 where t3b > t1a group by t3b limit 1 +) as col2, +t1b from t1; + +--source execute_various_ways.inc + + +# multiple aggregation of outer reference + +let $ver= 7c.2.0.0; +let $qry=select +( + select sum(t1a) from t2 where t2b > t1a group by t1b limit 1 +) as col1, +( + select sum(t1c) from t3 where t3b > t1a group by t3b limit 1 +) as col2, +t1b from t1; + +--source execute_various_ways.inc + + + +# we need to test that t1a, which refers to the table ambiguous, remains +# referring to this after a merge + +let $ver= 7c.0; +let $qry=select t1a from t1 -- select 1 +where t1a in +( + select t1a from ambiguous where t1a >= some -- select 2 + ( + select t3a from t3 where t1a=t3b -- select 3 + ) +); + +--source execute_various_ways.inc + + +# test cascading merges + +let $ver= 7d.1.0; +let $qry= + select * from t1 + where t1c in + ( + select * from + ( + select t2a from t2 + where t2a in + ( + select t3a from (select * from t3) table3 + where t3a in + ( + select t4a from t4 + where t4a < any(select t5c from t5 where t5a > t3a) + ) + ) + ) dt + ); + +--source execute_various_ways.inc + + +let $ver= 7d.2.0; +let $qry= + select * from t1 + where t1c in + ( + select * from + ( + select t2a from t2 + where t2a in + ( + select t3a from (select * from t3) table3 + where t3a in + ( + select t4a from t4 + where t4a < any(select t5c from t5 where t5a < t3a + t3b) + ) + ) + ) dt + ); + +--source execute_various_ways.inc + + +let $ver= 7e.1.0.0.1.0.1; +let $qry= select * from (select * from t1 limit 1) dt where (select t1a != 0); + +--source execute_various_ways.inc + + +let $ver= 7e.1.0.0.1.0.1; +let $qry= +select * from t1 AS ta where ta.t1a IN +( + select t2a from t2 AS tb where tb.t2b >= SOME + ( + select SUM(t4b) from t4 as tc group by t4a having ta.t1a=tc.t4a + ) +); + +--source execute_various_ways.inc + + +let $ver= 7f.1.0.0.1.0.1; +let $qry= +select sum(c1) from v6; + +--source execute_various_ways.inc + + + +let $ver= MDEV-32297; +let $qry= +SELECT * FROM +( + SELECT * FROM + ( + SELECT * FROM + (SELECT 1 as "x") dt2 + ) dt1 + WHERE + ( + SELECT x+1 ORDER BY + ( + SELECT 1 GROUP BY + (1 IN (SELECT x)) + ) + ) +) dt +WHERE x = 1; + +--source execute_various_ways.inc + + +let $ver= MDEV-6054; +let $qry= +SELECT * FROM +( + SELECT DISTINCT * FROM t1 +) AS sq +WHERE t1a in +( + SELECT t2c FROM t2 WHERE t2c <= sq.t1b +); + +--source execute_various_ways.inc + + +let $ver= MDEV-26944; +let $qry= +SELECT x FROM +( + SELECT t1a AS y, (SELECT y FROM t1 LIMIT 1 ) AS x FROM t1 a +) dt; + +--source execute_various_ways.inc + + +let $ver= MDEV-30756; +let $qry= +SELECT * FROM t1 k WHERE 1 IN +( + SELECT 1 FROM t1 WHERE EXISTS + ( + SELECT t1a FROM + ( + SELECT 1 FROM t1 limit 1 + ) d GROUP BY + ( + SELECT 1 FROM t1 dt HAVING t1a limit 1 + ) BETWEEN 0 AND 10 HAVING 1 + ) +); + +--source execute_various_ways.inc + + +drop view v1, v2, v3, v4, v5, v6; +drop table t1, t2, t3, t4, t5, t6, t7, ambiguous; + +--echo # +--echo # MDEV-32766 +--echo # + +CREATE TABLE t0 (a int) ; +INSERT INTO `t0` VALUES (1),(2),(3); +( SELECT a c28 FROM t0 LIMIT 5 ) ORDER BY ( SELECT c28 FROM t0 limit 1); +DROP TABLE t0; diff --git a/mysql-test/main/ps.result b/mysql-test/main/ps.result index fbe8f3b2e3c6b..b8cfa83f7acea 100644 --- a/mysql-test/main/ps.result +++ b/mysql-test/main/ps.result @@ -3081,12 +3081,12 @@ DROP TABLE t1; CREATE TABLE t1(f1 INT); INSERT INTO t1 VALUES (1),(1); PREPARE stmt FROM 'EXPLAIN SELECT 1 FROM t1 WHERE (SELECT (SELECT 1 FROM t1 GROUP BY f1))'; -Warnings: -Note 1249 Select 2 was reduced during optimization EXECUTE stmt; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort +Warnings: +Note 1249 Select 2 was reduced during optimization EXECUTE stmt; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 @@ -5543,11 +5543,9 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 system NULL NULL NULL NULL 0 0.00 Const row not found 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables Warnings: -Note 1276 Field or reference 'test.t1.c' of SELECT #2 was resolved in SELECT #1 Note 1003 /* select#1 */ select (/* select#2 */ select 1 from `test`.`t2` where 0) AS `(SELECT 1 FROM t2 WHERE d = c)` from `test`.`t1` SHOW WARNINGS; Level Code Message -Note 1276 Field or reference 'test.t1.c' of SELECT #2 was resolved in SELECT #1 Note 1003 /* select#1 */ select (/* select#2 */ select 1 from `test`.`t2` where 0) AS `(SELECT 1 FROM t2 WHERE d = c)` from `test`.`t1` DEALLOCATE PREPARE stmt; DROP TABLE t1, t2; diff --git a/mysql-test/main/table_elim.result b/mysql-test/main/table_elim.result index 4aac1c4fa3292..2cc3671e03445 100644 --- a/mysql-test/main/table_elim.result +++ b/mysql-test/main/table_elim.result @@ -143,7 +143,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DEPENDENT SUBQUERY t2 ref PRIMARY PRIMARY 4 test.a2.id 2 100.00 Using index Warnings: Note 1276 Field or reference 'test.a2.id' of SELECT #3 was resolved in SELECT #2 -Note 1003 /* select#1 */ select `f`.`id` AS `id` from `test`.`t0` `f` join `test`.`t2` `a2` where `f`.`id` = `a2`.`id` and `a2`.`attr2` between 12 and 14 and `a2`.`fromdate` = <`a2`.`id`>((/* select#3 */ select max(`test`.`t2`.`fromdate`) from `test`.`t2` where `test`.`t2`.`id` = `a2`.`id`)) +Note 1003 /* select#1 */ select `f`.`id` AS `id` from `test`.`t0` `f` join `test`.`t2` `a2` where `f`.`id` = `a2`.`id` and `a2`.`attr2` between 12 and 14 and `a2`.`fromdate` = <>((/* select#3 */ select max(`test`.`t2`.`fromdate`) from `test`.`t2` where `test`.`t2`.`id` = `a2`.`id`)) This should use one table: explain select id from v2 where id=2; id select_type table type possible_keys key key_len ref rows Extra @@ -171,7 +171,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DEPENDENT SUBQUERY t2 ref PRIMARY PRIMARY 4 test.f.id 2 100.00 Using index Warnings: Note 1276 Field or reference 'test.f.id' of SELECT #3 was resolved in SELECT #2 -Note 1003 /* select#1 */ select `f`.`id` AS `id` from `test`.`t0` `f` join `test`.`t2` `a2` where `f`.`id` = `a2`.`id` and `a2`.`attr2` between 12 and 14 and `a2`.`fromdate` = <`f`.`id`>((/* select#3 */ select max(`test`.`t2`.`fromdate`) from `test`.`t2` where `test`.`t2`.`id` = `f`.`id`)) +Note 1003 /* select#1 */ select `f`.`id` AS `id` from `test`.`t0` `f` join `test`.`t2` `a2` where `f`.`id` = `a2`.`id` and `a2`.`attr2` between 12 and 14 and `a2`.`fromdate` = <>((/* select#3 */ select max(`test`.`t2`.`fromdate`) from `test`.`t2` where `test`.`t2`.`id` = `f`.`id`)) drop view v1, v2; drop table t0, t1, t2; create table t1 (a int); diff --git a/mysql-test/suite/compat/oracle/r/sp-code.result b/mysql-test/suite/compat/oracle/r/sp-code.result index 0fc980a3b8432..54319c0c13b5f 100644 --- a/mysql-test/suite/compat/oracle/r/sp-code.result +++ b/mysql-test/suite/compat/oracle/r/sp-code.result @@ -869,7 +869,7 @@ Pos Instruction 1 set v_b@5 NULL 2 cpush c@0 3 set p_value_a@6 arg_value_a@0 -4 set p_value_b@7 (select arg_value_b@1) +4 set p_value_b@7 arg_value_b@1 5 set p_pattern_a@8 arg_pattern_a@2 6 set p_pattern_b@9 arg_pattern_b@3 7 set p_limit_a@10 100 diff --git a/sql/item.cc b/sql/item.cc index 61cdc08dd5aa3..201e5e1e765c9 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -727,8 +727,10 @@ bool Item_ident::remove_dependence_processor(void * arg) { DBUG_ENTER("Item_ident::remove_dependence_processor"); if (get_depended_from() == (st_select_lex *) arg) + { depended_from= 0; - context= &((st_select_lex *) arg)->context; + context= &((st_select_lex *) arg)->context; + } DBUG_RETURN(0); } @@ -3689,7 +3691,16 @@ void Item_field::fix_after_pullout(st_select_lex *new_parent, Item **ref, ctx->select_lex= new_parent; if (context->select_lex == NULL) ctx->select_lex= NULL; - ctx->first_name_resolution_table= context->first_name_resolution_table; + + /* + We have already fixed this Item_field, so hardwire the resolution table + to prevent later problems -- but fall back to the context's table when + the field is not backed by a base-table entry (e.g. a temporary table), + so we never store a NULL first_name_resolution_table. + */ + ctx->first_name_resolution_table= + (field && field->table && field->table->pos_in_table_list) ? + field->table->pos_in_table_list : context->first_name_resolution_table; ctx->last_name_resolution_table= context->last_name_resolution_table; ctx->error_processor= context->error_processor; ctx->error_processor_data= context->error_processor_data; @@ -5869,7 +5880,25 @@ resolve_ref_in_select_and_group(THD *thd, Item_ident *ref, SELECT_LEX *select) } -/* +void Field_fixer::visit_field(Item_field *item) +{ + if (item->fixed()) // item may not yet be (re)fixed + { + st_select_lex *cmp= select; + while (cmp->merged_into) + cmp= cmp->merged_into; + if (item->field->table->pos_in_table_list && + (item->field->table->pos_in_table_list->select_lex == cmp)) + used_tables|= item->field->table->map; + else + used_tables|= OUTER_REF_TABLE_BIT; + } + else + not_ready= TRUE; +} + + +/** @brief Whether a table belongs to an outer select. @@ -5901,6 +5930,56 @@ bool is_outer_table(TABLE_LIST *table, SELECT_LEX *select) } +/** + @description + This item represents a reference to a column in having clause of some outer + select. Wrap this item into an Item_ref object if we are at the + first execution of the query or at processing the prepare command for it. + Make this wrapping permanent for the first query execution so that it could + be used for next executions of the query. + + @returns + FALSE on success + TRUE on failure +*/ + +bool fix_field_reference_to_having(THD *thd, Name_resolution_context *context, + Field *found, Item_ident *item, + Item **reference) +{ + + Item_ref *rf; + if (thd->stmt_arena->state != Query_arena::STMT_EXECUTED) + { + Query_arena *arena= 0, backup; + bool is_first_execution= thd->is_first_query_execution(); + if (is_first_execution && !thd->stmt_arena->is_conventional()) + arena= thd->activate_stmt_arena_if_needed(&backup); + if ((rf= new (thd->mem_root) Item_ref(thd, context, found->table->s->db, + Lex_cstring_strlen( + found->table->alias.c_ptr()), + item->field_name))) + { + if (is_first_execution) + *reference= rf; + else + thd->change_item_tree(reference, rf); + } + if (arena) + thd->restore_active_arena(arena, &backup); + if (!rf) + return 1; + /* + rf is Item_ref => never substitute other items (in this case) + during fix_fields() => we can use rf after fix_fields() + */ + DBUG_ASSERT(!rf->fixed()); // Assured by Item_ref() + if (rf->fix_fields(thd, reference) || rf->check_cols(1)) + return 1; + } + return 0; +} + /** Resolve the name of an outer select column reference. @@ -5982,6 +6061,11 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference) if (current_sel->master_unit()->outer_select()) outer_context= context->outer_context; + // if we found this item before, depended_from is where we found it. + // start looking there instead. It will work even if the select is merged. + if (!table_list && !cached_table && depended_from) + outer_context= &depended_from->context; + /* This assert is to ensure we have an outer contex when *from_field is set. @@ -6005,11 +6089,15 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference) last_checked_context= outer_context; upward_lookup= TRUE; + /* + if something has been merged to the top level, during 2nd execution + prev_subselect_item can be a null pointer, i.e. the unit from the top + select_lex + */ if (!at_top) place= prev_subselect_item->parsing_place; else place= NO_MATTER; - /* If outer_field is set, field was already found by first call to find_field_in_tables(). Only need to find appropriate context. @@ -6146,11 +6234,14 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference) Item::Type ref_type= (*reference)->type(); if (!at_top) prev_subselect_item->used_tables_and_const_cache_join(*reference); + mark_as_dependent(thd, last_checked_context->select_lex, context->select_lex, this, ((ref_type == REF_ITEM || ref_type == FIELD_ITEM) ? (Item_ident*) (*reference) : 0), false); + if (ref_type == FIELD_ITEM) + set_field(((Item_field*)(*reference))->field); if (thd->lex->in_sum_func && last_checked_context->select_lex->parent_lex == context->select_lex->parent_lex && @@ -6337,43 +6428,9 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference) this, (Item_ident*)*reference, false); if (last_checked_context->select_lex->having_fix_field) { - /* - This Item_field represents a reference to a column in having clause - of some outer select. Wrap this Item_field item into an Item_ref object - if we are at the first execution of the query or at processing the - prepare command for it. Make this wrapping permanent for the first query - execution so that it could be used for next executions of the query. - */ - Item_ref *rf; - if (thd->stmt_arena->state != Query_arena::STMT_EXECUTED) - { - Query_arena *arena= 0, backup; - bool is_first_execution= thd->is_first_query_execution(); - if (is_first_execution && !thd->stmt_arena->is_conventional()) - arena= thd->activate_stmt_arena_if_needed(&backup); - if ((rf= new (thd->mem_root) Item_ref(thd, context, - (*from_field)->table->s->db, - Lex_cstring_strlen((*from_field)-> - table->alias.c_ptr()), - field_name))) - { - if (is_first_execution) - *reference= rf; - else - thd->change_item_tree(reference, rf); - } - if (arena) - thd->restore_active_arena(arena, &backup); - if (!rf) - return -1; - /* - rf is Item_ref => never substitute other items (in this case) - during fix_fields() => we can use rf after fix_fields() - */ - DBUG_ASSERT(!rf->fixed()); // Assured by Item_ref() - if (rf->fix_fields(thd, reference) || rf->check_cols(1)) - return -1; - } + if (fix_field_reference_to_having(thd, context, *from_field, this, + reference)) + return -1; return 0; } } @@ -6432,9 +6489,19 @@ bool Item_field::fix_fields(THD *thd, Item **reference) Field *from_field= (Field *)not_found_field; bool outer_fixed= false; SELECT_LEX *select; - if (context) + Name_resolution_context *ctx= context; + + if (depended_from) // this is outer reference and we have fixed before { select= context->select_lex; + if (!alias_name_used) // short circuit fix_outer_refs if this wasn't alias + ctx= &depended_from->context; + depended_from->add_outer_reference_resolved_here(thd, this); + } + + if (ctx) + { + select= ctx->select_lex; } else { @@ -6458,11 +6525,11 @@ bool Item_field::fix_fields(THD *thd, Item **reference) expression to 'reference', i.e. it substitute that expression instead of this Item_field */ - DBUG_ASSERT(context); + DBUG_ASSERT(ctx); if ((from_field= find_field_in_tables(thd, this, - context->first_name_resolution_table, - context->last_name_resolution_table, - context->ignored_tables, + ctx->first_name_resolution_table, + ctx->last_name_resolution_table, + ctx->ignored_tables, reference, thd->lex->use_only_table_context ? REPORT_ALL_ERRORS : @@ -6513,6 +6580,8 @@ bool Item_field::fix_fields(THD *thd, Item **reference) */ set_max_sum_func_level(thd, select); set_field(new_field); + if (resolution == RESOLVED_AGAINST_ALIAS) + alias_name_used= TRUE; depended_from= (*((Item_field**)res))->depended_from; return 0; } @@ -6524,7 +6593,7 @@ bool Item_field::fix_fields(THD *thd, Item **reference) Item_field created by the parser with the new Item_ref. */ Item_ref *rf= new (thd->mem_root) - Item_ref(thd, context, db_name, table_name, field_name); + Item_ref(thd, ctx, db_name, table_name, field_name); if (!rf) return 1; bool err= rf->fix_fields(thd, (Item **) &rf) || rf->check_cols(1); @@ -6560,14 +6629,18 @@ bool Item_field::fix_fields(THD *thd, Item **reference) else if (!from_field) goto error; + st_select_lex *context_sl= ctx->select_lex; + if (context_sl) + while (context_sl->merged_into) + context_sl= context_sl->merged_into; + table_list= (cached_table ? cached_table : from_field != view_ref_found ? from_field->table->pos_in_table_list : 0); if (!outer_fixed && table_list && table_list->select_lex && - context->select_lex && - table_list->select_lex != context->select_lex && - !context->select_lex->is_merged_child_of(table_list->select_lex) && - is_outer_table(table_list, context->select_lex)) + context_sl && + table_list->select_lex != context_sl && + is_outer_table(table_list, context_sl)) { int ret; if ((ret= fix_outer_field(thd, &from_field, reference)) < 0) @@ -6577,10 +6650,9 @@ bool Item_field::fix_fields(THD *thd, Item **reference) goto mark_non_agg_field; } - if (select && !thd->lex->current_select->no_wrap_view_item && + if (select && (thd->stmt_arena->state != Query_arena::STMT_EXECUTED) && thd->lex->in_sum_func && - thd->lex->in_sum_func->nest_level == - select->nest_level) + thd->lex->in_sum_func->nest_level >= select->nest_level) set_if_bigger(thd->lex->in_sum_func->max_arg_level, select->nest_level); /* @@ -6679,7 +6751,7 @@ bool Item_field::fix_fields(THD *thd, Item **reference) safe for use because it's either the SELECT we want to use (the current level) or a stub added by non-SELECT queries. */ - select_lex= context->select_lex; + select_lex= ctx->select_lex; } if (!thd->lex->in_sum_func) select_lex->set_non_agg_field_used(true); @@ -6695,7 +6767,7 @@ bool Item_field::fix_fields(THD *thd, Item **reference) return FALSE; error: - context->process_error(thd); + ctx->process_error(thd); return TRUE; } @@ -6724,7 +6796,6 @@ void Item_field::cleanup() { DBUG_ENTER("Item_field::cleanup"); Item_ident::cleanup(); - depended_from= NULL; /* Even if this object was created by direct link to field in setup_wild() it will be linked correctly next time by name of field and table alias. @@ -8676,9 +8747,45 @@ bool Item_ref::fix_fields(THD *thd, Item **reference) if (from_field != not_found_field) { Item_field* fld; - if (!(fld= new (thd->mem_root) Item_field(thd, context, from_field))) - goto error; - thd->change_item_tree(reference, fld); + if (thd->stmt_arena->is_conventional() || + thd->stmt_arena->state == Query_arena::STMT_PREPARED || + thd->stmt_arena->state == Query_arena::STMT_INITIALIZED_FOR_SP) + { + /* + During the first execution, this item needs to be on statement + memory, as it can appear in outer_references_resolved_here + We do not reverse this Item_field creation. + */ + Query_arena *arena, backup; + arena= thd->activate_stmt_arena_if_needed(&backup); + + if (!(fld= new (thd->mem_root) Item_field(thd, context, from_field))) + { + if (arena) + thd->restore_active_arena(arena, &backup); + goto error; + } + if (arena) + thd->restore_active_arena(arena, &backup); + + *reference= fld; + } + else + { + // if we have already executed this statement, pick up the reference + if (thd->stmt_arena->state == Query_arena::STMT_EXECUTED) + { + DBUG_ASSERT(reference && *reference && + (*reference)->type() == Item::FIELD_ITEM); + fld= (Item_field *)*reference; + } + else + { + if (!(fld= new (thd->mem_root) Item_field(thd, context, from_field))) + goto error; + thd->change_item_tree(reference, fld); + } + } mark_as_dependent(thd, last_checked_context->select_lex, current_sel, fld, fld, false); /* diff --git a/sql/item.h b/sql/item.h index a05d3c4d892dd..ae45000261864 100644 --- a/sql/item.h +++ b/sql/item.h @@ -2279,6 +2279,7 @@ class Item :public Value_source, bool cleanup_excluding_immutables_processor (void *arg); virtual bool cleanup_excluding_const_fields_processor (void *arg) { return cleanup_processor(arg); } + virtual bool select_update_base_processor(void *arg) { return 0; } virtual bool collect_item_field_processor(void *arg) { return 0; } virtual bool unknown_splocal_processor(void *arg) { return 0; } virtual bool collect_outer_ref_processor(void *arg) {return 0; } @@ -3041,6 +3042,17 @@ class Field_enumerator Field_enumerator() = default; /* Remove gcc warning */ }; + +class Field_fixer: public Field_enumerator +{ +public: + table_map used_tables; /* Collect used_tables here */ + st_select_lex *select; /* the select_lex we're confined to */ + bool not_ready; /* if we hit an unfixed field, set this */ + void visit_field(Item_field *item) override; +}; + + class Item_string; diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index a5c13276693c6..7bf0f03cf8455 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -170,6 +170,8 @@ void Item_subselect::cleanup() my_free(sortbuffer.str); sortbuffer.str= 0; + used_tables_cache= 0; + base_flags&= ~item_base_t::FIXED; value_assigned= 0; expr_cache= 0; forced_const= FALSE; @@ -397,9 +399,17 @@ bool Item_subselect::eliminate_subselect_processor(void *arg) bool Item_subselect::mark_as_dependent(THD *thd, st_select_lex *select, Item *item) { + is_correlated= TRUE; + if (thd->lex->is_ps_or_view_context_analysis()) + return FALSE; + + DBUG_ASSERT(!thd->stmt_arena->is_stmt_prepare()); + /* + This is needed only for the first execution of the query. + The assertion above guarantees that we use statement memory here. + */ if (inside_first_fix_fields) { - is_correlated= TRUE; Ref_to_outside *upper; if (!(upper= new (thd->mem_root) Ref_to_outside())) return TRUE; @@ -462,24 +472,38 @@ void Item_subselect::fix_after_pullout(st_select_lex *new_parent, } -class Field_fixer: public Field_enumerator +/** + Check whether a Field Item 'belongs' to a unit. + The Field Item is an outer reference, we search from the SELECT_LEX + where the item is defined, outwards until a limit, checking whether + that select_lex is part of a unit. + + @param item search item + @param search test unit + @param limit outermost select_lex to search + + @return + FALSE if item doesn't belong to unit + TRUE if it does +*/ + + +bool Item_belongs_to( Item_ident *item, + SELECT_LEX_UNIT *search, + SELECT_LEX *limit ) { -public: - table_map used_tables; /* Collect used_tables here */ - st_select_lex *new_parent; /* Select we're in */ - void visit_field(Item_field *item) override + SELECT_LEX *defined= item->context->select_lex; + + do { - //for (TABLE_LIST *tbl= new_parent->leaf_tables; tbl; tbl= tbl->next_local) - //{ - // if (tbl->table == field->table) - // { - used_tables|= item->field->table->map; - // return; - // } - //} - //used_tables |= OUTER_REF_TABLE_BIT; - } -}; + if (defined->master_unit() == search) + return TRUE; + + defined= defined->outer_select(); + } while (defined && (defined != limit)); + + return FALSE; +} /* @@ -489,68 +513,74 @@ class Field_fixer: public Field_enumerator void Item_subselect::recalc_used_tables(st_select_lex *new_parent, bool after_pullout) { - List_iterator_fast it(upper_refs); - Ref_to_outside *upper; + table_map res= 0; DBUG_ENTER("recalc_used_tables"); - - used_tables_cache= 0; - while ((upper= it++)) + // New implementation (MDEV-32294) + + /* + Only Items resolved in the parent are involved the calculation of + used_tables_cache, these are populated and maintained + in SELECT_LEX::outer_references_resolved_here + */ + st_select_lex *parent= new_parent; + while (parent->merged_into) + parent= parent->merged_into; + + if (parent->outer_references_resolved_here.elements) { - bool found= FALSE; - /* - Check if - 1. the upper reference refers to the new immediate parent select, or - 2. one of the further ancestors. - - We rely on the fact that the tree of selects is modified by some kind of - 'flattening', i.e. a process where child selects are merged into their - parents. - The merged selects are removed from the select tree but keep pointers to - their parents. - */ - for (st_select_lex *sel= upper->select; sel; sel= sel->outer_select()) + List_iterator it(parent->outer_references_resolved_here); + Item_ident* item; + while ((item= it++)) { - /* - If we've reached the new parent select by walking upwards from - reference's original select, this means that the reference is now - referring to the direct parent: - */ - if (sel == new_parent) + // Only items that 'belong' within this->unit are to be used in the map + if (Item_belongs_to( item, unit, parent)) { - found= TRUE; - /* - upper->item may be NULL when we've referred to a grouping function, - in which case we don't care about what it's table_map really is, - because item->with_sum_func==1 will ensure correct placement of the - item. - */ - if (upper->item) + // extract the field from the Item + item= (Item_ident *)item->real_item(); + // collect usage of Item_fields within this expression + Field_fixer collector; + collector.used_tables= 0; + collector.select= parent; + collector.not_ready= FALSE; + item->walk(&Item::enumerate_field_refs_processor, 0, &collector); + if (collector.not_ready) { - // Now, iterate over fields and collect used_tables() attribute: - Field_fixer fixer; - fixer.used_tables= 0; - fixer.new_parent= new_parent; - upper->item->walk(&Item::enumerate_field_refs_processor, 0, &fixer); - used_tables_cache |= fixer.used_tables; - upper->item->walk(&Item::update_table_bitmaps_processor, FALSE, NULL); -/* - if (after_pullout) - upper->item->fix_after_pullout(new_parent, &(upper->item)); - upper->item->update_used_tables(); -*/ + res= 0; + break; } + res|= collector.used_tables; + item->walk(&Item::update_table_bitmaps_processor, FALSE, NULL); } } - if (!found) - used_tables_cache|= OUTER_REF_TABLE_BIT; } - /* - Don't update const_tables_cache yet as we don't yet know which of the - parent's tables are constant. Parent will call update_used_tables() after - he has done const table detection, and that will be our chance to update - const_tables_cache. + + /* + Now we need to check if any items further outward reference this + Item_subselect, if they do, set OUTER_REF_TABLE_BIT */ - DBUG_PRINT("exit", ("used_tables_cache: %llx", used_tables_cache)); + for (st_select_lex *outer= parent->outer_select(); + outer; + outer= outer->outer_select()) + { + if (outer->outer_references_resolved_here.elements) + { + List_iterator it(outer->outer_references_resolved_here); + Item_ident* item; + while ((item= it++)) + { + // this item, which is defined outwards from parent, 'belongs' + // within this Item_subselect + if (Item_belongs_to( item, unit, nullptr)) + { + res|= OUTER_REF_TABLE_BIT; + break; + } + } + } + } + + used_tables_cache= res; + DBUG_PRINT("info", ("used_tables_cache: %llx", used_tables_cache)); DBUG_VOID_RETURN; } @@ -1038,12 +1068,6 @@ void Item_subselect::update_used_tables() { if (!forced_const) { - /* - upper_refs not built on 2nd execution, so for the moment, do not - recalculate our used_tables_cache - */ - if (!unit->thd->is_first_query_execution()) - return; recalc_used_tables(parent_select, FALSE); if (!(engine->uncacheable() & ~UNCACHEABLE_EXPLAIN)) { @@ -1233,8 +1257,17 @@ void Item_singlerow_subselect::reset() bool Item_singlerow_subselect::select_transformer(JOIN *join) { + /* + We cannot perform this transform for query preparation, for example + prepare s from 'select * from t6, v2 where ( select t6a*t6b=v2a ) != 0'; + v2a is substituted during prepare, but being an outer reference, when + it is substituted again during the 1st execution, it's context is wrong. + */ + if (!thd->is_first_query_execution()) + return false; + DBUG_ENTER("Item_singlerow_subselect::select_transformer"); - if (changed) + if ((thd->stmt_arena->state == Query_arena::STMT_EXECUTED) && changed) DBUG_RETURN(false); DBUG_ASSERT(join->thd == thd); @@ -1272,8 +1305,7 @@ Item_singlerow_subselect::select_transformer(JOIN *join) !join->conds && !join->having && need_to_pull_out_item( join->select_lex->outer_select()->context_analysis_place, - select_lex->item_list.head()) && - thd->stmt_arena->state != Query_arena::STMT_INITIALIZED_FOR_SP) + select_lex->item_list.head())) { have_to_be_excluded= 1; if (thd->lex->describe) @@ -1290,6 +1322,10 @@ Item_singlerow_subselect::select_transformer(JOIN *join) */ substitution->fix_after_pullout(select_lex->outer_select(), &substitution, TRUE); + select_lex->nest_level_base= select_lex->outer_select()->nest_level_base; + select_lex->merged_into= select_lex->outer_select(); + if(parent_select) // can happen with SP + recalc_used_tables(parent_select, true); } if (arena) thd->restore_active_arena(arena, &backup); @@ -7185,6 +7221,26 @@ Item_subselect::subselect_table_finder_processor(void *arg) } +/* + See SELECT_LEX::merge_subquery for details of usage +*/ + +bool +Item_subselect::select_update_base_processor(void *arg) +{ + nest_updater *update= (nest_updater*) arg; + for (SELECT_LEX *sl= unit->first_select(); sl; sl= sl->next_select()) + { + if (sl->nest_level_base != update->base) + { + sl->nest_level_base= update->base; + sl->nest_level+= update->inc; + } + } + return FALSE; +} + + bool Item_singlerow_subselect::test_set_strategy(uchar strategy_arg) { DBUG_ASSERT(strategy_arg && diff --git a/sql/item_subselect.h b/sql/item_subselect.h index a2b93a10e5962..c9a93f66f8b0c 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -244,6 +244,7 @@ class Item_subselect :public Item_result_field, bool mark_as_eliminated_processor(void *arg) override; bool eliminate_subselect_processor(void *arg) override; bool enumerate_field_refs_processor(void *arg) override; + bool select_update_base_processor(void *arg) override; bool check_vcol_func_processor(void *arg) override { return mark_unsupported_function("select ...", arg, VCOL_IMPOSSIBLE); diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index afd79b98eb6c4..b3c0344a58c4c 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -1613,6 +1613,38 @@ static void reset_equality_number_for_subq_conds(Item * cond) return; } + +/** + Remove Item_field elements of list that have been resolved in 'remove'. + + @param list A list of item (idents) that contain contextual information + (where they are defined). + remove A SELECT_LEX pointer for items that need to be removed. + @details + During optimization we can merge two SELECT_LEXs together. Each SELECT_LEX + contains a list of items that are resolved within that select_lex. Before + we merge a query into it's new parent, we need to remove items that are + resolved in the new parent, but are defined within the query being merged. + This function does that. +*/ + +void remove_outer_references_to(List *list, + SELECT_LEX *remove) +{ + if (list) + { + List_iterator it( *list ); + Item_ident *item; + + while ((item= it++)) + { + if (item->context->select_lex == remove) + it.remove(); + } + } +} + + /* Convert a subquery predicate into a TABLE_LIST semi-join nest @@ -1967,6 +1999,25 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred) item_eq->in_equality_no= 0; sj_nest->sj_on_expr= and_items(thd, sj_nest->sj_on_expr, item_eq); } + + /* + References in parent_lex->outer_references_resolved_here that are + resolved in subq_lex need to be removed as they are no longer outer + references + */ + remove_outer_references_to(&parent_lex->outer_references_resolved_here, + subq_lex); + if (subq_lex->outer_references_resolved_here.elements) + { + DBUG_PRINT("info", + ("shifting outer_references_resolved_here from select #%d to #%d", + subq_lex->select_number, + parent_lex->select_number)); + parent_lex->outer_references_resolved_here. + append(&subq_lex->outer_references_resolved_here); + subq_lex->outer_references_resolved_here.empty(); + } + /* Fix the created equality and AND @@ -1979,6 +2030,9 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred) if (sj_nest->sj_on_expr->fix_fields_if_needed(thd, &sj_nest->sj_on_expr)) goto restore_tl_and_exit; + /* We may need this during fix_after_pullout below */ + subq_lex->merged_into= parent_lex; + /* Walk through sj nest's WHERE and ON expressions and call item->fix_table_changes() for all items. diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 037451f292441..cab509f6a8df8 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -6292,8 +6292,6 @@ static void update_field_dependencies(THD *thd, Field *field, TABLE *table) item_name name of item if it will be created (VIEW) ref expression substituted in VIEW should be passed using this reference (return view_ref_found) - register_tree_change TRUE if ref is not stack variable and we - need register changes in item tree RETURN 0 field is not found @@ -6304,8 +6302,7 @@ static void update_field_dependencies(THD *thd, Field *field, TABLE *table) static Field * find_field_in_view(THD *thd, TABLE_LIST *table_list, const char *name, size_t length, - const char *item_name, Item **ref, - bool register_tree_change) + const char *item_name, Item **ref) { DBUG_ENTER("find_field_in_view"); DBUG_PRINT("enter", @@ -6688,8 +6685,7 @@ find_field_in_table_ref(THD *thd, TABLE_LIST *table_list, const char *name, if (table_list->field_translation) { /* 'table_list' is a view or an information schema table. */ - if ((fld= find_field_in_view(thd, table_list, name, length, item_name, ref, - register_tree_change))) + if ((fld= find_field_in_view(thd, table_list, name, length, item_name, ref))) *actual_table= table_list; } else if (!table_list->nested_join) @@ -6837,6 +6833,10 @@ Field *find_field_in_table_sef(TABLE *table, const char *name) return (Field *)0; } +extern +bool fix_field_reference_to_having(THD *thd, Name_resolution_context *context, + Field *found, Item_ident *item, + Item **reference); /* Find field in table list. @@ -6941,12 +6941,8 @@ find_field_in_tables(THD *thd, Item_ident *item, { if (found == WRONG_GRANT) return (Field*) 0; - - /* - Only views fields should be marked as dependent, not an underlying - fields. - */ - if (!table_ref->belong_to_view && !table_ref->belong_to_derived) + if (thd->stmt_arena->is_stmt_prepare_or_first_stmt_execute() || + thd->stmt_arena->is_conventional()) { SELECT_LEX *current_sel= item->context->select_lex; SELECT_LEX *last_select= table_ref->select_lex; @@ -6976,6 +6972,17 @@ find_field_in_tables(THD *thd, Item_ident *item, { mark_select_range_as_dependent(thd, last_select, current_sel, found, *ref, item, true); + if (found && + found != view_ref_found && + (thd->lex->in_sum_func ? + thd->lex->in_sum_func->nest_level != current_sel->nest_level: + true) && + last_select->having_fix_field) + { + if (fix_field_reference_to_having(thd, ¤t_sel->context, found, + item, ref)) + return (Field*) 0; + } } } return found; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index c3ce8dae3909b..d06fe1dc47c2a 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -3110,6 +3110,7 @@ void st_select_lex::init_query() prep_leaf_list_state= UNINIT; bzero((char*) expr_cache_may_be_used, sizeof(expr_cache_may_be_used)); select_list_tables= 0; + merged_into= 0; rownum_in_field_list= 0; window_specs.empty(); @@ -3119,6 +3120,7 @@ void st_select_lex::init_query() versioned_tables= 0; pushdown_select= 0; orig_names_of_item_list_elems= 0; + outer_references_resolved_here.empty(); } void st_select_lex::init_select() @@ -3171,6 +3173,7 @@ void st_select_lex::init_select() is_tvc_wrapper= false; nest_flags= 0; orig_names_of_item_list_elems= 0; + outer_references_resolved_here.empty(); } /* @@ -3485,6 +3488,8 @@ bool st_select_lex::mark_as_dependent(THD *thd, st_select_lex *last, DBUG_ASSERT(this != last); + if (dependency) + last->add_outer_reference_resolved_here(thd, dependency); /* Mark all selects from resolved to 1 before select where was found table as depended (of select where was found table) @@ -5311,6 +5316,12 @@ void st_select_lex::remap_tables(TABLE_LIST *derived, table_map map, } } + +extern +void remove_outer_references_to(List*list, + SELECT_LEX *remove_me); + + /** @brief Merge a subquery into this select. @@ -5376,8 +5387,61 @@ bool SELECT_LEX::merge_subquery(THD *thd, TABLE_LIST *derived, /* Walk through child's tables and adjust table map, tablenr, * parent_lex */ subq_select->remap_tables(derived, map, table_no, this); + + /* + We rely on nest_level_base being the same within everything inside + this->unit. Now that we have merged subq_select into this select, + we need to walk into subq_select, correcting this for all enclosed + select_lex + */ + nest_updater update; + update.inc= nest_level; + update.base= nest_level_base; + + if (subq_select->nest_level_base != nest_level_base) + { + subq_select->nest_level_base= nest_level_base; + subq_select->nest_level+= nest_level; + } + List_iterator_fast it(subq_select->item_list); + Item *item; + ORDER *order; + while ((item= it++)) + item->walk(&Item::select_update_base_processor, TRUE, (void*) &update); + + if (subq_select->where) + subq_select->where->walk(&Item::select_update_base_processor, TRUE, + (void*) &update); + + if (subq_select->having) + subq_select->having->walk(&Item::select_update_base_processor, TRUE, + (void*) &update); + + for (order= subq_select->order_list.first ; order; order= order->next) + (*order->item)->walk(&Item::select_update_base_processor, TRUE, + (void*) &update); + + for (order= subq_select->group_list.first ; order; order= order->next) + (*order->item)->walk(&Item::select_update_base_processor, TRUE, + (void*) &update); + subq_select->merged_into= this; + /* + References in this->outer_references_resolved_here that are resolved in + subq_select need to be removed as they are no longer outer references + */ + remove_outer_references_to(&this->outer_references_resolved_here, subq_select); + if (subq_select->outer_references_resolved_here.elements) + { + DBUG_PRINT("info", + ("shifting outer_references_resolved_here from select #%d to #%d", + subq_select->select_number, + this->select_number) ); + this->outer_references_resolved_here.append( + &subq_select->outer_references_resolved_here); + } + replace_leaf_table(derived, subq_select->leaf_tables); return FALSE; @@ -5932,53 +5996,6 @@ void st_select_lex::set_unique_exclude() } -/* - Return true if this select_lex has been converted into a semi-join nest - within 'ancestor'. - - We need a loop to check this because there could be several nested - subselects, like - - SELECT ... FROM grand_parent - WHERE expr1 IN (SELECT ... FROM parent - WHERE expr2 IN ( SELECT ... FROM child) - - which were converted into: - - SELECT ... - FROM grand_parent SEMI_JOIN (parent JOIN child) - WHERE - expr1 AND expr2 - - In this case, both parent and child selects were merged into the parent. -*/ - -bool st_select_lex::is_merged_child_of(st_select_lex *ancestor) -{ - bool all_merged= TRUE; - for (SELECT_LEX *sl= this; sl && sl!=ancestor; - sl=sl->outer_select()) - { - Item *subs= sl->master_unit()->item; - Item_in_subselect *in_subs= (subs ? subs->get_IN_subquery() : NULL); - if (in_subs && - ((Item_subselect*)subs)->substype() == Item_subselect::IN_SUBS && - in_subs->test_strategy(SUBS_SEMI_JOIN)) - { - continue; - } - - if (sl->master_unit()->derived && - sl->master_unit()->derived->is_merged_derived()) - { - continue; - } - all_merged= FALSE; - break; - } - return all_merged; -} - /* This is used by SHOW EXPLAIN|ANALYZE. It assumes query plan has been already collected into QPF structures and we only need to print it out. @@ -12513,4 +12530,59 @@ bool SELECT_LEX_UNIT::is_derived_eliminated() const if (!derived->table) return true; return derived->table->map & outer_select()->join->eliminated_tables; -} \ No newline at end of file +} + + +/** + Add an outer reference to the SELECT_LEX in which it is resolved. + + @param thd Thread Handle + original Item on which we are calling fix_outer_field + translated Item that is used to fetch data for results. + + @details + Adds an Item pointer to the maintained list of outer references that are + resolved in this SELECT_LEX. We pass in both the item which causes the + outer reference (on which fix_outer_field is called) and the result of + name resolution on this item. We need both as we need an item we can call + real_item() on to get Field information, as well as contextual information + which for an Item_ref will need saving. + + @retval FALSE no error + TRUE an error occurred +*/ + +bool SELECT_LEX::add_outer_reference_resolved_here(THD *thd, + Item_ident *dependency) +{ + bool ret= FALSE; + + /* + Only populate outer reference during either conventional execution or + on first execution of a prepared statement/stored procedure + */ + if (thd->stmt_arena->state == Query_arena::STMT_CONVENTIONAL_EXECUTION || + thd->stmt_arena->state == Query_arena::STMT_INITIALIZED_FOR_SP || + thd->stmt_arena->state == Query_arena::STMT_PREPARED) + { + /* + Skip if this exact reference is already recorded: a field can be + fix_fields()'d more than once during the first execution, and a + duplicate would only add redundant work to recalc_used_tables(). + */ + List_iterator_fast it(outer_references_resolved_here); + Item_ident *e; + bool already= FALSE; + while ((e= it++)) + if (e == dependency) { already= TRUE; break; } + if (!already) + { + Query_arena *arena, backup; + arena= thd->activate_stmt_arena_if_needed(&backup); + ret= outer_references_resolved_here.push_back(dependency, thd->mem_root); + if (arena) + thd->restore_active_arena(arena, &backup); + } + } + return ret; +} diff --git a/sql/sql_lex.h b/sql/sql_lex.h index fd914177e3195..9ee9dc44749d6 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1175,12 +1175,16 @@ class st_select_lex: public st_select_lex_node select_handler *pushdown_select; List *join_list; /* list for the currently parsed join */ st_select_lex *merged_into; /* select which this select is merged into */ - /* (not 0 only for views/derived tables) */ const char *type; /* type of select for EXPLAIN */ /* List of references to fields referenced from inner selects */ List inner_refs_list; + + /* List of Items that are in inner selects but resolved here */ + List outer_references_resolved_here; + bool add_outer_reference_resolved_here(THD *thd, Item_ident *dependency); + List attach_to_conds; /* Saved values of the WHERE and HAVING clauses*/ Item::cond_result cond_value, having_value; @@ -1602,8 +1606,6 @@ class st_select_lex: public st_select_lex_node void set_unique_exclude(); - bool is_merged_child_of(st_select_lex *ancestor); - /* For MODE_ONLY_FULL_GROUP_BY we need to maintain two flags: - Non-aggregated fields are used in this select. @@ -5331,5 +5333,7 @@ bool TABLE_LIST::is_pure_alias() const return !db.length || (table_options & TL_OPTION_ALIAS); } +struct nest_updater {int inc; SELECT_LEX_UNIT *base;}; + #endif /* MYSQL_SERVER */ #endif /* SQL_LEX_INCLUDED */ diff --git a/sql/sql_tvc.cc b/sql/sql_tvc.cc index 3fa4675574c48..7895712cd13d7 100644 --- a/sql/sql_tvc.cc +++ b/sql/sql_tvc.cc @@ -863,6 +863,8 @@ Item_subselect::wrap_tvc_into_select(THD *thd, st_select_lex *tvc_sl) { if (engine->engine_type() == subselect_engine::SINGLE_SELECT_ENGINE) ((subselect_single_select_engine *) engine)->change_select(wrapper_sl); + wrapper_sl->nest_level= tvc_sl->nest_level; + wrapper_sl->nest_level_base= tvc_sl->nest_level_base; } lex->current_select= parent_select; return wrapper_sl; diff --git a/sql/table.cc b/sql/table.cc index fa0ca2cf58362..872ae5592d7ee 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -7227,10 +7227,7 @@ Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref, { DBUG_RETURN(field); } - - Name_resolution_context *context= (view->view ? - &view->view->first_select_lex()->context: - &thd->lex->first_select_lex()->context); + Name_resolution_context *context= &thd->lex->current_select->context; Item *item= (new (thd->mem_root) Item_direct_view_ref(thd, context, field_ref, view->alias, *name, view)); From 2289fd42423f2dee0cd287effc95caf75f29c731 Mon Sep 17 00:00:00 2001 From: Rex Date: Thu, 16 Jul 2026 12:44:56 +1200 Subject: [PATCH 3/3] MDEV-35673 Item_subselect::used_tables_cache: setup_fields used_tables recalculation and the guards it requires (part 2/2) setup_fields(): for SQLCOM_SELECT, call item->update_used_tables() after split_sum_func so that used_tables() is not consulted before the caches are set up on the 2nd execution of a prepared statement (fixes a 1st/2nd execution result mismatch in main.subselect_nulls under --ps-protocol). That recalculation exposes items whose caches are read while still being (re)built, so add the guards it now depends on: - Item_field::used_tables(): return 0 when field / field->table is not yet set, instead of dereferencing a null pointer. - Item_direct_view_ref::used_tables(): return 0 when the item is not fixed yet, instead of asserting. - Item_func::fix_fields(): reset used_tables_cache/const_item_cache at entry (assignment) instead of asserting they are already clear, so a re-fix is idempotent. Remove select,ps.rdiff / select_jcl6,ps.rdiff / select_pkeycache,ps.rdiff: the extra "resolved in SELECT #1" notes they recorded no longer appear under --ps-protocol, so the select tests now match without an rdiff. Split and documentation by Claude Opus 4.8. --- mysql-test/main/select,ps.rdiff | 12 ------------ mysql-test/main/select_jcl6,ps.rdiff | 12 ------------ mysql-test/main/select_pkeycache,ps.rdiff | 12 ------------ sql/item.cc | 7 +++++-- sql/item_func.cc | 9 ++------- sql/sql_base.cc | 5 +++++ 6 files changed, 12 insertions(+), 45 deletions(-) delete mode 100644 mysql-test/main/select,ps.rdiff delete mode 100644 mysql-test/main/select_jcl6,ps.rdiff delete mode 100644 mysql-test/main/select_pkeycache,ps.rdiff diff --git a/mysql-test/main/select,ps.rdiff b/mysql-test/main/select,ps.rdiff deleted file mode 100644 index 61d6867c1dcb4..0000000000000 --- a/mysql-test/main/select,ps.rdiff +++ /dev/null @@ -1,12 +0,0 @@ ---- mysql-test/main/select.result -+++ mysql-test/main/select.reject -@@ -5661,6 +5661,8 @@ - Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1 - Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1 - Note 1249 Select 2 was reduced during optimization -+Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1 -+Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1 - Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = 1 and (1 or <`test`.`t1`.`a`>((/* select#3 */ select 3 from DUAL where `test`.`t1`.`a` = `test`.`t1`.`a`)) = 3) - PREPARE stmt FROM 'SELECT * FROM t1 WHERE a = 1 AND - (3 = 0 OR (SELECT a = 1 OR (SELECT 3 WHERE a = a) = 3))'; - diff --git a/mysql-test/main/select_jcl6,ps.rdiff b/mysql-test/main/select_jcl6,ps.rdiff deleted file mode 100644 index fc59dd211f99e..0000000000000 --- a/mysql-test/main/select_jcl6,ps.rdiff +++ /dev/null @@ -1,12 +0,0 @@ ---- mysql-test/main/select_jcl6.result -+++ mysql-test/main/select_jcl6.reject -@@ -5672,6 +5672,8 @@ - Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1 - Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1 - Note 1249 Select 2 was reduced during optimization -+Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1 -+Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1 - Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = 1 and (1 or <`test`.`t1`.`a`>((/* select#3 */ select 3 from DUAL where `test`.`t1`.`a` = `test`.`t1`.`a`)) = 3) - PREPARE stmt FROM 'SELECT * FROM t1 WHERE a = 1 AND - (3 = 0 OR (SELECT a = 1 OR (SELECT 3 WHERE a = a) = 3))'; - diff --git a/mysql-test/main/select_pkeycache,ps.rdiff b/mysql-test/main/select_pkeycache,ps.rdiff deleted file mode 100644 index dc9c30408a931..0000000000000 --- a/mysql-test/main/select_pkeycache,ps.rdiff +++ /dev/null @@ -1,12 +0,0 @@ ---- mysql-test/main/select_pkeycache.result -+++ mysql-test/main/select_pkeycache.reject -@@ -5661,6 +5661,8 @@ - Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1 - Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1 - Note 1249 Select 2 was reduced during optimization -+Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1 -+Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1 - Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = 1 and (1 or <`test`.`t1`.`a`>((/* select#3 */ select 3 from DUAL where `test`.`t1`.`a` = `test`.`t1`.`a`)) = 3) - PREPARE stmt FROM 'SELECT * FROM t1 WHERE a = 1 AND - (3 = 0 OR (SELECT a = 1 OR (SELECT 3 WHERE a = a) = 3))'; - diff --git a/sql/item.cc b/sql/item.cc index 201e5e1e765c9..81eb9b2260ee1 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -3588,7 +3588,9 @@ bool Item_field::eq(const Item *item, const Eq_config &config) const table_map Item_field::used_tables() const { - if (field->table->const_table) + if (!field || + !field->table || + field->table->const_table) return 0; // const item return (get_depended_from() ? OUTER_REF_TABLE_BIT : field->table->map); } @@ -11511,7 +11513,8 @@ void Item_direct_view_ref::update_used_tables() table_map Item_direct_view_ref::used_tables() const { - DBUG_ASSERT(fixed()); + if(!fixed()) + return (table_map) 0; if (get_depended_from()) return OUTER_REF_TABLE_BIT; diff --git a/sql/item_func.cc b/sql/item_func.cc index 37d63d984f3af..d30f8ae9d5101 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -364,13 +364,8 @@ Item_func::fix_fields(THD *thd, Item **ref) Item **arg,**arg_end; uchar buff[STACK_BUFF_ALLOC]; // Max argument in function - /* - The Used_tables_and_const_cache of "this" was initialized by - the constructor, or by Item_func::cleanup(). - */ - DBUG_ASSERT(used_tables_cache == 0); - DBUG_ASSERT(const_item_cache == true); - + used_tables_cache= 0; + const_item_cache= true; not_null_tables_cache= 0; /* diff --git a/sql/sql_base.cc b/sql/sql_base.cc index cab509f6a8df8..29e5e891435dd 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -8271,6 +8271,11 @@ bool setup_fields(THD *thd, Ref_ptr_array ref_pointer_array, item->split_sum_func(thd, ref_pointer_array, *sum_func_list, SPLIT_SUM_SELECT); } + + // update command causes problems + if (thd->lex->sql_command == SQLCOM_SELECT) + item->update_used_tables(); + lex->current_select->select_list_tables|= item->used_tables(); lex->used_tables|= item->used_tables(); lex->current_select->cur_pos_in_select_list++;