From 0afea0fb9440726f093794ad29f7c297650473fa Mon Sep 17 00:00:00 2001 From: Rex Johnston Date: Fri, 24 Jul 2026 15:52:49 +1200 Subject: [PATCH] MDEV-19941 "Duplicate column name" while using VALUES table constructor Copy mysql column name scheme for TVCs (column_[0-9999]), taking care with cases involving conflicting names. --- mysql-test/main/brackets.result | 106 +++---- mysql-test/main/ctype_utf16.result | 2 +- mysql-test/main/func_str.result | 8 +- mysql-test/main/func_str.test | 4 +- mysql-test/main/gis.result | 2 +- mysql-test/main/intersect_all.result | 12 +- mysql-test/main/opt_trace.result | 2 +- mysql-test/main/opt_tvc.result | 52 ++-- mysql-test/main/table_value_constr.result | 278 ++++++++++++------ mysql-test/main/table_value_constr.test | 72 +++++ mysql-test/main/vector_funcs.result | 4 +- mysql-test/main/vector_funcs.test | 2 +- .../compat/oracle/r/table_value_constr.result | 252 ++++++++-------- sql/sql_union.cc | 65 +++- 14 files changed, 544 insertions(+), 317 deletions(-) diff --git a/mysql-test/main/brackets.result b/mysql-test/main/brackets.result index 1f1922416a16c..05d3846784023 100644 --- a/mysql-test/main/brackets.result +++ b/mysql-test/main/brackets.result @@ -1091,7 +1091,7 @@ values (3), (7), (1) order by 1; 3 7 (values (3), (7), (1) limit 2) order by 1 desc; -3 +column_0 7 3 ((values (3), (7), (1)) order by 1 desc) limit 2; @@ -1153,7 +1153,7 @@ values (3), (7), (1) except values (3), (4), (2); 2 5 (values (3), (7), (1) union values (3), (4), (2)) union values (5), (7); -3 +column_0 3 7 1 @@ -1223,21 +1223,21 @@ values (3), (7), (1) union (values (3), (4), (2)) order by 1; (values (3), (7), (1) order by 1 limit 2) union (values (3), (4), (2) order by 1 desc limit 2); -3 +column_0 1 3 4 ((values (3), (7), (1) order by 1) limit 2) union ((values (3), (4), (2) order by 1 desc) limit 2); -3 +column_0 1 3 4 (((values (3), (7), (1)) order by 1) limit 2) union (((values (3), (4), (2)) order by 1 desc) limit 2); -3 +column_0 1 3 4 @@ -1246,7 +1246,7 @@ union union values (3), (4), (2) order by 1; -3 +column_0 1 2 3 @@ -1255,7 +1255,7 @@ order by 1; union ((values (3), (4), (2) order by 1 desc) limit 2) order by 1; -3 +column_0 1 3 4 @@ -1335,7 +1335,7 @@ a (values (3), (4), (2) order by 1 desc limit 2) union (select a from t1 where a <=3 order by 1 limit 2); -3 +column_0 4 3 1 @@ -1343,7 +1343,7 @@ union (values (3), (4), (2) order by 1 desc limit 2) union ((select a from t1 where a <=3) order by 1 limit 2); -3 +column_0 4 3 1 @@ -1351,7 +1351,7 @@ union (((values (3), (4), (2)) order by 1 desc) limit 2) union (((select a from t1 where a <=3) order by 1) limit 2); -3 +column_0 4 3 1 @@ -1360,7 +1360,7 @@ union union (((select a from t1 where a <=3) order by a) limit 2) order by 1; -3 +column_0 1 2 3 @@ -3485,61 +3485,61 @@ a # 9.3. derived table as [tailed] TVC select * from ( values (3), (7), (1) ) as dt; -3 +column_0 3 7 1 select * from ( (values (3), (7), (1)) ) as dt; -3 +column_0 3 7 1 select * from (((values (3), (7), (1)))) as dt; -3 +column_0 3 7 1 select * from ( values (3), (7), (1) order by 1 limit 2 ) as dt; -3 +column_0 1 3 select * from ( (values (3), (7), (1)) order by 1 limit 2 ) as dt; -3 +column_0 1 3 select * from ( ((values (3), (7), (1))) order by 1 limit 2 ) as dt; -3 +column_0 1 3 select * from ( (((values (3), (7), (1))) order by 1 limit 2) ) as dt; -3 +column_0 1 3 select * from ( ( (values (3), (7), (1) limit 2) order by 1 desc) ) as dt; -3 +column_0 3 7 select * from ( ((values (3), (7), (1)) order by 1 desc) limit 2 ) as dt; -3 +column_0 7 3 select * from ( (((values (3), (7), (1)) order by 1 desc) limit 2) ) as dt; -3 +column_0 7 3 # 9.3. derived table as union of TVCs select * from ( values (3), (7), (1) union values (3), (4), (2) ) dt; -3 +column_0 3 7 1 @@ -3547,7 +3547,7 @@ select * from 2 select * from ( values (3), (7), (1) union all values (3), (4), (2) ) as dt; -3 +column_0 3 7 1 @@ -3556,7 +3556,7 @@ select * from 2 select * from ( values (3), (7), (1) union values (3), (4), (2) ) as dt; -3 +column_0 3 7 1 @@ -3564,12 +3564,12 @@ select * from 2 select * from ( values (3), (7), (1) except values (3), (4), (2) ) as dt; -3 +column_0 7 1 select * from ( (values (3), (7), (1)) union (values (3), (4), (2)) ) as dt; -3 +column_0 3 7 1 @@ -3580,7 +3580,7 @@ select * from union (values (3), (4), (2)) union values (5), (7) ) dt; -3 +column_0 3 7 1 @@ -3593,7 +3593,7 @@ union (values (3), (4), (2)) union (values (5), (7)) ) as dt; -3 +column_0 3 7 1 @@ -3606,7 +3606,7 @@ union values (3), (4), (2)) union values (5), (7) ) as dt; -3 +column_0 3 7 1 @@ -3618,7 +3618,7 @@ select * from union (values (3), (4), (2) union values (5), (7)) ) as dt; -3 +column_0 3 7 1 @@ -3630,7 +3630,7 @@ select * from union ((values (3), (4), (2) union values (5), (7)))) ) dt; -3 +column_0 3 7 1 @@ -3642,7 +3642,7 @@ select * from union values (3), (4), (2) order by 1 ) as dt; -3 +column_0 1 2 3 @@ -3650,7 +3650,7 @@ order by 1 ) as dt; 7 select * from ( (values (3), (7), (1) union values (3), (4), (2)) order by 1 ) as dt; -3 +column_0 1 2 3 @@ -3658,7 +3658,7 @@ select * from 7 select * from ( (values (3), (7), (1) union values (3), (4), (2)) order by 1 ) as dt; -3 +column_0 1 2 3 @@ -3666,7 +3666,7 @@ select * from 7 select * from ( values (3), (7), (1) union (values (3), (4), (2)) order by 1 ) as dt; -3 +column_0 1 2 3 @@ -3674,7 +3674,7 @@ select * from 7 select * from ( (values (3), (7), (1) union values (3), (4), (2)) order by 1 ) as dt; -3 +column_0 1 2 3 @@ -3682,7 +3682,7 @@ select * from 7 select * from ( ((values (3), (7), (1)) union values (3), (4), (2)) order by 1 ) as dt; -3 +column_0 1 2 3 @@ -3692,7 +3692,7 @@ select * from ( (values (3), (7), (1) order by 1 limit 2) union (values (3), (4), (2) order by 1 desc limit 2) ) as dt; -3 +column_0 1 3 4 @@ -3700,7 +3700,7 @@ select * from ( ((values (3), (7), (1) order by 1) limit 2) union ((values (3), (4), (2) order by 1 desc) limit 2) ) as dt; -3 +column_0 1 3 4 @@ -3708,7 +3708,7 @@ select * from ( (((values (3), (7), (1)) order by 1) limit 2) union (((values (3), (4), (2)) order by 1 desc) limit 2) ) as dt; -3 +column_0 1 3 4 @@ -3717,7 +3717,7 @@ select * from union values (3), (4), (2) order by 1 limit 3 ) as dt; -3 +column_0 1 2 3 @@ -3726,7 +3726,7 @@ select * from union ((values (3), (4), (2) order by 1 desc) limit 2) order by 1 limit 3 ) as dt; -3 +column_0 1 3 4 @@ -3798,7 +3798,7 @@ a 4 select * from ( (((values (3), (4), (2)) order by 1 desc) limit 2) ) as dt; -3 +column_0 4 3 select * from @@ -3815,7 +3815,7 @@ select * from ( (values (3), (4), (2) order by 1 desc limit 2) union (select a from t1 where a <=3 order by 1 limit 2) ) as dt; -3 +column_0 4 3 1 @@ -3824,7 +3824,7 @@ select * from ( (values (3), (4), (2) order by 1 desc limit 2) union ((select a from t1 where a <=3) order by 1 limit 2) ) as dt; -3 +column_0 4 3 1 @@ -3833,7 +3833,7 @@ select * from ( (((values (3), (4), (2)) order by 1 desc) limit 2) union (((select a from t1 where a <=3) order by 1) limit 2) ) as dt; -3 +column_0 4 3 1 @@ -3843,7 +3843,7 @@ select * from union (((select a from t1 where a <=3) order by a) limit 2) order by 1 ) as dt; -3 +column_0 1 2 3 @@ -4343,7 +4343,7 @@ show create view v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS values (3),(7),(1) latin1 latin1_swedish_ci select * from v1; -3 +column_0 3 7 1 @@ -4354,7 +4354,7 @@ show create view v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS (values (3),(7),(1) order by 1) latin1 latin1_swedish_ci select * from v1; -3 +column_0 1 3 7 @@ -4366,7 +4366,7 @@ show create view v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS values (3),(7),(1) union values (3),(4),(2) latin1 latin1_swedish_ci select * from v1; -3 +column_0 3 7 1 @@ -4379,7 +4379,7 @@ show create view v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS values (3),(7),(1) union values (3),(4),(2) order by 1 latin1 latin1_swedish_ci select * from v1; -3 +column_0 1 2 3 @@ -4394,7 +4394,7 @@ show create view v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS (values (3),(7),(1) order by 1 limit 2) union (values (3),(4),(2) order by 1 desc limit 2) latin1 latin1_swedish_ci select * from v1; -3 +column_0 1 3 4 @@ -4408,7 +4408,7 @@ show create view v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS (values (3),(7),(1) order by 1 limit 2) union values (3),(4),(2) order by 1 latin1 latin1_swedish_ci select * from v1; -3 +column_0 1 2 3 diff --git a/mysql-test/main/ctype_utf16.result b/mysql-test/main/ctype_utf16.result index b88796b57418d..1f1db74d6aec5 100644 --- a/mysql-test/main/ctype_utf16.result +++ b/mysql-test/main/ctype_utf16.result @@ -3067,7 +3067,7 @@ select 'AMZ'like 'A%M%Z'; SET NAMES utf8; CREATE TABLE t1 (a TEXT CHARACTER SET utf16); SELECT * FROM (VALUES (1) UNION SELECT * FROM t1) AS t; -1 +column_0 1 DROP TABLE t1; VALUES (1) UNION SELECT _utf16 0x0020; diff --git a/mysql-test/main/func_str.result b/mysql-test/main/func_str.result index 2043b56927a58..c18fcb1dbede6 100644 --- a/mysql-test/main/func_str.result +++ b/mysql-test/main/func_str.result @@ -5449,8 +5449,8 @@ count(*) select count(*) from seq_1_to_1024 where length(random_bytes(seq)) = seq; count(*) 1024 -select random_bytes(`0`),`1` from (values (0,1),(null,2),(0,3)) t1; -random_bytes(`0`) 1 +select random_bytes(`column_0`),`column_1` from (values (0,1),(null,2),(0,3)) t1; +random_bytes(`column_0`) column_1 1 NULL 2 3 @@ -5765,8 +5765,8 @@ set @@block_encryption_mode=default; # # MDEV-31633 Assertion `!item->null_value' failed in Type_handler::Item_send_str # -select aes_encrypt(a,a) is null from (values('a'),(NULL),('b')) x; -aes_encrypt(a,a) is null +select aes_encrypt(column_0,column_0) is null from (values('a'),(NULL),('b')) x; +aes_encrypt(column_0,column_0) is null 0 1 0 diff --git a/mysql-test/main/func_str.test b/mysql-test/main/func_str.test index 576fe8a248a47..2e29348be17f8 100644 --- a/mysql-test/main/func_str.test +++ b/mysql-test/main/func_str.test @@ -2479,7 +2479,7 @@ select count(*) from seq_17_to_1024 where random_bytes(seq) <=> random_bytes(seq select count(*) from seq_1_to_1024 where length(random_bytes(seq)) = seq; -select random_bytes(`0`),`1` from (values (0,1),(null,2),(0,3)) t1; +select random_bytes(`column_0`),`column_1` from (values (0,1),(null,2),(0,3)) t1; --echo # --echo # Test NULL output for NULL input @@ -2678,7 +2678,7 @@ set @@block_encryption_mode=default; --echo # --echo # MDEV-31633 Assertion `!item->null_value' failed in Type_handler::Item_send_str --echo # -select aes_encrypt(a,a) is null from (values('a'),(NULL),('b')) x; +select aes_encrypt(column_0,column_0) is null from (values('a'),(NULL),('b')) x; --echo # --echo # MDEV-33659: Server crashed at Create_func_aes_decrypt::create_native diff --git a/mysql-test/main/gis.result b/mysql-test/main/gis.result index 6ed04d5064ecf..43c1e44d71431 100644 --- a/mysql-test/main/gis.result +++ b/mysql-test/main/gis.result @@ -5652,7 +5652,7 @@ v5 a 101 v6 a 101 v7 a 101 v8 a 101 -v9 (select max(`test`.`t1`.`a`) from `test`.`t1`) 101 +v9 column_0 101 DROP TABLE t2,t3,t4,t5,t6,t7,t8,t9; DROP VIEW v2,v3,v4,v5,v6,v7,v8,v9; DROP TABLE t1; diff --git a/mysql-test/main/intersect_all.result b/mysql-test/main/intersect_all.result index 81a57414426a4..52004738d29d7 100644 --- a/mysql-test/main/intersect_all.result +++ b/mysql-test/main/intersect_all.result @@ -1122,25 +1122,25 @@ drop view v; # First line of these results is column names, not the result # (pay attention to "affected rows") values (1, 2) union all values (1, 2); -1 2 +column_0 column_1 1 2 1 2 affected rows: 2 values (1, 2) union all values (1, 2) union values (4, 3) union all values (4, 3); -1 2 +column_0 column_1 1 2 4 3 4 3 affected rows: 3 values (1, 2) union all values (1, 2) union values (4, 3) union all values (4, 3) union all values (1, 2); -1 2 +column_0 column_1 1 2 4 3 4 3 1 2 affected rows: 4 values (1, 2) union all values (1, 2) union values (4, 3) union all values (4, 3) union all values (1, 2) union values (1, 2); -1 2 +column_0 column_1 1 2 4 3 affected rows: 2 @@ -1178,7 +1178,7 @@ a b create view v2 as select * from t1 union values (1, 2) intersect all select * from t2; show create view v2; View Create View character_set_client collation_connection -v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` union select `__5`.`1` AS `1`,`__5`.`2` AS `2` from (values (1,2) intersect all select `t2`.`a` AS `a`,`t2`.`b` AS `b` from `t2`) `__5` latin1 latin1_swedish_ci +v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` union select `__5`.`column_0` AS `column_0`,`__5`.`column_1` AS `column_1` from (values (1,2) intersect all select `t2`.`a` AS `a`,`t2`.`b` AS `b` from `t2`) `__5` latin1 latin1_swedish_ci select * from v2; a b 1 2 @@ -1240,7 +1240,7 @@ a b 2 3 show create view v2; View Create View character_set_client collation_connection -v2 CREATE VIEW "v2" AS select "__7"."a" AS "a","__7"."b" AS "b" from (select "t1"."a" AS "a","t1"."b" AS "b" from "t1" union select "__5"."1" AS "1","__5"."2" AS "2" from (select "__6"."1" AS "1","__6"."2" AS "2" from (values (1,2) intersect all select "t2"."a" AS "a","t2"."b" AS "b" from "t2") "__6") "__5") "__7" latin1 latin1_swedish_ci +v2 CREATE VIEW "v2" AS select "__7"."a" AS "a","__7"."b" AS "b" from (select "t1"."a" AS "a","t1"."b" AS "b" from "t1" union select "__5"."column_0" AS "column_0","__5"."column_1" AS "column_1" from (select "__6"."column_0" AS "column_0","__6"."column_1" AS "column_1" from (values (1,2) intersect all select "t2"."a" AS "a","t2"."b" AS "b" from "t2") "__6") "__5") "__7" latin1 latin1_swedish_ci select * from v2; a b 1 2 diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result index b8de88432befa..291915c72a7f8 100644 --- a/mysql-test/main/opt_trace.result +++ b/mysql-test/main/opt_trace.result @@ -12408,7 +12408,7 @@ jd } }, { - "expanded_query": "/* select#2 */ select tvc_0._col_1 from (values (1),(2),(3),(4),(5),(6)) tvc_0" + "expanded_query": "/* select#2 */ select tvc_0.column_0 from (values (1),(2),(3),(4),(5),(6)) tvc_0" } ] } diff --git a/mysql-test/main/opt_tvc.result b/mysql-test/main/opt_tvc.result index 819d42b539239..491171ee5641a 100644 --- a/mysql-test/main/opt_tvc.result +++ b/mysql-test/main/opt_tvc.result @@ -50,7 +50,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 100.00 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`_col_1` = `test`.`t1`.`a` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`column_0` = `test`.`t1`.`a` explain extended select * from t1 where a in ( @@ -62,7 +62,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 100.00 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`1` = `test`.`t1`.`a` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`column_0` = `test`.`t1`.`a` select * from t1 where a in (1,2,2,2,3,4,5,6,7); a b 1 2 @@ -88,7 +88,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 100.00 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2),(2),(2),(3),(4),(5),(6),(7)) `tvc_0` join `test`.`t1` where `tvc_0`.`_col_1` = `test`.`t1`.`a` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2),(2),(2),(3),(4),(5),(6),(7)) `tvc_0` join `test`.`t1` where `tvc_0`.`column_0` = `test`.`t1`.`a` explain extended select * from t1 where a in ( @@ -100,7 +100,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 100.00 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2),(2),(2),(2),(3),(4),(5),(6),(7)) `tvc_0` join `test`.`t1` where `tvc_0`.`1` = `test`.`t1`.`a` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2),(2),(2),(2),(3),(4),(5),(6),(7)) `tvc_0` join `test`.`t1` where `tvc_0`.`column_0` = `test`.`t1`.`a` # AND-condition with IN-predicates in WHERE-part select * from t1 where a in (1,2) and @@ -132,7 +132,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 5 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(5)) `tvc_1` join (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`_col_1` = `test`.`t1`.`a` and `tvc_1`.`_col_1` = `test`.`t1`.`b` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(5)) `tvc_1` join (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`column_0` = `test`.`t1`.`a` and `tvc_1`.`column_0` = `test`.`t1`.`b` explain extended select * from t1 where a in ( @@ -151,7 +151,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 5 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(5)) `tvc_1` join (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`1` = `test`.`t1`.`a` and `tvc_1`.`1` = `test`.`t1`.`b` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(5)) `tvc_1` join (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`column_0` = `test`.`t1`.`a` and `tvc_1`.`column_0` = `test`.`t1`.`b` # subquery with IN-predicate select * from t1 where a in @@ -186,7 +186,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 MATERIALIZED eq_ref distinct_key distinct_key 4 test.t2.b 1 100.00 4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (3),(4)) `tvc_0` join `test`.`t2`) where `tvc_0`.`_col_1` = `test`.`t2`.`b` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (3),(4)) `tvc_0` join `test`.`t2`) where `tvc_0`.`column_0` = `test`.`t2`.`b` explain extended select * from t1 where a in ( @@ -204,7 +204,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 MATERIALIZED eq_ref distinct_key distinct_key 4 test.t2.b 1 100.00 4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (3),(4)) `tvc_0` join `test`.`t2`) where `tvc_0`.`3` = `test`.`t2`.`b` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (3),(4)) `tvc_0` join `test`.`t2`) where `tvc_0`.`column_0` = `test`.`t2`.`b` # derived table with IN-predicate select * from ( @@ -242,7 +242,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 100.00 4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`_col_1` = `test`.`t1`.`a` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`column_0` = `test`.`t1`.`a` explain extended select * from ( select * @@ -259,7 +259,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 100.00 4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`1` = `test`.`t1`.`a` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`column_0` = `test`.`t1`.`a` # non-recursive CTE with IN-predicate with tvc_0 as ( @@ -299,7 +299,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 100.00 4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 with tvc_0 as (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (dual) join `test`.`t1` where `test`.`t1`.`a` in (1,2))/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`_col_1` = `test`.`t1`.`a` +Note 1003 with tvc_0 as (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (dual) join `test`.`t1` where `test`.`t1`.`a` in (1,2))/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`column_0` = `test`.`t1`.`a` explain extended select * from ( select * @@ -316,7 +316,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 100.00 4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`1` = `test`.`t1`.`a` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`column_0` = `test`.`t1`.`a` # VIEW with IN-predicate create view v1 as select * @@ -348,14 +348,14 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 100.00 4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`_col_1` = `test`.`t1`.`a` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`column_0` = `test`.`t1`.`a` explain extended select * from v2; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where 1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 100.00 4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`1` = `test`.`t1`.`a` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`column_0` = `test`.`t1`.`a` drop view v1,v2; # subselect defined by derived table with IN-predicate select * from t1 @@ -412,7 +412,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 MATERIALIZED eq_ref distinct_key distinct_key 4 test.t1.a 1 100.00 5 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0` join `test`.`t1`) where `test`.`t1`.`a` = 1 and `tvc_0`.`_col_1` = `test`.`t1`.`a` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0` join `test`.`t1`) where `test`.`t1`.`a` = 1 and `tvc_0`.`column_0` = `test`.`t1`.`a` explain extended select * from t1 where a in ( @@ -437,7 +437,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 MATERIALIZED eq_ref distinct_key distinct_key 4 test.t1.a 1 100.00 5 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0` join `test`.`t1`) where `test`.`t1`.`a` = 1 and `tvc_0`.`1` = `test`.`t1`.`a` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0` join `test`.`t1`) where `test`.`t1`.`a` = 1 and `tvc_0`.`column_0` = `test`.`t1`.`a` # derived table with IN-predicate and group by select * from ( @@ -475,7 +475,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DERIVED eq_ref distinct_key distinct_key 4 test.t1.b 1 100.00 4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `dr_table`.`max(a)` AS `max(a)`,`dr_table`.`b` AS `b` from (/* select#2 */ select max(`test`.`t1`.`a`) AS `max(a)`,`test`.`t1`.`b` AS `b` from (values (3),(5)) `tvc_0` join `test`.`t1` where `tvc_0`.`_col_1` = `test`.`t1`.`b` group by `test`.`t1`.`b`) `dr_table` +Note 1003 /* select#1 */ select `dr_table`.`max(a)` AS `max(a)`,`dr_table`.`b` AS `b` from (/* select#2 */ select max(`test`.`t1`.`a`) AS `max(a)`,`test`.`t1`.`b` AS `b` from (values (3),(5)) `tvc_0` join `test`.`t1` where `tvc_0`.`column_0` = `test`.`t1`.`b` group by `test`.`t1`.`b`) `dr_table` explain extended select * from ( select max(a),b @@ -494,7 +494,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DERIVED eq_ref distinct_key distinct_key 4 test.t1.b 1 100.00 4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `dr_table`.`max(a)` AS `max(a)`,`dr_table`.`b` AS `b` from (/* select#2 */ select max(`test`.`t1`.`a`) AS `max(a)`,`test`.`t1`.`b` AS `b` from (values (3),(5)) `tvc_0` join `test`.`t1` where `tvc_0`.`3` = `test`.`t1`.`b` group by `test`.`t1`.`b`) `dr_table` +Note 1003 /* select#1 */ select `dr_table`.`max(a)` AS `max(a)`,`dr_table`.`b` AS `b` from (/* select#2 */ select max(`test`.`t1`.`a`) AS `max(a)`,`test`.`t1`.`b` AS `b` from (values (3),(5)) `tvc_0` join `test`.`t1` where `tvc_0`.`column_0` = `test`.`t1`.`b` group by `test`.`t1`.`b`) `dr_table` # prepare statement prepare stmt from "select * from t1 where a in (1,2)"; execute stmt; @@ -531,10 +531,10 @@ a b explain extended select * from t3 where a in (1,4); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY ALL distinct_key NULL NULL NULL 2 100.00 -1 PRIMARY t3 ref idx idx 5 tvc_0._col_1 3 100.00 +1 PRIMARY t3 ref idx idx 5 tvc_0.column_0 3 100.00 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from (values (1),(4)) `tvc_0` join `test`.`t3` where `test`.`t3`.`a` = `tvc_0`.`_col_1` +Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from (values (1),(4)) `tvc_0` join `test`.`t3` where `test`.`t3`.`a` = `tvc_0`.`column_0` # use vectors in IN predeicate set @@in_predicate_conversion_threshold= 4; select * from t1 where (a,b) in ((1,2),(3,4)); @@ -546,7 +546,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.b 1 100.00 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1,2),(3,4)) `tvc_0` join `test`.`t1` where `tvc_0`.`_col_1` = `test`.`t1`.`a` and `tvc_0`.`_col_2` = `test`.`t1`.`b` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1,2),(3,4)) `tvc_0` join `test`.`t1` where `tvc_0`.`column_0` = `test`.`t1`.`a` and `tvc_0`.`column_1` = `test`.`t1`.`b` set @@in_predicate_conversion_threshold= 2; # transformation works for the one IN predicate and doesn't work for the other set @@in_predicate_conversion_threshold= 5; @@ -564,7 +564,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY eq_ref distinct_key distinct_key 8 test.t2.a,test.t2.c 1 100.00 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from (values (1,3),(8,0),(5,1)) `tvc_0` join `test`.`t2` where `tvc_0`.`_col_1` = `test`.`t2`.`a` and `tvc_0`.`_col_2` = `test`.`t2`.`c` and (`test`.`t2`.`a`,`test`.`t2`.`b`) in (((1,2)),((8,9))) +Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from (values (1,3),(8,0),(5,1)) `tvc_0` join `test`.`t2` where `tvc_0`.`column_0` = `test`.`t2`.`a` and `tvc_0`.`column_1` = `test`.`t2`.`c` and (`test`.`t2`.`a`,`test`.`t2`.`b`) in (((1,2)),((8,9))) set @@in_predicate_conversion_threshold= 2; # # mdev-14281: conversion of NOT IN predicate into subquery predicate @@ -592,7 +592,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DEPENDENT SUBQUERY unique_subquery distinct_key distinct_key 8 func,func 1 100.00 Using where; Full scan on NULL key 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<`test`.`t1`.`a`,`test`.`t1`.`b`>(((`test`.`t1`.`a`,`test`.`t1`.`b`),(((`test`.`t1`.`a`) in on distinct_key where trigcond((`test`.`t1`.`a`) = `tvc_0`.`_col_1`) and trigcond((`test`.`t1`.`b`) = `tvc_0`.`_col_2`))))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<`test`.`t1`.`a`,`test`.`t1`.`b`>(((`test`.`t1`.`a`,`test`.`t1`.`b`),(((`test`.`t1`.`a`) in on distinct_key where trigcond((`test`.`t1`.`a`) = `tvc_0`.`column_0`) and trigcond((`test`.`t1`.`b`) = `tvc_0`.`column_1`))))) explain extended select * from t1 where (a,b) not in (select * from (values (1,2),(8,9), (5,1)) as tvc_0); id select_type table type possible_keys key key_len ref rows filtered Extra @@ -600,7 +600,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DEPENDENT SUBQUERY unique_subquery distinct_key distinct_key 8 func,func 1 100.00 Using where; Full scan on NULL key 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<`test`.`t1`.`a`,`test`.`t1`.`b`>(((`test`.`t1`.`a`,`test`.`t1`.`b`),(((`test`.`t1`.`a`) in on distinct_key where trigcond((`test`.`t1`.`a`) = `tvc_0`.`1`) and trigcond((`test`.`t1`.`b`) = `tvc_0`.`2`))))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<`test`.`t1`.`a`,`test`.`t1`.`b`>(((`test`.`t1`.`a`,`test`.`t1`.`b`),(((`test`.`t1`.`a`) in on distinct_key where trigcond((`test`.`t1`.`a`) = `tvc_0`.`column_0`) and trigcond((`test`.`t1`.`b`) = `tvc_0`.`column_1`))))) select * from t1 where b < 7 and (a,b) not in ((1,2),(8,9), (5,1)); a b @@ -614,7 +614,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DEPENDENT SUBQUERY unique_subquery distinct_key distinct_key 8 func,func 1 100.00 Using where; Full scan on NULL key 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`b` < 7 and !<`test`.`t1`.`a`,`test`.`t1`.`b`>(((`test`.`t1`.`a`,`test`.`t1`.`b`),(((`test`.`t1`.`a`) in on distinct_key where trigcond((`test`.`t1`.`a`) = `tvc_0`.`_col_1`) and trigcond((`test`.`t1`.`b`) = `tvc_0`.`_col_2`))))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`b` < 7 and !<`test`.`t1`.`a`,`test`.`t1`.`b`>(((`test`.`t1`.`a`,`test`.`t1`.`b`),(((`test`.`t1`.`a`) in on distinct_key where trigcond((`test`.`t1`.`a`) = `tvc_0`.`column_0`) and trigcond((`test`.`t1`.`b`) = `tvc_0`.`column_1`))))) select * from t2 where (a,c) not in ((1,2),(8,9), (5,1)); a b c @@ -630,7 +630,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DEPENDENT SUBQUERY unique_subquery distinct_key distinct_key 8 func,func 1 100.00 Using where; Full scan on NULL key 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where !<`test`.`t2`.`a`,`test`.`t2`.`c`>(((`test`.`t2`.`a`,`test`.`t2`.`c`),(((`test`.`t2`.`a`) in on distinct_key where trigcond((`test`.`t2`.`a`) = `tvc_0`.`_col_1`) and trigcond((`test`.`t2`.`c`) = `tvc_0`.`_col_2`))))) +Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where !<`test`.`t2`.`a`,`test`.`t2`.`c`>(((`test`.`t2`.`a`,`test`.`t2`.`c`),(((`test`.`t2`.`a`) in on distinct_key where trigcond((`test`.`t2`.`a`) = `tvc_0`.`column_0`) and trigcond((`test`.`t2`.`c`) = `tvc_0`.`column_1`))))) drop table t1, t2, t3; set @@in_predicate_conversion_threshold= default; # diff --git a/mysql-test/main/table_value_constr.result b/mysql-test/main/table_value_constr.result index eef9e5b0cc43a..6e67fb5bdbeac 100644 --- a/mysql-test/main/table_value_constr.result +++ b/mysql-test/main/table_value_constr.result @@ -415,7 +415,7 @@ with t2 as values (1,2),(3,4) ) select * from t2; -1 2 +column_0 column_1 1 2 3 4 with t2 as @@ -444,7 +444,7 @@ union select 1,2 ) select * from t2; -1 2 +column_0 column_1 1 2 with t2 as ( @@ -453,7 +453,7 @@ union select 1,2 ) select * from t2; -1 2 +column_0 column_1 1 2 3 4 with t2 as @@ -463,7 +463,7 @@ union values (1,2),(3,4) ) select * from t2; -5 6 +column_0 column_1 5 6 1 2 3 4 @@ -474,7 +474,7 @@ union values (1,2),(3,4) ) select * from t2; -1 2 +column_0 column_1 1 2 3 4 with t2 as @@ -495,7 +495,7 @@ union all select 1,2 ) select * from t2; -1 2 +column_0 column_1 1 2 3 4 1 2 @@ -506,7 +506,7 @@ union all values (1,2),(3,4) ) select * from t2; -1 2 +column_0 column_1 1 2 1 2 3 4 @@ -594,7 +594,7 @@ n f 10 362880 # Derived table that uses VALUES structure(s) : singe VALUES structure select * from (values (1,2),(3,4)) as t2; -1 2 +column_0 column_1 1 2 3 4 # Derived table that uses VALUES structure(s) : UNION with VALUES structure(s) @@ -606,19 +606,19 @@ select * from (select 1,2 union values (1,2),(3,4)) as t2; 1 2 3 4 select * from (values (1,2) union select 1,2) as t2; -1 2 +column_0 column_1 1 2 select * from (values (1,2),(3,4) union select 1,2) as t2; -1 2 +column_0 column_1 1 2 3 4 select * from (values (5,6) union values (1,2),(3,4)) as t2; -5 6 +column_0 column_1 5 6 1 2 3 4 select * from (values (1,2) union values (1,2),(3,4)) as t2; -1 2 +column_0 column_1 1 2 3 4 # Derived table that uses VALUES structure(s) : UNION ALL with VALUES structure(s) @@ -628,19 +628,19 @@ select * from (select 1,2 union all values (1,2),(3,4)) as t2; 1 2 3 4 select * from (values (1,2),(3,4) union all select 1,2) as t2; -1 2 +column_0 column_1 1 2 3 4 1 2 select * from (values (1,2) union all values (1,2),(3,4)) as t2; -1 2 +column_0 column_1 1 2 1 2 3 4 # CREATE VIEW that uses VALUES structure(s) : singe VALUES structure create view v1 as values (1,2),(3,4); select * from v1; -1 2 +column_0 column_1 1 2 3 4 drop view v1; @@ -667,7 +667,7 @@ values (1,2) union select 1,2; select * from v1; -1 2 +column_0 column_1 1 2 drop view v1; create view v1 as @@ -675,7 +675,7 @@ values (1,2),(3,4) union select 1,2; select * from v1; -1 2 +column_0 column_1 1 2 3 4 drop view v1; @@ -684,7 +684,7 @@ values (5,6) union values (1,2),(3,4); select * from v1; -5 6 +column_0 column_1 5 6 1 2 3 4 @@ -695,7 +695,7 @@ values (1,2) union values (1,2),(3,4); select * from v1; -1 2 +column_0 column_1 1 2 3 4 drop view v1; @@ -714,7 +714,7 @@ values (1,2),(3,4) union all select 1,2; select * from v1; -1 2 +column_0 column_1 1 2 3 4 1 2 @@ -724,7 +724,7 @@ values (1,2) union all values (1,2),(3,4); select * from v1; -1 2 +column_0 column_1 1 2 1 2 3 4 @@ -747,7 +747,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 100.00 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1)) `tvc_0` join `test`.`t1` where `tvc_0`.`1` = `test`.`t1`.`a` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1)) `tvc_0` join `test`.`t1` where `tvc_0`.`column_0` = `test`.`t1`.`a` explain extended select * from t1 where a in (select * from (values (1)) as tvc_0); id select_type table type possible_keys key key_len ref rows filtered Extra @@ -755,7 +755,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 100.00 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1)) `tvc_0` join `test`.`t1` where `tvc_0`.`1` = `test`.`t1`.`a` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1)) `tvc_0` join `test`.`t1` where `tvc_0`.`column_0` = `test`.`t1`.`a` # IN-subquery with VALUES structure(s) : UNION with VALUES on the first place select * from t1 where a in (values (1) union select 2); @@ -779,7 +779,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#4 */ select `tvc_0`.`1` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`1` union /* select#3 */ select 2 having (`test`.`t1`.`a`) = (2)))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#4 */ select `tvc_0`.`column_0` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`column_0` union /* select#3 */ select 2 having (`test`.`t1`.`a`) = (2)))) explain extended select * from t1 where a in (select * from (values (1)) as tvc_0 union select 2); @@ -790,7 +790,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 4 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select `tvc_0`.`1` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`1` union /* select#4 */ select 2 having (`test`.`t1`.`a`) = (2)))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select `tvc_0`.`column_0` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`column_0` union /* select#4 */ select 2 having (`test`.`t1`.`a`) = (2)))) # IN-subquery with VALUES structure(s) : UNION with VALUES on the second place select * from t1 where a in (select 2 union values (1)); @@ -814,7 +814,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select 2 having (`test`.`t1`.`a`) = (2) union /* select#4 */ select `tvc_0`.`1` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`1`))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select 2 having (`test`.`t1`.`a`) = (2) union /* select#4 */ select `tvc_0`.`column_0` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`column_0`))) explain extended select * from t1 where a in (select 2 union select * from (values (1)) tvc_0); @@ -825,7 +825,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select 2 having (`test`.`t1`.`a`) = (2) union /* select#3 */ select `tvc_0`.`1` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`1`))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select 2 having (`test`.`t1`.`a`) = (2) union /* select#3 */ select `tvc_0`.`column_0` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`column_0`))) # IN-subquery with VALUES structure(s) : UNION ALL select * from t1 where a in (values (1) union all select b from t1); @@ -850,7 +850,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 3 DEPENDENT UNION t1 ALL NULL NULL NULL NULL 6 100.00 Using where Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#4 */ select `tvc_0`.`1` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`1` union all /* select#3 */ select `test`.`t1`.`b` from `test`.`t1` where (`test`.`t1`.`a`) = `test`.`t1`.`b`))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#4 */ select `tvc_0`.`column_0` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`column_0` union all /* select#3 */ select `test`.`t1`.`b` from `test`.`t1` where (`test`.`t1`.`a`) = `test`.`t1`.`b`))) explain extended select * from t1 where a in (select * from (values (1)) as tvc_0 union all select b from t1); @@ -860,7 +860,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 4 DEPENDENT UNION t1 ALL NULL NULL NULL NULL 6 100.00 Using where Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select `tvc_0`.`1` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`1` union all /* select#4 */ select `test`.`t1`.`b` from `test`.`t1` where (`test`.`t1`.`a`) = `test`.`t1`.`b`))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select `tvc_0`.`column_0` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`column_0` union all /* select#4 */ select `test`.`t1`.`b` from `test`.`t1` where (`test`.`t1`.`a`) = `test`.`t1`.`b`))) # NOT IN subquery with VALUES structure(s) : simple case select * from t1 where a not in (values (1),(2)); @@ -881,7 +881,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DEPENDENT SUBQUERY unique_subquery distinct_key distinct_key 4 func 1 100.00 Using where; Full scan on NULL key 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<`test`.`t1`.`a`>((`test`.`t1`.`a`,(((`test`.`t1`.`a`) in on distinct_key where trigcond((`test`.`t1`.`a`) = `tvc_0`.`1`))))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<`test`.`t1`.`a`>((`test`.`t1`.`a`,(((`test`.`t1`.`a`) in on distinct_key where trigcond((`test`.`t1`.`a`) = `tvc_0`.`column_0`))))) explain extended select * from t1 where a not in (select * from (values (1),(2)) as tvc_0); id select_type table type possible_keys key key_len ref rows filtered Extra @@ -889,7 +889,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DEPENDENT SUBQUERY unique_subquery distinct_key distinct_key 4 func 1 100.00 Using where; Full scan on NULL key 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<`test`.`t1`.`a`>((`test`.`t1`.`a`,(((`test`.`t1`.`a`) in on distinct_key where trigcond((`test`.`t1`.`a`) = `tvc_0`.`1`))))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<`test`.`t1`.`a`>((`test`.`t1`.`a`,(((`test`.`t1`.`a`) in on distinct_key where trigcond((`test`.`t1`.`a`) = `tvc_0`.`column_0`))))) # NOT IN subquery with VALUES structure(s) : UNION with VALUES on the first place select * from t1 where a not in (values (1) union select 2); @@ -913,7 +913,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#4 */ select `tvc_0`.`1` from (values (1)) `tvc_0` where trigcond((`test`.`t1`.`a`) = `tvc_0`.`1`) union /* select#3 */ select 2 having trigcond((`test`.`t1`.`a`) = (2))))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#4 */ select `tvc_0`.`column_0` from (values (1)) `tvc_0` where trigcond((`test`.`t1`.`a`) = `tvc_0`.`column_0`) union /* select#3 */ select 2 having trigcond((`test`.`t1`.`a`) = (2))))) explain extended select * from t1 where a not in (select * from (values (1)) as tvc_0 union select 2); @@ -924,7 +924,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 4 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select `tvc_0`.`1` from (values (1)) `tvc_0` where trigcond((`test`.`t1`.`a`) = `tvc_0`.`1`) union /* select#4 */ select 2 having trigcond((`test`.`t1`.`a`) = (2))))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select `tvc_0`.`column_0` from (values (1)) `tvc_0` where trigcond((`test`.`t1`.`a`) = `tvc_0`.`column_0`) union /* select#4 */ select 2 having trigcond((`test`.`t1`.`a`) = (2))))) # NOT IN subquery with VALUES structure(s) : UNION with VALUES on the second place select * from t1 where a not in (select 2 union values (1)); @@ -948,7 +948,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select 2 having trigcond((`test`.`t1`.`a`) = (2)) union /* select#4 */ select `tvc_0`.`1` from (values (1)) `tvc_0` where trigcond((`test`.`t1`.`a`) = `tvc_0`.`1`)))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select 2 having trigcond((`test`.`t1`.`a`) = (2)) union /* select#4 */ select `tvc_0`.`column_0` from (values (1)) `tvc_0` where trigcond((`test`.`t1`.`a`) = `tvc_0`.`column_0`)))) explain extended select * from t1 where a not in (select 2 union select * from (values (1)) as tvc_0); @@ -959,7 +959,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select 2 having trigcond((`test`.`t1`.`a`) = (2)) union /* select#3 */ select `tvc_0`.`1` from (values (1)) `tvc_0` where trigcond((`test`.`t1`.`a`) = `tvc_0`.`1`)))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select 2 having trigcond((`test`.`t1`.`a`) = (2)) union /* select#3 */ select `tvc_0`.`column_0` from (values (1)) `tvc_0` where trigcond((`test`.`t1`.`a`) = `tvc_0`.`column_0`)))) # ANY-subquery with VALUES structure(s) : simple case select * from t1 where a = any (values (1),(2)); @@ -980,7 +980,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 100.00 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`1` = `test`.`t1`.`a` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`column_0` = `test`.`t1`.`a` explain extended select * from t1 where a = any (select * from (values (1),(2)) as tvc_0); id select_type table type possible_keys key key_len ref rows filtered Extra @@ -988,7 +988,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 100.00 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`1` = `test`.`t1`.`a` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from (values (1),(2)) `tvc_0` join `test`.`t1` where `tvc_0`.`column_0` = `test`.`t1`.`a` # ANY-subquery with VALUES structure(s) : UNION with VALUES on the first place select * from t1 where a = any (values (1) union select 2); @@ -1012,7 +1012,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#4 */ select `tvc_0`.`1` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`1` union /* select#3 */ select 2 having (`test`.`t1`.`a`) = (2)))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#4 */ select `tvc_0`.`column_0` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`column_0` union /* select#3 */ select 2 having (`test`.`t1`.`a`) = (2)))) explain extended select * from t1 where a = any (select * from (values (1)) as tvc_0 union select 2); @@ -1023,7 +1023,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 4 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select `tvc_0`.`1` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`1` union /* select#4 */ select 2 having (`test`.`t1`.`a`) = (2)))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select `tvc_0`.`column_0` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`column_0` union /* select#4 */ select 2 having (`test`.`t1`.`a`) = (2)))) # ANY-subquery with VALUES structure(s) : UNION with VALUES on the second place select * from t1 where a = any (select 2 union values (1)); @@ -1047,7 +1047,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select 2 having (`test`.`t1`.`a`) = (2) union /* select#4 */ select `tvc_0`.`1` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`1`))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select 2 having (`test`.`t1`.`a`) = (2) union /* select#4 */ select `tvc_0`.`column_0` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`column_0`))) explain extended select * from t1 where a = any (select 2 union select * from (values (1)) as tvc_0); @@ -1058,7 +1058,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select 2 having (`test`.`t1`.`a`) = (2) union /* select#3 */ select `tvc_0`.`1` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`1`))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select 2 having (`test`.`t1`.`a`) = (2) union /* select#3 */ select `tvc_0`.`column_0` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`column_0`))) # ALL-subquery with VALUES structure(s) : simple case select * from t1 where a = all (values (1)); @@ -1077,7 +1077,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DEPENDENT SUBQUERY ALL NULL NULL NULL NULL 2 100.00 Using where 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (<`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#3 */ select `tvc_0`.`1` from (values (1)) `tvc_0` where trigcond((`test`.`t1`.`a`) <> `tvc_0`.`1`))))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (<`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#3 */ select `tvc_0`.`column_0` from (values (1)) `tvc_0` where trigcond((`test`.`t1`.`a`) <> `tvc_0`.`column_0`))))) explain extended select * from t1 where a = all (select * from (values (1)) as tvc_0); id select_type table type possible_keys key key_len ref rows filtered Extra @@ -1085,7 +1085,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DEPENDENT SUBQUERY ALL NULL NULL NULL NULL 2 100.00 Using where 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (<`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select `tvc_0`.`1` from (values (1)) `tvc_0` where trigcond((`test`.`t1`.`a`) <> `tvc_0`.`1`))))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (<`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select `tvc_0`.`column_0` from (values (1)) `tvc_0` where trigcond((`test`.`t1`.`a`) <> `tvc_0`.`column_0`))))) # ALL-subquery with VALUES structure(s) : UNION with VALUES on the first place select * from t1 where a = all (values (1) union select 1); @@ -1107,7 +1107,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (<`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#4 */ select `tvc_0`.`1` from (values (1)) `tvc_0` where trigcond((`test`.`t1`.`a`) <> `tvc_0`.`1`) union /* select#3 */ select 1 having trigcond((`test`.`t1`.`a`) <> (1)))))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (<`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#4 */ select `tvc_0`.`column_0` from (values (1)) `tvc_0` where trigcond((`test`.`t1`.`a`) <> `tvc_0`.`column_0`) union /* select#3 */ select 1 having trigcond((`test`.`t1`.`a`) <> (1)))))) explain extended select * from t1 where a = all (select * from (values (1)) as tvc_0 union select 1); @@ -1118,7 +1118,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 4 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (<`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select `tvc_0`.`1` from (values (1)) `tvc_0` where trigcond((`test`.`t1`.`a`) <> `tvc_0`.`1`) union /* select#4 */ select 1 having trigcond((`test`.`t1`.`a`) <> (1)))))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (<`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select `tvc_0`.`column_0` from (values (1)) `tvc_0` where trigcond((`test`.`t1`.`a`) <> `tvc_0`.`column_0`) union /* select#4 */ select 1 having trigcond((`test`.`t1`.`a`) <> (1)))))) # ALL-subquery with VALUES structure(s) : UNION with VALUES on the second place select * from t1 where a = any (select 1 union values (1)); @@ -1140,7 +1140,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select 1 having (`test`.`t1`.`a`) = (1) union /* select#4 */ select `tvc_0`.`1` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`1`))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select 1 having (`test`.`t1`.`a`) = (1) union /* select#4 */ select `tvc_0`.`column_0` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`column_0`))) explain extended select * from t1 where a = any (select 1 union select * from (values (1)) as tvc_0); @@ -1151,7 +1151,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select 1 having (`test`.`t1`.`a`) = (1) union /* select#3 */ select `tvc_0`.`1` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`1`))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#2 */ select 1 having (`test`.`t1`.`a`) = (1) union /* select#3 */ select `tvc_0`.`column_0` from (values (1)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`column_0`))) # prepare statement that uses VALUES structure(s): single VALUES structure prepare stmt1 from " values (1,2); @@ -2102,7 +2102,7 @@ ERROR HY000: Row with no elements is not allowed in table value constructor in t create table t1 (a int); insert into t1 values (9), (3), (2); select * from (values (7), (5), (8), (1), (3), (8), (1)) t; -7 +column_0 7 5 8 @@ -2115,7 +2115,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY ALL NULL NULL NULL NULL 7 2 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used select * from (values (1,11), (7,77), (3,31), (4,42)) t; -1 11 +column_0 column_1 1 11 7 77 3 31 @@ -2125,7 +2125,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY ALL NULL NULL NULL NULL 4 2 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used select * from (values (7), (5), (8), (1) union values (3), (8), (1)) t; -7 +column_0 7 5 8 @@ -2138,7 +2138,7 @@ id select_type table type possible_keys key key_len ref rows Extra 3 UNION NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL select * from (values (7), (5), (8), (1) union select * from t1) t; -7 +column_0 7 5 8 @@ -2178,14 +2178,14 @@ VALUES(1 + 1,2,"abc"); 1 + 1 2 abc 2 2 abc SELECT * FROM (VALUES(1 + 1,2,"abc")) t; -1 + 1 2 abc +column_0 column_1 column_2 2 2 abc PREPARE stmt FROM "SELECT * FROM (VALUES(1 + 1,2,'abc')) t"; EXECUTE stmt; -1 + 1 2 abc +column_0 column_1 column_2 2 2 abc EXECUTE stmt; -1 + 1 2 abc +column_0 column_1 column_2 2 2 abc DEALLOCATE PREPARE stmt; # @@ -2291,7 +2291,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select 2 AS `2` union (/* select#3 */ select `tvc_0`.`5` AS `5` from (values (5),(7),(1),(3),(4)) `tvc_0` order by 1 limit 2) +Note 1003 /* select#1 */ select 2 AS `2` union (/* select#3 */ select `tvc_0`.`column_0` AS `column_0` from (values (5),(7),(1),(3),(4)) `tvc_0` order by 1 limit 2) select 2 union (values (5), (7), (1), (3), (4) order by 1 limit 2 offset 1); 2 2 @@ -2304,7 +2304,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select 2 AS `2` union (/* select#3 */ select `tvc_0`.`5` AS `5` from (values (5),(7),(1),(3),(4)) `tvc_0` order by 1 limit 1,2) +Note 1003 /* select#1 */ select 2 AS `2` union (/* select#3 */ select `tvc_0`.`column_0` AS `column_0` from (values (5),(7),(1),(3),(4)) `tvc_0` order by 1 limit 1,2) (values (5), (7), (1), (3), (4) limit 2) union select 2; 5 5 @@ -2330,7 +2330,7 @@ NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: Note 1003 (values (5),(7),(1),(3),(4) limit 1,2) union /* select#2 */ select 2 AS `2` (values (5), (7), (1), (3), (4) order by 1 limit 2) union select 2; -5 +column_0 1 3 2 @@ -2341,9 +2341,9 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 (/* select#1 */ select `tvc_0`.`5` AS `5` from (values (5),(7),(1),(3),(4)) `tvc_0` order by 1 limit 2) union /* select#2 */ select 2 AS `2` +Note 1003 (/* select#1 */ select `tvc_0`.`column_0` AS `column_0` from (values (5),(7),(1),(3),(4)) `tvc_0` order by 1 limit 2) union /* select#2 */ select 2 AS `2` (values (5), (7), (1), (3), (4) order by 1 limit 2 offset 1) union select 2; -5 +column_0 3 4 2 @@ -2354,7 +2354,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 (/* select#1 */ select `tvc_0`.`5` AS `5` from (values (5),(7),(1),(3),(4)) `tvc_0` order by 1 limit 1,2) union /* select#2 */ select 2 AS `2` +Note 1003 (/* select#1 */ select `tvc_0`.`column_0` AS `column_0` from (values (5),(7),(1),(3),(4)) `tvc_0` order by 1 limit 1,2) union /* select#2 */ select 2 AS `2` select 3 union all (values (5), (7), (1), (3), (4) limit 2 offset 3); 3 3 @@ -2389,9 +2389,9 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select 3 AS `3` union all (/* select#3 */ select `tvc_0`.`5` AS `5` from (values (5),(7),(1),(3),(4)) `tvc_0` order by 1 limit 2) +Note 1003 /* select#1 */ select 3 AS `3` union all (/* select#3 */ select `tvc_0`.`column_0` AS `column_0` from (values (5),(7),(1),(3),(4)) `tvc_0` order by 1 limit 2) (values (5), (7), (1), (3), (4) order by 1 limit 2) union all select 3; -5 +column_0 1 3 3 @@ -2402,7 +2402,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 (/* select#1 */ select `tvc_0`.`5` AS `5` from (values (5),(7),(1),(3),(4)) `tvc_0` order by 1 limit 2) union all /* select#2 */ select 3 AS `3` +Note 1003 (/* select#1 */ select `tvc_0`.`column_0` AS `column_0` from (values (5),(7),(1),(3),(4)) `tvc_0` order by 1 limit 2) union all /* select#2 */ select 3 AS `3` ( values (5), (7), (1), (3), (4) limit 2 offset 1 ) union ( values (5), (7), (1), (3), (4) order by 1 limit 2 ); @@ -2419,7 +2419,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 (values (5),(7),(1),(3),(4) limit 1,2) union (/* select#3 */ select `tvc_0`.`5` AS `5` from (values (5),(7),(1),(3),(4)) `tvc_0` order by 1 limit 2) +Note 1003 (values (5),(7),(1),(3),(4) limit 1,2) union (/* select#3 */ select `tvc_0`.`column_0` AS `column_0` from (values (5),(7),(1),(3),(4)) `tvc_0` order by 1 limit 2) ( values (5), (7), (1), (3), (4) limit 2 offset 1 ) union all ( values (5), (7), (1), (3), (4) order by 1 limit 2 ); @@ -2437,7 +2437,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 (values (5),(7),(1),(3),(4) limit 1,2) union all (/* select#3 */ select `tvc_0`.`5` AS `5` from (values (5),(7),(1),(3),(4)) `tvc_0` order by 1 limit 2) +Note 1003 (values (5),(7),(1),(3),(4) limit 1,2) union all (/* select#3 */ select `tvc_0`.`column_0` AS `column_0` from (values (5),(7),(1),(3),(4)) `tvc_0` order by 1 limit 2) (values (5), (7), (1), (3), (4) limit 2 offset 3) union all select 3 order by 1; 5 3 @@ -2451,7 +2451,7 @@ NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Using filesort Warnings: Note 1003 (values (5),(7),(1),(3),(4) limit 3,2) union all /* select#2 */ select 3 AS `3` order by 1 (values (5), (7), (1), (3), (4) order by 1 limit 3 offset 1) union all select 3 order by 1; -5 +column_0 3 3 4 @@ -2463,10 +2463,10 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Using filesort Warnings: -Note 1003 (/* select#1 */ select `tvc_0`.`5` AS `5` from (values (5),(7),(1),(3),(4)) `tvc_0` order by 1 limit 1,3) union all /* select#2 */ select 3 AS `3` order by 1 +Note 1003 (/* select#1 */ select `tvc_0`.`column_0` AS `column_0` from (values (5),(7),(1),(3),(4)) `tvc_0` order by 1 limit 1,3) union all /* select#2 */ select 3 AS `3` order by 1 (values (5), (7), (1), (3), (4) order by 1 limit 3 offset 1) union all select 3 order by 1 limit 2 offset 1; -5 +column_0 3 4 explain extended (values (5), (7), (1), (3), (4) order by 1 limit 3 offset 1) union all select 3 @@ -2477,7 +2477,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Using filesort Warnings: -Note 1003 (/* select#1 */ select `tvc_0`.`5` AS `5` from (values (5),(7),(1),(3),(4)) `tvc_0` order by 1 limit 1,3) union all /* select#2 */ select 3 AS `3` order by 1 limit 1,2 +Note 1003 (/* select#1 */ select `tvc_0`.`column_0` AS `column_0` from (values (5),(7),(1),(3),(4)) `tvc_0` order by 1 limit 1,3) union all /* select#2 */ select 3 AS `3` order by 1 limit 1,2 values (5,90), (7,20), (1,70), (3,50), (4,10) order by 3; ERROR 42S22: Unknown column '3' in 'ORDER BY' prepare stmt from " @@ -2561,7 +2561,7 @@ show create view v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS values (5),(7),(1),(3),(4) order by 1 limit 2 latin1 latin1_swedish_ci select * from v1; -5 +column_0 1 3 drop view v1; @@ -2573,7 +2573,7 @@ show create view v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS (values (5),(7),(1),(3),(4) limit 1,2) union (values (5),(7),(1),(3),(4) order by 1 limit 2) latin1 latin1_swedish_ci select * from v1; -5 +column_0 7 1 3 @@ -2690,7 +2690,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#4 */ select `tvc_0`.`7` from (values (7)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`7` union /* select#5 */ select `tvc_0`.`8` from (values (8)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`8`))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where <`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#4 */ select `tvc_0`.`column_0` from (values (7)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`column_0` union /* select#5 */ select `tvc_0`.`column_0` from (values (8)) `tvc_0` where (`test`.`t1`.`a`) = `tvc_0`.`column_0`))) prepare stmt from "select a from t1 where a in (values (7) union values (8))"; execute stmt; a @@ -2712,7 +2712,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where !<`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#4 */ select `tvc_0`.`7` from (values (7)) `tvc_0` where trigcond((`test`.`t1`.`a`) = `tvc_0`.`7`) union /* select#5 */ select `tvc_0`.`8` from (values (8)) `tvc_0` where trigcond((`test`.`t1`.`a`) = `tvc_0`.`8`)))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where !<`test`.`t1`.`a`>((`test`.`t1`.`a`,(/* select#4 */ select `tvc_0`.`column_0` from (values (7)) `tvc_0` where trigcond((`test`.`t1`.`a`) = `tvc_0`.`column_0`) union /* select#5 */ select `tvc_0`.`column_0` from (values (8)) `tvc_0` where trigcond((`test`.`t1`.`a`) = `tvc_0`.`column_0`)))) select a from t1 where a < all(values (7) union values (8)); a 3 @@ -2726,7 +2726,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a`,(/* select#4 */ select `tvc_0`.`7` from (values (7)) `tvc_0` union /* select#5 */ select `tvc_0`.`8` from (values (8)) `tvc_0`) <= (`test`.`t1`.`a`))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a`,(/* select#4 */ select `tvc_0`.`column_0` from (values (7)) `tvc_0` union /* select#5 */ select `tvc_0`.`column_0` from (values (8)) `tvc_0`) <= (`test`.`t1`.`a`))) select a from t1 where a >= any(values (7) union values (8)); a 7 @@ -2739,7 +2739,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a`,(/* select#4 */ select `tvc_0`.`7` from (values (7)) `tvc_0` union /* select#5 */ select `tvc_0`.`8` from (values (8)) `tvc_0`) <= (`test`.`t1`.`a`))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a`,(/* select#4 */ select `tvc_0`.`column_0` from (values (7)) `tvc_0` union /* select#5 */ select `tvc_0`.`column_0` from (values (8)) `tvc_0`) <= (`test`.`t1`.`a`))) drop table t1; # # MDEV-24934:EXPLAIN for queries based on TVC using subqueries @@ -2994,25 +2994,25 @@ values ((values (8))), ((values ((select 4)))); 8 4 select * from (values ((values (2)))) dt; -(values (2)) +column_0 2 select * from (values ((values (2)), (5), (select 4))) dt; -(values (2)) 5 (select 4) +column_0 column_1 column_2 2 5 4 select * from (values ((values (2))) union values ((values (3)))) dt; -(values (2)) +column_0 2 3 select * from (values ((values (2))), ((values (3)))) dt; -(values (2)) +column_0 2 3 select * from (values ((values (2))), ((values (3)))) dt; -(values (2)) +column_0 2 3 select * from (values ((values (2))), ((select 4)), ((values (3)))) dt; -(values (2)) +column_0 2 4 3 @@ -3047,10 +3047,10 @@ NULL values ((select (values(2)) from t1 where a<7)); ERROR 21000: Subquery returns more than 1 row select * from (values ((values ((select a from t1 where a=7))))) dt; -(values ((select a from t1 where a=7))) +column_0 7 select * from (values ((values ((select (values(2)) from t1 where a=8))))) dt; -(values ((select (values(2)) from t1 where a=8))) +column_0 NULL insert into t1(a) values ((values (2))), ((values (3))); select * from t1; @@ -3071,11 +3071,11 @@ a 3 7 (values (3), (7), (1) limit 2) order by 1 desc; -3 +column_0 7 3 select * from ( (values (3), (7), (1) limit 2) order by 1 desc) as dt; -3 +column_0 3 7 select * from ( select * from t1 order by 1 limit 2 ) as dt; @@ -3087,7 +3087,7 @@ values (3),(7),(1) order by 1 limit 2; 1 3 select * from ( values (3),(7),(1) order by 1 limit 2 ) as dt; -3 +column_0 1 3 values (3),(7),(1) union values (2),(4) order by 1 limit 2; @@ -3095,7 +3095,7 @@ values (3),(7),(1) union values (2),(4) order by 1 limit 2; 1 2 select * from (values (3),(7),(1) union values (2),(4) order by 1 limit 2) as dt; -3 +column_0 1 2 drop table t1; @@ -3277,3 +3277,107 @@ drop table t1,t2; # # End of 10.4 tests # +# +# MDEV-19941 "Duplicate column name" while using VALUES table constructor +# +SELECT * from (VALUES (1,1),(2,2)) t; +column_0 column_1 +1 1 +2 2 +# explicit column list takes precedence over generated names +select * from (values (1,1)) t(a,b); +a b +1 1 +# generated names can be referenced +select column_0 from (values (1,2)) t; +column_0 +1 +# first select of a union determines the names +select * from (values (1,1) union select 2,3) t; +column_0 column_1 +1 1 +2 3 +select * from (values (1,1) except values (2,2)) t; +column_0 column_1 +1 1 +# generated names become table column names in CTAS +create table t1 as select * from (values (1,1)) x; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `column_0` int(2) NOT NULL DEFAULT 0, + `column_1` int(2) NOT NULL DEFAULT 0 +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +drop table t1; +# view over a TVC derived table +create view v1 as select * from (values (1,1)) t; +show create view v1; +View Create View character_set_client collation_connection +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t`.`column_0` AS `column_0`,`t`.`column_1` AS `column_1` from (values (1,1)) `t` latin1 latin1_swedish_ci +select * from v1; +column_0 column_1 +1 1 +drop view v1; +# prepared statement re-execution +prepare s from 'select * from (values (1,1)) t'; +execute s; +column_0 column_1 +1 1 +execute s; +column_0 column_1 +1 1 +deallocate prepare s; +# CTE without a column list gets generated names +with t as (values (1,1)) select * from t; +column_0 column_1 +1 1 +# explicit CTE column list takes precedence +with t(a,b) as (values (1,1)) select * from t; +a b +1 1 +with t as (values (1,2)) select column_1 from t; +column_1 +2 +# CTE referenced more than once +with t as (values (1,1)) select * from t a, t b; +column_0 column_1 column_0 column_1 +1 1 1 1 +with t as (values (1,1) union all values (2,2)) select * from t; +column_0 column_1 +1 1 +2 2 +# recursive CTE with a TVC anchor +with recursive t as ( +values (1,1) union +select column_0+1, column_1 from t where column_0 < 3) +select * from t; +column_0 column_1 +1 1 +2 1 +3 1 +# TVC CTE inside a derived table, derived TVC inside a CTE +select * from (with t as (values (1,1)) select * from t) d; +column_0 column_1 +1 1 +with t as (select * from (values (1,1)) x) select * from t; +column_0 column_1 +1 1 +prepare s from 'with t as (values (1,1)) select * from t'; +execute s; +column_0 column_1 +1 1 +execute s; +column_0 column_1 +1 1 +deallocate prepare s; +create view v1 as with t as (values (1,1)) select * from t; +show create view v1; +View Create View character_set_client collation_connection +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS with t as (values (1,1))select `t`.`column_0` AS `column_0`,`t`.`column_1` AS `column_1` from `t` latin1 latin1_swedish_ci +select * from v1; +column_0 column_1 +1 1 +drop view v1; +# +# End of 11.8 tests +# diff --git a/mysql-test/main/table_value_constr.test b/mysql-test/main/table_value_constr.test index 29347a16f9855..2a84db677a5aa 100644 --- a/mysql-test/main/table_value_constr.test +++ b/mysql-test/main/table_value_constr.test @@ -1837,3 +1837,75 @@ drop table t1,t2; --echo # --echo # End of 10.4 tests --echo # + +--echo # +--echo # MDEV-19941 "Duplicate column name" while using VALUES table constructor +--echo # + +SELECT * from (VALUES (1,1),(2,2)) t; + +--echo # explicit column list takes precedence over generated names +select * from (values (1,1)) t(a,b); + +--echo # generated names can be referenced +select column_0 from (values (1,2)) t; + +--echo # first select of a union determines the names +select * from (values (1,1) union select 2,3) t; + +select * from (values (1,1) except values (2,2)) t; + +--echo # generated names become table column names in CTAS +create table t1 as select * from (values (1,1)) x; +show create table t1; +drop table t1; + +--echo # view over a TVC derived table +create view v1 as select * from (values (1,1)) t; +show create view v1; +select * from v1; +drop view v1; + +--echo # prepared statement re-execution +prepare s from 'select * from (values (1,1)) t'; +execute s; +execute s; +deallocate prepare s; + +--echo # CTE without a column list gets generated names +with t as (values (1,1)) select * from t; + +--echo # explicit CTE column list takes precedence +with t(a,b) as (values (1,1)) select * from t; + +with t as (values (1,2)) select column_1 from t; + +--echo # CTE referenced more than once +with t as (values (1,1)) select * from t a, t b; + +with t as (values (1,1) union all values (2,2)) select * from t; + +--echo # recursive CTE with a TVC anchor +with recursive t as ( + values (1,1) union + select column_0+1, column_1 from t where column_0 < 3) +select * from t; + +--echo # TVC CTE inside a derived table, derived TVC inside a CTE +select * from (with t as (values (1,1)) select * from t) d; + +with t as (select * from (values (1,1)) x) select * from t; + +prepare s from 'with t as (values (1,1)) select * from t'; +execute s; +execute s; +deallocate prepare s; + +create view v1 as with t as (values (1,1)) select * from t; +show create view v1; +select * from v1; +drop view v1; + +--echo # +--echo # End of 11.8 tests +--echo # diff --git a/mysql-test/main/vector_funcs.result b/mysql-test/main/vector_funcs.result index 6aba9df0b055c..6834d4f1a028d 100644 --- a/mysql-test/main/vector_funcs.result +++ b/mysql-test/main/vector_funcs.result @@ -151,8 +151,8 @@ Warning 4036 Character disallowed in JSON in argument 1 to function 'VEC_FromTex # # MDEV-35220 Assertion `!item->null_value' failed upon VEC_TOTEXT call # -select vec_totext(`null`) from (values (null),(0x00000000)) x; -vec_totext(`null`) +select vec_totext(`column_0`) from (values (null),(0x00000000)) x; +vec_totext(`column_0`) NULL [0] # diff --git a/mysql-test/main/vector_funcs.test b/mysql-test/main/vector_funcs.test index b0ada0fa61fbf..c2e9041595993 100644 --- a/mysql-test/main/vector_funcs.test +++ b/mysql-test/main/vector_funcs.test @@ -70,7 +70,7 @@ select vec_fromtext(0x00000000); --echo # --echo # MDEV-35220 Assertion `!item->null_value' failed upon VEC_TOTEXT call --echo # -select vec_totext(`null`) from (values (null),(0x00000000)) x; +select vec_totext(`column_0`) from (values (null),(0x00000000)) x; --echo # --echo # MDEV-36011 Server crashes in Charset::mbminlen / Item_func_vec_fromtext::val_str upon mixing vector type with string diff --git a/mysql-test/suite/compat/oracle/r/table_value_constr.result b/mysql-test/suite/compat/oracle/r/table_value_constr.result index 1528099c2c72c..4fc449165a813 100644 --- a/mysql-test/suite/compat/oracle/r/table_value_constr.result +++ b/mysql-test/suite/compat/oracle/r/table_value_constr.result @@ -23,7 +23,7 @@ values (1,2); values (1,2) union select 1,2; -1 2 +column_0 column_1 1 2 select 1,2 union @@ -71,14 +71,14 @@ values (1,2),(3,6); values (1,2.4),(3,6) union select 2.8,9; -1 2.4 +column_0 column_1 1.0 2.4 3.0 6.0 2.8 9.0 values (1,2),(3,4),(5,6),(7,8) union select 5,6; -1 2 +column_0 column_1 1 2 3 4 5 6 @@ -93,18 +93,18 @@ we q values ('ab', 'cdf') union select 'ab','cdf'; -ab cdf +column_0 column_1 ab cdf values (1,2) union values (1,2),(5,6); -1 2 +column_0 column_1 1 2 5 6 values (1,2) union values (3,4),(5,6); -1 2 +column_0 column_1 1 2 3 4 5 6 @@ -112,21 +112,21 @@ values (1,2) union values (1,2) union values (4,5); -1 2 +column_0 column_1 1 2 4 5 # UNION ALL that uses VALUES structure values (1,2),(3,4) union all select 5,6; -1 2 +column_0 column_1 1 2 3 4 5 6 values (1,2),(3,4) union all select 1,2; -1 2 +column_0 column_1 1 2 3 4 1 2 @@ -147,14 +147,14 @@ values (1,2),(3,4); values (1,2) union all values (1,2),(5,6); -1 2 +column_0 column_1 1 2 1 2 5 6 values (1,2) union all values (3,4),(5,6); -1 2 +column_0 column_1 1 2 3 4 5 6 @@ -163,7 +163,7 @@ union all values (1,2) union all values (4,5); -1 2 +column_0 column_1 1 2 1 2 4 5 @@ -171,14 +171,14 @@ values (1,2) union all values (1,2) union values (1,2); -1 2 +column_0 column_1 1 2 values (1,2) union values (1,2) union all values (1,2); -1 2 +column_0 column_1 1 2 1 2 # EXCEPT that uses VALUES structure(s) @@ -194,24 +194,24 @@ values (1,2),(3,4); values (1,2),(3,4) except select 5,6; -1 2 +column_0 column_1 1 2 3 4 values (1,2),(3,4) except select 1,2; -1 2 +column_0 column_1 3 4 values (1,2),(3,4) except values (5,6); -1 2 +column_0 column_1 1 2 3 4 values (1,2),(3,4) except values (1,2); -1 2 +column_0 column_1 3 4 # INTERSECT that uses VALUES structure(s) select 1,2 @@ -226,27 +226,27 @@ values (1,2),(3,4); values (1,2),(3,4) intersect select 5,6; -1 2 +column_0 column_1 values (1,2),(3,4) intersect select 1,2; -1 2 +column_0 column_1 1 2 values (1,2),(3,4) intersect values (5,6); -1 2 +column_0 column_1 values (1,2),(3,4) intersect values (1,2); -1 2 +column_0 column_1 1 2 # combination of different structures that uses VALUES structures : UNION + EXCEPT values (1,2),(3,4) except select 1,2 union values (1,2); -1 2 +column_0 column_1 3 4 1 2 values (1,2),(3,4) @@ -254,7 +254,7 @@ except values (1,2) union values (1,2); -1 2 +column_0 column_1 3 4 1 2 values (1,2),(3,4) @@ -262,14 +262,14 @@ except values (1,2) union values (3,4); -1 2 +column_0 column_1 3 4 values (1,2),(3,4) union values (1,2) except values (1,2); -1 2 +column_0 column_1 3 4 # combination of different structures that uses VALUES structures : UNION ALL + EXCEPT values (1,2),(3,4) @@ -277,7 +277,7 @@ except select 1,2 union all values (1,2); -1 2 +column_0 column_1 3 4 1 2 values (1,2),(3,4) @@ -285,7 +285,7 @@ except values (1,2) union all values (1,2); -1 2 +column_0 column_1 3 4 1 2 values (1,2),(3,4) @@ -293,7 +293,7 @@ except values (1,2) union all values (3,4); -1 2 +column_0 column_1 3 4 3 4 values (1,2),(3,4) @@ -301,7 +301,7 @@ union all values (1,2) except values (1,2); -1 2 +column_0 column_1 3 4 # combination of different structures that uses VALUES structures : UNION + INTERSECT values (1,2),(3,4) @@ -309,21 +309,21 @@ intersect select 1,2 union values (1,2); -1 2 +column_0 column_1 1 2 values (1,2),(3,4) intersect values (1,2) union values (1,2); -1 2 +column_0 column_1 1 2 values (1,2),(3,4) intersect values (1,2) union values (3,4); -1 2 +column_0 column_1 1 2 3 4 values (1,2),(3,4) @@ -331,7 +331,7 @@ union values (1,2) intersect values (1,2); -1 2 +column_0 column_1 1 2 # combination of different structures that uses VALUES structures : UNION ALL + INTERSECT values (1,2),(3,4) @@ -339,7 +339,7 @@ intersect select 1,2 union all values (1,2); -1 2 +column_0 column_1 1 2 1 2 values (1,2),(3,4) @@ -347,7 +347,7 @@ intersect values (1,2) union all values (1,2); -1 2 +column_0 column_1 1 2 1 2 values (1,2),(3,4) @@ -355,7 +355,7 @@ intersect values (1,2) union all values (3,4); -1 2 +column_0 column_1 1 2 3 4 values (1,2),(3,4) @@ -363,7 +363,7 @@ union all values (1,2) intersect values (1,2); -1 2 +column_0 column_1 1 2 # combination of different structures that uses VALUES structures : UNION + UNION ALL values (1,2),(3,4) @@ -371,7 +371,7 @@ union all select 1,2 union values (1,2); -1 2 +column_0 column_1 1 2 3 4 values (1,2),(3,4) @@ -379,7 +379,7 @@ union all values (1,2) union values (1,2); -1 2 +column_0 column_1 1 2 3 4 values (1,2),(3,4) @@ -387,7 +387,7 @@ union all values (1,2) union values (3,4); -1 2 +column_0 column_1 1 2 3 4 values (1,2),(3,4) @@ -395,7 +395,7 @@ union values (1,2) union all values (1,2); -1 2 +column_0 column_1 1 2 3 4 1 2 @@ -404,7 +404,7 @@ union values (1,2) union all values (1,2); -1 2 +column_0 column_1 1 2 1 2 # CTE that uses VALUES structure(s) : non-recursive CTE @@ -413,7 +413,7 @@ with t2 as values (1,2),(3,4) ) select * from t2; -1 2 +column_0 column_1 1 2 3 4 with t2 as @@ -442,7 +442,7 @@ union select 1,2 ) select * from t2; -1 2 +column_0 column_1 1 2 with t2 as ( @@ -451,7 +451,7 @@ union select 1,2 ) select * from t2; -1 2 +column_0 column_1 1 2 3 4 with t2 as @@ -461,7 +461,7 @@ union values (1,2),(3,4) ) select * from t2; -5 6 +column_0 column_1 5 6 1 2 3 4 @@ -472,7 +472,7 @@ union values (1,2),(3,4) ) select * from t2; -1 2 +column_0 column_1 1 2 3 4 with t2 as @@ -493,7 +493,7 @@ union all select 1,2 ) select * from t2; -1 2 +column_0 column_1 1 2 3 4 1 2 @@ -504,7 +504,7 @@ union all values (1,2),(3,4) ) select * from t2; -1 2 +column_0 column_1 1 2 1 2 3 4 @@ -592,7 +592,7 @@ n f 10 362880 # Derived table that uses VALUES structure(s) : singe VALUES structure select * from (values (1,2),(3,4)) as t2; -1 2 +column_0 column_1 1 2 3 4 # Derived table that uses VALUES structure(s) : UNION with VALUES structure(s) @@ -604,19 +604,19 @@ select * from (select 1,2 union values (1,2),(3,4)) as t2; 1 2 3 4 select * from (values (1,2) union select 1,2) as t2; -1 2 +column_0 column_1 1 2 select * from (values (1,2),(3,4) union select 1,2) as t2; -1 2 +column_0 column_1 1 2 3 4 select * from (values (5,6) union values (1,2),(3,4)) as t2; -5 6 +column_0 column_1 5 6 1 2 3 4 select * from (values (1,2) union values (1,2),(3,4)) as t2; -1 2 +column_0 column_1 1 2 3 4 # Derived table that uses VALUES structure(s) : UNION ALL with VALUES structure(s) @@ -626,19 +626,19 @@ select * from (select 1,2 union all values (1,2),(3,4)) as t2; 1 2 3 4 select * from (values (1,2),(3,4) union all select 1,2) as t2; -1 2 +column_0 column_1 1 2 3 4 1 2 select * from (values (1,2) union all values (1,2),(3,4)) as t2; -1 2 +column_0 column_1 1 2 1 2 3 4 # CREATE VIEW that uses VALUES structure(s) : singe VALUES structure create view v1 as values (1,2),(3,4); select * from v1; -1 2 +column_0 column_1 1 2 3 4 drop view v1; @@ -665,7 +665,7 @@ values (1,2) union select 1,2; select * from v1; -1 2 +column_0 column_1 1 2 drop view v1; create view v1 as @@ -673,7 +673,7 @@ values (1,2),(3,4) union select 1,2; select * from v1; -1 2 +column_0 column_1 1 2 3 4 drop view v1; @@ -682,7 +682,7 @@ values (5,6) union values (1,2),(3,4); select * from v1; -5 6 +column_0 column_1 5 6 1 2 3 4 @@ -693,7 +693,7 @@ values (1,2) union values (1,2),(3,4); select * from v1; -1 2 +column_0 column_1 1 2 3 4 drop view v1; @@ -712,7 +712,7 @@ values (1,2),(3,4) union all select 1,2; select * from v1; -1 2 +column_0 column_1 1 2 3 4 1 2 @@ -722,7 +722,7 @@ values (1,2) union all values (1,2),(3,4); select * from v1; -1 2 +column_0 column_1 1 2 1 2 3 4 @@ -745,7 +745,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 100.00 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (values (1)) "tvc_0" join "test"."t1" where "tvc_0"."1" = "test"."t1"."a" +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (values (1)) "tvc_0" join "test"."t1" where "tvc_0"."column_0" = "test"."t1"."a" explain extended select * from t1 where a in (select * from (values (1)) as tvc_0); id select_type table type possible_keys key key_len ref rows filtered Extra @@ -753,7 +753,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 100.00 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (values (1)) "tvc_0" join "test"."t1" where "tvc_0"."1" = "test"."t1"."a" +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (values (1)) "tvc_0" join "test"."t1" where "tvc_0"."column_0" = "test"."t1"."a" # IN-subquery with VALUES structure(s) : UNION with VALUES on the first place select * from t1 where a in (values (1) union select 2); @@ -777,7 +777,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (values (1) union /* select#3 */ select 2 AS "2") "__4" join "test"."t1" where "__4"."1" = "test"."t1"."a" +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (values (1) union /* select#3 */ select 2 AS "2") "__4" join "test"."t1" where "__4"."column_0" = "test"."t1"."a" explain extended select * from t1 where a in (select * from (values (1)) as tvc_0 union select 2); @@ -789,7 +789,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 4 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (/* select#2 */ select "tvc_0"."1" AS "1" from (values (1)) "tvc_0" union /* select#4 */ select 2 AS "2") "__5" join "test"."t1" where "__5"."1" = "test"."t1"."a" +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (/* select#2 */ select "tvc_0"."column_0" AS "column_0" from (values (1)) "tvc_0" union /* select#4 */ select 2 AS "2") "__5" join "test"."t1" where "__5"."column_0" = "test"."t1"."a" # IN-subquery with VALUES structure(s) : UNION with VALUES on the second place select * from t1 where a in (select 2 union values (1)); @@ -825,7 +825,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (/* select#2 */ select 2 AS "2" union /* select#3 */ select "tvc_0"."1" AS "1" from (values (1)) "tvc_0") "__5" join "test"."t1" where "__5"."2" = "test"."t1"."a" +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (/* select#2 */ select 2 AS "2" union /* select#3 */ select "tvc_0"."column_0" AS "column_0" from (values (1)) "tvc_0") "__5" join "test"."t1" where "__5"."2" = "test"."t1"."a" # IN-subquery with VALUES structure(s) : UNION ALL select * from t1 where a in (values (1) union all select b from t1); @@ -850,7 +850,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 3 UNION t1 ALL NULL NULL NULL NULL 6 100.00 Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" semi join ((values (1) union all /* select#3 */ select "test"."t1"."b" AS "b" from "test"."t1") "__4") where "__4"."1" = "test"."t1"."a" +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" semi join ((values (1) union all /* select#3 */ select "test"."t1"."b" AS "b" from "test"."t1") "__4") where "__4"."column_0" = "test"."t1"."a" explain extended select * from t1 where a in (select * from (values (1)) as tvc_0 union all select b from t1); @@ -861,7 +861,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 4 UNION t1 ALL NULL NULL NULL NULL 6 100.00 Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" semi join ((/* select#2 */ select "tvc_0"."1" AS "1" from (values (1)) "tvc_0" union all /* select#4 */ select "test"."t1"."b" AS "b" from "test"."t1") "__5") where "__5"."1" = "test"."t1"."a" +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" semi join ((/* select#2 */ select "tvc_0"."column_0" AS "column_0" from (values (1)) "tvc_0" union all /* select#4 */ select "test"."t1"."b" AS "b" from "test"."t1") "__5") where "__5"."column_0" = "test"."t1"."a" # NOT IN subquery with VALUES structure(s) : simple case select * from t1 where a not in (values (1),(2)); @@ -882,7 +882,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DEPENDENT SUBQUERY unique_subquery distinct_key distinct_key 4 func 1 100.00 Using where; Full scan on NULL key 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" where !<"test"."t1"."a">(("test"."t1"."a",((("test"."t1"."a") in on distinct_key where trigcond(("test"."t1"."a") = "tvc_0"."1"))))) +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" where !<"test"."t1"."a">(("test"."t1"."a",((("test"."t1"."a") in on distinct_key where trigcond(("test"."t1"."a") = "tvc_0"."column_0"))))) explain extended select * from t1 where a not in (select * from (values (1),(2)) as tvc_0); id select_type table type possible_keys key key_len ref rows filtered Extra @@ -890,7 +890,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DEPENDENT SUBQUERY unique_subquery distinct_key distinct_key 4 func 1 100.00 Using where; Full scan on NULL key 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" where !<"test"."t1"."a">(("test"."t1"."a",((("test"."t1"."a") in on distinct_key where trigcond(("test"."t1"."a") = "tvc_0"."1"))))) +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" where !<"test"."t1"."a">(("test"."t1"."a",((("test"."t1"."a") in on distinct_key where trigcond(("test"."t1"."a") = "tvc_0"."column_0"))))) # NOT IN subquery with VALUES structure(s) : UNION with VALUES on the first place select * from t1 where a not in (values (1) union select 2); @@ -914,7 +914,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" where !<"test"."t1"."a">(("test"."t1"."a",((("test"."t1"."a") in on distinct_key where trigcond(("test"."t1"."a") = "__4"."1"))))) +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" where !<"test"."t1"."a">(("test"."t1"."a",((("test"."t1"."a") in on distinct_key where trigcond(("test"."t1"."a") = "__4"."column_0"))))) explain extended select * from t1 where a not in (select * from (values (1)) as tvc_0 union select 2); @@ -926,7 +926,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 4 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" where !<"test"."t1"."a">(("test"."t1"."a",((("test"."t1"."a") in on distinct_key where trigcond(("test"."t1"."a") = "__5"."1"))))) +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" where !<"test"."t1"."a">(("test"."t1"."a",((("test"."t1"."a") in on distinct_key where trigcond(("test"."t1"."a") = "__5"."column_0"))))) # NOT IN subquery with VALUES structure(s) : UNION with VALUES on the second place select * from t1 where a not in (select 2 union values (1)); @@ -983,7 +983,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 100.00 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (values (1),(2)) "tvc_0" join "test"."t1" where "tvc_0"."1" = "test"."t1"."a" +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (values (1),(2)) "tvc_0" join "test"."t1" where "tvc_0"."column_0" = "test"."t1"."a" explain extended select * from t1 where a = any (select * from (values (1),(2)) as tvc_0); id select_type table type possible_keys key key_len ref rows filtered Extra @@ -991,7 +991,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY eq_ref distinct_key distinct_key 4 test.t1.a 1 100.00 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (values (1),(2)) "tvc_0" join "test"."t1" where "tvc_0"."1" = "test"."t1"."a" +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (values (1),(2)) "tvc_0" join "test"."t1" where "tvc_0"."column_0" = "test"."t1"."a" # ANY-subquery with VALUES structure(s) : UNION with VALUES on the first place select * from t1 where a = any (values (1) union select 2); @@ -1015,7 +1015,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (values (1) union /* select#3 */ select 2 AS "2") "__4" join "test"."t1" where "__4"."1" = "test"."t1"."a" +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (values (1) union /* select#3 */ select 2 AS "2") "__4" join "test"."t1" where "__4"."column_0" = "test"."t1"."a" explain extended select * from t1 where a = any (select * from (values (1)) as tvc_0 union select 2); @@ -1027,7 +1027,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 4 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (/* select#2 */ select "tvc_0"."1" AS "1" from (values (1)) "tvc_0" union /* select#4 */ select 2 AS "2") "__5" join "test"."t1" where "__5"."1" = "test"."t1"."a" +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (/* select#2 */ select "tvc_0"."column_0" AS "column_0" from (values (1)) "tvc_0" union /* select#4 */ select 2 AS "2") "__5" join "test"."t1" where "__5"."column_0" = "test"."t1"."a" # ANY-subquery with VALUES structure(s) : UNION with VALUES on the second place select * from t1 where a = any (select 2 union values (1)); @@ -1063,7 +1063,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (/* select#2 */ select 2 AS "2" union /* select#3 */ select "tvc_0"."1" AS "1" from (values (1)) "tvc_0") "__5" join "test"."t1" where "__5"."2" = "test"."t1"."a" +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (/* select#2 */ select 2 AS "2" union /* select#3 */ select "tvc_0"."column_0" AS "column_0" from (values (1)) "tvc_0") "__5" join "test"."t1" where "__5"."2" = "test"."t1"."a" # ALL-subquery with VALUES structure(s) : simple case select * from t1 where a = all (values (1)); @@ -1082,7 +1082,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DEPENDENT SUBQUERY ALL NULL NULL NULL NULL 2 100.00 Using where 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" where (<"test"."t1"."a">(("test"."t1"."a",(/* select#3 */ select "tvc_0"."1" from (values (1)) "tvc_0" where trigcond(("test"."t1"."a") <> "tvc_0"."1"))))) +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" where (<"test"."t1"."a">(("test"."t1"."a",(/* select#3 */ select "tvc_0"."column_0" from (values (1)) "tvc_0" where trigcond(("test"."t1"."a") <> "tvc_0"."column_0"))))) explain extended select * from t1 where a = all (select * from (values (1)) as tvc_0); id select_type table type possible_keys key key_len ref rows filtered Extra @@ -1090,7 +1090,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DEPENDENT SUBQUERY ALL NULL NULL NULL NULL 2 100.00 Using where 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" where (<"test"."t1"."a">(("test"."t1"."a",(/* select#2 */ select "tvc_0"."1" from (values (1)) "tvc_0" where trigcond(("test"."t1"."a") <> "tvc_0"."1"))))) +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" where (<"test"."t1"."a">(("test"."t1"."a",(/* select#2 */ select "tvc_0"."column_0" from (values (1)) "tvc_0" where trigcond(("test"."t1"."a") <> "tvc_0"."column_0"))))) # ALL-subquery with VALUES structure(s) : UNION with VALUES on the first place select * from t1 where a = all (values (1) union select 1); @@ -1112,7 +1112,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" where (<"test"."t1"."a">(("test"."t1"."a",(/* select#4 */ select "__4"."1" from (values (1) union /* select#3 */ select 1 AS "1") "__4" where trigcond(("test"."t1"."a") <> "__4"."1"))))) +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" where (<"test"."t1"."a">(("test"."t1"."a",(/* select#4 */ select "__4"."column_0" from (values (1) union /* select#3 */ select 1 AS "1") "__4" where trigcond(("test"."t1"."a") <> "__4"."column_0"))))) explain extended select * from t1 where a = all (select * from (values (1)) as tvc_0 union select 1); @@ -1124,7 +1124,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 4 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" where (<"test"."t1"."a">(("test"."t1"."a",(/* select#5 */ select "__5"."1" from (/* select#2 */ select "tvc_0"."1" AS "1" from (values (1)) "tvc_0" union /* select#4 */ select 1 AS "1") "__5" where trigcond(("test"."t1"."a") <> "__5"."1"))))) +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" where (<"test"."t1"."a">(("test"."t1"."a",(/* select#5 */ select "__5"."column_0" from (/* select#2 */ select "tvc_0"."column_0" AS "column_0" from (values (1)) "tvc_0" union /* select#4 */ select 1 AS "1") "__5" where trigcond(("test"."t1"."a") <> "__5"."column_0"))))) # ALL-subquery with VALUES structure(s) : UNION with VALUES on the second place select * from t1 where a = any (select 1 union values (1)); @@ -1158,7 +1158,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (/* select#2 */ select 1 AS "1" union /* select#3 */ select "tvc_0"."1" AS "1" from (values (1)) "tvc_0") "__5" join "test"."t1" where "__5"."1" = "test"."t1"."a" +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from (/* select#2 */ select 1 AS "1" union /* select#3 */ select "tvc_0"."column_0" AS "column_0" from (values (1)) "tvc_0") "__5" join "test"."t1" where "__5"."1" = "test"."t1"."a" # prepare statement that uses VALUES structure(s): single VALUES structure prepare stmt1 from ' values (1,2); @@ -1191,11 +1191,11 @@ prepare stmt1 from ' select 1,2; '; execute stmt1; -1 2 +column_0 column_1 1 2 3 4 execute stmt1; -1 2 +column_0 column_1 1 2 3 4 deallocate prepare stmt1; @@ -1221,12 +1221,12 @@ prepare stmt1 from ' values (1,2),(3,4); '; execute stmt1; -5 6 +column_0 column_1 5 6 1 2 3 4 execute stmt1; -5 6 +column_0 column_1 5 6 1 2 3 4 @@ -1252,12 +1252,12 @@ prepare stmt1 from ' select 1,2; '; execute stmt1; -1 2 +column_0 column_1 1 2 3 4 1 2 execute stmt1; -1 2 +column_0 column_1 1 2 3 4 1 2 @@ -1286,12 +1286,12 @@ prepare stmt1 from ' values (1,2),(3,4); '; execute stmt1; -1 2 +column_0 column_1 1 2 1 2 3 4 execute stmt1; -1 2 +column_0 column_1 1 2 1 2 3 4 @@ -2613,7 +2613,7 @@ ERROR HY000: Row with no elements is not allowed in table value constructor in t create table t1 (a int); insert into t1 values (9), (3), (2); select * from (values (7), (5), (8), (1), (3), (8), (1)) t; -7 +column_0 7 5 8 @@ -2626,7 +2626,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY ALL NULL NULL NULL NULL 7 2 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used select * from (values (1,11), (7,77), (3,31), (4,42)) t; -1 11 +column_0 column_1 1 11 7 77 3 31 @@ -2636,7 +2636,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY ALL NULL NULL NULL NULL 4 2 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used select * from (values (7), (5), (8), (1) union values (3), (8), (1)) t; -7 +column_0 7 5 8 @@ -2649,7 +2649,7 @@ id select_type table type possible_keys key key_len ref rows Extra 3 UNION NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL select * from (values (7), (5), (8), (1) union select * from t1) t; -7 +column_0 7 5 8 @@ -2689,7 +2689,7 @@ VALUES(1 + 1,2,'abc'); 1 + 1 2 abc 2 2 abc SELECT * FROM (VALUES(1 + 1,2,'abc')) t; -1 + 1 2 abc +column_0 column_1 column_2 2 2 abc # # MDEV-17894: tvc with ORDER BY ... LIMIT @@ -2797,7 +2797,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "__3"."2" AS "2" from (/* select#2 */ select 2 AS "2" union (/* select#4 */ select "tvc_0"."5" AS "5" from (values (5),(7),(1),(3),(4)) "tvc_0" order by 1 limit 2)) "__3" +Note 1003 /* select#1 */ select "__3"."2" AS "2" from (/* select#2 */ select 2 AS "2" union (/* select#4 */ select "tvc_0"."column_0" AS "column_0" from (values (5),(7),(1),(3),(4)) "tvc_0" order by 1 limit 2)) "__3" select 2 union (values (5), (7), (1), (3), (4) order by 1 limit 2 offset 1); 2 2 @@ -2811,9 +2811,9 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "__3"."2" AS "2" from (/* select#2 */ select 2 AS "2" union (/* select#4 */ select "tvc_0"."5" AS "5" from (values (5),(7),(1),(3),(4)) "tvc_0" order by 1 limit 1,2)) "__3" +Note 1003 /* select#1 */ select "__3"."2" AS "2" from (/* select#2 */ select 2 AS "2" union (/* select#4 */ select "tvc_0"."column_0" AS "column_0" from (values (5),(7),(1),(3),(4)) "tvc_0" order by 1 limit 1,2)) "__3" (values (5), (7), (1), (3), (4) limit 2) union select 2; -5 +column_0 5 7 2 @@ -2824,9 +2824,9 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "__3"."5" AS "5" from ((values (5),(7),(1),(3),(4) limit 2) union /* select#3 */ select 2 AS "2") "__3" +Note 1003 /* select#1 */ select "__3"."column_0" AS "column_0" from ((values (5),(7),(1),(3),(4) limit 2) union /* select#3 */ select 2 AS "2") "__3" (values (5), (7), (1), (3), (4) limit 2 offset 1) union select 2; -5 +column_0 7 1 2 @@ -2837,9 +2837,9 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "__3"."5" AS "5" from ((values (5),(7),(1),(3),(4) limit 1,2) union /* select#3 */ select 2 AS "2") "__3" +Note 1003 /* select#1 */ select "__3"."column_0" AS "column_0" from ((values (5),(7),(1),(3),(4) limit 1,2) union /* select#3 */ select 2 AS "2") "__3" (values (5), (7), (1), (3), (4) order by 1 limit 2) union select 2; -5 +column_0 1 3 2 @@ -2851,9 +2851,9 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "__3"."5" AS "5" from ((/* select#4 */ select "tvc_0"."5" AS "5" from (values (5),(7),(1),(3),(4)) "tvc_0" order by 1 limit 2) union /* select#3 */ select 2 AS "2") "__3" +Note 1003 /* select#1 */ select "__3"."column_0" AS "column_0" from ((/* select#4 */ select "tvc_0"."column_0" AS "column_0" from (values (5),(7),(1),(3),(4)) "tvc_0" order by 1 limit 2) union /* select#3 */ select 2 AS "2") "__3" (values (5), (7), (1), (3), (4) order by 1 limit 2 offset 1) union select 2; -5 +column_0 3 4 2 @@ -2865,7 +2865,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "__3"."5" AS "5" from ((/* select#4 */ select "tvc_0"."5" AS "5" from (values (5),(7),(1),(3),(4)) "tvc_0" order by 1 limit 1,2) union /* select#3 */ select 2 AS "2") "__3" +Note 1003 /* select#1 */ select "__3"."column_0" AS "column_0" from ((/* select#4 */ select "tvc_0"."column_0" AS "column_0" from (values (5),(7),(1),(3),(4)) "tvc_0" order by 1 limit 1,2) union /* select#3 */ select 2 AS "2") "__3" select 3 union all (values (5), (7), (1), (3), (4) limit 2 offset 3); 3 3 @@ -2879,7 +2879,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra Warnings: Note 1003 /* select#1 */ select "__3"."3" AS "3" from (/* select#2 */ select 3 AS "3" union all (values (5),(7),(1),(3),(4) limit 3,2)) "__3" (values (5), (7), (1), (3), (4) limit 2 offset 3) union all select 3; -5 +column_0 3 4 3 @@ -2889,7 +2889,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 3 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select "__3"."5" AS "5" from ((values (5),(7),(1),(3),(4) limit 3,2) union all /* select#3 */ select 3 AS "3") "__3" +Note 1003 /* select#1 */ select "__3"."column_0" AS "column_0" from ((values (5),(7),(1),(3),(4) limit 3,2) union all /* select#3 */ select 3 AS "3") "__3" select 3 union all (values (5), (7), (1), (3), (4) order by 1 limit 2); 3 3 @@ -2902,9 +2902,9 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "__3"."3" AS "3" from (/* select#2 */ select 3 AS "3" union all (/* select#4 */ select "tvc_0"."5" AS "5" from (values (5),(7),(1),(3),(4)) "tvc_0" order by 1 limit 2)) "__3" +Note 1003 /* select#1 */ select "__3"."3" AS "3" from (/* select#2 */ select 3 AS "3" union all (/* select#4 */ select "tvc_0"."column_0" AS "column_0" from (values (5),(7),(1),(3),(4)) "tvc_0" order by 1 limit 2)) "__3" (values (5), (7), (1), (3), (4) order by 1 limit 2) union all select 3; -5 +column_0 1 3 explain extended (values (5), (7), (1), (3), (4) order by 1 limit 2) union all select 3; @@ -2915,11 +2915,11 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "__3"."5" AS "5" from ((/* select#4 */ select "tvc_0"."5" AS "5" from (values (5),(7),(1),(3),(4)) "tvc_0" order by 1 limit 2) union all /* select#3 */ select 3 AS "3") "__3" +Note 1003 /* select#1 */ select "__3"."column_0" AS "column_0" from ((/* select#4 */ select "tvc_0"."column_0" AS "column_0" from (values (5),(7),(1),(3),(4)) "tvc_0" order by 1 limit 2) union all /* select#3 */ select 3 AS "3") "__3" ( values (5), (7), (1), (3), (4) limit 2 offset 1 ) union ( values (5), (7), (1), (3), (4) order by 1 limit 2 ); -5 +column_0 7 1 3 @@ -2933,11 +2933,11 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "__3"."5" AS "5" from ((values (5),(7),(1),(3),(4) limit 1,2) union (/* select#4 */ select "tvc_0"."5" AS "5" from (values (5),(7),(1),(3),(4)) "tvc_0" order by 1 limit 2)) "__3" +Note 1003 /* select#1 */ select "__3"."column_0" AS "column_0" from ((values (5),(7),(1),(3),(4) limit 1,2) union (/* select#4 */ select "tvc_0"."column_0" AS "column_0" from (values (5),(7),(1),(3),(4)) "tvc_0" order by 1 limit 2)) "__3" ( values (5), (7), (1), (3), (4) limit 2 offset 1 ) union all ( values (5), (7), (1), (3), (4) order by 1 limit 2 ); -5 +column_0 7 1 3 @@ -2951,9 +2951,9 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "__3"."5" AS "5" from ((values (5),(7),(1),(3),(4) limit 1,2) union all (/* select#4 */ select "tvc_0"."5" AS "5" from (values (5),(7),(1),(3),(4)) "tvc_0" order by 1 limit 2)) "__3" +Note 1003 /* select#1 */ select "__3"."column_0" AS "column_0" from ((values (5),(7),(1),(3),(4) limit 1,2) union all (/* select#4 */ select "tvc_0"."column_0" AS "column_0" from (values (5),(7),(1),(3),(4)) "tvc_0" order by 1 limit 2)) "__3" (values (5), (7), (1), (3), (4) limit 2 offset 3) union all select 3 order by 1; -5 +column_0 3 3 4 @@ -2963,9 +2963,9 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 3 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select "__3"."5" AS "5" from ((values (5),(7),(1),(3),(4) limit 3,2) union all /* select#3 */ select 3 AS "3") "__3" order by 1 +Note 1003 /* select#1 */ select "__3"."column_0" AS "column_0" from ((values (5),(7),(1),(3),(4) limit 3,2) union all /* select#3 */ select 3 AS "3") "__3" order by 1 (values (5), (7), (1), (3), (4) order by 1 limit 3 offset 1) union all select 3 order by 1; -5 +column_0 3 4 5 @@ -2977,10 +2977,10 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "__3"."5" AS "5" from ((/* select#4 */ select "tvc_0"."5" AS "5" from (values (5),(7),(1),(3),(4)) "tvc_0" order by 1 limit 1,3) union all /* select#3 */ select 3 AS "3") "__3" order by 1 +Note 1003 /* select#1 */ select "__3"."column_0" AS "column_0" from ((/* select#4 */ select "tvc_0"."column_0" AS "column_0" from (values (5),(7),(1),(3),(4)) "tvc_0" order by 1 limit 1,3) union all /* select#3 */ select 3 AS "3") "__3" order by 1 (values (5), (7), (1), (3), (4) order by 1 limit 3 offset 1) union all select 3 order by 1 limit 2 offset 1; -5 +column_0 4 5 explain extended (values (5), (7), (1), (3), (4) order by 1 limit 3 offset 1) union all select 3 @@ -2992,7 +2992,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 3 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 /* select#1 */ select "__3"."5" AS "5" from ((/* select#4 */ select "tvc_0"."5" AS "5" from (values (5),(7),(1),(3),(4)) "tvc_0" order by 1 limit 1,3) union all /* select#3 */ select 3 AS "3") "__3" order by 1 limit 1,2 +Note 1003 /* select#1 */ select "__3"."column_0" AS "column_0" from ((/* select#4 */ select "tvc_0"."column_0" AS "column_0" from (values (5),(7),(1),(3),(4)) "tvc_0" order by 1 limit 1,3) union all /* select#3 */ select 3 AS "3") "__3" order by 1 limit 1,2 values (5,90), (7,20), (1,70), (3,50), (4,10) order by 3; ERROR 42S22: Unknown column '3' in 'ORDER BY' create view v1 as values (5), (7), (1), (3), (4) order by 1 limit 2; @@ -3000,7 +3000,7 @@ show create view v1; View Create View character_set_client collation_connection v1 CREATE VIEW "v1" AS values (5),(7),(1),(3),(4) order by 1 limit 2 latin1 latin1_swedish_ci select * from v1; -5 +column_0 1 3 drop view v1; @@ -3010,9 +3010,9 @@ union ( values (5), (7), (1), (3), (4) order by 1 limit 2 ); show create view v1; View Create View character_set_client collation_connection -v1 CREATE VIEW "v1" AS select "__4"."5" AS "5" from (select "__5"."5" AS "5" from ((values (5),(7),(1),(3),(4) limit 1,2) union (values (5),(7),(1),(3),(4) order by 1 limit 2)) "__5") "__4" latin1 latin1_swedish_ci +v1 CREATE VIEW "v1" AS select "__4"."column_0" AS "column_0" from (select "__5"."column_0" AS "column_0" from ((values (5),(7),(1),(3),(4) limit 1,2) union (values (5),(7),(1),(3),(4) order by 1 limit 2)) "__5") "__4" latin1 latin1_swedish_ci select * from v1; -5 +column_0 7 1 3 diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 5882487c703a5..e363d30f80821 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -1407,6 +1407,34 @@ inline bool st_select_lex_unit::rename_types_list(List *newnames) } +static bool sequential_rename_item_list(THD *thd, List *list) +{ + constexpr char TVC_COLUMN_NAME[]= "column_"; + constexpr uint TVC_MAX_COL_NO= 10000; // 0...9999 + constexpr uint TVC_MAX_COL_DIGITS= 4; + + if (list->elements > TVC_MAX_COL_NO) + { + my_error(ER_TOO_MANY_FIELDS, MYF(0)); + return TRUE; + } + + // rename these items column_[0..n-1] + List_iterator_fast li(*list); + Item *item; + char colname[sizeof(TVC_COLUMN_NAME)+TVC_MAX_COL_DIGITS]; + strcpy( colname, TVC_COLUMN_NAME); + + for (uint i= 0; (item= li++); i++) + { + snprintf(colname+sizeof(TVC_COLUMN_NAME)-1, TVC_MAX_COL_DIGITS+1, + "%u", i ); + item->set_name(thd, colname, strlen(colname), system_charset_info); + } + return FALSE; +} + + bool st_select_lex_unit::prepare(TABLE_LIST *derived_arg, select_result *sel_result, ulonglong additional_options) @@ -1708,10 +1736,20 @@ bool st_select_lex_unit::prepare(TABLE_LIST *derived_arg, { if (with_element) { - if (with_element->process_columns_of_derived_unit(thd, this)) - goto err; - if (check_duplicate_names(thd, sl->item_list, 0)) - goto err; + if (sl->tvc && !with_element->column_list.elements) + { + if (sequential_rename_item_list(thd, &sl->item_list)) + goto err; + if (with_element->process_columns_of_derived_unit(thd, this)) + goto err; + } + else + { + if (with_element->process_columns_of_derived_unit(thd, this)) + goto err; + if (check_duplicate_names(thd, sl->item_list, 0)) + goto err; + } } } else @@ -1790,9 +1828,22 @@ bool st_select_lex_unit::prepare(TABLE_LIST *derived_arg, We need to rename tvc BEFORE Item_holder pushed into result table below in join_union_item_types(). */ - if (first_select()->tvc && derived_arg && derived_arg->column_names) - if (rename_item_list(derived_arg)) - goto err; + if (first_select()->tvc && derived_arg) + { + if (derived_arg->column_names) + { + if (rename_item_list(derived_arg)) + goto err; + } + else + { + if (!with_element) + { + if (sequential_rename_item_list(thd, &first_select()->item_list)) + goto err; + } + } + } // In case of a non-recursive UNION, join data types for all UNION parts. if (!is_recursive && join_union_item_types(thd, types, union_part_count))