diff options
Diffstat (limited to 'mysql-test/t')
40 files changed, 1914 insertions, 50 deletions
diff --git a/mysql-test/t/compound.test b/mysql-test/t/compound.test index cabdf96e00e..94a6c18b2f5 100644 --- a/mysql-test/t/compound.test +++ b/mysql-test/t/compound.test @@ -106,7 +106,8 @@ select @a| /**/ while (select count(*) from information_schema.tables where table_schema='test') do select concat('drop table ', table_name) into @a - from information_schema.tables where table_schema='test' limit 1; + from information_schema.tables where table_schema='test' + order by table_name limit 1; select @a as 'executing:'; prepare dt from @a; execute dt; diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index bd89f220060..a8c4eff7365 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -1017,6 +1017,7 @@ from имя_таблицы_в_кодировке_утф8_длиной_больш # database, table, field, key, view select * from имя_таблицы_в_кодировке_утф8_длиной_больше_чем_48; +--sorted_result select TABLE_NAME from information_schema.tables where table_schema='test'; diff --git a/mysql-test/t/cte_nonrecursive.test b/mysql-test/t/cte_nonrecursive.test index 57b7ae1658f..742e8f6e4d7 100644 --- a/mysql-test/t/cte_nonrecursive.test +++ b/mysql-test/t/cte_nonrecursive.test @@ -743,3 +743,50 @@ eval $q; eval explain $q; DROP TABLE t1,t2; + +--echo # +--echo # MDEV-13780: tower of embedding CTEs with multiple usage of them +--echo # + +create table t1 (a int); +insert into t1 values (3), (2), (4), (7), (1), (2), (5); + +let $q= +with cte_e as +( + with cte_o as + ( + with cte_i as (select * from t1 where a < 7) + select * from cte_i where a > 1 + ) + select * from cte_o as cto_o1 where a < 3 + union + select * from cte_o as cto_o2 where a > 4 +) +select * from cte_e as cte_e1 where a > 1 +union +select * from cte_e as cte_e2; + +eval $q; +eval explain extended $q; + +drop table t1; + +--echo # +--echo # MDEV-13753: embedded CTE in a VIEW created in prepared statement +--echo # + +SET @sql_query = " + CREATE OR REPLACE VIEW cte_test AS + WITH cte1 AS ( SELECT 1 as a from dual ) + , cte2 AS ( SELECT * FROM cte1 ) + SELECT * FROM cte2; +"; +PREPARE stmt FROM @sql_query; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; + +SHOW CREATE VIEW cte_test; +SELECT * FROM cte_test; + +DROP VIEW cte_test; diff --git a/mysql-test/t/cte_recursive.test b/mysql-test/t/cte_recursive.test index 5701ee896cb..7d7600f0e88 100644 --- a/mysql-test/t/cte_recursive.test +++ b/mysql-test/t/cte_recursive.test @@ -1928,3 +1928,51 @@ set standard_compliant_cte=default; DROP TABLE t; +--echo # +--echo # mdev-14184: recursive CTE embedded into CTE with multiple references +--echo # + +WITH +cte1 AS ( + SELECT n FROM ( + WITH RECURSIVE rec_cte(n) AS ( + SELECT 1 as n1 + UNION ALL + SELECT n+1 as n2 FROM rec_cte WHERE n < 3 + ) SELECT n FROM rec_cte + ) AS X +), +cte2 as ( + SELECT 2 FROM cte1 +) +SELECT * +FROM cte1; + +--echo # +--echo # MDEV-14217 [db crash] Recursive CTE when SELECT includes new field +--echo # + +CREATE TEMPORARY TABLE a_tbl ( + a VARCHAR(33) PRIMARY KEY, + b VARCHAR(33) +); + +INSERT INTO a_tbl VALUES ('block0', 'block0'), ('block1', NULL); + +--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT +WITH RECURSIVE Q0 AS ( + SELECT T0.a, T0.b, 5 + FROM a_tbl T0 + WHERE b IS NULL + UNION ALL + SELECT T1.a, T1.b + FROM Q0 + JOIN a_tbl T1 + ON T1.a=Q0.a +) SELECT distinct(Q0.a), Q0.b + FROM Q0; +DROP TABLE a_tbl; + +--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT +WITH RECURSIVE x AS (SELECT 1,2 UNION ALL SELECT 1 FROM x) SELECT * FROM x; + diff --git a/mysql-test/t/default.test b/mysql-test/t/default.test index 7ee3b590a83..44778bc568a 100644 --- a/mysql-test/t/default.test +++ b/mysql-test/t/default.test @@ -180,7 +180,7 @@ CREATE TABLE t1 (a INT DEFAULT 10); INSERT INTO t1 VALUES (11); CREATE VIEW v1 AS SELECT a AS a FROM t1; CREATE VIEW v2 AS SELECT DEFAULT(a) AS a FROM t1; -CREATE VIEW v3 AS SELECT VALUES(a) AS a FROM t1; +CREATE VIEW v3 AS SELECT VALUE(a) AS a FROM t1; SELECT * FROM v1; SELECT * FROM v2; SELECT * FROM v3; @@ -447,7 +447,7 @@ CALL p1; DROP PROCEDURE p1; --error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED -CREATE TABLE t1 (a INT DEFAULT VALUES(a)); +CREATE TABLE t1 (a INT DEFAULT VALUE(a)); CREATE TABLE t1 (a INT); diff --git a/mysql-test/t/delimiter_case_mdev_10728.sql b/mysql-test/t/delimiter_case_mdev_10728.sql new file mode 100644 index 00000000000..72a1dcd9a9e --- /dev/null +++ b/mysql-test/t/delimiter_case_mdev_10728.sql @@ -0,0 +1,3 @@ +DeLiMiTeR A; +SELECT 1 A; +delimiter ; diff --git a/mysql-test/t/delimiter_command_case_sensitivity.test b/mysql-test/t/delimiter_command_case_sensitivity.test new file mode 100644 index 00000000000..11d1cf75aa0 --- /dev/null +++ b/mysql-test/t/delimiter_command_case_sensitivity.test @@ -0,0 +1,4 @@ +source include/not_embedded.inc; + +# MDEV-10728 +--exec $MYSQL --default-character-set=binary < "t/delimiter_case_mdev_10728.sql" diff --git a/mysql-test/t/derived_cond_pushdown.test b/mysql-test/t/derived_cond_pushdown.test index c4f1ee7d734..a9bb998bc33 100644 --- a/mysql-test/t/derived_cond_pushdown.test +++ b/mysql-test/t/derived_cond_pushdown.test @@ -1550,6 +1550,23 @@ DROP VIEW v2; DROP TABLE t1,t2; --echo # +--echo # MDEV-14237: derived with regexp_substr() in select list +--echo # + +create table t1 (a char(8)); +insert into t1 values ('b'), ('a'), ('xx'); + +let $q= +select * +from ( select distinct regexp_substr(t1.a,'^[A-Za-z]+') as f from t1) as t +where t.f = 'a' or t.f = 'b'; + +eval $q; +eval explain format=json $q; + +drop table t1; + +--echo # --echo # MDEV-10855: Pushdown into derived with window functions --echo # @@ -1834,3 +1851,4 @@ SELECT * FROM v3 JOIN t1 ON (bmax = b); DROP VIEW v1,v2,v3; DROP TABLE t1,t2; + diff --git a/mysql-test/t/errors.test b/mysql-test/t/errors.test index 55461002fd4..73d94d10382 100644 --- a/mysql-test/t/errors.test +++ b/mysql-test/t/errors.test @@ -179,16 +179,16 @@ SELECT UPDATEXML(-73 * -2465717823867977728,@@global.auto_increment_increment,nu CREATE TABLE t1 (a INT); CREATE TABLE t2(a INT PRIMARY KEY, b INT); --error ER_BAD_FIELD_ERROR -SELECT '' AS b FROM t1 GROUP BY VALUES(b); +SELECT '' AS b FROM t1 GROUP BY VALUE(b); --error ER_BAD_FIELD_ERROR -REPLACE t2(b) SELECT '' AS b FROM t1 GROUP BY VALUES(b); +REPLACE t2(b) SELECT '' AS b FROM t1 GROUP BY VALUE(b); --error ER_BAD_FIELD_ERROR -UPDATE t2 SET a=(SELECT '' AS b FROM t1 GROUP BY VALUES(b)); +UPDATE t2 SET a=(SELECT '' AS b FROM t1 GROUP BY VALUE(b)); --error ER_BAD_FIELD_ERROR INSERT INTO t2 VALUES (1,0) ON DUPLICATE KEY UPDATE - b=(SELECT '' AS b FROM t1 GROUP BY VALUES(b)); + b=(SELECT '' AS b FROM t1 GROUP BY VALUE(b)); INSERT INTO t2(a,b) VALUES (1,0) ON DUPLICATE KEY UPDATE - b=(SELECT VALUES(a)+2 FROM t1); + b=(SELECT VALUE(a)+2 FROM t1); DROP TABLE t1, t2; --echo # @@ -213,3 +213,14 @@ select * from seq_1_to_1000; --enable_result_log # We may not be able to execute any more queries with this connection # because of too little memory# + + +--echo # +--echo # MDEV-14269 errors.test fails with valgrind (Conditional jump or move depends on uninitialised value) +--echo # + +SET NAMES utf8; +--error ER_DATA_OUT_OF_RANGE +SELECT UPDATEXML(-73 * -2465717823867977728,@@global.auto_increment_increment,null); +--error ER_DATA_OUT_OF_RANGE +SELECT UPDATEXML(-73 * -2465717823867977728,@@global.long_query_time,null); diff --git a/mysql-test/t/except.test b/mysql-test/t/except.test index e13137701a9..f88d9b29e35 100644 --- a/mysql-test/t/except.test +++ b/mysql-test/t/except.test @@ -81,3 +81,17 @@ create table t3 (select a,b,b1 from t1) except (select c,d,d1 from t2); show create table t3; drop tables t1,t2,t3; + +--echo # +--echo # MDEV-13723: Server crashes in ha_heap::find_unique_row or +--echo # Assertion `0' failed in st_select_lex_unit::optimize with INTERSECT +--echo # +CREATE TABLE t (i INT); +INSERT INTO t VALUES (1),(2); + +SELECT * FROM t WHERE i != ANY ( SELECT 3 EXCEPT SELECT 3 ); + +drop table t; + + +--echo # End of 10.3 tests diff --git a/mysql-test/t/func_group_innodb.test b/mysql-test/t/func_group_innodb.test index c62d3d08496..1d175f85ed9 100644 --- a/mysql-test/t/func_group_innodb.test +++ b/mysql-test/t/func_group_innodb.test @@ -168,7 +168,7 @@ set storage_engine=innodb; create table y select 1 b; select 1 from y group by b; -select 1 from y group by values(b); +select 1 from y group by value(b); drop table y; SET storage_engine=@old_engine; diff --git a/mysql-test/t/func_misc.test b/mysql-test/t/func_misc.test index ac983048129..91ee449a7ff 100644 --- a/mysql-test/t/func_misc.test +++ b/mysql-test/t/func_misc.test @@ -316,7 +316,7 @@ CREATE TABLE t1 (a INT, b INT) ENGINE=MyISAM; INSERT INTO t1 VALUES (1,10); CREATE VIEW v1 AS SELECT * FROM t1; -EXPLAIN EXTENDED SELECT VALUES(b) FROM v1; +EXPLAIN EXTENDED SELECT VALUE(b) FROM v1; drop view v1; drop table t1; @@ -1104,6 +1104,23 @@ SELECT CONCAT(NAME_CONST('name',15),'오'); SET NAMES latin1; --echo # +--echo # MDEV-14116 INET6_NTOA output is set as null to varchar(39) variable +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1() +BEGIN + DECLARE ip_full_addr varchar(39) DEFAULT ""; + SELECT INET6_NTOA(UNHEX('20000000000000000000000000000000')) into ip_full_addr; + SELECT ip_full_addr; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP PROCEDURE p1; + + +--echo # --echo # Start of 10.2 tests --echo # diff --git a/mysql-test/t/gis.test b/mysql-test/t/gis.test index 94e56774bf4..ca806778f0e 100644 --- a/mysql-test/t/gis.test +++ b/mysql-test/t/gis.test @@ -1491,6 +1491,7 @@ SHOW CREATE TABLE information_schema.spatial_ref_sys; create table t1(g GEOMETRY, pt POINT); create table t2(g LINESTRING, pl POLYGON); +--sorted_result select * from information_schema.geometry_columns where f_table_schema='test'; drop table t1, t2; diff --git a/mysql-test/t/group_by_null.test b/mysql-test/t/group_by_null.test index b3fa2a003ec..93e965671dd 100644 --- a/mysql-test/t/group_by_null.test +++ b/mysql-test/t/group_by_null.test @@ -3,5 +3,5 @@ # create table t1 (a int); insert into t1 values (1),(2); -select max('foo') from t1 group by values(a), extractvalue('bar','qux') order by "v"; +select max('foo') from t1 group by value(a), extractvalue('bar','qux') order by "v"; drop table t1; diff --git a/mysql-test/t/having.test b/mysql-test/t/having.test index 160b347f870..3d8f7dc42b7 100644 --- a/mysql-test/t/having.test +++ b/mysql-test/t/having.test @@ -758,3 +758,83 @@ DROP VIEW v1; DROP TABLE t1; --echo End of 10.1 tests + +--echo # +--echo # MDEV-14093: GROUP BY with HAVING over function + ORDER BY +--echo # + +CREATE TABLE _authors ( + id MEDIUMINT(8) UNSIGNED AUTO_INCREMENT, + name VARCHAR(100), + some_field MEDIUMINT(8) UNSIGNED, + PRIMARY KEY (id), + index(some_field) +); + +CREATE TABLE _books ( + id MEDIUMINT(8) UNSIGNED AUTO_INCREMENT, + title VARCHAR(100), + PRIMARY KEY (id) +); +CREATE TABLE _books2authors ( + author_id MEDIUMINT(8) DEFAULT 0, + book_id MEDIUMINT(8) DEFAULT 0, + index(author_id), + index(book_id) +); + +INSERT INTO _authors (name, some_field) VALUES +('author1', 1),('author2', 2),('author3', 3); + +INSERT INTO _books (title) VALUES +('book1'),('book2'),('book3'); + +INSERT INTO _books2authors (author_id, book_id) VALUES +(2,1),(3,2),(3,3); + +SELECT A.id, + GROUP_CONCAT(B.title ORDER BY B.title DESC SEPARATOR ',') AS books, + some_field-1 AS having_field +FROM _authors A + LEFT JOIN _books2authors B2A FORCE INDEX(author_id) + ON B2A.author_id = A.id + LEFT JOIN + _books B ON B.id = B2A.book_id +GROUP BY A.id +HAVING having_field < 1 +ORDER BY having_field ASC; + +DROP TABLE _authors, _books, _books2authors; + +--echo # +--echo # Bug#17055185: WRONG RESULTS WHEN RUNNING A SELECT THAT INCLUDE +--echo # A HAVING BASED ON A FUNCTION. +--echo # + +# Generate series 1, 0, 1, 0.... +CREATE TABLE series ( + val INT(10) UNSIGNED NOT NULL +); +INSERT INTO series VALUES(1); + +DELIMITER |; +CREATE FUNCTION next_seq_value() RETURNS INT +BEGIN + DECLARE next_val INT; + SELECT val INTO next_val FROM series; + UPDATE series SET val=mod(val + 1, 2); + RETURN next_val; +END; +| +DELIMITER ;| + +CREATE TABLE t1 (t INT, u INT, KEY(t)); +INSERT INTO t1 VALUES(10, 10), (11, 11), (12, 12), (12, 13),(14, 15), (15, 16), + (16, 17), (17, 17); +ANALYZE TABLE t1; +SELECT t, next_seq_value() r FROM t1 FORCE INDEX(t) + GROUP BY t HAVING r = 1 ORDER BY t1.u; + +DROP TABLE t1; +DROP FUNCTION next_seq_value; +DROP TABLE series; diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index 417390dcafe..9c306de0e3f 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -32,7 +32,9 @@ create user mysqltest_3@localhost; create user mysqltest_3; +--sorted_result select * from information_schema.SCHEMATA where schema_name > 'm'; +--sorted_result select schema_name from information_schema.schemata; show databases like 't%'; show databases; @@ -71,6 +73,7 @@ select c, v2.table_name from v1 right join information_schema.TABLES v2 on (v1.c=v2.table_name) where v1.c like "t%"; +--sorted_result select table_name from information_schema.TABLES where table_schema = "mysqltest" and table_name like "t%"; @@ -206,6 +209,7 @@ show create procedure sel2; # Test for views # create view v0 (c) as select schema_name from information_schema.schemata; +--sorted_result select * from v0; --replace_column 3 # explain select * from v0; @@ -222,6 +226,7 @@ create view v4 (c) as select COLLATION_NAME from information_schema.collations where COLLATION_NAME like "latin1%"; select * from v4; show keys from v4; +--sorted_result select * from information_schema.views where TABLE_NAME like "v%"; drop view v0, v1, v2, v3, v4; @@ -273,6 +278,7 @@ create table t1(a int); create view v1 (c) as select a from t1 with check option; create view v2 (c) as select a from t1 WITH LOCAL CHECK OPTION; create view v3 (c) as select a from t1 WITH CASCADED CHECK OPTION; +--sorted_result select * from information_schema.views; grant select (a) on test.t1 to joe@localhost with grant option; select * from INFORMATION_SCHEMA.COLUMN_PRIVILEGES; @@ -316,6 +322,7 @@ drop table t1; create table t1 (s1 int); insert into t1 values (0),(9),(0); +--sorted_result select s1 from t1 where s1 in (select version from information_schema.tables) union select version from information_schema.tables; @@ -408,12 +415,18 @@ create view v3 (c) as select sub1(1); create table t4(f1 int, KEY f1_key (f1)); drop table t1; drop function sub1; +--sorted_result select table_name from information_schema.views where table_schema='test'; +--sorted_result select table_name from information_schema.views where table_schema='test'; select column_name from information_schema.columns -where table_schema='test'; +where table_schema='test' and table_name='t4'; +select column_name from information_schema.columns +where table_schema='test' and table_name='v2'; +select column_name from information_schema.columns +where table_schema='test' and table_name='v3'; select index_name from information_schema.statistics where table_schema='test'; select constraint_name from information_schema.table_constraints where table_schema='test'; @@ -503,9 +516,11 @@ drop table t_crashme; # select table_schema,table_name, column_name from information_schema.columns -where data_type = 'longtext' and table_schema != 'performance_schema'; +where data_type = 'longtext' and table_schema != 'performance_schema' +order by binary table_name, ordinal_position; select table_name, column_name, data_type from information_schema.columns -where data_type = 'datetime' and table_name not like 'innodb_%'; +where data_type = 'datetime' and table_name not like 'innodb_%' +order by binary table_name, ordinal_position; # # Bug#8164 subquery with INFORMATION_SCHEMA.COLUMNS, 100 % CPU @@ -870,7 +885,7 @@ connect (con16681,localhost,mysqltest_1,,test); connection con16681; select * from information_schema.views -where table_name='v1' or table_name='v2'; +where table_name='v1' or table_name='v2' order by table_name; connection default; disconnect con16681; drop view v1, v2; @@ -884,7 +899,7 @@ set @a:= '.'; create table t1(f1 char(5)); create table t2(f1 char(5)); select concat(@a, table_name), @a, table_name -from information_schema.tables where table_schema = 'test'; +from information_schema.tables where table_schema = 'test' order by table_name; drop table t1,t2; @@ -996,7 +1011,8 @@ create table t2 (f1 int(11), f2 int(11)); select table_name from information_schema.tables where table_schema = 'test' and table_name not in (select table_name from information_schema.columns - where table_schema = 'test' and column_name = 'f3'); + where table_schema = 'test' and column_name = 'f3') +order by table_name; drop table t1,t2; @@ -1007,7 +1023,7 @@ create table t1(f1 int); create view v1 as select f1+1 as a from t1; create table t2 (f1 int, f2 int); create view v2 as select f1+1 as a, f2 as b from t2; -select table_name, is_updatable from information_schema.views; +select table_name, is_updatable from information_schema.views order by table_name; # # Note: we can perform 'delete' for non updatable view. # @@ -1507,9 +1523,9 @@ let $wait_condition= --source include/wait_condition.inc --echo # These statements should not be blocked by pending lock requests select table_name, column_name, data_type from information_schema.columns - where table_schema = 'test' and table_name in ('t1', 't2'); + where table_schema = 'test' and table_name in ('t1', 't2') order by table_name, column_name; select table_name, auto_increment from information_schema.tables - where table_schema = 'test' and table_name in ('t1', 't2'); + where table_schema = 'test' and table_name in ('t1', 't2') order by table_name; connection con3726_1; unlock tables; connection con3726_2; @@ -1671,14 +1687,14 @@ let $wait_condition= --echo # Issue query to I_S which will open 't0' and get --echo # blocked on 't1' because of RENAME. ---send select table_name, auto_increment from information_schema.tables where table_schema='mysqltest' +--send select table_name, auto_increment from information_schema.tables where table_schema='mysqltest' and table_name='t0' union select table_name, auto_increment from information_schema.tables where table_schema='mysqltest' and table_name<>'t0' order by table_name connect (con12828477_3, localhost, root,,mysqltest); --echo # Wait while the above SELECT is blocked. let $wait_condition= select count(*) = 1 from information_schema.processlist where state = "Waiting for table metadata lock" and - info = "select table_name, auto_increment from information_schema.tables where table_schema='mysqltest'"; + info like '%t0%union%t0%'; --source include/wait_condition.inc --echo # diff --git a/mysql-test/t/information_schema2.test b/mysql-test/t/information_schema2.test index 9810c5a0aae..d2fa3da2b5f 100644 --- a/mysql-test/t/information_schema2.test +++ b/mysql-test/t/information_schema2.test @@ -15,5 +15,5 @@ create table t2 (x int); create table t3 (x int); create table t4 AS select table_name from information_schema.TABLES where table_schema = database() and table_type = 'BASE TABLE' ; delete from t4 where table_name not in (select table_name from information_schema.TABLES where table_schema = database() and table_type = 'BASE TABLE'); -select * from t4; +select * from t4 order by table_name; drop table t1, t2, t3, t4; diff --git a/mysql-test/t/information_schema_db.test b/mysql-test/t/information_schema_db.test index 70ad9b5b920..94908570969 100644 --- a/mysql-test/t/information_schema_db.test +++ b/mysql-test/t/information_schema_db.test @@ -100,10 +100,10 @@ create function f2 () returns int return (select max(i) from t2); create view v2 as select f2(); drop table t2; select table_name, table_type, table_comment from information_schema.tables -where table_schema='test'; +where table_schema='test' order by table_name; drop table t1; select table_name, table_type, table_comment from information_schema.tables -where table_schema='test'; +where table_schema='test' order by table_name; drop function f1; drop function f2; drop view v1, v2; diff --git a/mysql-test/t/information_schema_inno.test b/mysql-test/t/information_schema_inno.test index 9a9658e9027..3cdbb8111d9 100644 --- a/mysql-test/t/information_schema_inno.test +++ b/mysql-test/t/information_schema_inno.test @@ -16,8 +16,10 @@ FOREIGN KEY (t1_id) REFERENCES t1(id) ON UPDATE CASCADE) ENGINE=INNODB; CREATE TABLE t3 (id INT PRIMARY KEY, t2_id INT, INDEX par_ind (t2_id), FOREIGN KEY (id, t2_id) REFERENCES t2(t1_id, id) ON DELETE CASCADE) ENGINE=INNODB; +--sorted_result select * from information_schema.TABLE_CONSTRAINTS where TABLE_SCHEMA= "test"; +--sorted_result select * from information_schema.KEY_COLUMN_USAGE where TABLE_SCHEMA= "test"; @@ -45,6 +47,7 @@ CREATE TABLE t5(b1 INT, b2 INT, INDEX (b1, b2), FOREIGN KEY (b1, b2) REFERENCES t4(b1, b2) ON UPDATE RESTRICT ON DELETE CASCADE) ENGINE=INNODB; +--sorted_result select a.CONSTRAINT_SCHEMA, b.TABLE_NAME, CONSTRAINT_TYPE, b.CONSTRAINT_NAME, UNIQUE_CONSTRAINT_SCHEMA, UNIQUE_CONSTRAINT_NAME, MATCH_OPTION, UPDATE_RULE, DELETE_RULE, b.REFERENCED_TABLE_NAME @@ -74,7 +77,8 @@ create table `t-1` ( use test; select referenced_table_schema, referenced_table_name from information_schema.key_column_usage -where constraint_schema = 'db-1'; +where constraint_schema = 'db-1' +order by referenced_table_schema, referenced_table_name; drop database `db-1`; # diff --git a/mysql-test/t/information_schema_part.test b/mysql-test/t/information_schema_part.test index ea88f364c07..62fba4f53d8 100644 --- a/mysql-test/t/information_schema_part.test +++ b/mysql-test/t/information_schema_part.test @@ -63,7 +63,7 @@ subpartition by key (a) subpartition x22 tablespace t2) ); --replace_column 16 # 19 # 20 # -select * from information_schema.partitions where table_schema="test"; +select * from information_schema.partitions where table_schema="test" order by table_name, partition_name; drop table t1,t2; create table t1 ( diff --git a/mysql-test/t/insert_update.test b/mysql-test/t/insert_update.test index 7234973eeb8..06e16be84d7 100644 --- a/mysql-test/t/insert_update.test +++ b/mysql-test/t/insert_update.test @@ -22,9 +22,9 @@ SELECT * FROM t1; INSERT t1 SET a=5 ON DUPLICATE KEY UPDATE b=0; SELECT * FROM t1; INSERT t1 VALUES (2,1,11), (7,4,40) ON DUPLICATE KEY UPDATE c=c+VALUES(a); -SELECT *, VALUES(a) FROM t1; -explain extended SELECT *, VALUES(a) FROM t1; -explain extended select * from t1 where values(a); +SELECT *, VALUE(a) FROM t1; +explain extended SELECT *, VALUE(a) FROM t1; +explain extended select * from t1 where value(a); DROP TABLE t1; # @@ -79,7 +79,7 @@ SELECT * FROM t1; --error ER_NON_UNIQ_ERROR INSERT t1 SELECT a,b,c FROM t2 WHERE d=2 ON DUPLICATE KEY UPDATE c=c+VALUES(a); INSERT t1 SELECT a,b,c FROM t2 WHERE d=2 ON DUPLICATE KEY UPDATE c=t1.c+VALUES(t1.a); -SELECT *, VALUES(a) FROM t1; +SELECT *, VALUE(a) FROM t1; DROP TABLE t1; DROP TABLE t2; diff --git a/mysql-test/t/intersect.test b/mysql-test/t/intersect.test index 6028b2fa498..99a54606291 100644 --- a/mysql-test/t/intersect.test +++ b/mysql-test/t/intersect.test @@ -190,3 +190,4 @@ show create view v1; drop view v1; drop tables t1,t2,t3; +--echo # End of 10.3 tests diff --git a/mysql-test/t/mysql_upgrade_noengine.test b/mysql-test/t/mysql_upgrade_noengine.test index cfc3a1dc406..1d65e7ffa1c 100644 --- a/mysql-test/t/mysql_upgrade_noengine.test +++ b/mysql-test/t/mysql_upgrade_noengine.test @@ -19,16 +19,19 @@ install soname 'ha_archive'; vertical_results; create table t1 (a int) engine=blackhole; create table t2 (a int) engine=archive; -select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test'; +select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test' and table_name='t1'; +select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test' and table_name='t2'; flush tables; uninstall plugin blackhole; uninstall plugin archive; -select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test'; +select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test' and table_name='t1'; +select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test' and table_name='t2'; # upgrade from 10.1 - engines aren't enabled exec $MYSQL_UPGRADE 2>&1; -select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test'; +select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test' and table_name='t1'; +select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test' and table_name='t2'; # pretend it's an upgrade from 10.0 alter table mysql.user drop column default_role, drop column max_statement_time; @@ -41,14 +44,16 @@ EOF # still upgrade from 10.1 exec $MYSQL_UPGRADE 2>&1; -select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test'; +select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test' and table_name='t1'; +select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test' and table_name='t2'; alter table mysql.user drop column default_role, drop column max_statement_time; remove_file $datadir/mysql_upgrade_info; # upgrade from 10.0 - engines are enabled exec $MYSQL_UPGRADE 2>&1; -select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test'; +select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test' and table_name='t1'; +select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test' and table_name='t2'; drop table t1, t2; diff --git a/mysql-test/t/opt_tvc.test b/mysql-test/t/opt_tvc.test new file mode 100644 index 00000000000..2e00308aa78 --- /dev/null +++ b/mysql-test/t/opt_tvc.test @@ -0,0 +1,315 @@ +create table t1 (a int, b int); + +insert into t1 +values (1,2), (4,6), (9,7), + (1,1), (2,5), (7,8); + +create table t2 (a int, b int, c int); + +insert into t2 +values (1,2,3), (5,1,2), (4,3,7), + (8,9,0), (10,7,1), (5,5,1); + +create table t3 (a int, b varchar(16), index idx(a)); +insert into t3 values + (1, "abc"), (3, "egh"), (8, "axxx"), (10, "abc"), + (2, "ccw"), (8, "wqqe"), (7, "au"), (9, "waa"), + (3, "rass"), (9, "ert"), (9, "lok"), (8, "aww"), + (1, "todd"), (3, "rew"), (8, "aww"), (3, "sw"), + (11, "llk"), (7, "rbw"), (1, "sm"), (2, "jyp"), + (4, "yq"), (5, "pled"), (12, "ligin"), (12, "toww"), + (6, "mxm"), (15, "wanone"), (9, "sunqq"), (2, "abe"); + +--echo # optimization is not used + +let $query= select * from t1 where a in (1,2); +eval $query; +eval explain extended $query; + +--echo # set minimum number of values in VALUEs list when optimization works to 2 + +set @@in_subquery_conversion_threshold= 2; + +--echo # single IN-predicate in WHERE-part + +let $query= select * from t1 where a in (1,2); + +let $optimized_query= +select * from t1 +where a in + ( + select * + from (values (1),(2)) as tvc_0 + ); + +eval $query; +eval $optimized_query; +eval explain extended $query; +eval explain extended $optimized_query; + +--echo # AND-condition with IN-predicates in WHERE-part + +let $query= +select * from t1 +where a in (1,2) and + b in (1,5); + +let $optimized_query= +select * from t1 +where a in +( + select * + from (values (1),(2)) as tvc_0 +) +and b in +( + select * + from (values (1),(5)) as tvc_1 +); + +eval $query; +eval $optimized_query; +eval explain extended $query; +eval explain extended $optimized_query; + +--echo # subquery with IN-predicate + +let $query= +select * from t1 +where a in +( + select a + from t2 where b in (3,4) +); + +let $optimized_query= +select * from t1 +where a in +( + select a from t2 + where b in + ( + select * + from (values (3),(4)) as tvc_0 + ) +); + +eval $query; +eval $optimized_query; +eval explain extended $query; +eval explain extended $optimized_query; + +--echo # derived table with IN-predicate + +let $query= +select * from +( + select * + from t1 + where a in (1,2) +) as dr_table; + +let $optimized_query= +select * from +( + select * + from t1 + where a in + ( + select * + from (values (1),(2)) + as tvc_0 + ) +) as dr_table; + +eval $query; +eval $optimized_query; +eval explain extended $query; +eval explain extended $optimized_query; + +--echo # non-recursive CTE with IN-predicate + +let $cte_query= +with tvc_0 as +( + select * + from t1 + where a in (1,2) +) +select * from tvc_0; + +eval $cte_query; +eval $optimized_query; +eval explain extended $cte_query; +eval explain extended $optimized_query; + +--echo # VIEW with IN-predicate + +create view v1 as + select * + from t1 + where a in (1,2); + +create view v2 as + select * + from t1 + where a in + ( + select * + from (values (1),(2)) + as tvc_0 + ) +; + +let $query= select * from v1; +let $optimized_query= select * from v2; + +eval $query; +eval $optimized_query; +eval explain extended $query; +eval explain extended $optimized_query; + +drop view v1,v2; + +--echo # subselect defined by derived table with IN-predicate + +let $query= +select * from t1 +where a in +( + select 1 + from + ( + select * + from t1 + where a in (1,2) + ) + as dr_table +); + +let $optimized_query= +select * from t1 +where a in +( + select 1 + from + ( + select * + from t1 + where a in + ( + select * + from (values (1),(2)) + as tvc_0 + ) + ) + as dr_table +); + +eval $query; +eval $optimized_query; +eval explain extended $query; +eval explain extended $optimized_query; + +--echo # derived table with IN-predicate and group by + +let $query= +select * from +( + select max(a),b + from t1 + where b in (3,5) + group by b +) as dr_table; + +let $optimized_query= +select * from +( + select max(a),b + from t1 + where b in + ( + select * + from (values (3),(5)) + as tvc_0 + ) + group by b +) as dr_table; + +eval $query; +eval $optimized_query; +eval explain extended $query; +eval explain extended $optimized_query; + +--echo # prepare statement + +prepare stmt from "select * from t1 where a in (1,2)"; +execute stmt; +execute stmt; +deallocate prepare stmt; + +--echo # use inside out access from tvc rows + +let $query= select * from t3 where a in (1,4,10); +set @@in_subquery_conversion_threshold= default; +eval $query; +eval explain extended $query; +set @@in_subquery_conversion_threshold= 2; +eval $query; +eval explain extended $query; + +--echo # use vectors in IN predeicate + +set @@in_subquery_conversion_threshold= 4; + +let $query= +select * from t1 where (a,b) in ((1,2),(3,4)); + +eval $query; +eval explain extended $query; +set @@in_subquery_conversion_threshold= 2; + +--echo # trasformation works for the one IN predicate and doesn't work for the other + +set @@in_subquery_conversion_threshold= 5; + +let $query= +select * from t2 +where (a,b) in ((1,2),(8,9)) and + (a,c) in ((1,3),(8,0),(5,1)); + +eval $query; +eval explain extended $query; +set @@in_subquery_conversion_threshold= 2; + +--echo # +--echo # mdev-14281: conversion of NOT IN predicate into subquery predicate +--echo # + +let $query= +select * from t1 +where (a,b) not in ((1,2),(8,9), (5,1)); +let $optimized_query= +select * from t1 +where (a,b) not in (select * from (values (1,2),(8,9), (5,1)) as tvc_0); + +eval $query; +eval $optimized_query; +eval explain extended $query; +eval explain extended $optimized_query; + +let $query= +select * from t1 +where b < 7 and (a,b) not in ((1,2),(8,9), (5,1)); +eval $query; +eval explain extended $query; + +let $query= +select * from t2 +where (a,c) not in ((1,2),(8,9), (5,1)); +eval $query; +eval explain extended $query; + +drop table t1, t2, t3; + +set @@in_subquery_conversion_threshold= default; diff --git a/mysql-test/t/partition_exchange.test b/mysql-test/t/partition_exchange.test index e538bee16cd..8dc40da0caa 100644 --- a/mysql-test/t/partition_exchange.test +++ b/mysql-test/t/partition_exchange.test @@ -29,14 +29,16 @@ SHOW CREATE TABLE t2; SELECT TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, CREATE_OPTIONS FROM INFORMATION_SCHEMA.TABLES -WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2'); +WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2') +ORDER BY TABLE_NAME; ALTER TABLE t1 EXCHANGE PARTITION p1 WITH TABLE t2; SHOW CREATE TABLE t1; SHOW CREATE TABLE t2; SELECT TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, CREATE_OPTIONS FROM INFORMATION_SCHEMA.TABLES -WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2'); +WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2') +ORDER BY TABLE_NAME; DROP TABLE t2; @@ -53,7 +55,8 @@ SHOW CREATE TABLE t1; SHOW CREATE TABLE t2; SELECT TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, CREATE_OPTIONS FROM INFORMATION_SCHEMA.TABLES -WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2'); +WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2') +ORDER BY TABLE_NAME; --echo # Only the non partitioned table have ROW_FORMAT set. DROP TABLE t1, t2; @@ -77,7 +80,8 @@ SHOW CREATE TABLE t1; SHOW CREATE TABLE t2; SELECT TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, CREATE_OPTIONS FROM INFORMATION_SCHEMA.TABLES -WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2'); +WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2') +ORDER BY TABLE_NAME; --echo # No table have ROW_FORMAT set. DROP TABLE t1, t2; @@ -101,7 +105,8 @@ SHOW CREATE TABLE t1; SHOW CREATE TABLE t2; SELECT TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, CREATE_OPTIONS FROM INFORMATION_SCHEMA.TABLES -WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2'); +WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2') +ORDER BY TABLE_NAME; --echo # Not same ROW_FORMAT as default (but same). DROP TABLE t1, t2; @@ -125,7 +130,8 @@ SHOW CREATE TABLE t1; SHOW CREATE TABLE t2; SELECT TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, CREATE_OPTIONS FROM INFORMATION_SCHEMA.TABLES -WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2'); +WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2') +ORDER BY TABLE_NAME; --echo # Not same ROW_FORMAT as default (tables differs). DROP TABLE t1, t2; @@ -150,7 +156,8 @@ SHOW CREATE TABLE t1; SHOW CREATE TABLE t2; SELECT TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, CREATE_OPTIONS FROM INFORMATION_SCHEMA.TABLES -WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2'); +WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2') +ORDER BY TABLE_NAME; --echo # Different than default (forced ROW_TYPE) DROP TABLE t1, t2; @@ -175,7 +182,8 @@ SHOW CREATE TABLE t1; SHOW CREATE TABLE t2; SELECT TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, CREATE_OPTIONS FROM INFORMATION_SCHEMA.TABLES -WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2'); +WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME IN ('t1', 't2') +ORDER BY TABLE_NAME; --horizontal_results DROP TABLE t1, t2; diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index b61c4cf2568..ec55b9c9d21 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -4283,7 +4283,7 @@ EXECUTE IMMEDIATE MAX('SELECT 1 AS c'); EXECUTE IMMEDIATE DEFAULT(a); --error ER_BAD_FIELD_ERROR -EXECUTE IMMEDIATE VALUES(a); +EXECUTE IMMEDIATE VALUE(a); CREATE FUNCTION f1() RETURNS VARCHAR(64) RETURN 't1'; diff --git a/mysql-test/t/range.test b/mysql-test/t/range.test index ab951809b7a..ca6ac61d27a 100644 --- a/mysql-test/t/range.test +++ b/mysql-test/t/range.test @@ -3,6 +3,8 @@ # --source include/have_innodb.inc +set in_subquery_conversion_threshold=10000; + --disable_warnings drop table if exists t1, t2, t3, t10, t100; --enable_warnings @@ -2049,3 +2051,4 @@ drop table t1,t2,t3; --echo # End of 10.2 tests --echo # +set in_subquery_conversion_threshold=default; diff --git a/mysql-test/t/show_check.test b/mysql-test/t/show_check.test index 262013e0d2c..d84226460f2 100644 --- a/mysql-test/t/show_check.test +++ b/mysql-test/t/show_check.test @@ -423,7 +423,7 @@ create table t1 ( SHOW CREATE TABLE t1; DROP TABLE t1; -# Test for Bug#93 4.1 protocl crash on corupted frm and SHOW TABLE STATUS +# Test for Bug#93 4.1 protocol crash on corrupted frm and SHOW TABLE STATUS flush tables; @@ -437,7 +437,7 @@ show create table t1; --disable_warnings drop table if exists t1; --enable_warnings ---error 1,0 +--error 0,1 --remove_file $MYSQLD_DATADIR/test/t1.frm # diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 94d779de203..3b615d29166 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -5299,7 +5299,7 @@ insert into t3 (id, county) values (1, 'York')| create procedure bug15441(c varchar(25)) begin - update t3 set id=2, county=values(c); + update t3 set id=2, county=value(c); end| --error ER_BAD_FIELD_ERROR call bug15441('county')| @@ -5326,7 +5326,7 @@ begin on duplicate key update county= values(county); select * from t3; - update t3 set id=2, county=values(id); + update t3 set id=2, county=value(id); select * from t3; end| call bug15441('Yale')| @@ -5722,8 +5722,10 @@ create procedure bug18344_2() begin end| use test| +--sorted_result select schema_name from information_schema.schemata where schema_name like 'bug18344%'| +--sorted_result select routine_name,routine_schema from information_schema.routines where routine_schema like 'bug18344%'| diff --git a/mysql-test/t/status.test b/mysql-test/t/status.test index 7ab32241bcb..bff45fca583 100644 --- a/mysql-test/t/status.test +++ b/mysql-test/t/status.test @@ -387,6 +387,39 @@ drop table t1; # End of 5.3 tests +--echo # +--echo # MDEV-11153 - Introduce status variables for table cache monitoring and +--echo # tuning +--echo # +SET @old_table_open_cache= @@table_open_cache; +SET @@global.table_open_cache=10; +FLUSH TABLES; +FLUSH STATUS; +SHOW STATUS LIKE 'Table_open_cache%'; +disable_query_log; +let $i= `SELECT @@table_open_cache + 5`; +while ($i) +{ + eval CREATE TABLE t$i(a INT); + eval DELETE FROM t$i; + eval DELETE FROM t$i; + eval DELETE FROM t$i; + dec $i; +} +enable_query_log; +SHOW STATUS LIKE 'Table_open_cache%'; +FLUSH TABLES; +FLUSH STATUS; +disable_query_log; +let $i= `SELECT @@table_open_cache + 5`; +while ($i) +{ + eval DROP TABLE t$i; + dec $i; +} +enable_query_log; +SET @@global.table_open_cache= @old_table_open_cache; + # Restore global concurrent_insert value. Keep in the end of the test file. --connection default set @@global.concurrent_insert= @old_concurrent_insert; diff --git a/mysql-test/t/subselect_exists2in.test b/mysql-test/t/subselect_exists2in.test index a4fdbe5c50b..5a8ddb3612f 100644 --- a/mysql-test/t/subselect_exists2in.test +++ b/mysql-test/t/subselect_exists2in.test @@ -786,6 +786,46 @@ set optimizer_switch= @optimizer_switch_save; DROP TABLE t1; +--echo # +--echo # MDEV-14164: Unknown column error when adding aggregate to function +--echo # in oracle style procedure FOR loop +--echo # + +CREATE TABLE t1(id INT, val INT); +DELIMITER //; +CREATE PROCEDURE p1() +BEGIN + DECLARE cur1 CURSOR FOR SELECT * FROM ( + SELECT DISTINCT id FROM t1) a + WHERE NOT EXISTS (SELECT * FROM ( SELECT id FROM t1) b + WHERE a.id=b.id); + OPEN cur1; + CLOSE cur1; + OPEN cur1; + CLOSE cur1; +END; +// +DELIMITER ;// +CALL p1(); +DROP PROCEDURE p1; +DROP TABLE t1; + +CREATE TABLE t1(id INT, val INT); +DELIMITER //; +CREATE PROCEDURE p1() +BEGIN + SELECT * FROM (SELECT DISTINCT id FROM t1) a + WHERE NOT a.id IN (SELECT b.id FROM t1 b); + SELECT * FROM (SELECT DISTINCT id FROM t1) a + WHERE NOT EXISTS (SELECT * FROM t1 b WHERE a.id=b.id); +END; +// +DELIMITER ;// +CALL p1(); +CALL p1(); +DROP PROCEDURE p1; +DROP TABLE t1; + --echo # End of 10.0 tests #restore defaults diff --git a/mysql-test/t/subselect_sj.test b/mysql-test/t/subselect_sj.test index f90f1e2e927..6fdccee339d 100644 --- a/mysql-test/t/subselect_sj.test +++ b/mysql-test/t/subselect_sj.test @@ -2490,6 +2490,7 @@ drop table t1,t2; --echo # CREATE TABLE t1 (db VARCHAR(64) DEFAULT NULL); INSERT INTO t1 VALUES ('mysql'),('information_schema'); +--sorted_result SELECT * FROM t1 WHERE db IN (SELECT `SCHEMA_NAME` FROM information_schema.SCHEMATA); DROP TABLE t1; diff --git a/mysql-test/t/table_value_constr.test b/mysql-test/t/table_value_constr.test new file mode 100644 index 00000000000..578f8943fbb --- /dev/null +++ b/mysql-test/t/table_value_constr.test @@ -0,0 +1,1046 @@ +create table t1 (a int, b int); + +insert into t1 values (1,2),(4,6),(9,7), + (1,1),(2,5),(7,8); + +--echo # just VALUES + +values (1,2); + +values (1,2), (3,4), (5.6,0); + +values ("abc", "def"); + +--echo # UNION that uses VALUES structure(s) + +select 1,2 +union +values (1,2); + +values (1,2) +union +select 1,2; + +select 1,2 +union +values (1,2),(3,4),(5,6),(7,8); + +select 3,7 +union +values (1,2),(3,4),(5,6); + +select 3,7,4 +union +values (1,2,5),(4,5,6); + +select 1,2 +union +values (1,7),(3,6.5); + +select 1,2 +union +values (1,2.0),(3,6); + +select 1.8,2 +union +values (1,2),(3,6); + +values (1,2.4),(3,6) +union +select 2.8,9; + +values (1,2),(3,4),(5,6),(7,8) +union +select 5,6; + +select "ab","cdf" +union +values ("al","zl"),("we","q"); + +values ("ab", "cdf") +union +select "ab","cdf"; + +values (1,2) +union +values (1,2),(5,6); + +values (1,2) +union +values (3,4),(5,6); + +values (1,2) +union +values (1,2) +union values (4,5); + +--echo # UNION ALL that uses VALUES structure + +values (1,2),(3,4) +union all +select 5,6; + +values (1,2),(3,4) +union all +select 1,2; + +select 5,6 +union all +values (1,2),(3,4); + +select 1,2 +union all +values (1,2),(3,4); + +values (1,2) +union all +values (1,2),(5,6); + +values (1,2) +union all +values (3,4),(5,6); + +values (1,2) +union all +values (1,2) +union all +values (4,5); + +values (1,2) +union all +values (1,2) +union values (1,2); + +values (1,2) +union +values (1,2) +union all +values (1,2); + +--echo # EXCEPT that uses VALUES structure(s) + +select 1,2 +except +values (3,4),(5,6); + +select 1,2 +except +values (1,2),(3,4); + +values (1,2),(3,4) +except +select 5,6; + +values (1,2),(3,4) +except +select 1,2; + +values (1,2),(3,4) +except +values (5,6); + +values (1,2),(3,4) +except +values (1,2); + +--echo # INTERSECT that uses VALUES structure(s) + +select 1,2 +intersect +values (3,4),(5,6); + +select 1,2 +intersect +values (1,2),(3,4); + +values (1,2),(3,4) +intersect +select 5,6; + +values (1,2),(3,4) +intersect +select 1,2; + +values (1,2),(3,4) +intersect +values (5,6); + +values (1,2),(3,4) +intersect +values (1,2); + +--echo # combination of different structures that uses VALUES structures : UNION + EXCEPT + +values (1,2),(3,4) +except +select 1,2 +union values (1,2); + +values (1,2),(3,4) +except +values (1,2) +union +values (1,2); + +values (1,2),(3,4) +except +values (1,2) +union +values (3,4); + +values (1,2),(3,4) +union +values (1,2) +except +values (1,2); + +--echo # combination of different structures that uses VALUES structures : UNION ALL + EXCEPT + +values (1,2),(3,4) +except +select 1,2 +union all +values (1,2); + +values (1,2),(3,4) +except +values (1,2) +union all +values (1,2); + +values (1,2),(3,4) +except +values (1,2) +union all +values (3,4); + +values (1,2),(3,4) +union all +values (1,2) +except +values (1,2); + +--echo # combination of different structures that uses VALUES structures : UNION + INTERSECT + +values (1,2),(3,4) +intersect +select 1,2 +union +values (1,2); + +values (1,2),(3,4) +intersect +values (1,2) +union +values (1,2); + +values (1,2),(3,4) +intersect +values (1,2) +union +values (3,4); + +values (1,2),(3,4) +union +values (1,2) +intersect +values (1,2); + +--echo # combination of different structures that uses VALUES structures : UNION ALL + INTERSECT + +values (1,2),(3,4) +intersect +select 1,2 +union all +values (1,2); + +values (1,2),(3,4) +intersect +values (1,2) +union all +values (1,2); + +values (1,2),(3,4) +intersect +values (1,2) +union all +values (3,4); + +values (1,2),(3,4) +union all +values (1,2) +intersect +values (1,2); + +--echo # combination of different structures that uses VALUES structures : UNION + UNION ALL + +values (1,2),(3,4) +union all +select 1,2 +union +values (1,2); + +values (1,2),(3,4) +union all +values (1,2) +union +values (1,2); + +values (1,2),(3,4) +union all +values (1,2) +union +values (3,4); + +values (1,2),(3,4) +union +values (1,2) +union all +values (1,2); + +values (1,2) +union +values (1,2) +union all +values (1,2); + +--echo # CTE that uses VALUES structure(s) : non-recursive CTE + +with t2 as +( + values (1,2),(3,4) +) +select * from t2; + +with t2 as +( + select 1,2 + union + values (1,2) +) +select * from t2; + +with t2 as +( + select 1,2 + union + values (1,2),(3,4) +) +select * from t2; + +with t2 as +( + values (1,2) + union + select 1,2 +) +select * from t2; + +with t2 as +( + values (1,2),(3,4) + union + select 1,2 +) +select * from t2; + +with t2 as +( + values (5,6) + union + values (1,2),(3,4) +) +select * from t2; + +with t2 as +( + values (1,2) + union + values (1,2),(3,4) +) +select * from t2; + +with t2 as +( + select 1,2 + union all + values (1,2),(3,4) +) +select * from t2; + +with t2 as +( + values (1,2),(3,4) + union all + select 1,2 +) +select * from t2; + +with t2 as +( + values (1,2) + union all + values (1,2),(3,4) +) +select * from t2; + +--echo # recursive CTE that uses VALUES structure(s) : singe VALUES structure as anchor + +with recursive t2(a,b) as +( + values(1,1) + union + select t1.a, t1.b + from t1,t2 + where t1.a=t2.a +) +select * from t2; + +with recursive t2(a,b) as +( + values(1,1) + union + select t1.a+1, t1.b + from t1,t2 + where t1.a=t2.a +) +select * from t2; + +--echo # recursive CTE that uses VALUES structure(s) : several VALUES structures as anchors + +with recursive t2(a,b) as +( + values(1,1) + union + values (3,4) + union + select t2.a+1, t1.b + from t1,t2 + where t1.a=t2.a +) +select * from t2; + +--echo # recursive CTE that uses VALUES structure(s) : that uses UNION ALL + +with recursive t2(a,b,st) as +( + values(1,1,1) + union all + select t2.a, t1.b, t2.st+1 + from t1,t2 + where t1.a=t2.a and st<3 +) +select * from t2; + +--echo # recursive CTE that uses VALUES structure(s) : computation of factorial (first 10 elements) + +with recursive fact(n,f) as +( + values(1,1) + union + select n+1,f*n from fact where n < 10 +) +select * from fact; + +--echo # Derived table that uses VALUES structure(s) : singe VALUES structure + +select * from (values (1,2),(3,4)) as t2; + +--echo # Derived table that uses VALUES structure(s) : UNION with VALUES structure(s) + +select * from (select 1,2 union values (1,2)) as t2; + +select * from (select 1,2 union values (1,2),(3,4)) as t2; + +select * from (values (1,2) union select 1,2) as t2; + +select * from (values (1,2),(3,4) union select 1,2) as t2; + +select * from (values (5,6) union values (1,2),(3,4)) as t2; + +select * from (values (1,2) union values (1,2),(3,4)) as t2; + +--echo # Derived table that uses VALUES structure(s) : UNION ALL with VALUES structure(s) + +select * from (select 1,2 union all values (1,2),(3,4)) as t2; + +select * from (values (1,2),(3,4) union all select 1,2) as t2; + +select * from (values (1,2) union all values (1,2),(3,4)) as t2; + +--echo # CREATE VIEW that uses VALUES structure(s) : singe VALUES structure + +let $drop_view= drop view v1; +let $select_view= select * from v1; + +create view v1 as values (1,2),(3,4); + +eval $select_view; +eval $drop_view; + +--echo # CREATE VIEW that uses VALUES structure(s) : UNION with VALUES structure(s) + +create view v1 as + select 1,2 + union + values (1,2); + +eval $select_view; +eval $drop_view; + +create view v1 as + select 1,2 + union + values (1,2),(3,4); + +eval $select_view; +eval $drop_view; + +create view v1 as + values (1,2) + union + select 1,2; + +eval $select_view; +eval $drop_view; + +create view v1 as + values (1,2),(3,4) + union + select 1,2; + +eval $select_view; +eval $drop_view; + +create view v1 as + values (5,6) + union + values (1,2),(3,4); + +eval $select_view; +eval $drop_view; + +--echo # CREATE VIEW that uses VALUES structure(s) : UNION ALL with VALUES structure(s) + +create view v1 as + values (1,2) + union + values (1,2),(3,4); + +eval $select_view; +eval $drop_view; + +create view v1 as + select 1,2 + union all + values (1,2),(3,4); + +eval $select_view; +eval $drop_view; + +create view v1 as + values (1,2),(3,4) + union all + select 1,2; + +eval $select_view; +eval $drop_view; + +create view v1 as + values (1,2) + union all + values (1,2),(3,4); + +eval $select_view; +eval $drop_view; + +--echo # IN-subquery with VALUES structure(s) : simple case +let $query= +select * from t1 +where a in (values (1)); +let $subst_query= +select * from t1 +where a in (select * from (values (1)) as tvc_0); +eval $query; +eval $subst_query; +eval explain extended $query; +eval explain extended $subst_query; + +--echo # IN-subquery with VALUES structure(s) : UNION with VALUES on the first place +let $query= +select * from t1 +where a in (values (1) union select 2); +let $subst_query= +select * from t1 +where a in (select * from (values (1)) as tvc_0 union + select 2); +eval $query; +eval $subst_query; +eval explain extended $query; +eval explain extended $subst_query; + +--echo # IN-subquery with VALUES structure(s) : UNION with VALUES on the second place +let $query= +select * from t1 +where a in (select 2 union values (1)); +let $subst_query= +select * from t1 +where a in (select 2 union + select * from (values (1)) tvc_0); +eval $query; +eval $subst_query; +eval explain extended $query; +eval explain extended $subst_query; + +--echo # IN-subquery with VALUES structure(s) : UNION ALL +let $query= +select * from t1 +where a in (values (1) union all select b from t1); +let $subst_query= +select * from t1 +where a in (select * from (values (1)) as tvc_0 union all + select b from t1); + +eval $query; +eval $subst_query; +eval explain extended $query; +eval explain extended $subst_query; + +--echo # NOT IN subquery with VALUES structure(s) : simple case +let $query= +select * from t1 +where a not in (values (1),(2)); +let $subst_query= +select * from t1 +where a not in (select * from (values (1),(2)) as tvc_0); + +eval $query; +eval $subst_query; +eval explain extended $query; +eval explain extended $subst_query; + +--echo # NOT IN subquery with VALUES structure(s) : UNION with VALUES on the first place +let $query= +select * from t1 +where a not in (values (1) union select 2); +let $subst_query= +select * from t1 +where a not in (select * from (values (1)) as tvc_0 union + select 2); + +eval $query; +eval $subst_query; +eval explain extended $query; +eval explain extended $subst_query; + +--echo # NOT IN subquery with VALUES structure(s) : UNION with VALUES on the second place +let $query= +select * from t1 +where a not in (select 2 union values (1)); +let $subst_query= +select * from t1 +where a not in (select 2 union + select * from (values (1)) as tvc_0); + +eval $query; +eval $subst_query; +eval explain extended $query; +eval explain extended $subst_query; + +--echo # ANY-subquery with VALUES structure(s) : simple case +let $query= +select * from t1 +where a = any (values (1),(2)); +let $subst_query= +select * from t1 +where a = any (select * from (values (1),(2)) as tvc_0); + +eval $query; +eval $subst_query; +eval explain extended $query; +eval explain extended $subst_query; + +--echo # ANY-subquery with VALUES structure(s) : UNION with VALUES on the first place +let $query= +select * from t1 +where a = any (values (1) union select 2); +let $subst_query= +select * from t1 +where a = any (select * from (values (1)) as tvc_0 union + select 2); + +eval $query; +eval $subst_query; +eval explain extended $query; +eval explain extended $subst_query; + +--echo # ANY-subquery with VALUES structure(s) : UNION with VALUES on the second place +let $query= +select * from t1 +where a = any (select 2 union values (1)); +let $subst_query= +select * from t1 +where a = any (select 2 union + select * from (values (1)) as tvc_0); + +eval $query; +eval $subst_query; +eval explain extended $query; +eval explain extended $subst_query; + +--echo # ALL-subquery with VALUES structure(s) : simple case +let $query= +select * from t1 +where a = all (values (1)); +let $subst_query= +select * from t1 +where a = all (select * from (values (1)) as tvc_0); + +eval $query; +eval $subst_query; +eval explain extended $query; +eval explain extended $subst_query; + +--echo # ALL-subquery with VALUES structure(s) : UNION with VALUES on the first place +let $query= +select * from t1 +where a = all (values (1) union select 1); +let $subst_query= +select * from t1 +where a = all (select * from (values (1)) as tvc_0 union + select 1); + +eval $query; +eval $subst_query; +eval explain extended $query; +eval explain extended $subst_query; + +--echo # ALL-subquery with VALUES structure(s) : UNION with VALUES on the second place +let $query= +select * from t1 +where a = any (select 1 union values (1)); +let $subst_query= +select * from t1 +where a = any (select 1 union + select * from (values (1)) as tvc_0); + +eval $query; +eval $subst_query; +eval explain extended $query; +eval explain extended $subst_query; + +--echo # prepare statement that uses VALUES structure(s): single VALUES structure + +prepare stmt1 from " +values (1,2); +"; + +execute stmt1; +execute stmt1; +deallocate prepare stmt1; + +--echo # prepare statement that uses VALUES structure(s): UNION with VALUES structure(s) + +prepare stmt1 from " + select 1,2 + union + values (1,2),(3,4); +"; + +execute stmt1; +execute stmt1; +deallocate prepare stmt1; + +prepare stmt1 from " + values (1,2),(3,4) + union + select 1,2; +"; + +execute stmt1; +execute stmt1; +deallocate prepare stmt1; + +prepare stmt1 from " + select 1,2 + union + values (3,4) + union + values (1,2); +"; + +execute stmt1; +execute stmt1; +deallocate prepare stmt1; + +prepare stmt1 from " + values (5,6) + union + values (1,2),(3,4); +"; + +execute stmt1; +execute stmt1; +deallocate prepare stmt1; + +--echo # prepare statement that uses VALUES structure(s): UNION ALL with VALUES structure(s) + +prepare stmt1 from " + select 1,2 + union + values (1,2),(3,4); +"; + +execute stmt1; +execute stmt1; +deallocate prepare stmt1; + +prepare stmt1 from " + values (1,2),(3,4) + union all + select 1,2; +"; + +execute stmt1; +execute stmt1; +deallocate prepare stmt1; + +prepare stmt1 from " + select 1,2 + union all + values (3,4) + union all + values (1,2); +"; + +execute stmt1; +execute stmt1; +deallocate prepare stmt1; + +prepare stmt1 from " + values (1,2) + union all + values (1,2),(3,4); +"; + +execute stmt1; +execute stmt1; +deallocate prepare stmt1; + +--echo # explain query that uses VALUES structure(s): single VALUES structure + +explain +values (1,2); + +explain format=json +values (1,2); + +--echo # explain query that uses VALUES structure(s): UNION with VALUES structure(s) + +explain +select 1,2 +union +values (1,2),(3,4); + +explain +values (1,2),(3,4) +union +select 1,2; + +explain +values (5,6) +union +values (1,2),(3,4); + +explain format=json +select 1,2 +union +values (1,2),(3,4); + +explain format=json +values (1,2),(3,4) +union +select 1,2; + +explain format=json +values (5,6) +union +values (1,2),(3,4); + +explain +select 1,2 +union +values (3,4) +union +values (1,2); + +explain format=json +select 1,2 +union +values (3,4) +union +values (1,2); + +--echo # explain query that uses VALUES structure(s): UNION ALL with VALUES structure(s) + +explain +select 1,2 +union +values (1,2),(3,4); + +explain +values (1,2),(3,4) +union all +select 1,2; + +explain +values (1,2) +union all +values (1,2),(3,4); + +explain format=json +values (1,2),(3,4) +union all +select 1,2; + +explain format=json +select 1,2 +union +values (1,2),(3,4); + +explain format=json +values (1,2) +union all +values (1,2),(3,4); + +explain +select 1,2 +union all +values (3,4) +union all +values (1,2); + +explain format=json +select 1,2 +union all +values (3,4) +union all +values (1,2); + +--echo # analyze query that uses VALUES structure(s): single VALUES structure + +analyze +values (1,2); + +analyze format=json +values (1,2); + +--echo # analyze query that uses VALUES structure(s): UNION with VALUES structure(s) + +analyze +select 1,2 +union +values (1,2),(3,4); + +analyze +values (1,2),(3,4) +union +select 1,2; + +analyze +values (5,6) +union +values (1,2),(3,4); + +analyze format=json +select 1,2 +union +values (1,2),(3,4); + +analyze format=json +values (1,2),(3,4) +union +select 1,2; + +analyze format=json +values (5,6) +union +values (1,2),(3,4); + +analyze +select 1,2 +union +values (3,4) +union +values (1,2); + +analyze format=json +select 1,2 +union +values (3,4) +union +values (1,2); + +--echo # analyze query that uses VALUES structure(s): UNION ALL with VALUES structure(s) + +analyze +select 1,2 +union +values (1,2),(3,4); + +analyze +values (1,2),(3,4) +union all +select 1,2; + +analyze +values (1,2) +union all +values (1,2),(3,4); + +analyze format=json +values (1,2),(3,4) +union all +select 1,2; + +analyze format=json +select 1,2 +union +values (1,2),(3,4); + +analyze format=json +values (1,2) +union all +values (1,2),(3,4); + +analyze +select 1,2 +union all +values (3,4) +union all +values (1,2); + +analyze format=json +select 1,2 +union all +values (3,4) +union all +values (1,2); + +--echo # different number of values in TVC +--error ER_WRONG_NUMBER_OF_VALUES_IN_TVC +values (1,2),(3,4,5); + +--echo # illegal parameter data types in TVC +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +values (1,point(1,1)),(1,1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +values (1,point(1,1)+1); + +--echo # field reference in TVC +--error ER_FIELD_REFERENCE_IN_TVC +select * from (values (1), (b), (2)) as new_tvc; +--error ER_FIELD_REFERENCE_IN_TVC +select * from (values (1), (t1.b), (2)) as new_tvc; + +drop table t1; diff --git a/mysql-test/t/type_bit.test b/mysql-test/t/type_bit.test index 761f200fe0c..bb282fc15e5 100644 --- a/mysql-test/t/type_bit.test +++ b/mysql-test/t/type_bit.test @@ -439,3 +439,22 @@ SELECT SUM(a) FROM t1 GROUP BY c, b, a; DROP TABLE t1; --echo End of 5.1 tests + +--echo # +--echo # Start of 10.1 tests +--echo # + +--echo # +--echo # MDEV-8867 Wrong field type or metadata for COALESCE(bit_column, 1) +--echo # + +CREATE TABLE t1 (val bit(1)); +INSERT INTO t1 VALUES (0); +CREATE TABLE t2 AS SELECT COALESCE(val, 1) AS c FROM t1; +SELECT * FROM t2; +SHOW CREATE TABLE t2; +DROP TABLE t2; +--enable_metadata +SELECT COALESCE(val, 1) FROM t1; +--disable_metadata +DROP TABLE t1; diff --git a/mysql-test/t/type_date.test b/mysql-test/t/type_date.test index 7c4af618c23..8d29a54a26c 100644 --- a/mysql-test/t/type_date.test +++ b/mysql-test/t/type_date.test @@ -582,6 +582,15 @@ SELECT DATE(a), DATE(b), DATE(c) FROM t1; SELECT DATE(COALESCE(a)), DATE(COALESCE(b)), DATE(COALESCE(c)) FROM t1; DROP TABLE t1; +--echo # +--echo # MDEV-14221 Assertion `0' failed in Item::field_type_for_temporal_comparison +--echo # + +CREATE TABLE t1 (d DATE); +INSERT INTO t1 VALUES ('1985-05-13'),('1989-12-24'); +SELECT d, COUNT(*) FROM t1 GROUP BY d WITH ROLLUP HAVING CASE d WHEN '2017-05-25' THEN 0 ELSE 1 END; +DROP TABLE t1; + --echo # --echo # End of 10.1 tests diff --git a/mysql-test/t/type_datetime_hires.test b/mysql-test/t/type_datetime_hires.test index a62c227f563..d220a4601eb 100644 --- a/mysql-test/t/type_datetime_hires.test +++ b/mysql-test/t/type_datetime_hires.test @@ -57,6 +57,7 @@ INSERT INTO t2 VALUES ('2006-10-02 21:50:01.567',8), ('2006-10-02 21:50:01.5678',9); +--sorted_result select table_name,partition_name,partition_method,partition_expression,partition_description,table_rows from information_schema.partitions where table_name in ('t1', 't2'); drop table t1, t2; diff --git a/mysql-test/t/type_time.test b/mysql-test/t/type_time.test index 6662a3d9bb0..5f3f58df166 100644 --- a/mysql-test/t/type_time.test +++ b/mysql-test/t/type_time.test @@ -747,6 +747,17 @@ DROP TABLE t1,t2; --echo # +--echo # MDEV-10817 CAST(MAX(DATE'2001-01-01') AS TIME) returns a wrong result +--echo # + +SELECT CAST(DATE'2001-01-01' AS TIME); +SELECT CAST(MAX(DATE'2001-01-01') AS TIME); +CREATE FUNCTION f1() RETURNS DATE RETURN DATE'2001-01-01'; +SELECT CAST(f1() AS TIME); +DROP FUNCTION f1; + + +--echo # --echo # End of 10.2 tests --echo # diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test index 1f65956f8ad..67082fd48ff 100644 --- a/mysql-test/t/variables.test +++ b/mysql-test/t/variables.test @@ -1361,7 +1361,7 @@ set session rand_seed1=DEFAULT; # Bug #14211565 CRASH WHEN ATTEMPTING TO SET SYSTEM VARIABLE TO RESULT OF VALUES() # --error ER_BAD_FIELD_ERROR -set autocommit = values(v); +set autocommit = value(v); # # MDEV-6673 I_S.SESSION_VARIABLES shows global values diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 4850b6c06cb..847fb843ec8 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -1,3 +1,4 @@ +--source include/have_partition.inc # Save the initial number of concurrent sessions. --source include/count_sessions.inc diff --git a/mysql-test/t/win_percentile.test b/mysql-test/t/win_percentile.test new file mode 100644 index 00000000000..468d8cff56b --- /dev/null +++ b/mysql-test/t/win_percentile.test @@ -0,0 +1,104 @@ +CREATE TABLE t1 (name CHAR(10), test double, score DECIMAL(19,4)); +INSERT INTO t1 VALUES +('Chun', 0, 3), ('Chun', 0, 7), +('Kaolin', 0.5, 3), ('Kaolin', 0.6, 7), +('Kaolin', 0.5, 4), +('Tatiana', 0.8, 4), ('Tata', 0.8, 4); + +--echo # +--echo # Test invalid syntax +--echo # + +--echo # Order by clause has more than one element +--error ER_PARSE_ERROR +select percentile_disc(0.5) within group(order by score,test) over (partition by name) from t1; +--error ER_PARSE_ERROR +select percentile_cont(0.5) within group(order by score,test) over (partition by name) from t1; + +--echo # Order by clause has no element +--error ER_PARSE_ERROR +select percentile_disc(0.5) within group() over (partition by name) from t1; +--error ER_PARSE_ERROR +select percentile_cont(0.5) within group() over (partition by name) from t1; + +--echo # No parameters to the percentile functions +--error ER_PARSE_ERROR +select percentile_disc() within group() over (partition by name) from t1; +--error ER_PARSE_ERROR +select percentile_cont() within group() over (partition by name) from t1; + + + +--echo # +--echo # Test simple syntax +--echo # + +select name, percentile_cont(0.5) within group(order by score) over (partition by name) as c from t1; +select name, percentile_disc(0.5) within group(order by score) over (partition by name) as c from t1; + +--echo # no partition clause +select name, percentile_disc(0.5) within group(order by score) over () from t1; +select name, percentile_cont(0.5) within group(order by score) over () from t1; + +--echo # argument set to null +--error ER_WRONG_TYPE_OF_ARGUMENT +select name, percentile_cont(null) within group(order by score) over (partition by name) from t1; +--error ER_WRONG_TYPE_OF_ARGUMENT +select name, percentile_disc(null) within group(order by score) over (partition by name) from t1; + +--echo #subqueries having percentile functions +select * from ( select name , percentile_cont(0.5) within group ( order by score) over (partition by name ) from t1 ) as t; +select * from ( select name , percentile_disc(0.5) within group ( order by score) over (partition by name ) from t1 ) as t; +select name from t1 a where (select percentile_disc(0.5) within group (order by score) over (partition by name) from t1 b limit 1) >= 0.5; + +--echo #disallowed fields in order by +--error ER_WRONG_TYPE_FOR_PERCENTILE_FUNC +select score, percentile_cont(0.5) within group(order by name) over (partition by score) from t1; +--error ER_WRONG_TYPE_FOR_PERCENTILE_FUNC +select score, percentile_disc(0.5) within group(order by name) over (partition by score) from t1; + +--echo #parameter value should be in the range of [0,1] +--error ER_ARGUMENT_OUT_OF_RANGE +select percentile_disc(1.5) within group(order by score) over (partition by name) from t1; +--error ER_ARGUMENT_OUT_OF_RANGE +select percentile_cont(1.5) within group(order by score) over (partition by name) from t1; + +--echo #Argument should remain constant for the entire partition +--error ER_ARGUMENT_NOT_CONSTANT +select name,percentile_cont(test) within group(order by score) over (partition by name) from t1; +--error ER_ARGUMENT_NOT_CONSTANT +select name, percentile_disc(test) within group(order by score) over (partition by name) from t1; + +--echo #only numerical types are allowed as argument to percentile functions +--error ER_WRONG_TYPE_OF_ARGUMENT +select name, percentile_cont(name) within group(order by score) over (partition by name) from t1; +--error ER_WRONG_TYPE_OF_ARGUMENT +select name, percentile_disc(name) within group(order by score) over (partition by name) from t1; + +--echo #complete query with partition column +select name,cume_dist() over (partition by name order by score), percentile_disc(0.5) within group(order by score) over (partition by name) as c from t1; +select name, percentile_cont(0.5) within group(order by score) over (partition by name) as c from t1; + +select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.1) within group(order by score) over (partition by name) as c from t1; +select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.2) within group(order by score) over (partition by name) as c from t1; +select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.3) within group(order by score) over (partition by name) as c from t1; +select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.4) within group(order by score) over (partition by name) as c from t1; +select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.5) within group(order by score) over (partition by name) as c from t1; +select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.6) within group(order by score) over (partition by name) as c from t1; +select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.7) within group(order by score) over (partition by name) as c from t1; +select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.8) within group(order by score) over (partition by name) as c from t1; +select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.9) within group(order by score) over (partition by name) as c from t1; +select name,cume_dist() over (partition by name order by score) as b, percentile_disc(1) within group(order by score) over (partition by name) as c from t1; + +select median(score) over (partition by name), percentile_cont(0) within group(order by score) over (partition by name) as c from t1; +select median(score) over (partition by name), percentile_cont(0.1) within group(order by score) over (partition by name) as c from t1; +select median(score) over (partition by name), percentile_cont(0.2) within group(order by score) over (partition by name) as c from t1; +select median(score) over (partition by name), percentile_cont(0.3) within group(order by score) over (partition by name) as c from t1; +select median(score) over (partition by name), percentile_cont(0.4) within group(order by score) over (partition by name) as c from t1; +select median(score) over (partition by name), percentile_cont(0.5) within group(order by score) over (partition by name) as c from t1; +select median(score) over (partition by name), percentile_cont(0.6) within group(order by score) over (partition by name) as c from t1; +select median(score) over (partition by name), percentile_cont(0.7) within group(order by score) over (partition by name) as c from t1; +select median(score) over (partition by name), percentile_cont(0.8) within group(order by score) over (partition by name) as c from t1; +select median(score) over (partition by name), percentile_cont(0.9) within group(order by score) over (partition by name) as c from t1; +select median(score) over (partition by name), percentile_cont(1) within group(order by score) over (partition by name) as c from t1; +drop table t1; |