diff options
Diffstat (limited to 'mysql-test/t')
229 files changed, 14546 insertions, 2932 deletions
diff --git a/mysql-test/t/alter_table.test b/mysql-test/t/alter_table.test index 5a38abab1e5..5efbd7c8819 100644 --- a/mysql-test/t/alter_table.test +++ b/mysql-test/t/alter_table.test @@ -1455,6 +1455,8 @@ ALTER TABLE m1 ENABLE KEYS, ALGORITHM= INPLACE, LOCK= SHARED; ALTER TABLE m1 ENABLE KEYS, ALGORITHM= INPLACE, LOCK= EXCLUSIVE; --error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON ALTER TABLE m1 ENABLE KEYS, ALGORITHM= COPY, LOCK= NONE; +--error ER_ALTER_OPERATION_NOT_SUPPORTED +ALTER ONLINE TABLE m1 ADD COLUMN c int; # This works because the lock will be SNW for the copy phase. # It will still require exclusive lock for actually enabling keys. ALTER TABLE m1 ENABLE KEYS, ALGORITHM= COPY, LOCK= SHARED; @@ -1473,12 +1475,10 @@ INSERT INTO t1 VALUES (1,1), (2,2); START TRANSACTION; INSERT INTO t1 VALUES (3,3); ---echo # Connection con1 connect (con1, localhost, root); --echo # Sending: --send ALTER TABLE t1 DISABLE KEYS ---echo # Connection default connection default; --echo # Waiting until ALTER TABLE is blocked. let $wait_condition= @@ -1489,14 +1489,12 @@ let $wait_condition= UPDATE t1 SET b = 4; COMMIT; ---echo # Connection con1 connection con1; --echo # Reaping: ALTER TABLE t1 DISABLE KEYS --reap disconnect con1; --source include/wait_until_disconnected.inc ---echo # Connection default connection default; DROP TABLE t1; @@ -1777,3 +1775,18 @@ CREATE INDEX i1 ON t1(a) COMMENT 'comment1'; ALTER TABLE t1 DROP INDEX i1, ADD INDEX i1(a) COMMENT 'comment2'; SHOW CREATE TABLE t1; DROP TABLE t1; + +--echo # +--echo # MDEV-10421 duplicate CHECK CONSTRAINTs +--echo # +CREATE TABLE t1 (a INT, b INT) engine=myisam; +ALTER TABLE t1 ADD CONSTRAINT IF NOT EXISTS `min` CHECK (a+b > 100); +--error ER_DUP_CONSTRAINT_NAME +ALTER TABLE t1 ADD CONSTRAINT `min` CHECK (a+b > 100); +ALTER TABLE t1 ADD CONSTRAINT IF NOT EXISTS `min` CHECK (a+b > 100); +ALTER TABLE t1 ADD CONSTRAINT `mini` CHECK (a+b > 100); +SHOW CREATE TABLE t1; +DROP TABLE t1; +--error ER_DUP_CONSTRAINT_NAME +CREATE TABLE t1(a INT, b INT, CONSTRAINT min check (a>5), + CONSTRAINT min check (b>5)); diff --git a/mysql-test/t/alter_user.test b/mysql-test/t/alter_user.test new file mode 100644 index 00000000000..ca444f70a70 --- /dev/null +++ b/mysql-test/t/alter_user.test @@ -0,0 +1,79 @@ +--source include/not_embedded.inc + +select * from mysql.user where user = 'root' and host = 'localhost'; +--echo # Test syntax +--echo # +--echo # These 2 selects should have no changes from the first one. +alter user CURRENT_USER; +select * from mysql.user where user = 'root' and host = 'localhost'; +alter user CURRENT_USER(); +select * from mysql.user where user = 'root' and host = 'localhost'; + +create user foo; +select * from mysql.user where user = 'foo'; +alter user foo; +select * from mysql.user where user = 'foo'; + +--echo # Test super privilege works correctly with a read only database. +SET @start_read_only = @@global.read_only; +SET GLOBAL read_only=1; +grant create user on *.* to foo; + +--echo # Currently no super privileges. +connect (a, localhost, foo); +select @@global.read_only; + +--error ER_OPTION_PREVENTS_STATEMENT +alter user foo; + +--echo # Grant super privilege to the user. +connection default; +grant super on *.* to foo; + +--echo # We now have super privilege. We should be able to run alter user. +connect (b, localhost, foo); +alter user foo; + +connection default; +SET GLOBAL read_only = @start_read_only; + +--echo # Test inexistant user. +--error ER_CANNOT_USER +alter user boo; +--echo #--warning ER_CANNOT_USER +alter if exists user boo; + +--echo # Test password related altering. +alter user foo identified by 'something'; +select * from mysql.user where user = 'foo'; + +alter user foo identified by 'something2'; +select * from mysql.user where user = 'foo'; + +alter user foo identified by password '*88C89BE093D4ECF72D039F62EBB7477EA1FD4D63'; +select * from mysql.user where user = 'foo'; + +alter user foo identified with 'somecoolplugin'; +select * from mysql.user where user = 'foo'; + +alter user foo identified with 'somecoolplugin' using 'somecoolpassphrase'; +select * from mysql.user where user = 'foo'; + +--echo # Test ssl related altering. +alter user foo identified by 'something' require SSL; +select * from mysql.user where user = 'foo'; + +alter user foo identified by 'something' require X509; +select * from mysql.user where user = 'foo'; + +alter user foo identified by 'something' +require cipher 'text' issuer 'foo_issuer' subject 'foo_subject'; +select * from mysql.user where user = 'foo'; + +--echo # Test resource limits altering. +alter user foo with MAX_QUERIES_PER_HOUR 10 + MAX_UPDATES_PER_HOUR 20 + MAX_CONNECTIONS_PER_HOUR 30 + MAX_USER_CONNECTIONS 40; +select * from mysql.user where user = 'foo'; +drop user foo; diff --git a/mysql-test/t/analyze_stmt_privileges.test b/mysql-test/t/analyze_stmt_privileges.test index b565f17c0f7..32ff4ddfb7e 100644 --- a/mysql-test/t/analyze_stmt_privileges.test +++ b/mysql-test/t/analyze_stmt_privileges.test @@ -5,7 +5,6 @@ --echo # MDEV-7025 and MDEV-7027 ANALYZE SELECT/INSERT/UPDATE/DELETE from a --echo # view does not check access permissions on the underlying table --echo # ---enable_connect_log create database db; use db; create table t1 (i int, c varchar(8)); diff --git a/mysql-test/t/analyze_stmt_privileges2.test b/mysql-test/t/analyze_stmt_privileges2.test index 9a0299be535..e3274882ba6 100644 --- a/mysql-test/t/analyze_stmt_privileges2.test +++ b/mysql-test/t/analyze_stmt_privileges2.test @@ -23,7 +23,6 @@ # Save the initial number of concurrent sessions --source include/count_sessions.inc ---enable_connect_log set GLOBAL sql_mode=""; set LOCAL sql_mode=""; diff --git a/mysql-test/t/auth_rpl.test b/mysql-test/t/auth_rpl.test index 0ff024c73e7..9b2c4357cf0 100644 --- a/mysql-test/t/auth_rpl.test +++ b/mysql-test/t/auth_rpl.test @@ -10,13 +10,11 @@ # First stop the slave to guarantee that nothing is replicated. # --connection slave ---echo [connection slave] --source include/stop_slave.inc # # Create an replication account on the master. # --connection master ---echo [connection master] CREATE USER 'plug_user' IDENTIFIED WITH 'test_plugin_server' AS 'plug_user'; GRANT REPLICATION SLAVE ON *.* TO plug_user; FLUSH PRIVILEGES; @@ -25,7 +23,6 @@ FLUSH PRIVILEGES; # Now go to slave and change the replication user. # --connection slave ---echo [connection slave] --let $master_user= query_get_value(SHOW SLAVE STATUS, Master_User, 1) CHANGE MASTER TO MASTER_USER= 'plug_user', diff --git a/mysql-test/t/bug39022.test b/mysql-test/t/bug39022.test index 6056dbf0e7b..8d1deb163d7 100644 --- a/mysql-test/t/bug39022.test +++ b/mysql-test/t/bug39022.test @@ -18,20 +18,16 @@ connect (thread1, localhost, root,,); connect (thread2, localhost, root,,); connection thread1; ---echo # in thread1 START TRANSACTION; connection thread2; ---echo # in thread2 REPLACE INTO t2 VALUES (-17); SELECT d FROM t2,t1 WHERE d=(SELECT MAX(a) FROM t1 WHERE t1.a > t2.d) LOCK IN SHARE MODE; connection thread1; ---echo # in thread1 REPLACE INTO t1(a,b) VALUES (67,20); connection thread2; ---echo # in thread2 COMMIT; START TRANSACTION; REPLACE INTO t1(a,b) VALUES (65,-50); @@ -40,21 +36,18 @@ send; SELECT d FROM t2,t1 WHERE d=(SELECT MAX(a) FROM t1 WHERE t1.a > t2.d) LOCK IN SHARE MODE; #waits connection thread1; ---echo # in thread1 --echo # should not crash --error ER_LOCK_DEADLOCK SELECT d FROM t2,t1 WHERE d=(SELECT MAX(a) FROM t1 WHERE t1.a > t2.d) LOCK IN SHARE MODE; #crashes connection thread2; ---echo # in thread2 REAP; disconnect thread2; --source include/wait_until_disconnected.inc connection thread1; ---echo # in thread1; disconnect thread1; --source include/wait_until_disconnected.inc diff --git a/mysql-test/t/change_user.test b/mysql-test/t/change_user.test index c918224520d..d191b1c3ca0 100644 --- a/mysql-test/t/change_user.test +++ b/mysql-test/t/change_user.test @@ -142,3 +142,10 @@ if ($after != $before){ echo Value of com_select did not change; set global secure_auth=default; + +set timestamp=unix_timestamp('2010-10-10 10:10:10'); +select now(); +select year(now()) > 2011; +--echo change_user +--change_user +select year(now()) > 2011; diff --git a/mysql-test/t/check.test b/mysql-test/t/check.test index 966d41adfbd..6a7b7253a59 100644 --- a/mysql-test/t/check.test +++ b/mysql-test/t/check.test @@ -67,12 +67,10 @@ DROP TABLE IF EXISTS t1; CREATE TABLE t1(a INT); LOCK TABLE t1 WRITE; ---echo # Connection con1 connect(con1, localhost, root); SET lock_wait_timeout= 1; CHECK TABLE t1; ---echo # Connection default connection default; UNLOCK TABLES; DROP TABLE t1; diff --git a/mysql-test/t/check_constraint.test b/mysql-test/t/check_constraint.test new file mode 100644 index 00000000000..8dd6fcc4f27 --- /dev/null +++ b/mysql-test/t/check_constraint.test @@ -0,0 +1,71 @@ +# +# Check of check constraints + +set @save_check_constraint=@@check_constraint_checks; + +create table t1 (a int check(a>10), b int check (b > 20), constraint `min` check (a+b > 100), constraint `max` check (a+b <500)) engine=myisam; +show create table t1; +insert into t1 values (100,100); +--error ER_CONSTRAINT_FAILED +insert into t1 values (1,1); +--error ER_CONSTRAINT_FAILED +insert into t1 values (20,1); +--error ER_CONSTRAINT_FAILED +insert into t1 values (20,30); +--error ER_CONSTRAINT_FAILED +insert into t1 values (500,500); + +--error ER_CONSTRAINT_FAILED +insert into t1 values (101,101),(102,102),(600,600),(103,103); +select * from t1; +truncate table t1; +insert ignore into t1 values (101,101),(102,102),(600,600),(103,103); +select * from t1; +set check_constraint_checks=0; +truncate table t1; +insert into t1 values (101,101),(102,102),(600,600),(103,103); +select * from t1; +set check_constraint_checks=@save_check_constraint; + +--replace_regex /failed for.*/failed for table/ +--error ER_CONSTRAINT_FAILED +alter table t1 add c int default 0 check (c < 10); + +set check_constraint_checks=0; +alter table t1 add c int default 0 check (c < 10); +alter table t1 add check (a+b+c < 500); +set check_constraint_checks=@save_check_constraint; + +show create table t1; +--error ER_CONSTRAINT_FAILED +insert into t1 values(105,105,105); +--error ER_CONSTRAINT_FAILED +insert into t1 values(249,249,9); +insert into t1 values(105,105,9); +select * from t1; + +create table t2 like t1; +show create table t2; +--error ER_CANT_DROP_FIELD_OR_KEY +alter table t2 drop constraint c; +alter table t2 drop constraint if exists c; +alter table t2 drop constraint min; +show create table t2; + +drop table t1,t2; + +# +# check constraint name auto-generation: +# +create or replace table t1 (a int, b int, constraint check (a>b)); +show create table t1; +create or replace table t1 (a int, b int, + constraint CONSTRAINT_1 check (a>1), + constraint check (b>1)); +show create table t1; +create or replace table t1 (a int, b int, + constraint CONSTRAINT_1 check (a>1), + constraint check (b>1), + constraint CONSTRAINT_2 check (a>b)); +show create table t1; +drop table t1; diff --git a/mysql-test/t/commit.test b/mysql-test/t/commit.test index c2051358073..762397dfa23 100644 --- a/mysql-test/t/commit.test +++ b/mysql-test/t/commit.test @@ -15,7 +15,6 @@ connect (con1,localhost,root,,); # provided # init ---echo connection default; connection default; SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; @@ -63,13 +62,11 @@ START TRANSACTION; SELECT * FROM t1; SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED; ---echo connection con1 connection con1; START TRANSACTION; INSERT INTO t1 VALUES (1000); COMMIT; ---echo connection default connection default; --echo We should not be able to read the '1000' SELECT * FROM t1; @@ -99,29 +96,24 @@ SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; # transaction will have the same tran. iso. level # as the first. # ---echo connection default connection default; SET TRANSACTION ISOLATION LEVEL READ COMMITTED; START TRANSACTION; ---echo connection con1 connection con1; START TRANSACTION; INSERT INTO t1 VALUES (1001); COMMIT; ---echo connection default connection default; SELECT COUNT(*) FROM t1 WHERE s1 = 1001; --echo Should be 1 COMMIT AND CHAIN; ---echo connection con1 connection con1; INSERT INTO t1 VALUES (1002); COMMIT; ---echo connection default connection default; SELECT COUNT(*) FROM t1 WHERE s1 = 1002; --echo Should be 1 @@ -133,29 +125,24 @@ COMMIT; # # Verify isolation level with ROLLBACK AND CHAIN # ---echo connection default connection default; SET TRANSACTION ISOLATION LEVEL READ COMMITTED; START TRANSACTION; ---echo connection con1 connection con1; START TRANSACTION; INSERT INTO t1 VALUES (1001); COMMIT; ---echo connection default connection default; SELECT COUNT(*) FROM t1 WHERE s1 = 1001; --echo Should be 1 ROLLBACK AND CHAIN; ---echo connection con1 connection con1; INSERT INTO t1 VALUES (1002); COMMIT; ---echo connection default connection default; SELECT COUNT(*) FROM t1 WHERE s1 = 1002; --echo Should be 1 @@ -176,40 +163,33 @@ COMMIT; # SET @@completion_type=1; ---echo connection default connection default; SET TRANSACTION ISOLATION LEVEL READ COMMITTED; START TRANSACTION; ---echo connection con1 connection con1; START TRANSACTION; INSERT INTO t1 VALUES (1001); COMMIT; ---echo connection default connection default; SELECT * FROM t1 WHERE s1 >= 1000; --echo Should see 1001 COMMIT AND NO CHAIN; --echo default transaction is now in REPEATABLE READ ---echo connection con1 connection con1; INSERT INTO t1 VALUES (1002); COMMIT; ---echo connection default connection default; SELECT * FROM t1 WHERE s1 >= 1000; --echo Should see 1001 and 1002 ---echo connection con1 connection con1; INSERT INTO t1 VALUES (1003); COMMIT; ---echo connection default connection default; SELECT * FROM t1 WHERE s1 >= 1000; --echo Should see 1001 and 1002, but NOT 1003 @@ -225,42 +205,35 @@ COMMIT; # Verify that ROLLBACK AND NO CHAIN overrides the value # of @@completion_type # ---echo connection default connection default; SET @@completion_type=1; COMMIT AND NO CHAIN; SET TRANSACTION ISOLATION LEVEL READ COMMITTED; START TRANSACTION; ---echo connection con1 connection con1; START TRANSACTION; INSERT INTO t1 VALUES (1001); COMMIT; ---echo connection default connection default; SELECT * FROM t1 WHERE s1 >= 1000; --echo Should see 1001 ROLLBACK AND NO CHAIN; --echo default transaction is now in REPEATABLE READ ---echo connection con1 connection con1; INSERT INTO t1 VALUES (1002); COMMIT; ---echo connection default connection default; SELECT * FROM t1 WHERE s1 >= 1000; --echo Should see 1001 and 1002 ---echo connection con1 connection con1; INSERT INTO t1 VALUES (1003); COMMIT; ---echo connection default connection default; SELECT * FROM t1 WHERE s1 >= 1000; --echo Should see 1001 and 1002, but NOT 1003 @@ -281,7 +254,6 @@ COMMIT; # SET TRANSACTION. (Note that this is _not_ # in accordance with ISO 9075.) # ---echo connection default connection default; SET TRANSACTION ISOLATION LEVEL READ COMMITTED; @@ -289,12 +261,10 @@ SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; START TRANSACTION; SELECT * FROM t1; ---echo connection con1 connection con1; INSERT INTO t1 VALUES (1000); COMMIT; ---echo connection default connection default; SELECT * FROM t1; --echo Should get same result as above (i.e should not read '1000') @@ -320,12 +290,10 @@ INSERT INTO t1 VALUES (1000); SELECT * FROM t1; --echo Should read '1000' ---echo connection con1 connection con1; INSERT INTO t1 VALUES (1001); COMMIT; ---echo connection default connection default; SELECT * FROM t1; --echo Should only read the '1000' as this transaction is now in REP READ diff --git a/mysql-test/t/connect2.cnf b/mysql-test/t/connect2.cnf new file mode 100644 index 00000000000..0acd221b871 --- /dev/null +++ b/mysql-test/t/connect2.cnf @@ -0,0 +1,9 @@ +!include include/default_my.cnf + +[mysqld.1] +extra-port= @ENV.MASTER_EXTRA_PORT +extra-max-connections=2 +thread_handling=pool-of-threads + +[ENV] +MASTER_EXTRA_PORT= @OPT.port diff --git a/mysql-test/t/connect2.test b/mysql-test/t/connect2.test new file mode 100644 index 00000000000..9d2a438aa0a --- /dev/null +++ b/mysql-test/t/connect2.test @@ -0,0 +1,83 @@ +# This test is to check various cases of connections, some which require +# DBUG + +# This test makes no sense with the embedded server +--source include/not_embedded.inc +--source include/have_debug.inc +call mtr.add_suppression("Allocation failed"); +SET @old_debug= @@session.debug; +set @old_thread_cache_size=@@global.thread_cache_size; +set @@global.thread_cache_size=0; +# Test connections to the + +connect(con1,localhost,root,,test,,); +select 1; +disconnect con1; +connection default; +set global debug_dbug='+d,simulate_failed_connection_1'; +--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT +--error 1041,2013 +connect(con1,localhost,root,,test,,); +connection default; +set global debug_dbug=@old_debug; +set global debug_dbug='+d,simulate_failed_connection_2'; +--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT +--error 1041,2013 +connect(con1,localhost,root,,test,,); +--enable_result_log +connection default; +set global debug_dbug=@old_debug; +connect(con1,localhost,root,,test,,); +select 1; +disconnect con1; + +# Test connections to the extra port. +connect(con1,localhost,root,,test,$MASTER_EXTRA_PORT,); +select 1; +disconnect con1; +connection default; +set global debug_dbug='+d,simulate_failed_connection_1'; +--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_EXTRA_PORT MASTER_PORT +--error 1041,2013 +connect(con1,localhost,root,,test,$MASTER_EXTRA_PORT,); +connection default; +set global debug_dbug=@old_debug; +set global debug_dbug='+d,simulate_failed_connection_2'; +--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_EXTRA_PORT MASTER_PORT +--error 1041,2013 +connect(con1,localhost,root,,test,$MASTER_EXTRA_PORT,); +connection default; +set global debug_dbug=@old_debug; +connect(con1,localhost,root,,test,$MASTER_EXTRA_PORT,); +select 1; +disconnect con1; +connection default; + +# +# Test thread cache +# +set @@global.thread_cache_size=2; +connect(con1,localhost,root,,test,$MASTER_EXTRA_PORT,); +select 1; +connect(con2,localhost,root,,test,$MASTER_EXTRA_PORT,); +select 1; +disconnect con1; +disconnect con2; +connection default; +set global debug_dbug='+d,simulate_failed_connection_2'; +--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_EXTRA_PORT MASTER_PORT +--error 1041,2013 +connect(con1,localhost,root,,test,$MASTER_EXTRA_PORT,); +connection default; + +# Check that threads_connected didn't count aborted connections +let $count_sessions= 1; +--source include/wait_until_count_sessions.inc +show status like "Threads_connected"; + +# +# Cleanup +# + +set global debug_dbug=@old_debug; +set global thread_cache_size=@old_thread_cache_size; diff --git a/mysql-test/t/consistent_snapshot.test b/mysql-test/t/consistent_snapshot.test index fb1f3bc007c..a481e757bed 100644 --- a/mysql-test/t/consistent_snapshot.test +++ b/mysql-test/t/consistent_snapshot.test @@ -7,25 +7,20 @@ DROP TABLE IF EXISTS t1; --enable_warnings ---echo # Establish connection con1 (user=root) connect (con1,localhost,root,,); ---echo # Establish connection con2 (user=root) connect (con2,localhost,root,,); --echo ### Test 1: --echo ### - While a consistent snapshot transaction is executed, --echo ### no external inserts should be visible to the transaction. ---echo # Switch to connection con1 connection con1; CREATE TABLE t1 (a INT) ENGINE=innodb; START TRANSACTION WITH CONSISTENT SNAPSHOT; ---echo # Switch to connection con2 connection con2; INSERT INTO t1 VALUES(1); ---echo # Switch to connection con1 connection con1; SELECT * FROM t1; # if consistent snapshot was set as expected, we # should see nothing. @@ -38,11 +33,9 @@ COMMIT; DELETE FROM t1; START TRANSACTION; # Now we omit WITH CONSISTENT SNAPSHOT ---echo # Switch to connection con2 connection con2; INSERT INTO t1 VALUES(1); ---echo # Switch to connection con1 connection con1; SELECT * FROM t1; # if consistent snapshot was not set, as expected, we # should see 1. @@ -56,17 +49,14 @@ START TRANSACTION WITH CONSISTENT SNAPSHOT; DELETE FROM t1; COMMIT WORK AND CHAIN; ---echo # Switch to connection con2 connection con2; INSERT INTO t1 VALUES(1); ---echo # Switch to connection con1 connection con1; SELECT * FROM t1; # if consistent snapshot was not set, as expected, we # should see 1. COMMIT; ---echo # Switch to connection default + close connections con1 and con2 connection default; disconnect con1; disconnect con2; diff --git a/mysql-test/t/constraints.test b/mysql-test/t/constraints.test index 70a95e5f16e..1997c23bfa9 100644 --- a/mysql-test/t/constraints.test +++ b/mysql-test/t/constraints.test @@ -1,24 +1,30 @@ # # Testing of constraints -# Currently MySQL only ignores the syntax. # --disable_warnings drop table if exists t1; --enable_warnings create table t1 (a int check (a>0)); +show create table t1; insert into t1 values (1); +--error ER_CONSTRAINT_FAILED insert into t1 values (0); drop table t1; create table t1 (a int, b int, check (a>b)); +show create table t1; insert into t1 values (1,0); +--error ER_CONSTRAINT_FAILED insert into t1 values (0,1); drop table t1; create table t1 (a int ,b int, constraint abc check (a>b)); +show create table t1; insert into t1 values (1,0); +--error ER_CONSTRAINT_FAILED insert into t1 values (0,1); drop table t1; create table t1 (a int null); +show create table t1; insert into t1 values (1),(NULL); drop table t1; create table t1 (a int null); diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index 7306a819ad7..6948dd667d1 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -1297,7 +1297,6 @@ BEGIN UPDATE A SET `pk`=1 WHERE `pk`=0 ; END ;| ---error ER_NOT_SUPPORTED_YET CREATE TRIGGER f1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN UPDATE A SET `pk`=1 WHERE `pk`=0 ; @@ -1618,7 +1617,6 @@ drop view t1; create table t1 (a int) select 1 as a; create temporary table if not exists t1 (a int) select * from t1; ---error ER_CANT_REOPEN_TABLE create temporary table if not exists t1 (a int) select * from t1; select * from t1; drop temporary table t1; diff --git a/mysql-test/t/create_drop_binlog.test b/mysql-test/t/create_drop_binlog.test index 59a66d59e6f..d31ccd73429 100644 --- a/mysql-test/t/create_drop_binlog.test +++ b/mysql-test/t/create_drop_binlog.test @@ -2,7 +2,7 @@ --source include/have_log_bin.inc --source include/binlog_start_pos.inc ---let $pos=`select $binlog_start_pos + 65` +--let $pos=`select $binlog_start_pos + 73` --let $binlog_file=query_get_value(SHOW MASTER STATUS, File, 1) --let $binlog_start=query_get_value(SHOW MASTER STATUS, Position, 1) diff --git a/mysql-test/t/create_drop_server.test b/mysql-test/t/create_drop_server.test index d634cc1ccf1..1b9e9b2a788 100644 --- a/mysql-test/t/create_drop_server.test +++ b/mysql-test/t/create_drop_server.test @@ -23,3 +23,12 @@ CREATE OR REPLACE SERVER IF NOT EXISTS server_1 FOREIGN DATA WRAPPER mysql OPTIO CREATE OR REPLACE SERVER server_1 FOREIGN DATA WRAPPER mysql OPTIONS (USER 'mysqltest_1', HOST 'localhost', DATABASE 'test4'); SELECT server_name, username, db FROM mysql.servers; DROP SERVER server_1; + + +# MDEV-726 convert host names to lowercase + +CREATE SERVER server_1 FOREIGN DATA WRAPPER mysql OPTIONS (USER 'Remote', HOST 'Server.Example.Com', DATABASE 'test'); +SELECT Host FROM mysql.servers WHERE Server_Name = 'server_1'; +ALTER SERVER server_1 OPTIONS(HOST 'Server.Example.Org'); +SELECT Host FROM mysql.servers WHERE Server_Name = 'server_1'; +DROP SERVER server_1; diff --git a/mysql-test/t/create_drop_trigger.test b/mysql-test/t/create_drop_trigger.test index a8afc8716d6..0f19f5cf09f 100644 --- a/mysql-test/t/create_drop_trigger.test +++ b/mysql-test/t/create_drop_trigger.test @@ -6,7 +6,6 @@ SET @sum=0; INSERT INTO t1 VALUES (10), (20), (30); SELECT @sum; ---error ER_NOT_SUPPORTED_YET CREATE TRIGGER IF NOT EXISTS val_sum_new BEFORE INSERT ON t1 FOR EACH ROW SET @sum = @sum + NEW.val; CREATE TRIGGER IF NOT EXISTS val_sum AFTER INSERT ON t1 FOR EACH ROW SET @sum = @sum + 1 + NEW.val; diff --git a/mysql-test/t/create_or_replace2.test b/mysql-test/t/create_or_replace2.test index be1bd9a3d81..6cee7fac2e9 100644 --- a/mysql-test/t/create_or_replace2.test +++ b/mysql-test/t/create_or_replace2.test @@ -5,7 +5,7 @@ --source include/have_debug.inc --source include/master-slave.inc --source include/have_binlog_format_row.inc ---source include/have_xtradb.inc +--source include/have_innodb.inc --disable_warnings drop table if exists t1; diff --git a/mysql-test/t/create_user.test b/mysql-test/t/create_user.test new file mode 100644 index 00000000000..f04cb3e302a --- /dev/null +++ b/mysql-test/t/create_user.test @@ -0,0 +1,58 @@ +--source include/not_embedded.inc + +create user foo; +select * from mysql.user where user = 'foo'; +drop user foo; + +create user foo identified by 'password'; +select * from mysql.user where user = 'foo'; +drop user foo; + +create user foo identified by 'password' require SSL; +select * from mysql.user where user = 'foo'; +drop user foo; + +create user foo identified by 'password' require X509; +select * from mysql.user where user = 'foo'; +drop user foo; + +create user foo identified by 'password' require CIPHER 'cipher'; +select * from mysql.user where user = 'foo'; +drop user foo; + +create user foo identified by 'password' require ISSUER 'issuer'; +select * from mysql.user where user = 'foo'; +drop user foo; + +create user foo identified by 'password' require SUBJECT 'subject'; +select * from mysql.user where user = 'foo'; +drop user foo; + +create user foo identified by 'password' require CIPHER 'cipher' + SUBJECT 'subject'; +select * from mysql.user where user = 'foo'; +drop user foo; + +create user foo identified by 'password' require CIPHER 'cipher' + AND SUBJECT 'subject' + AND ISSUER 'issuer'; +select * from mysql.user where user = 'foo'; +drop user foo; + +create user foo, foo2 identified by 'password' require CIPHER 'cipher' + AND SUBJECT 'subject' + AND ISSUER 'issuer'; +select * from mysql.user where user like 'foo'; + +--echo #--warning ER_USER_CREATE_EXISTS +create user if not exists foo, foo2 identified by 'password2' + require CIPHER 'cipher2' AND SUBJECT 'subject2' AND ISSUER 'issuer2'; +select * from mysql.user where user like 'foo'; +drop user foo, foo2; + +create user foo with MAX_QUERIES_PER_HOUR 10 + MAX_UPDATES_PER_HOUR 20 + MAX_CONNECTIONS_PER_HOUR 30 + MAX_USER_CONNECTIONS 40; +select * from mysql.user where user like 'foo'; +drop user foo; diff --git a/mysql-test/t/cte_grant.test b/mysql-test/t/cte_grant.test new file mode 100644 index 00000000000..44fd4a0bc6e --- /dev/null +++ b/mysql-test/t/cte_grant.test @@ -0,0 +1,79 @@ +# Can't test with embedded server +-- source include/not_embedded.inc + +# Save the initial number of concurrent sessions +--source include/count_sessions.inc + +connect (root,localhost,root,,test); +connection root; + +--disable_warnings +create database mysqltest; +--enable_warnings + +create user mysqltest_1@localhost; +connect (user1,localhost,mysqltest_1,,test); +connection user1; + +connection root; + +create table mysqltest.t1 (a int, b int); +insert into mysqltest.t1 values (2,10), (1,30); +create table mysqltest.t2 (c int, d char(32)); +insert into mysqltest.t2 values (1,'xxx'), (1,'zzz'); + +grant select on mysqltest.t1 to mysqltest_1@localhost; +grant select (c) on mysqltest.t2 to mysqltest_1@localhost; + +connection user1; +with t as (select c from mysqltest.t2 where c < 2) +select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a; +--error ER_COLUMNACCESS_DENIED_ERROR +select t.c,t.d,t1.b +from (select c,d from mysqltest.t2 where c < 2) as t, mysqltest.t1 +where t.c=t1.a; +--error ER_COLUMNACCESS_DENIED_ERROR +with t as (select c,d from mysqltest.t2 where c < 2) +select t.c,t.d,t1.b from t,mysqltest.t1 where t.c=t1.a; + +connection root; + +create view mysqltest.v1(f1,f2) as +with t as (select c from mysqltest.t2 where c < 2) +select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a; +create view mysqltest.v2(c,d) as +with t as (select a from mysqltest.t1 where a>=3) +select t.a,b from t,mysqltest.t1 where mysqltest.t1.a = t.a; + +grant select on mysqltest.v1 to mysqltest_1@localhost; +grant select (c) on mysqltest.v2 to mysqltest_1@localhost; +grant create view on mysqltest.* to mysqltest_1@localhost; + +connection user1; + +create view mysqltest.v3(c,d) as +with t as (select c from mysqltest.t2 where c < 2) +select t.c,t1.b from t,mysqltest.t1 where t.c=t1.a; +--error ER_COLUMNACCESS_DENIED_ERROR +create view mysqltest.v4(f1,f2,f3) as +with t as (select c,d from mysqltest.t2 where c < 2) +select t.c,t.d,t1.b from t,mysqltest.t1 where t.c=t1.a; + +select * from mysqltest.v1; + +select c from mysqltest.v2; +# there are no privileges on column 'd' +--error ER_COLUMNACCESS_DENIED_ERROR +select d from mysqltest.v2; + +--error ER_TABLEACCESS_DENIED_ERROR +select * from mysqltest.v3; +connection root; +grant select on mysqltest.v3 to mysqltest_1@localhost; +connection user1; +select * from mysqltest.v3; + +connection root; +revoke all privileges on mysqltest.v1 from mysqltest_1@localhost; +drop user mysqltest_1@localhost; +drop database mysqltest;
\ No newline at end of file diff --git a/mysql-test/t/cte_nonrecursive.test b/mysql-test/t/cte_nonrecursive.test new file mode 100644 index 00000000000..8dbde472c16 --- /dev/null +++ b/mysql-test/t/cte_nonrecursive.test @@ -0,0 +1,611 @@ +create table t1 (a int, b varchar(32)); +insert into t1 values + (4,'aaaa' ), (7,'bb'), (1,'ccc'), (4,'dd'); +insert into t1 values + (3,'eee'), (7,'bb'), (1,'fff'), (4,'ggg'); +create table t2 (c int); +insert into t2 values + (2), (4), (5), (3); + +--echo # select certain field in the specification of t +with t as (select a from t1 where b >= 'c') + select * from t2,t where t2.c=t.a; +select * from t2, (select a from t1 where b >= 'c') as t + where t2.c=t.a; +explain +with t as (select a from t1 where b >= 'c') + select * from t2,t where t2.c=t.a; +explain +select * from t2, (select a from t1 where b >= 'c') as t + where t2.c=t.a; + +--echo # select '*' in the specification of t +with t as (select * from t1 where b >= 'c') + select * from t2,t where t2.c=t.a; +select * from t2, (select * from t1 where b >= 'c') as t + where t2.c=t.a; +explain +with t as (select * from t1 where b >= 'c') + select * from t2,t where t2.c=t.a; +explain +select * from t2, (select * from t1 where b >= 'c') as t + where t2.c=t.a; + +--echo # rename fields returned by the specication when defining t +with t(f1,f2) as (select * from t1 where b >= 'c') + select * from t2,t where t2.c=t.f1; +explain +with t(f1,f2) as (select * from t1 where b >= 'c') + select * from t2,t where t2.c=t.f1; + +--echo # materialized query specifying t +with t as (select a, count(*) from t1 where b >= 'c' group by a) + select * from t2,t where t2.c=t.a; +select * from t2, (select a, count(*) from t1 where b >= 'c' group by a) as t + where t2.c=t.a; +explain +with t as (select a, count(*) from t1 where b >= 'c' group by a) + select * from t2,t where t2.c=t.a; +explain +select * from t2, (select a, count(*) from t1 where b >= 'c' group by a) as t + where t2.c=t.a; + +--echo # specivication of t contains having +with t as (select a, count(*) from t1 where b >= 'c' + group by a having count(*)=1 ) + select * from t2,t where t2.c=t.a; +select * from t2, (select a, count(*) from t1 where b >= 'c' + group by a having count(*)=1) t + where t2.c=t.a; + +--echo # main query contains having +with t as (select * from t2 where c <= 4) + select a, count(*) from t1,t where t1.a=t.c group by a having count(*)=1; +select a, count(*) from t1, (select * from t2 where c <= 4) t + where t1.a=t.c group by a having count(*)=1; + +--echo # main query contains group by + order by +with t as (select * from t2 where c <= 4 ) + select a, count(*) from t1,t where t1.a=t.c group by a order by count(*); +select a, count(*) from t1, (select * from t2 where c <= 4 ) t + where t1.a=t.c group by a order by count(*); + +--echo # main query contains group by + order by + limit +with t as (select * from t2 where c <= 4 ) + select a, count(*) from t1,t + where t1.a=t.c group by a order by count(*) desc limit 1; +select a, count(*) from t1, (select * from t2 where c <= 4 ) t + where t1.a=t.c group by a order by count(*) desc limit 1; + + +--echo # t is used in a subquery +with t as (select a from t1 where a<5) + select * from t2 where c in (select a from t); +select * from t2 + where c in (select a from (select a from t1 where a<5) as t); +explain +with t as (select a from t1 where a<5) + select * from t2 where c in (select a from t); +explain +select * from t2 + where c in (select a from (select a from t1 where a<5) as t); + +--echo # materialized t is used in a subquery +with t as (select count(*) as c from t1 where b >= 'c' group by a) + select * from t2 where c in (select c from t); +select * from t2 + where c in (select c from (select count(*) as c from t1 + where b >= 'c' group by a) as t); +explain +with t as (select count(*) as c from t1 where b >= 'c' group by a) + select * from t2 where c in (select c from t); +explain +select * from t2 + where c in (select c from (select count(*) as c from t1 + where b >= 'c' group by a) as t); + +--echo # two references to t specified by a query +--echo # selecting a field: both in main query +with t as (select a from t1 where b >= 'c') + select * from t as r1, t as r2 where r1.a=r2.a; +select * from (select a from t1 where b >= 'c') as r1, + (select a from t1 where b >= 'c') as r2 + where r1.a=r2.a; +explain +with t as (select a from t1 where b >= 'c') + select * from t as r1, t as r2 where r1.a=r2.a; +explain +select * from (select a from t1 where b >= 'c') as r1, + (select a from t1 where b >= 'c') as r2 + where r1.a=r2.a; + +--echo # two references to materialized t: both in main query +with t as (select distinct a from t1 where b >= 'c') + select * from t as r1, t as r2 where r1.a=r2.a; +select * from (select distinct a from t1 where b >= 'c') as r1, + (select distinct a from t1 where b >= 'c') as r2 + where r1.a=r2.a; +explain +with t as (select distinct a from t1 where b >= 'c') + select * from t as r1, t as r2 where r1.a=r2.a; +explain +select * from (select distinct a from t1 where b >= 'c') as r1, + (select distinct a from t1 where b >= 'c') as r2 + where r1.a=r2.a; + +--echo # two references to t specified by a query +--echo # selecting all fields: both in main query +with t as (select * from t1 where b >= 'c') + select * from t as r1, t as r2 where r1.a=r2.a; +select * from (select * from t1 where b >= 'c') as r1, + (select * from t1 where b >= 'c') as r2 + where r1.a=r2.a; +explain +with t as (select * from t1 where b >= 'c') + select * from t as r1, t as r2 where r1.a=r2.a; +explain +select * from (select * from t1 where b >= 'c') as r1, + (select * from t1 where b >= 'c') as r2 + where r1.a=r2.a; + +--echo # two references to t specifying explicitly column names +with t(c) as (select a from t1 where b >= 'c') + select * from t r1, t r2 where r1.c=r2.c; + +--echo # t two references of t used in different parts of a union +with t as (select a from t1 where b >= 'c') + select * from t where a < 2 + union + select * from t where a >= 4; +select * from (select a from t1 where b >= 'c') as t + where t.a < 2 +union +select * from (select a from t1 where b >= 'c') as t + where t.a >= 4; +explain +with t as (select a from t1 where b >= 'c') + select * from t where a < 2 + union + select * from t where a >= 4; +explain +select * from (select a from t1 where b >= 'c') as t + where t.a < 2 +union +select * from (select a from t1 where b >= 'c') as t + where t.a >= 4; + +--echo # specification of t contains union +with t as (select a from t1 where b >= 'f' + union + select c as a from t2 where c < 4) + select * from t2,t where t2.c=t.a; +select * from t2, + (select a from t1 where b >= 'f' + union + select c as a from t2 where c < 4) as t + where t2.c=t.a; +explain +with t as (select a from t1 where b >= 'f' + union + select c as a from t2 where c < 4) + select * from t2,t where t2.c=t.a; +explain +select * from t2, + (select a from t1 where b >= 'f' + union + select c as a from t2 where c < 4) as t + where t2.c=t.a; + +--echo # t is defined in the with clause of a subquery +select t1.a,t1.b from t1,t2 + where t1.a>t2.c and + t2.c in (with t as (select * from t1 where t1.a<5) + select t2.c from t2,t where t2.c=t.a); +select t1.a,t1.b from t1,t2 + where t1.a>t2.c and + t2.c in (select t2.c + from t2,(select * from t1 where t1.a<5) as t + where t2.c=t.a); +explain +select t1.a,t1.b from t1,t2 + where t1.a>t2.c and + t2.c in (with t as (select * from t1 where t1.a<5) + select t2.c from t2,t where t2.c=t.a); +explain +select t1.a,t1.b from t1,t2 + where t1.a>t2.c and + t2.c in (select t2.c + from t2,(select * from t1 where t1.a<5) as t + where t2.c=t.a); + +--echo # two different definitions of t: one in the with clause of the main query, +--echo # the other in the with clause of a subquery +with t as (select c from t2 where c >= 4) + select t1.a,t1.b from t1,t + where t1.a=t.c and + t.c in (with t as (select * from t1 where t1.a<5) + select t2.c from t2,t where t2.c=t.a); +select t1.a,t1.b from t1, (select c from t2 where c >= 4) as t + where t1.a=t.c and + t.c in (select t2.c from t2, (select * from t1 where t1.a<5) as t + where t2.c=t.a); +explain +with t as (select c from t2 where c >= 4) + select t1.a,t1.b from t1,t + where t1.a=t.c and + t.c in (with t as (select * from t1 where t1.a<5) + select t2.c from t2,t where t2.c=t.a); +explain +select t1.a,t1.b from t1, (select c from t2 where c >= 4) as t + where t1.a=t.c and + t.c in (select t2.c from t2, (select * from t1 where t1.a<5) as t + where t2.c=t.a); + +--echo # another with table tt is defined in the with clause of a subquery +--echo # from the specification of t +with t as (select * from t1 + where a>2 and + b in (with tt as (select * from t2 where t2.c<5) + select t1.b from t1,tt where t1.a=tt.c)) + select t.a, count(*) from t1,t where t1.a=t.a group by t.a; +select t.a, count(*) + from t1, + (select * from t1 + where a>2 and + b in (select t1.b + from t1, + (select * from t2 where t2.c<5) as tt + where t1.a=tt.c)) as t + where t1.a=t.a group by t.a; +explain +with t as (select * from t1 + where a>2 and + b in (with tt as (select * from t2 where t2.c<5) + select t1.b from t1,tt where t1.a=tt.c)) + select t.a, count(*) from t1,t where t1.a=t.a group by t.a; +explain +select t.a, count(*) + from t1, + (select * from t1 + where a>2 and + b in (select t1.b + from t1, + (select * from t2 where t2.c<5) as tt + where t1.a=tt.c)) as t + where t1.a=t.a group by t.a; + +--echo # with clause in the specification of a derived table +select * + from t1, + (with t as (select a from t1 where b >= 'c') + select * from t2,t where t2.c=t.a) as tt + where t1.b > 'f' and tt.a=t1.a; +select * + from t1, + (select * from t2, + (select a from t1 where b >= 'c') as t + where t2.c=t.a) as tt + where t1.b > 'f' and tt.a=t1.a; +explain +select * + from t1, + (with t as (select a from t1 where b >= 'c') + select * from t2,t where t2.c=t.a) as tt + where t1.b > 'f' and tt.a=t1.a; +explain +select * + from t1, + (select * from t2, + (select a from t1 where b >= 'c') as t + where t2.c=t.a) as tt + where t1.b > 'f' and tt.a=t1.a; + +--echo # with claused in the specification of a view +create view v1 as +with t as (select a from t1 where b >= 'c') + select * from t2,t where t2.c=t.a; +show create view v1; +select * from v1; +explain +select * from v1; + +--echo # with claused in the specification of a materialized view +create view v2 as +with t as (select a, count(*) from t1 where b >= 'c' group by a) + select * from t2,t where t2.c=t.a; +show create view v2; +select * from v2; +explain +select * from v2; + +--echo # with clause in the specification of a view that whose definition +--echo # table alias for a with table +create view v3 as +with t(c) as (select a from t1 where b >= 'c') +select * from t r1 where r1.c=4; +show create view v3; +select * from v3; + +--echo # with clause in the specification of a view that whose definition +--echo # two table aliases for for the same with table +create view v4(c,d) as +with t(c) as (select a from t1 where b >= 'c') +select * from t r1, t r2 where r1.c=r2.c and r2.c=4; +show create view v4; +select * from v4; +explain +select * from v4; + +drop view v1,v2,v3,v4; + + +--echo # currently any views containing with clause are not updatable +create view v1(a) as +with t as (select a from t1 where b >= 'c') + select t.a from t2,t where t2.c=t.a; +--error ER_NON_UPDATABLE_TABLE +update v1 set a=0 where a > 4; +drop view v1; + + +--echo # prepare of a query containing a definition of a with table t +prepare stmt1 from " +with t as (select a from t1 where b >= 'c') + select * from t2,t where t2.c=t.a; +"; +execute stmt1; +execute stmt1; +deallocate prepare stmt1; + +--echo # prepare of a query containing a definition of a materialized t +prepare stmt1 from " +with t as (select a, count(*) from t1 where b >= 'c' group by a) + select * from t2,t where t2.c=t.a; +"; +execute stmt1; +execute stmt1; +deallocate prepare stmt1; + +--echo # prepare of a query containing two references to with table t +prepare stmt1 from " +with t as (select * from t1 where b >= 'c') + select * from t as r1, t as r2 where r1.a=r2.a; +"; +execute stmt1; +execute stmt1; +deallocate prepare stmt1; + +--ERROR ER_WITH_COL_WRONG_LIST +with t(f) as (select * from t1 where b >= 'c') + select * from t2,t where t2.c=t.f1; + +--ERROR ER_DUP_FIELDNAME +with t(f1,f1) as (select * from t1 where b >= 'c') + select * from t2,t where t2.c=t.f1; + +--ERROR ER_DUP_QUERY_NAME +with t as (select * from t2 where c>3), + t as (select a from t1 where a>2) + select * from t,t1 where t1.a=t.c; + +--ERROR ER_NO_SUCH_TABLE +with t as (select a from s where a<5), + s as (select a from t1 where b>='d') + select * from t,s where t.a=s.a; + +with recursive + t as (select a from s where a<5), + s as (select a from t1 where b>='d') + select * from t,s where t.a=s.a; + +--ERROR ER_RECURSIVE_WITHOUT_ANCHORS +with recursive t as (select * from s where a>2), + s as (select a from t1,r where t1.a>r.c), + r as (select c from t,t2 where t.a=t2.c) + select * from r where r.c<7; + +--ERROR ER_RECURSIVE_WITHOUT_ANCHORS +with recursive + t as (select * from s where a>2), + s as (select a from t1,r where t1.a>r.c), + r as (select c from t,t2 where t.a=t2.c) + select * from r where r.c<7; + +--ERROR ER_RECURSIVE_WITHOUT_ANCHORS +with recursive + t as (select * from t1 + where a in (select c from s where b<='ccc') and b>'b'), + s as (select * from t1,t2 + where t1.a=t2.c and t1.c in (select a from t where a<5)) + select * from s where s.b>'aaa'; + +--ERROR ER_RECURSIVE_WITHOUT_ANCHORS +with recursive + t as (select * from t1 where b>'aaa' and b <='d') + select t.b from t,t2 + where t.a=t2.c and + t2.c in (with recursive + s as (select t1.a from s,t1 where t1.a=s.a and t1.b<'c') + select * from s); +--echo #erroneous definition of unreferenced with table t +--ERROR ER_BAD_FIELD_ERROR +with t as (select count(*) from t1 where d>='f' group by a) + select t1.b from t2,t1 where t1.a = t2.c; + +with t as (select count(*) from t1 where b>='f' group by a) + select t1.b from t2,t1 where t1.a = t2.c; + +--echo #erroneous definition of s referring to unreferenced t +--ERROR ER_BAD_FIELD_ERROR +with t(d) as (select count(*) from t1 where b<='ccc' group by b), + s as (select * from t1 where a in (select t2.d from t2,t where t2.c=t.d)) + select t1.b from t1,t2 where t1.a=t2.c; +--ERROR ER_BAD_FIELD_ERROR +with t(d) as (select count(*) from t1 where b<='ccc' group by b), + s as (select * from t1 where a in (select t2.c from t2,t where t2.c=t.c)) + select t1.b from t1,t2 where t1.a=t2.c; + +with t(d) as (select count(*) from t1 where b<='ccc' group by b), + s as (select * from t1 where a in (select t2.c from t2,t where t2.c=t.d)) + select t1.b from t1,t2 where t1.a=t2.c; + +--echo #erroneous definition of unreferenced with table t +--ERROR ER_WITH_COL_WRONG_LIST +with t(f) as (select * from t1 where b >= 'c') + select t1.b from t2,t1 where t1.a = t2.c; + +--echo #erroneous definition of unreferenced with table t +--ERROR ER_DUP_FIELDNAME +with t(f1,f1) as (select * from t1 where b >= 'c') + select t1.b from t2,t1 where t1.a = t2.c; + +--echo # explain for query with unreferenced with table + +explain +with t as (select a from t1 where b >= 'c') + select t1.b from t2,t1 where t1.a = t2.c; + +explain +with t as (select a, count(*) from t1 where b >= 'c' group by a) + select t1.b from t2,t1 where t1.a = t2.c; + +--echo # too many with elements in with clause +let $m= 65; +let $i= $m; +dec $i; +let $q= with s$m as (select * from t1); +while ($i) +{ + let $q= $q, s$i as (select * from t1) ; + dec $i; + } +let $q= $q select * from s$m; +--ERROR ER_TOO_MANY_DEFINITIONS_IN_WITH_CLAUSE +eval $q; + +drop table t1,t2; + +--echo # +--echo # Bug mdev-9937: View used in the specification of with table +--echo # refers to the base table with the same name +--echo # + +create table t1 (a int); +insert into t1 values (20), (30), (10); +create view v1 as select * from t1 where a > 10; + +with t1 as (select * from v1) select * from t1; + +drop view v1; +drop table t1; + +--echo # +--echo # Bug mdev-10058: Invalid derived table with WITH clause +--echo # + +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a INT); +CREATE TABLE t3 (a INT); +INSERT INTO t1 VALUES (1),(2),(3); +INSERT INTO t2 VALUES (1),(2),(3); +INSERT INTO t3 VALUES (1),(2),(3); + +--ERROR ER_PARSE_ERROR +SELECT * FROM (WITH a AS (SELECT * FROM t1) (t2 NATURAL JOIN t3)); + +SELECT * FROM (WITH a AS (SELECT * FROM t1) SELECT * FROM t2 NATURAL JOIN t3) AS d1; + +DROP TABLE t1,t2,t3; + +--echo # +--echo # Bug mdev-10344: the WITH clause of the query refers to a view that uses +--echo # a base table with the same name as a CTE table from the clause +--echo # + + +create table ten(a int primary key); +insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table one_k(a int primary key); +insert into one_k select A.a + B.a* 10 + C.a * 100 from ten A, ten B, ten C; + +create view v1 as select * from ten; + +select * from v1; + +drop view v1; +drop table ten, one_k; + +--echo # +--echo # MDEV-10057 : Crash with EXPLAIN + WITH + constant query +--echo # +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2),(3); +SELECT * FROM (WITH a AS (SELECT * FROM t1) SELECT 1) AS t1; +EXPLAIN SELECT * FROM (WITH a AS (SELECT * FROM t1) SELECT 1) AS t1; +DROP TABLE t1; + +--echo # +--echo # MDEV-10058: Suspicious EXPLAIN output for a derived table + WITH + joined table +--echo # +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a INT); +CREATE TABLE t3 (a INT); +INSERT INTO t1 VALUES (1),(2),(3); +INSERT INTO t2 VALUES (1),(2),(3); +INSERT INTO t3 VALUES (1),(2),(3); +--error ER_PARSE_ERROR +EXPLAIN SELECT * FROM (WITH a AS (SELECT * FROM t1) (t2 NATURAL JOIN t3)); +explain SELECT * FROM (WITH a AS (SELECT * FROM t1) SELECT * FROM t2 NATURAL JOIN t3) AS d1; +DROP TABLE t1,t2,t3; + +--echo # +--echo # MDEV-10729: Server crashes in st_select_lex::set_explain_type +--echo # +CREATE TABLE t1 (i1 INT, KEY(i1)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (4),(8); + +CREATE TABLE t2 (a2 INT, b2 INT, KEY(b2)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (8,7); + +CREATE TABLE t3 (i3 INT) ENGINE=MyISAM; +INSERT INTO t3 VALUES (2),(6); + +SELECT * FROM t1, t2 WHERE a2 = i1 and b2 >= i1 AND i1 IN ( SELECT i3 FROM t3 ) +UNION +SELECT * FROM t1, t2 WHERE a2 = i1 and b2 >= i1 AND i1 IN ( SELECT i3 FROM t3 ) +; +DROP TABLE t1,t2,t3; + +--echo # +--echo # MDEV-10923: mergeable CTE used twice in the query +--echo # + +create table employees ( + name varchar(32), + dept varchar(32), + country varchar(8) +); + +insert into employees +values +('Sergei Golubchik', 'Development', 'DE'), +('Claudio Nanni', 'Support', 'ES'), +('Sergei Petrunia', 'Development', 'RU'); + +with eng as +( + select * from employees + where dept in ('Development','Support') +), +eu_eng as +( + select * from eng where country IN ('DE','ES','RU') +) +select * from eu_eng T1 +where + not exists (select 1 from eu_eng T2 + where T2.country=T1.country + and T2.name <> T1.name); + +drop table employees; diff --git a/mysql-test/t/cte_recursive.test b/mysql-test/t/cte_recursive.test new file mode 100644 index 00000000000..ea0f73be259 --- /dev/null +++ b/mysql-test/t/cte_recursive.test @@ -0,0 +1,1507 @@ +create table t1 (a int, b varchar(32)); +insert into t1 values +(4,'aaaa' ), (7,'bb'), (1,'ccc'), (4,'dd'); +insert into t1 values +(3,'eee'), (7,'bb'), (1,'fff'), (4,'ggg'); + +--ERROR ER_UNACCEPTABLE_MUTUAL_RECURSION +with recursive +t as +( + select * from t1 where t1.b >= 'c' + union + select * from r +), +r as +( + select * from t + union + select t1.* from t1,r where r.a+1 = t1.a +) +select * from r; + + +--ERROR ER_UNACCEPTABLE_MUTUAL_RECURSION +with recursive +a1(a,b) as +(select * from t1 where t1.a>3 +union +select * from b1 where b1.a >3 +union +select * from c1 where c1.a>3), +b1(a,b) as +(select * from a1 where a1.b > 'ccc' +union +select * from c1 where c1.b > 'ddd'), +c1(a,b) as +(select * from a1 where a1.a<6 and a1.b< 'zz' +union +select * from b1 where b1.b > 'auu') +select * from c1; + +drop table t1; + + +--echo # WITH RECURSIVE vs just WITH + +create table t1 (a int); +insert into t1 values + (0), (1), (2), (3), (4); +create table t2 (a int); +insert into t2 values + (1), (2), (3), (4), (5); + + +--echo # just WITH : s refers to t defined after s +--ERROR ER_NO_SUCH_TABLE +with + s(a) as (select t.a + 10 from t), + t(a) as (select t1.a from t1) +select * from s; + +--echo # WITH RECURSIVE: s refers to t defined after s +with recursive + s(a) as (select t.a + 10 from t), + t(a) as (select t1.a from t1) +select * from s; + +--echo # just WITH : defined t1 is non-recursive and uses base tables t1,t2 +with +t1 as +( +select a from t2 where t2.a=3 +union +select t2.a from t1,t2 where t1.a+1=t2.a +) +select * from t1; + +explain +with +t1 as +( +select a from t2 where t2.a=3 +union +select t2.a from t1,t2 where t1.a+1=t2.a +) +select * from t1; + + +--echo #WITH RECURSIVE : defined t1 is recursive and uses only base table t2 +with recursive +t1 as +( +select a from t2 where t2.a=3 +union +select t2.a from t1,t2 where t1.a+1=t2.a +) +select * from t1; + +explain +with recursive +t1 as +( +select a from t2 where t2.a=3 +union +select t2.a from t1,t2 where t1.a+1=t2.a +) +select * from t1; + +--echo # just WITH : types of t1 columns are determined by all parts of union + +create view v1 as +with +t1 as +( +select a from t2 where t2.a=3 +union +select t2.a+1 from t1,t2 where t1.a=t2.a +) +select * from t1; + +show columns from v1; + + +--echo # WITH RECURSIVE : types of t1 columns are determined by anchor parts + +create view v2 as +with recursive +t1 as +( +select a from t2 where t2.a=3 +union +select t2.a+1 from t1,t2 where t1.a=t2.a +) +select * from t1; + +show columns from v2; + +drop view v1,v2; + +drop table t1,t2; + + +create table folks(id int, name char(32), dob date, father int, mother int); + +insert into folks values +(100, 'Me', '2000-01-01', 20, 30), +(20, 'Dad', '1970-02-02', 10, 9), +(30, 'Mom', '1975-03-03', 8, 7), +(10, 'Grandpa Bill', '1940-04-05', null, null), +(9, 'Grandma Ann', '1941-10-15', null, null), +(25, 'Uncle Jim', '1968-11-18', 8, 7), +(98, 'Sister Amy', '2001-06-20', 20, 30), +(7, 'Grandma Sally', '1943-08-23', null, 6), +(8, 'Grandpa Ben', '1940-10-21', null, null), +(6, 'Grandgrandma Martha', '1923-05-17', null, null), +(67, 'Cousin Eddie', '1992-02-28', 25, 27), +(27, 'Auntie Melinda', '1971-03-29', null, null); + +--echo # simple recursion with one anchor and one recursive select +--echo # the anchor is the first select in the specification +with recursive +ancestors +as +( + select * + from folks + where name = 'Me' and dob = '2000-01-01' + union + select p.id, p.name, p.dob, p.father, p.mother + from folks as p, ancestors AS a + where p.id = a.father or p.id = a.mother +) +select * from ancestors; + +--echo # simple recursion with one anchor and one recursive select +--echo # the anchor is the last select in the specification +with recursive +ancestors +as +( + select p.* + from folks as p, ancestors AS a + where p.id = a.father or p.id = a.mother + union + select * + from folks + where name = 'Me' and dob = '2000-01-01' +) +select * from ancestors; + +--echo # simple recursion with one anchor and one recursive select +--echo # the anchor is the first select in the specification +with recursive +ancestors +as +( + select * + from folks + where name = 'Cousin Eddie' + union + select p.* + from folks as p, ancestors as a + where p.id = a.father or p.id = a.mother +) +select * from ancestors; + +--echo # simple recursion with or in anchor and or in recursive part +with recursive +ancestors +as +( + select * + from folks + where name = 'Me' or name='Sister Amy' + union + select p.* + from folks as p, ancestors as a + where p.id = a.father or p.id = a.mother +) +select * from ancestors; + +--echo # two recursive definition, one uses another +with recursive +prev_gen +as +( + select folks.* + from folks, prev_gen + where folks.id=prev_gen.father or folks.id=prev_gen.mother + union + select * + from folks + where name='Me' +), +ancestors +as +( + select * + from folks + where name='Me' + union + select * + from ancestors + union + select * + from prev_gen +) +select ancestors.name, ancestors.dob from ancestors; + +--echo # recursive definition with two attached non-recursive +with recursive +ancestors(id,name,dob) +as +( + with + father(child_id,id,name,dob) + as + ( + select folks.id, f.id, f.name, f.dob + from folks, folks f + where folks.father=f.id + + ), + mother(child_id,id,name,dob) + as + ( + select folks.id, m.id, m.name, m.dob + from folks, folks m + where folks.mother=m.id + + ) + select folks.id, folks.name, folks.dob + from folks + where name='Me' + union + select f.id, f.name, f.dob + from ancestors a, father f + where f.child_id=a.id + union + select m.id, m.name, m.dob + from ancestors a, mother m + where m.child_id=a.id + +) +select ancestors.name, ancestors.dob from ancestors; + +--echo # simple recursion with one anchor and one recursive select +--echo # the anchor is the first select in the specification +with recursive +descendants +as +( + select * + from folks + where name = 'Grandpa Bill' + union + select folks.* + from folks, descendants as d + where d.id=folks.father or d.id=folks.mother +) +select * from descendants; + +--echo # simple recursion with one anchor and one recursive select +--echo # the anchor is the first select in the specification +with recursive +descendants +as +( + select * + from folks + where name = 'Grandma Sally' + union + select folks.* + from folks, descendants as d + where d.id=folks.father or d.id=folks.mother +) +select * from descendants; + + +--echo # simple recursive table used three times in the main query +with recursive +ancestors +as +( + select * + from folks + where name = 'Me' and dob = '2000-01-01' + union + select p.* + from folks as p, ancestors AS a + where p.id = a.father OR p.id = a.mother +) +select * + from ancestors t1, ancestors t2 + where exists (select * from ancestors a + where a.father=t1.id AND a.mother=t2.id); + + +--echo # simple recursive table used three times in the main query +with +ancestor_couples(husband, h_dob, wife, w_dob) +as +( +with recursive +ancestors +as +( + select * + from folks + where name = 'Me' + union + select p.* + from folks as p, ancestors AS a + where p.id = a.father OR p.id = a.mother +) +select t1.name, t1.dob, t2.name, t2.dob + from ancestors t1, ancestors t2 + where exists (select * from ancestors a + where a.father=t1.id AND a.mother=t2.id) +) +select * from ancestor_couples; + + +--echo # simple recursion with two selects in recursive part +with recursive +ancestors +as +( + select * + from folks + where name = 'Me' + union + select p.* + from folks as p, ancestors as fa + where p.id = fa.father + union + select p.* + from folks as p, ancestors as ma + where p.id = ma.mother +) +select * from ancestors; + + +--echo # mutual recursion with renaming +with recursive +ancestor_couples(h_id, h_name, h_dob, h_father, h_mother, + w_id, w_name, w_dob, w_father, w_mother) +as +( + select h.*, w.* + from folks h, folks w, coupled_ancestors a + where a.father = h.id AND a.mother = w.id + union + select h.*, w.* + from folks v, folks h, folks w + where v.name = 'Me' and + (v.father = h.id AND v.mother= w.id) +), +coupled_ancestors (id, name, dob, father, mother) +as +( + select h_id, h_name, h_dob, h_father, h_mother + from ancestor_couples + union + select w_id, w_name, w_dob, w_father, w_mother + from ancestor_couples +) +select h_name, h_dob, w_name, w_dob + from ancestor_couples; + + +--echo # mutual recursion with union all +with recursive +ancestor_couples(h_id, h_name, h_dob, h_father, h_mother, + w_id, w_name, w_dob, w_father, w_mother) +as +( + select h.*, w.* + from folks h, folks w, coupled_ancestors a + where a.father = h.id AND a.mother = w.id + union + select h.*, w.* + from folks v, folks h, folks w + where v.name = 'Me' and + (v.father = h.id AND v.mother= w.id) +), +coupled_ancestors (id, name, dob, father, mother) +as +( + select h_id, h_name, h_dob, h_father, h_mother + from ancestor_couples + union all + select w_id, w_name, w_dob, w_father, w_mother + from ancestor_couples +) +select h_name, h_dob, w_name, w_dob + from ancestor_couples; + + +--echo # mutual recursion with renaming +with recursive +ancestor_couples(h_id, h_name, h_dob, h_father, h_mother, + w_id, w_name, w_dob, w_father, w_mother) +as +( + select h.*, w.* + from folks h, folks w, coupled_ancestors a + where a.father = h.id AND a.mother = w.id + union + select h.*, w.* + from folks v, folks h, folks w + where v.name = 'Me' and + (v.father = h.id AND v.mother= w.id) +), +coupled_ancestors (id, name, dob, father, mother) +as +( + select h_id, h_name, h_dob, h_father, h_mother + from ancestor_couples + union + select w_id, w_name, w_dob, w_father, w_mother + from ancestor_couples +) +select h_name, h_dob, w_name, w_dob + from ancestor_couples; + + +--echo # mutual recursion with union all +with recursive +ancestor_couples(h_id, h_name, h_dob, h_father, h_mother, + w_id, w_name, w_dob, w_father, w_mother) +as +( + select h.*, w.* + from folks h, folks w, coupled_ancestors a + where a.father = h.id AND a.mother = w.id +), +coupled_ancestors (id, name, dob, father, mother) +as +( + select * + from folks + where name = 'Me' + union all + select h_id, h_name, h_dob, h_father, h_mother + from ancestor_couples + union all + select w_id, w_name, w_dob, w_father, w_mother + from ancestor_couples +) +select h_name, h_dob, w_name, w_dob + from ancestor_couples; + +--echo # mutual recursion with one select in the first definition +with recursive +ancestor_couple_ids(h_id, w_id) +as +( + select a.father, a.mother + from coupled_ancestors a + where a.father is not null and a.mother is not null +), +coupled_ancestors (id, name, dob, father, mother) +as +( + select * + from folks + where name = 'Me' + union all + select p.* + from folks p, ancestor_couple_ids fa + where p.id = fa.h_id + union all + select p.* + from folks p, ancestor_couple_ids ma + where p.id = ma.w_id +) +select * + from ancestor_couple_ids; + + +--echo # join of a mutually recursive table with base tables +with recursive +ancestor_couple_ids(h_id, w_id) +as +( + select a.father, a.mother + from coupled_ancestors a + where a.father is not null and a.mother is not null +), +coupled_ancestors (id, name, dob, father, mother) +as +( + select * + from folks + where name = 'Me' + union all + select p.* + from folks p, ancestor_couple_ids fa + where p.id = fa.h_id + union all + select p.* + from folks p, ancestor_couple_ids ma + where p.id = ma.w_id +) +select h.name, h.dob, w.name, w.dob + from ancestor_couple_ids c, folks h, folks w + where c.h_id = h.id and c.w_id= w.id; + + +--echo # join of two mutually recursive tables +with recursive +ancestor_couple_ids(h_id, w_id) +as +( + select a.father, a.mother + from coupled_ancestors a + where a.father is not null and a.mother is not null +), +coupled_ancestors (id, name, dob, father, mother) +as +( + select * + from folks + where name = 'Me' + union all + select p.* + from folks p, ancestor_couple_ids fa + where p.id = fa.h_id + union all + select p.* + from folks p, ancestor_couple_ids ma + where p.id = ma.w_id +) +select h.name, h.dob, w.name, w.dob + from ancestor_couple_ids c, coupled_ancestors h, coupled_ancestors w + where c.h_id = h.id and c.w_id= w.id; + +explain extended +with recursive +ancestor_couple_ids(h_id, w_id) +as +( + select a.father, a.mother + from coupled_ancestors a + where a.father is not null and a.mother is not null +), +coupled_ancestors (id, name, dob, father, mother) +as +( + select * + from folks + where name = 'Me' + union all + select p.* + from folks p, ancestor_couple_ids fa + where p.id = fa.h_id + union all + select p.* + from folks p, ancestor_couple_ids ma + where p.id = ma.w_id +) +select h.name, h.dob, w.name, w.dob + from ancestor_couple_ids c, coupled_ancestors h, coupled_ancestors w + where c.h_id = h.id and c.w_id= w.id; + + +--echo # simple mutual recursion +with recursive +ancestor_couple_ids(h_id, w_id) +as +( + select a.father, a.mother + from coupled_ancestors a +), +coupled_ancestors (id, name, dob, father, mother) +as +( + select * + from folks + where name = 'Me' + union all + select p.* + from folks p, ancestor_couple_ids fa + where p.id = fa.h_id + union all + select p.* + from folks p, ancestor_couple_ids ma + where p.id = ma.w_id +) +select * + from ancestor_couple_ids; + + +--echo # join of two mutually recursive tables +with recursive +ancestor_couple_ids(h_id, w_id) +as +( + select a.father, a.mother + from coupled_ancestors a +), +coupled_ancestors (id, name, dob, father, mother) +as +( + select * + from folks + where name = 'Me' + union all + select p.* + from folks p, ancestor_couple_ids fa + where p.id = fa.h_id + union all + select p.* + from folks p, ancestor_couple_ids ma + where p.id = ma.w_id +) +select h.name, h.dob, w.name, w.dob + from ancestor_couple_ids c, coupled_ancestors h, coupled_ancestors w + where c.h_id = h.id and c.w_id= w.id; + + +--echo # execution of prepared query using a recursive table +prepare stmt1 from " +with recursive +ancestors +as +( + select * + from folks + where name = 'Me' and dob = '2000-01-01' + union + select p.id, p.name, p.dob, p.father, p.mother + from folks as p, ancestors AS a + where p.id = a.father or p.id = a.mother +) +select * from ancestors; +"; + +execute stmt1; +execute stmt1; + +deallocate prepare stmt1; + + +--echo # view using a recursive table +create view v1 as +with recursive +ancestors +as +( + select * + from folks + where name = 'Me' and dob = '2000-01-01' + union + select p.id, p.name, p.dob, p.father, p.mother + from folks as p, ancestors AS a + where p.id = a.father or p.id = a.mother +) +select * from ancestors; + +show create view v1; + +select * from v1; + +create view v2 as +with recursive +ancestors +as +( + select * + from folks + where name = 'Me' + union + select p.* + from folks as p, ancestors as fa + where p.id = fa.father + union + select p.* + from folks as p, ancestors as ma + where p.id = ma.mother +) +select * from ancestors; + +show create view v2; + +select * from v2; + +drop view v1,v2; + + +explain extended +with recursive +ancestors +as +( + select * + from folks + where name = 'Me' and dob = '2000-01-01' + union + select p.id, p.name, p.dob, p.father, p.mother + from folks as p, ancestors AS a + where p.id = a.father or p.id = a.mother +) +select * from ancestors; + + +--echo # recursive spec with two anchor selects and two recursive ones +with recursive +ancestor_ids (id) +as +( + select father from folks where name = 'Me' + union + select mother from folks where name = 'Me' + union + select father from folks, ancestor_ids a where folks.id = a.id + union + select mother from folks, ancestor_ids a where folks.id = a.id +), +ancestors +as +( + select p.* from folks as p, ancestor_ids as a + where p.id = a.id +) +select * from ancestors; + + +--echo # recursive spec using union all +with recursive +ancestors +as +( + select * + from folks + where name = 'Me' + union all + select p.* + from folks as p, ancestors as fa + where p.id = fa.father + union all + select p.* + from folks as p, ancestors as ma + where p.id = ma.mother +) +select * from ancestors; + + +--ERROR ER_NOT_STANDARDS_COMPLIANT_RECURSIVE +with recursive +ancestor_ids (id, generation) +as +( + select father, 1 from folks where name = 'Me' and father is not null + union all + select mother, 1 from folks where name = 'Me' and mother is not null + union all + select father, fa.generation+1 from folks, ancestor_ids fa + where folks.id = fa.id and (father not in (select id from ancestor_ids)) + union all + select mother, ma.generation+1 from folks, ancestor_ids ma + where folks.id = ma.id and (mother not in (select id from ancestor_ids)) +) +select generation, name from ancestor_ids a, folks + where a.id = folks.id; + +set standards_compliant_cte=0; + +--ERROR ER_WITH_COL_WRONG_LIST +with recursive +ancestor_ids (id, generation) +as +( + select father from folks where name = 'Me' and father is not null + union all + select mother from folks where name = 'Me' and mother is not null + union all + select father, fa.generation+1 from folks, ancestor_ids fa + where folks.id = fa.id and (father not in (select id from ancestor_ids)) + union all + select mother, ma.generation+1 from folks, ancestor_ids ma + where folks.id = ma.id and (mother not in (select id from ancestor_ids)) +) +select generation, name from ancestor_ids a, folks + where a.id = folks.id; + +with recursive +ancestor_ids (id, generation) +as +( + select father, 1 from folks where name = 'Me' and father is not null + union all + select mother, 1 from folks where name = 'Me' and mother is not null + union all + select father, fa.generation+1 from folks, ancestor_ids fa + where folks.id = fa.id and father is not null and + (father not in (select id from ancestor_ids)) + union all + select mother, ma.generation+1 from folks, ancestor_ids ma + where folks.id = ma.id and mother is not null and + (mother not in (select id from ancestor_ids)) +) +select generation, name from ancestor_ids a, folks + where a.id = folks.id; + +set standards_compliant_cte=1; + +--ERROR ER_NOT_STANDARDS_COMPLIANT_RECURSIVE +with recursive +coupled_ancestor_ids (id) +as +( + select father from folks where name = 'Me' and father is not null + union + select mother from folks where name = 'Me' and mother is not null + union + select n.father + from folks, coupled_ancestor_ids fa, coupled_ancestor_ids ma, folks n + where folks.father = fa.id and folks.mother = ma.id and + (fa.id = n.id or ma.id = n.id) and + n.father is not null and n.mother is not null + union + select n.mother + from folks, coupled_ancestor_ids fa, coupled_ancestor_ids ma, folks n + where folks.father = fa.id and folks.mother = ma.id and + (fa.id = n.id or ma.id = n.id) and + n.father is not null and n.mother is not null +) +select p.* from coupled_ancestor_ids a, folks p + where a.id = p.id; + +set statement standards_compliant_cte=0 for +with recursive +coupled_ancestor_ids (id) +as +( + select father from folks where name = 'Me' and father is not null + union + select mother from folks where name = 'Me' and mother is not null + union + select n.father + from folks, coupled_ancestor_ids fa, coupled_ancestor_ids ma, folks n + where folks.father = fa.id and folks.mother = ma.id and + (fa.id = n.id or ma.id = n.id) and + n.father is not null and n.mother is not null + union + select n.mother + from folks, coupled_ancestor_ids fa, coupled_ancestor_ids ma, folks n + where folks.father = fa.id and folks.mother = ma.id and + (fa.id = n.id or ma.id = n.id) and + n.father is not null and n.mother is not null +) +select p.* from coupled_ancestor_ids a, folks p + where a.id = p.id; + +--ERROR ER_NOT_STANDARDS_COMPLIANT_RECURSIVE +with recursive +ancestor_ids (id) +as +( + select father from folks where name = 'Me' + union + select mother from folks where name = 'Me' + union + select father from folks left join ancestor_ids a on folks.id = a.id + union + select mother from folks left join ancestor_ids a on folks.id = a.id +), +ancestors +as +( + select p.* from folks as p, ancestor_ids as a + where p.id = a.id +) +select * from ancestors; + +set statement standards_compliant_cte=0 for +with recursive +ancestor_ids (id) +as +( + select father from folks where name = 'Me' + union + select mother from folks where name = 'Me' + union + select father from folks left join ancestor_ids a on folks.id = a.id + union + select mother from folks left join ancestor_ids a on folks.id = a.id +), +ancestors +as +( + select p.* from folks as p, ancestor_ids as a + where p.id = a.id +) +select * from ancestors; + +with recursive +ancestor_ids (id, generation) +as +( + select father, 1 from folks where name = 'Me' + union + select mother, 1 from folks where name = 'Me' + union + select father, a.generation+1 from folks, ancestor_ids a + where folks.id = a.id + union + select mother, a.generation+1 from folks, ancestor_ids a + where folks.id = a.id +), +ancestors +as +( + select generation, name from folks as p, ancestor_ids as a + where p.id = a.id +) +select * from ancestors; + +--ERROR ER_NOT_STANDARDS_COMPLIANT_RECURSIVE +with recursive +ancestor_ids (id, generation) +as +( + select father, 1 from folks where name = 'Me' + union + select mother, 1 from folks where name = 'Me' + union + select max(father), max(a.generation)+1 from folks, ancestor_ids a + where folks.id = a.id + group by a.generation + union + select max(mother), max(a.generation)+1 from folks, ancestor_ids a + where folks.id = a.id + group by a.generation +), +ancestors +as +( + select generation, name from folks as p, ancestor_ids as a + where p.id = a.id +) +select * from ancestors; + +set statement standards_compliant_cte=0 for +with recursive +ancestor_ids (id, generation) +as +( + select father, 1 from folks where name = 'Me' + union + select mother, 1 from folks where name = 'Me' + union + select max(father), a.generation+1 from folks, ancestor_ids a + where folks.id = a.id + group by a.generation + union + select max(mother), a.generation+1 from folks, ancestor_ids a + where folks.id = a.id + group by a.generation +), +ancestors +as +( + select generation, name from folks as p, ancestor_ids as a + where p.id = a.id +) +select * from ancestors; + +set statement max_recursive_iterations=1 for +with recursive +ancestor_ids (id, generation) +as +( + select father, 1 from folks where name = 'Me' + union + select mother, 1 from folks where name = 'Me' + union + select father, a.generation+1 from folks, ancestor_ids a + where folks.id = a.id + union + select mother, a.generation+1 from folks, ancestor_ids a + where folks.id = a.id +), +ancestors +as +( + select generation, name from folks as p, ancestor_ids as a + where p.id = a.id +) +select * from ancestors; + +--echo # query with recursive tables using key access + +alter table folks add primary key (id); + +explain +with recursive +ancestors +as +( + select * + from folks + where name = 'Me' + union + select p.* + from folks as p, ancestors as fa + where p.id = fa.father + union + select p.* + from folks as p, ancestors as ma + where p.id = ma.mother +) +select * from ancestors; + + +with recursive +ancestors +as +( + select * + from folks + where name = 'Me' + union + select p.* + from folks as p, ancestors as fa + where p.id = fa.father + union + select p.* + from folks as p, ancestors as ma + where p.id = ma.mother +) +select * from ancestors; + + +--echo # +--echo # EXPLAIN FORMAT=JSON on a query where one recursive CTE uses another: +--echo # +explain +with recursive +prev_gen +as +( + select folks.* + from folks, prev_gen + where folks.id=prev_gen.father or folks.id=prev_gen.mother + union + select * + from folks + where name='Me' +), +ancestors +as +( + select * + from folks + where name='Me' + union + select * + from ancestors + union + select * + from prev_gen +) +select ancestors.name, ancestors.dob from ancestors; + +explain FORMAT=JSON +with recursive +prev_gen +as +( + select folks.* + from folks, prev_gen + where folks.id=prev_gen.father or folks.id=prev_gen.mother + union + select * + from folks + where name='Me' +), +ancestors +as +( + select * + from folks + where name='Me2' + union + select * + from ancestors where id < 234 + union + select * + from prev_gen where id < 345 +) +select ancestors.name, ancestors.dob from ancestors; + +--echo # +explain format=json +with recursive +ancestor_couples(h_id, h_name, h_dob, h_father, h_mother, + w_id, w_name, w_dob, w_father, w_mother) +as +( + select h.*, w.* + from folks h, folks w, coupled_ancestors a + where a.father = h.id AND a.mother = w.id + union + select h.*, w.* + from folks v, folks h, folks w + where v.name = 'Me' and + (v.father = h.id AND v.mother= w.id) +), +coupled_ancestors (id, name, dob, father, mother) +as +( + select h_id, h_name, h_dob, h_father, h_mother + from ancestor_couples + union all + select w_id, w_name, w_dob, w_father, w_mother + from ancestor_couples +) +select h_name, h_dob, w_name, w_dob + from ancestor_couples; + + +create table my_ancestors +with recursive +ancestor_ids (id) +as +( + select father from folks where name = 'Me' + union + select mother from folks where name = 'Me' + union + select father from folks, ancestor_ids a where folks.id = a.id + union + select mother from folks, ancestor_ids a where folks.id = a.id +) +select p.* from folks as p, ancestor_ids as a where p.id = a.id; + +select * from my_ancestors; + +delete from my_ancestors; + +insert into my_ancestors +with recursive +ancestor_ids (id) +as +( + select father from folks where name = 'Me' + union + select mother from folks where name = 'Me' + union + select father from folks, ancestor_ids a where folks.id = a.id + union + select mother from folks, ancestor_ids a where folks.id = a.id +) +select p.* from folks as p, ancestor_ids as a where p.id = a.id; + +select * from my_ancestors; + +drop table my_ancestors; + +--echo # +--echo # MDEV-10883: execution of prepared statement from SELECT +--echo # with recursive CTE that renames columns +--echo # + +prepare stmt from" +with recursive +ancestor_ids (id) +as +( + select father from folks where name = 'Me' + union + select mother from folks where name = 'Me' + union + select father from folks, ancestor_ids a where folks.id = a.id + union + select mother from folks, ancestor_ids a where folks.id = a.id +) +select p.* from folks as p, ancestor_ids as a where p.id = a.id; +"; +execute stmt; +deallocate prepare stmt; + +--echo # +--echo # MDEV-10881: execution of prepared statement from +--echo # CREATE ... SELECT, INSERT ... SELECT +--echo # + +prepare stmt from" +create table my_ancestors +with recursive +ancestor_ids (id) +as +( + select father from folks where name = 'Me' + union + select mother from folks where name = 'Me' + union + select father from folks, ancestor_ids a where folks.id = a.id + union + select mother from folks, ancestor_ids a where folks.id = a.id +) +select p.* from folks as p, ancestor_ids as a where p.id = a.id; +"; +execute stmt; +deallocate prepare stmt; +select * from my_ancestors; + +delete from my_ancestors; + +prepare stmt from" +insert into my_ancestors +with recursive +ancestor_ids (id) +as +( + select father from folks where name = 'Me' + union + select mother from folks where name = 'Me' + union + select father from folks, ancestor_ids a where folks.id = a.id + union + select mother from folks, ancestor_ids a where folks.id = a.id +) +select p.* from folks as p, ancestor_ids as a where p.id = a.id; +"; +execute stmt; +deallocate prepare stmt; +select * from my_ancestors; + +drop table my_ancestors; + +--echo # +--echo # MDEV-10933: WITH clause together with SELECT in parenthesis +--echo # CREATE SELECT +--echo # + +create table my_ancestors +( +with recursive +ancestor_ids (id) +as +( + select father from folks where name = 'Me' + union + select mother from folks where name = 'Me' + union + select father from folks, ancestor_ids a where folks.id = a.id + union + select mother from folks, ancestor_ids a where folks.id = a.id +) +select p.* from folks as p, ancestor_ids as a where p.id = a.id +); +select * from my_ancestors; +drop table my_ancestors; + +drop table folks; + +--echo # +--echo # MDEV-10372: [bb-10.2-mdev9864 tree] EXPLAIN with recursive CTE enters endless recursion +--echo # +create table t1(a int); +insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +explain format=json +with recursive t as (select a from t1 union select a+10 from t where a < 1000) +select * from t; + +drop table t1; + + +--echo # +--echo # MDEV-10737: recursive union with several anchors at the end +--echo # + +WITH RECURSIVE cte(n) AS + ( SELECT n+1 FROM cte WHERE n < 5 UNION SELECT 1 UNION SELECT 1 ) +SELECT * FROM cte; + +--echo # +--echo # MDEV-10736: recursive definition with anchor over a table with blob +--echo # + +CREATE TABLE t1 (f VARCHAR(1024)); +WITH RECURSIVE cte(f) AS + (SELECT t1.f FROM t1 UNION ALL SELECT cte.f FROM cte) +SELECT * FROM cte as t; +DROP TABLE t1; + +--echo # +--echo # MDEV-10899: mergeable derived in the spec of recursive CTE +--echo # + +create table t1 (a int); +insert into t1 values + (0), (1), (2), (3), (4); +create table t2 (a int); +insert into t2 values + (1), (2), (3), (4), (5); + +with recursive +t1 as +( +select x.a from (select a from t2 where t2.a=3) x +union +select t2.a from t1,t2 where t1.a+1=t2.a +) +select * from t1; + +explain +with recursive +t1 as +( +select x.a from (select a from t2 where t2.a=3) x +union +select t2.a from t1,t2 where t1.a+1=t2.a +) +select * from t1; + +drop table t1,t2; + +--echo # +--echo # MDEV-11278: non-mergeable view in the spec of recursive CTE +--echo # + +create table t1 (a int); +insert into t1 values + (0), (1), (2), (3), (4); +create table t2 (a int); +insert into t2 values + (1), (2), (3), (4), (5); + +create view v1 as + select a from t2 where a < 3 + union + select a from t2 where a > 4; + +with recursive +t1 as +( +select a from v1 where a=1 +union +select v1.a from t1,v1 where t1.a+1=v1.a +) +select * from t1; + +drop view v1; +drop table t1,t2; + + +--echo # +--echo # MDEV-11259: recursive CTE with concatenation operation +--echo # + +DROP TABLE IF EXISTS edges; +CREATE TABLE edges( + a int(10) unsigned NOT NULL, + b int(10) unsigned NOT NULL, + PRIMARY KEY (a,b), + KEY b(b) +); + +INSERT INTO edges + VALUES (1,3),(2,1),(2,4),(3,4),(3,5),(3,6),(4,7),(5,1),(5,6),(6,1); + +DROP TABLE IF EXISTS edges2; +CREATE VIEW edges2 (a, b) AS + SELECT a, b FROM edges UNION ALL SELECT b, a FROM edges; + +--sorted_result +WITH RECURSIVE transitive_closure(a, b, distance, path_string) AS +( SELECT a, b, 1 AS distance, + concat(a, '.', b, '.') AS path_string + FROM edges + + UNION ALL + + SELECT tc.a, e.b, tc.distance + 1, + concat(tc.path_string, e.b, '.') AS path_string + FROM edges AS e + JOIN transitive_closure AS tc + ON e.a = tc.b + WHERE tc.path_string NOT LIKE concat('%', e.b, '.%') +) +SELECT * FROM transitive_closure +ORDER BY a, b, distance; + +--sorted_result +WITH RECURSIVE transitive_closure(a, b, distance, path_string) AS +( SELECT a, b, 1 AS distance, + concat(a, '.', b, '.') AS path_string + FROM edges + WHERE a = 1 -- source + + UNION ALL + + SELECT tc.a, e.b, tc.distance + 1, + concat(tc.path_string, e.b, '.') AS path_string + FROM edges AS e + JOIN transitive_closure AS tc ON e.a = tc.b + WHERE tc.path_string NOT LIKE concat('%', e.b, '.%') +) + SELECT * FROM transitive_closure + WHERE b = 6 -- destination +ORDER BY a, b, distance; + +--sorted_result +WITH RECURSIVE transitive_closure(a, b, distance, path_string) AS +( SELECT a, b, 1 AS distance, + concat(a, '.', b, '.') AS path_string + FROM edges2 + + UNION ALL + + SELECT tc.a, e.b, tc.distance + 1, + concat(tc.path_string, e.b, '.') AS path_string + FROM edges2 AS e + JOIN transitive_closure AS tc ON e.a = tc.b + WHERE tc.path_string NOT LIKE concat('%', e.b, '.%') +) +SELECT * FROM transitive_closure +ORDER BY a, b, distance; + +--sorted_result +WITH RECURSIVE transitive_closure(a, b, distance, path_string) +AS +( SELECT a, b, 1 AS distance, + concat(a, '.', b, '.') AS path_string + FROM edges2 + + UNION ALL + + SELECT tc.a, e.b, tc.distance + 1, + concat(tc.path_string, e.b, '.') AS path_string + FROM edges2 AS e + JOIN transitive_closure AS tc ON e.a = tc.b + WHERE tc.path_string NOT LIKE concat('%', e.b, '.%') +) +SELECT a, b, min(distance) AS dist FROM transitive_closure +GROUP BY a, b +ORDER BY a, dist, b; + +DROP VIEW edges2; +DROP TABLE edges; + + +--echo # +--echo # MDEV-11674: recursive CTE table that cannot be stored +--echo # in a heap table +--echo # + +create table t1 (id int, test_data varchar(36)); + +insert into t1(id, test_data) +select id, test_data + from ( + with recursive data_generator(id, test_data) as ( + select 1 as id, uuid() as test_data + union all + select id + 1, uuid() from data_generator where id < 150000 + ) + select * from data_generator + ) as a; + +drop table t1; diff --git a/mysql-test/t/ctype_big5.test b/mysql-test/t/ctype_big5.test index 46bb29514ff..fe29f769a89 100644 --- a/mysql-test/t/ctype_big5.test +++ b/mysql-test/t/ctype_big5.test @@ -18,11 +18,13 @@ SET collation_connection='big5_chinese_ci'; -- source include/ctype_like_escape.inc -- source include/ctype_like_range_f1f2.inc -- source include/ctype_ascii_order.inc +-- source include/ctype_pad_space.inc SET collation_connection='big5_bin'; -- source include/ctype_filesort.inc -- source include/ctype_innodb_like.inc -- source include/ctype_like_escape.inc -- source include/ctype_like_range_f1f2.inc +-- source include/ctype_pad_space.inc # # Bugs#9357: TEXT columns break string with special word in BIG5 charset. @@ -247,3 +249,23 @@ DROP TABLE t1; --echo # --echo # End of 10.0 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9711 NO PAD Collatons +--echo # +SET character_set_connection=big5; +let $coll='big5_chinese_nopad_ci'; +let $coll_pad='big5_chinese_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='big5_nopad_bin'; +let $coll_pad='big5_bin'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_cp1251.test b/mysql-test/t/ctype_cp1251.test index 93fd5cc9a1a..97978463407 100644 --- a/mysql-test/t/ctype_cp1251.test +++ b/mysql-test/t/ctype_cp1251.test @@ -65,6 +65,7 @@ DROP TABLE t1; --echo # --source include/ctype_8bit.inc +--source include/ctype_pad_space.inc # # Bug #48053 String::c_ptr has a race and/or does an invalid diff --git a/mysql-test/t/ctype_cp932.test b/mysql-test/t/ctype_cp932.test index 96a2666f69b..2486ca8a79e 100644 --- a/mysql-test/t/ctype_cp932.test +++ b/mysql-test/t/ctype_cp932.test @@ -27,3 +27,23 @@ DROP TABLE t1; SET @@character_set_client= @old_character_set_client; SET @@character_set_connection= @old_character_set_connection; SET @@character_set_results= @old_character_set_results; + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9711 NO PAD Collatons +--echo # +SET character_set_connection=cp932; +let $coll='cp932_japanese_nopad_ci'; +let $coll_pad='cp932_japanese_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='cp932_nopad_bin'; +let $coll_pad='cp932_bin'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_errors.test b/mysql-test/t/ctype_errors.test index 681223dae64..b228a3b9f19 100644 --- a/mysql-test/t/ctype_errors.test +++ b/mysql-test/t/ctype_errors.test @@ -50,13 +50,11 @@ connection default; --echo # connect (con1,localhost,root,,test); ---echo # Connection con1 SET lc_messages=ru_RU; SET NAMES latin1; --error ER_PARSE_ERROR --query SELECT '01234567890123456789012345678901234\' disconnect con1; ---echo # Connection default connection default; --echo End of 5.5 tests diff --git a/mysql-test/t/ctype_eucjpms.test b/mysql-test/t/ctype_eucjpms.test index d533e38b2a2..bda4cec61cc 100644 --- a/mysql-test/t/ctype_eucjpms.test +++ b/mysql-test/t/ctype_eucjpms.test @@ -566,3 +566,31 @@ DROP TABLE t1; --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9842 LOAD DATA INFILE does not work well with a TEXT column when using sjis +--echo # +CREATE TABLE t1 (a TEXT CHARACTER SET eucjpms); +LOAD DATA INFILE '../../std_data/loaddata/mdev9823.ujis.txt' INTO TABLE t1 CHARACTER SET eucjpms IGNORE 4 LINES; +SELECT HEX(a) FROM t1; +DROP TABLE t1; + +--echo # +--echo # MDEV-9711 NO PAD Collatons +--echo # +SET character_set_connection=eucjpms; +let $coll='eucjpms_japanese_nopad_ci'; +let $coll_pad='eucjpms_japanese_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='eucjpms_nopad_bin'; +let $coll_pad='eucjpms_bin'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_euckr.test b/mysql-test/t/ctype_euckr.test index 33b3e96cba8..b0b1569e540 100644 --- a/mysql-test/t/ctype_euckr.test +++ b/mysql-test/t/ctype_euckr.test @@ -197,3 +197,23 @@ set collation_connection=euckr_bin; --echo # End of 5.6 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9711 NO PAD Collatons +--echo # +SET character_set_connection=euckr; +let $coll='euckr_korean_nopad_ci'; +let $coll_pad='euckr_korean_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='euckr_nopad_bin'; +let $coll_pad='euckr_bin'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_gb2312.test b/mysql-test/t/ctype_gb2312.test index 3ca6941705c..8f15f72fad5 100644 --- a/mysql-test/t/ctype_gb2312.test +++ b/mysql-test/t/ctype_gb2312.test @@ -160,3 +160,23 @@ let $ctype_unescape_combinations=selected; --echo # --echo # End of 10.0 tests --echo # + + +--echo # +--echo # Start of 10.2 tests +--echo # +--echo # +--echo # MDEV-9711 NO PAD Collatons +--echo # +SET character_set_connection=gb2312; +let $coll='gb2312_chinese_nopad_ci'; +let $coll_pad='gb2312_chinese_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='gb2312_nopad_bin'; +let $coll_pad='gb2312_bin'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_gbk.test b/mysql-test/t/ctype_gbk.test index 07e73cdf745..88bfda46748 100644 --- a/mysql-test/t/ctype_gbk.test +++ b/mysql-test/t/ctype_gbk.test @@ -435,3 +435,33 @@ SELECT HEX(CONVERT(CAST(0xA341 AS CHAR CHARACTER SET gb2312) USING utf8)); --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9811 LOAD DATA INFILE does not work well with gbk in some cases +--echo # +CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET gbk); +LOAD DATA INFILE '../../std_data/loaddata/mdev8711.txt' INTO TABLE t1 CHARACTER SET gbk LINES TERMINATED BY '@'; +SELECT HEX(a) FROM t1; +DELETE FROM t1; +LOAD DATA INFILE '../../std_data/loaddata/mdev8711.txt' INTO TABLE t1 CHARACTER SET gbk LINES TERMINATED BY '@' IGNORE 1 LINES; +SELECT HEX(a) FROM t1; +DROP TABLE t1; +--echo # +--echo # MDEV-9711 NO PAD Collatons +--echo # +SET character_set_connection=gbk; +let $coll='gbk_chinese_nopad_ci'; +let $coll_pad='gbk_chinese_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='gbk_nopad_bin'; +let $coll_pad='gbk_bin'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_gbk_export_import.test b/mysql-test/t/ctype_gbk_export_import.test new file mode 100644 index 00000000000..02d18fe60d4 --- /dev/null +++ b/mysql-test/t/ctype_gbk_export_import.test @@ -0,0 +1,161 @@ +--source include/not_windows.inc +--source include/have_case_sensitive_file_system.inc +--source include/have_gbk.inc + +# +# Check if we're running on a POSIX-locale machine +# + +--disable_query_log +--exec locale -a > $MYSQLTEST_VARDIR/tmp/locale_a_gbk.output 2>/dev/null || true +SET @file=REPLACE(LOAD_FILE('../../tmp/locale_a_gbk.output'), '-', ''); +# Note, file content must be case sensitive. See mysql_locale_posix.test +--remove_file $MYSQLTEST_VARDIR/tmp/locale_a_gbk.output +if (`SELECT (IFNULL(@file,'') NOT LIKE '%\nzh_CN.gbk\n%')`) +{ + Skip Need POSIX locale zh_CN.gbk; +} +--enable_query_log + + +--disable_warnings +DROP DATABASE IF EXISTS gbk; +--enable_warnings + +CREATE DATABASE gbk DEFAULT CHARACTER SET gbk; +USE gbk; + +CREATE TABLE t1 ( + id INT NOT NULL, + a1 TEXT NOT NULL, + a2 TEXT CHARACTER SET utf8 NOT NULL, + b1 BLOB NOT NULL, + eol TEXT NOT NULL); + +DELIMITER |; +CREATE PROCEDURE populate() +BEGIN + TRUNCATE TABLE t1; + INSERT INTO t1 SET id=1, a1=0xEE5C, a2=_gbk 0xEE5C, b1=0xEE5C, eol='$'; + INSERT INTO t1 SET id=2, a1=0xEE5C5C, a2=_gbk 0xEE5C5C, b1=0xEE5C5C, eol='$'; +END| + +CREATE FUNCTION cmt(id INT, field_name TEXT, field_value BLOB) + RETURNS TEXT CHARACTER SET utf8 +BEGIN + DECLARE comment TEXT CHARACTER SET utf8; + DECLARE expected_value_01 BLOB; + DECLARE expected_value_02 BLOB; + SET comment= CASE field_name WHEN 'a1' THEN 'TEXT-GBK' WHEN 'a2' THEN 'TEXT-UTF8' WHEN 'b1' THEN 'BLOB' ELSE '' END; + SET expected_value_01= CASE field_name WHEN 'a1' THEN 0xEE5C WHEN 'a2' THEN 0xE9A0AB WHEN 'b1' THEN 0xEE5C ELSE '' END; + SET expected_value_02= CASE field_name WHEN 'a1' THEN 0xEE5C5C WHEN 'a2' THEN 0xE9A0AB5C WHEN 'b1' THEN 0xEE5C5C ELSE '' END; + RETURN IF(CASE id + WHEN 1 THEN expected_value_01 + WHEN 2 THEN expected_value_02 + ELSE '' + END <> field_value, + CONCAT('BAD-', comment), ''); +END| + +CREATE FUNCTION display_file(file BLOB) RETURNS TEXT CHARACTER SET utf8 +BEGIN + SET file=REPLACE(file, 0x09, '----'); + SET file=REPLACE(file, 0x0A, '++++'); + RETURN REPLACE(REPLACE(HEX(file), '2D2D2D2D','-'), '2B2B2B2B','|'); +END| + +DELIMITER ;| + +CREATE VIEW v1 AS +SELECT + id, + CONCAT(RPAD(HEX(a1),50,' '), cmt(id, 'a1', a1)) AS a1, + CONCAT(RPAD(HEX(a2),50,' '), cmt(id, 'a2', a2)) AS a2, + CONCAT(RPAD(HEX(b1),50,' '), cmt(id, 'b1', b1)) AS b1, + CONCAT(RPAD(HEX(eol),50,' '), IF(eol<>'$','BAD-EOL','')) AS eol, + '---' AS `---` +FROM t1; +SHOW CREATE TABLE t1; + +--echo # +--echo # Dump using SELECT INTO OUTFILE +--echo # + +--perl +my $dir= $ENV{'MYSQL_TMP_DIR'}; +open (my $FILE, '>', "$dir/tmpgbk.inc") or die "open(): $!"; +for $LOCALE ("zh_CN.gbk") { +for $DUMP_OPTIONS ("--default-character-set=auto", "--default-character-set=gbk","--default-character-set=utf8") { +for $DUMP_CHARSET_CLAUSE ("", "CHARACTER SET gbk", "CHARACTER SET utf8", "CHARACTER SET binary") { +for $RESTORE_OPTIONS ("--default-character-set=auto", "--default-character-set=gbk","--default-character-set=utf8") { +for $RESTORE_CHARSET_CLAUSE ("", "CHARACTER SET gbk", "CHARACTER SET utf8", "CHARACTER SET binary") { +print $FILE <<END +--echo Start of {$LOCALE}{$DUMP_OPTIONS $DUMP_CHARSET_CLAUSE}{$RESTORE_OPTIONS $RESTORE_CHARSET_CLAUSE} +--echo Locale: $LOCALE +--echo OUTFILE: $DUMP_OPTIONS $DUMP_CHARSET_CLAUSE +--echo INFILE: $RESTORE_OPTIONS $RESTORE_CHARSET_CLAUSE +--disable_query_log +CALL populate(); +--exec LC_ALL=$LOCALE \$MYSQL $DUMP_OPTIONS gbk -e "SELECT * INTO OUTFILE '\$MYSQLTEST_VARDIR/tmp/t1' $DUMP_CHARSET_CLAUSE FROM t1" +--vertical_results +TRUNCATE TABLE t1; +--eval SELECT display_file(LOAD_FILE('\$MYSQLTEST_VARDIR/tmp/t1')) AS file; +--exec LC_ALL=$LOCALE \$MYSQL $RESTORE_OPTIONS gbk -e "LOAD DATA INFILE '\$MYSQLTEST_VARDIR/tmp/t1' INTO TABLE t1 $RESTORE_CHARSET_CLAUSE" +SELECT * FROM v1; +--echo End of {$LOCALE}{$DUMP_OPTIONS $DUMP_CHARSET_CLAUSE}{$RESTORE_OPTIONS $RESTORE_CHARSET_CLAUSE} +--echo +--echo +--horizontal_results +--enable_query_log +--remove_file \$MYSQLTEST_VARDIR/tmp/t1 +END +}}}}} +close $FILE +EOF +--source $MYSQL_TMP_DIR/tmpgbk.inc +--remove_file $MYSQL_TMP_DIR/tmpgbk.inc + + +--echo # +--echo # Dump using mysqldump -Tdir +--echo # + +--exec mkdir $MYSQLTEST_VARDIR/tmp/tmpgbk +--perl +my $dir= $ENV{'MYSQL_TMP_DIR'}; +open (my $FILE, '>', "$dir/tmpgbk.inc") or die "open(): $!"; +for $LOCALE ("zh_CN.gbk") { +for $DUMP_OPTIONS ("--default-character-set=binary","--default-character-set=gbk","--default-character-set=utf8") { +for $RESTORE_OPTIONS ("--default-character-set=auto","--default-character-set=binary","--default-character-set=gbk","--default-character-set=utf8") { +for $RESTORE_CHARSET_CLAUSE ("", "CHARACTER SET gbk", "CHARACTER SET utf8", "CHARACTER SET binary") { +print $FILE <<END +--echo Start of {$LOCALE}{$DUMP_OPTIONS}{$RESTORE_OPTIONS $RESTORE_CHARSET_CLAUSE} +--echo Locale: $LOCALE +--echo mysqldump: $DUMP_OPTIONS +--echo INFILE: $RESTORE_OPTIONS $RESTORE_CHARSET_CLAUSE +--disable_query_log +CALL populate(); +--exec LC_ALL=$LOCALE \$MYSQL_DUMP $DUMP_OPTIONS -T\$MYSQLTEST_VARDIR/tmp/tmpgbk gbk t1 +--vertical_results +TRUNCATE TABLE t1; +--eval SELECT display_file(LOAD_FILE('\$MYSQLTEST_VARDIR/tmp/tmpgbk/t1.txt')) AS file; +--exec LC_ALL=$LOCALE \$MYSQL $RESTORE_OPTIONS gbk -e "LOAD DATA INFILE '\$MYSQLTEST_VARDIR/tmp/tmpgbk/t1.txt' INTO TABLE t1 $RESTORE_CHARSET_CLAUSE" +SELECT * FROM v1; +--echo End of {$LOCALE}{$DUMP_OPTIONS}{$RESTORE_OPTIONS $RESTORE_CHARSET_CLAUSE} +--echo +--echo +--horizontal_results +--enable_query_log +--remove_file \$MYSQLTEST_VARDIR/tmp/tmpgbk/t1.txt +--remove_file \$MYSQLTEST_VARDIR/tmp/tmpgbk/t1.sql +END +}}}} +close $FILE +EOF +--source $MYSQL_TMP_DIR/tmpgbk.inc +--remove_file $MYSQL_TMP_DIR/tmpgbk.inc +--rmdir $MYSQLTEST_VARDIR/tmp/tmpgbk + + +DROP DATABASE gbk; +USE test; diff --git a/mysql-test/t/ctype_latin1.test b/mysql-test/t/ctype_latin1.test index a30c7ae9a5d..78d5f819f57 100644 --- a/mysql-test/t/ctype_latin1.test +++ b/mysql-test/t/ctype_latin1.test @@ -87,9 +87,11 @@ SET collation_connection='latin1_swedish_ci'; -- source include/ctype_filesort.inc -- source include/ctype_like_escape.inc -- source include/ctype_str_to_date.inc +-- source include/ctype_pad_space.inc SET collation_connection='latin1_bin'; -- source include/ctype_filesort.inc -- source include/ctype_like_escape.inc +-- source include/ctype_pad_space.inc # # Bug#8041 @@ -376,3 +378,23 @@ DROP TABLE t1; --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9711 NO PAD Collatons +--echo # +SET character_set_connection=latin1; +let $coll='latin1_swedish_nopad_ci'; +let $coll_pad='latin1_swedish_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='latin1_nopad_bin'; +let $coll_pad='latin1_bin'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_ldml-master.opt b/mysql-test/t/ctype_ldml-master.opt index d7ecd9095cb..250dd2cb5a2 100644 --- a/mysql-test/t/ctype_ldml-master.opt +++ b/mysql-test/t/ctype_ldml-master.opt @@ -1,2 +1,2 @@ ---character-sets-dir=$MYSQL_TEST_DIR/std_data/ +--character-sets-dir=$MYSQL_TEST_DIR/std_data/ldml/ --log-error=$MYSQLTEST_VARDIR/tmp/ctype_ldml_log.err diff --git a/mysql-test/t/ctype_ldml.test b/mysql-test/t/ctype_ldml.test index 1ea8002a2eb..1d58daa89e4 100644 --- a/mysql-test/t/ctype_ldml.test +++ b/mysql-test/t/ctype_ldml.test @@ -409,3 +409,196 @@ INSERT INTO t1 VALUES (_ucs2 0x3400),(_ucs2 0x3560),(_ucs2 0x3561),(_ucs2 0x3600 INSERT INTO t1 VALUES (_ucs2 0x3700),(_ucs2 0x3701); SELECT HEX(CONVERT(a USING ucs2)) AS ch, HEX(WEIGHT_STRING(a)) AS w, HEX(WEIGHT_STRING(a COLLATE utf8_unicode_ci)) AS ducet FROM t1 ORDER BY a,ch; DROP TABLE t1; + + +--echo # +--echo # Testing that the MY_CS_PUREASCII flag is set properly +--echo # Comparison between ascii2 and latin1 should not give "illegal collation error" +--echo # +CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET ascii2, b VARCHAR(10) CHARACTER SET latin1); +INSERT INTO t1 VALUES ('a','a'),('b','b'); +SELECT * FROM t1 WHERE a=b; +ALTER TABLE t1 MODIFY a VARCHAR(10) CHARACTER SET ascii2 COLLATE ascii2_bin2; +SELECT * FROM t1 WHERE a=b; +ALTER TABLE t1 MODIFY a VARCHAR(10) CHARACTER SET ascii2 COLLATE ascii2_bin; +SELECT * FROM t1 WHERE a=b; +ALTER TABLE t1 MODIFY a VARCHAR(10) CHARACTER SET ascii2 COLLATE ascii2_general_inherited_ci; +SELECT * FROM t1 WHERE a=b; +ALTER TABLE t1 MODIFY a VARCHAR(10) CHARACTER SET ascii2 COLLATE ascii2_general_inherited2_ci; +SELECT * FROM t1 WHERE a=b; +DROP TABLE t1; + +--echo # +--echo # Testing that in case of two binary collations +--echo # "BINARY" in a column definition uses the collation with the least id +--echo # +CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET ascii2 BINARY); +INSERT INTO t1 VALUES ('test'); +SELECT COLLATION(a) FROM t1; +DROP TABLE t1; + + +--echo # +--echo # Testing mixing of two binary collations of the same character set +--echo # +CREATE TABLE t1 ( + a VARCHAR(10) CHARACTER SET ascii2 COLLATE ascii2_bin, + b VARCHAR(10) CHARACTER SET ascii2 COLLATE ascii2_bin2 +); +INSERT INTO t1 VALUES ('a','a'); +--error ER_CANT_AGGREGATE_2COLLATIONS +SELECT * FROM t1 WHERE a=b; +DROP TABLE t1; + +--echo # +--echo # Testing bad collation inheritance +--echo # +--error ER_UNKNOWN_COLLATION +CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET ascii2 COLLATE ascii2_badly_inherited_ci); + +--echo # +--echo # Testing that the MY_CS_CSSORT flag is set properly +--echo # +CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_test); +INSERT INTO t1 VALUES ('a'),('A'); +# should be case insensitive +SELECT * FROM t1 WHERE a RLIKE 'a'; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_test2_cs); +INSERT INTO t1 VALUES ('a'),('A'); + # should be case sensitive +SELECT * FROM t1 WHERE a RLIKE 'a'; +DROP TABLE t1; + +--echo # +--echo # MDEV-9711 NO PAD collations +--echo # +CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET ascii2 COLLATE ascii2_general_nopad_ci); +INSERT INTO t1 VALUES ('a'),('a '),('A'),('A '); +SELECT a, a='a', a='a ', HEX(a), LOWER(a), UPPER(a), CONVERT(a USING utf8) FROM t1; +ALTER TABLE t1 MODIFY a VARCHAR(10) CHARACTER SET ascii2 COLLATE ascii2_nopad_bin; +SELECT a, a='a', a='a ', HEX(a), LOWER(a), UPPER(a), CONVERT(a USING utf8) FROM t1; +ALTER TABLE t1 MODIFY a VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_swedish_nopad2_ci; +SELECT a, a='a', a='a ', HEX(a), LOWER(a), UPPER(a), CONVERT(a USING utf8) FROM t1; +DROP TABLE t1; + +--echo # +--echo # MDEV-10877 xxx_unicode_nopad_ci collations +--echo # +CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_test_520_nopad_ci); +INSERT INTO t1 VALUES ('a'),('b'),('a '),('b '); +SELECT + HEX(a), + WEIGHT_STRING(a)=WEIGHT_STRING(a COLLATE utf8mb4_unicode_ci) AS is_400, + WEIGHT_STRING(a)=WEIGHT_STRING(a COLLATE utf8mb4_unicode_520_ci) AS is_520 +FROM t1 +ORDER BY a; +SELECT COUNT(DISTINCT a) FROM t1; +SELECT HEX(a), REPLACE(a,' ','<SP>') FROM t1 WHERE a='a'; +SELECT HEX(a), REPLACE(a,' ','<SP>') FROM t1 ORDER BY a; +SELECT HEX(a), REPLACE(a,' ','<SP>') FROM t1 ORDER BY a DESC; +DROP TABLE t1; + + +SET NAMES utf8 COLLATE utf8_czech_test_w2; +CREATE TABLE t1 AS SELECT SPACE(10) AS c1 LIMIT 0; +--source include/ctype_unicode_latin.inc +INSERT INTO t1 VALUES ('a '); +SELECT c1, HEX(WEIGHT_STRING(c1 LEVEL 1)), HEX(WEIGHT_STRING(c1 LEVEL 2)) FROM t1 ORDER BY c1, BINARY c1; +SELECT c1, HEX(WEIGHT_STRING(c1 AS CHAR(3) LEVEL 1)), HEX(WEIGHT_STRING(c1 AS CHAR(3) LEVEL 2)) FROM t1 WHERE c1 BETWEEN 'a' AND 'aZ' ORDER BY c1, BINARY c1; +DROP TABLE t1; + +SELECT 'a' = 'a '; +SELECT 'a' < 'á'; +SELECT 'áa' < 'ab'; +SELECT 'á' < 'ä'; +SELECT 'äa' < 'áb'; +SELECT 'c' < 'Ä'; +SELECT 'cb' < 'Äa'; +SELECT 'd' < 'Ä'; +SELECT 'Äa' < 'db'; +SELECT 'e' < 'é'; +SELECT 'éa' < 'eb'; +SELECT 'é' < 'Ä›'; +SELECT 'Ä›a' < 'éb'; +SELECT 'i' < 'Ã'; +SELECT 'Ãa' < 'ib'; +SELECT 'n' < 'ň'; +SELECT 'ňa' < 'nb'; +SELECT 'o' < 'ó'; +SELECT 'óa' < 'ob'; +SELECT 'ó' < 'ö'; +SELECT 'öa' < 'ób'; +SELECT 'r' < 'Å™'; +SELECT 'rb' < 'Å™a'; +SELECT 's' < 'Å¡'; +SELECT 'sb' < 'Å¡a'; +SELECT 't' < 'Å¥'; +SELECT 'Å¥a' < 'tb'; +SELECT 'u' < 'ú'; +SELECT 'úa' < 'ub'; +SELECT 'ú' < 'ů'; +SELECT 'ůa' < 'úb'; +SELECT 'ů' < 'ü'; +SELECT 'üa' < 'ůb'; +SELECT 'y' < 'ý'; +SELECT 'ýa' < 'yb'; +SELECT 'z' < 'ž'; +SELECT 'zb' < 'ža'; +SELECT 'hž' < 'ch'; +SELECT 'chž'< 'i'; + + + +SET NAMES utf8 COLLATE utf8_czech_test_nopad_w2; +CREATE TABLE t1 AS SELECT SPACE(10) AS c1 LIMIT 0; +--source include/ctype_unicode_latin.inc +INSERT INTO t1 VALUES ('a '); +SELECT c1, HEX(WEIGHT_STRING(c1 LEVEL 1)), HEX(WEIGHT_STRING(c1 LEVEL 2)) FROM t1 ORDER BY c1, BINARY c1; +SELECT c1, HEX(WEIGHT_STRING(c1 AS CHAR(3) LEVEL 1)), HEX(WEIGHT_STRING(c1 AS CHAR(3) LEVEL 2)) FROM t1 WHERE c1 BETWEEN 'a' AND 'aZ' ORDER BY c1, BINARY c1; +DROP TABLE t1; + +SELECT 'a' = 'a '; +SELECT 'a' < 'á'; +SELECT 'áa' < 'ab'; +SELECT 'á' < 'ä'; +SELECT 'äa' < 'áb'; +SELECT 'c' < 'Ä'; +SELECT 'cb' < 'Äa'; +SELECT 'd' < 'Ä'; +SELECT 'Äa' < 'db'; +SELECT 'e' < 'é'; +SELECT 'éa' < 'eb'; +SELECT 'é' < 'Ä›'; +SELECT 'Ä›a' < 'éb'; +SELECT 'i' < 'Ã'; +SELECT 'Ãa' < 'ib'; +SELECT 'n' < 'ň'; +SELECT 'ňa' < 'nb'; +SELECT 'o' < 'ó'; +SELECT 'óa' < 'ob'; +SELECT 'ó' < 'ö'; +SELECT 'öa' < 'ób'; +SELECT 'r' < 'Å™'; +SELECT 'rb' < 'Å™a'; +SELECT 's' < 'Å¡'; +SELECT 'sb' < 'Å¡a'; +SELECT 't' < 'Å¥'; +SELECT 'Å¥a' < 'tb'; +SELECT 'u' < 'ú'; +SELECT 'úa' < 'ub'; +SELECT 'ú' < 'ů'; +SELECT 'ůa' < 'úb'; +SELECT 'ů' < 'ü'; +SELECT 'üa' < 'ůb'; +SELECT 'y' < 'ý'; +SELECT 'ýa' < 'yb'; +SELECT 'z' < 'ž'; +SELECT 'zb' < 'ža'; +SELECT 'hž' < 'ch'; +SELECT 'chž'< 'i'; + + +--error ER_UNKNOWN_COLLATION +SELECT 'a' COLLATE utf8_czech_test_bad_w2; diff --git a/mysql-test/t/ctype_like_range.test b/mysql-test/t/ctype_like_range.test index e9387e46eb4..e8784990d36 100644 --- a/mysql-test/t/ctype_like_range.test +++ b/mysql-test/t/ctype_like_range.test @@ -136,3 +136,24 @@ SELECT * FROM v1; DROP VIEW v1; DROP TABLE t1; + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-10134 Add full support for DEFAULT +--echo # +CREATE TABLE t1 ( + a VARCHAR(10), + mn VARCHAR(10) DEFAULT LIKE_RANGE_MIN(a,10), + mx VARCHAR(10) DEFAULT LIKE_RANGE_MAX(a,10) +); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('a'),('a_'),('a%'); +SELECT a, HEX(mn), HEX(mx) FROM t1; +DROP TABLE t1; + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_nopad_8bit.test b/mysql-test/t/ctype_nopad_8bit.test new file mode 100644 index 00000000000..fc60bbd7759 --- /dev/null +++ b/mysql-test/t/ctype_nopad_8bit.test @@ -0,0 +1,239 @@ +# +# Tests with the nopad 8 bit character sets +# + +--echo # +--echo # MDEV-9711 NO PAD Collatons +--echo # +SET character_set_connection=dec8; +let $coll='dec8_swedish_nopad_ci'; +let $coll_pad='dec8_swedish_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='dec8_nopad_bin'; +let $coll_pad='dec8_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=cp850; +let $coll='cp850_general_nopad_ci'; +let $coll_pad='cp850_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='cp850_nopad_bin'; +let $coll_pad='cp850_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=hp8; +let $coll='hp8_english_nopad_ci'; +let $coll_pad='hp8_english_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='hp8_nopad_bin'; +let $coll_pad='hp8_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=koi8r; +let $coll='koi8r_general_nopad_ci'; +let $coll_pad='koi8r_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='koi8r_nopad_bin'; +let $coll_pad='koi8r_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=latin2; +let $coll='latin2_general_nopad_ci'; +let $coll_pad='latin2_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='latin2_nopad_bin'; +let $coll_pad='latin2_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=swe7; +let $coll='swe7_swedish_nopad_ci'; +let $coll_pad='swe7_swedish_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='swe7_nopad_bin'; +let $coll_pad='swe7_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=ascii; +let $coll='ascii_general_nopad_ci'; +let $coll_pad='ascii_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='ascii_nopad_bin'; +let $coll_pad='ascii_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=hebrew; +let $coll='hebrew_general_nopad_ci'; +let $coll_pad='hebrew_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='hebrew_nopad_bin'; +let $coll_pad='hebrew_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=koi8u; +let $coll='koi8u_general_nopad_ci'; +let $coll_pad='koi8u_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='koi8u_nopad_bin'; +let $coll_pad='koi8u_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=greek; +let $coll='greek_general_nopad_ci'; +let $coll_pad='greek_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='greek_nopad_bin'; +let $coll_pad='greek_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=cp1250; +let $coll='cp1250_general_nopad_ci'; +let $coll_pad='cp1250_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='cp1250_nopad_bin'; +let $coll_pad='cp1250_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=cp1257; +let $coll='cp1257_general_nopad_ci'; +let $coll_pad='cp1257_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='cp1257_nopad_bin'; +let $coll_pad='cp1257_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=latin5; +let $coll='latin5_turkish_nopad_ci'; +let $coll_pad='latin5_turkish_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='latin5_nopad_bin'; +let $coll_pad='latin5_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=armscii8; +let $coll='armscii8_general_nopad_ci'; +let $coll_pad='armscii8_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='armscii8_nopad_bin'; +let $coll_pad='armscii8_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=cp866; +let $coll='cp866_general_nopad_ci'; +let $coll_pad='cp866_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='cp866_nopad_bin'; +let $coll_pad='cp866_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=keybcs2; +let $coll='keybcs2_general_nopad_ci'; +let $coll_pad='keybcs2_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='keybcs2_nopad_bin'; +let $coll_pad='keybcs2_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=macce; +let $coll='macce_general_nopad_ci'; +let $coll_pad='macce_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='macce_nopad_bin'; +let $coll_pad='macce_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=macroman; +let $coll='macroman_general_nopad_ci'; +let $coll_pad='macroman_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='macroman_nopad_bin'; +let $coll_pad='macroman_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=cp852; +let $coll='cp852_general_nopad_ci'; +let $coll_pad='cp852_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='cp852_nopad_bin'; +let $coll_pad='cp852_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=latin7; +let $coll='latin7_general_nopad_ci'; +let $coll_pad='latin7_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='latin7_nopad_bin'; +let $coll_pad='latin7_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=cp1251; +let $coll='cp1251_general_nopad_ci'; +let $coll_pad='cp1251_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='cp1251_nopad_bin'; +let $coll_pad='cp1251_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=cp1256; +let $coll='cp1256_general_nopad_ci'; +let $coll_pad='cp1256_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='cp1256_nopad_bin'; +let $coll_pad='cp1256_bin'; +--source include/ctype_pad_all_engines.inc + + +SET character_set_connection=geostd8; +let $coll='geostd8_general_nopad_ci'; +let $coll_pad='geostd8_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='geostd8_nopad_bin'; +let $coll_pad='geostd8_bin'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_sjis.test b/mysql-test/t/ctype_sjis.test index 2777cf6a035..a962f69003d 100644 --- a/mysql-test/t/ctype_sjis.test +++ b/mysql-test/t/ctype_sjis.test @@ -231,3 +231,32 @@ SET NAMES sjis; --echo # --echo # End of 10.0 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9842 LOAD DATA INFILE does not work well with a TEXT column when using sjis +--echo # +CREATE TABLE t1 (a TEXT CHARACTER SET sjis); +LOAD DATA INFILE '../../std_data/loaddata/mdev9842.txt' INTO TABLE t1 CHARACTER SET sjis; +SELECT HEX(a) FROM t1; +SELECT a=CONCAT('x', REPEAT(_sjis 0x835C, 200)) FROM t1; +DROP TABLE t1; + +--echo # +--echo # MDEV-9711 NO PAD Collatons +--echo # +SET character_set_connection=sjis; +let $coll='sjis_japanese_nopad_ci'; +let $coll_pad='sjis_japanese_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='sjis_nopad_bin'; +let $coll_pad='sjis_bin'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_swe7.test b/mysql-test/t/ctype_swe7.test index 7d1ef89b374..2e648a89406 100644 --- a/mysql-test/t/ctype_swe7.test +++ b/mysql-test/t/ctype_swe7.test @@ -17,3 +17,24 @@ let $ctype_unescape_combinations=selected; --echo # --echo # End of 10.0 tests --echo # + + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9711 NO PAD Collatons +--echo # +SET character_set_connection=swe7; +let $coll='swe7_swedish_nopad_ci'; +let $coll_pad='swe7_swedish_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='swe7_nopad_bin'; +let $coll_pad='swe7_bin'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_tis620.test b/mysql-test/t/ctype_tis620.test index ba5db9df54f..7bc248aec2b 100644 --- a/mysql-test/t/ctype_tis620.test +++ b/mysql-test/t/ctype_tis620.test @@ -178,15 +178,37 @@ set names tis620; set collation_connection=tis620_thai_ci; --source include/weight_string.inc --source include/weight_string_l1.inc +--source include/ctype_pad_space.inc select hex(weight_string(cast(0xE0A1 as char))); select hex(weight_string(cast(0xE0A1 as char) as char(1))); set collation_connection=tis620_bin; --source include/weight_string.inc --source include/weight_string_l1.inc +--source include/ctype_pad_space.inc select hex(weight_string(cast(0xE0A1 as char))); select hex(weight_string(cast(0xE0A1 as char) as char(1))); --echo # --echo # End of 5.6 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9711 NO PAD Collatons +--echo # +SET character_set_connection=tis620; +let $coll='tis620_thai_nopad_ci'; +let $coll_pad='tis620_thai_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='tis620_nopad_bin'; +let $coll_pad='tis620_bin'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_uca.test b/mysql-test/t/ctype_uca.test index 7406bafc5e6..15a945fde6d 100644 --- a/mysql-test/t/ctype_uca.test +++ b/mysql-test/t/ctype_uca.test @@ -656,3 +656,24 @@ SET collation_connection=ucs2_thai_520_w2; --echo # --echo # End of MariaDB-10.1 tests --echo # + + +--echo # +--echo # Start of MariaDB-10.2 tests +--echo # + +--echo # +--echo # MDEV-9407 Illegal mix of collation when using GROUP_CONCAT in a VIEW +--echo # +SET NAMES utf8; +CREATE TABLE t1 (col1 VARCHAR(12) CHARACTER SET utf8 COLLATE utf8_unicode_ci); +INSERT INTO t1 VALUES ('a'),('b'); +CREATE VIEW v1 AS SELECT group_concat('f') AS col1; +SELECT col1 FROM v1 UNION SELECT col1 FROM t1; +DROP VIEW v1; +DROP TABLE t1; + + +--echo # +--echo # End of MariaDB-10.2 tests +--echo # diff --git a/mysql-test/t/ctype_ucs.test b/mysql-test/t/ctype_ucs.test index c4794f143af..5b8c2f74528 100644 --- a/mysql-test/t/ctype_ucs.test +++ b/mysql-test/t/ctype_ucs.test @@ -965,3 +965,63 @@ SELECT CAST(CONVERT('1IJ3' USING ucs2) AS SIGNED); --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9711 NO PAD Collatons +--echo # +SET character_set_connection=ucs2; +let $coll='ucs2_general_nopad_ci'; +let $coll_pad='ucs2_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='ucs2_nopad_bin'; +let $coll_pad='ucs2_bin'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # MDEV-10585 EXECUTE IMMEDIATE statement +--echo # +SET character_set_connection=ucs2; +EXECUTE IMMEDIATE 'SELECT COLLATION("a")'; + +SET @stmt='SELECT COLLATION("a")'; +EXECUTE IMMEDIATE @stmt; + +--echo # +--echo # MDEV-10866 Extend PREPARE and EXECUTE IMMEDIATE to understand expressions +--echo # +SET NAMES utf8, collation_connection=ucs2_bin; +SET @stmt='SELECT COLLATION(''a'')'; +EXECUTE IMMEDIATE @stmt; + +SET NAMES utf8, character_set_connection=ucs2; +SET @stmt='SELECT COLLATION(''a'')'; +EXECUTE IMMEDIATE @stmt; + +EXECUTE IMMEDIATE CONCAT('SELECT ''a'' FROM DUAL'); + +SELECT HEX('aä') FROM DUAL; +EXECUTE IMMEDIATE 'SELECT HEX(''aä'') FROM DUAL'; +EXECUTE IMMEDIATE CONCAT('SELECT HEX(''aä'') FROM DUAL'); +EXECUTE IMMEDIATE CONCAT('SELECT HEX(''aä'') FROM ', 'DUAL'); +PREPARE stmt FROM 'SELECT HEX(''aä'') FROM DUAL'; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; + +SET @table='DUAL'; +SELECT HEX(@table); +EXECUTE IMMEDIATE CONCAT('SELECT HEX(''aä'') FROM ', @table); +EXECUTE IMMEDIATE CONCAT('SELECT HEX(''aä'') FROM ', CONVERT(@table USING utf8)); +SET @stmt='SELECT HEX(''aä'') FROM DUAL'; +EXECUTE IMMEDIATE @stmt; +PREPARE stmt FROM @stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_ucs2_uca.test b/mysql-test/t/ctype_ucs2_uca.test new file mode 100644 index 00000000000..bc6d6150ee6 --- /dev/null +++ b/mysql-test/t/ctype_ucs2_uca.test @@ -0,0 +1,21 @@ +-- source include/have_ucs2.inc + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-10877 xxx_unicode_nopad_ci collations +--echo # +SET NAMES utf8, character_set_connection=ucs2; +let $coll='ucs2_unicode_nopad_ci'; +let $coll_pad='ucs2_unicode_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='ucs2_unicode_520_nopad_ci'; +let $coll_pad='ucs2_unicode_520_ci'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_ujis.test b/mysql-test/t/ctype_ujis.test index 3f444580b13..17aa3850219 100644 --- a/mysql-test/t/ctype_ujis.test +++ b/mysql-test/t/ctype_ujis.test @@ -1396,3 +1396,32 @@ SELECT HEX(a) FROM t1 ORDER BY a;DROP TABLE t1; --echo # --echo # End of 10.1 tests --echo # + + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9842 LOAD DATA INFILE does not work well with a TEXT column when using sjis +--echo # +CREATE TABLE t1 (a TEXT CHARACTER SET ujis); +LOAD DATA INFILE '../../std_data/loaddata/mdev9823.ujis.txt' INTO TABLE t1 CHARACTER SET ujis IGNORE 4 LINES; +SELECT HEX(a) FROM t1; +DROP TABLE t1; + +--echo # +--echo # MDEV-9711 NO PAD Collatons +--echo # +SET character_set_connection=ujis; +let $coll='ujis_japanese_nopad_ci'; +let $coll_pad='ujis_japanese_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='ujis_nopad_bin'; +let $coll_pad='ujis_bin'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_utf16.test b/mysql-test/t/ctype_utf16.test index 4b95257cbde..c986309707e 100644 --- a/mysql-test/t/ctype_utf16.test +++ b/mysql-test/t/ctype_utf16.test @@ -904,3 +904,23 @@ SELECT CAST(CONVERT('1IJ3' USING utf16) AS SIGNED); --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9711 NO PAD Collatons +--echo # +SET character_set_connection=utf16; +let $coll='utf16_general_nopad_ci'; +let $coll_pad='utf16_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='utf16_nopad_bin'; +let $coll_pad='utf16_bin'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_utf16_uca.test b/mysql-test/t/ctype_utf16_uca.test index 160d5b19d12..95ce74076d0 100644 --- a/mysql-test/t/ctype_utf16_uca.test +++ b/mysql-test/t/ctype_utf16_uca.test @@ -221,3 +221,23 @@ SET collation_connection=utf16_thai_520_w2; --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-10877 xxx_unicode_nopad_ci collations +--echo # +SET NAMES utf8, character_set_connection=utf16; +let $coll='utf16_unicode_nopad_ci'; +let $coll_pad='utf16_unicode_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='utf16_unicode_520_nopad_ci'; +let $coll_pad='utf16_unicode_520_ci'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_utf16le.test b/mysql-test/t/ctype_utf16le.test index 42017f9a635..665443bb278 100644 --- a/mysql-test/t/ctype_utf16le.test +++ b/mysql-test/t/ctype_utf16le.test @@ -778,3 +778,23 @@ SELECT CAST(CONVERT('1IJ3' USING utf16le) AS SIGNED); --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9711 NO PAD Collatons +--echo # +SET character_set_connection=utf16le; +let $coll='utf16le_general_nopad_ci'; +let $coll_pad='utf16le_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='utf16le_nopad_bin'; +let $coll_pad='utf16le_bin'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_utf32.test b/mysql-test/t/ctype_utf32.test index 96e9ecdd805..f113f046d42 100644 --- a/mysql-test/t/ctype_utf32.test +++ b/mysql-test/t/ctype_utf32.test @@ -993,3 +993,23 @@ SELECT CAST(CONVERT('1IJ3' USING utf32) AS SIGNED); --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9711 NO PAD Collatons +--echo # +SET character_set_connection=utf32; +let $coll='utf32_general_nopad_ci'; +let $coll_pad='utf32_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='utf32_nopad_bin'; +let $coll_pad='utf32_bin'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_utf32_uca.test b/mysql-test/t/ctype_utf32_uca.test index fb691221db8..e5eb3b6d881 100644 --- a/mysql-test/t/ctype_utf32_uca.test +++ b/mysql-test/t/ctype_utf32_uca.test @@ -242,3 +242,24 @@ SET collation_connection=utf32_thai_520_w2; --echo # --echo # End of 10.1 tests --echo # + + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-10877 xxx_unicode_nopad_ci collations +--echo # +SET NAMES utf8, character_set_connection=utf32; +let $coll='utf32_unicode_nopad_ci'; +let $coll_pad='utf32_unicode_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='utf32_unicode_520_nopad_ci'; +let $coll_pad='utf32_unicode_520_ci'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index 5f1de609df1..0b0e5dc37b2 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -1987,3 +1987,104 @@ SET @@SQL_MODE=default; --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9824 LOAD DATA does not work with multi-byte strings in LINES TERMINATED BY when IGNORE is specified +--echo # +CREATE TABLE t1 (c1 VARCHAR(10) CHARACTER SET utf8); +LOAD DATA INFILE '../../std_data/loaddata/mdev9824.txt' INTO TABLE t1 CHARACTER SET utf8 LINES TERMINATED BY 'ёё'; +SELECT c1 FROM t1; +DELETE FROM t1; +LOAD DATA INFILE '../../std_data/loaddata/mdev9824.txt' INTO TABLE t1 CHARACTER SET utf8 LINES TERMINATED BY 'ёё' IGNORE 1 LINES; +SELECT c1 FROM t1; +DROP TABLE t1; + +--echo # +--echo # MDEV-9842 LOAD DATA INFILE does not work well with a TEXT column when using sjis +--echo # +CREATE TABLE t1 (a TEXT CHARACTER SET utf8); +LOAD DATA INFILE '../../std_data/loaddata/mdev9823.utf8mb4.txt' INTO TABLE t1 CHARACTER SET utf8 IGNORE 4 LINES; +SELECT HEX(a) FROM t1; +DROP TABLE t1; + +--echo # +--echo # MDEV-9874 LOAD XML INFILE does not handle well broken multi-byte characters +--echo # +CREATE TABLE t1 (a TEXT CHARACTER SET utf8); +LOAD XML INFILE '../../std_data/loaddata/mdev9874.xml' INTO TABLE t1 CHARACTER SET utf8 ROWS IDENTIFIED BY '<row>'; +SELECT HEX(a) FROM t1; +DROP TABLE t1; + +--echo # +--echo # MDEV-10134 Add full support for DEFAULT +--echo # + +# This test uses some magic codes: +# _latin1 0xC39F is "A WITH TILDE + Y WITH DIAERESIS" +# _utf8 0xC39F is "SHARP S" + +# "A WITH TILDE + Y WITH DIAERESIS" in DEFAULT. +SET NAMES latin1; +CREATE TABLE t1 (a VARCHAR(30) CHARACTER SET latin1 DEFAULT CONCAT('ß')); +SET NAMES utf8; +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT HEX(a),a FROM t1; +SET NAMES latin1; +ALTER TABLE t1 ADD b VARCHAR(30) CHARACTER SET latin1 DEFAULT CONCAT('ß'); +SET NAMES utf8; +ALTER TABLE t1 ADD c VARCHAR(30) CHARACTER SET latin1 DEFAULT CONCAT('ß'); +SHOW CREATE TABLE t1; +# Testing that DEFAULT is independent on the current "SET NAMES". +DELETE FROM t1; +INSERT INTO t1 VALUES(); +SELECT * FROM t1; +SET NAMES latin1; +DELETE FROM t1; +INSERT INTO t1 VALUES(); +SET NAMES utf8; +SELECT * FROM t1; +DROP TABLE t1; + +SET NAMES latin1; +CREATE TABLE t1 (a VARCHAR(30) CHARACTER SET utf8 DEFAULT CONCAT('ß')); +SET NAMES utf8; +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT HEX(a), a FROM t1; +DROP TABLE t1; + +# "SHARP S" in DEFAULT +SET NAMES utf8; +CREATE TABLE t1 (a VARCHAR(30) CHARACTER SET latin1 DEFAULT CONCAT('ß')); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT HEX(a) FROM t1; +DROP TABLE t1; + +SET NAMES utf8; +CREATE TABLE t1 (a VARCHAR(30) CHARACTER SET utf8 DEFAULT CONCAT('ß')); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT HEX(a) FROM t1; +DROP TABLE t1; + + +--echo # +--echo # MDEV-9711 NO PAD Collatons +--echo # +let $coll='utf8_general_nopad_ci'; +let $coll_pad='utf8_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='utf8_nopad_bin'; +let $coll_pad='utf8_bin'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_utf8_uca.test b/mysql-test/t/ctype_utf8_uca.test new file mode 100644 index 00000000000..670998a367b --- /dev/null +++ b/mysql-test/t/ctype_utf8_uca.test @@ -0,0 +1,20 @@ +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-10877 xxx_unicode_nopad_ci collations +--echo # +SET NAMES utf8; +let $coll='utf8_unicode_nopad_ci'; +let $coll_pad='utf8_unicode_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='utf8_unicode_520_nopad_ci'; +let $coll_pad='utf8_unicode_520_ci'; +--source include/ctype_pad_all_engines.inc + + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_utf8mb4.test b/mysql-test/t/ctype_utf8mb4.test index 060c2aa1afb..55aad5b1454 100644 --- a/mysql-test/t/ctype_utf8mb4.test +++ b/mysql-test/t/ctype_utf8mb4.test @@ -1943,3 +1943,46 @@ DROP FUNCTION f1; --echo # --echo # End of 10.1 tests --echo # + + +--echo # +--echo # End of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9842 LOAD DATA INFILE does not work well with a TEXT column when using sjis +--echo # +CREATE TABLE t1 (a TEXT CHARACTER SET utf8mb4); +LOAD DATA INFILE '../../std_data/loaddata/mdev9823.utf8mb4.txt' INTO TABLE t1 CHARACTER SET utf8mb4 IGNORE 4 LINES; +SELECT HEX(a) FROM t1; +DROP TABLE t1; + +--echo # +--echo # MDEV-9711 NO PAD Collatons +--echo # +let $coll='utf8mb4_general_nopad_ci'; +let $coll_pad='utf8mb4_general_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='utf8mb4_nopad_bin'; +let $coll_pad='utf8mb4_bin'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # MDEV-10867 PREPARE..EXECUTE is not consistent about non-ASCII characters +--echo # +SET NAMES utf8mb4; +SELECT '😎' AS c; + +SET @src='SELECT ''😎'' AS c'; +PREPARE stmt FROM @src; +EXECUTE stmt; +EXECUTE IMMEDIATE @src; + +PREPARE stmt FROM 'SELECT ''😎'' AS c'; +EXECUTE stmt; +EXECUTE IMMEDIATE 'SELECT ''😎'' AS c'; + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ctype_utf8mb4_innodb-master.opt b/mysql-test/t/ctype_utf8mb4_innodb-master.opt index 96f0ce3f36c..56d40323eae 100644 --- a/mysql-test/t/ctype_utf8mb4_innodb-master.opt +++ b/mysql-test/t/ctype_utf8mb4_innodb-master.opt @@ -1 +1,2 @@ --default-storage-engine=MyISAM +--loose-innodb-large-prefix=OFF diff --git a/mysql-test/t/ctype_utf8mb4_uca.test b/mysql-test/t/ctype_utf8mb4_uca.test index e56c6d7b884..fe76ed45e3f 100644 --- a/mysql-test/t/ctype_utf8mb4_uca.test +++ b/mysql-test/t/ctype_utf8mb4_uca.test @@ -83,3 +83,23 @@ SET collation_connection=utf8mb4_thai_520_w2; --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9711 NO PAD Collatons +--echo # +SET NAMES utf8mb4; +let $coll='utf8mb4_unicode_nopad_ci'; +let $coll_pad='utf8mb4_unicode_ci'; +--source include/ctype_pad_all_engines.inc + +let $coll='utf8mb4_unicode_520_nopad_ci'; +let $coll_pad='utf8mb4_unicode_520_ci'; +--source include/ctype_pad_all_engines.inc + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/ddl_i18n_koi8r.test b/mysql-test/t/ddl_i18n_koi8r.test index 0a62a8ba0f8..5e2417fab4d 100644 --- a/mysql-test/t/ddl_i18n_koi8r.test +++ b/mysql-test/t/ddl_i18n_koi8r.test @@ -116,8 +116,6 @@ ALTER DATABASE mysqltest1 COLLATE cp866_general_ci| # - Change connection to flush cache; --connect (con2,localhost,root,,) ---echo ---echo ---> connection: con2 # - Switch environment variables and trigger loading views; @@ -178,8 +176,6 @@ DROP DATABASE mysqltest1| # - Change connection to flush cache; --connect (con3,localhost,root,,) ---echo ---echo ---> connection: con3 # - Switch environment variables and trigger loading views; @@ -208,9 +204,6 @@ set names koi8r| # --connection default ---echo ---echo ---> connection: default - --disconnect con2 --disconnect con3 @@ -378,8 +371,6 @@ ALTER DATABASE mysqltest2 COLLATE cp866_general_ci| # - Change connection to flush SP-cache; --connect (con2,localhost,root,,mysqltest1) ---echo ---echo ---> connection: con2 # - Switch environment variables and trigger loading stored procedures; @@ -458,8 +449,6 @@ DROP DATABASE mysqltest2| # - Change connection to flush SP-cache; --connect (con3,localhost,root,,mysqltest1) ---echo ---echo ---> connection: con3 # - Switch environment variables and trigger loading stored procedures; @@ -485,9 +474,6 @@ set names koi8r| # --connection default ---echo ---echo ---> connection: default - --disconnect con2 --disconnect con3 @@ -654,8 +640,6 @@ ALTER TABLE mysqltest2.t1 DROP COLUMN fake| # (connect using NULL database); --connect (con2,localhost,root,,) ---echo ---echo ---> connection: con2 SET @@character_set_client= cp1251| SET @@character_set_results= cp1251| @@ -744,8 +728,6 @@ ALTER TABLE mysqltest2.t1 DROP COLUMN fake| # (connect using NULL database); --connect (con3,localhost,root,,) ---echo ---echo ---> connection: con3 SET @@character_set_client= cp1251| SET @@character_set_results= cp1251| @@ -772,9 +754,6 @@ use mysqltest1| # --connection default ---echo ---echo ---> connection: default - --disconnect con2 --disconnect con3 @@ -914,8 +893,6 @@ ALTER DATABASE mysqltest2 COLLATE cp866_general_ci| # - Change connection to flush cache; --connect (con2,localhost,root,,mysqltest1) ---echo ---echo ---> connection: con2 # - Switch environment variables and trigger loading stored procedures; @@ -996,8 +973,6 @@ DROP DATABASE mysqltest2| # - Change connection to flush cache; --connect (con3,localhost,root,,mysqltest1) ---echo ---echo ---> connection: con3 # - Switch environment variables and trigger loading stored procedures; @@ -1135,19 +1110,12 @@ SHOW CREATE TABLE mysqltest2.t2| delimiter ;| --connection con2 ---echo ---echo ---> connection: con2 --disconnect con2 --source include/wait_until_disconnected.inc --connection con3 ---echo ---echo ---> connection: con3 --disconnect con3 --source include/wait_until_disconnected.inc --connection default ---echo ---echo ---> connection: default USE test; DROP DATABASE mysqltest1; DROP DATABASE mysqltest2; - diff --git a/mysql-test/t/ddl_i18n_utf8.test b/mysql-test/t/ddl_i18n_utf8.test index 023047b952e..9fecad87515 100644 --- a/mysql-test/t/ddl_i18n_utf8.test +++ b/mysql-test/t/ddl_i18n_utf8.test @@ -116,8 +116,6 @@ ALTER DATABASE mysqltest1 COLLATE cp866_general_ci| # - Change connection to flush cache; --connect (con2,localhost,root,,) ---echo ---echo ---> connection: con2 # - Switch environment variables and trigger loading views; @@ -178,8 +176,6 @@ DROP DATABASE mysqltest1| # - Change connection to flush cache; --connect (con3,localhost,root,,) ---echo ---echo ---> connection: con3 # - Switch environment variables and trigger loading views; @@ -208,8 +204,6 @@ set names utf8| # --connection default ---echo ---echo ---> connection: default --disconnect con2 --disconnect con3 @@ -378,8 +372,6 @@ ALTER DATABASE mysqltest2 COLLATE cp866_general_ci| # - Change connection to flush SP-cache; --connect (con2,localhost,root,,mysqltest1) ---echo ---echo ---> connection: con2 # - Switch environment variables and trigger loading stored procedures; @@ -458,8 +450,6 @@ DROP DATABASE mysqltest2| # - Change connection to flush SP-cache; --connect (con3,localhost,root,,mysqltest1) ---echo ---echo ---> connection: con3 # - Switch environment variables and trigger loading stored procedures; @@ -485,8 +475,6 @@ set names utf8| # --connection default ---echo ---echo ---> connection: default --disconnect con2 --disconnect con3 @@ -654,8 +642,6 @@ ALTER TABLE mysqltest2.t1 DROP COLUMN fake| # (connect using NULL database); --connect (con2,localhost,root,,) ---echo ---echo ---> connection: con2 SET @@character_set_client= cp1251| SET @@character_set_results= cp1251| @@ -744,8 +730,6 @@ ALTER TABLE mysqltest2.t1 DROP COLUMN fake| # (connect using NULL database); --connect (con3,localhost,root,,) ---echo ---echo ---> connection: con3 SET @@character_set_client= cp1251| SET @@character_set_results= cp1251| @@ -772,8 +756,6 @@ use mysqltest1| # --connection default ---echo ---echo ---> connection: default --disconnect con2 --disconnect con3 @@ -914,8 +896,6 @@ ALTER DATABASE mysqltest2 COLLATE cp866_general_ci| # - Change connection to flush cache; --connect (con2,localhost,root,,mysqltest1) ---echo ---echo ---> connection: con2 # - Switch environment variables and trigger loading stored procedures; @@ -996,8 +976,6 @@ DROP DATABASE mysqltest2| # - Change connection to flush cache; --connect (con3,localhost,root,,mysqltest1) ---echo ---echo ---> connection: con3 # - Switch environment variables and trigger loading stored procedures; @@ -1135,19 +1113,12 @@ SHOW CREATE TABLE mysqltest2.t2| delimiter ;| --connection con2 ---echo ---echo ---> connection: con2 --disconnect con2 --source include/wait_until_disconnected.inc --connection con3 ---echo ---echo ---> connection: con3 --disconnect con3 --source include/wait_until_disconnected.inc --connection default ---echo ---echo ---> connection: default USE test; DROP DATABASE mysqltest1; DROP DATABASE mysqltest2; - diff --git a/mysql-test/t/debug_sync.test b/mysql-test/t/debug_sync.test index ebeeec61632..89414939f59 100644 --- a/mysql-test/t/debug_sync.test +++ b/mysql-test/t/debug_sync.test @@ -330,23 +330,19 @@ SHOW VARIABLES LIKE 'DEBUG_SYNC'; # CREATE USER mysqltest_1@localhost; GRANT SUPER ON *.* TO mysqltest_1@localhost; ---echo connection con1, mysqltest_1 connect (con1,localhost,mysqltest_1,,); SET DEBUG_SYNC= 'RESET'; disconnect con1; ---echo connection default connection default; DROP USER mysqltest_1@localhost; # CREATE USER mysqltest_2@localhost; GRANT ALL ON *.* TO mysqltest_2@localhost; REVOKE SUPER ON *.* FROM mysqltest_2@localhost; ---echo connection con1, mysqltest_2 connect (con1,localhost,mysqltest_2,,); --error ER_SPECIFIC_ACCESS_DENIED_ERROR SET DEBUG_SYNC= 'RESET'; disconnect con1; ---echo connection default connection default; DROP USER mysqltest_2@localhost; @@ -361,21 +357,17 @@ DROP TABLE IF EXISTS t1; # # Test. CREATE TABLE t1 (c1 INT); - --echo connection con1 connect (con1,localhost,root,,); SET DEBUG_SYNC= 'before_lock_tables_takes_lock SIGNAL opened WAIT_FOR flushed'; send INSERT INTO t1 VALUES(1); ---echo connection default connection default; SET DEBUG_SYNC= 'now WAIT_FOR opened'; SET DEBUG_SYNC= 'after_flush_unlock SIGNAL flushed'; FLUSH TABLE t1; - --echo connection con1 connection con1; reap; disconnect con1; ---echo connection default connection default; DROP TABLE t1; @@ -389,25 +381,40 @@ DROP TABLE IF EXISTS t1; --enable_warnings # # Test. -CREATE TABLE t1 (c1 INT); -LOCK TABLE t1 READ; - --echo connection con1 - connect (con1,localhost,root,,); - # Retain action after use. First used by general_log. - SET DEBUG_SYNC= 'wait_for_lock SIGNAL locked EXECUTE 2'; - send INSERT INTO t1 VALUES (1); ---echo connection default +CREATE TABLE t1 (c1 INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1); +SELECT GET_LOCK('mysqltest_lock', 100); + +connect (con1,localhost,root,,); +--echo # Sending: +--send UPDATE t1 SET c1=GET_LOCK('mysqltest_lock', 100); + +connect (con2,localhost,root,,); +let $wait_condition= + select count(*) = 1 from information_schema.processlist + where state = "User lock" and + info = "UPDATE t1 SET c1=GET_LOCK('mysqltest_lock', 100)"; +--source include/wait_condition.inc + +# Retain action after use. First used by general_log. +SET DEBUG_SYNC= 'wait_for_lock SIGNAL locked EXECUTE 2'; +send INSERT INTO t1 VALUES (1); + connection default; # Wait until INSERT waits for lock. SET DEBUG_SYNC= 'now WAIT_FOR locked'; -# let INSERT continue. -UNLOCK TABLES; - --echo connection con1 - connection con1; - --echo retrieve INSERT result. - reap; - disconnect con1; ---echo connection default +# let UPDATE continue. +SELECT RELEASE_LOCK('mysqltest_lock'); +connection con1; +--echo # Reaping UPDATE +reap; +SELECT RELEASE_LOCK('mysqltest_lock'); + +connection con2; +--echo retrieve INSERT result. +reap; +disconnect con1; +disconnect con2; connection default; DROP TABLE t1; diff --git a/mysql-test/t/default.test b/mysql-test/t/default.test index cf09ba048b8..9ae088405fa 100644 --- a/mysql-test/t/default.test +++ b/mysql-test/t/default.test @@ -166,7 +166,7 @@ select * from t1; drop table t1, t2; ---echo End of 5.0 tests. +--echo # End of 5.0 tests --echo # --echo # Start of 10.0 tests @@ -226,3 +226,1809 @@ DROP TABLE IF EXISTS t1; --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +SET timestamp=UNIX_TIMESTAMP('2001-01-01 10:20:30.123456'); + +--echo # +--echo # Check that CURRENT_TIMESTAMP works as before +--echo # + +CREATE or replace TABLE t1 (event_time TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP); +SHOW CREATE TABLE t1; + +CREATE or replace TABLE t1 (event_time TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(2) ON UPDATE CURRENT_TIMESTAMP); +SHOW CREATE TABLE t1; + +CREATE or replace TABLE t1 (event_time TIMESTAMP(6) NOT NULL DEFAULT SYSDATE(2) ON UPDATE CURRENT_TIMESTAMP); +SHOW CREATE TABLE t1; + +drop table t1; + +--echo # +--echo # Check default expressions +--echo # + +create or replace table t1 (a int default 1, b int default (a+1), c int default (a+b)) engine myisam; +show create table t1; +insert into t1 values (); +insert into t1 (a) values (2); +insert into t1 (a,b) values (10,20); +insert into t1 (a,b,c) values (100,200,400); +select * from t1; +truncate table t1; +insert delayed into t1 values (); +insert delayed into t1 (a) values (2); +insert delayed into t1 (a,b) values (10,20); +insert delayed into t1 (a,b,c) values (100,200,400); +flush tables t1; +select * from t1; + +create or replace table t1 (a int, b blob default (1), c blob default "hello", t text default concat(a,b,c)) engine=myisam; +show create table t1; +insert into t1 (a) values (2); +insert into t1 (a,b) values (10,"test1"); +insert into t1 (a,b,c) values (10,"test2","test3"); +insert delayed into t1 (a,b) values (10,"test4"); +flush tables t1; +select * from t1; +drop table t1; + +create or replace table t1 (a bigint default uuid_short()); +insert into t1 values(); +select a > 0 from t1; +drop table t1; + +create or replace table t1 (param_list int DEFAULT (1+1) NOT NULL); +--error ER_PARSE_ERROR +create or replace table t1 (param_list int DEFAULT 1+1 NOT NULL); +create or replace table t1 (param_list blob DEFAULT "" NOT NULL); + +drop table t1; + +create table t1 (a int); +insert into t1 values(-1); +alter table t1 add b int default 1, add c int default -1, add d int default (1+1), add e timestamp; +select a,b,c,d,e from t1; +insert into t1 values(10,10,10,10,0); +alter table t1 add f int default (1+1+1) null, add g int default (1+1+1+1) not null,add h int default (2+2+2+2); +select a,b,c,d,e,f,g,h from t1; +show create table t1; + +create table t2 like t1; +show create table t2; +insert into t2 (a) values (100); +select a,b,c,d,e,f,g,h from t2; +drop table t1,t2; + +create table t1 (a int default (1----1), b int default - 1, c int default +1, e int default (--1)); +show create table t1; +insert into t1 values(); +insert into t1 values(); +select * from t1; +drop table t1; + +--echo # +--echo # Create or replace can delete a table on error +--echo # +create table t1 (a int); +--error ER_EXPRESSION_REFERS_TO_UNINIT_FIELD +create or replace table t1 (a int default b, b int default a); +--error ER_NO_SUCH_TABLE +show create table t1; + +--echo # +--echo # Refering to other columns +--echo # + +create or replace table t1 (a int default 1, b int default a); +create or replace table t1 (a int default 1, b int as (a)); +create or replace table t1 (a int default b, b int default 1); +create or replace table t1 (a int as (b), b int default 1); +create or replace table t1 (a int as (b), b int default (1+1)); +create or replace table t1 (a int default 1, b int as (c), c int default (a+1)); +create or replace table t1 (a int default (1+1), b int as (c), c int default (a+1)); +create or replace table t1 (a varchar(128) default @@version); +create or replace table t1 (a int not null, b int as (a)); +create or replace table t1 (a int not null, b int default (a+1)); + + +--error ER_EXPRESSION_REFERS_TO_UNINIT_FIELD +create or replace table t1 (a int default a); +create or replace table t1 (a int default b, b int default (1+1)); +--error ER_EXPRESSION_REFERS_TO_UNINIT_FIELD +create or replace table t1 (a int default 1, b int as (c), c int as (a+1)); +--error ER_EXPRESSION_REFERS_TO_UNINIT_FIELD +CREATE TABLE t1 (a INT DEFAULT (DEFAULT(a))); +--error ER_EXPRESSION_REFERS_TO_UNINIT_FIELD +CREATE TABLE t1 (a INT DEFAULT(DEFAULT(b)), b INT DEFAULT(DEFAULT(a))); +--error ER_EXPRESSION_REFERS_TO_UNINIT_FIELD +CREATE TABLE t1 (a INT DEFAULT(DEFAULT(b)) NOT NULL, b INT DEFAULT(DEFAULT(a)) NOT NULL); + +--echo # +--echo # Allow defaults to refer to not default fields +--echo # + +create or replace table t1 (a int default b, b int not null); +insert into t1 values(); +insert into t1 (a) values(1); +insert into t1 (b) values(2); +insert into t1 (a,b) values(3,4); +select * from t1; +drop table t1; +CREATE OR REPLACE TABLE t1 (a INT DEFAULT @v); drop table t1; +CREATE TABLE t1 (a INT DEFAULT @v:=1); drop table t1; + +--echo # +--echo # Error handling +--echo # + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create or replace table t1 (a bigint default xxx()); +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create or replace table t1 (a bigint default (select (1))); +--error ER_OPERAND_COLUMNS +create or replace table t1 (a bigint default (1,2,3)); +--error ER_OPERAND_COLUMNS +create or replace table t1 (a bigint default ((1,2,3))); +--error ER_PARSE_ERROR +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a DIV b); +--error ER_PARSE_ERROR +CREATE TABLE t1 (a INT, b INT DEFAULT -a); + +--echo # +--echo # Invalid DEFAULT expressions +--echo # + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT ((SELECT 1))); + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT (EXISTS (SELECT 1))); + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT (1=ANY (SELECT 1))); + +--error ER_OPERAND_COLUMNS +CREATE TABLE t1 (a INT DEFAULT ROW(1,1)); + +--error ER_OPERAND_COLUMNS +CREATE TABLE t1 (a INT DEFAULT (1,1)); + +--error ER_OPERAND_COLUMNS +CREATE TABLE t1 (a INT DEFAULT ((1,1))); + +--error ER_PARSE_ERROR,2031 +CREATE TABLE t1 (a INT DEFAULT ?); +--error ER_PARSE_ERROR,2031 +CREATE TABLE t1 (a INT DEFAULT(?)); + +--error ER_EXPRESSION_REFERS_TO_UNINIT_FIELD +CREATE TABLE t1 (a INT DEFAULT (b), b INT DEFAULT(a)); + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT(NAME_CONST('xxx', 'yyy')); + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT COUNT(*)); + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT COUNT(1)); + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT AVG(1)); + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT MIN(1)); + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT GROUP_CONCAT(1)); + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT ROW_NUMBER() OVER ()); + +CREATE FUNCTION f1() RETURNS INT RETURN 1; +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT f1()); +DROP FUNCTION f1; + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE PROCEDURE p1(par INT) CREATE TABLE t1 (a INT DEFAULT par); + +--error ER_BAD_FIELD_ERROR +CREATE TABLE t1 (a INT DEFAULT par); + +CREATE PROCEDURE p1() CREATE TABLE t1 (a INT DEFAULT par); +--error ER_BAD_FIELD_ERROR +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); +# "Explicit or implicit commit is not allowed in stored function or trigger +# because the entire CREATE TABLE is actually not allowed in triggers! +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TRIGGER tr1 AFTER INSERT ON t1 FOR EACH ROW CREATE TABLE t2 (a INT DEFAULT NEW.a); +# This is OK to return Function or expression is not allowed for 'DEFAULT' +# because CREATE TEMPORARY TABLE is allowed in triggers +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TRIGGER tr1 AFTER INSERT ON t1 FOR EACH ROW CREATE TEMPORARY TABLE t2 (a INT DEFAULT NEW.a); +DROP TABLE t1; + +--echo # +--echo # Prepared statements +--echo # + +PREPARE stmt FROM 'CREATE TABLE t1 (a INT DEFAULT(?))'; +set @a=1; +execute stmt using @a; +show create table t1; +drop table t1; +set @a=-1; +execute stmt using @a; +show create table t1; +drop table t1; +DEALLOCATE PREPARE stmt; + +PREPARE stmt FROM 'CREATE TABLE t1 (a INT DEFAULT(?), b INT DEFAULT(?))'; +set @a=1, @b=2; +execute stmt using @a,@b; +show create table t1; +drop table t1; +DEALLOCATE PREPARE stmt; + +# +# We can't have an expression for prepared statements +# + +prepare stmt from 'create table t1 (a int default(?+?))'; +set @a=1; +execute stmt using @a,@a; +deallocate prepare stmt; +show create table t1; +drop table t1; + +--echo # +--echo # Parenthesized Item_basic_constant +--echo # + + +# It would be better if SHOW would display PI() rather than '3.141592653589793' +# The problem is that PI() is declared as a basic constant item and it +# could cause some problems changing it. + +CREATE TABLE t1 ( + i01 INT DEFAULT (((1))), + i02 INT DEFAULT (((0x3939))), + i03 INT DEFAULT (((1.0))), + i04 INT DEFAULT (((1e0))), + i05 INT DEFAULT (((NULL))), + + f01 DOUBLE DEFAULT (((PI()))), + + s01 VARCHAR(10) DEFAULT (((_latin1'test'))), + s02 VARCHAR(10) DEFAULT ((('test'))), + s03 VARCHAR(10) DEFAULT (((0x40))), + s04 VARCHAR(10) DEFAULT (((X'40'))), + s05 VARCHAR(10) DEFAULT (((B'1000000'))), + + d01 TIME DEFAULT (((TIME'10:20:30'))), + d02 DATE DEFAULT (((DATE'2001-01-01'))), + d03 DATETIME DEFAULT (((TIMESTAMP'2001-01-01 10:20:30'))) +); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (); +--vertical_results +SELECT * FROM t1; +--horizontal_results +DROP TABLE t1; + + +--echo # +--echo # COALESCE(Item_basic_constant) +--echo # + +# i02 INT DEFAULT 0x3939 -- gives 14649 (see the previous query), +# because it treats as a number +# i02 INT DEFAULT COALESCE(0x3939) -- gives 99, because it converts to string +# +# should be at least documented + +CREATE TABLE t1 ( + i01 INT DEFAULT COALESCE(1), + i02 INT DEFAULT COALESCE(0x3939), + i03 INT DEFAULT COALESCE(1.0), + i04 INT DEFAULT COALESCE(1e0), + i05 INT DEFAULT COALESCE(NULL), + + f01 DOUBLE DEFAULT COALESCE(PI()), + + s01 VARCHAR(10) DEFAULT COALESCE(_latin1'test'), + s02 VARCHAR(10) DEFAULT COALESCE('test'), + s03 VARCHAR(10) DEFAULT COALESCE(0x40), + s04 VARCHAR(10) DEFAULT COALESCE(X'40'), + s05 VARCHAR(10) DEFAULT COALESCE(B'1000000'), + + d01 TIME DEFAULT COALESCE(TIME'10:20:30'), + d02 DATE DEFAULT COALESCE(DATE'2001-01-01'), + d03 DATETIME DEFAULT COALESCE(TIMESTAMP'2001-01-01 10:20:30') +); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (); +--vertical_results +SELECT * FROM t1; +--horizontal_results +DROP TABLE t1; + + +--echo # +--echo # TINYINT: out of range +--echo # +--error ER_INVALID_DEFAULT +CREATE TABLE t1 (a TINYINT DEFAULT 300 NOT NULL); +--error ER_INVALID_DEFAULT +CREATE TABLE t1 (a TINYINT DEFAULT 128 NOT NULL); +--error ER_INVALID_DEFAULT +CREATE TABLE t1 (a TINYINT DEFAULT -500 NOT NULL); + +--echo # +--echo # INT: simple numeric expressions +--echo # +CREATE TABLE t1 (a INT DEFAULT 1 NOT NULL); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT DEFAULT COALESCE(1) NOT NULL); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # INT: simple string expressions +--echo # + +CREATE TABLE t1 (a INT DEFAULT '1' NOT NULL); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT DEFAULT CONCAT('1') NOT NULL); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT DEFAULT COALESCE('1') NOT NULL); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # INT: string expressions with garbage +--echo # +--error ER_INVALID_DEFAULT +CREATE TABLE t1 (a INT DEFAULT 'x'); +--error ER_INVALID_DEFAULT +CREATE TABLE t1 (a INT DEFAULT CONCAT('x')); +--error ER_INVALID_DEFAULT +CREATE TABLE t1 (a INT DEFAULT COALESCE('x')); +--error ER_INVALID_DEFAULT +CREATE TABLE t1 (a INT DEFAULT (((((COALESCE('x'))))))); + +--echo # +--echo # INT: string expressions with numbers + garbage +--echo # + +--error ER_INVALID_DEFAULT +CREATE TABLE t1 (a INT DEFAULT '1x'); +--error ER_INVALID_DEFAULT +CREATE TABLE t1 (a INT DEFAULT COALESCE('1x')); +--error ER_INVALID_DEFAULT +CREATE TABLE t1 (a INT DEFAULT CONCAT('1x')); + +--echo # +--echo # INT: string expressions with numbers + trailing space +--echo # + +CREATE TABLE t1 (a INT DEFAULT '1 '); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +# unlike constant, this preserve trailing spaces +# and sends a note on INSERT. Perhaps CREATE should be rejected +CREATE TABLE t1 (a INT DEFAULT CONCAT('1 ')); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +# unlike constant, this preserve trailing spaces +# and sends a note on INSERT +CREATE TABLE t1 (a INT DEFAULT COALESCE('1 ')); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # INT: a HEX value +--echo # +CREATE TABLE t1 (a INT DEFAULT 0x61 NOT NULL); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + + +--echo # +--echo # VARCHAR: good defaults +--echo # +CREATE TABLE t1 (a VARCHAR(30) DEFAULT 'xxx' NOT NULL); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(2) DEFAULT 0x41 NOT NULL); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(2) DEFAULT CONCAT(0x41) NOT NULL); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(2) DEFAULT COALESCE(0x41) NOT NULL); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(2) DEFAULT CONCAT(_utf8 0x41) NOT NULL); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(2) DEFAULT CONCAT(_utf8 X'41') NOT NULL); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + + +--echo # +--echo # VARCHAR: Too long default +--echo # +--error ER_INVALID_DEFAULT +CREATE TABLE t1 (a VARCHAR(2) DEFAULT 'xxx' NOT NULL); +--error ER_INVALID_DEFAULT +CREATE TABLE t1 (a VARCHAR(2) DEFAULT CONCAT('xxx') NOT NULL); + +--echo # +--echo # VARCHAR: Too long default with non-important data +--echo # +--error ER_INVALID_DEFAULT +CREATE TABLE t1 (a VARCHAR(2) DEFAULT 'xx ' NOT NULL); +--error ER_INVALID_DEFAULT +CREATE TABLE t1 (a VARCHAR(2) DEFAULT CONCAT('xx ') NOT NULL); + +--echo # +--echo # VARCHAR: conversion failures +--echo # + +# DEFAULT with a Cyrillic letter for a Latin1 column +--error ER_INVALID_DEFAULT +CREATE TABLE t1 (a VARCHAR(2) CHARACTER SET latin1 DEFAULT _utf8 X'D18F' NOT NULL); +--error ER_INVALID_DEFAULT +CREATE TABLE t1 (a VARCHAR(2) CHARACTER SET latin1 DEFAULT CONCAT(_utf8 X'D18F') NOT NULL); +--error ER_INVALID_DEFAULT +CREATE TABLE t1 (a VARCHAR(2) CHARACTER SET latin1 DEFAULT CONCAT(_utf8 0xD18F) NOT NULL); + +--echo # +--echo # Field as a default value +--echo # + +CREATE TABLE t1 (a INT, b INT DEFAULT (a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (1, 1); +INSERT INTO t1 VALUES (DEFAULT, DEFAULT); +INSERT INTO t1 VALUES (1, DEFAULT); +INSERT INTO t1 VALUES (DEFAULT, 1); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # Function DEFAULT(field) +--echo # + +CREATE TABLE t1 (a INT DEFAULT(DEFAULT(b)), b INT DEFAULT 1); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT DEFAULT 1, b INT DEFAULT(DEFAULT(a))); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # SQL Standard <datetime value function> as a <default option> +--echo # + +CREATE TABLE t1 (a DATETIME DEFAULT CURRENT_TIMESTAMP); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TIME DEFAULT CURRENT_TIME); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATE DEFAULT CURRENT_DATE); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo # +--echo # DECIMAL + CURRENT_TIMESTAMP, no truncation +--echo # +CREATE TABLE t1 (a DECIMAL(30,6) DEFAULT CURRENT_TIMESTAMP(6)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DECIMAL(30,6) DEFAULT COALESCE(CURRENT_TIMESTAMP(6))); +SHOW CREATE TABLE t1; +# Same as insert into t1 values ("2016-06-05 12:54:52.342095"); +INSERT INTO t1 VALUES(); +INSERT IGNORE INTO t1 VALUES(); +SET sql_mode = 'STRICT_ALL_TABLES'; +--error WARN_DATA_TRUNCATED +INSERT INTO t1 VALUES(); +SET sql_mode = DEFAULT; +DROP TABLE t1; + +--echo # +--echo # DECIMAL + CURRENT_TIME, no truncation +--echo # +CREATE TABLE t1 (a DECIMAL(30,6) DEFAULT COALESCE(CURRENT_TIME(6))); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES(); +DROP TABLE t1; + +--echo # +--echo # DECIMAL + CURRENT_DATE, no truncation +--echo # +CREATE TABLE t1 (a DECIMAL(30,6) DEFAULT COALESCE(CURRENT_DATE)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES(); +DROP TABLE t1; + + +--echo # +--echo # COALESCE for SQL Standard <datetime value function> +--echo # + +CREATE TABLE t1 (a TIMESTAMP DEFAULT COALESCE(CURRENT_TIMESTAMP)); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATE DEFAULT COALESCE(CURRENT_DATE)); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TIME DEFAULT COALESCE(CURRENT_TIME)); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + a TIMESTAMP DEFAULT CURRENT_TIMESTAMP(6), + b TIMESTAMP DEFAULT COALESCE(CURRENT_TIMESTAMP(6)) +); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (); +SELECT CURRENT_TIMESTAMP(6); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + a DECIMAL(30,0) DEFAULT CURRENT_TIMESTAMP(6), + b DECIMAL(30,0) DEFAULT COALESCE(CURRENT_TIMESTAMP(6)) +); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # Check DEFAULT() function +--echo # + +CREATE TABLE `t1` (`a` int(11) DEFAULT (3+3),`b` int(11) DEFAULT '1000'); +SHOW CREATE TABLE t1; +insert into t1 values (1,1),(2,2); +insert into t1 values (default,default); +select * from t1; +select default(a),b from t1; +select a,default(b) from t1; +drop table t1; + + +--echo # +--echo # Real functions +--echo # + +CREATE TABLE t1 (a DECIMAL(10,1), b DOUBLE DEFAULT CAST(a AS DOUBLE)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (10.1, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DOUBLE, b DOUBLE DEFAULT EXP(a), c DOUBLE DEFAULT LOG(b), d DOUBLE DEFAULT LOG(4, b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (2, DEFAULT, DEFAULT, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b DOUBLE DEFAULT LOG2(a), c DOUBLE DEFAULT LOG10(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (4, DEFAULT, DEFAULT); +INSERT INTO t1 VALUES (100, DEFAULT, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + + +CREATE TABLE t1 (a DOUBLE, b DOUBLE DEFAULT SQRT(a), c DOUBLE DEFAULT POW(a,3)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (4, DEFAULT, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DOUBLE, b DOUBLE DEFAULT ACOS(a), c DOUBLE DEFAULT ASIN(a), d DOUBLE DEFAULT ATAN(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (1, DEFAULT, DEFAULT, DEFAULT); +SELECT a, b/PI(), c/PI(), d/PI() FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DOUBLE, b DOUBLE DEFAULT COS(a), c DOUBLE DEFAULT SIN(a), d DOUBLE DEFAULT TAN(a), e DOUBLE DEFAULT COT(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (PI()/3); +SELECT ROUND(a,3), ROUND(b,3), ROUND(c,3), ROUND(d,3), ROUND(e,3) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DOUBLE DEFAULT RAND()); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT); +DROP TABLE t1; + +CREATE TABLE t1 (a DOUBLE, b DOUBLE DEFAULT DEGREES(a), c DOUBLE DEFAULT RADIANS(b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (PI(), DEFAULT, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # INT result functions +--echo # + +CREATE TABLE t1 (a INT, b INT DEFAULT INTERVAL(a, 10, 20, 30, 40)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (34); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a DIV b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a, b) VALUES (13, 3); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT DEFAULT SIGN(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (-10),(0), (10); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(30), b INT DEFAULT FIELD(a, 'Hej', 'ej', 'Heja', 'hej', 'foo')); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('ej'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(30), b INT DEFAULT FIND_IN_SET(a, 'Hej,ej,Heja,hej,foo')); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('ej'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(30), b INT DEFAULT ASCII(a), c INT DEFAULT ORD(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('a'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TEXT DEFAULT UUID_SHORT()); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (); +SELECT a>0 FROM t1; +DROP TABLE t1; + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT BENCHMARK(1,1)); + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT GET_LOCK('a',1)); + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT RELEASE_LOCK('a')); + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT IS_USED_LOCK('a')); + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT IS_FREE_LOCK('a')); + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT SLEEP(1)); + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT ROW_COUNT()); + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT FOUND_ROWS()); + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT MASTER_POS_WAIT('test',100)); + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT MASTER_GTID_WAIT('test')); + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a VARCHAR(30), b DOUBLE DEFAULT MATCH (a) AGAINST('bbbb' IN BOOLEAN MODE)); + +--echo # +--echo # Temporal functions +--echo # + +--echo # Item_temporal_hybrid_func + +CREATE TABLE t1 (a DATE, b INT, c DATE DEFAULT DATE_ADD(a, INTERVAL b DAY)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES ('2001-01-01', 30, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATE, b TIME, c DATETIME DEFAULT ADDTIME(a, b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES ('2001-01-01', '10:20:30', DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(32), b VARCHAR(32), c DATE DEFAULT STR_TO_DATE(a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES ('01,5,2013','%d,%m,%Y', DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # Item_datefunc + +SET time_zone='-10:00'; +SET timestamp=UNIX_TIMESTAMP('2001-01-01 23:59:59'); +CREATE TABLE t1 (a DATE DEFAULT CURDATE(), b DATE DEFAULT UTC_DATE()); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (); +SELECT * FROM t1; +DROP TABLE t1; +SET time_zone=DEFAULT, timestamp= DEFAULT; + +CREATE TABLE t1 (a INT, b DATE DEFAULT FROM_DAYS(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (730669, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATE, b DATE DEFAULT LAST_DAY(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES ('2003-02-05', DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (yy INT, yd INT, d DATE DEFAULT MAKEDATE(yy, yd)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (2011,32,DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # Item_timefunc + +SET time_zone='-10:00'; +SET timestamp=UNIX_TIMESTAMP('2001-01-01 23:59:59'); +CREATE TABLE t1 (a TIME DEFAULT CURTIME(), b TIME DEFAULT UTC_TIME()); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (); +SELECT * FROM t1; +DROP TABLE t1; +SET time_zone=DEFAULT, timestamp= DEFAULT; + +CREATE TABLE t1 (a INT, b TIME DEFAULT SEC_TO_TIME(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (2378, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATETIME, b DATETIME, c TIME DEFAULT TIMEDIFF(a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES ('2000:01:01 00:00:00', '2000:01:02 10:20:30', DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (hh INT, mm INT, ss INT, t TIME DEFAULT MAKETIME(hh,mm,ss)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (10,20,30,DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + + +--echo # Item_datetimefunc + +SET time_zone='-10:00'; +SET timestamp=UNIX_TIMESTAMP('2001-01-01 23:59:59'); +CREATE TABLE t1 (a TIMESTAMP DEFAULT NOW(), b TIMESTAMP DEFAULT UTC_TIMESTAMP()); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (); +SELECT * FROM t1; +DROP TABLE t1; +SET time_zone=DEFAULT, timestamp= DEFAULT; + +# SYSDATE is evaluated during get_date() rather than fix_fields. +CREATE TABLE t1 (a TIMESTAMP(6) DEFAULT SYSDATE(6), s INT, b TIMESTAMP(6) DEFAULT SYSDATE(6)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (DEFAULT, SLEEP(0.1), DEFAULT); +SELECT b>a FROM t1; +DROP TABLE t1; + +SET time_zone='+00:00'; +CREATE TABLE t1 (a INT, b TIMESTAMP DEFAULT FROM_UNIXTIME(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (1447430881, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; +SET time_zone=DEFAULT; + +CREATE TABLE t1 (a TIMESTAMP, b TIMESTAMP DEFAULT CONVERT_TZ(a, '-10:00', '+10:00')); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES ('2001-01-01 10:20:30', DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # Item_temporal_typecast +CREATE TABLE t1 (a INT, b DATE DEFAULT CAST(a AS DATE)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (20010203, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b TIME DEFAULT CAST(a AS TIME)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (102030, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a BIGINT, b DATETIME DEFAULT CAST(a AS DATETIME)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (20010203102030, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + + +--echo # +--echo # Functions with temporal input +--echo # + +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT PERIOD_ADD(a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES (200801, 2); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT PERIOD_DIFF(a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES (200802, 200703); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT DEFAULT TO_DAYS(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (950501); +SELECT * FROM t1; +DROP TABLE t1; +CREATE TABLE t1 (a DATE, b INT DEFAULT TO_DAYS(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('2007-10-07'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b BIGINT DEFAULT TO_SECONDS(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (950501); +SELECT * FROM t1; +DROP TABLE t1; +CREATE TABLE t1 (a DATE, b BIGINT DEFAULT TO_SECONDS(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('2009-11-29'); +SELECT * FROM t1; +DROP TABLE t1; +CREATE TABLE t1 (a DATETIME, b BIGINT DEFAULT TO_SECONDS(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('2009-11-29 13:43:32'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATE, b BIGINT DEFAULT DAYOFMONTH(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('2007-02-03'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATE, b BIGINT DEFAULT DAYOFWEEK(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('2007-02-03'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATE, b BIGINT DEFAULT DAYOFYEAR(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('2007-02-03'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TIME, b INT DEFAULT HOUR(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('10:05:03'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TIME, b INT DEFAULT MINUTE(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('10:05:03'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TIME, b INT DEFAULT SECOND(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('10:05:03'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATETIME(6), b INT DEFAULT MICROSECOND(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('2009-12-31 23:59:59.000010'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATE, b INT DEFAULT YEAR(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('1987-01-01'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATE, b INT DEFAULT MONTH(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('1987-01-01'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATE, b INT DEFAULT WEEK(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('1987-02-01'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATE, b INT DEFAULT YEARWEEK(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('2000-01-01'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATE, b INT DEFAULT QUARTER(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('2008-04-01'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATE, b INT DEFAULT EXTRACT(YEAR FROM a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('2009-07-02'); +SELECT * FROM t1; +DROP TABLE t1; +CREATE TABLE t1 (a DATETIME, b INT DEFAULT EXTRACT(YEAR_MONTH FROM a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('2009-07-02 01:02:03'); +SELECT * FROM t1; +DROP TABLE t1; +CREATE TABLE t1 (a DATETIME, b INT DEFAULT EXTRACT(DAY_MINUTE FROM a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('2009-07-02 01:02:03'); +SELECT * FROM t1; +DROP TABLE t1; +CREATE TABLE t1 (a DATETIME(6), b INT DEFAULT EXTRACT(MICROSECOND FROM a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('2009-07-02 01:02:03.000123'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATE, b DATE, c INT DEFAULT TIMESTAMPDIFF(MONTH,a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES ('2003-02-01','2003-05-01'); +SELECT * FROM t1; +DROP TABLE t1; +CREATE TABLE t1 (a DATE, b DATE, c INT DEFAULT TIMESTAMPDIFF(YEAR,a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES ('2002-05-01','2001-01-01'); +SELECT * FROM t1; +DROP TABLE t1; +CREATE TABLE t1 (a DATE, b DATETIME, c INT DEFAULT TIMESTAMPDIFF(MINUTE,a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES ('2003-02-01','2003-05-01 12:05:55'); +SELECT * FROM t1; +DROP TABLE t1; + + +--echo # +--echo # Hybrid type functions +--echo # + +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT COALESCE(a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (NULL, 1, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + + +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT IFNULL(a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (NULL, 2, DEFAULT); +INSERT INTO t1 VALUES (1, 2, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + + +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT NULLIF(a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (1, 1, DEFAULT); +INSERT INTO t1 VALUES (1, 2, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT IF(a,b,2)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (0, 1, DEFAULT); +INSERT INTO t1 VALUES (1, 1, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT CASE WHEN a THEN b ELSE 2 END); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (0, 1, DEFAULT); +INSERT INTO t1 VALUES (1, 1, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT DEFAULT (-a)); +SHOW CREATE TABLE t1; +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (10, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT DEFAULT ABS(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (-10, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DOUBLE, b INT DEFAULT CEILING(a), c INT DEFAULT FLOOR(a), d INT DEFAULT ROUND(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (1.5, DEFAULT, DEFAULT, DEFAULT); +INSERT INTO t1 VALUES (-1.5, DEFAULT, DEFAULT, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a+b), d INT DEFAULT (a-b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (2, 1, DEFAULT, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a*b), d INT DEFAULT (a/b), e INT DEFAULT (a MOD b)); +SHOW CREATE TABLE t1; +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (7, 3, DEFAULT, DEFAULT, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +SET time_zone='+00:00'; +CREATE TABLE t1 (a DATETIME, b INT DEFAULT UNIX_TIMESTAMP(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES ('2001-01-01 10:20:30', DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; +SET time_zone=DEFAULT; + +CREATE TABLE t1 (a TIME, b INT DEFAULT TIME_TO_SEC(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES ('22:23:00', DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT LEAST(a,b), d INT DEFAULT GREATEST(a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (0, 1, DEFAULT, DEFAULT); +INSERT INTO t1 VALUES (1, 1, DEFAULT, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT LAST_VALUE(a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (1, 2, DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # CAST +--echo # +CREATE TABLE t1 (a VARCHAR(30), b DECIMAL(10,6) DEFAULT CAST(a AS DECIMAL(10,1))); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('123.456'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DECIMAL(10,3), + b VARCHAR(10) DEFAULT CAST(a AS CHAR(10)), + c VARCHAR(10) DEFAULT CAST(a AS CHAR(4))); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (123.456); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT UNSIGNED DEFAULT CAST(a AS UNSIGNED)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (-1); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a BIGINT UNSIGNED, b BIGINT SIGNED DEFAULT CAST(a AS SIGNED)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (0xFFFFFFFFFFFFFFFF); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + a VARCHAR(10) CHARACTER SET latin1, + b VARCHAR(10) CHARACTER SET latin1 DEFAULT a COLLATE latin1_bin, + c VARCHAR(10) CHARACTER SET utf8 DEFAULT CONVERT(a USING utf8), + d VARBINARY(10) DEFAULT (BINARY(a)) +); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('a'); +SELECT * FROM t1; +DROP TABLE t1; + + +--echo # +--echo # Bit functions +--echo # + +CREATE TABLE t1 (a INT, b INT DEFAULT BIT_COUNT(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (7); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a|b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES (1,2); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a&b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES (5,4); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a^b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES (11,3); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a&~b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES (5,1); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT, c INT DEFAULT (a<<b), d INT DEFAULT (a>>b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES (5,1); +SELECT * FROM t1; +DROP TABLE t1; + + +--echo # +--echo # String functions +--echo # + +CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(20) DEFAULT REVERSE(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('abcd'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10) DEFAULT UPPER(a), c VARCHAR(10) DEFAULT LOWER(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('ABcd'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10) DEFAULT LEFT(a,1), c VARCHAR(10) DEFAULT RIGHT(a,1), d VARCHAR(10) DEFAULT SUBSTR(a,2,2)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('abcd'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(20), b VARCHAR(20) DEFAULT SUBSTRING_INDEX(a,'.',2)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('www.mariadb.org'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10), c VARCHAR(20) DEFAULT CONCAT(a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES ('a','b'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10), c VARCHAR(20) DEFAULT CONCAT_WS(',',a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES ('a','b'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10) DEFAULT REPLACE(a,'a','A')); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('abc'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10) DEFAULT REGEXP_REPLACE(a,'[0-9]','.')); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('a1b2c'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10) DEFAULT REGEXP_SUBSTR(a,'[0-9]+')); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('ab12cd'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(20), b VARCHAR(20) DEFAULT SOUNDEX(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('tester'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(20), b VARCHAR(20) DEFAULT QUOTE(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('a\'b'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10) DEFAULT LPAD(a,10,'.'), c VARCHAR(10) DEFAULT RPAD(a,10,'.')); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('ab'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10) DEFAULT LTRIM(a), c VARCHAR(10) DEFAULT RTRIM(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (' ab '); +SELECT a, HEX(b), HEX(c) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10) DEFAULT TRIM(BOTH 'a' FROM a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('abba'); +SELECT a, b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b VARCHAR(10) DEFAULT SPACE(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (3); +SELECT a, HEX(b) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b VARCHAR(10), c VARCHAR(10) DEFAULT REPEAT(b,a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES (3,'x'); +SELECT a, b, c FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (str VARCHAR(10), pos INT, len INT, newstr VARCHAR(10), result VARCHAR(10) DEFAULT INSERT(str,pos,len,newstr)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (str,pos,len,newstr) VALUES ('Quadratic', 3, 4, 'What'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (n INT, res VARCHAR(10) DEFAULT ELT(n,'ej', 'Heja', 'hej', 'foo')); +SHOW CREATE TABLE t1; +INSERT INTO t1 (n) VALUES (1); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (bits INT, res VARCHAR(10) DEFAULT MAKE_SET(bits,'a','b','c','d')); +SHOW CREATE TABLE t1; +INSERT INTO t1 (bits) VALUES (1|4); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b VARCHAR(10) DEFAULT CHAR(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (77); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b VARCHAR(10) DEFAULT CONV(a,10,16)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (64); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT, c VARCHAR(30) DEFAULT FORMAT(a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES (10000,3); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT, l VARCHAR(10), c VARCHAR(30) DEFAULT FORMAT(a,b,l)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b,l) VALUES (10000,2,'no_NO'),(10000,2,'ru_RU'),(10000,2,'ar_BH'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(20) DEFAULT GET_FORMAT(DATE,a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('EUR'),('USA'),('JIS'),('ISO'),('INTERNAL'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + bits INT, + v_on VARCHAR(10), + v_off VARCHAR(10), + v_separator VARCHAR(10), + number_of_bits INT, + x VARCHAR(30) DEFAULT EXPORT_SET(bits, v_on, v_off, v_separator, number_of_bits) +); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (0x50006,'Y','N','',64,DEFAULT); +SELECT * FROM t1; +DROP TABLE t1; + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a VARCHAR(30), b BLOB DEFAULT LOAD_FILE(a)); + +--echo # +--echo # Predicates +--echo # + +CREATE TABLE t1 (a INT, b INT DEFAULT (NOT a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (NULL),(0),(1); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT, x INT DEFAULT (a XOR b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES (0,0),(0,1),(1,0),(1,1); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT DEFAULT (a IS TRUE), c INT DEFAULT (a IS NOT TRUE)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (NULL),(0),(1); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT DEFAULT (a IS FALSE), c INT DEFAULT (a IS NOT FALSE)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (NULL),(0),(1); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT DEFAULT (a IS NULL), c INT DEFAULT (a IS NOT NULL)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (NULL),(0),(1); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT DEFAULT (a IS UNKNOWN), c INT DEFAULT (a IS NOT UNKNOWN)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (NULL),(0),(1); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, + eq INT DEFAULT (a=0), equal INT DEFAULT (a<=>0), + ne INT DEFAULT (a<>0), + lt INT DEFAULT (a<0), le INT DEFAULT (a<=0), + gt INT DEFAULT (a>0), ge INT DEFAULT (a>=0)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (NULL),(-1),(0),(1); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT (a LIKE 'a%')); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('AAA'),('aaa'),('bbb'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT (a RLIKE 'a$')); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('AAA'),('aaa'),('bbb'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT (a IN ('aaa','bbb'))); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('AAA'),('aaa'),('bbb'),('ccc'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT (a NOT IN ('aaa','bbb'))); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('AAA'),('aaa'),('bbb'),('ccc'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT (a BETWEEN 'aaa' AND 'bbb')); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('AAA'),('aaa'),('bbb'),('ccc'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT (a NOT BETWEEN 'aaa' AND 'bbb')); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('AAA'),('aaa'),('bbb'),('ccc'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TEXT DEFAULT UUID()); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (); +SELECT LENGTH(a)>0 FROM t1; +DROP TABLE t1; + +--echo # +--echo # Numeric result functions with string input +--echo # + +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT STRCMP(a,'b')); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('A'),('a'),('B'),('b'),('C'),('c'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT LENGTH(a), c INT DEFAULT CHAR_LENGTH(a), d INT DEFAULT BIT_LENGTH(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('a'),('aa'),('aaa'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT LOCATE('a',a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('xa'),('xxa'),('xxxa'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT REGEXP_INSTR(a, 'a')); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('xa'),('xxa'),('xxxa'); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # INT result metadata functions +--echo # + +# QQ: LAST_INSERT_ID() should probably be allowed +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 +( + id SERIAL PRIMARY KEY, + b INT DEFAULT LAST_INSERT_ID() +); + +CREATE TABLE t1 (a INT DEFAULT CONNECTION_ID()); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES(); +SELECT a>0 FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b INT DEFAULT COERCIBILITY(a), c INT DEFAULT COERCIBILITY(b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('test'); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # String result metadata functions +--echo # +CREATE TABLE t1 ( + a VARCHAR(10) CHARACTER SET latin1, + b VARCHAR(20) DEFAULT CHARSET(a), + c VARCHAR(20) DEFAULT COLLATION(a) +); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('test'); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # Hash, compression, encode/decode +--echo # +CREATE TABLE t1 (a VARCHAR(10), b BIGINT DEFAULT CRC32(a), c TEXT DEFAULT MD5(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('a'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b TEXT DEFAULT TO_BASE64(a), c TEXT DEFAULT FROM_BASE64(b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('aaaabbbb'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b TEXT DEFAULT HEX(a), c TEXT DEFAULT UNHEX(b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('aaaabbbb'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(10), b TEXT DEFAULT ENCODE(a,'test'), c TEXT DEFAULT DECODE(b,'test')); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('aaaabbbb'); +SELECT a, HEX(b), c FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(30), b TEXT DEFAULT PASSWORD(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('notagoodpwd'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + a VARCHAR(30), + b BLOB DEFAULT AES_ENCRYPT(a, 'passwd'), + c TEXT DEFAULT AES_DECRYPT(b, 'passwd') +); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('test'); +SELECT c FROM t1; +DROP TABLE t1; + +--echo # +--echo # Collations +--echo # + +--error ER_BAD_DATA +CREATE TABLE t1 (a VARCHAR(20) CHARACTER SET latin1 DEFAULT CONCAT('ö')) CHARACTER SET koi8r COLLATE koi8r_bin; +CREATE OR REPLACE TABLE t1 (a char(2) default concat('A') COLLATE utf8mb4_unicode_ci); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +# +# Order of evaluation: +# +create table t1 (a int default 1, b int default (rand()*0+2), c int); +insert t1 (c) values (a); +insert t1 (c) values (b); +select * from t1; +drop table t1; + +# +# ALTER ... SET DEFAULT +# +create table t1 (a int default 1, b int default (1+1), c int); +show create table t1; +alter table t1 alter a set default (2+3), alter b set default 4, + alter c set default (-a); +--error ER_PARSE_ERROR +alter table t1 alter a set default 1+2; +show create table t1; +drop table t1; + +# +# CREATE ... SELECT +# +create table t1 (a int default 5 check (a>10), b int default (5+5), c int as (a+b)); +create table t2 as select a, b, c from t1; +create table t3 as select max(a), max(b), max(c) from t1; +show create table t2; +show create table t3; +drop table t1, t2, t3; + +--echo # MDEV-11359: Implement IGNORE for bulk operation +create table t1 (a int primary key default 0, b int default 3); +insert into t1 values (1, ignore); +insert into t1 values (2, ignore); +replace into t1 values (2, ignore); +replace into t1 values (3, ignore); +replace into t1 values (4, 6); +replace into t1 values (5, 7); +update t1 set a=6,b=ignore where a=5; +insert into t1 values (ignore, ignore); +--error ER_DUP_ENTRY +insert into t1 values (ignore, ignore); +select * from t1 order by a; +delete from t1 where a < 4; +--echo # actually insert default instead of ignoring +--echo # (but REPLACE is non standard operator) +replace into t1 values (4, ignore); +select * from t1 order by a; +drop table t1; + +#using in load +create table t1 (a int default 100, b int, c varchar(60) default 'x'); +load data infile '../../std_data/rpl_loaddata.dat' into table t1 (a, @b) set b=@b+10, c=ignore; +select * from t1; +drop table t1; + +#using in duplicate +CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY AUTO_INCREMENT); +CREATE TABLE t2 (a INT); +INSERT INTO t2 VALUES (1),(2),(3),(2); +INSERT INTO t1 SELECT a FROM t2 ON DUPLICATE KEY UPDATE a=DEFAULT; +SELECT * FROM t1 order by a; +truncate table t1; +# efectively it is DEFALT +INSERT INTO t1 SELECT a FROM t2 ON DUPLICATE KEY UPDATE a=IGNORE; +SELECT * FROM t1 order by a; +DROP TABLE t1,t2; + +create table t1 (a int primary key default 0, b int default 3); +prepare insstmt from "insert into t1 values (?, ?)"; +prepare repstmt from "replace into t1 values (?, ?)"; +prepare updstmt from "update t1 set a=6,b=? where a=5"; +execute insstmt using 1, ignore; +execute insstmt using 2, ignore; +execute repstmt using 2, ignore; +execute repstmt using 3, ignore; +execute repstmt using 4, 6; +execute repstmt using 5, 7; +execute updstmt using ignore; +execute insstmt using ignore, ignore; +--error ER_DUP_ENTRY +execute insstmt using ignore, ignore; +select * from t1 order by a; +delete from t1 where a < 4; +execute repstmt using 4, ignore; +select * from t1 order by a; +drop table t1; + +--echo # +--echo # DEVAULT & PS adoption +--echo # + + +# Correct usage +CREATE TABLE t1 (a INT DEFAULT 10, b INT DEFAULT NULL); +EXECUTE IMMEDIATE 'INSERT INTO t1 VALUES (?,?)' USING IGNORE, IGNORE; +SELECT * FROM t1; +UPDATE t1 SET a=20, b=30; +SELECT * FROM t1; +EXECUTE IMMEDIATE 'UPDATE t1 SET a=?,b=?' USING IGNORE, IGNORE; +SELECT * FROM t1; +DROP TABLE t1; + +# Incorrect usage in a expression in INSERT..VALUES +CREATE TABLE t1 (a INT DEFAULT 10); +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'INSERT INTO t1 VALUES (?+1)' USING IGNORE; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'INSERT INTO t1 VALUES (CONCAT(?,?))' USING IGNORE, 'test'; +DROP TABLE t1; + +# Incorrect usage in UPDATE..SET +CREATE TABLE t1 (a INT DEFAULT 10); +INSERT INTO t1 VALUES (20); +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'UPDATE t1 SET a=?+1' USING IGNORE; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'UPDATE t1 SET a=CONCAT(?,?)' USING IGNORE, 'test'; +DROP TABLE t1; + + +# Incorrect usage in not an UPDATE/INSERT query at all +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT CAST(? AS SIGNED)' USING IGNORE; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT CAST(? AS DOUBLE)' USING IGNORE; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT CAST(? AS CHAR)' USING IGNORE; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT CAST(? AS DECIMAL(10,1))' USING IGNORE; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT CAST(? AS TIME)' USING IGNORE; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT CAST(? AS DATE)' USING IGNORE; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT CAST(? AS DATETIME)' USING IGNORE; + +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT ?+1' USING IGNORE; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT CONCAT(?,?)' USING IGNORE,'test'; + + +# Incorrect usage in the LIMIT clause +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT 1 LIMIT ?' USING IGNORE; +CREATE TABLE t1 (a INT DEFAULT 10); +INSERT INTO t1 VALUES (1),(2),(3); +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT * FROM t1 LIMIT ?' USING IGNORE; +DROP TABLE t1; + + +--echo # The output of this query in 'Note' is a syntactically incorrect query. +--echo # But as it's never logged, it's ok. It should be human readable only. +EXECUTE IMMEDIATE 'EXPLAIN EXTENDED SELECT ?' USING IGNORE; + + +# This tests Item_param::eq() for IGNORE as a bound value +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2),(3); +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'EXPLAIN EXTENDED SELECT * FROM t1 WHERE ?+a<=>?+a' USING DEFAULT,DEFAULT; +DROP TABLE t1; + + +--echo # end of 10.2 test + +# +# ANSI_QUOTES +# +set sql_mode=ansi_quotes; +create table t1 (a int, b int default (a+1)); +show create table t1; +insert t1 (a) values (10); +set sql_mode=''; +show create table t1; +insert t1 (a) values (20); +flush tables; +show create table t1; +insert t1 (a) values (30); +select * from t1; +drop table t1; +set sql_mode=default; + diff --git a/mysql-test/t/default_session.test b/mysql-test/t/default_session.test new file mode 100644 index 00000000000..7796354ffd4 --- /dev/null +++ b/mysql-test/t/default_session.test @@ -0,0 +1,82 @@ +# +# DEFAULT clause with functions that depend on the current session state +# + +source include/not_embedded.inc; + +create database mysqltest1; + +create user ''@localhost; +create user foo@localhost; +create role bar; +grant select on *.* to ''@localhost; +grant select,insert on *.* to foo@localhost; +grant select,insert on *.* to bar; +grant bar to ''@localhost; + +create table t1 (n varchar(100), + u varchar(100) default user(), + cu varchar(100) default current_user(), + cr varchar(100) default current_role(), + d varchar(100) default database()); + +create definer=foo@localhost view mysqltest1.v1 as select * from t1; +create definer=bar view v2 as select * from t1; +create view v3 as select * from v2; + +create definer=foo@localhost view mysqltest1.v4 as select default(n),default(u),default(cu),default(cr), default(d) from t1; +create definer=bar view v5 as select default(n),default(u),default(cu),default(cr), default(d) from t1; +create view v6 as select * from v5; + +insert t1 (n) values ('t1'); +insert mysqltest1.v1 (n) values ('v1'); +insert v2 (n) values ('v2'); +insert v3 (n) values ('v3'); + +select default(n),default(u),default(cu),default(cr), default(d) from t1 limit 1; +select * from mysqltest1.v4 limit 1; +select * from v5 limit 1; +select * from v6 limit 1; + +connect (conn,localhost,conn,,mysqltest1); +set role bar; +insert test.t1 (n) values ('t1'); +insert v1 (n) values ('v1'); +insert test.v2 (n) values ('v2'); +insert test.v3 (n) values ('v3'); + +select default(n),default(u),default(cu),default(cr), default(d) from test.t1 limit 1; +select * from v4 limit 1; +select * from test.v5 limit 1; +select * from test.v6 limit 1; +connection default; +disconnect conn; + +select * from t1; +drop database mysqltest1; +drop view v2, v3, v5, v6; +drop table t1; +drop user ''@localhost; +drop user foo@localhost; +drop role bar; + +create table t1 (a date, + mn varchar(100) default monthname(a), + dn varchar(100) default dayname(a), + df varchar(100) default date_format(a, "%a, %b")); + +insert t1 (a) values ('2010-12-2'); +set lc_time_names=de_DE; +insert t1 (a) values ('2010-12-2'); +set lc_time_names=default; + +select * from t1; +drop table t1; + +create table t1 (a varchar(100) default @@sql_mode); +insert t1 () values (); +set sql_mode=ansi; +insert t1 () values (); +set sql_mode=default; +select * from t1; +drop table t1; diff --git a/mysql-test/t/delayed.test b/mysql-test/t/delayed.test index 644cbfbe6ce..dea16c84a51 100644 --- a/mysql-test/t/delayed.test +++ b/mysql-test/t/delayed.test @@ -322,7 +322,6 @@ insert into t1 values (1,1); lock table t1 read; connect (update,localhost,root,,); connection update; ---echo connection: update --send insert delayed into t1 values (2,2); connection default; let $wait_condition= @@ -330,10 +329,8 @@ let $wait_condition= where command = "Delayed insert" and state = "Waiting for table level lock"; --source include/wait_condition.inc connect (select,localhost,root,,); ---echo connection: select select * from t1; connection default; ---echo connection: default select * from t1; connection default; disconnect update; @@ -428,17 +425,14 @@ CREATE TABLE t3 (a INT); --echo # Test 1: Using LOCK TABLE ---echo # Connection con1 connect (con1, localhost, root); LOCK TABLE t1 WRITE; ---echo # Connection default connection default; LOCK TABLE t2 WRITE; --echo # Sending: --send INSERT DELAYED INTO t1 VALUES (1) ---echo # Connection con1 connection con1; --echo # Wait until INSERT DELAYED is blocked on table 't1'. let $wait_condition= @@ -450,7 +444,6 @@ let $wait_condition= INSERT DELAYED INTO t2 VALUES (1); UNLOCK TABLES; ---echo # Connection default connection default; --echo # Reaping: INSERT DELAYED INTO t1 VALUES (1) --reap @@ -461,12 +454,10 @@ UNLOCK TABLES; START TRANSACTION; SELECT * FROM t1 WHERE a=0; ---echo # Connection con1 connection con1; --echo # Sending: --send ALTER TABLE t1 MODIFY a INT UNSIGNED; ---echo # Connection default connection default; --echo # Wait until ALTER TABLE is blocked on table 't1'. let $wait_condition= @@ -478,24 +469,20 @@ let $wait_condition= INSERT DELAYED INTO t1 VALUES (3); COMMIT; ---echo # Connection con1 connection con1; --echo # Reaping: ALTER TABLE t1 COMMENT 'test' --reap --echo # Test 3: Using RENAME TABLE ---echo # Connection default connection default; START TRANSACTION; INSERT INTO t2 VALUES (1); ---echo # Connection con1 connection con1; --echo # Sending: --send RENAME TABLE t1 to t5, t2 to t4 ---echo # Connection default connection default; --echo # Wait until RENAME TABLE is blocked on table 't1'. let $wait_condition= @@ -507,12 +494,10 @@ let $wait_condition= INSERT DELAYED INTO t1 VALUES (4); COMMIT; ---echo # Connection con1 connection con1; --echo # Reaping: RENAME TABLE t1 to t5, t2 to t4 --reap ---echo # Connection default connection default; --echo # Reverting the renames RENAME TABLE t5 to t1, t4 to t2; @@ -522,11 +507,9 @@ RENAME TABLE t5 to t1, t4 to t2; START TRANSACTION; INSERT INTO t2 VALUES (1); ---echo # Connection con2 connect (con2, localhost, root); --send LOCK TABLE t1 WRITE, t2 WRITE ---echo # Connection con1 connection con1; --echo # Wait until LOCK TABLE is blocked on table 't2'. let $wait_condition= @@ -536,7 +519,6 @@ let $wait_condition= --source include/wait_condition.inc --send INSERT DELAYED INTO t1 VALUES (5) ---echo # Connection default connection default; --echo # Wait until INSERT DELAYED is blocked on table 't1'. let $wait_condition= @@ -548,18 +530,15 @@ let $wait_condition= INSERT DELAYED INTO t1 VALUES (6); COMMIT; ---echo # Connection con2 connection con2; --echo # Reaping: LOCK TABLE t1 WRITE, t2 WRITE --reap UNLOCK TABLES; ---echo # Connection con1 connection con1; --echo # Reaping: INSERT DELAYED INTO t1 VALUES (5) --reap ---echo # Connection default connection default; --echo # Test 5: LOCK TABLES + INSERT DELAYED in one connection. @@ -574,16 +553,13 @@ INSERT DELAYED INTO t2 VALUES (8); UNLOCK TABLES; SET AUTOCOMMIT= 1; ---echo # Connection con2 connection con2; disconnect con2; --source include/wait_until_disconnected.inc ---echo # Connection con1 connection con1; disconnect con1; --source include/wait_until_disconnected.inc ---echo # Connection default connection default; DROP TABLE t1, t2, t3; --enable_ps_protocol @@ -603,12 +579,10 @@ create table tm(a int) engine=merge union=(t1, t2); begin; select * from t1; ---echo # Connection 'con1'. connection con1; --echo # Sending: --send alter table t1 comment 'test' ---echo # Connection 'default'. connection default; --echo # Wait until ALTER TABLE blocks and starts waiting --echo # for connection 'default'. It should wait with a @@ -626,14 +600,12 @@ insert delayed into tm values (1); --echo # Unblock ALTER TABLE. commit; ---echo # Connection 'con1'. connection con1; --echo # Reaping ALTER TABLE: --reap disconnect con1; --source include/wait_until_disconnected.inc ---echo # Connection 'default'. connection default; drop tables tm, t1, t2; diff --git a/mysql-test/t/derived_cond_pushdown.test b/mysql-test/t/derived_cond_pushdown.test new file mode 100644 index 00000000000..e43751472db --- /dev/null +++ b/mysql-test/t/derived_cond_pushdown.test @@ -0,0 +1,1321 @@ +let $no_pushdown= set statement optimizer_switch='condition_pushdown_for_derived=off' for; + +create table t1 (a int, b int, c int); +create table t2 (a int, b int, c int, d decimal); +insert into t1 values + (1,21,345), (1,33,7), (8,33,114), (1,21,500), (1,19,107), (5,14,787), + (8,33,123), (9,10,211), (5,16,207), (1,33,988), (5,27,132), (1,21,104), + (6,20,309), (6,20,315), (1,21,101), (8,33,404), (9,10,800), (1,21,123), + (7,11,708), (6,20,214); +insert into t2 values + (2,3,207,207.0000), (1,21,909,12.0000), (7,13,312,406.0000), + (8,64,248,107.0000), (6,20,315,279.3333), (1,19,203,107.0000), + (8,80,800,314.0000), (3,12,231,190.0000), (6,23,303,909.0000); + +create table t1_double(a int, b double, c double); +insert into t1_double values + (1,23.4,14.3333), (1,12.5,18.9), (3,12.5,18.9), + (4,33.4,14.3333), (4,14.3333,13.65), (5,17.89,7.22), + (6,33.4,14.3), (10,33.4,13.65), (11,33.4,13.65); + +create table t2_double(a int, b double, c double); +insert into t2_double values + (1,22.4,14.3333), (1,12.5,18.9), (2,22.4,18.9), + (4,33.4,14.3333), (5,22.4,13.65), (7,17.89,18.9), + (6,33.4,14.3333), (10,31.4,13.65), (12,33.4,13.65); + +create table t1_char(a char, b char(8), c int); +insert into t1_char values + ('a','Ivan',1), ('b','Vika',2), ('b','Inga',6), ('c','Vika',7), + ('b','Ivan',7), ('a','Alex',6), ('b','Inga',5), ('d','Ron',9), + ('d','Harry',2), ('d','Hermione',3), ('c','Ivan',3), ('c','Harry',4); + +create table t2_char(a char, b char(8), c int); +insert into t2_char values + ('b','Ivan',1), ('c','Vinny',3), ('c','Inga',9), ('a','Vika',1), + ('c','Ivan',2), ('b','Ali',6), ('c','Inga',2), ('a','Ron',9), + ('d','Harry',1), ('b','Hermes',3), ('b','Ivan',11), ('b','Harry',4); + +create table t1_decimal (a decimal(3,1), b decimal(3,1), c int); +insert into t1_decimal values + (1,1,23),(2,2,11),(3,3,16), + (1,1,12),(1,1,14),(2,3,15), + (2,1,13),(2,3,11),(3,3,16); + +create table t2_decimal (a decimal(3,1), b decimal(3,1), c int); +insert into t2_decimal values + (2,1,13),(2,2,11),(3,3,16), + (1,3,22),(1,3,14),(2,2,15), + (2,1,43),(2,3,11),(2,3,16); + +create view v1 as select a, b, max(c) as max_c, avg(c) as avg_c from t1 + group by a,b having max_c < 707; + +create view v2 as select a, b, max(c) as max_c, avg(c) as avg_c from t1 + where t1.a>5 group by a,b having max_c < 707; + +create view v3 as select a, b, min(c) as min_c from t1 + where t1.a<10 group by a,b having min_c > 109; + +create view v4 as + select a, b, min(max_c) as min_c from v1 + where (v1.a<15) group by a,b; + +create view v_union as + select a, b, min(c) as c from t1 + where t1.a<10 group by a,b having c > 109 + union + select a, b, max(c) as c from t1 + where t1.b>10 group by a,b having c < 300; + +create view v2_union as + select a, b, min(c) as c from t1 + where t1.a<10 group by a,b having c > 109 + union + select a, b, max(c) as c from t1 + where t1.b>10 group by a,b having c < 300 + union + select a, b, avg(c) as c from t1 + where t1.c>300 group by a,b having c < 707; + +create view v3_union as + select a, b, (a+1) as c from t1 + where t1.a<10 + union + select a, b, c from t1 + where t1.b>10 and t1.c>100; + +create view v4_union as + select a, b, max(c)-100 as c from t1 + where t1.a<10 group by a,b having c > 109 + union + select a, b, (c+100) as c from t1 + where t1.b>10; + +create view v_double as + select a, avg(a/4) as avg_a, b, c from t1_double + where (b>12.2) group by b,c having (avg_a<22.333); + +create view v_char as + select a, b, max(c) as max_c from t1_char + group by a,b having max_c < 9; + +create view v_decimal as + select a, b, avg(c) as avg_c from t1_decimal + group by a,b having (avg_c>12); + +--echo # conjunctive subformula : pushing into HAVING +let $query= select * from v1,t2 where (v1.max_c>214) and (t2.a>v1.a); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= + select * from + (select a, b, max(c) as max_c, avg(c) as avg_c from t1 + group by a,b having max_c < 707) v1, + t2 where (v1.a=t2.a) and (v1.max_c>300); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # extracted or formula : pushing into HAVING +let $query= + select * from v1,t2 where + ((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a)); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= + select * from v1,t2 where + ((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or + ((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a)); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # conjunctive subformula : pushing into WHERE +let $query= select * from v1,t2 where (v1.a>6) and (t2.b>v1.b); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= select * from v2,t2 where (v2.b>25) and (t2.a<v2.a); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # extracted or formula : pushing into WHERE +let $query= + select * from v1,t2 where + ((v1.a>7) and (t2.c<v1.max_c)) or ((v1.a<2) and (t2.b<v1.b)); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= + select * from v2,t2 where + ((v2.a>7) and (t2.c<v2.max_c)) or ((v2.a>5) and (t2.b<v2.b)); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= + select * from v1,t2 where + ((v1.a>4) and (v1.b>t2.b) and (v1.max_c=t2.d)) or + ((v1.a<2) and (v1.max_c<t2.c) and (v1.max_c=t2.d)); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # conjunctive subformulas : pushing into HAVING and WHERE +let $query= + select * from v1,t2 where (v1.a<2) and (v1.max_c>400) and (t2.b>v1.b); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= + select * from v_double as v,t2_double as t where + (v.a=t.a) and (v.avg_a>0.45) and (v.b>10); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= + select * from v_decimal as v,t2_decimal as t where + (v.a=t.a) and (v.avg_c>15) and (v.b>1); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # extracted or formula : pushing into HAVING and WHERE +let $query= + select * from v1,t2 where + ((v1.a>7) and (v1.max_c>300) and (t2.c<v1.max_c)) or + ((v1.a<4) and (v1.max_c<500) and (t2.b<v1.b)); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= + select * from v1,t2 where ((v1.a<2) and (v1.max_c>120)) or (v1.a>7); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # extracted or formulas : pushing into WHERE and HAVING +let $query= + select * from v1,t2 where + ((v1.a<2) and (v1.max_c>120) and (v1.b=t2.b)) or (v1.a>7); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= + select * from v1,t2 where + ((v1.a<2) and (v1.max_c<200) and (t2.c>v1.max_c) and (v1.max_c=t2.d)) or + ((v1.a>4) and (v1.max_c<500) and (t2.b<v1.b) and (v1.max_c=t2.c)); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # prepare of a query containing extracted or formula +prepare stmt from "select * from v1,t2 where + ((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));"; +execute stmt; +execute stmt; +deallocate prepare stmt; +prepare stmt from + "explain format=json select * from v1,t2 where + ((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));"; +execute stmt; +execute stmt; +deallocate prepare stmt; + +--echo # conjunctive subformula : pushing into WHERE +--echo # pushing equalities +let $query= + select * from v1,t2 where (t2.a=v1.a) and (v1.b=t2.b) and (v1.a=1); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= select * from v1,t2 where (v1.a=5) and (v1.max_c=t2.d); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # conjunctive subformula : pushing into WHERE using equalities +let $query= select * from v1,t2 where (t2.a<5) and (v1.a=t2.a); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= + select * from v1,t2 where (v1.a=v1.b) and (v1.a=t2.a); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # conjunctive subformula : pushing into HAVING using equalities +let $query= select * from v1,t2 where (t2.c>150) and (v1.max_c=t2.c); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # extracted and formula : pushing into WHERE +--echo # pushing equalities +let $query= + select * from v1,t2 where (v1.a=v1.b) and (v1.a=t2.a) and (v1.a=3); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= + select * from v1,t2 where (v1.a=1) and (v1.b=21) and (t2.a=2); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= + select * from v_char as v,t2_char as t where + (v.a='c') and (v.b<'Hermes') and ((v.b=t.b) or (v.max_c>20)); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # extracted and formula : pushing into WHERE using equalities +--echo # pushing equalities +let $query= +select * from v_decimal as v,t2_decimal as t where + (v.a=v.b) and (v.b=t.b) and ((t.b>1) or (v.a=1)); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # extracted or formula : pushing into HAVING using equalities +let $query= + select * from v1,t2 + where ((t2.a<4) and (v1.a=t2.a)) or ((t2.c>150) and (v1.max_c=t2.c)); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # conjunctive subformulas : pushing into WHERE and HAVING using equalities +let $query= + select * from v1,t2 + where ((t2.a>5) and (v1.a=t2.a)) and ((t2.c>250) and (v1.max_c=t2.c)); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # conjunctive subformulas : pushing into WHERE and HAVING +--echo # pushing equalities +let $query= + select * from + (select a, b, max(c) as max_c, avg(c) as avg_c from t1 + group by a,b having max_c < 707) v1, + t2 where (v1.a=8) and (v1.a=t2.a) and (v1.max_c=404); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # conjunctive subformulas : pushing into WHERE and HAVING +let $query= + select * from v1,t2 where + (v1.a>3) and (v1.max_c>200) and (t2.b<v1.b) and (t2.d=v1.max_c); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # conjunctive subformula : pushing into WHERE +--echo # extracted or formula : pushing into HAVING using equalities +--echo # pushing equalities +let $query= + select * from v_double as v,t2_double as t where + (v.b=v.c) and (v.c=t.c) and ((t.c>10) or (v.a=1)); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # conjunctive subformula : pushing into WHERE +--echo # extracted or formula : pushing into HAVING using equalities +let $query= + select * from v_double as v,t2_double as t where + (((v.a>0.2) or (v.b<17)) or (t.c>17)) and (t.c=v.c) and (v.c>18); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # extracted or formula : pushing into WHERE +--echo # conjunctive subformula : pushing into HAVING +--echo # pushing equalities +let $query= + select * from v_decimal as v,t2_decimal as t where + (((v.a>4) or (v.a=2)) or (v.b>3)) and (v.avg_c=13); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= + select * from + (select a, b, max(c) as max_c, avg(c) as avg_c from t1 + where t1.a>5 group by a,b having max_c < 707) v1, + t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.a=v1.b); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # nothing to push +let $query= + select * from v1,t2 where (t2.a<2) and (t2.c>900); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= select * from v1,t2 where (v1.a=t2.a) and (v1.b=t2.b); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= + select * from v1,t2 where + (t2.a=v1.a) or (v1.b=t2.b) and ((v1.a=1) or (v1.a=6)); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= + select * from v1,t2 where (v1.a=1) or (v1.b=21) or (t2.a=2); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= + select * from v1,t2 where + (t2.a<2) and (t2.c>900) and ((v1.a<t2.a) or (t2.a<11)); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using several derived tables : nothing to push +let $query= select * from v1,v2,t2 where + (v1.a=v2.a) and (v1.a=t2.a) and (v2.b<50); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= + select * from v1,v2,t2 where + ((v1.a=v2.a) or (v1.a=t2.a)) and (t2.b<50) and (v1.b=v2.b); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= + select * from v1,v2,t2 where + ((v1.a=v2.a) and (v1.a=t2.a)) or ((v2.b>13) and (t2.c<115)); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using several derived tables : pushing in all tables +--echo # conjunctive subformula : pushing into HAVING +--echo # extracted or formula : pushing into WHERE +--echo # pushing equalities +let $query= + select * from v1,v2,t2 where ((v1.a=v2.a) or (v1.a=t2.a)) and + ((v2.b<50) or (v2.b=19)) and (v1.max_c<300); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using several derived tables : pushing only in one table +--echo # conjunctive subformula : pushing into WHERE +--echo # pushing equalities +let $query= + select * from v1,v2,t2 where + (v1.a=t2.a) and (v1.a=v1.b) and (v1.a=v2.a) and (v2.max_c<300); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using several derived tables : pushing only in one table +--echo # extracted and formula : pushing into WHERE +--echo # conjunctive subformula : pushing into WHERE using equalities +--echo # pushing equalities +let $query= + select * from v1,v2,t2 where (v1.a=1) and (v1.b>10) and (v1.b=v2.b); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # extracted or formula : pushing into WHERE +--echo # conjunctive subformula : pushing into WHERE using equalities +--echo # pushing equalities +let $query= + select * from v_char as v,t2_char as t where + (v.a=t.a) and (t.a='b') and ((v.b='Vika') or (v.b='Ali')); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using several derived tables : pushing in all tables +--echo # extracted or formula : pushing into WHERE +--echo # conjunctive subformulas : pushing into HAVING +--echo # pushing equalities +let $query= + select * from v1,v2,v3,t2 where + ((v1.a=v2.a) or (v1.a=t2.a)) and ((v3.b<50) or (v3.b=33)) + and (v1.max_c<500) and (v3.a=t2.a) and (v2.max_c>300); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using several derived tables : pushing in all tables +--echo # conjunctive subformulas : pushing into HAVING +let $query= + select * from + (select a, b, max(c) as max_c, avg(c) as avg_c from t1 + where t1.a>5 group by a,b having max_c < 707) v1, + (select a, b, min(c) as min_c from t1 + where t1.a>5 group by a,b having min_c < 707) v2, + t2 where (v1.a=v2.a) and (v1.b=t2.b) and (v1.max_c>130) and (v2.min_c<130); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using several derived tables : pushing in all tables +--echo # extracted or formulas : pushing into HAVING +--echo # conjunctive subformula : pushing into HAVING +let $query= + select * from + (select a, b, max(c) as max_c, avg(c) as avg_c from t1 + where t1.a>5 group by a,b having max_c < 707) v1, + (select a, b, min(c) as min_c from t1 + where t1.a>5 group by a,b having min_c < 707) v2, + (select a, b, avg(c) as avg_c from t1 + where t1.a<8 group by a,b) v3, + t2 where (v1.a=v2.a) and (v1.b=v3.b) and ((v3.avg_c>170) or (v3.a<5)) + and ((v1.avg_c<400) or (v1.a>1)) and (v2.min_c<200); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # extracted or formula : pushing into HAVING +--echo # conjunctive subformula : pushing into WHERE +let $query= + select * from + (select a, b, max(c) as max_c, avg(c) as avg_c from t1 + group by a,b having max_c < 707) v1, + t2 where ((v1.a=1) or (v1.max_c<300)) and (v1.b>25); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # extracted and formula : pushing into WHERE +--echo # conjunctive subformula : pushing into HAVING +let $query= + select * from + (select a, b, max(c) as max_c, avg(c) as avg_c from t1 + where t1.a>5 group by a,b having max_c < 707) v1, + t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.b<30); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using query with union +--echo # conjunctive subformula : pushing into WHERE +--echo # conjunctive subformulas : pushing into HAVING and WHERE +let $query= + select * from v1,t2 where (v1.a<5) and (v1.b=t2.b) and (t2.c>800) + union + select * from v1,t2 where (v1.max_c>100) and (v1.a>7) and (t2.d>800); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using query with union +--echo # extracted and formula : pushing into WHERE +--echo # extracted or formula : pushing into HAVING +--echo # pushing equalities +let $query= + select * from v1,t2 where (v1.a<5) and (v1.b=t2.b) and (v1.b=19) + union + select * from v1,t2 where ((v1.max_c>400) or (v1.avg_c>270)) and (v1.a<t2.a); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using query with union +--echo # extracted or formula : pushing into HAVING +--echo # extracted or formula : pushing into WHERE +--echo # pushing equalities +let $query= + select * from v1,t2 where + ((t2.a=v1.a) or (v1.b=t2.b)) and ((v1.a=1) or (v1.a=6)) + union + select * from v1,t2 where ((v1.a>3) and (v1.b>27)) or (v1.max_c>550); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using query with union +--echo # extracted or formula : pushing into HAVING +--echo # conjunctive subformulas : pushing into WHERE +--echo # pushing equalities +let $query= + select * from v1,t2 where + ((v1.a=1) and (v1.a=t2.a)) and ((v1.max_c<500) or (v1.avg_c>500)) + union + select * from v2,t2 where + ((v2.a<t2.b) or (v2.max_c>200)) and (v2.b>10) and (t2.a<2) + union + select * from v2,t2 where + (v2.max_c=t2.c) and (v2.b<10); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using derived table with union +--echo # conjunctive subformulas : pushing into WHERE and HAVING +let $query= select * from v_union,t2 where (v_union.a<3) and (v_union.c>100); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using derived table with union +--echo # conjunctive subformula : pushing into WHERE +--echo # extracted or formula : pushing into HAVING +let $query= + select * from v_union,t2 where + ((v_union.a<2) or (v_union.c>800)) and (v_union.b>12); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using derived table with union +--echo # conjunctive subformula : pushing into HAVING +--echo # conjunctive subformula : pushing into WHERE +--echo # pushing equalities +let $query= + select * from v_union,t2 where + (v_union.a=1) and (v_union.a=t2.a) and (v_union.c<200); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +let $query= + select * from v_char as v,t2_char as t where + (v.a=t.a) and (v.b='Vika') and (v.max_c>2); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using derived table with union +--echo # using several derived tables : pushing in all tables +--echo # conjunctive subformula : pushing into WHERE using equalities +--echo # pushing equalities +let $query= + select * from v_union,v1,t2 where + (v_union.a=v1.a) and (v1.a=t2.a) and (t2.a=1) + and ((v_union.c>800) or (v1.max_c>200)); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using derived table with union +--echo # extracted or formula : pushing into WHERE +--echo # conjunctive subformula : pushing into HAVING +--echo # pushing equalities +let $query= + select * from v2_union as v,t2 where + ((v.a=6) or (v.a=8)) and (v.c>200) and (v.a=t2.a); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using derived table with union of selects without aggregation +--echo # extracted conjunctive predicate: pushing in WHERE of both selects +let $query= + select * from v3_union as v,t2 where (v.a=t2.a) and (v.c>6); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using derived table with union of selects without aggregation +--echo # extracted conjunctive OR subformula: pushing in WHERE using equalities +let $query= + select * from v3_union as v,t2 where (v.a=t2.a) and ((t2.a>1) or (v.b<20)); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using derived table with union of selects without aggregation +--echo # extracted the whole condition: in WHERE of both selects +let $query= + select * from v3_union as v,t2 where + (v.a=t2.a) and ((v.b=19) or (v.b=21)) and ((v.c<3) or (v.c>600)); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using derived table with union of +--echo # a select without aggregation and a select with aggregation +--echo # extracted conjunctive predicate: pushing in WHERE of both selects +let $query= + select * from v4_union as v,t2 where (v.a=t2.a) and (v.b<20); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using derived table with union of +--echo # a select without aggregation and a select with aggregation +--echo # extracted subformula: pushing in WHERE of one select +--echo # extracted subformula: pushing in HAVING of the other select +--echo # extracted sub-subformula: pushing in WHERE of the other select +--echo # using an equality in all pushdowns +let $query= + select * from v4_union as v,t2 where + (v.a=t2.a) and ((t2.a<3) or (v.b<40)) and (v.c>500); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using embedded derived table : pushing the same conditions +--echo # using several derived tables : pushing in all tables +--echo # conjunctive subformula : pushing into WHERE +--echo # extracted and formula : pushing into WHERE +let $query= +select * from v4,v1 where + (v4.a<13) and (v1.a>5) and (v1.b>12); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using embedded view : nothing to push +--echo # using several derived tables : pushing only in one table +--echo # conjunctive subformula : pushing into WHERE +let $query= + select * from v4,v1,t2 where + (v4.a=t2.a) and (v4.a=v1.a) and (v1.b>30); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using embedded view : pushing different conditions +--echo # using several derived tables : pushing in all tables +--echo # conjunctive subformula : pushing into WHERE using equalities +--echo # extracted and formula : pushing into WHERE using equalities +--echo # conjunctive subformula : pushing into HAVING +let $query= + select * from v4,v1,t2 where + (v4.a=t2.a) and (v4.a>1) and (v4.a=v1.a) and (v4.min_c>100) and (v1.b<30); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using embedded view : pushing different conditions +--echo # using several derived tables : pushing in all tables +--echo # extracted or formula : pushing into WHERE +--echo # conjunctive subformula : pushing into HAVING +let $query= + select * from v4,v1,t2 where + (((v4.b>10) and (v4.a>1)) or (v4.b<20)) and (v1.max_c>200) and (v1.a=v4.a); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using embedded view : pushing different conditions +--echo # using several derived tables : pushing only in one table +--echo # extracted or formula : pushing into WHERE +--echo # extracted or formula : pushing into HAVING +let $query= + select * from v4,v2 where + ((v4.a>12) and (v4.min_c<300) and (v4.b>13)) or (v4.a<1); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using embedded view : pushing different conditions +--echo # using several derived tables : pushing only in one table +--echo # conjunctive subformula : pushing into WHERE +--echo # conjunctive subformula : pushing into HAVING +--echo # pushing equalities +let $query= + select * from v4,v2 where + (v4.a=v2.b) and (v4.a=v4.b) and (v4.min_c<100); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using embedded view : pushing the same conditions +--echo # using several derived tables : pushing in all tables +--echo # extracted and formula : pushing into WHERE using equalities +--echo # conjunctive subformula : pushing into WHERE +--echo # pushing equalities +let $query= + select * from v4,v2 where + (v4.a=v2.b) and (v4.a=v4.b) and (v2.b<30); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using embedded view : pushing the same conditions +--echo # using several derived tables : pushing in all tables +--echo # extracted or formula : pushing into WHERE using equalities +--echo # extracted and formula : pushing into WHERE using equalities +--echo # pushing equalities +let $query= + select * from v4,v2 where + (v4.a=v2.b) and (v4.a=v4.b) and ((v2.b<30) or (v4.a>2)); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using embedded view : pushing the same conditions +--echo # using several derived tables : pushing in all tables +--echo # extracted or formula : pushing into WHERE +--echo # conjunctive subformula : pushing into WHERE +--echo # pushing equalities +let $query= + select * from v4,v2 where + (((v4.a<12) and (v4.b>13)) or (v4.a>10)) and + (v4.min_c=v2.max_c) and (v4.min_c>100); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +--echo # using embedded view : pushing the same conditions +--echo # using several derived tables : pushing only in one table +--echo # extracted or formula : pushing into WHERE +let $query= + select * from v4,v2,t2 where + (((v4.a<12) and (t2.b>13)) or (v4.a>10)) and + (v4.min_c=t2.c) and (t2.c>100); +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +drop view v1,v2,v3,v4; +drop view v_union,v2_union,v3_union,v4_union; +drop view v_double,v_char,v_decimal; +drop table t1,t2,t1_double,t2_double,t1_char,t2_char,t1_decimal,t2_decimal; + +--echo # +--echo # MDEV-10782: condition extracted from a multiple equality +--echo # pushed into HAVING +--echo # + +CREATE TABLE t1 (i int); +INSERT INTO t1 VALUES (1),(2); +EXPLAIN EXTENDED +SELECT * + FROM ( SELECT * FROM ( SELECT MIN(i) as f FROM t1 ) sq1 ) AS sq2 + WHERE f = 8; +SELECT * + FROM ( SELECT * FROM ( SELECT MIN(i) as f FROM t1 ) sq1 ) AS sq2 + WHERE f = 8; +SELECT * + FROM ( SELECT * FROM ( SELECT MIN(i) as f FROM t1 ) sq1 ) AS sq2 + WHERE f = 1; +DROP TABLE t1; + +--echo # +--echo # MDEV-10783: pushdown into constant view +--echo # + +CREATE TABLE t1 (i int) ENGINE=MyISAM; +CREATE VIEW v AS SELECT 5; +SELECT * FROM t1 WHERE 1 IN ( SELECT * FROM v ); +DROP VIEW v; +DROP TABLE t1; + +--echo # +--echo # MDEV-10785: second execution of a query with condition +--echo # pushed into view +--echo # + +CREATE TABLE t1 (i int); +CREATE VIEW v1 AS SELECT i FROM t1 WHERE i < 5; +CREATE FUNCTION f (in1 int) RETURNS int RETURN in1; +CREATE VIEW v2 AS SELECT * FROM v1 GROUP BY i; +PREPARE stmt FROM "SELECT * FROM v2 WHERE f(0) <> 2"; +EXECUTE stmt; +EXECUTE stmt; +DROP FUNCTION f; +DROP VIEW v2,v1; +DROP TABLE t1; + +--echo # +--echo # MDEV-10884: condition pushdown into derived specified by +--echo # 1. unit with SELECT containing ORDER BY ... LIMIT +--echo # 2. unit containing global ORDER BY ... LIMIT +--echo # + +create table t1(a int); +insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +select a from t1 order by a limit 5; + +set statement optimizer_switch='condition_pushdown_for_derived=off' for +select * from (select a from t1 order by a limit 5) t where t.a not in (1,2,3); +set statement optimizer_switch='condition_pushdown_for_derived=on' for +select * from (select a from t1 order by a limit 5) t where t.a not in (1,2,3); + +select a from t1 where a < 4 union select a from t1 where a > 5 + order by a limit 5; +set statement optimizer_switch='condition_pushdown_for_derived=off' for +select * from +(select a from t1 where a < 4 union select a from t1 where a > 5 + order by a limit 5) t where t.a not in (2,9); +set statement optimizer_switch='condition_pushdown_for_derived=on' for +select * from +(select a from t1 where a < 4 union select a from t1 where a > 5 + order by a limit 5) t where t.a not in (2,9); + +drop table t1; + +--echo # +--echo # MDEV-11072: pushdown of the condition obtained +--echo # after constant row substitution +--echo # + +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +CREATE OR REPLACE VIEW v2 AS SELECT * FROM t2; +CREATE TABLE t3 (c INT) ENGINE=MyISAM; +CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v3 AS SELECT * FROM t3; + +SELECT * FROM t1 WHERE a IN ( + SELECT b FROM v2 WHERE b < a OR b IN ( + SELECT c FROM v3 WHERE c = a + ) +); + +INSERT INTO t1 VALUES (2); +INSERT INTO t2 VALUES (3), (2); +INSERT INTO t3 VALUES (4), (1), (2), (7); + +SELECT * FROM t1 WHERE a IN ( + SELECT b FROM v2 WHERE b < a OR b IN ( + SELECT c FROM v3 WHERE c = a + ) +); + +EXPLAIN FORMAT=JSON +SELECT * FROM t1 WHERE a IN ( + SELECT b FROM v2 WHERE b < a OR b IN ( + SELECT c FROM v3 WHERE c = a + ) +); + +CREATE TABLE t4 (d INT, e INT) ENGINE=MyISAM; +INSERT INTO t4 VALUES (1,10),(3,11),(2,10),(2,20),(3,21); +CREATE OR REPLACE VIEW v4 AS +SELECT d, sum(e) AS s FROM t4 GROUP BY d; + +let $query = +SELECT * FROM t1 WHERE a IN ( + SELECT b FROM v2 WHERE b < a OR b IN ( + SELECT d FROM v4 WHERE s > a + ) +); + +eval $no_pushdown $query; +eval $query; +eval explain $query; +eval explain format=json $query; + +DROP VIEW v2,v3,v4; +DROP TABLE t1,t2,t3,t4; + +--echo # +--echo # MDEV-10800: pushdown of the condition obtained +--echo # after constant row substitution +--echo # + + +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1); + +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (3),(4); +CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2; + +SELECT * FROM +( SELECT * FROM t1 + WHERE EXISTS ( SELECT * FROM v2 WHERE b = a ) ) AS sq; + +EXPLAIN FORMAT=JSON +SELECT * FROM +( SELECT * FROM t1 + WHERE EXISTS ( SELECT * FROM v2 WHERE b = a ) ) AS sq; + +DROP VIEW v2; +DROP TABLE t1,t2; + +--echo # +--echo # MDEV-11102: condition pushdown into materialized inner table +--echo # of outer join is not applied as not being valid +--echo # + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (0),(2); + +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (1),(2); + +CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2; + +SELECT * FROM t1 LEFT JOIN t2 ON a = b WHERE b IS NULL; + +SELECT * FROM t1 LEFT JOIN v2 ON a = b WHERE b IS NULL; + +EXPLAIN FORMAT=JSON +SELECT * FROM t1 LEFT JOIN v2 ON a = b WHERE b IS NULL; + +DROP VIEW v2; +DROP TABLE t1,t2; + +--echo # +--echo # MDEV-11103: pushdown condition with ANY subquery +--echo # + +CREATE TABLE t1 (i INT); +CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1; +INSERT INTO t1 VALUES (1),(2); + +EXPLAIN FORMAT=JSON +SELECT * FROM v1 WHERE i <= ANY ( SELECT 3 ); + +SELECT * FROM v1 WHERE i <= ANY ( SELECT 3 ); + +DROP VIEW v1; +DROP TABLE t1; + +--echo # +--echo # MDEV-11315: condition with outer reference to mergeable derived +--echo # + +CREATE TABLE t1 (pk1 INT PRIMARY KEY, a INT, b INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (10,7,1),(11,0,2); + +CREATE TABLE t2 (pk2 INT PRIMARY KEY, c INT, d DATETIME) ENGINE=MyISAM; +INSERT INTO t2 VALUES + (1,4,'2008-09-27 00:34:58'), + (2,5,'2007-05-28 00:00:00'), + (3,6,'2009-07-25 09:21:20'); + +CREATE VIEW v1 AS SELECT * FROM t1; +CREATE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2; + +SELECT * FROM v1 AS sq + WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100; +EXPLAIN FORMAT=JSON +SELECT * FROM v1 AS sq + WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100; + +SELECT * FROM ( SELECT * FROM t1 ) AS sq + WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100; +EXPLAIN FORMAT=JSON +SELECT * FROM ( SELECT * FROM t1 ) AS sq + WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100; + +DROP VIEW v1,v2; +DROP TABLE t1,t2; + +--echo # +--echo # MDEV-11313: pushdown of the condition obtained +--echo # after constant row substitution +--echo # + +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (50); +CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1; + +SELECT ( SELECT COUNT(*) FROM v1 WHERE a = t2.b ) AS f FROM t2 GROUP BY f; +EXPLAIN FORMAT=JSON +SELECT ( SELECT COUNT(*) FROM v1 WHERE a = t2.b ) AS f FROM t2 GROUP BY f; + +CREATE TABLE t3 (a INT, b INT) ENGINE=MYISAM; +INSERT INTO t3 VALUES (1,10),(3,11),(2,10),(2,20),(3,21); +CREATE VIEW v2 AS SELECT a, sum(b) AS s FROM t3 GROUP BY a ; +SELECT ( SELECT COUNT(*) FROM v2 WHERE s < t2.b ) AS f FROM t2 GROUP BY f; +EXPLAIN FORMAT=JSON +SELECT ( SELECT COUNT(*) FROM v2 WHERE s < t2.b ) AS f FROM t2 GROUP BY f; + + +DROP VIEW v1,v2; +DROP TABLE t1,t2,t3; + +--echo # +--echo # MDEV-10882: pushdown of the predicate with cached value +--echo # + +CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL) ENGINE=MyISAM; +CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1; +INSERT INTO t1 VALUES (1,2),(3,4); + +CREATE TABLE t2 (c INT NOT NULL) ENGINE=MyISAM; +INSERT INTO t2 VALUES (5),(6); + +SELECT a, GROUP_CONCAT(b) FROM v1 + WHERE b IN ( SELECT COUNT(c) FROM t2 ) GROUP BY a; + +EXPLAIN FORMAT=JSON +SELECT a, GROUP_CONCAT(b) FROM v1 + WHERE b IN ( SELECT COUNT(c) FROM t2 ) GROUP BY a; + +DROP VIEW v1; +DROP TABLE t1,t2; + +--echo # +--echo # MDEV-10836: pushdown of the predicate with cached value +--echo # + +CREATE TABLE t (pk INT PRIMARY KEY, f INT) ENGINE=MyISAM; +CREATE ALGORITHM=TEMPTABLE VIEW v AS SELECT * FROM t; +INSERT INTO t VALUES (1,1),(3,2); + +SELECT * FROM v AS v1, v AS v2 + WHERE v2.pk > v1.f AND v1.f IN ( SELECT COUNT(pk) FROM t ); + +EXPLAIN FORMAT=JSON +SELECT * FROM v AS v1, v AS v2 + WHERE v2.pk > v1.f AND v1.f IN ( SELECT COUNT(pk) FROM t ); + +DROP VIEW v; +DROP TABLE t; + +--echo # +--echo # MDEV-11488: pushdown of the predicate with cached value +--echo # + +CREATE TABLE t1 (i INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(3),(2); + +CREATE TABLE t2 (j INT, KEY(j)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (3),(4); + +SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq + WHERE i IN ( SELECT MIN(j) FROM t2 ); +EXPLAIN FORMAT=JSON +SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq + WHERE i IN ( SELECT MIN(j) FROM t2 ); + +UPDATE t2 SET j = 2 WHERE j = 3; +SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq + WHERE i IN ( SELECT MIN(j) FROM t2 ); + +DROP TABLE t1,t2; + +CREATE TABLE t1 (i FLOAT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1.5),(3.2),(2.71); + +CREATE TABLE t2 (j FLOAT, KEY(j)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (3.2),(2.71); + +SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq + WHERE i IN ( SELECT MIN(j) FROM t2 ); +EXPLAIN FORMAT=JSON +SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq + WHERE i IN ( SELECT MIN(j) FROM t2 ); + +DROP TABLE t1,t2; + +CREATE TABLE t1 (i DECIMAL(10,2)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1.5),(3.21),(2.47); + +CREATE TABLE t2 (j DECIMAL(10,2), KEY(j)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (3.21),(4.55); + +SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq + WHERE i IN ( SELECT MIN(j) FROM t2 ); +EXPLAIN FORMAT=JSON +SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq + WHERE i IN ( SELECT MIN(j) FROM t2 ); + +DROP TABLE t1,t2; + +CREATE TABLE t1 (i VARCHAR(32)) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('cc'),('aa'),('ddd'); + +CREATE TABLE t2 (j VARCHAR(16), KEY(j)) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('bbb'),('aa'); + +SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq + WHERE i IN ( SELECT MIN(j) FROM t2 ); +EXPLAIN FORMAT=JSON +SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq + WHERE i IN ( SELECT MIN(j) FROM t2 ); + +DROP TABLE t1,t2; + +CREATE TABLE t1 (i DATETIME) ENGINE=MyISAM; +INSERT INTO t1 VALUES + ('2008-09-27 00:34:58'),('2007-05-28 00:00:00'), ('2009-07-25 09:21:20'); + +CREATE TABLE t2 (j DATETIME, KEY(j)) ENGINE=MyISAM; +INSERT INTO t2 VALUES + ('2007-05-28 00:00:00'), ('2010-08-25 00:00:00'); + +SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq + WHERE i IN ( SELECT MIN(j) FROM t2 ); +EXPLAIN FORMAT=JSON +SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq + WHERE i IN ( SELECT MIN(j) FROM t2 ); + +DROP TABLE t1,t2; + +CREATE TABLE t1 (i DATE) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('2008-09-27'),('2007-05-28'), ('2009-07-25'); + +CREATE TABLE t2 (j DATE, KEY(j)) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('2007-05-28'), ('2010-08-25'); + +SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq + WHERE i IN ( SELECT MIN(j) FROM t2 ); +EXPLAIN FORMAT=JSON +SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq + WHERE i IN ( SELECT MIN(j) FROM t2 ); + +DROP TABLE t1,t2; + +CREATE TABLE t1 (i TIME) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('00:34:58'),('10:00:02'), ('09:21:20'); + +CREATE TABLE t2 (j TIME, KEY(j)) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('10:00:02'), ('11:00:10'); + +SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq + WHERE i IN ( SELECT MIN(j) FROM t2 ); +EXPLAIN FORMAT=JSON +SELECT * FROM ( SELECT DISTINCT * FROM t1 ) AS sq + WHERE i IN ( SELECT MIN(j) FROM t2 ); + +DROP TABLE t1,t2; + +--echo # +--echo # MDEV-11593: pushdown of condition with NULLIF +--echo # + +CREATE TABLE t1 (i INT); +CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1; + +INSERT INTO t1 VALUES (2), (1); + +SELECT * FROM v1 WHERE NULLIF(1, i); +EXPLAIN FORMAT=JSON +SELECT * FROM v1 WHERE NULLIF(1, i); + +DROP VIEW v1; +DROP TABLE t1; + +--echo # +--echo # MDEV-11608: pushdown of the predicate with cached null value +--echo # + +CREATE TABLE t1 (c VARCHAR(3)); +CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1; +INSERT INTO t1 VALUES ('foo'),('bar'); + +CREATE TABLE t2 (c VARCHAR(3)); +INSERT INTO t2 VALUES ('foo'),('xyz'); + +SELECT * FROM v1 WHERE v1.c IN ( SELECT MIN(c) FROM t2 WHERE 0 ); +EXPLAIN FORMAT=JSON +SELECT * FROM v1 WHERE v1.c IN ( SELECT MIN(c) FROM t2 WHERE 0 ); + +DROP VIEW v1; +DROP TABLE t1,t2; + +CREATE TABLE t1 (d DECIMAL(10,2)); +CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1; +INSERT INTO t1 VALUES (5.37),(1.1); + +CREATE TABLE t2 (d DECIMAL(10,2)); +INSERT INTO t2 VALUES ('1.1'),('2.23'); + +SELECT * FROM v1 WHERE v1.d IN ( SELECT MIN(d) FROM t2 WHERE 0 ); + +DROP VIEW v1; +DROP TABLE t1,t2; diff --git a/mysql-test/t/derived_view.test b/mysql-test/t/derived_view.test index ba58fada7f7..3a18e9a086e 100644 --- a/mysql-test/t/derived_view.test +++ b/mysql-test/t/derived_view.test @@ -113,6 +113,7 @@ select * from t1 join v2 on f1=f2; show status like 'Handler_read%'; explain extended select * from v1 join v4 on f1=f2; +explain format=json select * from v1 join v4 on f1=f2; select * from v1 join v4 on f1=f2; --echo merged derived in merged derived @@ -136,6 +137,8 @@ select * from (select * from --echo materialized derived in materialized derived explain extended select * from (select * from (select * from t1 where f1 < 7 group by f1) tt where f1 > 2 group by f1) zz; +explain format=json select * from (select * from + (select * from t1 where f1 < 7 group by f1) tt where f1 > 2 group by f1) zz; select * from (select * from (select * from t1 where f1 < 7 group by f1) tt where f1 > 2 group by f1) zz; @@ -145,6 +148,11 @@ explain extended select * from join (select * from (select * from t1 where f1 < 7 group by f1) tt where f1 > 2) z on x.f1 = z.f1; +explain format=json select * from + (select * from (select * from t1 where f1 < 7 group by f1) tt where f1 > 2) x +join + (select * from (select * from t1 where f1 < 7 group by f1) tt where f1 > 2) z + on x.f1 = z.f1; flush status; select * from @@ -181,6 +189,13 @@ join (select * from (select * from t1 where f1 < 7 group by f1) tt where f1 > 2 group by f1) z on x.f1 = z.f1; +explain format=json select * from + (select * from + (select * from t1 where f1 < 7 group by f1) tt where f1 > 2 group by f1) x +join + (select * from + (select * from t1 where f1 < 7 group by f1) tt where f1 > 2 group by f1) z + on x.f1 = z.f1; select * from (select * from @@ -198,6 +213,8 @@ select * from (select * from v4 group by 1) tt; --echo materialized view in merged derived explain extended select * from ( select * from v1 where f1 < 7) tt; +explain format=json +select * from ( select * from v1 where f1 < 7) tt; select * from ( select * from v1 where f1 < 7) tt; --echo merged view in a merged view in a merged derived @@ -212,6 +229,7 @@ select * from (select * from v7 group by 1) tt; --echo join of above two explain extended select * from v6 join v7 on f2=f1; +explain format=json select * from v6 join v7 on f2=f1; select * from v6 join v7 on f2=f1; --echo test two keys diff --git a/mysql-test/t/dyncol.test b/mysql-test/t/dyncol.test index 03e2345ba1c..c0d22e9d1c4 100644 --- a/mysql-test/t/dyncol.test +++ b/mysql-test/t/dyncol.test @@ -661,7 +661,7 @@ select column_get(column_create(1, "18446744073709552001" as char), 1 as int); --echo # mysqld --echo # --error ER_TOO_BIG_SCALE -SELECT COLUMN_GET(`x`, 'y' AS DECIMAL(5,34)); +SELECT COLUMN_GET(`x`, 'y' AS DECIMAL(5,50)); --echo # --echo # test of symbolic names @@ -805,24 +805,24 @@ select column_json(column_create(1, "val", 2, column_create(3, "val2"))); --echo # Time encoding --echo # select hex(column_create("t", "800:46:06.23434" AS time)) as hex, - column_json(column_create("t", "800:46:06.23434" AS time)) as json; + column_json(column_create("t", "800:46:06.23434" AS time)) as js; select hex(column_create(1, "800:46:06.23434" AS time)) as hex, - column_json(column_create(1, "800:46:06.23434" AS time)) as json; + column_json(column_create(1, "800:46:06.23434" AS time)) as js; select hex(column_create("t", "800:46:06" AS time)) as hex, - column_json(column_create("t", "800:46:06" AS time)) as json; + column_json(column_create("t", "800:46:06" AS time)) as js; select hex(column_create(1, "800:46:06" AS time)) as hex, - column_json(column_create(1, "800:46:06" AS time)) as json; + column_json(column_create(1, "800:46:06" AS time)) as js; select hex(column_create("t", "2012-12-21 10:46:06.23434" AS datetime)) as hex, - column_json(column_create("t", "2012-12-21 10:46:06.23434" AS datetime)) as json; + column_json(column_create("t", "2012-12-21 10:46:06.23434" AS datetime)) as js; select hex(column_create(1, "2012-12-21 10:46:06.23434" AS datetime)) as hex, - column_json(column_create(1, "2012-12-21 10:46:06.23434" AS datetime)) as json; + column_json(column_create(1, "2012-12-21 10:46:06.23434" AS datetime)) as js; select hex(column_create("t", "2012-12-21 10:46:06" AS datetime)) as hex, - column_json(column_create("t", "2012-12-21 10:46:06" AS datetime)) as json; + column_json(column_create("t", "2012-12-21 10:46:06" AS datetime)) as js; select hex(column_create(1, "2012-12-21 10:46:06" AS datetime)) as hex, - column_json(column_create(1, "2012-12-21 10:46:06" AS datetime)) as json; + column_json(column_create(1, "2012-12-21 10:46:06" AS datetime)) as js; --echo # --echo # MDEV-4849: Out of memory error and valgrind warnings on COLUMN_ADD @@ -923,3 +923,45 @@ SELECT COLUMN_JSON(COLUMN_CREATE('a',1 AS DECIMAL,'b',1 AS DECIMAL)); --echo # --echo # end of 10.0 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +# +# Item_func_dyncol_add::print +# +create view v1 as select column_get(column_add(column_create(1 , 'blue' as char), 2, 'ttt'), 1 as char); +show create view v1; +select * from v1; +drop view v1; + +--echo # +--echo # MDEV-10134 Add full support for DEFAULT +--echo # +CREATE TABLE t1 ( + name VARCHAR(10), + value VARCHAR(10), + dyncol0 BLOB DEFAULT COLUMN_CREATE(name, value), + value_dyncol0_name0 VARCHAR(10) DEFAULT COLUMN_GET(dyncol0, 'name0' AS CHAR), + dyncol1 BLOB DEFAULT COLUMN_ADD(dyncol0, 'name1', 'value1'), + value_dyncol1_name1 VARCHAR(10) DEFAULT COLUMN_GET(dyncol1, 'name1' AS CHAR), + dyncol2 BLOB DEFAULT COLUMN_DELETE(dyncol1, 'name1'), + dyncol2_exists_name0 INT DEFAULT COLUMN_EXISTS(dyncol2, 'name0'), + dyncol2_exists_name1 INT DEFAULT COLUMN_EXISTS(dyncol2, 'name1'), + dyncol2_check INT DEFAULT COLUMN_CHECK(dyncol2), + dyncol1_list TEXT DEFAULT COLUMN_LIST(dyncol1), + dyncol1_json TEXT DEFAULT COLUMN_JSON(dyncol1) +); +SHOW CREATE TABLE t1; +INSERT INTO t1 (name,value) VALUES ('name0', 'value0'); +SELECT value_dyncol0_name0, value_dyncol1_name1 FROM t1; +SELECT dyncol2_check, dyncol2_exists_name0, dyncol2_exists_name1 FROM t1; +SELECT dyncol1_list FROM t1; +SELECT dyncol1_json FROM t1; +DROP TABLE t1; + + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/empty_table.test b/mysql-test/t/empty_table.test index e8e532832f4..754671868ba 100644 --- a/mysql-test/t/empty_table.test +++ b/mysql-test/t/empty_table.test @@ -10,6 +10,15 @@ create table t1 (nr int(5) not null auto_increment,b blob,str char(10), primary select count(*) from t1; select * from t1; select * from t1 limit 0; +show status like "Empty_queries"; drop table t1; +# +# Accessing a non existing table should not increase Empty_queries +# + +--error 1146 +select * from t2; +show status like "Empty_queries"; + # End of 4.1 tests diff --git a/mysql-test/t/events_bugs.test b/mysql-test/t/events_bugs.test index cace397e92a..76288c8fbae 100644 --- a/mysql-test/t/events_bugs.test +++ b/mysql-test/t/events_bugs.test @@ -919,7 +919,6 @@ GRANT create, insert, select, event ON events_test.* TO evtest1@localhost; GRANT select,insert ON test.* TO evtest1@localhost; SHOW GRANTS FOR evtest1@localhost; ---echo connection e1; --replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK connect (e1,localhost,evtest1,ev1,events_test,$MASTER_MYPORT,$MASTER_MYSOCK); DELIMITER |; @@ -951,7 +950,6 @@ SELECT COUNT(*) > 0 FROM events_test.event_log; --source include/wait_condition.inc SELECT COUNT(*) > 0 AS "Expect 1" FROM events_test.event_log; # ---echo connection default; connection default; DROP USER evtest1@localhost; # 2. If we meet BUG#28924 again than a server crash happens within the next @@ -1025,10 +1023,6 @@ SET GLOBAL READ_ONLY = 1; --echo ---echo # ---echo # Connection: u1_con (mysqltest_u1@localhost/events_test). ---echo # - --connect(u1_con,localhost,mysqltest_u1,,events_test) --echo @@ -1050,10 +1044,6 @@ DROP EVENT e1; # Check that the super user still can create/update/drop events. ---echo # ---echo # Connection: root_con (root@localhost/events_test). ---echo # - --connect(root_con,localhost,root,,events_test) --echo @@ -1079,10 +1069,6 @@ SET GLOBAL READ_ONLY = 0; --echo ---echo # ---echo # Connection: u1_con (mysqltest_u1@localhost/test). ---echo # - --connection u1_con --echo @@ -1101,10 +1087,6 @@ WHERE event_schema = 'events_test'; --echo ---echo # ---echo # Connection: root_con (root@localhost/events_test). ---echo # - --connection root_con --echo @@ -1170,10 +1152,6 @@ SET GLOBAL READ_ONLY = 0; --echo ---echo # ---echo # Connection: default ---echo # - --disconnect u1_con --disconnect root_con --connection default diff --git a/mysql-test/t/explain_json.test b/mysql-test/t/explain_json.test index 153d85359c9..22bfd5aedcd 100644 --- a/mysql-test/t/explain_json.test +++ b/mysql-test/t/explain_json.test @@ -394,5 +394,15 @@ set join_cache_level=@tmp_join_cache_level; drop table t1,t2,t3,t4; +--echo # +--echo # MDEV-9652: EXPLAIN FORMAT=JSON should show outer_ref_cond +--echo # +create table t0(a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1 (a int, b int); +insert into t1 select a,a from t0; +explain format=json +select a, (select max(a) from t1 where t0.a<5 and t1.b<t0.a) from t0; +drop table t0,t1; diff --git a/mysql-test/t/features.test b/mysql-test/t/features.test index 225ab40b361..1241bd50bdd 100644 --- a/mysql-test/t/features.test +++ b/mysql-test/t/features.test @@ -98,6 +98,7 @@ set @a:=0; select @a; insert into t1 values (1),(2); select @a; +--replace_column 6 # SHOW TRIGGERS IN test like 't1'; drop trigger trg; drop table t1; @@ -130,3 +131,11 @@ insert into t1 values(2); drop table t1; show status like "feature_delay_key_write"; + +# +# Feature CHECK CONSTRAINT +# +create table t1 (a int check (a > 5)); +create table t2 (b int, constraint foo check (b < 10)); +drop table t1, t2; +show status like "feature_check_constraint"; diff --git a/mysql-test/t/filesort_debug.test b/mysql-test/t/filesort_debug.test index c375334ad29..86795298f07 100644 --- a/mysql-test/t/filesort_debug.test +++ b/mysql-test/t/filesort_debug.test @@ -32,7 +32,6 @@ DROP FUNCTION f1; connect (con1, localhost, root); connect (con2, localhost, root); ---echo # connection 1 connection con1; CREATE TABLE t1(f0 int auto_increment primary key, f1 int); INSERT INTO t1(f1) VALUES (0),(1),(2),(3),(4),(5); @@ -43,14 +42,12 @@ SET DEBUG_SYNC='filesort_start SIGNAL filesort_started WAIT_FOR filesort_killed' --echo # Sending: (not reaped since connection is killed later) --send SELECT * FROM t1 ORDER BY f1 ASC, f0 ---echo # connection 2 connection con2; let $ignore= `SELECT @id := $ID`; SET DEBUG_SYNC='now WAIT_FOR filesort_started'; KILL @id; SET DEBUG_SYNC='now SIGNAL filesort_killed'; ---echo # connection default connection default; disconnect con1; disconnect con2; diff --git a/mysql-test/t/flush-innodb-notembedded.test b/mysql-test/t/flush-innodb-notembedded.test index 15bfeb53475..1f73ba50fc4 100644 --- a/mysql-test/t/flush-innodb-notembedded.test +++ b/mysql-test/t/flush-innodb-notembedded.test @@ -14,54 +14,44 @@ GRANT RELOAD, SELECT ON *.* TO user3@localhost; GRANT SELECT, LOCK TABLES ON *.* TO user4@localhost; GRANT RELOAD, LOCK TABLES ON *.* TO user5@localhost; ---echo # Connection con1 as user1 --connect(con1, localhost, user1) FLUSH TABLE db1.t1 FOR EXPORT; UNLOCK TABLES; --disconnect con1 --source include/wait_until_disconnected.inc ---echo # Connection default --connection default ---echo # Connection con1 as user2 --connect(con1, localhost, user2) --error ER_SPECIFIC_ACCESS_DENIED_ERROR FLUSH TABLE db1.t1 FOR EXPORT; --disconnect con1 --source include/wait_until_disconnected.inc ---echo # Connection default --connection default ---echo # Connection con1 as user3 --connect(con1, localhost, user3) --error ER_DBACCESS_DENIED_ERROR FLUSH TABLE db1.t1 FOR EXPORT; --disconnect con1 --source include/wait_until_disconnected.inc ---echo # Connection default --connection default ---echo # Connection con1 as user4 --connect(con1, localhost, user4) --error ER_SPECIFIC_ACCESS_DENIED_ERROR FLUSH TABLE db1.t1 FOR EXPORT; --disconnect con1 --source include/wait_until_disconnected.inc ---echo # Connection default --connection default ---echo # Connection con1 as user5 --connect(con1, localhost, user5) --error ER_TABLEACCESS_DENIED_ERROR FLUSH TABLE db1.t1 FOR EXPORT; --disconnect con1 --source include/wait_until_disconnected.inc ---echo # Connection default --connection default DROP USER user1@localhost, user2@localhost, user3@localhost, user4@localhost, user5@localhost; diff --git a/mysql-test/t/flush-innodb.test b/mysql-test/t/flush-innodb.test index acf9493693a..bf7b79bb5a3 100644 --- a/mysql-test/t/flush-innodb.test +++ b/mysql-test/t/flush-innodb.test @@ -109,18 +109,15 @@ DROP VIEW v1; CREATE TABLE t1 (a INT PRIMARY KEY, b INT) engine= InnoDB; CREATE TABLE t2 (a INT) engine= InnoDB; ---echo # Connection con1 --connect (con1, localhost, root) START TRANSACTION; INSERT INTO t1 VALUES (1, 1); ---echo # Connection default --connection default --echo # Should be blocked --echo # Sending: --send FLUSH TABLES t1 FOR EXPORT ---echo # Connection con1 --connection con1 let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist @@ -129,12 +126,10 @@ let $wait_condition= --source include/wait_condition.inc COMMIT; ---echo # Connection default --connection default --echo # Reaping: FLUSH TABLES t1 FOR EXPORT --reap ---echo # Connection con1 --connection con1 --echo # Should not be blocked INSERT INTO t2 VALUES (1); @@ -142,7 +137,6 @@ INSERT INTO t2 VALUES (1); --echo # Sending: --send INSERT INTO t1 VALUES (2, 2) ---echo # Connection default --connection default let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist @@ -151,7 +145,6 @@ let $wait_condition= --source include/wait_condition.inc UNLOCK TABLES; ---echo # Connection con1 --connection con1 --echo # Reaping: INSERT INTO t1 VALUES (2, 2); --reap @@ -162,18 +155,15 @@ UNLOCK TABLES; START TRANSACTION; SELECT * FROM t1; ---echo # Connection default --connection default --echo # Should not be blocked FLUSH TABLES t1 FOR EXPORT; ---echo # Connection con1 --connection con1 COMMIT; --echo # Should not be blocked SELECT * FROM t1; ---echo # Connection default --connection default UNLOCK TABLES; @@ -183,12 +173,10 @@ UNLOCK TABLES; START TRANSACTION; SELECT * FROM t1; ---echo # Connection con2 --connect (con2, localhost, root) --echo # Sending: --send ALTER TABLE t1 ADD INDEX i1(b) ---echo # Connection con1 --connection con1 let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist @@ -198,7 +186,6 @@ let $wait_condition= --echo # Should be blocked --send FLUSH TABLE t1 FOR EXPORT ---echo # Connection default --connection default let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist @@ -207,27 +194,22 @@ let $wait_condition= --source include/wait_condition.inc COMMIT; ---echo # Connection con2 --connection con2 --echo # Reaping ALTER TABLE ... --reap ---echo # Connection con1 --connection con1 --echo # Reaping FLUSH TABLE t1 FOR EXPORT --reap UNLOCK TABLES; ---echo # Connection default --connection default FLUSH TABLE t1 FOR EXPORT; ---echo # Connection con2 --connection con2 --echo # Should be blocked --send DROP TABLE t1 ---echo # Connection default --connection default let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist @@ -236,14 +218,12 @@ let $wait_condition= --source include/wait_condition.inc UNLOCK TABLES; ---echo # Connection con2 --connection con2 --echo # Reaping DROP TABLE t1 --reap --disconnect con2 --source include/wait_until_disconnected.inc ---echo # Connection default --connection default DROP TABLE t2; @@ -253,13 +233,11 @@ DROP TABLE t2; CREATE TABLE t1(a INT) engine= InnoDB; FLUSH TABLES WITH READ LOCK; ---echo # Connection con1 --connection con1 --echo # This should not block FLUSH TABLE t1 FOR EXPORT; UNLOCK TABLES; ---echo # Connection default --connection default UNLOCK TABLES; DROP TABLE t1; @@ -272,12 +250,10 @@ CREATE TABLE t1(a INT) engine= MEMORY; FLUSH TABLE t1 FOR EXPORT; DROP TABLE t1; ---echo # Connection con1 --connection con1 --disconnect con1 --source include/wait_until_disconnected.inc ---echo # Connection defalt --connection default --echo # Test 7: Check privileges required. @@ -291,11 +267,9 @@ DROP TABLE t1; CREATE TABLE t1 (a INT) engine= InnoDB; CREATE TABLE t2 (a INT) engine= InnoDB; ---echo # Connection con1 --connect (con1, localhost, root) FLUSH TABLE t1 FOR EXPORT; ---echo # Connection default --connection default --echo # This should not block FLUSH TABLE t2 FOR EXPORT; @@ -304,7 +278,6 @@ UNLOCK TABLES; --echo # Sending: --send FLUSH TABLE t1 FOR EXPORT ---echo # Connection con1 --connection con1 let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist @@ -313,7 +286,6 @@ let $wait_condition= --source include/wait_condition.inc UNLOCK TABLES; ---echo # Connection default --connection default --echo # Reaping: FLUSH TABLE t1 FOR EXPORT --reap @@ -324,33 +296,27 @@ UNLOCK TABLES; LOCK TABLE t1 READ; ---echo # Connection con1 --connection con1 --echo # Should not block FLUSH TABLE t1 FOR EXPORT; UNLOCK TABLES; ---echo # Connection default --connection default UNLOCK TABLES; FLUSH TABLE t1 FOR EXPORT; ---echo # Connection con1 --connection con1 --echo # Should not block LOCK TABLE t1 READ; UNLOCK TABLES; ---echo # Connection default --connection default UNLOCK TABLES; ---echo # Connection con1 --connection con1 --disconnect con1 --source include/wait_until_disconnected.inc ---echo # Connection default --connection default DROP TABLE t1, t2; @@ -372,21 +338,17 @@ DROP TABLE t1; --echo # Test 11: Test 'flush table with fully qualified table names --echo # and with syntax local/NO_WRITE_TO_BINLOG ---echo # Connection con1 --connect (con1, localhost, root) ---echo # Connection default --connection default CREATE TABLE t1 ( i INT ) ENGINE = Innodb; INSERT INTO t1 VALUES (100),(200); FLUSH LOCAL TABLES test.t1 FOR EXPORT; ---echo # Connection con1 --connection con1 --echo # Should be blocked --echo # Sending: --send FLUSH LOCAL TABLES t1 FOR EXPORT ---echo # Connection default --connection default let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist @@ -395,19 +357,16 @@ let $wait_condition= --source include/wait_condition.inc UNLOCK TABLE; ---echo # Connection con1 --connection con1 --echo # Reaping: FLUSH LOCAL TABLES t1 FOR EXPORT --reap SELECT * FROM t1 ORDER BY i; ---echo # Connection default --connection default --echo # Should be blocked --echo # Sending: --send FLUSH NO_WRITE_TO_BINLOG TABLES test.t1 FOR EXPORT ---echo # Connection con1 --connection con1 let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist @@ -416,7 +375,6 @@ let $wait_condition= --source include/wait_condition.inc UNLOCK TABLES; ---echo # Connection default --connection default --echo # Reaping: FLUSH NO_WRITE_TO_BINLOG TABLES test.t1 FOR EXPORT --reap @@ -427,7 +385,6 @@ DROP TABLE t1; --echo # Test 12: Active transaction get committed if user execute --echo # "FLUSH TABLE ... FOR EXPORT" or "LOCK TABLE.." ---echo # Connection default --connection default CREATE TABLE t1 ( i INT ) ENGINE = Innodb; INSERT INTO t1 VALUES (100),(200); @@ -448,7 +405,6 @@ DROP TABLE t1; --echo # Test 13: Verify "FLUSH TABLE ... FOR EXPORT" and "LOCK TABLE.." --echo # in same session ---echo # Connection default --connection default CREATE TABLE t1 ( i INT ) ENGINE = Innodb; diff --git a/mysql-test/t/flush.test b/mysql-test/t/flush.test index a1df9359d30..81834b7de10 100644 --- a/mysql-test/t/flush.test +++ b/mysql-test/t/flush.test @@ -303,19 +303,16 @@ insert into t3 (a) values (2); --echo # III. Concurrent tests. --echo # connect (con1,localhost,root,,); ---echo # --> connection default --echo # --echo # Check that flush tables <list> with read lock --echo # does not affect non-locked tables. connection default; --echo # flush tables t1 with read lock; ---echo # --> connection con1; connection con1; select * from t1; select * from t2; insert into t2 (a) values (3); ---echo # --> connection default; connection default; unlock tables; --echo # @@ -324,12 +321,10 @@ unlock tables; --echo # Vice versa it is not true, since tables read-locked by --echo # "FLUSH TABLES <list> WITH READ LOCK" can't be flushed. flush tables with read lock; ---echo # --> connection con1; connection con1; flush table t1 with read lock; select * from t1; unlock tables; ---echo # --> connection default; connection default; unlock tables; --echo # @@ -338,11 +333,9 @@ unlock tables; --echo # WITH READ LOCK. --echo # flush table t1 with read lock; ---echo # --> connection con1 connection con1; flush table t2 with read lock; unlock tables; ---echo # --> connection default connection default; unlock tables; --echo # @@ -350,11 +343,9 @@ unlock tables; --echo # does not conflict with SET GLOBAL read_only=1. --echo # set global read_only=1; ---echo # connection con1 connection con1; flush table t1 with read lock; unlock tables; ---echo # connection default connection default; set global read_only=0; --echo # @@ -362,15 +353,12 @@ set global read_only=0; --echo # tables locked with FLUSH TABLE <list> WITH READ LOCK. --echo # flush tables t1, t2 with read lock; ---echo # connection con1 connection con1; lock table t1 read, t2 read; unlock tables; ---echo # connection default connection default; unlock tables; ---echo # --> connection con1 connection con1; disconnect con1; --source include/wait_until_disconnected.inc @@ -440,13 +428,11 @@ drop table if exists t1; --enable_warnings connect (con1,localhost,root,,); connect (con2,localhost,root,,); ---echo # --> conection default connection default; create table t1 (a int); begin; select * from t1; ---echo # --> connection con1 connection con1; --echo # --echo # Issue a LOCK TABLE t1 READ. We could use HANDLER t1 OPEN @@ -454,13 +440,11 @@ connection con1; --echo # prevents FLUSH TABLE t1 from immediate completion would do. --echo # lock table t1 read; ---echo # --> connection con2 connection con2; --echo # --echo # FLUSH TABLE expels the table definition from the cache. --echo # Sending 'flush table t1'... send flush table t1; ---echo # --> connection default connection default; --echo # Let flush table sync in. let $wait_condition= @@ -469,7 +453,6 @@ let $wait_condition= and info = "flush table t1"; --source include/wait_condition.inc send select * from t1; ---echo # --> connection con1 connection con1; let $wait_condition= select count(*) = 1 from information_schema.processlist @@ -477,11 +460,9 @@ let $wait_condition= and info = "select * from t1"; select * from t1; unlock tables; ---echo # --> connection con2 connection con2; --echo # Reaping 'flush table t1'... reap; ---echo # --> connection default connection default; --echo # Reaping 'select * from t1'... reap; @@ -493,19 +474,16 @@ commit; begin; select * from t1; ---echo # --> connection con1 connection con1; --echo # --echo # Issue a LOCK TABLE t1 READ. --echo # lock table t1 read; ---echo # --> connection con2 connection con2; --echo # --echo # FLUSH TABLES expels the table definition from the cache. --echo # Sending 'flush tables'... send flush tables; ---echo # --> connection default connection default; --echo # Let flush table sync in. let $wait_condition= @@ -514,7 +492,6 @@ let $wait_condition= and info = "flush tables"; --source include/wait_condition.inc send select * from t1; ---echo # --> connection con1 connection con1; let $wait_condition= select count(*) = 1 from information_schema.processlist @@ -522,11 +499,9 @@ let $wait_condition= and info = "select * from t1"; select * from t1; unlock tables; ---echo # --> connection con2 connection con2; --echo # Reaping 'flush tables'... reap; ---echo # --> connection default connection default; --echo # Reaping 'select * from t1'... reap; @@ -534,15 +509,12 @@ commit; --echo # Cleanup ---echo # --> connection con1 connection con1; disconnect con1; --source include/wait_until_disconnected.inc ---echo # --> connection con2 connection con2; disconnect con2; --source include/wait_until_disconnected.inc ---echo # --> connection default connection default; drop table t1; @@ -593,12 +565,10 @@ create table t1 (i int); create table t2 (i int); handler t1 open; ---echo # Switching to connection 'con1'. connection con1; --echo # Sending: --send flush tables with read lock ---echo # Switching to connection 'con2'. connection con2; --echo # Wait until FTWRL starts waiting for 't1' to be closed. let $wait_condition= @@ -607,13 +577,11 @@ let $wait_condition= and info = "flush tables with read lock"; --source include/wait_condition.inc ---echo # Switching to connection 'default'. connection default; --echo # The below statement should not cause deadlock. --echo # Sending: --send insert into t2 values (1) ---echo # Switching to connection 'con2'. connection con2; --echo # Wait until INSERT starts to wait for FTWRL to go away. let $wait_condition= @@ -622,14 +590,12 @@ let $wait_condition= and info = "insert into t2 values (1)"; --source include/wait_condition.inc ---echo # Switching to connection 'con1'. connection con1; --echo # FTWRL should be able to continue now. --echo # Reap FTWRL. --reap unlock tables; ---echo # Switching to connection 'default'. connection default; --echo # Reap INSERT. --reap @@ -688,7 +654,6 @@ CREATE TRIGGER t1_au AFTER UPDATE ON t1 FOR EACH ROW SET @var = "a"; BEGIN; UPDATE t1 SET value= value + 1 WHERE id = 1; ---echo # Switching to connection 'con1'. connect(con1, localhost, root); --echo # The below FLUSH TABLES WITH READ LOCK should succeed and --echo # should not be blocked by the transaction in default connection. @@ -697,7 +662,6 @@ UNLOCK TABLES; disconnect con1; --source include/wait_until_disconnected.inc ---echo # Switching to connection 'default'. connection default; COMMIT; DROP TABLE t1; diff --git a/mysql-test/t/flush_block_commit.test b/mysql-test/t/flush_block_commit.test index 90443dc9242..6a6120ce63f 100644 --- a/mysql-test/t/flush_block_commit.test +++ b/mysql-test/t/flush_block_commit.test @@ -9,13 +9,9 @@ --echo # Save the initial number of concurrent sessions --source include/count_sessions.inc ---echo # Establish connection con1 (user=root) connect (con1,localhost,root,,); ---echo # Establish connection con2 (user=root) connect (con2,localhost,root,,); ---echo # Establish connection con3 (user=root) connect (con3,localhost,root,,); ---echo # Switch to connection con1 connection con1; --disable_warnings @@ -27,14 +23,11 @@ CREATE TABLE t1 (a INT) ENGINE=innodb; BEGIN; INSERT INTO t1 VALUES(1); ---echo # Switch to connection con2 connection con2; FLUSH TABLES WITH READ LOCK; ---echo # Switch to connection con1 connection con1; --echo # Sending: --send COMMIT ---echo # Switch to connection con2 connection con2; --echo # Wait until COMMIT gets blocked. let $wait_condition= @@ -44,33 +37,26 @@ let $wait_condition= --echo # Verify that 'con1' was blocked and data did not move. SELECT * FROM t1; UNLOCK TABLES; ---echo # Switch to connection con1 connection con1; --echo # Reaping COMMIT --reap # No deadlock ? ---echo # Switch to connection con1 connection con1; BEGIN; SELECT * FROM t1 FOR UPDATE; ---echo # Switch to connection con2 connection con2; BEGIN; send SELECT * FROM t1 FOR UPDATE; # blocked by con1 sleep 1; ---echo # Switch to connection con3 connection con3; send FLUSH TABLES WITH READ LOCK; # blocked by con2 ---echo # Switch to connection con1 connection con1; COMMIT; # should not be blocked by con3 ---echo # Switch to connection con2 connection con2; reap; COMMIT; ---echo # Switch to connection con3 connection con3; reap; UNLOCK TABLES; @@ -78,15 +64,12 @@ UNLOCK TABLES; # Bug#6732 FLUSH TABLES WITH READ LOCK + COMMIT hangs later FLUSH TABLES # WITH READ LOCK ---echo # Switch to connection con2 connection con2; COMMIT; # unlock InnoDB row locks to allow insertions ---echo # Switch to connection con1 connection con1; BEGIN; INSERT INTO t1 VALUES(10); FLUSH TABLES WITH READ LOCK; ---echo # Switch to connection con2 connection con2; FLUSH TABLES WITH READ LOCK; # bug caused hang here UNLOCK TABLES; @@ -100,7 +83,6 @@ COMMIT; --echo # Cleanup ---echo # Switch to connection default and close connections con1, con2, con3 connection default; disconnect con1; disconnect con2; diff --git a/mysql-test/t/flush_block_commit_notembedded.test b/mysql-test/t/flush_block_commit_notembedded.test index fe9dbf7c19e..3d894c5f16c 100644 --- a/mysql-test/t/flush_block_commit_notembedded.test +++ b/mysql-test/t/flush_block_commit_notembedded.test @@ -13,31 +13,24 @@ --source include/count_sessions.inc ---echo # Establish connection con1 (user=root) connect (con1,localhost,root,,); ---echo # Establish connection con2 (user=root) connect (con2,localhost,root,,); # FLUSH TABLES WITH READ LOCK should block writes to binlog too ---echo # Switch to connection con1 connection con1; CREATE TABLE t1 (a INT) ENGINE=innodb; RESET MASTER; SET AUTOCOMMIT=0; SELECT 1; ---echo # Switch to connection con2 connection con2; FLUSH TABLES WITH READ LOCK; --source include/show_binlog_events.inc ---echo # Switch to connection con1 connection con1; send INSERT INTO t1 VALUES (1); ---echo # Switch to connection con2 connection con2; sleep 1; --source include/show_binlog_events.inc UNLOCK TABLES; ---echo # Switch to connection con1 connection con1; reap; DROP TABLE t1; @@ -62,7 +55,6 @@ connection con2; commit; drop table t1; ---echo # Switch to connection default and close connections con1 and con2 connection default; disconnect con1; disconnect con2; diff --git a/mysql-test/t/flush_read_lock.test b/mysql-test/t/flush_read_lock.test index 7ba80ea38ac..4a9752ae9f1 100644 --- a/mysql-test/t/flush_read_lock.test +++ b/mysql-test/t/flush_read_lock.test @@ -231,41 +231,30 @@ unlock tables; --echo # COMMIT is blocked by active FTWRL in another --echo # connection. --echo # ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; begin; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; unlock tables; ---echo # Switching to connection 'default'. connection default; --echo # Do some work so ROLLBACK is not a no-op. insert into t3_trans values (1); ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; rollback; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; unlock tables; ---echo # Switching to connection 'default'. connection default; begin; --echo # Do some work so COMMIT is not a no-op. insert into t3_trans values (1); ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; --echo # Send: --send commit ---echo # Switching to connection '$con_aux1'. connection $con_aux1; --echo # Wait until COMMIT is blocked. let $wait_condition= @@ -274,7 +263,6 @@ let $wait_condition= info = "commit"; --source include/wait_condition.inc unlock tables; ---echo # Switching to connection 'default'. connection default; --echo # Reap COMMIT. --reap @@ -286,11 +274,9 @@ insert into t3_trans values (1); set debug_sync='RESET'; set debug_sync='ha_commit_trans_after_acquire_commit_lock SIGNAL parked WAIT_FOR go'; --send commit ---echo # Switching to connection '$con_aux1'. connection $con_aux1; set debug_sync='now WAIT_FOR parked'; --send flush tables with read lock ---echo # Switching to connection '$con_aux2'. connection $con_aux2; --echo # Wait until FTWRL is blocked. let $wait_condition= @@ -299,16 +285,13 @@ let $wait_condition= info = "flush tables with read lock"; --source include/wait_condition.inc set debug_sync='now SIGNAL go'; ---echo # Switching to connection 'default'. connection default; --echo # Reap COMMIT. --reap ---echo # Switching to connection '$con_aux1'. connection $con_aux1; --echo # Reap FTWRL. --reap unlock tables; ---echo # Switching to connection 'default'. connection default; delete from t3_trans; set debug_sync= "RESET"; @@ -574,13 +557,10 @@ unlock tables; --echo # Check that active FTWRL in another connection --echo # blocks EXECUTE which changes data. --echo # ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; --send execute stmt1 ---echo # Switching to connection '$con_aux1'. connection $con_aux1; --echo # Check that EXECUTE is blocked. let $wait_condition= @@ -589,18 +569,15 @@ let $wait_condition= info = "insert into t1_base values (1)"; --source include/wait_condition.inc unlock tables; ---echo # Switching to connection 'default'. connection default; --echo # Reap EXECUTE. --reap set debug_sync='RESET'; set debug_sync='execute_command_after_close_tables SIGNAL parked WAIT_FOR go'; --send execute stmt1; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; set debug_sync='now WAIT_FOR parked'; --send flush tables with read lock ---echo # Switching to connection '$con_aux2'. connection $con_aux2; --echo # Wait until FTWRL is blocked. let $wait_condition= @@ -609,16 +586,13 @@ let $wait_condition= info = "flush tables with read lock"; --source include/wait_condition.inc set debug_sync='now SIGNAL go'; ---echo # Switching to connection 'default'. connection default; --echo # Reap EXECUTE. --reap ---echo # Switching to connection '$con_aux1'. connection $con_aux1; --echo # Reap FTWRL. --reap unlock tables; ---echo # Switching to connection 'default'. connection default; set debug_sync= "RESET"; delete from t1_base; @@ -808,23 +782,18 @@ drop trigger t1_bi; --echo # Check that FTWRL statements can be run while FTWRL --echo # is active in another connection. --echo # ---echo # Switching to connection '$con_aux1'. flush tables with read lock; --echo # The second FTWRL in a row is allowed at the moment. --echo # It does not make much sense as it does only flush. flush tables with read lock; unlock tables; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; flush tables with read lock; unlock tables; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; unlock tables; ---echo # Switching to connection 'default'. connection default; --echo # @@ -836,23 +805,17 @@ flush tables with read lock; --echo # It does not make much sense though. flush tables t1_base, t2_base with read lock; unlock tables; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; flush tables t1_base, t2_base with read lock; unlock tables; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; unlock tables; ---echo # Switching to connection 'default'. connection default; flush tables t1_base, t2_base with read lock; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; --send flush tables with read lock ---echo # Switching to connection '$con_aux2'. connection $con_aux2; --echo # Wait until FTWRL is blocked. let $wait_condition= @@ -860,15 +823,12 @@ let $wait_condition= where state = "Waiting for table flush" and info = "flush tables with read lock"; --source include/wait_condition.inc ---echo # Switching to connection 'default'. connection default; unlock tables; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; --echo # Reap FTWRL. --reap unlock tables; ---echo # Switching to connection 'default'. connection default; @@ -915,18 +875,14 @@ unlock tables; --echo # Check that HANDLER statements can be run while FTWRL --echo # is active in another connection. --echo # ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; handler t1_base open; handler t1_base read first; handler t1_base close; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; unlock tables; ---echo # Switching to connection 'default'. connection default; @@ -984,29 +940,23 @@ unlock tables; --echo # Check that KILL statements can be run while FTWRL --echo # is active in another connection. --echo # ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; --error ER_QUERY_INTERRUPTED kill query @id; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; unlock tables; ---echo # Switching to connection 'default'. connection default; --echo # Finally check that KILL doesn't block FTWRL set debug_sync='RESET'; set debug_sync='execute_command_after_close_tables SIGNAL parked WAIT_FOR go'; --send kill query @id ---echo # Switching to connection '$con_aux1'. connection $con_aux1; set debug_sync='now WAIT_FOR parked'; flush tables with read lock; unlock tables; set debug_sync='now SIGNAL go'; ---echo # Switching to connection 'default'. connection default; --echo # Reap KILL. --error ER_QUERY_INTERRUPTED @@ -1043,17 +993,13 @@ flush tables with read lock; lock tables t1_base read; unlock tables; --echo # ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; lock tables t1_base read; unlock tables; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; unlock tables; ---echo # Switching to connection 'default'. connection default; --echo # @@ -1064,13 +1010,10 @@ flush tables with read lock; lock tables t1_base write; unlock tables; --echo # ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; --send lock tables t1_base write ---echo # Switching to connection '$con_aux1'. connection $con_aux1; --echo # Check that LOCK TABLES WRITE is blocked. let $wait_condition= @@ -1079,7 +1022,6 @@ let $wait_condition= info = "lock tables t1_base write"; --source include/wait_condition.inc unlock tables; ---echo # Switching to connection 'default'. connection default; --echo # Reap LOCK TABLES WRITE --reap @@ -1093,17 +1035,13 @@ flush tables with read lock; lock tables t1_temp write; unlock tables; --echo # ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; lock tables t1_temp write; unlock tables; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; unlock tables; ---echo # Switching to connection 'default'. connection default; @@ -1116,13 +1054,10 @@ flush tables with read lock; optimize table t1_base; unlock tables; --echo # ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; --send optimize table t1_base ---echo # Switching to connection '$con_aux1'. connection $con_aux1; --echo # Check that OPTIMIZE TABLE is blocked. let $wait_condition= @@ -1131,7 +1066,6 @@ let $wait_condition= info = "optimize table t1_base"; --source include/wait_condition.inc unlock tables; ---echo # Switching to connection 'default'. connection default; --echo # Reap OPTIMIZE TABLE --reap @@ -1191,43 +1125,31 @@ commit; --echo # Check that these statements are not blocked by --echo # active FTWRL in another connection. --echo # ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; begin; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; unlock tables; ---echo # Switching to connection 'default'. connection default; --echo # Do some changes to avoid SAVEPOINT and friends --echo # being almost no-ops. insert into t3_trans values (1); ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; savepoint sv1; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; unlock tables; ---echo # Switching to connection 'default'. connection default; insert into t3_trans values (2); ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; rollback to savepoint sv1; release savepoint sv1; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; unlock tables; ---echo # Switching to connection 'default'. connection default; rollback; --echo # Check that these statements don't block FTWRL in @@ -1239,38 +1161,32 @@ insert into t3_trans values (1); set debug_sync='RESET'; set debug_sync='execute_command_after_close_tables SIGNAL parked WAIT_FOR go'; --send savepoint sv1 ---echo # Switching to connection '$con_aux1'. connection $con_aux1; set debug_sync='now WAIT_FOR parked'; flush tables with read lock; unlock tables; set debug_sync='now SIGNAL go'; ---echo # Switching to connection 'default'. connection default; --echo # Reap SAVEPOINT --reap insert into t3_trans values (2); set debug_sync='execute_command_after_close_tables SIGNAL parked WAIT_FOR go'; --send rollback to savepoint sv1 ---echo # Switching to connection '$con_aux1'. connection $con_aux1; set debug_sync='now WAIT_FOR parked'; flush tables with read lock; unlock tables; set debug_sync='now SIGNAL go'; ---echo # Switching to connection 'default'. connection default; --echo # Reap ROLLBACK TO SAVEPOINT --reap set debug_sync='execute_command_after_close_tables SIGNAL parked WAIT_FOR go'; --send release savepoint sv1 ---echo # Switching to connection '$con_aux1'. connection $con_aux1; set debug_sync='now WAIT_FOR parked'; flush tables with read lock; unlock tables; set debug_sync='now SIGNAL go'; ---echo # Switching to connection 'default'. connection default; --echo # Reap RELEASE SAVEPOINT --reap @@ -1304,13 +1220,10 @@ flush tables with read lock; repair table t1_base; unlock tables; --echo # ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; --send repair table t1_base ---echo # Switching to connection '$con_aux1'. connection $con_aux1; --echo # Check that REPAIR TABLE is blocked. let $wait_condition= @@ -1319,7 +1232,6 @@ let $wait_condition= info = "repair table t1_base"; --source include/wait_condition.inc unlock tables; ---echo # Switching to connection 'default'. connection default; --echo # Reap REPAIR TABLE --reap @@ -1496,28 +1408,21 @@ delete from t3_temp_trans; --echo # SET AUTOCOMMIT=1 is blocked by active FTWRL in --echo # another connection. --echo # ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; set autocommit= 0; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; unlock tables; ---echo # Switching to connection 'default'. connection default; --echo # Do some work so implicit commit in SET AUTOCOMMIT=1 --echo # is not a no-op. insert into t3_trans values (1); ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; --echo # Send: --send set autocommit= 1 ---echo # Switching to connection '$con_aux1'. connection $con_aux1; --echo # Wait until SET AUTOCOMMIT=1 is blocked. let $wait_condition= @@ -1526,7 +1431,6 @@ let $wait_condition= info = "set autocommit= 1"; --source include/wait_condition.inc unlock tables; ---echo # Switching to connection 'default'. connection default; --echo # Reap SET AUTOCOMMIT=1. --reap @@ -1538,11 +1442,9 @@ insert into t3_trans values (1); set debug_sync='RESET'; set debug_sync='ha_commit_trans_after_acquire_commit_lock SIGNAL parked WAIT_FOR go'; --send set autocommit= 1 ---echo # Switching to connection '$con_aux1'. connection $con_aux1; set debug_sync='now WAIT_FOR parked'; --send flush tables with read lock ---echo # Switching to connection '$con_aux2'. connection $con_aux2; --echo # Wait until FTWRL is blocked. let $wait_condition= @@ -1551,16 +1453,13 @@ let $wait_condition= info = "flush tables with read lock"; --source include/wait_condition.inc set debug_sync='now SIGNAL go'; ---echo # Switching to connection 'default'. connection default; --echo # Reap SET AUTOCOMMIT=1. --reap ---echo # Switching to connection '$con_aux1'. connection $con_aux1; --echo # Reap FTWRL. --reap unlock tables; ---echo # Switching to connection 'default'. connection default; delete from t3_trans; set debug_sync= "RESET"; @@ -1698,44 +1597,33 @@ unlock tables; --echo # Check that XA non-COMMIT statements are not and COMMIT is --echo # blocked by active FTWRL in another connection --echo # ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; xa start 'test1'; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; unlock tables; ---echo # Switching to connection 'default'. connection default; insert into t3_trans values (1); ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; xa end 'test1'; xa prepare 'test1'; xa rollback 'test1'; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; unlock tables; ---echo # Switching to connection 'default'. connection default; xa start 'test1'; insert into t3_trans values (1); ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; connection default; xa end 'test1'; xa prepare 'test1'; --echo # Send: --send xa commit 'test1'; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; --echo # Wait until XA COMMIT is blocked. let $wait_condition= @@ -1744,7 +1632,6 @@ let $wait_condition= info = "xa commit 'test1'"; --source include/wait_condition.inc unlock tables; ---echo # Switching to connection 'default'. connection default; --echo # Reap XA COMMIT. --reap @@ -1758,11 +1645,9 @@ xa prepare 'test1'; set debug_sync='RESET'; set debug_sync='trans_xa_commit_after_acquire_commit_lock SIGNAL parked WAIT_FOR go'; --send xa commit 'test1' ---echo # Switching to connection '$con_aux1'. connection $con_aux1; set debug_sync='now WAIT_FOR parked'; --send flush tables with read lock ---echo # Switching to connection '$con_aux2'. connection $con_aux2; --echo # Wait until FTWRL is blocked. let $wait_condition= @@ -1771,16 +1656,13 @@ let $wait_condition= info = "flush tables with read lock"; --source include/wait_condition.inc set debug_sync='now SIGNAL go'; ---echo # Switching to connection 'default'. connection default; --echo # Reap XA COMMIT. --reap ---echo # Switching to connection '$con_aux1'. connection $con_aux1; --echo # Reap FTWRL. --reap unlock tables; ---echo # Switching to connection 'default'. connection default; delete from t3_trans; set debug_sync= "RESET"; @@ -1841,13 +1723,10 @@ flush tables with read lock; analyze table t3_trans; unlock tables; --echo # ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; --send analyze table t3_trans ---echo # Switching to connection '$con_aux1'. connection $con_aux1; --echo # Check that ANALYZE TABLE is blocked. let $wait_condition= @@ -1856,7 +1735,6 @@ let $wait_condition= info = "analyze table t3_trans"; --source include/wait_condition.inc unlock tables; ---echo # Switching to connection 'default'. connection default; --echo # Reap ANALYZE TABLE --reap @@ -1920,13 +1798,10 @@ let $cleanup_stmt= alter table t3_temp_trans drop column c1; begin; insert into t3_trans values (1); --echo # ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; --send check table t1_base ---echo # Switching to connection '$con_aux1'. connection $con_aux1; --echo # Check that CHECK TABLE is blocked. let $wait_condition= @@ -1935,20 +1810,16 @@ let $wait_condition= info = "check table t1_base"; --source include/wait_condition.inc unlock tables; ---echo # Switching to connection 'default'. connection default; --echo # Reap CHECK TABLE --reap begin; delete from t3_trans; --echo # ---echo # Switching to connection '$con_aux1'. connection $con_aux1; flush tables with read lock; ---echo # Switching to connection 'default'. connection default; --send alter table t1_temp add column c1 int ---echo # Switching to connection '$con_aux1'. connection $con_aux1; --echo # Check that ALTER TABLE is blocked. let $wait_condition= @@ -1957,7 +1828,6 @@ let $wait_condition= info = "alter table t1_temp add column c1 int"; --source include/wait_condition.inc unlock tables; ---echo # Switching to connection 'default'. connection default; --echo # Reap ALTER TABLE --reap @@ -1974,21 +1844,17 @@ alter table t1_temp drop column c1; begin; insert into t1_base values (1); insert into t3_trans values (1); ---echo # Switching to connection '$con_aux1'. connection $con_aux1; --echo # The below FTWRL should not be blocked by transaction in 'default'. flush tables with read lock; ---echo # Switching to connection 'default'. connection default; --echo # Transaction still is able to read even with FTWRL active in another --echo # connection. select * from t1_base; select * from t2_base; select * from t3_trans; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; unlock tables; ---echo # Switching to connection 'default'. connection default; commit; delete from t1_base; @@ -2004,11 +1870,9 @@ delete from t3_trans; set debug_sync='RESET'; set debug_sync='execute_command_after_close_tables SIGNAL parked WAIT_FOR go'; --send insert into t1_base values (1) ---echo # Switching to connection '$con_aux1'. connection $con_aux1; set debug_sync='now WAIT_FOR parked'; --send flush tables with read lock ---echo # Switching to connection '$con_aux2'. connection $con_aux2; --echo # Wait until FTWRL is blocked. let $wait_condition= @@ -2018,7 +1882,6 @@ let $wait_condition= --source include/wait_condition.inc --echo # Try to run another INSERT and see that it is blocked. --send insert into t2_base values (1); ---echo # Switching to connection 'con3'. connection con3; --echo # Wait until new INSERT is blocked. let $wait_condition= @@ -2027,20 +1890,16 @@ let $wait_condition= info = "insert into t2_base values (1)"; --echo # Unblock INSERT in the first connection. set debug_sync='now SIGNAL go'; ---echo # Switching to connection 'default'. connection default; --echo # Reap first INSERT. --reap ---echo # Switching to connection '$con_aux1'. connection $con_aux1; --echo # Reap FTWRL. --reap unlock tables; ---echo # Switching to connection '$con_aux2'. connection $con_aux2; --echo # Reap second INSERT. --reap ---echo # Switching to connection 'default'. connection default; set debug_sync= "RESET"; delete from t1_base; @@ -2056,22 +1915,18 @@ delete from t2_base; --echo # only taken when there were such modifications. --echo flush tables with read lock; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; --echo # The below FTWRL should not be blocked by transaction in 'default'. flush tables with read lock; ---echo # Switching to connection 'default'. connection default; select * from t1_base; select * from t3_trans; commit; ---echo # Switching to connection '$con_aux1'. connection $con_aux1; select * from t1_base; select * from t3_trans; commit; unlock tables; ---echo # Switching to connection 'default'. connection default; unlock tables; diff --git a/mysql-test/t/flush_read_lock_kill.test b/mysql-test/t/flush_read_lock_kill.test index a672fa5dfc5..d83e5b3f1df 100644 --- a/mysql-test/t/flush_read_lock_kill.test +++ b/mysql-test/t/flush_read_lock_kill.test @@ -26,7 +26,6 @@ SET DEBUG_SYNC= 'RESET'; CREATE TABLE t1 (kill_id INT) engine = InnoDB; INSERT INTO t1 VALUES(connection_id()); ---echo # Switching to connection 'default'. connection default; --echo # Start transaction. BEGIN; @@ -38,7 +37,6 @@ SET DEBUG_SYNC='ha_commit_trans_after_acquire_commit_lock SIGNAL acquired WAIT_F --echo # Sending: --send COMMIT ---echo # Switching to 'con1'. connection con1; --echo # Wait till COMMIT acquires protection against global read --echo # lock and pauses. @@ -46,7 +44,6 @@ SET DEBUG_SYNC='now WAIT_FOR acquired'; --echo # Sending: send FLUSH TABLES WITH READ LOCK; ---echo # Switching to 'con2'. connection con2; SELECT ((@id := kill_id) - kill_id) FROM t1 LIMIT 1; @@ -61,19 +58,16 @@ let $wait_condition= --echo # Kill connection 'con1'. KILL CONNECTION @id; ---echo # Switching to 'con1'. connection con1; --echo # Try to reap FLUSH TABLES WITH READ LOCK, --echo # it fail due to killed statement and connection. --error 1317,2013 reap; ---echo # Switching to 'con2'. connection con2; --echo # Resume COMMIT. SET DEBUG_SYNC='now SIGNAL go'; ---echo # Switching to 'default'. connection default; --echo # Reaping COMMIT. --reap diff --git a/mysql-test/t/func_analyse.test b/mysql-test/t/func_analyse.test index c77967a0cc9..d99f5c0fa9a 100644 --- a/mysql-test/t/func_analyse.test +++ b/mysql-test/t/func_analyse.test @@ -11,7 +11,7 @@ insert into t1 values (1,2,"","Y","2002-03-03"), (3,4,"","N","2002-03-04"), (5,6 select count(*) from t1 procedure analyse(); select * from t1 procedure analyse(); select * from t1 procedure analyse(2); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR create table t2 select * from t1 procedure analyse(); drop table t1; @@ -127,7 +127,7 @@ CREATE TABLE t1(a INT); INSERT INTO t1 VALUES (1),(2); --echo # should not crash ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR CREATE TABLE t2 SELECT 1 FROM t1, t1 t3 GROUP BY t3.a PROCEDURE ANALYSE(); DROP TABLE t1; @@ -157,3 +157,27 @@ SELECT * FROM t2 LIMIT 1 PROCEDURE ANALYSE(); DROP TABLE t1, t2; --echo End of 5.1 tests + +--echo # +--echo # Start of 10.2 tests +--echo # +(SELECT 1 FROM DUAL PROCEDURE ANALYSE()); +((SELECT 1 FROM DUAL PROCEDURE ANALYSE())); + +# TODO: +--error ER_PARSE_ERROR +SELECT * FROM t1 UNION SELECT * FROM t1 PROCEDURE analyse(); + +--echo # +--echo # MDEV-10030 sql_yacc.yy: Split table_expression and remove PROCEDURE from create_select, select_paren_derived, select_derived2, query_specification +--echo # + +--error ER_PARSE_ERROR +SELECT * FROM (SELECT * FROM t1 PROCEDURE ANALYSE()); +--ERROR ER_PARSE_ERROR +SELECT * FROM t1 NATURAL JOIN (SELECT * FROM t2 PROCEDURE ANALYSE()); + +--error ER_PARSE_ERROR +SELECT (SELECT 1 FROM t1 PROCEDURE ANALYSE()) FROM t2; +--error ER_PARSE_ERROR +SELECT ((SELECT 1 FROM t1 PROCEDURE ANALYSE())) FROM t2; diff --git a/mysql-test/t/func_compress.test b/mysql-test/t/func_compress.test index 6305df3952d..3fd9cad467b 100644 --- a/mysql-test/t/func_compress.test +++ b/mysql-test/t/func_compress.test @@ -171,3 +171,20 @@ DROP TABLE t1; --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-10134 Add full support for DEFAULT +--echo # +CREATE TABLE t1 (a TEXT, b BLOB DEFAULT COMPRESS(a), bl INT DEFAULT UNCOMPRESSED_LENGTH(b), a1 TEXT DEFAULT UNCOMPRESS(b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (REPEAT('a',100)); +SELECT bl, a1 FROM t1; +DROP TABLE t1; + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/func_crypt.test b/mysql-test/t/func_crypt.test index dc4bf4663d5..ab5be573932 100644 --- a/mysql-test/t/func_crypt.test +++ b/mysql-test/t/func_crypt.test @@ -69,8 +69,7 @@ INSERT INTO t1 VALUES (REPEAT('a', 1024)); SELECT OLD_PASSWORD(c1), PASSWORD(c1) FROM t1; DROP TABLE t1; ---echo End of 5.0 tests - +--echo # End of 5.0 tests --echo # --echo # Start of 10.1 tests @@ -92,7 +91,10 @@ SELECT f1 FROM t1 WHERE f1='test' AND (f2= encrypt('test','key' SELECT f1 FROM t1 WHERE f1='test' AND (f2= encrypt('TEST','key') OR f2= encrypt('test','key')); DROP TABLE t1; +--echo # Start of 10.2 tests ---echo # ---echo # End of 10.1 tests ---echo # +CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(30) DEFAULT ENCRYPT(a,123)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('hello'); +SELECT * FROM t1; +DROP TABLE t1; diff --git a/mysql-test/t/func_date_add.test b/mysql-test/t/func_date_add.test index 5f27978347c..3106889fde6 100644 --- a/mysql-test/t/func_date_add.test +++ b/mysql-test/t/func_date_add.test @@ -100,3 +100,34 @@ drop table t1; --echo End of 5.5 tests +# +# how + interval is printed +# + +create or replace view v1 as select 3 & 20010101 + interval 2 day as x; +show create view v1; +select 3 & 20010101 + interval 2 day, x from v1; + +create or replace view v1 as select (3 & 20010101) + interval 2 day as x; +show create view v1; +select (3 & 20010101) + interval 2 day, x from v1; + +create or replace view v1 as select 3 & (20010101 + interval 2 day) as x; +show create view v1; +select 3 & (20010101 + interval 2 day), x from v1; + +create or replace view v1 as select 30 + 20010101 + interval 2 day as x; +show create view v1; +select 30 + 20010101 + interval 2 day, x from v1; + +create or replace view v1 as select (30 + 20010101) + interval 2 day as x; +show create view v1; +select (30 + 20010101) + interval 2 day, x from v1; + +create or replace view v1 as select 30 + (20010101 + interval 2 day) as x; +show create view v1; +select 30 + (20010101 + interval 2 day), x from v1; + +drop view v1; + +--echo End of 10.2 tests diff --git a/mysql-test/t/func_default.test b/mysql-test/t/func_default.test index 7bebd4b4b72..fbd73990297 100644 --- a/mysql-test/t/func_default.test +++ b/mysql-test/t/func_default.test @@ -29,3 +29,15 @@ INSERT INTO t1 VALUES (1, 'one'), (2, 'two'), (3, 'three'); SELECT s, 32 AS mi FROM t1 GROUP BY s HAVING DEFAULT(mi) IS NULL; DROP TABLE t1; +# +# 10.2 tests +# + +set timestamp=unix_timestamp('2001-01-01 10:20:30.123456'); +create table t1 (a int default 1, b int default (a+1), + c varchar(100) default 'foo', d text default 'bar', + e timestamp default now(), f timestamp(6) default now(2)); +insert t1 () values (); +insert t1 (a) values (10); +select default(a),default(b),default(c),default(d),default(e),default(f) from t1; +drop table t1; diff --git a/mysql-test/t/func_digest.test b/mysql-test/t/func_digest.test index 39edb64fef2..e7d73b4f368 100644 --- a/mysql-test/t/func_digest.test +++ b/mysql-test/t/func_digest.test @@ -518,5 +518,23 @@ EXECUTE stmt; DEALLOCATE PREPARE stmt; --echo # ---echo # End of 10.1 tests +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-10134 Add full support for DEFAULT +--echo # + +CREATE TABLE t1 ( + a VARCHAR(30), + b TEXT DEFAULT SHA(a), + c TEXT DEFAULT SHA2(a,224) +); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('abc'); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # End of 10.2 tests --echo # diff --git a/mysql-test/t/func_encrypt.test b/mysql-test/t/func_encrypt.test index ed3e0a7b2d1..e27a2bd46d3 100644 --- a/mysql-test/t/func_encrypt.test +++ b/mysql-test/t/func_encrypt.test @@ -121,3 +121,25 @@ DROP TABLE t1; --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-10134 Add full support for DEFAULT +--echo # + +CREATE TABLE t1 ( + a VARCHAR(30), + b BLOB DEFAULT DES_ENCRYPT(a, 'passwd'), + c TEXT DEFAULT DES_DECRYPT(b, 'passwd') +); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('test'); +SELECT c FROM t1; +DROP TABLE t1; + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/func_gconcat.test b/mysql-test/t/func_gconcat.test index 3cc244339d3..bdd295d0fa9 100644 --- a/mysql-test/t/func_gconcat.test +++ b/mysql-test/t/func_gconcat.test @@ -873,3 +873,45 @@ SELECT LENGTH(GROUP_CONCAT(f1 ORDER BY f2)) FROM t1 GROUP BY f2; DROP TABLE t1; SET group_concat_max_len= DEFAULT; + + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-10124 Incorrect usage of CUBE/ROLLUP and ORDER BY with GROUP_CONCAT(a ORDER BY a) +--echo # + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20),(30); + +SELECT a,GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP; +CREATE VIEW v1 AS +SELECT a,GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP; +SELECT * FROM v1; +DROP VIEW v1; + +SELECT a,GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP HAVING GROUP_CONCAT(a ORDER BY a)='10,20,30'; +CREATE VIEW v1 AS +SELECT a,GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP HAVING GROUP_CONCAT(a ORDER BY a)='10,20,30'; +SELECT * FROM v1; +DROP VIEW v1; + +SELECT * FROM (SELECT a,GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP HAVING GROUP_CONCAT(a ORDER BY a)='10,20,30') t1; +CREATE VIEW v1 AS +SELECT * FROM (SELECT a,GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP HAVING GROUP_CONCAT(a ORDER BY a)='10,20,30') t1; +SELECT * FROM v1; +DROP VIEW v1; + +SELECT (SELECT GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP HAVING GROUP_CONCAT(a ORDER BY a)='10,20,30'); +CREATE VIEW v1 AS +SELECT (SELECT GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP HAVING GROUP_CONCAT(a ORDER BY a)='10,20,30'); +SELECT * FROM v1; +DROP VIEW v1; + +DROP TABLE t1; + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/func_json.test b/mysql-test/t/func_json.test new file mode 100644 index 00000000000..7ab136f177c --- /dev/null +++ b/mysql-test/t/func_json.test @@ -0,0 +1,179 @@ +select json_valid('[1, 2]'); +select json_valid('"string"}'); +select json_valid('{"key1":1, "key2":[2,3]}'); +select json_valid('[false, true, null]'); +select json_valid(repeat('[', 1000)); +select json_valid(repeat('{"a":', 1000)); + +select json_value('{"key1":123}', '$.key2'); +select json_value('{"key1":123}', '$.key1'); +select json_value('{"key1":[1,2,3]}', '$.key1'); +select json_value('{"key1": [1,2,3], "key1":123}', '$.key1'); + +select json_query('{"key1":{"a":1, "b":[1,2]}}', '$.key2'); +select json_query('{"key1":{"a":1, "b":[1,2]}}', '$.key1'); +select json_query('{"key1": 1}', '$.key1'); +select json_query('{"key1":123, "key1": [1,2,3]}', '$.key1'); +select json_query('{"key1":123, "key1": [1,2,3]}', concat('$', repeat('.k', 1000))); + +select json_array(); +select json_array(1); +select json_array(1, "text", false, null); + +select json_array_append('["a", "b"]', '$', FALSE); +select json_array_append('{"k1":1, "k2":["a", "b"]}', '$.k2', 2); +select json_array_append('["a", ["b", "c"], "d"]', '$[0]', 2); + +select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[1]', 'x'); +select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[2]', 'x'); +select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[3]', 'x'); +select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[4]', 'x'); +select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[1].b[0]', 'x'); +select json_array_insert('true', '$', 1); +select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[2][1]', 'y'); + +select json_contains('{"k1":123, "k2":345}', '123', '$.k1'); +select json_contains('"you"', '"you"'); +select json_contains('"youth"', '"you"'); +--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT +select json_contains('[1]', '[1]', '$', '$[0]'); +select json_contains('', '', '$'); +select json_contains('null', 'null', '$'); +select json_contains('"10"', '"10"', '$'); +select json_contains('"10"', '10', '$'); +select json_contains('10.1', '10', '$'); +select json_contains('10.0', '10', '$'); +select json_contains('[1]', '1'); +select json_contains('[2, 1]', '1'); +select json_contains('[2, [2, 3], 1]', '1'); +select json_contains('[4, [2, 3], 1]', '2'); +select json_contains('[2, 1]', '[1, 2]'); +select json_contains('[2, 1]', '[1, 0, 2]'); +select json_contains('[2, 0, 3, 1]', '[1, 2]'); +select json_contains('{"b":[1,2], "a":1}', '{"a":1, "b":2}'); +select json_contains('{"a":1}', '{}'); +select json_contains('[1, {"a":1}]', '{}'); +select json_contains('[1, {"a":1}]', '{"a":1}'); +select json_contains('[{"abc":"def", "def":"abc"}]', '["foo","bar"]'); +select json_contains('[{"abc":"def", "def":"abc"}, "bar"]', '["bar", {}]'); + +select json_contains_path('{"key1":1, "key2":[2,3]}', "oNE", "$.key2[1]"); +select json_contains_path('{"key1":1, "key2":[2,3]}', "oNE", "$.key2[10]"); +select json_contains_path('{"key1":1, "key2":[2,3]}', "oNE", "$.ma"); +select json_contains_path('{"key1":1, "key2":[2,3]}', "one", "$.key1"); +select json_contains_path('{"key1":1, "key2":[2,3]}', "one", "$.key1", "$.ma"); +select json_contains_path('{"key1":1, "key2":[2,3]}', "aLl", "$.key1", "$.ma"); +select json_contains_path('{"key1":1, "key2":[2,3]}', "aLl", "$.key1", "$.key2"); +select json_contains_path('{ "a": true }', NULL, '$.a' ); +select json_contains_path('{ "a": true }', 'all', NULL ); +select json_contains_path('{"a":{"b":"c"}}', 'one', '$.a.*'); + +select json_extract('{"key1":"asd", "key2":[2,3]}', "$.key1"); +select json_extract('{"key1":"asd", "key2":[2,3]}', "$.keyX", "$.keyY"); +select json_extract('{"key1":"asd", "key2":[2,3]}', "$.key1", "$.key2"); +select json_extract('{"key1":5, "key2":[2,3]}', "$.key1", "$.key2"); +select json_extract('{"key0":true, "key1":"qwe"}', "$.key1"); +select json_extract(json_object('foo', 'foobar'),'$'); +select json_extract('[10, 20, [30, 40]]', '$[2][*]'); +select json_extract('[10, 20, [{"a":3}, 30, 40]]', '$[2][*]'); +select json_extract('1', '$'); +select json_extract('[10, 20, [30, 40], 1, 10]', '$[1]'); + +select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.b.k1', 'word'); +select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.d[3]', 3); +select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.a[2]', 2); +select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.b.c', 'word'); + +select json_set('{ "a": 1, "b": [2, 3]}', '$.a', 10, '$.c', '[true, false]'); + +select json_replace('{ "a": 1, "b": [2, 3]}', '$.a', 10, '$.c', '[true, false]'); +select json_replace('{ "a": 1, "b": [2, 3]}', '$.a', 10, '$.b', '[true, false]'); + +set @j = '["a", ["b", "c"], "d"]'; +select json_remove(@j, '$[0]'); +select json_remove(@j, '$[1]'); +select json_remove(@j, '$[2]'); +set @j = '{"a": 1, "b": [2, 3]}'; +select json_remove(@j, '$.b'); +select json_remove(@j, '$.a'); + +select json_object(); +select json_object("ki", 1, "mi", "ya"); +create table t1 as select json_object('id', 87, 'name', 'carrot') as f; +show create table t1; +select * from t1; +drop table t1; + +select json_exists('{"key1":"xxxx", "key2":[1, 2, 3]}', "$.key2"); +select json_exists('{"key1":"xxxx", "key2":[1, 2, 3]}', "$.key2[1]"); +select json_exists('{"key1":"xxxx", "key2":[1, 2, 3]}', "$.key2[10]"); + +select json_quote('"string"'); +create table t1 as select json_quote('foo'); +select * from t1; +show create table t1; +drop table t1; + +--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT +select json_merge('string'); +select json_merge('string', 123); +select json_merge('"string"', 123); +select json_merge('[1, 2]', '[true, false]'); +select json_merge('{"1": 2}', '{"true": false}'); +select json_merge('{"1": 2}', '{"true": false}', '{"3": 4}'); +select json_merge(NULL,json_object('foo', 1)); +select json_merge('a','b'); +select json_merge('{"a":"b"}','{"c":"d"}'); +SELECT JSON_MERGE('[1, 2]', '{"id": 47}'); + +select json_type('{"k1":123, "k2":345}'); +select json_type('[123, "k2", 345]'); +select json_type("true"); +select json_type('123'); +select json_type('123.12'); + +select json_keys('{"a":{"c":1, "d":2}, "b":2}'); +select json_keys('{"a":{"c":1, "d":2}, "b":2}', "$.a"); +select json_keys('{"a":{"c":1, "d":2}, "b":2}', "$.b"); +select json_keys('foo'); + +SET @j = '["abc", [{"k": "10"}, "def"], {"x":"abc"}, {"y":"bcd"}]'; +select json_search(@j, 'one', 'abc'); +select json_search(@j, 'all', 'abc'); +select json_search(@j, 'all', 'abc', NULL, '$[2]'); +select json_search(@j, 'all', 'abc', NULL, '$'); +select json_search(@j, 'all', '10', NULL, '$'); +select json_search(@j, 'all', '10', NULL, '$[*]'); +select json_search(@j, 'all', '10', NULL, '$[*][0].k'); +select json_search(@j, 'all', '10', NULL, '$**.k'); +create table t1( json_col text ); +insert into t1 values +('{ "a": "foobar" }'), + ('{ "a": "foobar", "b": "focus", "c": [ "arm", "foot", "shoulder" ] }'); +select json_search( json_col, 'all', 'foot' ) from t1; +drop table t1; + + +select json_unquote('"abc"'); +select json_unquote('abc'); + +select json_object("a", json_object("b", "abcd")); +select json_object("a", '{"b": "abcd"}'); +select json_object("a", cast('{"b": "abcd"}' as json)); + +select cast(NULL AS JSON); +select json_depth(cast(NULL as JSON)); +select json_depth('[[], {}]'); +select json_depth('[[[1,2,3],"s"], {}, []]'); +select json_depth('[10, {"a": 20}]'); + +select json_length(''); +select json_length('{}'); +select json_length('[1, 2, {"a": 3}]'); +select json_length('{"a": 1, "b": {"c": 30}}', '$.b'); +select json_length('{"a": 1, "b": {"c": 30}}'); + +create table json (j INT); +show create table json; +drop table json; + diff --git a/mysql-test/t/func_like.test b/mysql-test/t/func_like.test index d1b9b170a3b..b65bff63298 100644 --- a/mysql-test/t/func_like.test +++ b/mysql-test/t/func_like.test @@ -185,3 +185,25 @@ DROP TABLE t1; --echo # --echo # End of 10.1 tests --echo # + +# +# Item_func_line::print() +# +create view v1 as select 'foo!' like 'foo!!', 'foo!' like 'foo!!' escape '!'; +show create view v1; +select * from v1; +drop view v1; + +create table t1 (a varchar(100), + b int default (a like '%f\\_'), + c int default (a like '%f\\_' escape ''), + d int default (a like '%f\\_' escape '\\')); +show create table t1; +insert t1 (a) values ('1 f_'), ('1 f\\_'); +set sql_mode=no_backslash_escapes; +insert t1 (a) values ('2 f_'), ('2 f\_'); +flush tables; +insert t1 (a) values ('3 f_'), ('3 f\_'); +set sql_mode=default; +select * from t1; +drop table t1; diff --git a/mysql-test/t/func_math.test b/mysql-test/t/func_math.test index 8cacb4c575a..08349f007e1 100644 --- a/mysql-test/t/func_math.test +++ b/mysql-test/t/func_math.test @@ -597,5 +597,14 @@ DROP TABLE t1; SELECT STDDEV_POP(ROUND(0,@A:=2009)) FROM (SELECT 1 UNION SELECT 2) fake_table; --echo # ---echo # End of 10.0 tests +--echo # Start of 10.2 tests --echo # + +--echo # Test zero +select 0=0, 0=-0, 0.0= -0.0, 0.0 = -(0.0), 0.0E1=-0.0E1, 0.0E1=-(0.0E1); + +--echo # +--echo # CRC32 tests +--echo # + +select CRC32(NULL), CRC32(''), CRC32('MySQL'), CRC32('mysql'), CRC32('01234567'), CRC32('012345678'); diff --git a/mysql-test/t/func_misc.test b/mysql-test/t/func_misc.test index b874700f29d..f931352c0e2 100644 --- a/mysql-test/t/func_misc.test +++ b/mysql-test/t/func_misc.test @@ -627,7 +627,6 @@ select is_free_lock('test'); select is_used_lock('test') = connection_id(); connect (con1,localhost,root,,); ---echo # -> Switching to connection 'con1' connection con1; --echo # IS_USED_LOCK, IS_FREE_LOCK: the lock is acquired in another --echo # connection @@ -640,7 +639,6 @@ select get_lock('test', 0); --echo # RELEASE_LOCK returns 0 if the lock belongs to another connection select release_lock('test'); ---echo # -> Switching to connection 'default' connection default; --echo # RELEASE_LOCK returns 1 if it successfully releases a lock @@ -650,23 +648,19 @@ select release_lock('test'); --echo # Test that get_lock() returns NULL if error. select get_lock('test', 0); ---echo # -> Switching to connection 'con1' connection con1; create table t1 select connection_id() as id; send select get_lock('test', 7200); ---echo # -> Switching to connection 'default' connection default; let $wait_condition= SELECT count(*) > 0 FROM information_schema.processlist WHERE info LIKE 'select%' AND state='User lock'; source include/wait_condition.inc; select (@id := id) - id from t1; kill query @id; ---echo # -> Switching to connection 'con1' connection con1; reap; ---echo # -> Switching to connection 'default' connection default; --echo # GET_LOCK() works recursively @@ -696,12 +690,10 @@ select release_lock('test3'); --echo # Deadlocks are detected e.g. in case of a mutual wait select get_lock('test1', 0); ---echo # -> Switching to connection 'con1' connection con1; select get_lock('test2', 0); send select get_lock('test1', 7200); ---echo # -> Switching to connection 'default' connection default; let $wait_condition= SELECT count(*) > 0 FROM information_schema.processlist WHERE info LIKE 'select%' AND state='User lock'; source include/wait_condition.inc; @@ -710,13 +702,11 @@ select get_lock('test2', 7200); select release_lock('test1'); ---echo # -> Switching to connection 'con1' connection con1; reap; select release_lock('test2'); select release_lock('test1'); ---echo # -> Switching to connection 'default' connection default; --echo # LOCK/UNLOCK TABLES works fine with a user lock. @@ -748,12 +738,10 @@ select release_lock('test2'); --echo # are detected OK. select get_lock('test', 0); ---echo # -> Switching to connection 'con1' connection con1; lock table t1 write; send select get_lock('test', 7200); ---echo # -> Switching to connection 'default' connection default; let $wait_condition= SELECT count(*) > 0 FROM information_schema.processlist WHERE info LIKE 'select%' AND state = 'User lock'; source include/wait_condition.inc; @@ -762,7 +750,6 @@ lock table t1 read; select release_lock('test'); ---echo # -> Switching to connection 'con1' connection con1; reap; select release_lock('test'); @@ -1081,7 +1068,6 @@ DROP TABLE t2; --echo # MDEV-4018 : Microseconds in GET_LOCK() --echo # ---echo # -> Switching to connection 'default' connection default; select is_used_lock('test') = connection_id(); @@ -1089,7 +1075,6 @@ select is_used_lock('test') = connection_id(); select get_lock('test', 0); connect (con1,localhost,root,,); ---echo # -> Switching to connection 'con1' connection con1; select is_used_lock('test') = connection_id(); select get_lock('test', 0); @@ -1099,7 +1084,6 @@ select get_lock('test', 0.1); select get_lock('test', 0.000001); select get_lock('test', 0.0000000000000001); ---echo # -> Switching to connection 'default' connection default; select is_used_lock('test') = connection_id(); select release_lock('test'); @@ -1107,3 +1091,39 @@ select release_lock('test'); --echo --echo # -- Done. --echo + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-10134 Add full support for DEFAULT +--echo # + +CREATE TABLE t1 ( + a VARCHAR(30), + b BIGINT DEFAULT INET_ATON(a), + a1 VARCHAR(30) DEFAULT INET_NTOA(b), + c INT DEFAULT IS_IPV4(a), + d INT DEFAULT IS_IPV6(a) +); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('192.168.001.001'),('::1'),('xxx'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + str VARCHAR(128), + addr VARBINARY(16) DEFAULT INET6_ATON(str), + str1 VARCHAR(128) DEFAULT INET6_NTOA(addr), + b INT DEFAULT IS_IPV4_COMPAT(addr), + c INT DEFAULT IS_IPV4_MAPPED(addr) +); +SHOW CREATE TABLE t1; +INSERT INTO t1 (str) VALUES ('::FFFF:192.168.0.1'),('::10.0.5.9'); +SELECT str, str1, b,c FROM t1; +DROP TABLE t1; + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/func_test.test b/mysql-test/t/func_test.test index b7bca957e5b..d1c0702da80 100644 --- a/mysql-test/t/func_test.test +++ b/mysql-test/t/func_test.test @@ -179,6 +179,8 @@ explain extended select not (a+0) from t1; select * from t1 where not (a+0); explain extended select * from t1 where not (a+0); +select not 1, not null, not not null, 1 is not null; + drop table t1; --echo # diff --git a/mysql-test/t/func_weight_string.test b/mysql-test/t/func_weight_string.test index b8fdfd8b250..b376b996556 100644 --- a/mysql-test/t/func_weight_string.test +++ b/mysql-test/t/func_weight_string.test @@ -147,3 +147,27 @@ DROP TABLE t1; --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-10134 Add full support for DEFAULT +--echo # +CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET latin1, b VARBINARY(10) DEFAULT WEIGHT_STRING(a AS CHAR(10))); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('a'); +SELECT a, HEX(b) FROM t1; +DROP TABLE t1; + +# +# Item_func_weight_string::print() +# +create view v1 as select weight_string("MySQL" as char(4)); +select * from v1; +drop view v1; + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/gis-debug.test b/mysql-test/t/gis-debug.test index a0647a2c9f4..4b36a8e20e0 100644 --- a/mysql-test/t/gis-debug.test +++ b/mysql-test/t/gis-debug.test @@ -4,3 +4,19 @@ SET @tmp=ST_GIS_DEBUG(1); --source include/gis_debug.inc + + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-10134 Add full support for DEFAULT +--echo # + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 (a INT DEFAULT ST_GIS_DEBUG(1)); + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/gis.test b/mysql-test/t/gis.test index 18cfe95b749..09d7a29744f 100644 --- a/mysql-test/t/gis.test +++ b/mysql-test/t/gis.test @@ -1525,3 +1525,197 @@ CREATE TABLE t1 (g1 GEOMETRY NOT NULL,g2 GEOMETRY NULL); CREATE TABLE t2 AS SELECT WITHIN(g1,g1) as w1,WITHIN(g2,g2) AS w2 FROM t1; SHOW CREATE TABLE t2; DROP TABLE t1,t2; + +--echo # +--echo # Start of 10.2 tests +--echo # + +# +# Item_func_spatial_collection::print() +# +create view v1 as select AsWKT(GeometryCollection(Point(44, 6), LineString(Point(3, 6), Point(7, 9)))); +show create view v1; +select * from v1; +drop view v1; + +--echo # +--echo # MDEV-10134 Add full support for DEFAULT +--echo # + +CREATE TABLE t1 (a POINT, x DOUBLE DEFAULT x(a), y DOUBLE DEFAULT y(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (Point(1,2)); +SELECT x,y FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (g GEOMETRY, area DOUBLE DEFAULT ST_AREA(g)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (g) VALUES (GeomFromText('POLYGON((0 0,20 0,20 20,0 20,0 0))')); +SELECT area FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (g GEOMETRY, length DOUBLE DEFAULT ST_LENGTH(g)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (g) VALUES (GeomFromText('LINESTRING(0 0,20 0,20 20,0 20,0 0)')); +SELECT length FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (g POINT, distance DOUBLE DEFAULT ST_DISTANCE(g, POINT(0,0))); +SHOW CREATE TABLE t1; +INSERT INTO t1 (g) VALUES (Point(1,0)); +SELECT distance FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TEXT, g GEOMETRY DEFAULT GeomFromText(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('point(1 1)'); +SELECT AsText(g) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (x INT, y INT, g GEOMETRY DEFAULT POINT(x,y)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (x,y) VALUES (10,20); +SELECT AsText(g) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT PointN(a,2)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('LineString(1 1,2 2,3 3)')); +SELECT AsText(b) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT StartPoint(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('LineString(1 1,2 2,3 3)')); +SELECT AsText(b) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY, c GEOMETRY DEFAULT GeometryCollection(a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES (Point(1,1), Point(2,2)); +SELECT AsText(c) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT GeomFromWKB(AsBinary(a),20)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('POINT(1 1)', 10)); +SELECT AsText(a), SRID(a), AsText(b), SRID(b) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT BOUNDARY(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))')); +SELECT AsText(b) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT BUFFER(a,10)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))')); +SELECT GeometryType(b) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT CENTROID(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))')); +SELECT AsText(b) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT ENVELOPE(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('LineString(1 1,4 4)')); +SELECT AsText(b) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT PointOnSurface(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))')); +SELECT GeometryType(b) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT Point(1,1), c GEOMETRY DEFAULT ST_UNION(a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (Point(0,0)); +SELECT AsText(c) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b VARCHAR(20) DEFAULT GeometryType(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (Point(0, 0)); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT IsSimple(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (Point(0, 0)); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT IsEmpty(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (Point(0, 0)); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT IsRing(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('LineString(0 0,0 1,1 1,1 0,0 0)')); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT IsClosed(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('LineString(0 0,0 1,1 1,1 0,0 0)')); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT Dimension(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (Buffer(Point(1,1),1)); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT NumGeometries(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (ST_UNION(Point(1,1),Point(0,0))); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT NumInteriorRings(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))')); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT NumPoints(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (LineString(Point(1,1),Point(0,0))); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT SRID(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('Point(1 1)', 100)); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY, c INT DEFAULT MBRDisjoint(a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES (Point(1,1),Point(1,1)); +SELECT c FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY, c INT DEFAULT ST_Disjoint(a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES (Point(1,1),Point(1,1)); +SELECT c FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY, c INT DEFAULT ST_Relate(a,b,'T*F**FFF*')); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES (Point(1,1),Point(1,1)); +SELECT c FROM t1; +DROP TABLE t1; + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/grant.test b/mysql-test/t/grant.test index 1d828cd8693..b816afed851 100644 --- a/mysql-test/t/grant.test +++ b/mysql-test/t/grant.test @@ -1037,8 +1037,6 @@ GRANT ALL PRIVILEGES ON test.* TO mysqltest_1@localhost; # Test. --connect (bug9504_con1,localhost,mysqltest_1,,) ---echo ---echo ---> connection: bug9504_con1 # - Check that we can switch to the db; @@ -1065,9 +1063,6 @@ SELECT mysqltest4.f_inv(); # Cleanup. --connection default ---echo ---echo ---> connection: default - --disconnect bug9504_con1 DROP DATABASE mysqltest1; @@ -1106,8 +1101,6 @@ CREATE PROCEDURE mysqltest1.p1() SQL SECURITY INVOKER # Test. --connect (bug27337_con1,localhost,mysqltest_1,,mysqltest2) ---echo ---echo ---> connection: bug27337_con1 --error ER_TABLEACCESS_DENIED_ERROR CREATE TABLE t1(c INT); @@ -1120,8 +1113,6 @@ CREATE TABLE t1(c INT); --disconnect bug27337_con1 --connect (bug27337_con2,localhost,mysqltest_1,,mysqltest2) ---echo ---echo ---> connection: bug27337_con2 --error ER_TABLEACCESS_DENIED_ERROR CREATE TABLE t1(c INT); @@ -1131,9 +1122,6 @@ SHOW TABLES; # Cleanup. --connection default ---echo ---echo ---> connection: default - --disconnect bug27337_con2 DROP DATABASE mysqltest1; @@ -1162,8 +1150,6 @@ GRANT SELECT ON mysqltest2.t2 TO mysqltest_2@localhost; # Test. --connect (bug27337_con1,localhost,mysqltest_1,,mysqltest1) ---echo ---echo ---> connection: bug27337_con1 SHOW TABLES FROM mysqltest1; @@ -1172,8 +1158,6 @@ PREPARE stmt1 FROM 'SHOW TABLES FROM mysqltest1'; EXECUTE stmt1; --connect (bug27337_con2,localhost,mysqltest_2,,mysqltest2) ---echo ---echo ---> connection: bug27337_con2 SHOW COLUMNS FROM mysqltest2.t2; @@ -1182,15 +1166,11 @@ PREPARE stmt2 FROM 'SHOW COLUMNS FROM mysqltest2.t2'; EXECUTE stmt2; --connection default ---echo ---echo ---> connection: default REVOKE SELECT ON mysqltest1.t1 FROM mysqltest_1@localhost; REVOKE SELECT ON mysqltest2.t2 FROM mysqltest_2@localhost; --connection bug27337_con1 ---echo ---echo ---> connection: bug27337_con1 --error ER_DBACCESS_DENIED_ERROR SHOW TABLES FROM mysqltest1; @@ -1199,8 +1179,6 @@ SHOW TABLES FROM mysqltest1; EXECUTE stmt1; --connection bug27337_con2 ---echo ---echo ---> connection: bug27337_con2 --error ER_TABLEACCESS_DENIED_ERROR SHOW COLUMNS FROM mysqltest2.t2; @@ -1211,8 +1189,6 @@ EXECUTE stmt2; # Cleanup. --connection default ---echo ---echo ---> connection: default --disconnect bug27337_con1 --disconnect bug27337_con2 @@ -1321,8 +1297,6 @@ GRANT SELECT(b) ON t1 TO testuser@localhost; GRANT SELECT ON t2 TO testuser@localhost; GRANT SELECT ON mysqltest2.* TO testuser@localhost; ---echo ---echo # Connection: bug57952_con1 (testuser@localhost, db: mysqltest1) --connect (bug57952_con1,localhost,testuser,,mysqltest1) PREPARE s1 FROM 'SELECT b FROM t1'; PREPARE s2 FROM 'SELECT a FROM t2'; @@ -1336,16 +1310,12 @@ CALL p1; CALL p2; CALL p3; ---echo ---echo # Connection: default --connection default REVOKE SELECT ON t1 FROM testuser@localhost; GRANT SELECT(a) ON t1 TO testuser@localhost; REVOKE SELECT ON t2 FROM testuser@localhost; REVOKE SELECT ON mysqltest2.* FROM testuser@localhost; ---echo ---echo # Connection: bug57952_con1 (testuser@localhost, db: mysqltest1) --connection bug57952_con1 --echo # - Check column-level privileges... --error ER_COLUMNACCESS_DENIED_ERROR @@ -1380,8 +1350,6 @@ EXECUTE s3; --error ER_DBACCESS_DENIED_ERROR CALL p3; ---echo ---echo # Connection: default --connection default --disconnect bug57952_con1 DROP DATABASE mysqltest1; @@ -1410,14 +1378,10 @@ grant execute on procedure mysqltest1.p1 to mysqluser1@localhost; --echo # in privilege tables and in in-memory structures. show grants for mysqluser1@localhost; select db, routine_name, routine_type, proc_priv from mysql.procs_priv where user='mysqluser1' and host='localhost'; ---echo # ---echo # Create connection 'bug_36544_con1' as 'mysqluser1@localhost'. --connect (bug36544_con1,localhost,mysqluser1,,) call mysqltest1.p1(); select mysqltest1.f1(); ---echo # ---echo # Switch to connection 'default'. --connection default drop user mysqluser1@localhost; @@ -1425,7 +1389,6 @@ drop user mysqluser1@localhost; --echo # Test that dropping of user is properly reflected in --echo # both privilege tables and in in-memory structures. --echo # ---echo # Switch to connection 'bug36544_con1'. --connection bug36544_con1 --echo # The connection cold be alive but should not be able to --echo # access to any of the stored routines. @@ -1435,8 +1398,6 @@ call mysqltest1.p1(); select mysqltest1.f1(); --disconnect bug36544_con1 ---echo # ---echo # Switch to connection 'default'. --connection default --echo # --echo # Now create user with the same name and check that he @@ -1444,16 +1405,12 @@ select mysqltest1.f1(); create user mysqluser1@localhost; show grants for mysqluser1@localhost; select db, routine_name, routine_type, proc_priv from mysql.procs_priv where user='mysqluser1' and host='localhost'; ---echo # ---echo # Create connection 'bug_36544_con2' as 'mysqluser1@localhost'. --connect (bug36544_con2,localhost,mysqluser1,,) --echo # Newly created user should not be able to access any of the routines. --error ER_PROCACCESS_DENIED_ERROR call mysqltest1.p1(); --error ER_PROCACCESS_DENIED_ERROR select mysqltest1.f1(); ---echo # ---echo # Switch to connection 'default'. --connection default --echo # @@ -1482,23 +1439,18 @@ grant select on mysqltest1.t11 to mysqluser1@localhost; show grants for mysqluser1@localhost; select db, routine_name, routine_type, proc_priv from mysql.procs_priv where user='mysqluser1' and host='localhost'; select db, table_name, table_priv from mysql.tables_priv where user='mysqluser1' and host='localhost'; ---echo # ---echo # Switch to connection 'bug36544_con2'. --connection bug36544_con2 call mysqltest1.p1(); select mysqltest1.f1(); select * from mysqltest1.t11; select * from mysqltest1.t22; ---echo # ---echo # Switch to connection 'default'. --connection default rename user mysqluser1@localhost to mysqluser10@localhost; --echo # --echo # Test that there are no privileges left for mysqluser1. --echo # ---echo # Switch to connection 'bug36544_con2'. --connection bug36544_con2 --echo # The connection cold be alive but should not be able to --echo # access to any of the stored routines or tables. @@ -1512,8 +1464,6 @@ select * from mysqltest1.t11; select * from mysqltest1.t22; --disconnect bug36544_con2 ---echo # ---echo # Switch to connection 'default'. --connection default --echo # --echo # Now create user with the old name and check that he @@ -1522,8 +1472,6 @@ create user mysqluser1@localhost; show grants for mysqluser1@localhost; select db, routine_name, routine_type, proc_priv from mysql.procs_priv where user='mysqluser1' and host='localhost'; select db, table_name, table_priv from mysql.tables_priv where user='mysqluser1' and host='localhost'; ---echo # ---echo # Create connection 'bug_36544_con3' as 'mysqluser1@localhost'. --connect (bug36544_con3,localhost,mysqluser1,,) --echo # Newly created user should not be able to access to any of the --echo # stored routines or tables. @@ -1537,8 +1485,6 @@ select * from mysqltest1.t11; select * from mysqltest1.t22; --disconnect bug36544_con3 ---echo # ---echo # Switch to connection 'default'. --connection default --echo # --echo # Now check that privileges became associated with a new user @@ -1547,8 +1493,6 @@ select * from mysqltest1.t22; show grants for mysqluser10@localhost; select db, routine_name, routine_type, proc_priv from mysql.procs_priv where user='mysqluser10' and host='localhost'; select db, table_name, table_priv from mysql.tables_priv where user='mysqluser10' and host='localhost'; ---echo # ---echo # Create connection 'bug_36544_con4' as 'mysqluser10@localhost'. --connect (bug36544_con4,localhost,mysqluser10,,) call mysqltest1.p1(); select mysqltest1.f1(); @@ -1556,8 +1500,6 @@ select * from mysqltest1.t11; select * from mysqltest1.t22; --disconnect bug36544_con4 ---echo # ---echo # Switch to connection 'default'. --connection default --echo # --echo # Clean-up. @@ -1905,8 +1847,6 @@ GRANT USAGE ON *.* TO mysqltest_u1@localhost; --echo SHOW GRANTS FOR mysqltest_u1@localhost; ---echo ---echo # connection: con1 (mysqltest_u1@mysqltest_db1) --connect (con1,localhost,mysqltest_u1,,mysqltest_db1) --connection con1 @@ -1914,8 +1854,6 @@ SHOW GRANTS FOR mysqltest_u1@localhost; --error ER_TABLEACCESS_DENIED_ERROR SHOW CREATE TABLE t1; ---echo ---echo # connection: default --connection default --disconnect con1 @@ -2191,7 +2129,6 @@ DROP DATABASE IF EXISTS no_such_db; CREATE DATABASE secret; GRANT USAGE ON *.* TO untrusted@localhost; ---echo # Connection con1 connect (con1, localhost, untrusted); SHOW GRANTS; SHOW DATABASES; @@ -2204,7 +2141,6 @@ CREATE PROCEDURE no_such_db.foo() BEGIN END; --error ER_DBACCESS_DENIED_ERROR CREATE PROCEDURE secret.peek_at_secret() BEGIN END; ---echo # Connection default --connection default disconnect con1; DROP USER untrusted@localhost; @@ -2236,3 +2172,30 @@ drop user mysqltest_u1; set GLOBAL sql_mode=default; # Wait till we reached the initial number of concurrent sessions --source include/wait_until_count_sessions.inc + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-10134 Add full support for DEFAULT +--echo # + + +CREATE TABLE t1 (a VARCHAR(30) DEFAULT USER()); +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (); +GRANT ALL PRIVILEGES ON test.* TO dummy@localhost IDENTIFIED BY 'pwd'; +connect (conn1,localhost,dummy,pwd,test); +connection conn1; +INSERT INTO t1 VALUES (); +connection default; +disconnect conn1; +INSERT INTO t1 VALUES (); +SELECT * FROM t1; +DROP TABLE t1; +DROP USER dummy@localhost; + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/grant2.test b/mysql-test/t/grant2.test index a40fd2afb18..5e8a130feea 100644 --- a/mysql-test/t/grant2.test +++ b/mysql-test/t/grant2.test @@ -744,8 +744,6 @@ CREATE TABLE mysqltest_db2.t2_1(a INT); --echo # sql_command enum). --echo ########################################################################### ---echo ---echo # -- connect con1, mysqltest_u1@localhost, mysqltest_db1 --connect (con1,localhost,mysqltest_u1,,mysqltest_db1) --echo # @@ -931,8 +929,6 @@ DROP TEMPORARY TABLE t1; --echo # table once it is created. --echo ########################################################################### ---echo ---echo # -- connect con2, mysqltest_u2@localhost, mysqltest_db1 --connect (con2,localhost,mysqltest_u2,,mysqltest_db1) --error ER_DBACCESS_DENIED_ERROR @@ -957,8 +953,6 @@ DROP TEMPORARY TABLE t4; --echo # context, even by user without any privileges on tables. --echo ########################################################################### ---echo ---echo # -- connect con3, mysqltest_u4@localhost, mysqltest_db1 --connect (con3,localhost,mysqltest_u4,,mysqltest_db1) CALL p1(); @@ -975,8 +969,6 @@ DROP TEMPORARY TABLE t4; --echo # a temporary table into the underlying-table-list. --echo ########################################################################### ---echo ---echo # -- connect con4, mysqltest_u5@localhost, mysqltest_db1 --connect (con4,localhost,mysqltest_u5,,mysqltest_db1) CREATE TEMPORARY TABLE t7(a INT); @@ -1004,21 +996,12 @@ DROP TEMPORARY TABLE t9; --echo # That's all. Cleanup. --echo ########################################################################### ---echo ---echo # -- connection: default --connection default ---echo # -- disconnect con1 --echo # All remaining temporary tables are automatically dropped. --disconnect con1 - ---echo # -- disconnect con2 --disconnect con2 - ---echo # -- disconnect con3 --disconnect con3 - ---echo # -- disconnect con4 --disconnect con4 SET GLOBAL keycache1.key_buffer_size = 0; diff --git a/mysql-test/t/grant4.test b/mysql-test/t/grant4.test index a3578c9b85a..2715b7c7145 100644 --- a/mysql-test/t/grant4.test +++ b/mysql-test/t/grant4.test @@ -183,7 +183,6 @@ flush table mysqltest_db1.t1; --remove_file $MYSQLD_DATADIR/mysqltest_db1/t1.MYI --copy_file std_data/corrupt_t1.MYI $MYSQLD_DATADIR/mysqltest_db1/t1.MYI ---echo # Switching to connection 'con1'. connection con1; check table mysqltest_db1.t1; --echo # The below statement should fail before repairing t1. @@ -199,7 +198,6 @@ repair table mysqltest_db1.t1; --echo # Clean-up. disconnect con1; --source include/wait_until_disconnected.inc ---echo # Switching to connection 'default'. connection default; drop database mysqltest_db1; drop user mysqltest_u1@localhost; diff --git a/mysql-test/t/greedy_optimizer.test b/mysql-test/t/greedy_optimizer.test index 8f969f2562a..dcd0587d76e 100644 --- a/mysql-test/t/greedy_optimizer.test +++ b/mysql-test/t/greedy_optimizer.test @@ -138,7 +138,7 @@ insert into t7 values (21,2,3,4,5,6); # The actual test begins here # -# Check the default values for the optimizer paramters +# Check the default values for the optimizer parameters select @@optimizer_search_depth; select @@optimizer_prune_level; diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test index 334d9272e71..a97d8ef4248 100644 --- a/mysql-test/t/group_by.test +++ b/mysql-test/t/group_by.test @@ -996,8 +996,33 @@ EXPLAIN SELECT a FROM t1 WHERE a < 2 ORDER BY a; EXPLAIN SELECT a FROM t1 WHERE a < 2 GROUP BY a; EXPLAIN SELECT a FROM t1 IGNORE INDEX (PRIMARY,i2); EXPLAIN SELECT a FROM t1 IGNORE INDEX FOR JOIN (PRIMARY,i2); + +--echo # +--echo # For this explain, the query plan is weird: if we are using +--echo # the primary key for reasons other than doing grouping, can't +--echo # GROUP BY code take advantage of this? Well, currently it doesnt: EXPLAIN SELECT a FROM t1 IGNORE INDEX FOR GROUP BY (PRIMARY,i2) GROUP BY a; +--echo # Here's a proof it is really doing sorting: +flush status; +--disable_result_log +SELECT a FROM t1 IGNORE INDEX FOR GROUP BY (PRIMARY,i2) GROUP BY a; +--enable_result_log +show status like 'Sort_%'; +--echo # Proof ends. +--echo # + +--echo # For this explain, the query plan is weird: if we are using +--echo # the primary key for reasons other than doing sorting, can't +--echo # ORDER BY code take advantage of this? Well, currently it doesnt: EXPLAIN SELECT a FROM t1 IGNORE INDEX FOR ORDER BY (PRIMARY,i2) ORDER BY a; +--echo # Here's a proof it is really doing sorting: +flush status; +--disable_result_log +SELECT a FROM t1 IGNORE INDEX FOR ORDER BY (PRIMARY,i2) ORDER BY a; +--enable_result_log +show status like 'Sort_%'; +--echo # Proof ends. +--echo # SELECT a FROM t1 IGNORE INDEX FOR ORDER BY (PRIMARY,i2) ORDER BY a; EXPLAIN SELECT a FROM t1 IGNORE INDEX FOR ORDER BY (PRIMARY) IGNORE INDEX FOR GROUP BY (i2) GROUP BY a; diff --git a/mysql-test/t/index_intersect.test b/mysql-test/t/index_intersect.test index 19918c03479..1be963cb9e5 100644 --- a/mysql-test/t/index_intersect.test +++ b/mysql-test/t/index_intersect.test @@ -221,6 +221,7 @@ SELECT * FROM City AND Country BETWEEN 'S' AND 'Z'; --replace_column 9 # +--replace_result PRIMARY,Country,Population PRIMARY,Population,Country 4,7,4 4,4,7 EXPLAIN SELECT * FROM City WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000 @@ -306,6 +307,7 @@ SELECT * FROM City WHERE ID BETWEEN 1 AND 500 AND Population > 1000000 AND Country LIKE 'A%'; --replace_column 9 # +--replace_result PRIMARY,Country,Population PRIMARY,Population,Country 4,7,4 4,4,7 EXPLAIN SELECT * FROM City WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000 diff --git a/mysql-test/t/index_merge_innodb.test b/mysql-test/t/index_merge_innodb.test index fb56e44b5ae..53ce3114b49 100644 --- a/mysql-test/t/index_merge_innodb.test +++ b/mysql-test/t/index_merge_innodb.test @@ -12,7 +12,7 @@ # Slow test, don't run during staging part --source include/not_staging.inc ---source include/have_xtradb.inc +--source include/have_innodb.inc let $engine_type= InnoDB; # InnoDB does not support Merge tables (affects include/index_merge1.inc) diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index 5b0e2910889..157b4c69508 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -8,8 +8,7 @@ # on the presence of the log tables (which are CSV-based). --source include/have_csv.inc -# Check that XtraDB is enabled as result depends on it --- source include/have_xtradb.inc +-- source include/have_innodb.inc # Save the initial number of concurrent sessions --source include/count_sessions.inc @@ -576,7 +575,9 @@ begin end if; end| delimiter ;| +--replace_column 6 # show triggers; +--replace_column 17 # select * from information_schema.triggers where trigger_schema in ('mysql', 'information_schema', 'test', 'mysqltest'); drop trigger trg1; @@ -1034,12 +1035,14 @@ grant select(b) on mysqltest.t1 to mysqltest_1@localhost; select trigger_name from information_schema.triggers where event_object_table='t1'; +--replace_column 6 # show triggers from mysqltest; connect (con27629,localhost,mysqltest_1,,mysqltest); show columns from t1; select column_name from information_schema.columns where table_name='t1'; +--replace_column 6 # show triggers; select trigger_name from information_schema.triggers where event_object_table='t1'; @@ -1489,16 +1492,13 @@ drop tables if exists t1, t2, t3; create table t1 (i int); create table t2 (j int primary key auto_increment); connect (con3726_1,localhost,root,,test); ---echo # Switching to connection 'con3726_1' connection con3726_1; lock table t2 read; connect (con3726_2,localhost,root,,test); ---echo # Switching to connection 'con3726_2' connection con3726_2; --echo # RENAME below will be blocked by 'lock table t2 read' above but --echo # will add two pending requests for exclusive metadata locks. --send rename table t2 to t3 ---echo # Switching to connection 'default' connection default; let $wait_condition= select count(*) = 1 from information_schema.processlist @@ -1510,13 +1510,10 @@ select table_name, column_name, data_type from information_schema.columns where table_schema = 'test' and table_name in ('t1', 't2'); select table_name, auto_increment from information_schema.tables where table_schema = 'test' and table_name in ('t1', 't2'); ---echo # Switching to connection 'con3726_1' connection con3726_1; unlock tables; ---echo # Switching to connection 'con3726_2' connection con3726_2; --reap ---echo # Switching to connection 'default' connection default; disconnect con3726_1; disconnect con3726_2; @@ -1604,10 +1601,8 @@ create view v1 as select t1.a, t1.b from t1; alter table t1 change b c int; lock table t1 read; connect(con1, localhost, root,,); ---echo # --> connection con1 connection con1; send flush tables; ---echo # --> connection default connection default; let $wait_condition= select count(*) = 1 from information_schema.processlist @@ -1623,13 +1618,11 @@ unlock tables; --echo # Cleanup. --echo # ---echo # --> connection con1 connection con1; --echo # Reaping 'flush tables' reap; disconnect con1; --source include/wait_until_disconnected.inc ---echo # --> connection default connection default; drop table t1; drop view v1; @@ -1663,17 +1656,11 @@ create table t2 (k int); --echo # blocked. lock tables t2 read; ---echo # ---echo # Switching to connection 'con12828477_1'. ---echo # connect (con12828477_1, localhost, root,,mysqltest); --echo # The below RENAME should wait on 't2' while --echo # keeping X lock on 't1'. --send rename table t1 to t3, t2 to t1, t3 to t2 ---echo # ---echo # Switching to connection 'con12828477_2'. ---echo # connect (con12828477_2, localhost, root,,mysqltest); --echo # Wait while the above RENAME is blocked. let $wait_condition= @@ -1686,9 +1673,6 @@ let $wait_condition= --echo # blocked on 't1' because of RENAME. --send select table_name, auto_increment from information_schema.tables where table_schema='mysqltest' ---echo # ---echo # Switching to connection 'con12828477_3'. ---echo # connect (con12828477_3, localhost, root,,mysqltest); --echo # Wait while the above SELECT is blocked. let $wait_condition= @@ -1701,31 +1685,19 @@ let $wait_condition= --echo # Check that it holds no lock on 't0' so it can be renamed. rename table t0 to t4; ---echo # ---echo # Switching to connection 'default'. ---echo # connection default; --echo # --echo # Unblock the first RENAME. unlock tables; ---echo # ---echo # Switching to connection 'con12828477_1'. ---echo # connection con12828477_1; --echo # Reap the first RENAME --reap ---echo # ---echo # Switching to connection 'con12828477_2'. ---echo # connection con12828477_2; --echo # Reap SELECT to I_S. --reap ---echo # ---echo # Switching to connection 'default'. ---echo # connection default; --echo # @@ -1739,17 +1711,11 @@ rename table t4 to t0; --echo # blocked. lock tables t2 read; ---echo # ---echo # Switching to connection 'con12828477_1'. ---echo # connection con12828477_1; --echo # The below RENAME should wait on 't2' while --echo # keeping X lock on 't1'. --send rename table t1 to t3, t2 to t1, t3 to t2 ---echo # ---echo # Switching to connection 'con12828477_2'. ---echo # connection con12828477_2; --echo # Wait while the above RENAME is blocked. let $wait_condition= @@ -1762,9 +1728,6 @@ let $wait_condition= --echo # blocked on 't1' because of RENAME. --send select event_object_table, trigger_name from information_schema.triggers where event_object_schema='mysqltest' ---echo # ---echo # Switching to connection 'con12828477_3'. ---echo # connection con12828477_3; --echo # Wait while the above SELECT is blocked. let $wait_condition= @@ -1777,31 +1740,19 @@ let $wait_condition= --echo # Check that it holds no lock on 't0' so it can be renamed. rename table t0 to t4; ---echo # ---echo # Switching to connection 'default'. ---echo # connection default; --echo # --echo # Unblock the first RENAME. unlock tables; ---echo # ---echo # Switching to connection 'con12828477_1'. ---echo # connection con12828477_1; --echo # Reap the first RENAME --reap ---echo # ---echo # Switching to connection 'con12828477_2'. ---echo # connection con12828477_2; --echo # Reap SELECT to I_S. --reap ---echo # ---echo # Switching to connection 'default'. ---echo # connection default; disconnect con12828477_1; disconnect con12828477_2; diff --git a/mysql-test/t/information_schema_all_engines.test b/mysql-test/t/information_schema_all_engines.test index 8c898909c1e..f8d685d2560 100644 --- a/mysql-test/t/information_schema_all_engines.test +++ b/mysql-test/t/information_schema_all_engines.test @@ -3,7 +3,7 @@ # available (since these engines inject tables into INFORMATION_SCHEMA). --source include/not_embedded.inc ---source include/have_xtradb.inc +--source include/have_innodb.inc --source include/have_perfschema.inc --source include/not_staging.inc diff --git a/mysql-test/t/init_file.opt b/mysql-test/t/init_file.opt index 825311dabf2..f6af01ee2c3 100644 --- a/mysql-test/t/init_file.opt +++ b/mysql-test/t/init_file.opt @@ -1 +1 @@ ---init-file=$MYSQL_TEST_DIR/std_data/init_file.dat +--init-file=$MYSQL_TEST_DIR/std_data/init_file.dat --log-bin=mariadb-bin diff --git a/mysql-test/t/innodb_mysql_lock.test b/mysql-test/t/innodb_mysql_lock.test index b3c52a1b1cf..39ea7e5df88 100644 --- a/mysql-test/t/innodb_mysql_lock.test +++ b/mysql-test/t/innodb_mysql_lock.test @@ -19,24 +19,20 @@ connect (con1,localhost,root,,); connect (con2,localhost,root,,); connect (con3,localhost,root,,); ---echo # Connection 1 connection con1; set @@autocommit=0; CREATE TABLE t1(s1 INT UNIQUE) ENGINE=innodb; INSERT INTO t1 VALUES (1); ---echo # Connection 2 connection con2; set @@autocommit=0; INSERT INTO t1 VALUES (2); --send INSERT INTO t1 VALUES (1) ---echo # Connection 3 connection con3; set @@autocommit=0; --send DROP TABLE t1 ---echo # Connection 1 connection con1; let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist @@ -68,6 +64,7 @@ set @@autocommit=1; connection default; disconnect con1; +disconnect con2; disconnect con3; @@ -85,7 +82,6 @@ begin; update t1 set c3=c3+1 where c2=3; --echo # ---echo # Switching to connection 'con37346'. connect (con37346,localhost,root,,test,,); connection con37346; --echo # The below ALTER TABLE statement should wait till transaction @@ -95,7 +91,6 @@ connection con37346; --send alter table t1 add column c4 int; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Wait until the above ALTER TABLE gets blocked because this --echo # connection holds SW metadata lock on table to be altered. @@ -113,69 +108,15 @@ update t1 set c3=c3+1 where c2=4; commit; --echo # ---echo # Switching to connection 'con37346'. connection con37346; --echo # Reaping ALTER TABLE. --reap --echo # ---echo # Switching to connection 'default'. connection default; disconnect con37346; drop table t1; - ---echo # ---echo # Bug #42147 Concurrent DML and LOCK TABLE ... READ for InnoDB ---echo # table cause warnings in errlog ---echo # - ---echo # ---echo # Note that this test for now relies on a global suppression of ---echo # the warning "Found lock of type 6 that is write and read locked" ---echo # This suppression rule can be removed once Bug#42147 is properly ---echo # fixed. See bug page for more info. ---echo # - ---disable_warnings -DROP TABLE IF EXISTS t1; ---enable_warnings - -CREATE TABLE t1 (i INT) engine= innodb; - ---echo # Connection 2 ---echo # Get user-level lock -connection con2; -SELECT get_lock('bug42147_lock', 60); - ---echo # Connection 1 -connection default; ---send INSERT INTO t1 SELECT get_lock('bug42147_lock', 60) - ---echo # Connection 2 -connection con2; -let $wait_condition= - SELECT COUNT(*) > 0 FROM information_schema.processlist - WHERE state = 'User lock' - AND info = 'INSERT INTO t1 SELECT get_lock(\'bug42147_lock\', 60)'; ---source include/wait_condition.inc -LOCK TABLES t1 READ; -SELECT release_lock('bug42147_lock'); - ---echo # Connection 1 -connection default; ---reap - ---echo # Connection 2 -connection con2; -UNLOCK TABLES; - ---echo # Connection 1 -connection default; -disconnect con2; -DROP TABLE t1; - - --echo # --echo # Bug#53798 OPTIMIZE TABLE breaks repeatable read --echo # @@ -187,18 +128,15 @@ DROP TABLE IF EXISTS t1; CREATE TABLE t1 (a INT) engine=innodb; INSERT INTO t1 VALUES (1), (2), (3); ---echo # Connection con1 connect (con1, localhost, root); START TRANSACTION WITH CONSISTENT SNAPSHOT; SELECT * FROM t1; ---echo # Connection default connection default; --echo # This should block --echo # Sending: --send OPTIMIZE TABLE t1 ---echo # Connection con1 connection con1; let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state='Waiting for table metadata lock' AND info='OPTIMIZE TABLE t1'; @@ -206,7 +144,6 @@ let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist SELECT * FROM t1; COMMIT; ---echo # Connection default connection default; --echo # Reaping OPTIMIZE TABLE t1 --reap @@ -230,18 +167,15 @@ CREATE VIEW v1 AS SELECT 1 FROM t1; connect (con2, localhost, root); connect (con3, localhost, root); ---echo # Connection con3 connection con3; LOCK TABLE t1 WRITE; ---echo # Connection default connection default; START TRANSACTION; # This should block due to t1 being locked. --echo # Sending: --send SELECT * FROM v1 ---echo # Connection con2 connection con2; --echo # Waiting for 'SELECT * FROM v1' to sync in. let $wait_condition= @@ -252,7 +186,6 @@ let $wait_condition= --echo # Sending: --send ALTER VIEW v1 AS SELECT 2 FROM t2 ---echo # Connection con3 connection con3; --echo # Waiting for 'ALTER VIEW v1 AS SELECT 2 FROM t2' to sync in. let $wait_condition= @@ -263,19 +196,16 @@ let $wait_condition= # Unlock t1 allowing SELECT * FROM v1 to proceed. UNLOCK TABLES; ---echo # Connection default; connection default; --echo # Reaping: SELECT * FROM v1 --reap SELECT * FROM v1; COMMIT; ---echo # Connection con2 connection con2; --echo # Reaping: ALTER VIEW v1 AS SELECT 2 FROM t2 --reap ---echo # Connection default connection default; DROP TABLE t1, t2; DROP VIEW v1; @@ -294,14 +224,12 @@ DROP TABLE IF EXISTS t1; --connect (con1,localhost,root) ---echo # Connection default connection default; CREATE TABLE t1 (id INT PRIMARY KEY, value INT) ENGINE = InnoDB; INSERT INTO t1 VALUES (1, 12345); START TRANSACTION; SELECT * FROM t1; ---echo # Connection con1 --connection con1 SET lock_wait_timeout=1; # Test with two timeouts, as the first version of this patch @@ -311,7 +239,6 @@ ALTER TABLE t1 ADD INDEX idx(value); --error ER_LOCK_WAIT_TIMEOUT ALTER TABLE t1 ADD INDEX idx(value); ---echo # Connection default --connection default SELECT * FROM t1; COMMIT; diff --git a/mysql-test/t/innodb_mysql_lock2.test b/mysql-test/t/innodb_mysql_lock2.test index 640f9652462..f319fe23568 100644 --- a/mysql-test/t/innodb_mysql_lock2.test +++ b/mysql-test/t/innodb_mysql_lock2.test @@ -789,12 +789,10 @@ begin; --echo # Acquire SR metadata lock on t1 and LOCK_S row-locks on its rows. insert into t2 select count(*) from t1; ---echo # Switching to connection 'con1'. connection con1; --echo # Sending: --send alter table t1 add column j int ---echo # Switching to connection 'default'. connection default; --echo # Wait until ALTER is blocked because it tries to upgrade SNW --echo # metadata lock to X lock. @@ -817,12 +815,10 @@ insert into t1 values (6); --echo # Unblock ALTER TABLE. commit; ---echo # Switching to connection 'con1'. connection con1; --echo # Reaping ALTER TABLE. --reap ---echo # Switching to connection 'default'. connection default; --echo # @@ -838,12 +834,10 @@ begin; --echo # Acquire SR metadata lock on t1. select * from t1; ---echo # Switching to connection 'con1'. connection con1; --echo # Sending: --send alter table t1 rebuild partition p0 ---echo # Switching to connection 'default'. connection default; --echo # Wait until ALTER is blocked because of active SR lock. let $wait_condition= @@ -859,12 +853,10 @@ insert into t2 select count(*) from t1; --echo # Unblock ALTER TABLE. commit; ---echo # Switching to connection 'con1'. connection con1; --echo # Reaping ALTER TABLE. --reap ---echo # Switching to connection 'default'. connection default; disconnect con1; --echo # Clean-up. diff --git a/mysql-test/t/innodb_mysql_sync.test b/mysql-test/t/innodb_mysql_sync.test index 31365cb8db8..66935f811d7 100644 --- a/mysql-test/t/innodb_mysql_sync.test +++ b/mysql-test/t/innodb_mysql_sync.test @@ -22,20 +22,17 @@ DROP TABLE IF EXISTS t1; CREATE TABLE t1 (id INT) engine=innodb; connect (con2, localhost, root); ---echo # Connection 1 --echo # Start optimizing table connection default; SET DEBUG_SYNC='ha_admin_try_alter SIGNAL optimize_started WAIT_FOR table_altered'; --send OPTIMIZE TABLE t1 ---echo # Connection 2 --echo # Change table to engine=memory connection con2; SET DEBUG_SYNC='now WAIT_FOR optimize_started'; ALTER TABLE t1 engine=memory; SET DEBUG_SYNC='now SIGNAL table_altered'; ---echo # Connection 1 --echo # Complete optimization connection default; --reap @@ -59,24 +56,20 @@ connection default; CREATE TABLE t1(a INT) ENGINE= InnoDB; ---echo # Connection con1 connection con1; SET DEBUG_SYNC= "ha_admin_open_ltable SIGNAL opening WAIT_FOR dropped"; --echo # Sending: --send OPTIMIZE TABLE t1 ---echo # Connection default connection default; SET DEBUG_SYNC= "now WAIT_FOR opening"; DROP TABLE t1; SET DEBUG_SYNC= "now SIGNAL dropped"; ---echo # Connection con1 connection con1; --echo # Reaping: OPTIMIZE TABLE t1 --reap ---echo # Connection default connection default; disconnect con1; SET DEBUG_SYNC= "RESET"; @@ -123,26 +116,22 @@ DROP TABLE IF EXISTS t1; CREATE TABLE t1 (a INT) ENGINE=InnoDB; INSERT INTO t1 VALUES (1), (2); ---echo # Connection con1 connect (con1,localhost,root); let $ID= `SELECT connection_id()`; SET DEBUG_SYNC= 'ha_admin_open_ltable SIGNAL waiting WAIT_FOR killed'; --echo # Sending: --send OPTIMIZE TABLE t1 ---echo # Connection default connection default; SET DEBUG_SYNC= 'now WAIT_FOR waiting'; --replace_result $ID ID eval KILL QUERY $ID; SET DEBUG_SYNC= 'now SIGNAL killed'; ---echo # Connection con1 connection con1; --echo # Reaping: OPTIMIZE TABLE t1 --reap ---echo # Connection default connection default; DROP TABLE t1; SET DEBUG_SYNC= 'RESET'; @@ -164,7 +153,6 @@ connect(con2,localhost,root); --echo # Test 1: Secondary index, should not block reads (original test case). ---echo # Connection default connection default; CREATE DATABASE db1; CREATE TABLE db1.t1(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, value INT) engine=innodb; @@ -173,7 +161,6 @@ SET DEBUG_SYNC= "alter_table_inplace_after_lock_downgrade SIGNAL manage WAIT_FOR --echo # Sending: --send ALTER TABLE db1.t1 ADD INDEX(value) ---echo # Connection con1 connection con1; SET DEBUG_SYNC= "now WAIT_FOR manage"; # Neither of these two statements should be blocked @@ -181,7 +168,6 @@ USE db1; SELECT * FROM t1; SET DEBUG_SYNC= "now SIGNAL query"; ---echo # Connection default connection default; --echo # Reaping: ALTER TABLE db1.t1 ADD INDEX(value) --reap @@ -194,7 +180,6 @@ SET DEBUG_SYNC= "alter_table_inplace_after_lock_downgrade SIGNAL manage WAIT_FOR --echo # Sending: --send ALTER TABLE t1 ADD UNIQUE INDEX(a), LOCK=SHARED ---echo # Connection con1 connection con1; SET DEBUG_SYNC= "now WAIT_FOR manage"; USE test; @@ -202,7 +187,6 @@ SELECT * FROM t1; --echo # Sending: --send UPDATE t1 SET a=NULL ---echo # Connection con2 connection con2; --echo # Waiting for SELECT to be blocked by the metadata lock on t1 let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist @@ -211,33 +195,28 @@ let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist --source include/wait_condition.inc SET DEBUG_SYNC= "now SIGNAL query"; ---echo # Connection default connection default; --echo # Reaping: ALTER TABLE t1 ADD UNIQUE INDEX(a) --reap ---echo # Connection con1 connection con1; --echo # Reaping: UPDATE t1 SET a=NULL --reap --echo # Test 3: Primary index (explicit), should block writes. ---echo # Connection default connection default; ALTER TABLE t1 DROP INDEX a; SET DEBUG_SYNC= "alter_table_inplace_after_lock_downgrade SIGNAL manage WAIT_FOR query"; --echo # Sending: --send ALTER TABLE t1 ADD PRIMARY KEY (a), LOCK=SHARED ---echo # Connection con1 connection con1; SET DEBUG_SYNC= "now WAIT_FOR manage"; SELECT * FROM t1; --echo # Sending: --send UPDATE t1 SET a=NULL ---echo # Connection con2 connection con2; --echo # Waiting for SELECT to be blocked by the metadata lock on t1 let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist @@ -246,31 +225,26 @@ let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist --source include/wait_condition.inc SET DEBUG_SYNC= "now SIGNAL query"; ---echo # Connection default connection default; --echo # Reaping: ALTER TABLE t1 ADD PRIMARY KEY (a) --reap ---echo # Connection con1 connection con1; --echo # Reaping: UPDATE t1 SET a=NULL --reap --echo # Test 4: Secondary unique index, should not block reads. ---echo # Connection default connection default; SET DEBUG_SYNC= "alter_table_inplace_after_lock_downgrade SIGNAL manage WAIT_FOR query"; --echo # Sending: --send ALTER TABLE t1 ADD UNIQUE (b) ---echo # Connection con1 connection con1; SET DEBUG_SYNC= "now WAIT_FOR manage"; SELECT * FROM t1; SET DEBUG_SYNC= "now SIGNAL query"; ---echo # Connection default connection default; --echo # Reaping: ALTER TABLE t1 ADD UNIQUE (b) --reap @@ -293,14 +267,12 @@ DROP TABLE IF EXISTS t1; CREATE TABLE t1(a INT NOT NULL, b INT NOT NULL) engine=innodb; INSERT INTO t1 VALUES (1, 12345), (2, 23456); ---echo # Connection con1 --connect (con1,localhost,root) SET SESSION debug_dbug= "+d,alter_table_rollback_new_index"; --error ER_UNKNOWN_ERROR ALTER TABLE t1 ADD PRIMARY KEY(a); SELECT * FROM t1; ---echo # Connection default --connection default SELECT * FROM t1; DROP TABLE t1; @@ -322,20 +294,17 @@ CREATE DATABASE db1; connect(con1, localhost, root); connect(con2, localhost, root); ---echo # Connection con1 connection con1; SET DEBUG_SYNC= 'after_innobase_rename_table SIGNAL locked WAIT_FOR continue'; --echo # Sending: --send ALTER TABLE t1 RENAME db1.t1 ---echo # Connection con2 connection con2; SET DEBUG_SYNC= 'now WAIT_FOR locked'; --echo # DROP DATABASE db1 should now be blocked by ALTER TABLE --echo # Sending: --send DROP DATABASE db1 ---echo # Connection default connection default; --echo # Check that DROP DATABASE is blocked by IX lock on db1 let $wait_condition= @@ -346,17 +315,14 @@ let $wait_condition= --echo # Resume ALTER TABLE SET DEBUG_SYNC= 'now SIGNAL continue'; ---echo # Connection con1 connection con1; --echo # Reaping: ALTER TABLE t1 RENAME db1.t1; --reap ---echo # Connection con2 connection con2; --echo # Reaping: DROP DATABASE db1 --reap ---echo # Connection default; connection default; SET DEBUG_SYNC= 'RESET'; disconnect con1; @@ -384,7 +350,6 @@ SET SESSION lock_wait_timeout= 1; --echo # 1: In-place + writes blocked. --echo # ---echo # Connection default --connection default SET DEBUG_SYNC= 'alter_opened_table SIGNAL opened WAIT_FOR continue1'; SET DEBUG_SYNC= 'alter_table_inplace_after_lock_upgrade SIGNAL upgraded WAIT_FOR continue2'; @@ -393,7 +358,6 @@ SET DEBUG_SYNC= 'alter_table_before_main_binlog SIGNAL binlog WAIT_FOR continue4 --echo # Sending: --send ALTER TABLE t1 ADD INDEX i1(b), ALGORITHM= INPLACE, LOCK= SHARED ---echo # Connection con1; --connection con1 SET DEBUG_SYNC= 'now WAIT_FOR opened'; --echo # At this point, neither reads nor writes should be blocked. @@ -425,7 +389,6 @@ SELECT * FROM t1; INSERT INTO t1 VALUES (6,6); SET DEBUG_SYNC= 'now SIGNAL continue4'; ---echo # Connection default --connection default --echo # Reaping ALTER TABLE ... --reap @@ -442,7 +405,6 @@ SET DEBUG_SYNC= 'alter_table_before_main_binlog SIGNAL binlog WAIT_FOR continue3 --echo # Sending: --send ALTER TABLE t1 ADD INDEX i2(b), ALGORITHM= COPY, LOCK= SHARED ---echo # Connection con1; --connection con1 SET DEBUG_SYNC= 'now WAIT_FOR opened'; --echo # At this point, neither reads nor writes should be blocked. @@ -465,7 +427,6 @@ SELECT * FROM t1 limit 1; INSERT INTO t1 VALUES (5,5); SET DEBUG_SYNC= 'now SIGNAL continue3'; ---echo # Connection default --connection default --echo # Reaping ALTER TABLE ... --reap @@ -479,7 +440,6 @@ DELETE FROM t1 WHERE a= 3; --echo # TODO: Enable this test once WL#5526 is pushed --disable_parsing ---echo # Connection default --connection default SET DEBUG_SYNC= 'alter_opened_table SIGNAL opened WAIT_FOR continue1'; SET DEBUG_SYNC= 'alter_table_inplace_after_lock_upgrade SIGNAL upgraded WAIT_FOR continue2'; @@ -489,7 +449,6 @@ SET DEBUG_SYNC= 'alter_table_before_main_binlog SIGNAL binlog WAIT_FOR continue5 --echo # Sending: --send ALTER TABLE t1 ADD INDEX i3(b), ALGORITHM= INPLACE, LOCK= NONE ---echo # Connection con1; --connection con1 SET DEBUG_SYNC= 'now WAIT_FOR opened'; --echo # At this point, neither reads nor writes should be blocked. @@ -526,7 +485,6 @@ SELECT * FROM t1; INSERT INTO t1 VALUES (7,7); SET DEBUG_SYNC= 'now SIGNAL continue5'; ---echo # Connection default --connection default --echo # Reaping ALTER TABLE ... --reap @@ -540,7 +498,6 @@ DELETE FROM t1 WHERE a= 3 OR a= 4; --echo # 4: In-place + reads and writes blocked. --echo # ---echo # Connection default --connection default SET DEBUG_SYNC= 'alter_opened_table SIGNAL opened WAIT_FOR continue1'; SET DEBUG_SYNC= 'alter_table_inplace_after_lock_upgrade SIGNAL upgraded WAIT_FOR continue2'; @@ -549,7 +506,6 @@ SET DEBUG_SYNC= 'alter_table_before_main_binlog SIGNAL binlog WAIT_FOR continue4 --echo # Sending: --send ALTER TABLE t1 ADD INDEX i4(b), ALGORITHM= INPLACE, LOCK= EXCLUSIVE ---echo # Connection con1; --connection con1 SET DEBUG_SYNC= 'now WAIT_FOR opened'; --echo # At this point, neither reads nor writes should be blocked. @@ -581,7 +537,6 @@ SELECT * FROM t1; INSERT INTO t1 VALUES (6,6); SET DEBUG_SYNC= 'now SIGNAL continue4'; ---echo # Connection default --connection default --echo # Reaping ALTER TABLE ... --reap @@ -606,7 +561,6 @@ INSERT INTO t1 VALUES (155, 45, 55); --echo #Concurrent INSERT, UPDATE, SELECT and DELETE is supported --echo #during OPTIMIZE TABLE operation for INNODB tables. ---enable_connect_log --connection default --echo #OPTIMIZE TABLE operation. --send OPTIMIZE TABLE t1 @@ -785,7 +739,6 @@ SET DEBUG_SYNC= 'now WAIT_FOR rebuild'; --connection default --reap ---disable_connect_log --disconnect con1 SET DEBUG_SYNC= 'RESET'; diff --git a/mysql-test/t/insert_notembedded.test b/mysql-test/t/insert_notembedded.test index 713eaf5db40..2769aee8d8a 100644 --- a/mysql-test/t/insert_notembedded.test +++ b/mysql-test/t/insert_notembedded.test @@ -156,41 +156,5 @@ connection default; DROP DATABASE meow; -# -# Bug#28587 SELECT is blocked by INSERT waiting on read lock, even with low_priority_updates -# ---echo connection: default -set low_priority_updates=1; ---disable_warnings -drop table if exists t1; ---enable_warnings -create table t1 (a int, b int, unique key t1$a (a)); -lock table t1 read; -connect (update,localhost,root,,); -connection update; ---echo connection: update -set low_priority_updates=1; -show variables like 'low_priority_updates'; -let $ID= `select connection_id()`; ---send insert into t1 values (1, 2) ON DUPLICATE KEY UPDATE b = 2; -connection default; -# we must wait till the insert opens and locks the table -let $wait_condition= - select count(*) = 1 from information_schema.processlist - where state = "Waiting for table level lock" and id = $ID; ---source include/wait_condition.inc -connect (select,localhost,root,,); ---echo connection: select -select * from t1; -connection default; ---echo connection: default -select * from t1; -connection default; -disconnect update; -disconnect select; -unlock tables; -drop table t1; -set low_priority_updates=default; - set local sql_mode=default; set global sql_mode=default; diff --git a/mysql-test/t/ipv4_as_ipv6.test b/mysql-test/t/ipv4_as_ipv6.test index 1fbc0317a36..2a3ab6647ff 100644 --- a/mysql-test/t/ipv4_as_ipv6.test +++ b/mysql-test/t/ipv4_as_ipv6.test @@ -52,7 +52,7 @@ echo =============Test of '::1' ========================; let $IPv6= ::1; --echo connect (con1, $IPv6, root, , test, MASTER_MYPORT,); --disable_query_log ---error 2003,2006 +--error 2002,2006 connect (con1, $IPv6, root, , test, $MASTER_MYPORT,); --enable_query_log diff --git a/mysql-test/t/keywords.test b/mysql-test/t/keywords.test index 54052e65014..40beee9e3c1 100644 --- a/mysql-test/t/keywords.test +++ b/mysql-test/t/keywords.test @@ -173,3 +173,10 @@ drop table option; set option=1; --error 1193 set option option=1; + +--echo # +--echo # MDEV-10585 EXECUTE IMMEDIATE statement +--echo # + +CREATE TABLE immediate (immediate int); +DROP TABLE immediate; diff --git a/mysql-test/t/kill.test b/mysql-test/t/kill.test index aaf931a2e7f..b6000ffced1 100644 --- a/mysql-test/t/kill.test +++ b/mysql-test/t/kill.test @@ -345,8 +345,6 @@ SET DEBUG_SYNC = 'RESET'; --echo # depending on platform. --echo # ---echo ---echo # Connection: con1. --connection con1 let $ID= `SELECT @id := CONNECTION_ID()`; SET DEBUG_SYNC= 'thread_end SIGNAL con1_end'; @@ -385,14 +383,11 @@ connect (dml, localhost, root, , ); connect (ddl, localhost, root, , ); --echo # Test for RENAME TABLE ---echo # Switching to connection 'blocker' connection blocker; lock table t1 read; ---echo # Switching to connection 'ddl' connection ddl; let $ID= `select connection_id()`; --send rename table t1 to t2 ---echo # Switching to connection 'default' connection default; let $wait_condition= select count(*) = 1 from information_schema.processlist @@ -401,14 +396,12 @@ let $wait_condition= --source include/wait_condition.inc --replace_result $ID ID eval kill query $ID; ---echo # Switching to connection 'ddl' connection ddl; --error ER_QUERY_INTERRUPTED --reap --echo # Test for DROP TABLE --send drop table t1 ---echo # Switching to connection 'default' connection default; let $wait_condition= select count(*) = 1 from information_schema.processlist @@ -417,14 +410,12 @@ let $wait_condition= --source include/wait_condition.inc --replace_result $ID ID eval kill query $ID; ---echo # Switching to connection 'ddl' connection ddl; --error ER_QUERY_INTERRUPTED --reap --echo # Test for CREATE TRIGGER --send create trigger t1_bi before insert on t1 for each row set @a:=1 ---echo # Switching to connection 'default' connection default; let $wait_condition= select count(*) = 1 from information_schema.processlist @@ -433,7 +424,6 @@ let $wait_condition= --source include/wait_condition.inc --replace_result $ID ID eval kill query $ID; ---echo # Switching to connection 'ddl' connection ddl; --error ER_QUERY_INTERRUPTED --reap @@ -443,7 +433,6 @@ connection ddl; --echo # --echo # Full-blown ALTER which should copy table --send alter table t1 add column j int ---echo # Switching to connection 'default' connection default; let $wait_condition= select count(*) = 1 from information_schema.processlist @@ -452,14 +441,12 @@ let $wait_condition= --source include/wait_condition.inc --replace_result $ID ID eval kill query $ID; ---echo # Switching to connection 'ddl' connection ddl; --error ER_QUERY_INTERRUPTED --reap --echo # Two kinds of simple ALTER --send alter table t1 rename to t2 ---echo # Switching to connection 'default' connection default; let $wait_condition= select count(*) = 1 from information_schema.processlist @@ -468,12 +455,10 @@ let $wait_condition= --source include/wait_condition.inc --replace_result $ID ID eval kill query $ID; ---echo # Switching to connection 'ddl' connection ddl; --error ER_QUERY_INTERRUPTED --reap --send alter table t1 disable keys ---echo # Switching to connection 'default' connection default; let $wait_condition= select count(*) = 1 from information_schema.processlist @@ -482,13 +467,11 @@ let $wait_condition= --source include/wait_condition.inc --replace_result $ID ID eval kill query $ID; ---echo # Switching to connection 'ddl' connection ddl; --error ER_QUERY_INTERRUPTED --reap --echo # Fast ALTER --send alter table t1 alter column i set default 100 ---echo # Switching to connection 'default' connection default; let $wait_condition= select count(*) = 1 from information_schema.processlist @@ -497,20 +480,16 @@ let $wait_condition= --source include/wait_condition.inc --replace_result $ID ID eval kill query $ID; ---echo # Switching to connection 'ddl' connection ddl; --error ER_QUERY_INTERRUPTED --reap --echo # Special case which is triggered only for MERGE tables. ---echo # Switching to connection 'blocker' connection blocker; unlock tables; create table t2 (i int primary key) engine=merge union=(t1); lock tables t2 read; ---echo # Switching to connection 'ddl' connection ddl; --send alter table t2 alter column i set default 100 ---echo # Switching to connection 'default' connection default; let $wait_condition= select count(*) = 1 from information_schema.processlist @@ -519,21 +498,17 @@ let $wait_condition= --source include/wait_condition.inc --replace_result $ID ID eval kill query $ID; ---echo # Switching to connection 'ddl' connection ddl; --error ER_QUERY_INTERRUPTED --reap --echo # Test for DML waiting for meta-data lock ---echo # Switching to connection 'blocker' connection blocker; unlock tables; lock tables t1 read; ---echo # Switching to connection 'ddl' connection ddl; # Let us add pending exclusive metadata lock on t2 --send truncate table t1 ---echo # Switching to connection 'dml' connection dml; let $wait_condition= select count(*) = 1 from information_schema.processlist @@ -542,7 +517,6 @@ let $wait_condition= --source include/wait_condition.inc let $ID2= `select connection_id()`; --send insert into t1 values (1) ---echo # Switching to connection 'default' connection default; let $wait_condition= select count(*) = 1 from information_schema.processlist @@ -551,26 +525,20 @@ let $wait_condition= --source include/wait_condition.inc --replace_result $ID2 ID2 eval kill query $ID2; ---echo # Switching to connection 'dml' connection dml; --error ER_QUERY_INTERRUPTED --reap ---echo # Switching to connection 'blocker' connection blocker; unlock tables; ---echo # Switching to connection 'ddl' connection ddl; --reap --echo # Test for DML waiting for tables to be flushed ---echo # Switching to connection 'blocker' connection blocker; lock tables t1 read; ---echo # Switching to connection 'ddl' connection ddl; --echo # Let us mark locked table t1 as old --send flush tables ---echo # Switching to connection 'dml' connection dml; let $wait_condition= select count(*) = 1 from information_schema.processlist @@ -578,7 +546,6 @@ let $wait_condition= info = "flush tables"; --source include/wait_condition.inc --send select * from t1 ---echo # Switching to connection 'default' connection default; let $wait_condition= select count(*) = 1 from information_schema.processlist @@ -587,19 +554,15 @@ let $wait_condition= --source include/wait_condition.inc --replace_result $ID2 ID2 eval kill query $ID2; ---echo # Switching to connection 'dml' connection dml; --error ER_QUERY_INTERRUPTED --reap ---echo # Switching to connection 'blocker' connection blocker; unlock tables; ---echo # Switching to connection 'ddl' connection ddl; --reap --echo # Cleanup. ---echo # Switching to connection 'default' connection default; drop table t1; drop table t2; diff --git a/mysql-test/t/kill_processlist-6619.test b/mysql-test/t/kill_processlist-6619.test index 551d36e03fd..d984924f9db 100644 --- a/mysql-test/t/kill_processlist-6619.test +++ b/mysql-test/t/kill_processlist-6619.test @@ -4,7 +4,6 @@ --source include/not_embedded.inc --source include/have_debug_sync.inc ---enable_connect_log --connect (con1,localhost,root,,) --let $con_id = `SELECT CONNECTION_ID()` --replace_column 1 # 3 # 6 # 7 # diff --git a/mysql-test/t/kill_query-6728.test b/mysql-test/t/kill_query-6728.test index 485256a65b6..a04c51a88dc 100644 --- a/mysql-test/t/kill_query-6728.test +++ b/mysql-test/t/kill_query-6728.test @@ -1,7 +1,6 @@ # # MDEV-6728 KILL QUERY executed on an idle connection can interrupt the next query # ---enable_connect_log --connect (con1,localhost,root,,) let $id=`select connection_id()`; diff --git a/mysql-test/t/limit_rows_examined.test b/mysql-test/t/limit_rows_examined.test index 45ee483c7aa..3f7424d5541 100644 --- a/mysql-test/t/limit_rows_examined.test +++ b/mysql-test/t/limit_rows_examined.test @@ -125,6 +125,7 @@ UNION UNION (select * from t1, t2 where c1 < c2 LIMIT ROWS EXAMINED 6); +--error ER_PARSE_ERROR select * from t1, t2 where c1 = c2 LIMIT ROWS EXAMINED 0 UNION select * from t1, t2 where c1 < c2 LIMIT ROWS EXAMINED 6; @@ -305,7 +306,6 @@ select c1, sum(c2) from t3 group by c1; explain select c1, sum(c2) from t3 group by c1 LIMIT ROWS EXAMINED 0; select c1, sum(c2) from t3 group by c1 LIMIT ROWS EXAMINED 0; ---error 1028 select c1, sum(c2) from t3 group by c1 LIMIT ROWS EXAMINED 1; select c1, sum(c2) from t3 group by c1 LIMIT ROWS EXAMINED 20; select c1, sum(c2) from t3 group by c1 LIMIT ROWS EXAMINED 21; @@ -321,7 +321,6 @@ insert into t3i values explain select c1, sum(c2) from t3i group by c1 LIMIT ROWS EXAMINED 0; select c1, sum(c2) from t3i group by c1 LIMIT ROWS EXAMINED 0; ---error 1028 select c1, sum(c2) from t3i group by c1 LIMIT ROWS EXAMINED 1; select c1, sum(c2) from t3i group by c1 LIMIT ROWS EXAMINED 20; select c1, sum(c2) from t3i group by c1 LIMIT ROWS EXAMINED 21; @@ -432,7 +431,7 @@ drop table t1,t2,t1i,t2i; SET @@optimizer_switch='in_to_exists=on,outer_join_with_cache=on'; CREATE TABLE t1 ( a VARCHAR(3) ) ENGINE=MyISAM; -INSERT INTO t1 VALUES ('USA'); +INSERT INTO t1 VALUES ('USA'),('CAN'); CREATE TABLE t2 ( b INT ); INSERT INTO t2 VALUES (3899),(3914),(3888); diff --git a/mysql-test/t/loaddata.test b/mysql-test/t/loaddata.test index 1bc7eb139b9..4de7138e4dc 100644 --- a/mysql-test/t/loaddata.test +++ b/mysql-test/t/loaddata.test @@ -676,3 +676,21 @@ CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf8); LOAD DATA INFILE '../../std_data/loaddata/mdev-11631.txt' INTO TABLE t1 CHARACTER SET utf8; SELECT HEX(a) FROM t1; DROP TABLE t1; + +CREATE DATABASE d1 CHARSET latin1; +USE d1; +CREATE TABLE t1 (val TEXT); +LOAD DATA INFILE '../../std_data/bug20683959loaddata.txt' INTO TABLE t1; +SELECT COUNT(*) FROM t1; +SELECT HEX(val) FROM t1; + +CREATE DATABASE d2 CHARSET utf8; +USE d2; +CREATE TABLE t1 (val TEXT); +LOAD DATA INFILE '../../std_data/bug20683959loaddata.txt' INTO TABLE t1; +SELECT COUNT(*) FROM t1; +SELECT HEX(val) FROM t1; + +DROP TABLE d1.t1, d2.t1; +DROP DATABASE d1; +DROP DATABASE d2; diff --git a/mysql-test/t/lock.test b/mysql-test/t/lock.test index 78f0e2ecf8d..2e164de9b93 100644 --- a/mysql-test/t/lock.test +++ b/mysql-test/t/lock.test @@ -333,7 +333,6 @@ connect(con1,localhost,root,,); set autocommit= 0; insert into t1 values (1); lock table t1 write; ---echo # Disconnect --echo # Ensure that metadata locks will be released if there is an open --echo # transaction (autocommit=off) in conjunction with lock tables. disconnect con1; @@ -349,7 +348,6 @@ create table t1 (a int); connect(con1,localhost,root,,); begin; insert into t1 values (1); ---echo # Disconnect --echo # Ensure that metadata locks held by the transaction are released. disconnect con1; connection default; @@ -444,11 +442,6 @@ alter table t1 add column j int; unlock tables; drop table t1; create temporary table t1 (i int); ---echo # ---echo # This is just for test coverage purposes, ---echo # when this is allowed, remove the --error. ---echo # ---error ER_CANT_REOPEN_TABLE lock tables t1 write, t1 as a read, t1 as b read; alter table t1 add column j int; unlock tables; @@ -556,12 +549,10 @@ connect (con2, localhost, root); CREATE TABLE t1 (id INT); CREATE TABLE t2 (id INT); ---echo # Connection default connection default; LOCK TABLE t1 WRITE; ANALYZE TABLE t1; ---echo # Connection con2 connection con2; LOCK TABLE t2 WRITE; --echo # This used to hang until the first connection @@ -570,7 +561,6 @@ FLUSH TABLE t2; UNLOCK TABLES; ---echo # Connection default connection default; UNLOCK TABLES; DROP TABLE t1, t2; diff --git a/mysql-test/t/lock_multi.test b/mysql-test/t/lock_multi.test index efd0fe5d630..51cc4a50233 100644 --- a/mysql-test/t/lock_multi.test +++ b/mysql-test/t/lock_multi.test @@ -371,13 +371,10 @@ create table t1 (a int); create table t2 like t1; connection con1; ---echo # con1 lock tables t1 write; connection con2; ---echo # con2 send flush tables with read lock; connection con5; ---echo # con5 let $wait_condition= select count(*) = 1 from information_schema.processlist where state = "Waiting for global read lock" and @@ -385,7 +382,6 @@ let $wait_condition= --source include/wait_condition.inc --echo # global read lock is taken connection con3; ---echo # con3 send select * from t2 for update; connection con5; let $wait_condition= @@ -395,7 +391,6 @@ let $wait_condition= --source include/wait_condition.inc --echo # waiting for release of read lock connection con4; ---echo # con4 --echo # would hang and later cause a deadlock flush tables t2; connection con1; @@ -431,13 +426,10 @@ create table t2 like t1; --echo # connection default; ---echo # default flush tables with read lock; connection con1; ---echo # con1 send update t2 set a = 1; connection default; ---echo # default let $wait_condition= select count(*) = 1 from information_schema.processlist where state = "Waiting for global read lock" and @@ -445,13 +437,10 @@ let $wait_condition= --source include/wait_condition.inc --echo # statement is waiting for release of read lock connection con2; ---echo # con2 flush table t2; connection default; ---echo # default unlock tables; connection con1; ---echo # con1 --reap --echo # @@ -459,13 +448,10 @@ connection con1; --echo # connection default; ---echo # default flush tables with read lock; connection con1; ---echo # con1 send lock tables t2 write; connection default; ---echo # default let $wait_condition= select count(*) = 1 from information_schema.processlist where state = "Waiting for global read lock" and @@ -473,13 +459,10 @@ let $wait_condition= --source include/wait_condition.inc --echo # statement is waiting for release of read lock connection con2; ---echo # con2 flush table t2; connection default; ---echo # default unlock tables; connection con1; ---echo # con1 --reap unlock tables; @@ -553,13 +536,10 @@ drop table if exists t1; create table t1 (i int); connect (flush,localhost,root,,test,,); connection default; ---echo connection: default lock tables t1 write; connection flush; ---echo connection: flush --send flush tables with read lock; connection default; ---echo connection: default let $wait_condition= select count(*) = 1 from information_schema.processlist where state = "Waiting for global read lock" and @@ -568,14 +548,12 @@ let $wait_condition= alter table t1 add column j int; connect (insert,localhost,root,,test,,); connection insert; ---echo connection: insert let $wait_condition= select count(*) = 1 from information_schema.processlist where state = "Waiting for global read lock" and info = "flush tables with read lock"; --source include/wait_condition.inc --send insert into t1 values (1,2); ---echo connection: default connection default; let $wait_condition= select count(*) = 1 from information_schema.processlist @@ -584,7 +562,6 @@ let $wait_condition= --source include/wait_condition.inc unlock tables; connection flush; ---echo connection: flush --reap let $wait_condition= select count(*) = 1 from information_schema.processlist @@ -615,13 +592,10 @@ drop table if exists t1; create table t1 (i int); connect (flush,localhost,root,,test,,); connection default; ---echo connection: default lock tables t1 write; connection flush; ---echo connection: flush --send flush tables with read lock; connection default; ---echo connection: default let $wait_condition= select count(*) = 1 from information_schema.processlist where state = "Waiting for global read lock"; @@ -684,13 +658,10 @@ drop table if exists t1; create table t1 (i int); connect (flush,localhost,root,,test,,); connection default; ---echo connection: default lock tables t1 write; connection flush; ---echo connection: flush --send flush tables with read lock; connection default; ---echo connection: default let $wait_condition= select count(*) = 1 from information_schema.processlist where state = "Waiting for global read lock"; @@ -718,8 +689,6 @@ insert into t1 values (1,1,0),(2,2,0),(3,3,0),(4,4,0),(5,5,0); begin; update t1 set c3=c3+1 where c2=3; ---echo # ---echo # Switching to connection 'con46272'. connect (con46272,localhost,root,,test,,); connection con46272; --echo # The below ALTER TABLE statement should wait till transaction @@ -728,8 +697,6 @@ connection con46272; --echo # Sending: --send alter table t1 add column c4 int; ---echo # ---echo # Switching to connection 'default'. connection default; --echo # Wait until the above ALTER TABLE gets blocked because this --echo # connection holds SW metadata lock on table to be altered. @@ -746,14 +713,10 @@ update t1 set c3=c3+1 where c2=4; --echo # Unblock ALTER TABLE by committing transaction. commit; ---echo # ---echo # Switching to connection 'con46272'. connection con46272; --echo # Reaping ALTER TABLE. --reap ---echo # ---echo # Switching to connection 'default'. connection default; disconnect con46272; drop table t1; @@ -794,14 +757,12 @@ DROP VIEW v1; CREATE TABLE t1 ( f1 integer ); CREATE VIEW v1 AS SELECT f1 FROM t1 ; ---echo # Connection 2 connect (con2,localhost,root); LOCK TABLES t1 WRITE, v1 READ; FLUSH TABLE t1; disconnect con2; --source include/wait_until_disconnected.inc ---echo # Connection 1 connection default; LOCK TABLES t1 WRITE; FLUSH TABLE t1; # Assertion happened here @@ -826,12 +787,10 @@ create view v1 as select i from t1; begin; select * from t1; ---echo # Switching to connection 'con50913'. connection con50913; --echo # Sending: --send alter table t1 add column j int ---echo # Switching to connection 'default'. connection default; --echo # Wait until ALTER TABLE gets blocked. let $wait_condition= @@ -847,22 +806,18 @@ delete a from t1 as a where i = 1; --echo # Unblock ALTER TABLE. commit; ---echo # Switching to connection 'con50913'. connection con50913; --echo # Reaping ALTER TABLE; --reap ---echo # Switching to connection 'default'. connection default; begin; select * from v1; ---echo # Switching to connection 'con50913'. connection con50913; --echo # Sending: --send alter table t1 drop column j ---echo # Switching to connection 'default'. connection default; --echo # Wait until ALTER TABLE gets blocked. let $wait_condition= @@ -878,12 +833,10 @@ insert into v1 values (1); --echo # Unblock ALTER TABLE. commit; ---echo # Switching to connection 'con50913'. connection con50913; --echo # Reaping ALTER TABLE; --reap ---echo # Switching to connection 'default'. connection default; disconnect con50913; drop view v1; @@ -910,17 +863,14 @@ SET SESSION lock_wait_timeout= 1; --echo # Test 1: acquire exclusive lock --echo # ---echo # Connection default connection default; START TRANSACTION; INSERT INTO t1 VALUES (1); ---echo # Connection 2 connection con2; --error ER_LOCK_WAIT_TIMEOUT DROP TABLE t1; ---echo # Connection default connection default; COMMIT; @@ -928,17 +878,14 @@ COMMIT; --echo # Test 2: upgrade shared lock --echo # ---echo # Connection default connection default; START TRANSACTION; SELECT * FROM t1; ---echo # Connection 2 connection con2; --error ER_LOCK_WAIT_TIMEOUT ALTER TABLE t1 RENAME TO t2; ---echo # Connection default connection default; COMMIT; @@ -946,16 +893,13 @@ COMMIT; --echo # Test 3: acquire shared lock --echo # ---echo # Connection default connection default; LOCK TABLE t1 WRITE; ---echo # Connection 2 connection con2; --error ER_LOCK_WAIT_TIMEOUT INSERT INTO t1(id) VALUES (2); ---echo # Connection default connection default; UNLOCK TABLES; @@ -963,16 +907,13 @@ UNLOCK TABLES; --echo # Test 4: table level locks --echo # ---echo # Connection default connection default; LOCK TABLE t1 READ; ---echo # Connection 2 connection con2; --error ER_LOCK_WAIT_TIMEOUT INSERT INTO t1(id) VALUES(4); ---echo # Connection default connection default; UNLOCK TABLES; @@ -982,16 +923,13 @@ UNLOCK TABLES; connect(con3, localhost, root); ---echo # Connection default connection default; LOCK TABLE t1 READ; ---echo # Connection con3 connection con3; --echo # Sending: --send FLUSH TABLES ---echo # Connection con2 connection con2; let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist @@ -1000,11 +938,9 @@ let $wait_condition= --error ER_LOCK_WAIT_TIMEOUT SELECT * FROM t1; ---echo # Connection default connection default; UNLOCK TABLES; ---echo # Connection con3 connection con3; --echo # Reaping: FLUSH TABLES --reap @@ -1013,17 +949,14 @@ connection con3; --echo # Test 6: Timeouts in I_S queries --echo # ---echo # Connection default connection default; CREATE TABLE t2 (id INT); LOCK TABLE t2 WRITE; ---echo # Connection con3 connection con3; --echo # Sending: --send DROP TABLE t1, t2 ---echo # Connection con2 connection con2; let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist @@ -1036,16 +969,13 @@ let $wait_condition= SELECT table_name, table_comment FROM information_schema.tables WHERE table_schema= 'test' AND table_name= 't1'; ---echo # Connection default connection default; UNLOCK TABLES; ---echo # Connection con3 connection con3; --echo # Reaping: DROP TABLE t1, t2 --reap ---echo # Connection default connection default; --echo # Cleanup disconnect con2; @@ -1064,12 +994,10 @@ connect (con2, localhost, root, , ); connection default; create table t3 (i int); ---echo # Switching to connection 'con1' connection con1; --echo # Lock 't3' so upcoming RENAME is blocked. lock table t3 read; ---echo # Switching to connection 'con2' connection con2; --echo # Remember ID for this connection. let $ID= `select connection_id()`; @@ -1078,7 +1006,6 @@ let $ID= `select connection_id()`; --echo # Sending: --send rename tables t1 to t2, t2 to t3; ---echo # Switching to connection 'default' connection default; --echo # Wait until RENAME TABLE is blocked on table 't3'. let $wait_condition= @@ -1090,17 +1017,14 @@ let $wait_condition= --replace_result $ID ID eval kill query $ID; ---echo # Switching to connection 'con2' connection con2; --echo # RENAME TABLE should be aborted but should not crash. --error ER_QUERY_INTERRUPTED --reap ---echo # Switching to connection 'con1' connection con1; unlock tables; ---echo # Switching to connection 'default' connection default; disconnect con1; disconnect con2; @@ -1120,13 +1044,11 @@ DROP TABLE IF EXISTS t1; CREATE TABLE t1 (id INT); LOCK TABLE t1 WRITE; ---echo # Connection con1 connect (con1, localhost, root); CREATE TEMPORARY TABLE t1 (id INT); # This alter should not block and timeout. ALTER TABLE t1 ADD COLUMN j INT; ---echo # Connection default connection default; disconnect con1; UNLOCK TABLES; diff --git a/mysql-test/t/lock_sync.test b/mysql-test/t/lock_sync.test index ef79cc2c0f4..af8435f7fbb 100644 --- a/mysql-test/t/lock_sync.test +++ b/mysql-test/t/lock_sync.test @@ -231,7 +231,6 @@ let $con_aux1= con1; let $con_aux2= con2; let $table= t1; ---echo # Switch to connection 'con1'. connection con1; --echo # Cache all functions used in the tests below so statements --echo # calling them won't need to open and lock mysql.proc table @@ -259,7 +258,6 @@ show create function f15; show create function f16; show create function f17; --enable_result_log ---echo # Switch back to connection 'default'. connection default; --echo # @@ -301,13 +299,11 @@ let $restore_table= t2; --echo # target table and thus does not take any lock on it. --echo # We check this for completeness of coverage. lock table t1 write; ---echo # Switching to connection 'con1'. connection con1; --echo # This statement should not be blocked. --disable_result_log describe t1; --enable_result_log ---echo # Switching to connection 'default'. connection default; unlock tables; @@ -316,7 +312,6 @@ unlock tables; --echo # --echo # The above is true for SHOW statements as well. lock table t1 write; ---echo # Switching to connection 'con1'. connection con1; --echo # These statements should not be blocked. # The below test for SHOW CREATE TABLE is disabled until bug 52593 @@ -328,7 +323,6 @@ show create table t1; --disable_result_log show keys from t1; --enable_result_log ---echo # Switching to connection 'default'. connection default; unlock tables; @@ -412,6 +406,12 @@ let $restore_table= t2; --echo # 2.8 REPLACE with a subquery. --echo # --echo # Same is true for this statement as well. + +--echo # Suppress warnings for REPLACE ... SELECT +--disable_query_log +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +--enable_query_log + let $statement= replace into t2 select i+5 from t1; let $restore_table= t2; --source include/check_no_concurrent_insert.inc @@ -879,125 +879,6 @@ set @@global.concurrent_insert= @old_concurrent_insert; --echo # ---echo # Test for bug #45143 "All connections hang on concurrent ALTER TABLE". ---echo # ---echo # Concurrent execution of statements which required weak write lock ---echo # (TL_WRITE_ALLOW_WRITE) on several instances of the same table and ---echo # statements which tried to acquire stronger write lock (TL_WRITE, ---echo # TL_WRITE_ALLOW_READ) on this table might have led to deadlock. -# -# Suppress warnings for INSERTs that use get_lock(). -# -disable_query_log; -call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); -enable_query_log; - ---disable_warnings -drop table if exists t1; -drop view if exists v1; ---enable_warnings ---echo # Create auxiliary connections used through the test. -connect (con_bug45143_1,localhost,root,,test,,); -connect (con_bug45143_3,localhost,root,,test,,); -connect (con_bug45143_2,localhost,root,,test,,); -connection default; ---echo # Reset DEBUG_SYNC facility before using it. -set debug_sync= 'RESET'; ---echo # Turn off logging so calls to locking subsystem performed ---echo # for general_log table won't interfere with our test. -set @old_general_log = @@global.general_log; -set @@global.general_log= OFF; - -create table t1 (i int) engine=InnoDB; ---echo # We have to use view in order to make LOCK TABLES avoid ---echo # acquiring SNRW metadata lock on table. -create view v1 as select * from t1; -insert into t1 values (1); ---echo # Prepare user lock which will be used for resuming execution of ---echo # the first statement after it acquires TL_WRITE_ALLOW_WRITE lock. -select get_lock("lock_bug45143_wait", 0); - ---echo # Switch to connection 'con_bug45143_1'. -connection con_bug45143_1; ---echo # Sending: ---send insert into t1 values (get_lock("lock_bug45143_wait", 100)); - ---echo # Switch to connection 'con_bug45143_2'. -connection con_bug45143_2; ---echo # Wait until the above INSERT takes TL_WRITE_ALLOW_WRITE lock on 't1' ---echo # and then gets blocked on user lock 'lock_bug45143_wait'. -let $wait_condition= select count(*)= 1 from information_schema.processlist - where state= 'User lock' and - info='insert into t1 values (get_lock("lock_bug45143_wait", 100))'; ---source include/wait_condition.inc ---echo # Ensure that upcoming SELECT waits after acquiring TL_WRITE_ALLOW_WRITE ---echo # lock for the first instance of 't1'. -set debug_sync='thr_multi_lock_after_thr_lock SIGNAL parked WAIT_FOR go'; ---echo # Sending: ---send select count(*) > 0 from t1 as a, t1 as b for update; - ---echo # Switch to connection 'con_bug45143_3'. -connection con_bug45143_3; ---echo # Wait until the above SELECT ... FOR UPDATE is blocked after ---echo # acquiring lock for the the first instance of 't1'. -set debug_sync= 'now WAIT_FOR parked'; ---echo # Send LOCK TABLE statement which will try to get TL_WRITE lock on 't1': ---send lock table v1 write; - ---echo # Switch to connection 'default'. -connection default; ---echo # Wait until this LOCK TABLES statement starts waiting for table lock. -let $wait_condition= select count(*)= 1 from information_schema.processlist - where state= 'Waiting for table level lock' and - info='lock table v1 write'; ---source include/wait_condition.inc ---echo # Allow SELECT ... FOR UPDATE to resume. ---echo # Since it already has TL_WRITE_ALLOW_WRITE lock on the first instance ---echo # of 't1' it should be able to get lock on the second instance without ---echo # waiting, even although there is another thread which has such lock ---echo # on this table and also there is a thread waiting for a TL_WRITE on it. -set debug_sync= 'now SIGNAL go'; - ---echo # Switch to connection 'con_bug45143_2'. -connection con_bug45143_2; ---echo # Reap SELECT ... FOR UPDATE ---reap - ---echo # Switch to connection 'default'. -connection default; ---echo # Resume execution of the INSERT statement. -select release_lock("lock_bug45143_wait"); - ---echo # Switch to connection 'con_bug45143_1'. -connection con_bug45143_1; ---echo # Reap INSERT statement. ---echo # In Statement and Mixed replication mode we get here "Unsafe ---echo # for binlog" warnings. In row mode there are no warnings. ---echo # Hide the discrepancy. ---disable_warnings ---reap ---enable_warnings - - ---echo # Switch to connection 'con_bug45143_3'. -connection con_bug45143_3; ---echo # Reap LOCK TABLES statement. ---reap -unlock tables; - ---echo # Switch to connection 'default'. -connection default; ---echo # Do clean-up. -disconnect con_bug45143_1; -disconnect con_bug45143_2; -disconnect con_bug45143_3; -set debug_sync= 'RESET'; -set @@global.general_log= @old_general_log; -drop view v1; -drop table t1; - - ---echo # --echo # Bug#50821 Deadlock between LOCK TABLES and ALTER TABLE --echo # @@ -1008,17 +889,14 @@ DROP TABLE IF EXISTS t1, t2; CREATE TABLE t1(id INT); CREATE TABLE t2(id INT); ---echo # Connection con2 connect (con2, localhost, root); START TRANSACTION; SELECT * FROM t1; ---echo # Connection default connection default; --echo # Sending: --send ALTER TABLE t1 ADD COLUMN j INT ---echo # Connection con2 connection con2; let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist @@ -1031,7 +909,6 @@ INSERT INTO t2 SELECT * FROM t1; COMMIT; ---echo # Connection default connection default; --echo # Reaping ALTER TABLE t1 ADD COLUMN j INT --reap @@ -1047,88 +924,29 @@ disconnect con2; CREATE EVENT e1 ON SCHEDULE EVERY 5 HOUR DO SELECT 1; CREATE EVENT e2 ON SCHEDULE EVERY 5 HOUR DO SELECT 2; ---echo # Connection con1 connect(con1, localhost, root); SET DEBUG_SYNC="before_lock_tables_takes_lock SIGNAL drop WAIT_FOR query"; --echo # Sending: --send DROP EVENT e1; ---echo # Connection default connection default; SET DEBUG_SYNC="now WAIT_FOR drop"; SELECT name FROM mysql.event, INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE definer = VARIABLE_VALUE; SET DEBUG_SYNC="now SIGNAL query"; ---echo # Connection con1 connection con1; --echo # Reaping: DROP EVENT t1 --reap disconnect con1; --source include/wait_until_disconnected.inc ---echo # Connection default connection default; DROP EVENT e2; SET DEBUG_SYNC="RESET"; --echo # ---echo # Bug#55930 Assertion `thd->transaction.stmt.is_empty() || ---echo # thd->in_sub_stmt || (thd->state.. ---echo # - ---disable_warnings -DROP TABLE IF EXISTS t1; ---enable_warnings - -CREATE TABLE t1(a INT) engine=InnoDB; -INSERT INTO t1 VALUES (1), (2); - -connect (con1, localhost, root); -connect (con2, localhost, root); - ---echo # Connection con1 -connection con1; -SET SESSION lock_wait_timeout= 1; -SET DEBUG_SYNC= 'ha_admin_open_ltable SIGNAL opti_recreate WAIT_FOR opti_analyze'; ---echo # Sending: ---send OPTIMIZE TABLE t1 - ---echo # Connection con2 -connection con2; -SET DEBUG_SYNC= 'now WAIT_FOR opti_recreate'; -SET DEBUG_SYNC= 'after_lock_tables_takes_lock SIGNAL thrlock WAIT_FOR release_thrlock'; ---echo # Sending: ---send INSERT INTO t1 VALUES (3) - ---echo # Connection default -connection default; -SET DEBUG_SYNC= 'now WAIT_FOR thrlock'; -SET DEBUG_SYNC= 'now SIGNAL opti_analyze'; - ---echo # Connection con1 -connection con1; ---echo # Reaping: OPTIMIZE TABLE t1 ---reap -SET DEBUG_SYNC= 'now SIGNAL release_thrlock'; -disconnect con1; ---source include/wait_until_disconnected.inc - ---echo # Connection con2 -connection con2; ---echo # Reaping: INSERT INTO t1 VALUES (3) ---reap -disconnect con2; ---source include/wait_until_disconnected.inc - ---echo # Connection default -connection default; -DROP TABLE t1; -SET DEBUG_SYNC= 'RESET'; - - ---echo # --echo # Bug#57130 crash in Item_field::print during SHOW CREATE TABLE or VIEW --echo # @@ -1144,7 +962,6 @@ CREATE VIEW v1 AS SELECT * FROM t1 WHERE f1() = 1; DROP FUNCTION f1; connect(con2, localhost, root); ---echo # Connection con1 connect (con1, localhost, root); # Need to trigger this sync point at least twice in order to # get valgrind test failures without the patch @@ -1152,7 +969,6 @@ SET DEBUG_SYNC= 'open_tables_after_open_and_process_table SIGNAL opened WAIT_FOR --echo # Sending: --send SHOW CREATE VIEW v1 ---echo # Connection con2 connection con2; SET DEBUG_SYNC= 'now WAIT_FOR opened'; SET DEBUG_SYNC= 'now SIGNAL dropped'; @@ -1160,7 +976,6 @@ SET DEBUG_SYNC= 'now WAIT_FOR opened'; --echo # Sending: --send FLUSH TABLES ---echo # Connection default connection default; --echo # Waiting for FLUSH TABLES to be blocked. let $wait_condition= SELECT COUNT(*)=1 FROM information_schema.processlist @@ -1168,17 +983,14 @@ let $wait_condition= SELECT COUNT(*)=1 FROM information_schema.processlist --source include/wait_condition.inc SET DEBUG_SYNC= 'now SIGNAL dropped'; ---echo # Connection con1 connection con1; --echo # Reaping: SHOW CREATE VIEW v1 --reap ---echo # Connection con2 connection con2; --echo # Reaping: FLUSH TABLES --reap ---echo # Connection default connection default; SET DEBUG_SYNC= 'RESET'; DROP VIEW v1; @@ -1186,6 +998,102 @@ DROP TABLE t1; disconnect con1; disconnect con2; + +--echo # +--echo # Bug#28587 SELECT is blocked by INSERT waiting on read lock, even with low_priority_updates +--echo # +set low_priority_updates=1; +--disable_warnings +drop table if exists t1; +drop table if exists t2; +--enable_warnings +set debug_sync='RESET'; +create table t1 (a int, b int, unique key t1$a (a)); +create table t2 (j int, k int); +set debug_sync='after_lock_tables_takes_lock SIGNAL parked WAIT_FOR go'; +--echo # Sending: +--send insert into t2 select * from t1; +connect (update,localhost,root,,); +connection update; +set debug_sync='now WAIT_FOR parked'; +set low_priority_updates=1; +show variables like 'low_priority_updates'; +let $ID= `select connection_id()`; +--send insert into t1 values (1, 2) ON DUPLICATE KEY UPDATE b = 2; +connect (select,localhost,root,,); +# we must wait till the insert opens and locks the table +let $wait_condition= + select count(*) = 1 from information_schema.processlist + where state = "Waiting for table level lock" and id = $ID; +--source include/wait_condition.inc +select * from t1; +set debug_sync='now SIGNAL go'; +connection default; +disconnect update; +disconnect select; +--echo # Reaping INSERT SELECT +--reap +drop tables t1, t2; +set low_priority_updates=default; +set debug_sync='RESET'; + + +--echo # +--echo # Additional test coverage for LOCK TABLES ... READ LOCAL +--echo # for InnoDB tables. +--echo # +--echo # Check that we correctly handle deadlocks which can occur +--echo # during metadata lock upgrade which happens when one tries +--echo # to use LOCK TABLES ... READ LOCAL for InnoDB tables. + +--enable_connect_log +CREATE TABLE t1 (i INT) ENGINE=InnoDB; +CREATE TABLE t2 (j INT) ENGINE=InnoDB; + +--echo # Execute LOCK TABLE READ LOCK which will pause after acquiring +--echo # SR metadata lock and before upgrading it to SRO lock. +SET DEBUG_SYNC="after_open_table_mdl_shared SIGNAL locked WAIT_FOR go"; +--echo # Sending: +--send LOCK TABLE t1 READ LOCAL + +connect (con1, localhost, root); +SET DEBUG_SYNC="now WAIT_FOR locked"; +--echo # Execute RENAME TABLE which will try to acquire X lock. +--echo # Sending: +--send RENAME TABLE t1 TO t3, t2 TO t1, t3 TO t2 + +connect (con2, localhost, root); +--echo # Wait until RENAME TABLE is blocked. +let $wait_condition= + select count(*) = 1 from information_schema.processlist + where state = "Waiting for table metadata lock" and + info = "RENAME TABLE t1 TO t3, t2 TO t1, t3 TO t2"; +--source include/wait_condition.inc +--echo # Resume LOCK TABLE statement. It should try to +--echo # upgrade SR lock to SRO lock which will create +--echo # deadlock due to presence of pending X lock. +--echo # Deadlock should be detected and LOCK TABLES should +--echo # release its MDL and retry opening of tables. +SET DEBUG_SYNC="now SIGNAL go"; + +connection con1; +--echo # RENAME TABLE should be able to complete. Reap it. +--reap + +connection default; +--echo # Reap LOCK TABLES. +--reap +--echo # Check that we see new version of table. +SELECT * FROM t1; +UNLOCK TABLES; + +--echo # Clean-up. +SET DEBUG_SYNC="RESET"; +disconnect con1; +disconnect con2; +DROP TABLES t1, t2; +--disable_connect_log + # Check that all connections opened by test cases in this file are really # gone so execution of other tests won't be affected by their presence. --source include/wait_until_count_sessions.inc diff --git a/mysql-test/t/log_state.test b/mysql-test/t/log_state.test index 12c7a7fd92b..68e06dfa042 100644 --- a/mysql-test/t/log_state.test +++ b/mysql-test/t/log_state.test @@ -33,9 +33,7 @@ flush logs; show global variables where Variable_name = 'general_log' or Variable_name = 'slow_query_log'; ---echo # Establish connection con1 (user=root) connect (con1,localhost,root,,); ---echo # Switch to connection con1 connection con1; # Please increase @long_query_time if the corresponding selects show an # additional unexpected entry like @@ -48,12 +46,10 @@ set session long_query_time = @long_query_time; select sleep(@long_query_time + 1); --replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME 12 THREAD_ID select * from mysql.slow_log where sql_text NOT LIKE '%slow_log%'; ---echo # Switch to connection default connection default; set global slow_query_log= ON; set local slow_query_log= ON; ---echo # Switch to connection con1 connection con1; set session long_query_time = @long_query_time; select sleep(@long_query_time + 1); @@ -64,7 +60,6 @@ select sleep(@long_query_time + 2); --replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME 12 THREAD_ID select * from mysql.slow_log where sql_text NOT LIKE '%slow_log%'; ---echo # Switch to connection default connection default; show global variables where Variable_name = 'general_log' or Variable_name = 'slow_query_log'; @@ -328,7 +323,6 @@ SET GLOBAL general_log_file = @old_general_log_file; # Cleanup # # Disconnect must be done last to avoid delayed 'Quit' message in general log ---echo # Close connection con1 disconnect con1; # set back the saved default values connection default; diff --git a/mysql-test/t/mdev375.test b/mysql-test/t/mdev375.test index fe259b37808..92e403b6513 100644 --- a/mysql-test/t/mdev375.test +++ b/mysql-test/t/mdev375.test @@ -17,6 +17,7 @@ SELECT 2; --connection default SELECT 0; +show status like "Threads_connected"; SET GLOBAL log_warnings=default; SET GLOBAL max_connections=default; diff --git a/mysql-test/t/mdl_sync.test b/mysql-test/t/mdl_sync.test index 8e809788a08..4aa191d3dfc 100644 --- a/mysql-test/t/mdl_sync.test +++ b/mysql-test/t/mdl_sync.test @@ -101,7 +101,6 @@ create table t1 (c1 int); --echo # handler t1 open; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that S, SH, SR and SW locks are compatible with it. handler t1 open t; @@ -120,15 +119,10 @@ alter table t1 add index (not_exist); --echo # lock. --error ER_DUP_ENTRY alter table t1 add primary key (c1); ---echo # Check that SNRW lock is compatible with S lock. -lock table t1 write; -insert into t1 values (1); -unlock tables; --echo # Check that X lock is incompatible with S lock. --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above RENAME is blocked because of S lock. let $wait_condition= @@ -137,29 +131,24 @@ let $wait_condition= info = "rename table t1 to t2"; --source include/wait_condition.inc --echo # ---echo # Switching to connection 'default'. connection default; --echo # Unblock RENAME TABLE. handler t1 close; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping RENAME TABLE. --reap --echo # Restore the original state of the things. rename table t2 to t1; --echo # ---echo # Switching to connection 'default'. connection default; handler t1 open; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that upgrade from SNW to X is blocked by presence of S lock. --echo # Sending: --send alter table t1 add column c2 int; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above ALTER TABLE is blocked because of S lock. let $wait_condition= @@ -168,53 +157,16 @@ let $wait_condition= info = "alter table t1 add column c2 int"; --source include/wait_condition.inc --echo # ---echo # Switching to connection 'default'. connection default; --echo # Unblock ALTER TABLE. handler t1 close; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping ALTER TABLE. --reap --echo # Restore the original state of the things. alter table t1 drop column c2; --echo # ---echo # Switching to connection 'default'. -connection default; -handler t1 open; ---echo # ---echo # Switching to connection 'mdl_con1'. -connection mdl_con1; ---echo # Check that upgrade from SNRW to X is blocked by presence of S lock. -lock table t1 write; ---echo # Sending: ---send alter table t1 add column c2 int; ---echo # ---echo # Switching to connection 'mdl_con2'. -connection mdl_con2; ---echo # Check that the above upgrade of SNRW to X in ALTER TABLE is blocked ---echo # because of S lock. -let $wait_condition= - select count(*) = 1 from information_schema.processlist - where state = "Waiting for table metadata lock" and - info = "alter table t1 add column c2 int"; ---source include/wait_condition.inc ---echo # ---echo # Switching to connection 'default'. -connection default; ---echo # Unblock ALTER TABLE. -handler t1 close; ---echo # ---echo # Switching to connection 'mdl_con1'. -connection mdl_con1; ---echo # Reaping ALTER TABLE. ---reap ---echo # Restore the original state of the things. -alter table t1 drop column c2; -unlock tables; ---echo # ---echo # Switching to connection 'default'. connection default; --echo # --echo # 2) Acquire SH (shared high-priority) lock on the table. @@ -225,7 +177,6 @@ set debug_sync= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish'; --echo # Sending: --send select table_name, table_type, auto_increment, table_comment from information_schema.tables where table_schema='test' and table_name='t1'; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; set debug_sync= 'now WAIT_FOR locked'; --echo # Check that S, SH, SR and SW locks are compatible with it. @@ -253,7 +204,6 @@ unlock tables; --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above RENAME is blocked because of SH lock. let $wait_condition= @@ -264,32 +214,27 @@ let $wait_condition= --echo # Unblock RENAME TABLE. set debug_sync= 'now SIGNAL finish'; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping SELECT ... FROM I_S. --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping RENAME TABLE. --reap --echo # Restore the original state of the things. rename table t2 to t1; --echo # ---echo # Switching to connection 'default'. connection default; set debug_sync= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish'; --echo # Sending: --send select table_name, table_type, auto_increment, table_comment from information_schema.tables where table_schema='test' and table_name='t1'; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; set debug_sync= 'now WAIT_FOR locked'; --echo # Check that upgrade from SNW to X is blocked by presence of SH lock. --echo # Sending: --send alter table t1 add column c2 int; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above ALTER TABLE is blocked because of SH lock. let $wait_condition= @@ -300,24 +245,20 @@ let $wait_condition= --echo # Unblock RENAME TABLE. set debug_sync= 'now SIGNAL finish'; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping SELECT ... FROM I_S. --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping ALTER TABLE. --reap --echo # Restore the original state of the things. alter table t1 drop column c2; --echo # ---echo # Switching to connection 'default'. connection default; set debug_sync= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish'; --send select table_name, table_type, auto_increment, table_comment from information_schema.tables where table_schema='test' and table_name='t1'; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; set debug_sync= 'now WAIT_FOR locked'; --echo # Check that upgrade from SNRW to X is blocked by presence of S lock. @@ -325,7 +266,6 @@ lock table t1 write; --echo # Sending: --send alter table t1 add column c2 int; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above upgrade of SNRW to X in ALTER TABLE is blocked --echo # because of S lock. @@ -337,12 +277,10 @@ let $wait_condition= --echo # Unblock RENAME TABLE. set debug_sync= 'now SIGNAL finish'; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping SELECT ... FROM I_S. --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping ALTER TABLE. --reap @@ -350,7 +288,6 @@ connection mdl_con1; alter table t1 drop column c2; unlock tables; --echo # ---echo # Switching to connection 'default'. connection default; --echo # --echo # @@ -360,7 +297,6 @@ connection default; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that S, SH, SR and SW locks are compatible with it. handler t1 open; @@ -383,7 +319,6 @@ alter table t1 add primary key (c1); --echo # Sending: --send lock table t1 write; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Check that the above LOCK TABLES is blocked because of SR lock. let $wait_condition= @@ -394,25 +329,21 @@ let $wait_condition= --echo # Unblock LOCK TABLES. commit; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping LOCK TABLES. --reap delete from t1 limit 1; unlock tables; --echo # ---echo # Switching to connection 'default'. connection default; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that X lock is incompatible with SR lock. --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above RENAME is blocked because of SR lock. let $wait_condition= @@ -421,30 +352,25 @@ let $wait_condition= info = "rename table t1 to t2"; --source include/wait_condition.inc --echo # ---echo # Switching to connection 'default'. connection default; --echo # Unblock RENAME TABLE. commit; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping RENAME TABLE. --reap --echo # Restore the original state of the things. rename table t2 to t1; --echo # ---echo # Switching to connection 'default'. connection default; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that upgrade from SNW to X is blocked by presence of SR lock. --echo # Sending: --send alter table t1 add column c2 int; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above ALTER TABLE is blocked because of SR lock. let $wait_condition= @@ -453,12 +379,10 @@ let $wait_condition= info = "alter table t1 add column c2 int"; --source include/wait_condition.inc --echo # ---echo # Switching to connection 'default'. connection default; --echo # Unblock ALTER TABLE. commit; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping ALTER TABLE. --reap @@ -469,7 +393,6 @@ alter table t1 drop column c2; --echo # by presence of SR lock because SNRW is incompatible with SR anyway. --echo # --echo # ---echo # Switching to connection 'default'. connection default; --echo # --echo # @@ -479,7 +402,6 @@ connection default; begin; insert into t1 values (1); --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that S, SH, SR and SW locks are compatible with it. handler t1 open; @@ -503,7 +425,6 @@ alter table t1 add index (not_exist); --echo # Sending: --send alter table t1 add primary key (c1); --echo # ---echo # Switching to connection 'default'. connection default; --echo # Check that the above ALTER TABLE is blocked because of SW lock. let $wait_condition= @@ -514,24 +435,20 @@ let $wait_condition= --echo # Unblock ALTER TABLE. commit; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping ALTER TABLE. --error ER_DUP_ENTRY --reap --echo # ---echo # Switching to connection 'default'. connection default; begin; insert into t1 values (1); --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that SNRW lock is not compatible with SW lock. --echo # Sending: --send lock table t1 write; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Check that the above LOCK TABLES is blocked because of SW lock. let $wait_condition= @@ -542,25 +459,21 @@ let $wait_condition= --echo # Unblock LOCK TABLES. commit; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping LOCK TABLES. --reap delete from t1 limit 2; unlock tables; --echo # ---echo # Switching to connection 'default'. connection default; begin; insert into t1 values (1); --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that X lock is incompatible with SW lock. --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above RENAME is blocked because of SW lock. let $wait_condition= @@ -569,12 +482,10 @@ let $wait_condition= info = "rename table t1 to t2"; --source include/wait_condition.inc --echo # ---echo # Switching to connection 'default'. connection default; --echo # Unblock RENAME TABLE. commit; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping RENAME TABLE. --reap @@ -586,7 +497,6 @@ rename table t2 to t1; --echo # with SW anyway. --echo # --echo # ---echo # Switching to connection 'default'. connection default; --echo # --echo # @@ -597,7 +507,6 @@ set debug_sync= 'alter_opened_table SIGNAL locked WAIT_FOR finish'; --echo # Sending: --send alter table t1 add primary key (c1); --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; set debug_sync= 'now WAIT_FOR locked'; --echo # Check that S, SH, SR and SW locks are compatible with it. @@ -611,7 +520,6 @@ delete from t1 limit 1; --echo # Sending: --send alter table t1 add primary key (c1); --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above ALTER is blocked because of SU lock. let $wait_condition= @@ -622,32 +530,27 @@ let $wait_condition= --echo # Unblock ALTERs. set debug_sync= 'now SIGNAL finish'; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping first ALTER TABLE. --error ER_DUP_ENTRY --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping another ALTER TABLE. --error ER_DUP_ENTRY --reap --echo # ---echo # Switching to connection 'default'. connection default; set debug_sync= 'alter_opened_table SIGNAL locked WAIT_FOR finish'; --echo # Sending: --send alter table t1 add primary key (c1); --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; set debug_sync= 'now WAIT_FOR locked'; --echo # Check that SNRW lock is incompatible with SU lock. --echo # Sending: --send lock table t1 write; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above LOCK TABLES is blocked because of SU lock. let $wait_condition= @@ -658,33 +561,28 @@ let $wait_condition= --echo # Unblock ALTER and thus LOCK TABLES. set debug_sync= 'now SIGNAL finish'; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping ALTER TABLE. --error ER_DUP_ENTRY --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping LOCK TABLES --reap insert into t1 values (1); unlock tables; --echo # ---echo # Switching to connection 'default'. connection default; set debug_sync= 'alter_opened_table SIGNAL locked WAIT_FOR finish'; --echo # Sending: --send alter table t1 add primary key (c1); --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; set debug_sync= 'now WAIT_FOR locked'; --echo # Check that X lock is incompatible with SU lock. --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above RENAME is blocked because of SU lock. let $wait_condition= @@ -695,7 +593,6 @@ let $wait_condition= --echo # Unblock ALTER and thus RENAME TABLE. set debug_sync= 'now SIGNAL finish'; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Now we have ALTER TABLE with SU->SNW and RENAME TABLE with pending --echo # X-lock. In this case ALTER TABLE should be chosen as victim. @@ -703,7 +600,6 @@ connection default; --error ER_LOCK_DEADLOCK --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping RENAME TABLE --reap @@ -714,7 +610,6 @@ rename table t2 to t1; --echo # blocked by presence of another SU lock because SNW/SNRW is --echo # incompatible with SU anyway. --echo # ---echo # Switching to connection 'default'. connection default; --echo # --echo # @@ -725,7 +620,6 @@ set debug_sync= 'alter_table_copy_after_lock_upgrade SIGNAL locked WAIT_FOR fini --echo # Sending: --send alter table t1 add primary key (c1), lock=shared, algorithm=copy; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; set debug_sync= 'now WAIT_FOR locked'; --echo # Check that S, SH and SR locks are compatible with it. @@ -738,7 +632,6 @@ select count(*) from t1; --echo # Sending: --send delete from t1 limit 2; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above DELETE is blocked because of SNW lock. let $wait_condition= @@ -749,31 +642,26 @@ let $wait_condition= --echo # Unblock ALTER and thus DELETE. set debug_sync= 'now SIGNAL finish'; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping ALTER TABLE. --error ER_DUP_ENTRY --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping DELETE. --reap --echo # ---echo # Switching to connection 'default'. connection default; set debug_sync= 'alter_table_copy_after_lock_upgrade SIGNAL locked WAIT_FOR finish'; --echo # Sending: --send alter table t1 add primary key (c1), lock=shared, algorithm=copy; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; set debug_sync= 'now WAIT_FOR locked'; --echo # Check that SU lock is incompatible with SNW lock. --echo # Sending: --send alter table t1 add primary key (c1); --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above ALTER is blocked because of SNW lock. let $wait_condition= @@ -784,13 +672,11 @@ let $wait_condition= --echo # Unblock ALTERs. set debug_sync= 'now SIGNAL finish'; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping first ALTER TABLE. --error ER_DUP_ENTRY --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping another ALTER TABLE. --error ER_DUP_ENTRY @@ -800,20 +686,17 @@ connection mdl_con1; --echo # SNW is only used by ALTER TABLE after upgrading from SU --echo # and SU is also incompatible with SNW. --echo # ---echo # Switching to connection 'default'. connection default; set debug_sync= 'alter_table_copy_after_lock_upgrade SIGNAL locked WAIT_FOR finish'; --echo # Sending: --send alter table t1 add primary key (c1), lock=shared, algorithm=copy; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; set debug_sync= 'now WAIT_FOR locked'; --echo # Check that SNRW lock is incompatible with SNW lock. --echo # Sending: --send lock table t1 write; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above LOCK TABLES is blocked because of SNW lock. let $wait_condition= @@ -824,33 +707,28 @@ let $wait_condition= --echo # Unblock ALTER and thus LOCK TABLES. set debug_sync= 'now SIGNAL finish'; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping ALTER TABLE. --error ER_DUP_ENTRY --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping LOCK TABLES --reap insert into t1 values (1); unlock tables; --echo # ---echo # Switching to connection 'default'. connection default; set debug_sync= 'alter_table_copy_after_lock_upgrade SIGNAL locked WAIT_FOR finish'; --echo # Sending: --send alter table t1 add primary key (c1), algorithm=copy, lock=shared; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; set debug_sync= 'now WAIT_FOR locked'; --echo # Check that X lock is incompatible with SNW lock. --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above RENAME is blocked because of SNW lock. let $wait_condition= @@ -861,13 +739,11 @@ let $wait_condition= --echo # Unblock ALTER and thus RENAME TABLE. set debug_sync= 'now SIGNAL finish'; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping ALTER TABLE. --error ER_DUP_ENTRY --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping RENAME TABLE --reap @@ -878,7 +754,6 @@ rename table t2 to t1; --echo # blocked by presence of another SNW lock because SNW/SNRW is --echo # incompatible with SNW anyway. --echo # ---echo # Switching to connection 'default'. connection default; --echo # --echo # @@ -887,18 +762,14 @@ connection default; --echo # lock table t1 write; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that S and SH locks are compatible with it. -handler t1 open; -handler t1 close; select column_name from information_schema.columns where table_schema='test' and table_name='t1'; --echo # Check that SR lock is incompatible with SNRW lock. --echo # Sending: --send select count(*) from t1; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Check that the above SELECT is blocked because of SNRW lock. let $wait_condition= @@ -909,22 +780,18 @@ let $wait_condition= --echo # Unblock SELECT. unlock tables; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping SELECT. --reap --echo # ---echo # Switching to connection 'default'. connection default; lock table t1 write; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that SW lock is incompatible with SNRW lock. --echo # Sending: --send delete from t1 limit 1; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Check that the above DELETE is blocked because of SNRW lock. let $wait_condition= @@ -935,22 +802,18 @@ let $wait_condition= --echo # Unblock DELETE. unlock tables; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping DELETE. --reap --echo # ---echo # Switching to connection 'default'. connection default; lock table t1 write; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that SU lock is incompatible with SNRW lock. --echo # Sending: --send alter table t1 add primary key (c1); --echo # ---echo # Switching to connection 'default'. connection default; --echo # Check that the above ALTER is blocked because of SNRW lock. let $wait_condition= @@ -961,7 +824,6 @@ let $wait_condition= --echo # Unblock ALTER. unlock tables; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping ALTER TABLE. --error ER_DUP_ENTRY @@ -971,17 +833,14 @@ connection mdl_con1; --echo # SNW is only used by ALTER TABLE after upgrading from SU --echo # and SU is also incompatible with SNRW. --echo # ---echo # Switching to connection 'default'. connection default; lock table t1 write; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that SNRW lock is incompatible with SNRW lock. --echo # Sending: --send lock table t1 write; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Check that the above LOCK TABLES is blocked because of SNRW lock. let $wait_condition= @@ -992,24 +851,20 @@ let $wait_condition= --echo # Unblock waiting LOCK TABLES. unlock tables; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping LOCK TABLES --reap insert into t1 values (1); unlock tables; --echo # ---echo # Switching to connection 'default'. connection default; lock table t1 write; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that X lock is incompatible with SNRW lock. --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Check that the above RENAME is blocked because of SNRW lock. let $wait_condition= @@ -1020,7 +875,6 @@ let $wait_condition= --echo # Unblock RENAME TABLE unlock tables; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping RENAME TABLE --reap @@ -1031,7 +885,6 @@ rename table t2 to t1; --echo # blocked by presence of another SNRW lock because SNW/SNRW is --echo # incompatible with SNRW anyway. --echo # ---echo # Switching to connection 'default'. connection default; --echo # --echo # @@ -1040,18 +893,15 @@ connection default; --echo # create table t2 (c1 int); --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Take a lock on t2, so RENAME TABLE t1 TO t2 will get blocked --echo # after acquiring X lock on t1. lock tables t2 read; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that RENAME has acquired X lock on t1 and is waiting for t2. let $wait_condition= @@ -1063,7 +913,6 @@ where state = "Waiting for table metadata lock" and --echo # Sending: --send handler t1 open; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above HANDLER statement is blocked because of X lock. let $wait_condition= @@ -1074,29 +923,24 @@ where state = "Waiting for table metadata lock" and --echo # Unblock RENAME TABLE unlock tables; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping RENAME TABLE. --error ER_TABLE_EXISTS_ERROR --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping HANDLER. --reap handler t1 close; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Prepare for blocking RENAME TABLE. lock tables t2 read; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that RENAME has acquired X lock on t1 and is waiting for t2. let $wait_condition= @@ -1108,7 +952,6 @@ where state = "Waiting for table metadata lock" and --echo # Sending: --send select column_name from information_schema.columns where table_schema='test' and table_name='t1'; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above SELECT ... FROM I_S ... statement is blocked --echo # because of X lock. @@ -1120,28 +963,23 @@ where state = "Waiting for table metadata lock" and --echo # Unblock RENAME TABLE unlock tables; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping RENAME TABLE. --error ER_TABLE_EXISTS_ERROR --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping SELECT ... FROM I_S. --reap --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Prepare for blocking RENAME TABLE. lock tables t2 read; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that RENAME has acquired X lock on t1 and is waiting for t2. let $wait_condition= @@ -1153,7 +991,6 @@ where state = "Waiting for table metadata lock" and --echo # Sending: --send select count(*) from t1; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above SELECT statement is blocked --echo # because of X lock. @@ -1165,28 +1002,23 @@ where state = "Waiting for table metadata lock" and --echo # Unblock RENAME TABLE unlock tables; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping RENAME TABLE. --error ER_TABLE_EXISTS_ERROR --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping SELECT. --reap --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Prepare for blocking RENAME TABLE. lock tables t2 read; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that RENAME has acquired X lock on t1 and is waiting for t2. let $wait_condition= @@ -1198,7 +1030,6 @@ where state = "Waiting for table metadata lock" and --echo # Sending: --send delete from t1 limit 1; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above DELETE statement is blocked --echo # because of X lock. @@ -1210,28 +1041,23 @@ where state = "Waiting for table metadata lock" and --echo # Unblock RENAME TABLE unlock tables; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping RENAME TABLE. --error ER_TABLE_EXISTS_ERROR --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping DELETE. --reap --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Prepare for blocking RENAME TABLE. lock tables t2 read; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that RENAME has acquired X lock on t1 and is waiting for t2. let $wait_condition= @@ -1243,7 +1069,6 @@ where state = "Waiting for table metadata lock" and --echo # Sending: --send alter table t1 add primary key (c1); --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above ALTER statement is blocked --echo # because of X lock. @@ -1255,13 +1080,11 @@ where state = "Waiting for table metadata lock" and --echo # Unblock RENAME TABLE unlock tables; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping RENAME TABLE --error ER_TABLE_EXISTS_ERROR --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping ALTER. --error ER_DUP_ENTRY @@ -1271,17 +1094,14 @@ connection mdl_con1; --echo # SNW is only used by ALTER TABLE after upgrading from SU --echo # and SU is also incompatible with X. --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Prepare for blocking RENAME TABLE. lock tables t2 read; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that RENAME has acquired X lock on t1 and is waiting for t2. let $wait_condition= @@ -1293,7 +1113,6 @@ where state = "Waiting for table metadata lock" and --echo # Sending: --send lock table t1 write; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above LOCK TABLE statement is blocked --echo # because of X lock. @@ -1305,29 +1124,24 @@ where state = "Waiting for table metadata lock" and --echo # Unblock RENAME TABLE unlock tables; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping RENAME TABLE --error ER_TABLE_EXISTS_ERROR --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping LOCK TABLE. --reap unlock tables; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Prepare for blocking RENAME TABLE. lock tables t2 read; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that RENAME has acquired X lock on t1 and is waiting for t2. let $wait_condition= @@ -1339,7 +1153,6 @@ where state = "Waiting for table metadata lock" and --echo # Sending: --send rename table t1 to t3; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above RENAME statement is blocked --echo # because of X lock. @@ -1351,13 +1164,11 @@ where state = "Waiting for table metadata lock" and --echo # Unblock RENAME TABLE unlock tables; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping RENAME TABLE --error ER_TABLE_EXISTS_ERROR --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping RENAME. --reap @@ -1373,7 +1184,6 @@ rename table t3 to t1; --echo # --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # --echo # 1) Check compatibility for pending SNW lock. @@ -1382,13 +1192,11 @@ connection mdl_con2; begin; insert into t1 values (1); --echo # ---echo # Switching to connection 'default'. connection default; --echo # Add pending SNW lock. --echo # Sending: --send alter table t1 add primary key (c1); --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that ALTER TABLE is waiting with pending SNW lock. let $wait_condition= @@ -1406,7 +1214,6 @@ select count(*) from t1; --echo # Sending: --send delete from t1 limit 1; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above DELETE is blocked because of pending SNW lock. let $wait_condition= @@ -1417,13 +1224,11 @@ where state = "Waiting for table metadata lock" and --echo # Unblock ALTER TABLE. commit; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping ALTER. --error ER_DUP_ENTRY --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping DELETE. --reap @@ -1432,7 +1237,6 @@ connection mdl_con1; --echo # they will also be blocked by active SW lock. --echo # --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # --echo # 2) Check compatibility for pending SNRW lock. @@ -1441,13 +1245,11 @@ connection mdl_con2; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Add pending SNRW lock. --echo # Sending: --send lock table t1 write; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that LOCK TABLE is waiting with pending SNRW lock. let $wait_condition= @@ -1456,15 +1258,12 @@ where state = "Waiting for table metadata lock" and info = "lock table t1 write"; --source include/wait_condition.inc --echo # Check that S and SH locks are compatible with pending SNRW -handler t1 open t; -handler t close; select column_name from information_schema.columns where table_schema='test' and table_name='t1'; --echo # Check that SR is incompatible with pending SNRW --echo # Sending: --send select count(*) from t1; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above SELECT is blocked because of pending SNRW lock. let $wait_condition= @@ -1475,29 +1274,24 @@ where state = "Waiting for table metadata lock" and --echo # Unblock LOCK TABLE. commit; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping LOCK TABLE. --reap unlock tables; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping SELECT. --reap --echo # Restore pending SNRW lock. --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Sending: --send lock table t1 write; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that LOCK TABLE is waiting with pending SNRW lock. let $wait_condition= @@ -1509,7 +1303,6 @@ where state = "Waiting for table metadata lock" and --echo # Sending: --send insert into t1 values (1); --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above INSERT is blocked because of pending SNRW lock. let $wait_condition= @@ -1520,29 +1313,24 @@ where state = "Waiting for table metadata lock" and --echo # Unblock LOCK TABLE. commit; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping LOCK TABLE. --reap unlock tables; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping INSERT. --reap --echo # Restore pending SNRW lock. --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Sending: --send lock table t1 write; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that LOCK TABLE is waiting with pending SNRW lock. let $wait_condition= @@ -1555,12 +1343,10 @@ where state = "Waiting for table metadata lock" and --error ER_DUP_ENTRY alter table t1 add primary key (c1); --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Unblock LOCK TABLE. commit; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping LOCK TABLE. --reap @@ -1570,7 +1356,6 @@ unlock tables; --echo # they will also be blocked by active SR lock. --echo # --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # --echo # 3) Check compatibility for pending X lock. @@ -1579,13 +1364,11 @@ connection mdl_con2; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Add pending X lock. --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that RENAME TABLE is waiting with pending X lock. let $wait_condition= @@ -1600,7 +1383,6 @@ select column_name from information_schema.columns where --echo # Sending: --send handler t1 open; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above HANDLER OPEN is blocked because of pending X lock. let $wait_condition= @@ -1611,31 +1393,26 @@ where state = "Waiting for table metadata lock" and --echo # Unblock RENAME TABLE. commit; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping RENAME TABLE. --error ER_TABLE_EXISTS_ERROR --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping HANDLER t1 OPEN. --reap handler t1 close; --echo # Restore pending X lock. --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Add pending X lock. --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that RENAME TABLE is waiting with pending X lock. let $wait_condition= @@ -1647,7 +1424,6 @@ where state = "Waiting for table metadata lock" and --echo # Sending: --send select count(*) from t1; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above SELECT is blocked because of pending X lock. let $wait_condition= @@ -1658,30 +1434,25 @@ where state = "Waiting for table metadata lock" and --echo # Unblock RENAME TABLE. commit; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping RENAME TABLE. --error ER_TABLE_EXISTS_ERROR --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping SELECT. --reap --echo # Restore pending X lock. --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Add pending X lock. --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that RENAME TABLE is waiting with pending X lock. let $wait_condition= @@ -1693,7 +1464,6 @@ where state = "Waiting for table metadata lock" and --echo # Sending: --send delete from t1 limit 1; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above DELETE is blocked because of pending X lock. let $wait_condition= @@ -1704,30 +1474,25 @@ where state = "Waiting for table metadata lock" and --echo # Unblock RENAME TABLE. commit; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping RENAME TABLE. --error ER_TABLE_EXISTS_ERROR --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping DELETE. --reap --echo # Restore pending X lock. --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Add pending X lock. --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that RENAME TABLE is waiting with pending X lock. let $wait_condition= @@ -1739,7 +1504,6 @@ where state = "Waiting for table metadata lock" and --echo # Sending: --send alter table t1 add primary key (c1); --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above ALTER TABLE is blocked because of pending X lock. let $wait_condition= @@ -1750,30 +1514,25 @@ where state = "Waiting for table metadata lock" and --echo # Unblock RENAME TABLE. commit; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping RENAME TABLE. --error ER_TABLE_EXISTS_ERROR --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping ALTER TABLE. --error ER_DUP_ENTRY --reap --echo # Restore pending X lock. --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; handler t1 open; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Add pending X lock. --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that RENAME TABLE is waiting with pending X lock. let $wait_condition= @@ -1785,7 +1544,6 @@ where state = "Waiting for table metadata lock" and --echo # Sending: --send lock table t1 write; --echo # ---echo # Switching to connection 'mdl_con3'. connection mdl_con3; --echo # Check that the above LOCK TABLES is blocked because of pending X lock. let $wait_condition= @@ -1794,24 +1552,20 @@ where state = "Waiting for table metadata lock" and info = "lock table t1 write"; --source include/wait_condition.inc --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Unblock RENAME TABLE. handler t1 close; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping RENAME TABLE. --error ER_TABLE_EXISTS_ERROR --reap --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reaping LOCK TABLES. --reap unlock tables; --echo # ---echo # Switching to connection 'default'. connection default; --echo # @@ -1833,7 +1587,6 @@ connection default; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Create an active SNW lock on t2. --echo # We have to use DEBUG_SYNC facility as otherwise SNW lock @@ -1843,7 +1596,6 @@ set debug_sync= 'alter_table_copy_after_lock_upgrade SIGNAL locked WAIT_FOR fini --echo # Sending: --send alter table t2 add primary key (c1), algorithm=copy, lock=shared; --echo # ---echo # Switching to connection 'default'. connection default; set debug_sync= 'now WAIT_FOR locked'; --echo # SR lock should be acquired without any waiting. @@ -1855,7 +1607,6 @@ select count(*) from t1; --echo # Sending: --send insert into t2 values (1); --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above INSERT is blocked. let $wait_condition= @@ -1866,13 +1617,11 @@ where state = "Waiting for table metadata lock" and --echo # Unblock ALTER TABLE and thus INSERT. set debug_sync= 'now SIGNAL finish'; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reap ALTER TABLE. --error ER_DUP_ENTRY --reap --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reap INSERT. --reap @@ -1887,14 +1636,12 @@ commit; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Create an active SNW lock on t1. set debug_sync= 'alter_table_copy_after_lock_upgrade SIGNAL locked WAIT_FOR finish'; --echo # Sending: --send alter table t1 add primary key (c1), algorithm=copy, lock=shared; --echo # ---echo # Switching to connection 'default'. connection default; set debug_sync= 'now WAIT_FOR locked'; --echo # We should still be able to get SR lock without waiting. @@ -1905,7 +1652,6 @@ select count(*) from t1; --echo # Sending: --send insert into t1 values (1); --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above INSERT is blocked. let $wait_condition= @@ -1916,13 +1662,11 @@ where state = "Waiting for table metadata lock" and --echo # Unblock ALTER TABLE and thus INSERT. set debug_sync= 'now SIGNAL finish'; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reap ALTER TABLE. --error ER_DUP_ENTRY --reap --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reap INSERT. --reap @@ -1935,13 +1679,11 @@ commit; begin; insert into t1 values (1); --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Create pending SNW lock on t1. --echo # Sending: --send alter table t1 add primary key (c1); --echo # ---echo # Switching to connection 'default'. connection default; --echo # Wait until ALTER TABLE starts waiting for SNW lock. let $wait_condition= @@ -1955,13 +1697,11 @@ delete from t1 limit 1; --echo # Unblock ALTER TABLE. commit; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reap ALTER TABLE. --error ER_DUP_ENTRY --reap --echo # ---echo # Switching to connection 'default'. connection default; --echo # --echo # 2) Now similar tests for active SNW lock which is being upgraded @@ -1972,20 +1712,17 @@ connection default; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Start transaction which will prevent SNW -> X upgrade from --echo # completing immediately. begin; select count(*) from t2; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Create SNW lock pending upgrade to X on t2. --echo # Sending: --send alter table t2 add column c2 int; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Wait until ALTER TABLE starts waiting X lock. let $wait_condition= @@ -1997,7 +1734,6 @@ where state = "Waiting for table metadata lock" and --echo # Sending: --send select count(*) from t2; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above SELECT is blocked. let $wait_condition= @@ -2008,12 +1744,10 @@ where state = "Waiting for table metadata lock" and --echo # Unblock ALTER TABLE. commit; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reap ALTER TABLE. --reap --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reap SELECT. --reap @@ -2022,20 +1756,17 @@ commit; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Start transaction which will prevent SNW -> X upgrade from --echo # completing immediately. begin; select count(*) from t2; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Create SNW lock pending upgrade to X on t2. --echo # Sending: --send alter table t2 drop column c2; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Wait until ALTER TABLE starts waiting X lock. let $wait_condition= @@ -2047,7 +1778,6 @@ where state = "Waiting for table metadata lock" and --echo # Sending: --send insert into t2 values (1); --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above INSERT is blocked. let $wait_condition= @@ -2058,12 +1788,10 @@ where state = "Waiting for table metadata lock" and --echo # Unblock ALTER TABLE. commit; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reap ALTER TABLE. --reap --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reap INSERT. --reap @@ -2075,13 +1803,11 @@ commit; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Create SNW lock pending upgrade to X. --echo # Sending: --send alter table t1 add column c2 int; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Wait until ALTER TABLE starts waiting X lock. let $wait_condition= @@ -2098,12 +1824,10 @@ delete from t1 limit 1; --echo # Unblock ALTER TABLE. commit; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reap ALTER TABLE. --reap --echo # ---echo # Switching to connection 'default'. connection default; --echo # --echo # 3) Check how various locks used within transactional context @@ -2114,18 +1838,15 @@ connection default; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; lock table t2 write; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Attempt to acquire SR should be blocked. It should --echo # not cause errors as it does not creates deadlock. --echo # Sending: --send select count(*) from t2; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that the above SELECT is blocked let $wait_condition= @@ -2136,7 +1857,6 @@ where state = "Waiting for table metadata lock" and --echo # Unblock SELECT. unlock tables; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reap SELECT. --reap @@ -2145,18 +1865,15 @@ commit; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; lock table t2 write; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Again attempt to acquire SW should be blocked and should --echo # not cause any errors. --echo # Sending: --send delete from t2 limit 1; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Check that the above DELETE is blocked let $wait_condition= @@ -2167,7 +1884,6 @@ where state = "Waiting for table metadata lock" and --echo # Unblock DELETE. unlock tables; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reap DELETE. --reap @@ -2182,12 +1898,10 @@ commit; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Sending: --send lock table t1 write; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Wait until LOCK TABLE is blocked creating pending request for X lock. let $wait_condition= @@ -2204,13 +1918,11 @@ delete from t1 limit 1; --echo # Unblock LOCK TABLES. commit; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reap LOCK TABLES. --reap unlock tables; --echo # ---echo # Switching to connection 'default'. connection default; --echo # --echo # **) Now case when transaction has a SW lock. @@ -2218,12 +1930,10 @@ connection default; begin; delete from t1 limit 1; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Sending: --send lock table t1 write; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Wait until LOCK TABLE is blocked creating pending request for X lock. let $wait_condition= @@ -2238,13 +1948,11 @@ insert into t1 values (1, 1); --echo # Unblock LOCK TABLES. commit; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reap LOCK TABLES. --reap unlock tables; --echo # ---echo # Switching to connection 'default'. connection default; --echo # --echo # 4) Check how various locks used within transactional context @@ -2255,20 +1963,17 @@ connection default; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Start transaction which will prevent X lock from going away --echo # immediately. begin; select count(*) from t2; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Create pending X lock on t2. --echo # Sending: --send rename table t2 to t3; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Wait until RENAME TABLE starts waiting with pending X lock. let $wait_condition= @@ -2280,7 +1985,6 @@ where state = "Waiting for table metadata lock" and --echo # Sending: --send select count(*) from t2; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above SELECT is blocked. let $wait_condition= @@ -2291,12 +1995,10 @@ where state = "Waiting for table metadata lock" and --echo # Unblock RENAME TABLE. commit; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reap RENAME TABLE. --reap --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reap SELECT. --error ER_NO_SUCH_TABLE @@ -2307,20 +2009,17 @@ rename table t3 to t2; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Start transaction which will prevent X lock from going away --echo # immediately. begin; select count(*) from t2; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Create pending X lock on t2. --echo # Sending: --send rename table t2 to t3; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Wait until RENAME TABLE starts waiting with pending X lock. let $wait_condition= @@ -2332,7 +2031,6 @@ where state = "Waiting for table metadata lock" and --echo # Sending: --send delete from t2 limit 1; --echo # ---echo # Switching to connection 'mdl_con2'. connection mdl_con2; --echo # Check that the above DELETE is blocked. let $wait_condition= @@ -2343,12 +2041,10 @@ where state = "Waiting for table metadata lock" and --echo # Unblock RENAME TABLE. commit; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reap RENAME TABLE. --reap --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reap DELETE. --error ER_NO_SUCH_TABLE @@ -2365,12 +2061,10 @@ rename table t3 to t2; begin; select count(*) from t1; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Wait until RENAME TABLE is blocked creating pending request for X lock. let $wait_condition= @@ -2387,13 +2081,11 @@ delete from t1 limit 1; --echo # Unblock RENAME TABLE. commit; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reap RENAME TABLE. --error ER_TABLE_EXISTS_ERROR --reap --echo # ---echo # Switching to connection 'default'. connection default; --echo # --echo # **) The second case is when transaction has a SW lock. @@ -2401,12 +2093,10 @@ connection default; begin; delete from t1 limit 1; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Sending: --send rename table t1 to t2; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Wait until RENAME TABLE is blocked creating pending request for X lock. let $wait_condition= @@ -2421,13 +2111,11 @@ insert into t1 values (1, 1); --echo # Unblock RENAME TABLE. commit; --echo # ---echo # Switching to connection 'mdl_con1'. connection mdl_con1; --echo # Reap RENAME TABLE. --error ER_TABLE_EXISTS_ERROR --reap --echo # ---echo # Switching to connection 'default'. connection default; --echo # Clean-up. @@ -2437,214 +2125,6 @@ disconnect mdl_con3; set debug_sync= 'RESET'; drop table t1, t2; - ---echo # ---echo # Additional coverage for some scenarios in which not quite ---echo # correct use of S metadata locks by HANDLER statement might ---echo # have caused deadlocks. ---echo # ---disable_warnings -drop table if exists t1, t2; ---enable_warnings -connect(handler_con1,localhost,root,,); -connect(handler_con2,localhost,root,,); -connection default; -create table t1 (i int); -create table t2 (j int); -insert into t1 values (1); - ---echo # ---echo # First, check scenario in which we upgrade SNRW lock to X lock ---echo # on a table while having HANDLER READ trying to acquire TL_READ ---echo # on the same table. ---echo # -handler t1 open; ---echo # ---echo # Switching to connection 'handler_con1'. -connection handler_con1; -lock table t1 write; ---echo # Upgrade SNRW to X lock. ---echo # Sending: ---send alter table t1 add column j int; ---echo # ---echo # Switching to connection 'handler_con2'. -connection handler_con2; ---echo # Wait until ALTER is blocked during upgrade. -let $wait_condition= - select count(*) = 1 from information_schema.processlist - where state = "Waiting for table metadata lock" and - info = "alter table t1 add column j int"; ---source include/wait_condition.inc ---echo # ---echo # Switching to connection 'default'. -connection default; ---echo # The below statement should not cause deadlock. ---send handler t1 read first; ---echo # ---echo # Switching to connection 'handler_con1'. -connection handler_con1; ---echo # Reap ALTER TABLE. ---reap -unlock tables; ---echo # ---echo # Switching to connection 'default'. -connection default; ---echo # Reap HANDLER READ. ---reap -handler t1 close; - ---echo # ---echo # Now, check scenario in which upgrade of SNRW lock to X lock ---echo # can be blocked by HANDLER which is open in connection currently ---echo # waiting to get table-lock owned by connection doing upgrade. ---echo # -handler t1 open; ---echo # ---echo # Switching to connection 'handler_con1'. -connection handler_con1; -lock table t1 write, t2 read; ---echo # ---echo # Switching to connection 'default'. -connection default; ---echo # Execute statement which will be blocked on table-level lock ---echo # owned by connection 'handler_con1'. ---echo # Sending: ---send insert into t2 values (1); ---echo # ---echo # Switching to connection 'handler_con1'. -connection handler_con1; ---echo # Wait until INSERT is blocked on table-level lock. -let $wait_condition= - select count(*) = 1 from information_schema.processlist - where state = "Waiting for table level lock" and - info = "insert into t2 values (1)"; ---source include/wait_condition.inc ---echo # Sending 'alter table t1 drop column j'. It should not cause ---echo # deadlock. -send alter table t1 drop column j; ---echo # Switching to connection 'handler_con2'. -connection handler_con2; ---echo # Wait until ALTER is blocked during upgrade. -let $wait_condition= - select count(*) = 1 from information_schema.processlist - where state = "Waiting for table metadata lock" and - info = "alter table t1 drop column j"; ---source include/wait_condition.inc ---echo # ---echo # Switching to connection 'default'. -connection default; ---echo # Reap INSERT. ---error ER_LOCK_ABORTED ---reap -handler t1 close; ---echo # ---echo # Switching to connection 'handler_con1'. -connection handler_con1; ---echo # Reaping 'alter table t1 drop column j' ---reap -unlock tables; ---echo # Switching to connection 'default'. -connection default; - ---echo # Then, check the scenario in which upgrade of SNRW lock to X ---echo # lock is blocked by HANDLER which is open in connection currently ---echo # waiting to get SW lock on the same table. ---echo # -handler t1 open; ---echo # ---echo # Switching to connection 'handler_con1'. -connection handler_con1; -lock table t1 write; ---echo # ---echo # Switching to connection 'default'. -connection default; ---echo # The below insert should be blocked because active SNRW lock on 't1'. ---echo # Sending: ---send insert into t1 values (1); ---echo # ---echo # Switching to connection 'handler_con1'. -connection handler_con1; ---echo # Wait until INSERT is blocked because of SNRW lock. -let $wait_condition= - select count(*) = 1 from information_schema.processlist - where state = "Waiting for table metadata lock" and - info = "insert into t1 values (1)"; ---source include/wait_condition.inc ---echo # The below ALTER TABLE will be blocked because of presence of HANDLER. ---echo # Sending: ---send alter table t1 add column j int; ---echo # ---echo # Switching to connection 'default'. -connection default; ---echo # INSERT should be chosen as victim for resolving deadlock. ---echo # Reaping INSERT. ---error ER_LOCK_DEADLOCK ---reap ---echo # Close HANDLER to unblock ALTER TABLE. -handler t1 close; ---echo # ---echo # Switching to connection 'handler_con1'. -connection handler_con1; ---echo # Reaping ALTER TABLE. ---reap -unlock tables; ---echo # ---echo # Switching to connection 'default'. -connection default; - ---echo # ---echo # Finally, test in which upgrade of SNRW lock to X lock is blocked ---echo # by HANDLER which is open in connection currently waiting to get ---echo # SR lock on the table on which lock is upgraded. ---echo # -handler t1 open; ---echo # ---echo # Switching to connection 'handler_con1'. -connection handler_con1; -lock table t1 write, t2 write; ---echo # ---echo # Switching to connection 'default'. -connection default; ---echo # The below insert should be blocked because active SNRW lock on 't1'. ---echo # Sending: ---send insert into t2 values (1); ---echo # ---echo # Switching to connection 'handler_con1'. -connection handler_con1; ---echo # Wait until INSERT is blocked because of SNRW lock. -let $wait_condition= - select count(*) = 1 from information_schema.processlist - where state = "Waiting for table metadata lock" and - info = "insert into t2 values (1)"; ---source include/wait_condition.inc ---echo # The below ALTER TABLE will be blocked because of presence of HANDLER. ---echo # Sending: ---send alter table t1 drop column j; ---echo # ---echo # Switching to connection 'default'. -connection default; ---echo # INSERT should be chosen as victim for resolving deadlock. ---echo # Reaping INSERT. ---error ER_LOCK_DEADLOCK ---reap ---echo # Close HANDLER to unblock ALTER TABLE. -handler t1 close; ---echo # ---echo # Switching to connection 'handler_con1'. -connection handler_con1; ---echo # Reaping ALTER TABLE. ---reap -unlock tables; ---echo # ---echo # Switching to connection 'default'. -connection default; - ---echo # Clean-up. -disconnect handler_con1; -disconnect handler_con2; -drop tables t1, t2; - - --echo # --echo # Test coverage for basic deadlock detection in metadata --echo # locking subsystem. @@ -2668,25 +2148,21 @@ create table t4 (k int); --echo # --echo # ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; begin; insert into t1 values (1); --echo # ---echo # Switching to connection 'deadlock_con2'. connection deadlock_con2; begin; insert into t2 values (1); --echo # ---echo # Switching to connection 'default'. connection default; --echo # Send: --send rename table t2 to t0, t3 to t2, t0 to t3; --echo # ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; --echo # Wait until the above RENAME TABLE is blocked because it has to wait --echo # for 'deadlock_con2' which holds shared metadata lock on 't2'. @@ -2702,7 +2178,6 @@ let $wait_condition= --send select * from t2; --echo # ---echo # Switching to connection 'deadlock_con2'. connection deadlock_con2; --echo # Wait until the above SELECT * FROM t2 is starts waiting --echo # for an exclusive metadata lock to go away. @@ -2716,19 +2191,16 @@ let $wait_condition= commit; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reap RENAME TABLE. --reap --echo # ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; --echo # Reap SELECT. --reap --echo # ---echo # Switching to connection 'default'. connection default; --echo # --echo # Let us check that in the process of waiting for conflicting lock @@ -2738,7 +2210,6 @@ connection default; --send rename table t1 to t0, t3 to t1, t0 to t3; --echo # ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; --echo # Wait until the above RENAME TABLE is blocked because it has to wait --echo # for 'deadlock_con1' which should still hold shared metadata lock on @@ -2752,7 +2223,6 @@ let $wait_condition= commit; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reap RENAME TABLE. --reap @@ -2762,19 +2232,16 @@ connection default; --echo # --echo # ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; begin; insert into t2 values (2); --echo # ---echo # Switching to connection 'default'. connection default; --echo # Send: --send rename table t2 to t0, t1 to t2, t0 to t1; --echo # ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; --echo # Wait until the above RENAME TABLE is blocked because it has to wait --echo # for 'deadlock_con1' which holds shared metadata lock on 't2'. @@ -2791,7 +2258,6 @@ let $wait_condition= select * from t1; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reap RENAME TABLE. --reap @@ -2801,18 +2267,15 @@ connection default; --echo # --echo # ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; begin; insert into t2 values (1); --echo # ---echo # Switching to connection 'default'. connection default; lock table t1 write; --echo # ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; --echo # The below SELECT statement should wait for metadata lock --echo # on table 't1' and should not produce ER_LOCK_DEADLOCK @@ -2820,7 +2283,6 @@ connection deadlock_con1; --send select * from t1; --echo # ---echo # Switching to connection 'deadlock_con2'. connection deadlock_con2; --echo # Wait until the above SELECT * FROM t1 is starts waiting --echo # for an UNRW metadata lock to go away. @@ -2834,7 +2296,6 @@ let $wait_condition= --send rename table t1 to t0, t2 to t1, t0 to t2; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Wait till above RENAME TABLE is blocked while holding --echo # pending X lock on t1. @@ -2848,7 +2309,6 @@ let $wait_condition= unlock tables; --echo # ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; --echo # Since the latest RENAME TABLE entered in deadlock with SELECT --echo # statement the latter should be aborted and emit ER_LOCK_DEADLOCK @@ -2858,13 +2318,11 @@ connection deadlock_con1; --reap --echo # ---echo # Switching to connection 'deadlock_con2'. connection deadlock_con2; --echo # Reap RENAME TABLE ... . --reap; --echo # ---echo # Switching to connection 'default'. connection default; drop tables t1, t2, t3, t4; @@ -2881,19 +2339,16 @@ insert into t1 values (1); select * from t1; --echo # ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; begin; select * from t1; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Send: --send alter table t1 add column j int, rename to t2; --echo # ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; --echo # Wait until the above ALTER TABLE ... RENAME acquires exclusive --echo # metadata lock on 't2' and starts waiting for connection @@ -2911,7 +2366,6 @@ let $wait_condition= select * from t2; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reap ALTER TABLE ... RENAME. --reap @@ -2935,7 +2389,6 @@ set debug_sync= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish'; --send select * from t2, t1 --echo # ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; --echo # Wait till SELECT acquires MDL on 't2' and starts waiting for signal. set debug_sync= 'now WAIT_FOR locked'; @@ -2943,7 +2396,6 @@ set debug_sync= 'now WAIT_FOR locked'; --send lock tables t1 write, t2 write --echo # ---echo # Switching to connection 'deadlock_con2'. connection deadlock_con2; --echo # Wait until LOCK TABLES acquires SNRW lock on 't1' and is blocked --echo # while trying to acquire SNRW lock on 't1'. @@ -2956,14 +2408,12 @@ let $wait_condition= set debug_sync= 'now SIGNAL finish'; --echo # ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; --echo # Reaping LOCK TABLES. --reap unlock tables; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping SELECT. It succeed and not report ER_LOCK_DEADLOCK error. --reap @@ -2983,7 +2433,6 @@ set debug_sync='alter_table_copy_after_lock_upgrade SIGNAL parked1 WAIT_FOR go1' --send alter table t1 add column j int --echo # ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; --echo # Wait till ALTER acquires SNW lock and stops. set debug_sync='now WAIT_FOR parked1'; @@ -2995,7 +2444,6 @@ set debug_sync='mdl_acquire_lock_wait SIGNAL parked2 WAIT_FOR go2'; --send insert into t1 values () --echo # ---echo # Switching to connection 'deadlock_con2'. connection deadlock_con2; --echo # Wait till INSERT is paused. set debug_sync='now WAIT_FOR parked2'; @@ -3005,7 +2453,6 @@ set debug_sync='now WAIT_FOR parked2'; set debug_sync='now SIGNAL go1'; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping ALTER TABLE. --reap @@ -3014,7 +2461,6 @@ connection default; --send alter table t1 drop column j --echo # ---echo # Switching to connection 'deadlock_con2'. connection deadlock_con2; --echo # Wait until ALTER is blocked. let $wait_condition= @@ -3035,13 +2481,11 @@ let $wait_condition= set debug_sync='now SIGNAL go2'; --echo # ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; --echo # Reaping INSERT. --reap --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reaping ALTER. It should succeed and not produce ER_LOCK_DEADLOCK. --reap @@ -3063,7 +2507,6 @@ create table t2(j int); --echo # set debug_sync= 'RESET'; ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; --echo # Start a statement, which will acquire SR metadata lock on t1, open it --echo # and then stop, before trying to acquire SW lock on t2 and opening it. @@ -3071,7 +2514,6 @@ set debug_sync='open_tables_after_open_and_process_table SIGNAL parked WAIT_FOR --echo # Sending: --send select * from t1 where i in (select j from t2 for update) ---echo # Switching to connection 'deadlock_con2'. connection deadlock_con2; --echo # Wait till the above SELECT stops. set debug_sync='now WAIT_FOR parked'; @@ -3080,7 +2522,6 @@ set debug_sync='now WAIT_FOR parked'; --echo # Sending: send flush tables t1, t2 with read lock; ---echo # Switching to connection 'deadlock_con3'. connection deadlock_con3; --echo # Wait until FLUSH TABLES WITH t1, t2 READ LOCK starts waiting --echo # for SELECT to close t1. @@ -3095,13 +2536,11 @@ let $wait_condition= --echo # by backing-off SELECT. As a result FTWRL should be able to finish. set debug_sync='now SIGNAL go'; ---echo # Switching to connection 'deadlock_con2'. connection deadlock_con2; --echo # Reap FLUSH TABLES WITH READ LOCK. reap; unlock tables; ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; --echo # Reap SELECT. reap; @@ -3113,7 +2552,6 @@ reap; --echo # set debug_sync= 'RESET'; ---echo # Switching to connection 'deadlock_con2'. connection deadlock_con2; set debug_sync='flush_tables_with_read_lock_after_acquire_locks SIGNAL parked WAIT_FOR go'; @@ -3122,7 +2560,6 @@ set debug_sync='flush_tables_with_read_lock_after_acquire_locks SIGNAL parked WA --echo # Sending: send flush tables t1, t2 with read lock; ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; --echo # Wait till FLUSH TABLE WITH READ LOCK stops. set debug_sync='now WAIT_FOR parked'; @@ -3132,7 +2569,6 @@ set debug_sync='now WAIT_FOR parked'; --echo # Sending: send select * from t1 where i in (select j from t2 for update); ---echo # Switching to connection 'deadlock_con3'. connection deadlock_con3; --echo # Wait till the above SELECT blocks. let $wait_condition= @@ -3146,13 +2582,11 @@ let $wait_condition= --echo # backing-off SELECT. As a result FTWRL should be able to finish. set debug_sync='now SIGNAL go'; ---echo # Switching to connection 'deadlock_con2'. connection deadlock_con2; --echo # Reap FLUSH TABLES WITH READ LOCK. reap; unlock tables; ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; --echo # Reap SELECT. reap; @@ -3163,7 +2597,6 @@ reap; --echo # set debug_sync= 'RESET'; ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; --echo # Start a statement which will acquire SR metadata lock on t2, open it --echo # and then stop, before trying to acquire SR on t1 and opening it. @@ -3171,7 +2604,6 @@ set debug_sync='open_tables_after_open_and_process_table SIGNAL parked WAIT_FOR --echo # Sending: send select * from t2, t1; ---echo # Switching to connection 'deadlock_con2'. connection deadlock_con2; --echo # Wait till the above SELECT stops. set debug_sync='now WAIT_FOR parked'; @@ -3180,7 +2612,6 @@ set debug_sync='now WAIT_FOR parked'; --echo # Sending: send flush tables t2 with read lock; ---echo # Switching to connection 'deadlock_con3'. connection deadlock_con3; --echo # Wait until FLUSH TABLES WITH READ LOCK starts waiting --echo # for SELECT to close t2. @@ -3195,7 +2626,6 @@ let $wait_condition= --echo # Sending: send drop tables t1, t2; ---echo # Switching to connection 'default'. connection default; --echo # Wait until DROP TABLES starts waiting for X lock on t2. let $wait_condition= @@ -3209,25 +2639,21 @@ let $wait_condition= --echo # by backing-off SELECT. As a result, FTWRL should be able to finish. set debug_sync='now SIGNAL go'; ---echo # Switching to connection 'deadlock_con2'. connection deadlock_con2; --echo # Reap FLUSH TABLES WITH READ LOCK. reap; --echo # Unblock DROP TABLES. unlock tables; ---echo # Switching to connection 'deadlock_con3'. connection deadlock_con3; --echo # Reap DROP TABLES. reap; ---echo # Switching to connection 'deadlock_con1'. connection deadlock_con1; --echo # Reap SELECT. It should emit error about missing table. --error ER_NO_SUCH_TABLE reap; ---echo # Switching to connection 'default'. connection default; set debug_sync= 'RESET'; @@ -3251,7 +2677,6 @@ set debug_sync= 'RESET'; create table t1(i int); create table t2(j int); ---echo # Switching to connection 'con2'. connection con2; set debug_sync='open_tables_after_open_and_process_table SIGNAL parked WAIT_FOR go'; @@ -3261,7 +2686,6 @@ set debug_sync='open_tables_after_open_and_process_table SIGNAL parked WAIT_FOR --echo # Sending: send flush tables t1, t2 with read lock; ---echo # Switching to connection 'con1'. connection con1; --echo # Wait till FLUSH TABLES <list> WITH READ LOCK stops. set debug_sync='now WAIT_FOR parked'; @@ -3271,7 +2695,6 @@ set debug_sync='now WAIT_FOR parked'; --echo # Sending: send flush tables; ---echo # Switching to connection 'default'. connection default; --echo # Wait till the above FLUSH TABLES blocks. let $wait_condition= @@ -3286,19 +2709,16 @@ let $wait_condition= --echo # which would result in assertion failures. set debug_sync='now SIGNAL go'; ---echo # Switching to connection 'con2'. connection con2; --echo # Reap FLUSH TABLES <list> WITH READ LOCK. reap; unlock tables; ---echo # Switching to connection 'con1'. connection con1; --echo # Reap FLUSH TABLES. reap; --echo # Clean-up. ---echo # Switching to connection 'default'. connection default; drop tables t1, t2; set debug_sync= 'RESET'; @@ -3328,16 +2748,13 @@ create trigger t1_bi before insert on t1 for each row create trigger t2_bi before insert on t2 for each row insert into t3 values (new.j); --echo # ---echo # Switching to connection 'con1root'. connection con1root; lock tables t4 read; --echo # ---echo # Switching to connection 'con2root'. connection con2root; --echo # Send : --send rename table t3 to t5, t4 to t3; --echo # ---echo # Switching to connection 'default'. connection default; --echo # Wait until the above RENAME TABLE adds pending requests for exclusive --echo # metadata lock on its tables and blocks due to 't4' being used by LOCK @@ -3349,7 +2766,6 @@ let $wait_condition= select count(*)= 1 from information_schema.processlist --echo # Send : --send insert into t1 values (1); --echo # ---echo # Switching to connection 'con1root'. connection con1root; --echo # Wait until INSERT statement waits due to encountering pending --echo # exclusive metadata lock on 't3'. @@ -3359,12 +2775,10 @@ let $wait_condition= select count(*)= 1 from information_schema.processlist --source include/wait_condition.inc unlock tables; --echo # ---echo # Switching to connection 'con2root'. connection con2root; --echo # Reap RENAME TABLE. --reap --echo # ---echo # Switching to connection 'default'. connection default; --echo # Reap INSERT. --reap @@ -3390,14 +2804,12 @@ connect(con2, localhost, root,,); --echo # Test 1: CREATE TABLE --echo # ---echo # Connection 2 connection con2; --echo # Start insert on the not-yet existing table --echo # Wait after taking the MDL lock SET DEBUG_SYNC= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish'; --send INSERT INTO t1 VALUES(1,"def") ---echo # Connection 1 connection default; SET DEBUG_SYNC= 'now WAIT_FOR locked'; --echo # Now INSERT has a MDL on the non-existent table t1. @@ -3408,13 +2820,11 @@ SET DEBUG_SYNC= 'mdl_acquire_lock_wait SIGNAL finish'; --echo # Try to create that table. --send CREATE TABLE t1 (c1 INT, c2 VARCHAR(100), KEY(c1)) ---echo # Connection 2 --echo # Insert fails connection con2; --error ER_NO_SUCH_TABLE --reap ---echo # Connection 1 connection default; --reap; SET DEBUG_SYNC= 'RESET'; @@ -3430,14 +2840,12 @@ DROP TABLE IF EXISTS t1; CREATE TABLE t2 (c1 INT, c2 VARCHAR(100), KEY(c1)); ---echo # Connection 2 connection con2; --echo # Start insert on the not-yet existing table --echo # Wait after taking the MDL SET DEBUG_SYNC= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish'; --send INSERT INTO t1 VALUES(1,"def") ---echo # Connection 1 connection default; SET DEBUG_SYNC= 'now WAIT_FOR locked'; --echo # Now INSERT has a MDL on the non-existent table t1. @@ -3448,13 +2856,11 @@ SET DEBUG_SYNC= 'mdl_acquire_lock_wait SIGNAL finish'; --echo # Try to create that table. --send CREATE TABLE t1 LIKE t2 ---echo # Connection 2 --echo # Insert fails connection con2; --error ER_NO_SUCH_TABLE --reap ---echo # Connection 1 connection default; --reap SET DEBUG_SYNC= 'RESET'; @@ -3488,12 +2894,10 @@ insert into t1 values(1); --echo # which owner is in its turn waiting for our connection. lock tables t1 read; ---echo # Switching to connection 'con46044_2'. connection con46044_2; --echo # Sending: --send update t1 set i = 2 ---echo # Switching to connection 'con46044'. connection con46044; --echo # Waiting until UPDATE t1 SET ... is blocked. @@ -3506,7 +2910,6 @@ let $wait_condition= --echo # Sending: --send create table t2 select * from t1; ---echo # Switching to connection 'default'. connection default; --echo # Waiting until CREATE TABLE ... SELECT ... is blocked. let $wait_condition= @@ -3533,11 +2936,9 @@ select column_name from information_schema.columns select table_name, table_type, auto_increment, table_comment from information_schema.tables where table_schema='test' and table_name='t2'; ---echo # Switching to connection 'default'. connection default; unlock tables; ---echo # Switching to connection 'con46044'. connection con46044; --echo # Reaping CREATE TABLE ... SELECT ... . --reap @@ -3555,16 +2956,13 @@ connection con46044_2; --echo # --echo # We check same three queries to I_S in this new situation. ---echo # Switching to connection 'con46044_2'. connection con46044_2; lock tables t1 read; ---echo # Switching to connection 'con46044_3'. connection con46044_3; --echo # Sending: send update t1 set i = 3; ---echo # Switching to connection 'con46044'. connection con46044; --echo # Waiting until UPDATE t1 SET ... is blocked. @@ -3577,7 +2975,6 @@ let $wait_condition= --echo # Sending: --send create table t2 select * from t1; ---echo # Switching to connection 'default'. connection default; --echo # Waiting until CREATE TABLE ... SELECT ... is blocked. let $wait_condition= @@ -3590,7 +2987,6 @@ let $wait_condition= --echo # Sending: --send show fields from t2; ---echo # Switching to connection 'con46044_2'. connection con46044_2; --echo # Wait until SHOW FIELDS gets blocked. let $wait_condition= @@ -3601,12 +2997,10 @@ let $wait_condition= unlock tables; ---echo # Switching to connection 'con46044'. connection con46044; --echo # Reaping CREATE TABLE ... SELECT ... . --reap ---echo # Switching to connection 'default'. connection default; --echo # Reaping SHOW FIELDS ... --reap @@ -3616,16 +3010,13 @@ connection con46044_3; --echo # Reaping UPDATE t1 statement --reap ---echo # Switching to connection 'con46044_2'. connection con46044_2; lock tables t1 read; ---echo # Switching to connection 'con46044_3'. connection con46044_3; --echo # Sending: --send update t1 set i = 4 ---echo # Switching to connection 'con46044'. connection con46044; --echo # Waiting until UPDATE t1 SET ... is blocked. @@ -3638,7 +3029,6 @@ let $wait_condition= --echo # Sending: --send create table t2 select * from t1; ---echo # Switching to connection 'default'. connection default; --echo # Waiting until CREATE TABLE ... SELECT ... is blocked. let $wait_condition= @@ -3651,7 +3041,6 @@ let $wait_condition= --echo # Sending: --send select column_name from information_schema.columns where table_schema='test' and table_name='t2'; ---echo # Switching to connection 'con46044_2'. connection con46044_2; --echo # Wait until SELECT COLUMN_NAME FROM I_S.COLUMNS gets blocked. let $wait_condition= @@ -3662,12 +3051,10 @@ let $wait_condition= unlock tables; ---echo # Switching to connection 'con46044'. connection con46044; --echo # Reaping CREATE TABLE ... SELECT ... . --reap ---echo # Switching to connection 'default'. connection default; --echo # Reaping SELECT COLUMN_NAME FROM I_S.COLUMNS --reap @@ -3677,16 +3064,13 @@ connection con46044_3; --echo # Reaping UPDATE t1 statement --reap ---echo # Switching to connection 'con46044_2'. connection con46044_2; lock tables t1 read; ---echo # Switching to connection 'con46044_3'. connection con46044_3; --echo # Sending: --send update t1 set i = 5 ---echo # Switching to connection 'con46044'. connection con46044; --echo # Waiting until UPDATE t1 SET ... is blocked. @@ -3699,7 +3083,6 @@ let $wait_condition= --echo # Sending: --send create table t2 select * from t1; ---echo # Switching to connection 'default'. connection default; --echo # Waiting until CREATE TABLE ... SELECT ... is blocked. let $wait_condition= @@ -3713,7 +3096,6 @@ let $wait_condition= --echo # Sending: --send select table_name, table_type, auto_increment, table_comment from information_schema.tables where table_schema='test' and table_name='t2'; ---echo # Switching to connection 'con46044_2'. connection con46044_2; --echo # Wait until SELECT ... FROM I_S.TABLES gets blocked. let $wait_condition= @@ -3724,12 +3106,10 @@ let $wait_condition= unlock tables; ---echo # Switching to connection 'con46044'. connection con46044; --echo # Reaping CREATE TABLE ... SELECT ... . --reap ---echo # Switching to connection 'default'. connection default; --echo # Reaping SELECT ... FROM I_S.TABLES --reap @@ -3739,7 +3119,6 @@ connection con46044_3; --echo # Reaping UPDATE t1 statement --reap ---echo # Switching to connection 'default'. connection default; --echo # Clean-up. disconnect con46044; @@ -3765,13 +3144,11 @@ begin; select * from t1 where c2 = 3; --echo # ---echo # Switching to connection 'con46273'. connection con46273; set debug_sync='alter_table_copy_after_lock_upgrade SIGNAL alter_table_locked WAIT_FOR alter_go'; --send alter table t1 add column e int, rename to t2; --echo # ---echo # Switching to connection 'default'. connection default; set debug_sync='now WAIT_FOR alter_table_locked'; set debug_sync='mdl_acquire_lock_wait SIGNAL alter_go'; @@ -3782,13 +3159,11 @@ set debug_sync='mdl_acquire_lock_wait SIGNAL alter_go'; update t1 set c3=c3+1 where c2 = 3; --echo # ---echo # Switching to connection 'con46273'. connection con46273; --echo # Reap ALTER TABLE. --reap --echo # ---echo # Switching to connection 'default'. connection default; disconnect con46273; --echo # Clean-up. @@ -3807,12 +3182,10 @@ connect (con46673, localhost, root,,); connection default; create table t1 (i int); ---echo # Switching to connection 'con46673'. connection con46673; begin; insert into t1 values (1); ---echo # Switching to connection 'default'. connection default; --echo # Statement below should not get blocked. And if after some --echo # changes to code it is there should not be a deadlock between @@ -3820,12 +3193,10 @@ connection default; flush tables with read lock; unlock tables; ---echo # Switching to connection 'con46673'. connection con46673; delete from t1 where i = 1; commit; ---echo # Switching to connection 'default'. connection default; --echo # Clean-up disconnect con46673; @@ -3841,13 +3212,11 @@ connect (con2, localhost, root); --echo # Test 1: CREATE PROCEDURE ---echo # Connection 1 connection default; --echo # Start CREATE PROCEDURE and open mysql.proc SET DEBUG_SYNC= 'after_open_table_mdl_shared SIGNAL table_opened WAIT_FOR grlwait'; --send CREATE PROCEDURE p1() SELECT 1 ---echo # Connection 2 connection con2; SET DEBUG_SYNC= 'now WAIT_FOR table_opened'; --echo # Check that FLUSH must wait to get the GRL @@ -3855,16 +3224,13 @@ SET DEBUG_SYNC= 'now WAIT_FOR table_opened'; SET DEBUG_SYNC= 'mdl_acquire_lock_wait SIGNAL grlwait'; --send FLUSH TABLES WITH READ LOCK ---echo # Connection 1 connection default; --reap ---echo # Connection 2 connection con2; --reap UNLOCK TABLES; ---echo # Connection 1 connection default; SET DEBUG_SYNC= 'RESET'; @@ -3875,7 +3241,6 @@ connection default; SET DEBUG_SYNC= 'after_open_table_mdl_shared SIGNAL table_opened WAIT_FOR grlwait'; --send DROP PROCEDURE p1 ---echo # Connection 2 connection con2; SET DEBUG_SYNC= 'now WAIT_FOR table_opened'; --echo # Check that FLUSH must wait to get the GRL @@ -3883,7 +3248,6 @@ SET DEBUG_SYNC= 'now WAIT_FOR table_opened'; SET DEBUG_SYNC= 'mdl_acquire_lock_wait SIGNAL grlwait'; --send FLUSH TABLES WITH READ LOCK ---echo # Connection 1 connection default; --echo # Once FLUSH TABLES WITH READ LOCK starts waiting --echo # DROP PROCEDURE will be waked up and will drop @@ -3893,13 +3257,11 @@ connection default; --echo # Reaping DROP PROCEDURE. --reap ---echo # Connection 2 connection con2; --echo # Reaping FTWRL. --reap UNLOCK TABLES; ---echo # Connection 1 connection default; SET DEBUG_SYNC= 'RESET'; @@ -4015,13 +3377,11 @@ connect (con50913_2,localhost,root); connection default; create table t1 (i int) engine=InnoDB; ---echo # Switching to connection 'con50913_1'. connection con50913_1; set debug_sync= 'alter_table_copy_after_lock_upgrade SIGNAL parked WAIT_FOR go'; --echo # Sending: --send alter table t1 add column j int, ALGORITHM=COPY ---echo # Switching to connection 'default'. connection default; --echo # Wait until ALTER TABLE gets blocked on a sync point after --echo # acquiring thr_lock.c lock. @@ -4031,7 +3391,6 @@ set debug_sync= 'now WAIT_FOR parked'; --echo # Sending: --send truncate table t1 ---echo # Switching to connection 'con50913_2'. connection con50913_2; --echo # Wait until TRUNCATE TABLE is blocked on MDL lock. let $wait_condition= @@ -4042,12 +3401,10 @@ let $wait_condition= --echo # Unblock ALTER TABLE. set debug_sync= 'now SIGNAL go'; ---echo # Switching to connection 'con50913_1'. connection con50913_1; --echo # Reaping ALTER TABLE. --reap ---echo # Switching to connection 'default'. connection default; --echo # Reaping TRUNCATE TABLE. --reap @@ -4074,17 +3431,14 @@ connect (con3,localhost,root); connection default; create table t1 (i int); ---echo # Switching to connection 'con1'. connection con1; begin; select * from t1; ---echo # Switching to connection 'con2'. connection con2; begin; select * from t1; ---echo # Switching to connection 'default'. connection default; --echo # Start ALTER TABLE which will acquire SNW lock and --echo # table lock and get blocked on sync point. @@ -4092,19 +3446,16 @@ set debug_sync= 'alter_table_copy_after_lock_upgrade SIGNAL parked WAIT_FOR go'; --echo # Sending: --send alter table t1 add column j int ---echo # Switching to connection 'con1'. connection con1; --echo # Wait until ALTER TABLE gets blocked on a sync point. set debug_sync= 'now WAIT_FOR parked'; --echo # Sending: --send insert into t1 values (1) ---echo # Switching to connection 'con2'. connection con2; --echo # Sending: --send insert into t1 values (1) ---echo # Switching to connection 'con3'. connection con3; --echo # Wait until both 'con1' and 'con2' are blocked trying to acquire --echo # SW lock on the table. @@ -4119,7 +3470,6 @@ let $wait_condition= --echo # should be aborted with ER_LOCK_DEADLOCK errors. set debug_sync= 'now SIGNAL go'; ---echo # Switching to connection 'con1'. connection con1; --echo # Reaping INSERT. It should end with ER_LOCK_DEADLOCK error and --echo # not wait indefinitely (as it happened before the bugfix). @@ -4127,14 +3477,12 @@ connection con1; --reap commit; ---echo # Switching to connection 'con2'. connection con2; --echo # Reaping INSERT. --error ER_LOCK_DEADLOCK --reap commit; ---echo # Switching to connection 'default'. connection default; --echo # Reap ALTER TABLE. --reap @@ -4165,32 +3513,26 @@ DROP TABLE IF EXISTS t1; CREATE TABLE t1 (a INT) ENGINE=InnoDB; INSERT INTO t1 VALUES (1),(2),(3); ---echo # Connection: con1 connection con1; LOCK TABLES t1 WRITE; SET debug_sync='upgrade_lock_for_truncate SIGNAL parked_truncate WAIT_FOR go_truncate'; send TRUNCATE TABLE t1; connection default; ---echo # Connection: default SET debug_sync='now WAIT_FOR parked_truncate'; connection con2; ---echo # Connection: con2 SET debug_sync='after_open_table_ignore_flush SIGNAL parked_show WAIT_FOR go_show'; send SHOW FIELDS FROM t1; connection default; ---echo # Connection: default SET debug_sync='now WAIT_FOR parked_show'; connection con3; ---echo # Connection: con3 SET debug_sync='after_flush_unlock SIGNAL parked_flush WAIT_FOR go_flush'; send FLUSH TABLES t1; connection default; ---echo # Connection: default SET debug_sync='now WAIT_FOR parked_flush'; SET debug_sync='now SIGNAL go_truncate'; --echo # Ensure that truncate waits for a exclusive lock @@ -4200,22 +3542,18 @@ let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist SET debug_sync= 'now SIGNAL go_show'; connection con1; ---echo # Connection: con1 (TRUNCATE) --echo # Reaping... reap; UNLOCK TABLES; connection con2; ---echo # Connection: con2 (SHOW FIELDS FROM t1) --echo # Reaping... reap; connection default; ---echo # Connection: default SET debug_sync= 'now SIGNAL go_flush'; connection con3; ---echo # Connection: con3 (FLUSH TABLES t1) --echo # Reaping... reap; @@ -4224,7 +3562,6 @@ disconnect con2; disconnect con3; connection default; ---echo # Connection: default SET debug_sync= 'RESET'; DROP TABLE t1; @@ -4268,20 +3605,17 @@ connect (con3, localhost, root); --echo # not database DDL on different databases. Tests X vs X lock. --echo # ---echo # Connection default connection default; SET DEBUG_SYNC= 'after_wait_locked_schema_name SIGNAL locked WAIT_FOR blocked'; --echo # Sending: --send CREATE DATABASE db1 ---echo # Connection con2 connection con2; SET DEBUG_SYNC= 'now WAIT_FOR locked'; --echo # Sending: # This should block. --send CREATE DATABASE db1 ---echo # Connection con3 connection con3; let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state='Waiting for schema metadata lock' AND info='CREATE DATABASE db1'; @@ -4292,12 +3626,10 @@ ALTER DATABASE db2 DEFAULT CHARACTER SET utf8; DROP DATABASE db2; SET DEBUG_SYNC= 'now SIGNAL blocked'; ---echo # Connection default connection default; --echo # Reaping: CREATE DATABASE db1 --reap ---echo # Connection con2 connection con2; --echo # Reaping: CREATE DATABASE db1 --error ER_DB_CREATE_EXISTS @@ -4308,20 +3640,17 @@ connection con2; --echo # not database DDL on different databases. Tests X vs X lock. --echo # ---echo # Connection default connection default; SET DEBUG_SYNC= 'after_wait_locked_schema_name SIGNAL locked WAIT_FOR blocked'; --echo # Sending: --send ALTER DATABASE db1 DEFAULT CHARACTER SET utf8 ---echo # Connection con2 connection con2; SET DEBUG_SYNC= 'now WAIT_FOR locked'; --echo # Sending: # This should block. --send ALTER DATABASE db1 DEFAULT CHARACTER SET utf8 ---echo # Connection con3 connection con3; let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state='Waiting for schema metadata lock' @@ -4333,42 +3662,35 @@ ALTER DATABASE db2 DEFAULT CHARACTER SET utf8; DROP DATABASE db2; SET DEBUG_SYNC= 'now SIGNAL blocked'; ---echo # Connection default connection default; --echo # Reaping: ALTER DATABASE db1 DEFAULT CHARACTER SET utf8 --reap ---echo # Connection con2 connection con2; --echo # Reaping: ALTER DATABASE db1 DEFAULT CHARACTER SET utf8 --reap ---echo # Connection default connection default; SET DEBUG_SYNC= 'after_wait_locked_schema_name SIGNAL locked WAIT_FOR blocked'; --echo # Sending: --send ALTER DATABASE db1 DEFAULT CHARACTER SET utf8 ---echo # Connection con2 connection con2; SET DEBUG_SYNC= 'now WAIT_FOR locked'; --echo # Sending: # This should also block. --send DROP DATABASE db1 ---echo # Connection con3 connection con3; let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state='Waiting for schema metadata lock' AND info='DROP DATABASE db1'; --source include/wait_condition.inc SET DEBUG_SYNC= 'now SIGNAL blocked'; ---echo # Connection default connection default; --echo # Reaping: ALTER DATABASE db1 DEFAULT CHARACTER SET utf8 --reap ---echo # Connection con2 connection con2; --echo # Reaping: DROP DATABASE db1 --reap @@ -4387,20 +3709,17 @@ let $MYSQLD_DATADIR= `select @@datadir`; --mkdir $MYSQLD_DATADIR/a-b-c-d --copy_file $MYSQLD_DATADIR/db1/db.opt $MYSQLD_DATADIR/a-b-c-d/db.opt ---echo # Connection default connection default; SET DEBUG_SYNC= 'after_wait_locked_schema_name SIGNAL locked WAIT_FOR blocked'; --echo # Sending: --send ALTER DATABASE `#mysql50#a-b-c` UPGRADE DATA DIRECTORY NAME ---echo # Connection con2 connection con2; SET DEBUG_SYNC= 'now WAIT_FOR locked'; --echo # Sending: # This should block. --send ALTER DATABASE `#mysql50#a-b-c` UPGRADE DATA DIRECTORY NAME ---echo # Connection con3 connection con3; let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state='Waiting for schema metadata lock' @@ -4410,12 +3729,10 @@ let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist ALTER DATABASE `#mysql50#a-b-c-d` UPGRADE DATA DIRECTORY NAME; SET DEBUG_SYNC= 'now SIGNAL blocked'; ---echo # Connection default connection default; --echo # Reaping: ALTER DATABASE '#mysql50#a-b-c' UPGRADE DATA DIRECTORY NAME --reap ---echo # Connection con2 connection con2; --echo # Reaping: ALTER DATABASE '#mysql50#a-b-c' UPGRADE DATA DIRECTORY NAME --error ER_BAD_DB_ERROR @@ -4428,20 +3745,17 @@ DROP DATABASE `a-b-c-d`; --echo # not database DDL on different databases. Tests X vs X lock. --echo # ---echo # Connection default connection default; SET DEBUG_SYNC= 'after_wait_locked_schema_name SIGNAL locked WAIT_FOR blocked'; --echo # Sending: --send DROP DATABASE db1 ---echo # Connection con2 connection con2; SET DEBUG_SYNC= 'now WAIT_FOR locked'; --echo # Sending: # This should block. --send DROP DATABASE db1 ---echo # Connection con3 connection con3; let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state='Waiting for schema metadata lock' AND info='DROP DATABASE db1'; @@ -4452,32 +3766,27 @@ ALTER DATABASE db2 DEFAULT CHARACTER SET utf8; DROP DATABASE db2; SET DEBUG_SYNC= 'now SIGNAL blocked'; ---echo # Connection default connection default; --echo # Reaping: DROP DATABASE db1 --reap ---echo # Connection con2 connection con2; --echo # Reaping: DROP DATABASE db1 --error ER_DB_DROP_EXISTS --reap ---echo # Connection default connection default; CREATE DATABASE db1; SET DEBUG_SYNC= 'after_wait_locked_schema_name SIGNAL locked WAIT_FOR blocked'; --echo # Sending: --send DROP DATABASE db1 ---echo # Connection con2 connection con2; SET DEBUG_SYNC= 'now WAIT_FOR locked'; --echo # Sending: # This should also block. --send ALTER DATABASE db1 DEFAULT CHARACTER SET utf8 ---echo # Connection con3 connection con3; let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state='Waiting for schema metadata lock' @@ -4485,12 +3794,10 @@ let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist --source include/wait_condition.inc SET DEBUG_SYNC= 'now SIGNAL blocked'; ---echo # Connection default connection default; --echo # Reaping: DROP DATABASE db1 --reap ---echo # Connection con2 connection con2; --echo # Reaping: ALTER DATABASE db1 DEFAULT CHARACTER SET utf8 # Error 1 is from ALTER DATABASE when the database does not exist. @@ -4504,21 +3811,18 @@ connection con2; --echo # Tests X vs IX lock. --echo # ---echo # Connection default connection default; CREATE DATABASE db1; SET DEBUG_SYNC= 'after_wait_locked_schema_name SIGNAL locked WAIT_FOR blocked'; --echo # Sending: --send DROP DATABASE db1 ---echo # Connection con2 connection con2; SET DEBUG_SYNC= 'now WAIT_FOR locked'; --echo # Sending: # This should block. --send CREATE TABLE db1.t1 (a INT) ---echo # Connection con3 connection con3; let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state='Waiting for schema metadata lock' AND @@ -4526,12 +3830,10 @@ let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist --source include/wait_condition.inc SET DEBUG_SYNC= 'now SIGNAL blocked'; ---echo # Connection default connection default; --echo # Reaping: DROP DATABASE db1 --reap ---echo # Connection con2 connection con2; --echo # Reaping: CREATE TABLE db1.t1 (a INT) --error ER_BAD_DB_ERROR @@ -4542,7 +3844,6 @@ connection con2; --echo # Tests X vs IX lock. --echo # ---echo # Connection default connection default; CREATE DATABASE db1; CREATE TABLE db1.t1 (a INT); @@ -4550,14 +3851,12 @@ SET DEBUG_SYNC= 'after_wait_locked_schema_name SIGNAL locked WAIT_FOR blocked'; --echo # Sending: --send DROP DATABASE db1 ---echo # Connection con2 connection con2; SET DEBUG_SYNC= 'now WAIT_FOR locked'; --echo # Sending: # This should block. --send RENAME TABLE db1.t1 TO test.t1 ---echo # Connection con3 connection con3; let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state='Waiting for schema metadata lock' AND @@ -4565,18 +3864,15 @@ let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist --source include/wait_condition.inc SET DEBUG_SYNC= 'now SIGNAL blocked'; ---echo # Connection default connection default; --echo # Reaping: DROP DATABASE db1 --reap ---echo # Connection con2 connection con2; --echo # Reaping: RENAME TABLE db1.t1 TO test.t1 --error ER_NO_SUCH_TABLE --reap ---echo # Connection default connection default; CREATE DATABASE db1; CREATE TABLE test.t2 (a INT); @@ -4584,14 +3880,12 @@ SET DEBUG_SYNC= 'after_wait_locked_schema_name SIGNAL locked WAIT_FOR blocked'; --echo # Sending: --send DROP DATABASE db1 ---echo # Connection con2 connection con2; SET DEBUG_SYNC= 'now WAIT_FOR locked'; --echo # Sending: # This should block. --send RENAME TABLE test.t2 TO db1.t2 ---echo # Connection con3 connection con3; let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state='Waiting for schema metadata lock' AND @@ -4599,12 +3893,10 @@ let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist --source include/wait_condition.inc SET DEBUG_SYNC= 'now SIGNAL blocked'; ---echo # Connection default connection default; --echo # Reaping: DROP DATABASE db1 --reap ---echo # Connection con2 connection con2; --echo # Reaping: RENAME TABLE test.t2 TO db1.t2 # Error 7 is from RENAME TABLE where the target database does not exist. @@ -4619,7 +3911,6 @@ DROP TABLE test.t2; --echo # Tests X vs IX lock. --echo # ---echo # Connection default connection default; CREATE DATABASE db1; CREATE TABLE db1.t1 (a INT); @@ -4627,32 +3918,27 @@ SET DEBUG_SYNC= 'after_wait_locked_schema_name SIGNAL locked WAIT_FOR blocked'; --echo # Sending: --send DROP DATABASE db1 ---echo # Connection con2 connection con2; SET DEBUG_SYNC= 'now WAIT_FOR locked'; --echo # Sending: # This should block. --send DROP TABLE db1.t1 ---echo # Connection con3 connection con3; let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state='Waiting for schema metadata lock' AND info='DROP TABLE db1.t1'; --source include/wait_condition.inc SET DEBUG_SYNC= 'now SIGNAL blocked'; ---echo # Connection default connection default; --echo # Reaping: DROP DATABASE db1 --reap ---echo # Connection con2 connection con2; --echo # Reaping: DROP TABLE db1.t1 --error ER_BAD_TABLE_ERROR --reap ---echo # Connection default connection default; disconnect con2; disconnect con3; @@ -4671,16 +3957,13 @@ CREATE TABLE db1.t1(a INT); connect(con2, localhost, root); connect(con3, localhost, root); ---echo # Connection default connection default; FLUSH TABLE WITH READ LOCK; ---echo # Connection con2 connection con2; # IX global lock should block --send CREATE TABLE db1.t2(a INT) ---echo # Connection default connection default; let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state='Waiting for global read lock' @@ -4688,21 +3971,17 @@ let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist --source include/wait_condition.inc UNLOCK TABLES; ---echo # Connection con2 connection con2; --echo # Reaping CREATE TABLE db1.t2(a INT) --reap ---echo # Connection default connection default; FLUSH TABLE WITH READ LOCK; ---echo # Connection con2 connection con2; # X global lock should block --send ALTER DATABASE db1 DEFAULT CHARACTER SET utf8 ---echo # Connection default connection default; let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state='Waiting for global read lock' @@ -4710,22 +3989,18 @@ let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist --source include/wait_condition.inc UNLOCK TABLES; ---echo # Connection con2 connection con2; --echo # Reaping ALTER DATABASE db1 DEFAULT CHARACTER SET utf8 --reap ---echo # Connection default connection default; FLUSH TABLE WITH READ LOCK; ---echo # Connection con2 connection con2; # S global lock should not block FLUSH TABLE WITH READ LOCK; UNLOCK TABLES; ---echo # Connection default connection default; UNLOCK TABLES; DROP DATABASE db1; @@ -4752,7 +4027,6 @@ connect(con1, localhost, root); connect(con2, localhost, root); connect(con3, localhost, root); ---echo # Connection con1 connection con1; --echo # We need EXECUTE 2 since ALTER TABLE does SU => SNW => X and we want --echo # to stop at the second upgrade. @@ -4760,7 +4034,6 @@ SET DEBUG_SYNC= 'mdl_upgrade_lock SIGNAL upgrade WAIT_FOR continue EXECUTE 2'; --echo # Sending: --send ALTER TABLE m1 engine=MERGE UNION=(t2, t1) ---echo # Connection con2 connection con2; --echo # Waiting for ALTER TABLE to try lock upgrade SET DEBUG_SYNC= 'now WAIT_FOR upgrade'; @@ -4769,7 +4042,6 @@ SET DEBUG_SYNC= 'now WAIT_FOR upgrade'; --echo # Sending: --send DELETE FROM t2 WHERE a = 3 ---echo # Connection default connection con3; --echo # Check that DELETE is waiting on a metadata lock and not a table lock. let $wait_condition= @@ -4786,18 +4058,15 @@ connection default; --echo # Resuming ALTER TABLE SET DEBUG_SYNC= 'now SIGNAL continue'; ---echo # Connection con1 connection con1; --echo # Reaping: ALTER TABLE m1 engine=MERGE UNION=(t2, t1) --reap ---echo # Connection con2 connection con2; --echo # Reaping: DELETE FROM t2 WHERE a = 3 --reap connection con3; --echo # Reaping: SELECT * FROM m1 WHERE a < 3 --reap ---echo # Connection default connection default; DROP TABLE m1, t1, t2; SET DEBUG_SYNC= 'RESET'; diff --git a/mysql-test/t/merge-big.test b/mysql-test/t/merge-big.test index 78c3e8c00ac..9bd2cab2c8a 100644 --- a/mysql-test/t/merge-big.test +++ b/mysql-test/t/merge-big.test @@ -40,13 +40,11 @@ drop table if exists t1,t2,t3,t4,t5,t6; CREATE TABLE t1 (c1 INT) ENGINE= MyISAM; LOCK TABLE t1 WRITE; #SELECT NOW(); - --echo # connection con1 connect (con1,localhost,root,,); let $con1_id= `SELECT CONNECTION_ID()`; SET @orig_debug=@@debug; SET GLOBAL debug_dbug="+d,sleep_open_and_lock_after_open"; send INSERT INTO t1 VALUES (1); ---echo # connection default connection default; --echo # Let INSERT go into thr_multi_lock(). #--sleep 8 @@ -72,12 +70,9 @@ FLUSH TABLES; SELECT * FROM t1; #SELECT NOW(); UNLOCK TABLES; - --echo # connection con1 connection con1; reap; SET GLOBAL debug_dbug=@orig_debug; disconnect con1; ---echo # connection default connection default; DROP TABLE t1; - diff --git a/mysql-test/t/merge.test b/mysql-test/t/merge.test index e9d69b446d5..09f313616f1 100644 --- a/mysql-test/t/merge.test +++ b/mysql-test/t/merge.test @@ -1678,6 +1678,7 @@ CREATE TABLE t1(a int); CREATE TABLE t2(a int); CREATE TABLE t3(a int) ENGINE = MERGE UNION(t1, t2); CREATE TRIGGER tr1 AFTER INSERT ON t3 FOR EACH ROW CALL foo(); +--replace_column 7 # SHOW CREATE TRIGGER tr1; DROP TRIGGER tr1; DROP TABLE t1, t2, t3; @@ -2585,7 +2586,6 @@ DROP TABLE t1, t2, t3, t4, m1, m2; --disable_warnings DROP TABLE IF EXISTS t1, t2, t3; --enable_warnings ---echo # Connection con1. connect (con1,localhost,root,,); CREATE TABLE t1 (c1 int); CREATE TABLE t2 (c1 int); @@ -2594,12 +2594,10 @@ START TRANSACTION; --error ER_ILLEGAL_HA HANDLER t3 OPEN; DROP TABLE t1, t2, t3; ---echo # Connection default. connection default; ---echo # Disconnecting con1, all mdl_tickets must have been released. +--echo # all mdl_tickets must have been released. disconnect con1; --echo # The bug-specific case. ---echo # Connection con1. connect (con1,localhost,root,,); CREATE TABLE t1 (c1 int); CREATE TABLE t2 (c1 int); @@ -2609,9 +2607,8 @@ START TRANSACTION; --error ER_WRONG_MRG_TABLE HANDLER t3 OPEN; DROP TABLE t1, t3; ---echo # Connection default. connection default; ---echo # Disconnecting con1, all mdl_tickets must have been released. +--echo # all mdl_tickets must have been released. disconnect con1; --echo # diff --git a/mysql-test/t/merge_debug.test b/mysql-test/t/merge_debug.test index e147946b394..3c617cfc545 100644 --- a/mysql-test/t/merge_debug.test +++ b/mysql-test/t/merge_debug.test @@ -8,6 +8,8 @@ set @default_storage_engine= @@global.storage_engine; set global storage_engine=myisam; set session storage_engine=myisam; +call mtr.add_suppression("Index for table .*crashed' is corrupt; try to repair it"); + --disable_warnings drop table if exists crashed,t2,t3,t4; --enable_warnings diff --git a/mysql-test/t/multi_update.test b/mysql-test/t/multi_update.test index 0297280340d..4e09b2370f5 100644 --- a/mysql-test/t/multi_update.test +++ b/mysql-test/t/multi_update.test @@ -8,17 +8,6 @@ source include/have_log_bin.inc; CALL mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT."); ---disable_warnings -drop table if exists t1,t2,t3; -drop database if exists mysqltest; -drop view if exists v1; ---error 0,ER_NONEXISTING_GRANT,ER_NONEXISTING_TABLE_GRANT -revoke all privileges on mysqltest.t1 from mysqltest_1@localhost; ---error 0,ER_NONEXISTING_GRANT,ER_NONEXISTING_TABLE_GRANT -revoke all privileges on mysqltest.* from mysqltest_1@localhost; -delete from mysql.user where user=_binary'mysqltest_1'; ---enable_warnings - create table t1(id1 int not null auto_increment primary key, t char(12)); create table t2(id2 int not null, t char(12)); create table t3(id3 int not null, t char(12), index(id3)); @@ -372,9 +361,7 @@ drop table t1, t2; connect (root,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK); connection root; ---disable_warnings create database mysqltest; ---enable_warnings create table mysqltest.t1 (a int, b int, primary key (a)); create table mysqltest.t2 (a int, b int, primary key (a)); create table mysqltest.t3 (a int, b int, primary key (a)); @@ -415,22 +402,6 @@ update t1,t2 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1; delete t1 from t1,t2 where t1.col1 < (select max(col1) from t1) and t1.col1 = t2.col1; drop table t1,t2; -# Test for Bug#5837 delete with outer join and const tables ---disable_warnings -create table t1 ( - aclid bigint not null primary key, - status tinyint(1) not null -) engine = innodb; - -create table t2 ( - refid bigint not null primary key, - aclid bigint, index idx_acl(aclid) -) engine = innodb; ---enable_warnings -insert into t2 values(1,null); -delete t2, t1 from t2 left join t1 on (t2.aclid=t1.aclid) where t2.refid='1'; -drop table t1, t2; - # # Bug#19225 unchecked error leads to server crash # @@ -442,47 +413,6 @@ drop table t1, t2; # End of 4.1 tests # -# Test for Bug#1980. -# ---disable_warnings -create table t1 ( c char(8) not null ) engine=innodb; ---enable_warnings - -insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9'); -insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F'); - -alter table t1 add b char(8) not null; -alter table t1 add a char(8) not null; -alter table t1 add primary key (a,b,c); -update t1 set a=c, b=c; - -create table t2 like t1; -insert into t2 select * from t1; - -delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b; - -drop table t1,t2; - ---disable_warnings -create table t1 ( c char(8) not null ) engine=innodb; ---enable_warnings - -insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9'); -insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F'); - -alter table t1 add b char(8) not null; -alter table t1 add a char(8) not null; -alter table t1 add primary key (a,b,c); -update t1 set a=c, b=c; - -create table t2 like t1; -insert into t2 select * from t1; - -delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b; - -drop table t1,t2; - -# # Test alter table and a concurrent multi update # (Before we have introduced data-lock-aware metadata locks # this test case forced update to reopen tables). @@ -618,9 +548,6 @@ set @@session.binlog_format= @sav_binlog_format; # # prepare ---disable_warnings -drop table if exists t1, t2, t3; ---enable_warnings CREATE TABLE t1 (a int, PRIMARY KEY (a)); CREATE TABLE t2 (a int, PRIMARY KEY (a)); CREATE TABLE t3 (a int, PRIMARY KEY (a)) ENGINE=MyISAM; @@ -1057,54 +984,3 @@ deallocate prepare stmt1; drop view v3,v2,v1; drop table t1,t2,t3; --echo end of 5.5 tests - - ---source include/have_xtradb.inc - ---echo ---echo # Bug mdev-5970 ---echo # Bug#13256831 - ERROR 1032 (HY000): CAN'T FIND RECORD ---echo - -CREATE TABLE t1 (f1 INT PRIMARY KEY, f2 INT) ENGINE=InnoDB; -CREATE TABLE t2 (f1 INT PRIMARY KEY, f2 INT) ENGINE=InnoDB; -INSERT INTO t1 VALUES (5, 7); -INSERT INTO t2 VALUES (6, 97); - -CREATE ALGORITHM = MERGE VIEW v1 AS -SELECT a2.f1 AS f1, a2.f2 AS f2 -FROM t1 AS a1 JOIN t2 AS a2 ON a1.f2 > a2.f1 -WITH LOCAL CHECK OPTION; - -SELECT * FROM v1; -UPDATE v1 SET f1 = 1; -SELECT * FROM v1; - -DROP TABLE t1, t2; -DROP VIEW v1; - ---echo # ---echo # MDEV-5973: MySQL Bug#11757486:49539: NON-DESCRIPTIVE ERR (ERROR 0 ---echo # FROM STORAGE ENGINE) WITH MULTI-TABLE UPDATE ---echo # - -CREATE TABLE table_11757486 (field1 tinyint) ENGINE=INNODB; -INSERT INTO table_11757486 VALUES (0),(0); -SET SESSION SQL_MODE='STRICT_ALL_TABLES'; -UPDATE IGNORE (SELECT 128 as col1) x, table_11757486 SET field1=x.col1; -UPDATE IGNORE table_11757486 SET field1=128; - ---error ER_WARN_DATA_OUT_OF_RANGE -UPDATE (SELECT 128 as col1) x, table_11757486 SET field1=x.col1; ---error ER_WARN_DATA_OUT_OF_RANGE -UPDATE table_11757486 SET field1=128; - -SET SESSION SQL_MODE=''; -UPDATE IGNORE (SELECT 128 as col1) x, table_11757486 SET field1=x.col1; -UPDATE IGNORE table_11757486 SET field1=128; - -DROP TABLE table_11757486; - -SET SESSION SQL_MODE=default; - ---echo end of 10.0 tests diff --git a/mysql-test/t/multi_update_innodb.test b/mysql-test/t/multi_update_innodb.test index 51757c29553..f5f8f91edb8 100644 --- a/mysql-test/t/multi_update_innodb.test +++ b/mysql-test/t/multi_update_innodb.test @@ -75,3 +75,101 @@ UPDATE t2 AS A NATURAL JOIN t2 B SET A.pk_2=10,B.pk_2=11; SELECT * FROM t2; DROP TABLE t1,t2; + +--echo +--echo # Bug mdev-5970 +--echo # Bug#13256831 - ERROR 1032 (HY000): CAN'T FIND RECORD +--echo + +CREATE TABLE t1 (f1 INT PRIMARY KEY, f2 INT) ENGINE=InnoDB; +CREATE TABLE t2 (f1 INT PRIMARY KEY, f2 INT) ENGINE=InnoDB; +INSERT INTO t1 VALUES (5, 7); +INSERT INTO t2 VALUES (6, 97); + +CREATE ALGORITHM = MERGE VIEW v1 AS +SELECT a2.f1 AS f1, a2.f2 AS f2 +FROM t1 AS a1 JOIN t2 AS a2 ON a1.f2 > a2.f1 +WITH LOCAL CHECK OPTION; + +SELECT * FROM v1; +UPDATE v1 SET f1 = 1; +SELECT * FROM v1; + +DROP TABLE t1, t2; +DROP VIEW v1; + +--echo # +--echo # MDEV-5973: MySQL Bug#11757486:49539: NON-DESCRIPTIVE ERR (ERROR 0 +--echo # FROM STORAGE ENGINE) WITH MULTI-TABLE UPDATE +--echo # + +CREATE TABLE table_11757486 (field1 tinyint) ENGINE=INNODB; +INSERT INTO table_11757486 VALUES (0),(0); +SET SESSION SQL_MODE='STRICT_ALL_TABLES'; +UPDATE IGNORE (SELECT 128 as col1) x, table_11757486 SET field1=x.col1; +UPDATE IGNORE table_11757486 SET field1=128; + +--error ER_WARN_DATA_OUT_OF_RANGE +UPDATE (SELECT 128 as col1) x, table_11757486 SET field1=x.col1; +--error ER_WARN_DATA_OUT_OF_RANGE +UPDATE table_11757486 SET field1=128; + +SET SESSION SQL_MODE=''; +UPDATE IGNORE (SELECT 128 as col1) x, table_11757486 SET field1=x.col1; +UPDATE IGNORE table_11757486 SET field1=128; + +DROP TABLE table_11757486; + +SET SESSION SQL_MODE=default; + +# Test for Bug#5837 delete with outer join and const tables +create table t1 ( + aclid bigint not null primary key, + status tinyint(1) not null +) engine = innodb; + +create table t2 ( + refid bigint not null primary key, + aclid bigint, index idx_acl(aclid) +) engine = innodb; +insert into t2 values(1,null); +delete t2, t1 from t2 left join t1 on (t2.aclid=t1.aclid) where t2.refid='1'; +drop table t1, t2; + +# +# Test for Bug#1980. +# +create table t1 ( c char(8) not null ) engine=innodb; + +insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9'); +insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F'); + +alter table t1 add b char(8) not null; +alter table t1 add a char(8) not null; +alter table t1 add primary key (a,b,c); +update t1 set a=c, b=c; + +create table t2 like t1; +insert into t2 select * from t1; + +delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b; + +drop table t1,t2; + +create table t1 ( c char(8) not null ) engine=innodb; + +insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9'); +insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F'); + +alter table t1 add b char(8) not null; +alter table t1 add a char(8) not null; +alter table t1 add primary key (a,b,c); +update t1 set a=c, b=c; + +create table t2 like t1; +insert into t2 select * from t1; + +delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b; + +drop table t1,t2; + diff --git a/mysql-test/t/myisam.test b/mysql-test/t/myisam.test index 9ac49a9063d..a454fa25ac4 100644 --- a/mysql-test/t/myisam.test +++ b/mysql-test/t/myisam.test @@ -552,6 +552,8 @@ insert t2 select * from t1; checksum table t1, t2, t3 quick; checksum table t1, t2, t3; checksum table t1, t2, t3 extended; +alter table t1 add d int default 30, add e bigint default 300000, add f decimal(30) default 442; +checksum table t1; #show table status; drop table t1,t2; diff --git a/mysql-test/t/myisam_debug.test b/mysql-test/t/myisam_debug.test index 5b5d006bd22..b106ecdea5e 100644 --- a/mysql-test/t/myisam_debug.test +++ b/mysql-test/t/myisam_debug.test @@ -34,13 +34,11 @@ while ($i) commit; --enable_query_log ---echo # Switch to insert Connection CONNECTION insertConn; SET SESSION debug_dbug='+d,wait_in_enable_indexes'; --echo # Send insert data SEND INSERT INTO t1(id) SELECT id FROM t2; ---echo # Switch to default Connection CONNECTION default; --echo # Wait for insert data to reach the debug point diff --git a/mysql-test/t/myisam_recover.test b/mysql-test/t/myisam_recover.test index 49fe9c33460..0c686e59fb1 100644 --- a/mysql-test/t/myisam_recover.test +++ b/mysql-test/t/myisam_recover.test @@ -12,9 +12,6 @@ --echo # For that, we set the table cache to minimal size and populate it --echo # in a concurrent connection. connect(con1,localhost,root,,test,,); ---echo # ---echo # Switching to connection con1 ---echo # connection con1; --echo # --echo # Minimal values. @@ -56,9 +53,6 @@ drop procedure p_create; let $lock=`select @lock_table_stmt`; eval $lock; --enable_query_log ---echo # ---echo # Switching to connection 'default' ---echo # connection default; --echo # --echo # We have to disable the ps-protocol, to avoid @@ -102,9 +96,6 @@ select * from t1_mrg; --echo # Cleanup --echo # drop table t1, t1_mrg; ---echo # ---echo # Switching to connection con1 ---echo # connection con1; unlock tables; prepare stmt from @drop_table_stmt; diff --git a/mysql-test/t/mysql57_virtual.test b/mysql-test/t/mysql57_virtual.test new file mode 100644 index 00000000000..3ebdd894b79 --- /dev/null +++ b/mysql-test/t/mysql57_virtual.test @@ -0,0 +1,29 @@ +let $MYSQLD_DATADIR= `select @@datadir`; + +--echo # +--echo # Test that we can use tables created in MySQL 5.7 +--echo # + +--copy_file std_data/mysql57_virtual.frm $MYSQLD_DATADIR/test/mysql57_virtual.frm +--copy_file std_data/mysql57_virtual.MYD $MYSQLD_DATADIR/test/mysql57_virtual.MYD +--copy_file std_data/mysql57_virtual.MYI $MYSQLD_DATADIR/test/mysql57_virtual.MYI + +SHOW CREATE TABLE mysql57_virtual; +insert into mysql57_virtual (a) values (1),(2); +select * from mysql57_virtual; + +# We can't do online changes, as the MariaDB storage is incompatible with MySQL +--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON +alter online table mysql57_virtual comment "I am now a MariaDB table"; + +alter table mysql57_virtual comment "I am now a MariaDB table"; +SHOW CREATE TABLE mysql57_virtual; +DROP TABLE mysql57_virtual; + +--echo # +--echo # Check MySQL 5.7 syntax +--echo # + +create table t1 (a int, b int generated always as (a+1) STORED, c int generated always as (a+2) VIRTUAL); +show create table t1; +drop table t1; diff --git a/mysql-test/t/mysql_comments.test b/mysql-test/t/mysql_comments.test index 7b00f17e259..fb0e5f94950 100644 --- a/mysql-test/t/mysql_comments.test +++ b/mysql-test/t/mysql_comments.test @@ -30,10 +30,12 @@ drop trigger if exists t1_bi; # Test without comments --echo "Pass 1 : --disable-comments" +--replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(.[0-9]{2})*/--TIME--/ --exec $MYSQL --disable-comments test 2>&1 < "./t/mysql_comments.sql" # Test with comments --echo "Pass 2 : --enable-comments" +--replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(.[0-9]{2})*/--TIME--/ --exec $MYSQL --enable-comments test 2>&1 < "./t/mysql_comments.sql" diff --git a/mysql-test/t/mysqlbinlog_row_big.test b/mysql-test/t/mysqlbinlog_row_big.test index ffd1b79af34..44bceaad66b 100644 --- a/mysql-test/t/mysqlbinlog_row_big.test +++ b/mysql-test/t/mysqlbinlog_row_big.test @@ -52,11 +52,8 @@ SET @@global.max_allowed_packet= 1024*1024*1024; --echo to be seen and used, we must start a new connection. --echo The change does not take effect with the current one. --echo For simplicity, we just disconnect / reconnect connection default here. ---echo Disconnecting default connection... disconnect default; ---echo Reconnecting default connection... connect (default, localhost,root,,); ---echo default connection established, continuing with the test --echo # --echo # Delete all existing binary logs. diff --git a/mysql-test/t/mysqlbinlog_row_compressed.test b/mysql-test/t/mysqlbinlog_row_compressed.test new file mode 100644 index 00000000000..1a7ce093986 --- /dev/null +++ b/mysql-test/t/mysqlbinlog_row_compressed.test @@ -0,0 +1,68 @@ +# +# Test for compressed row event +# + +--source include/have_log_bin.inc +--source include/have_binlog_format_row.inc + +# +# +# mysqlbinlog: compressed row event +# +# + +SET GLOBAL log_bin_compress=on; +SET GLOBAL log_bin_compress_min_len=10; +CREATE TABLE t1 (pk INT PRIMARY KEY, f1 INT, f2 INT, f3 TINYINT, f4 MEDIUMINT, f5 BIGINT, f6 INT, f7 INT, f8 char(1)); +CREATE TABLE t2 (pk INT PRIMARY KEY, f1 INT, f2 INT, f3 INT, f4 INT, f5 MEDIUMINT, f6 INT, f7 INT, f8 char(1)); +INSERT INTO t1 VALUES (10, 1, 2, 3, 4, 5, 6, 7, ""); +INSERT INTO t1 VALUES (11, 1, 2, 3, 4, 5, 6, 7, NULL); +INSERT INTO t1 VALUES (12, 1, 2, 3, NULL, 5, 6, 7, "A"); +INSERT INTO t1 VALUES (13, 1, 2, 3, 0, 5, 6, 7, "A"); +INSERT INTO t2 SELECT * FROM t1; +UPDATE t2 SET f4=5 WHERE f4>0 or f4 is NULL; +DELETE FROM t1; +DELETE FROM t2; + +--let $binlog = query_get_value(SHOW MASTER STATUS, File, 1) +--let $datadir = `SELECT @@datadir` + +FLUSH BINARY LOGS; +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--replace_regex /\d{6} *\d*:\d\d:\d\d/<date>/ /Start:.*at startup/Start: xxx/ /SET TIMESTAMP=\d*/SET TIMESTAMP=X/ /exec_time=\d*/exec_time=x/ /mapped to number \d*/mapped to number num/ /CRC32 0x[0-9a-f]+/CRC32 XXX/ +--exec $MYSQL_BINLOG --verbose --verbose --base64-output=DECODE-ROWS $datadir/$binlog + +--echo +--echo Test mysqlbinlog | mysql type point-in-time recovery with compressed events. +--echo + +FLUSH BINARY LOGS; +--let $binlog_file = query_get_value(SHOW MASTER STATUS, File, 1) +CREATE TABLE t3 (a INT PRIMARY KEY, b INT, c VARCHAR(100)); +INSERT INTO t3 VALUES (0, 10, "hello"); +BEGIN; +INSERT INTO t3 VALUES (1, 10, "cat"), (2, 10, "mouse"), (3, 10, "dog"); +INSERT INTO t3 VALUES (4, 10, "goodbye"); +COMMIT; +UPDATE t3 SET b=b+100 where a<>1; +DELETE FROM t3 WHERE a=2; +SET @old_image=@@binlog_row_image; +SET binlog_row_image=minimal; +INSERT INTO t3 VALUES (5, 20, "red"), (6, 30, "green"), (7, 40, "blue"); +INSERT INTO t3 VALUES (8, 20, "rigel"); +UPDATE t3 SET c = concat("colour of ", c) WHERE a > 5; +UPDATE t3 SET b=b*2 WHERE a IN (5,6,7); +DELETE FROM t3 WHERE a=6; +SET binlog_row_image=@old_image; +SELECT * FROM t3 ORDER BY a; +FLUSH LOGS; +DROP TABLE t3; + +--let $MYSQLD_DATADIR= `select @@datadir` +--exec $MYSQL_BINLOG $MYSQLD_DATADIR/$binlog_file | $MYSQL + +SELECT * FROM t3 ORDER BY a; + +DROP TABLE t1,t2,t3; +SET GLOBAL log_bin_compress=off; +SET GLOBAL log_bin_compress_min_len=256; diff --git a/mysql-test/t/mysqlbinlog_row_minimal.test b/mysql-test/t/mysqlbinlog_row_minimal.test index 216cb43eb6f..7909f75e9a1 100644 --- a/mysql-test/t/mysqlbinlog_row_minimal.test +++ b/mysql-test/t/mysqlbinlog_row_minimal.test @@ -27,7 +27,7 @@ DELETE FROM t2; FLUSH BINARY LOGS; --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR ---replace_regex /\d{6} *\d*:\d\d:\d\d/<date>/ /Start:.*at startup/Start: xxx/ /SET TIMESTAMP=\d*/SET TIMESTAMP=X/ /exec_time=\d*/exec_time=x/ +--replace_regex /\d{6} *\d*:\d\d:\d\d/<date>/ /Start:.*at startup/Start: xxx/ /SET TIMESTAMP=\d*/SET TIMESTAMP=X/ /exec_time=\d*/exec_time=x/ /mapped to number \d*/mapped to number num/ /CRC32 0x[0-9a-f]+/CRC32 XXX/ --exec $MYSQL_BINLOG --verbose --verbose --base64-output=DECODE-ROWS $datadir/$binlog DROP TABLE t1,t2; diff --git a/mysql-test/t/mysqlbinlog_stmt_compressed.test b/mysql-test/t/mysqlbinlog_stmt_compressed.test new file mode 100644 index 00000000000..c4331ddf229 --- /dev/null +++ b/mysql-test/t/mysqlbinlog_stmt_compressed.test @@ -0,0 +1,59 @@ +# +# Test for compressed query event +# + +--source include/have_log_bin.inc +--source include/have_binlog_format_statement.inc + +# +# +# mysqlbinlog: compressed query event +# +# + +SET GLOBAL log_bin_compress=on; +SET GLOBAL log_bin_compress_min_len=10; +CREATE TABLE t1 (pk INT PRIMARY KEY, f1 INT, f2 INT, f3 TINYINT, f4 MEDIUMINT, f5 BIGINT, f6 INT, f7 INT, f8 char(1)); +CREATE TABLE t2 (pk INT PRIMARY KEY, f1 INT, f2 INT, f3 INT, f4 INT, f5 MEDIUMINT, f6 INT, f7 INT, f8 char(1)); +INSERT INTO t1 VALUES (10, 1, 2, 3, 4, 5, 6, 7, ""); +INSERT INTO t1 VALUES (11, 1, 2, 3, 4, 5, 6, 7, NULL); +INSERT INTO t1 VALUES (12, 1, 2, 3, NULL, 5, 6, 7, "A"); +INSERT INTO t1 VALUES (13, 1, 2, 3, 0, 5, 6, 7, "A"); +INSERT INTO t2 SELECT * FROM t1; +UPDATE t2 SET f4=5 WHERE f4>0 or f4 is NULL; +DELETE FROM t1; +DELETE FROM t2; + +--let $binlog = query_get_value(SHOW MASTER STATUS, File, 1) +--let $datadir = `SELECT @@datadir` + +FLUSH BINARY LOGS; +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--replace_regex /\d{6} *\d*:\d\d:\d\d/<date>/ /Start:.*at startup/Start: xxx/ /SET TIMESTAMP=\d*/SET TIMESTAMP=X/ /exec_time=\d*/exec_time=x/ /mapped to number \d*/mapped to number num/ /CRC32 0x[0-9a-f]+/CRC32 XXX/ +--exec $MYSQL_BINLOG --verbose --verbose --base64-output=DECODE-ROWS $datadir/$binlog + +--echo +--echo Test mysqlbinlog | mysql type point-in-time recovery with compressed events. +--echo + +FLUSH BINARY LOGS; +--let $binlog_file = query_get_value(SHOW MASTER STATUS, File, 1) +CREATE TABLE t3 (a INT PRIMARY KEY, b INT, c VARCHAR(100)); +INSERT INTO t3 VALUES (0, 10, "hello"); +BEGIN; +INSERT INTO t3 VALUES (1, 10, "cat"), (2, 10, "mouse"), (3, 10, "dog"); +INSERT INTO t3 VALUES (4, 10, "goodbye"); +COMMIT; +DELETE FROM t3 WHERE a=2; +SELECT * FROM t3 ORDER BY a; +FLUSH LOGS; +DROP TABLE t3; + +--let $MYSQLD_DATADIR= `select @@datadir` +--exec $MYSQL_BINLOG $MYSQLD_DATADIR/$binlog_file | $MYSQL + +SELECT * FROM t3 ORDER BY a; + +DROP TABLE t1,t2,t3; +SET GLOBAL log_bin_compress=off; +SET GLOBAL log_bin_compress_min_len=256; diff --git a/mysql-test/t/mysqld--help.test b/mysql-test/t/mysqld--help.test index b37b33fa8a3..e6499957cd2 100644 --- a/mysql-test/t/mysqld--help.test +++ b/mysql-test/t/mysqld--help.test @@ -31,7 +31,7 @@ perl; connect null-audit aria oqgraph sphinx thread-handling test-sql-discovery rpl-semi-sync query-cache-info query-response-time metadata-lock-info locales unix-socket - wsrep file-key-management cracklib-password-check/; + wsrep file-key-management cracklib-password-check user-variables/; # And substitute the content some environment variables with their # names: diff --git a/mysql-test/t/mysqldump-max.test b/mysql-test/t/mysqldump-max.test index 3f73f046959..c0596f27e4f 100644 --- a/mysql-test/t/mysqldump-max.test +++ b/mysql-test/t/mysqldump-max.test @@ -1133,7 +1133,6 @@ connect(c2,127.0.0.1,root,,test,$MASTER_MYPORT,); connect(c3,127.0.0.1,root,,test,$MASTER_MYPORT,); connection default; ---echo # Connection default SET binlog_format= mixed; RESET MASTER; CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; @@ -1143,23 +1142,19 @@ INSERT INTO t2 VALUES (1,0), (2,0); SELECT GET_LOCK("block_queries_1", 120); connection c3; ---echo # Connection c3 SELECT GET_LOCK("block_queries_2", 120); # Start two queries that will be running on the tables during mysqldump connection c1; ---echo # Connection c1 SET @c= 0; send SELECT IF(@c<1, @c:=@c+1, GET_LOCK("block_queries_1", 120)) FROM t1 ORDER BY a; connection c2; ---echo # Connection c2 SET binlog_format="row"; SET @d= 10; send UPDATE t2 SET b=IF(@d<=10, @d:=@d+1, GET_LOCK("block_queries_2", 120)) ORDER BY a; connection default; ---echo # Connection default --echo # Make sure other queries are running (and waiting). let $wait_condition= SELECT COUNT(*) FROM information_schema.processlist @@ -1175,19 +1170,15 @@ let $wait_condition= SELECT RELEASE_LOCK("block_queries_1"); connection c3; ---echo # Connection c3 SELECT RELEASE_LOCK("block_queries_2"); connection c1; ---echo # Connection c1 reap; connection c2; ---echo # Connection c2 reap; connection default; ---echo # Connection default SELECT * FROM t2 ORDER BY a; DROP TABLE t1; DROP TABLE t2; @@ -1199,7 +1190,7 @@ source include/binlog_start_pos.inc; let _BINLOG_START_POS= $binlog_start_pos; --perl my $f= "$ENV{MYSQLTEST_VARDIR}/tmp/mwl136.sql"; -my $pos=$ENV{_BINLOG_START_POS} + 691; +my $pos=$ENV{_BINLOG_START_POS} + 739; open F, '<', $f or die "Failed to open $f: $!\n"; while (<F>) { s/$pos/<pos>/; diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index 9cde1f93a4a..299698ed04b 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -174,7 +174,7 @@ drop database mysqldump_test_db; --echo # Check that we don't dump in UTF8 in compatible mode by default, --echo # but use the default compiled values, or the values given in --echo # --default-character-set=xxx. However, we should dump in UTF8 ---echo # if it is explicitely set. +--echo # if it is explicitly set. CREATE TABLE t1 (a CHAR(10)); INSERT INTO t1 VALUES (_latin1 'ÄÖÜß'); @@ -1007,6 +1007,7 @@ SELECT * FROM `test2`; #DROP TABLE test2; # restore --exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/mysqldump.sql +--replace_column 6 # SHOW TRIGGERS; SELECT * FROM `test1`; SELECT * FROM `test2`; @@ -2053,6 +2054,7 @@ CREATE PROCEDURE pr1 () SELECT "Meow"; CREATE EVENT ev1 ON SCHEDULE AT '2030-01-01 00:00:00' DO SELECT "Meow"; --echo +--replace_column 6 # SHOW TRIGGERS; SHOW EVENTS; SELECT name,body FROM mysql.proc WHERE NAME = 'pr1'; @@ -2071,6 +2073,7 @@ DROP PROCEDURE pr1; --echo --echo reload table; this should restore table and trigger --exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/t1.sql +--replace_column 6 # SHOW TRIGGERS; SHOW EVENTS; SELECT name,body FROM mysql.proc WHERE NAME = 'pr1'; @@ -2078,6 +2081,7 @@ SELECT name,body FROM mysql.proc WHERE NAME = 'pr1'; --echo --echo reload db; this should restore routines and events --exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/test_34861.sql +--replace_column 6 # SHOW TRIGGERS; SHOW EVENTS; SELECT name,body FROM mysql.proc WHERE NAME = 'pr1'; @@ -2311,13 +2315,13 @@ CREATE VIEW v2 AS SELECT * FROM t2; --echo # Dumping BUG52792 database in xml format. --echo --echo # Running 'replace_regex on timestamp' ---replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/--TIME--/ +--replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(.[0-9]{2})*/--TIME--/ --exec $MYSQL_DUMP --user=root --compact -R -E --triggers -X BUG52792 --echo --echo # Dumping BUG52792 database in xml format with comments. --echo --echo # Running 'replace_regex on timestamp' ---replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/--TIME--/ +--replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(.[0-9]{2})*/--TIME--/ --exec $MYSQL_DUMP --comments --user=root -R -E --triggers -X BUG52792 --echo @@ -2330,7 +2334,8 @@ connect (conn_1, localhost, user1, , BUG52792, $MASTER_MYPORT, $MASTER_MYSOCK); connection conn_1; --echo # Running 'replace_regex on timestamp' ---replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/--TIME--/ +--replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(.[0-9]{2})*/--TIME--/ + --replace_result mysqldump.exe mysqldump --error 2 --exec $MYSQL_DUMP --user=user1 -R -E --triggers -X BUG52792 diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index e85d793b628..b2706a8459f 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -427,7 +427,6 @@ select 7; --error 1 --exec echo "--disable_info OCNE" | $MYSQL_TEST 2>&1 ---enable_connect_log ONCE connect (con1,localhost,root,,); connection default; disconnect con1; @@ -1780,12 +1779,14 @@ eval select "$long_rep" as x; # Repeat connect/disconnect --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql let $i=200; +disable_connect_log; while ($i) { connect (test_con1,localhost,root,,); disconnect test_con1; dec $i; } +enable_connect_log; echo 200 connects succeeded; EOF --exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql;" | $MYSQL_TEST 2>&1 @@ -1829,7 +1830,6 @@ disconnect con2; connection default; # Test enable_connect_log ---enable_connect_log connect (con1,localhost,root,,); connection default; connection con1; @@ -1842,7 +1842,6 @@ connection con1; --enable_query_log disconnect con1; connection default; ---disable_connect_log # ---------------------------------------------------------------------------- # Test mysqltest arguments diff --git a/mysql-test/t/not_embedded_server.test b/mysql-test/t/not_embedded_server.test index f22bf8cd7b5..b2cbdba6850 100644 --- a/mysql-test/t/not_embedded_server.test +++ b/mysql-test/t/not_embedded_server.test @@ -46,7 +46,6 @@ DROP TABLE t1; CREATE USER nopriv_user@localhost; connection default; ---echo connection: default --disable_warnings DROP TABLE IF EXISTS t1,t2,t3; @@ -65,7 +64,6 @@ FLUSH PRIVILEGES; connect (con1,localhost,nopriv_user,,); connection con1; ---echo connection: con1 let outfile=$MYSQLTEST_VARDIR/tmp/mytest; --error 0,1 @@ -93,7 +91,6 @@ disconnect con1; --source include/wait_until_disconnected.inc connection default; ---echo connection: default DROP TABLE t1,t2; DROP FUNCTION f; diff --git a/mysql-test/t/null.test b/mysql-test/t/null.test index a55f5ce58d3..072038fae50 100644 --- a/mysql-test/t/null.test +++ b/mysql-test/t/null.test @@ -22,6 +22,7 @@ SELECT (NULL OR NULL) IS NULL; select NULL AND 0, 0 and NULL; select inet_ntoa(null),inet_aton(null),inet_aton("122.256"),inet_aton("122.226."),inet_aton(""); explain extended select inet_ntoa(null),inet_aton(null),inet_aton("122.256"),inet_aton("122.226."),inet_aton(""); +select not null is true, not null or true, not null and false, not null <=> null; create table t1 (x int); insert into t1 values (null); diff --git a/mysql-test/t/openssl_1.test b/mysql-test/t/openssl_1.test index eea74b5b012..8e2d9133359 100644 --- a/mysql-test/t/openssl_1.test +++ b/mysql-test/t/openssl_1.test @@ -16,22 +16,22 @@ create table t1(f1 int); insert into t1 values (5); grant select on test.* to ssl_user1@localhost require SSL; -grant select on test.* to ssl_user2@localhost require cipher "DHE-RSA-AES256-SHA"; -grant select on test.* to ssl_user3@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "/C=FI/ST=Helsinki/L=Helsinki/O=MariaDB/CN=client"; -grant select on test.* to ssl_user4@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "/C=FI/ST=Helsinki/L=Helsinki/O=MariaDB/CN=client" ISSUER "/CN=cacert/C=FI/ST=Helsinki/L=Helsinki/O=MariaDB"; -grant select on test.* to ssl_user5@localhost require cipher "DHE-RSA-AES256-SHA" AND SUBJECT "xxx"; +grant select on test.* to ssl_user2@localhost require cipher "AES256-SHA"; +grant select on test.* to ssl_user3@localhost require cipher "AES256-SHA" AND SUBJECT "/C=FI/ST=Helsinki/L=Helsinki/O=MariaDB/CN=client"; +grant select on test.* to ssl_user4@localhost require cipher "AES256-SHA" AND SUBJECT "/C=FI/ST=Helsinki/L=Helsinki/O=MariaDB/CN=client" ISSUER "/CN=cacert/C=FI/ST=Helsinki/L=Helsinki/O=MariaDB"; +grant select on test.* to ssl_user5@localhost require cipher "AES256-SHA" AND SUBJECT "xxx"; flush privileges; -connect (con1,localhost,ssl_user1,,,,,SSL-CIPHER=DHE-RSA-AES256-SHA); +connect (con1,localhost,ssl_user1,,,,,SSL-CIPHER=AES256-SHA); --replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT --error ER_ACCESS_DENIED_ERROR +connect (con2,localhost,ssl_user2,,,,,SSL-CIPHER=AES128-SHA); connect (con2,localhost,ssl_user2,,,,,SSL-CIPHER=AES256-SHA); -connect (con2,localhost,ssl_user2,,,,,SSL-CIPHER=DHE-RSA-AES256-SHA); -connect (con3,localhost,ssl_user3,,,,,SSL-CIPHER=DHE-RSA-AES256-SHA); -connect (con4,localhost,ssl_user4,,,,,SSL-CIPHER=DHE-RSA-AES256-SHA); +connect (con3,localhost,ssl_user3,,,,,SSL-CIPHER=AES256-SHA); +connect (con4,localhost,ssl_user4,,,,,SSL-CIPHER=AES256-SHA); --replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT --error ER_ACCESS_DENIED_ERROR -connect (con5,localhost,ssl_user5,,,,,SSL-CIPHER=DHE-RSA-AES256-SHA); +connect (con5,localhost,ssl_user5,,,,,SSL-CIPHER=AES256-SHA); connection con1; # Check ssl turned on @@ -79,7 +79,6 @@ drop table t1; # --exec echo "this query should not execute;" > $MYSQLTEST_VARDIR/tmp/test.sql # Handle that openssl gives different error messages from YaSSL. -#--replace_regex /error:00000001:lib\(0\):func\(0\):reason\(1\)/ASN: bad other signature confirmation/ --replace_regex /2026 SSL connection error.*/2026 SSL connection error: xxxx/ --error 1 --exec $MYSQL_TEST --ssl-ca=$MYSQL_TEST_DIR/std_data/untrusted-cacert.pem --max-connect-retries=1 < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 @@ -89,7 +88,6 @@ drop table t1; # Test that we can't open connection to server if we are using # a blank ca # -#--replace_regex /error:00000001:lib\(0\):func\(0\):reason\(1\)/ASN: bad other signature confirmation/ --replace_regex /2026 SSL connection error.*/2026 SSL connection error: xxxx/ --error 1 --exec $MYSQL_TEST --ssl-ca= --max-connect-retries=1 < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 @@ -99,7 +97,6 @@ drop table t1; # Test that we can't open connection to server if we are using # a nonexistent ca file # -#--replace_regex /error:00000001:lib\(0\):func\(0\):reason\(1\)/ASN: bad other signature confirmation/ --replace_regex /2026 SSL connection error.*/2026 SSL connection error: xxxx/ --error 1 --exec $MYSQL_TEST --ssl-ca=nonexisting_file.pem --max-connect-retries=1 < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 @@ -109,23 +106,27 @@ drop table t1; # Test that we can't open connection to server if we are using # a blank client-key # +--replace_regex /2026 SSL connection error.*/2026 SSL connection error: xxxx/ --error 1 --exec $MYSQL_TEST --ssl-key= --max-connect-retries=1 < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 +--echo # # Test that we can't open connection to server if we are using # a blank client-cert # +--replace_regex /2026 SSL connection error.*/2026 SSL connection error: xxxx/ --error 1 --exec $MYSQL_TEST --ssl-cert= --max-connect-retries=1 < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 +--echo # # Bug#21611 Slave can't connect when master-ssl-cipher specified # - Apparently selecting a cipher doesn't work at all -# - Usa a cipher that both yaSSL and OpenSSL supports +# - Use a cipher that both yaSSL and OpenSSL supports # --exec echo "SHOW STATUS LIKE 'Ssl_cipher'; exit;" > $MYSQLTEST_VARDIR/tmp/test.sql ---exec $MYSQL_TEST --ssl-cipher=DHE-RSA-AES256-SHA < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 +--exec $MYSQL_TEST --ssl-cipher=AES256-SHA < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 # # Bug#25309 SSL connections without CA certificate broken since MySQL 5.0.23 @@ -190,6 +191,7 @@ SET GLOBAL event_scheduler=0; # Test to connect using an unknown cipher # --exec echo "SHOW STATUS LIKE 'Ssl_cipher'; exit" > $MYSQLTEST_VARDIR/tmp/test.sql +--replace_regex /2026 SSL connection error.*/2026 SSL connection error: xxxx/ --error 1 --exec $MYSQL_TEST --ssl-cipher=UNKNOWN-CIPHER < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 @@ -209,9 +211,10 @@ INSERT INTO t1 VALUES (1), (2); # With wrong parameters --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR mysqldump.exe mysqldump +--replace_regex /\"SSL connection error.*/SSL connection error: xxxx/ --error 2 --exec $MYSQL_DUMP --skip-create-options --skip-comments --ssl --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem test 2>&1 - +--echo DROP TABLE t1; --remove_file $MYSQLTEST_VARDIR/tmp/test.sql @@ -221,8 +224,8 @@ DROP TABLE t1; # # Common ciphers to openssl and yassl ---exec $MYSQL --host=localhost -e "SHOW STATUS LIKE 'Ssl_cipher';" --ssl-cipher=DHE-RSA-AES256-SHA ---exec $MYSQL --host=localhost -e "SHOW STATUS LIKE 'Ssl_cipher';" --ssl-cipher=EDH-RSA-DES-CBC3-SHA +--exec $MYSQL --host=localhost -e "SHOW STATUS LIKE 'Ssl_cipher';" --ssl-cipher=AES256-SHA +--exec $MYSQL --host=localhost -e "SHOW STATUS LIKE 'Ssl_cipher';" --ssl-cipher=DES-CBC3-SHA --disable_query_log --disable_result_log @@ -231,20 +234,7 @@ DROP TABLE t1; --exec $MYSQL --host=localhost -e "SHOW STATUS LIKE 'Ssl-cipher';" --ssl-cipher=NOT----EXIST # These probably exist but the server's keys can't be used to accept these kinds of connections. --error 1,0 ---exec $MYSQL --host=localhost -e "SHOW STATUS LIKE 'Ssl-cipher';" --ssl-cipher=DHE-DSS-AES128-RMD ---error 1,0 ---exec $MYSQL --host=localhost -e "SHOW STATUS LIKE 'Ssl-cipher';" --ssl-cipher=DHE-DSS-AES128-SHA ---error 1,0 ---exec $MYSQL --host=localhost -e "SHOW STATUS LIKE 'Ssl-cipher';" --ssl-cipher=DHE-DSS-AES256-RMD ---error 1,0 ---exec $MYSQL --host=localhost -e "SHOW STATUS LIKE 'Ssl-cipher';" --ssl-cipher=DHE-DSS-AES256-SHA ---error 1,0 ---exec $MYSQL --host=localhost -e "SHOW STATUS LIKE 'Ssl-cipher';" --ssl-cipher=DHE-DSS-DES-CBC3-RMD ---error 1,0 ---exec $MYSQL --host=localhost -e "SHOW STATUS LIKE 'Ssl-cipher';" --ssl-cipher=EDH-DSS-DES-CBC3-SHA ---error 1,0 ---exec $MYSQL --host=localhost -e "SHOW STATUS LIKE 'Ssl-cipher';" --ssl-cipher=EDH-DSS-DES-CBC-SHA -# End of crashers. ########################## +--exec $MYSQL --host=localhost -e "SHOW STATUS LIKE 'Ssl-cipher';" --ssl-cipher=AES128-RMD # If this gives a result, then the bug is fixed. --enable_result_log diff --git a/mysql-test/t/order_by_optimizer.test b/mysql-test/t/order_by_optimizer.test new file mode 100644 index 00000000000..a4c134afec9 --- /dev/null +++ b/mysql-test/t/order_by_optimizer.test @@ -0,0 +1,34 @@ +--disable_warnings +drop table if exists t0,t1,t2,t3; + +--enable_warnings +--echo # +--echo # MDEV-7885: EXPLAIN shows wrong info for ORDER BY query +--echo # +create table t0(a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1(a int); +insert into t1 select A.a + B.a* 10 + C.a * 100 from t0 A, t0 B, t0 C; + +create table t2 (key1 int, col1 int, key(key1)); +insert into t2 select a,a from t0; +insert into t2 select 15,15 from t1; +alter table t2 add key2 int, add key(key2); +--echo # This must show "Using filesort": +explain +select * from t2 ignore index for order by (key1) where col1<0 order by key1 limit 10; + +drop table t0, t1, t2; + +--echo # +--echo # MDEV-8857: [Upstream too] EXPLAIN incorrectly shows Distinct for tables using join buffer +--echo # +create table t0(a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t1 (a int, filler char(200), key(a)); +insert into t1 select A.a + B.a* 10, 'AAAAAAAAAAAAAAAAAAAA' from t0 A, t0 B where B.a in (0,1); +explain select distinct A.a from t0 A, t1 B where A.a+B.a> 0; + +drop table t0, t1; + diff --git a/mysql-test/t/parser.test b/mysql-test/t/parser.test index e27db9c4e48..1fa7df7fc3d 100644 --- a/mysql-test/t/parser.test +++ b/mysql-test/t/parser.test @@ -832,7 +832,7 @@ SELECT 1 FROM (SELECT 1 FROM DUAL WHERE 1 GROUP BY 1 HAVING 1 ORDER BY 1 FOR UPDATE) a; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR SELECT 1 FROM (SELECT 1 FROM DUAL WHERE 1 GROUP BY 1 HAVING 1 ORDER BY 1 PROCEDURE ANALYSE() FOR UPDATE) a; @@ -841,7 +841,7 @@ SELECT 1 FROM t1 WHERE EXISTS(SELECT 1 FROM DUAL WHERE 1 GROUP BY 1 HAVING 1 ORDER BY 1 FOR UPDATE); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR SELECT 1 FROM t1 WHERE EXISTS(SELECT 1 FROM DUAL WHERE 1 GROUP BY 1 HAVING 1 ORDER BY 1 PROCEDURE ANALYSE() FOR UPDATE); @@ -851,13 +851,13 @@ UNION SELECT 1 FROM DUAL WHERE 1 GROUP BY 1 HAVING 1 ORDER BY 1 FOR UPDATE; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR SELECT 1 FROM t1 UNION SELECT 1 FROM DUAL WHERE 1 GROUP BY 1 HAVING 1 ORDER BY 1 PROCEDURE ANALYSE() FOR UPDATE; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR SELECT 1 FROM DUAL PROCEDURE ANALYSE() UNION SELECT 1 FROM t1; @@ -867,7 +867,7 @@ UNION (SELECT 1 FROM DUAL WHERE 1 GROUP BY 1 HAVING 1 ORDER BY 1 FOR UPDATE); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR (SELECT 1 FROM t1) UNION (SELECT 1 FROM DUAL WHERE 1 GROUP BY 1 HAVING 1 ORDER BY 1 @@ -889,10 +889,10 @@ SELECT 1 INTO @var17727401; SELECT 1 INTO @var17727401 FROM t1; SELECT 1 INTO @var17727401 FROM DUAL; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR SELECT 1 INTO @var17727401_1 FROM t1 INTO @var17727401_2; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR SELECT 1 INTO @var17727401_1 FROM DUAL INTO @var17727401_2; @@ -902,7 +902,7 @@ SELECT 1 FROM t1 WHERE 1 GROUP BY 1 HAVING 1 ORDER BY 1 LIMIT 1 INTO @var1772740 --error ER_PARSE_ERROR SELECT 1 FROM t1 WHERE 1 INTO @var17727401 GROUP BY 1 HAVING 1 ORDER BY 1 LIMIT 1; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR SELECT 1 INTO @var17727401_1 FROM t1 WHERE 1 GROUP BY 1 HAVING 1 ORDER BY 1 LIMIT 1 INTO @var17727401_2; @@ -914,17 +914,17 @@ SELECT 1 FROM (SELECT 1 FROM t1 INTO @var17727401) a; --error ER_PARSE_ERROR SELECT EXISTS(SELECT 1 FROM t1 INTO @var17727401); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR SELECT 1 FROM t1 INTO @var17727401 UNION SELECT 1 FROM t1 INTO t1; --error ER_WRONG_USAGE (SELECT 1 FROM t1 INTO @var17727401) UNION (SELECT 1 FROM t1 INTO t1); SELECT 1 FROM t1 UNION SELECT 1 FROM t1 INTO @var17727401; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR SELECT 1 INTO @var17727401 FROM t1 PROCEDURE ANALYSE(); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR SELECT 1 FROM t1 PROCEDURE ANALYSE() INTO @var17727401; --echo # ORDER and LIMIT clause combinations @@ -973,27 +973,27 @@ eval SELECT ($q); eval SELECT 1 FROM ($q) a; let $q=SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval $q; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT ($q); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT 1 FROM ($q) a; let $q=SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval $q; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT ($q); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT 1 FROM ($q) a; let $q=SELECT 1 FROM t1 ORDER BY 1 LIMIT 1 UNION SELECT 1 FROM t1; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval $q; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT ($q); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT 1 FROM ($q) a; let $q=SELECT 1 FROM t1 LIMIT 1 ORDER BY 1 UNION SELECT 1 FROM t1; @@ -1001,39 +1001,39 @@ let $q=SELECT 1 FROM t1 LIMIT 1 ORDER BY 1 UNION SELECT 1 FROM t1; eval $q; --error ER_PARSE_ERROR eval SELECT ($q); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT 1 FROM ($q) a; let $q=SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1 ORDER BY 1; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval $q; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT ($q); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT 1 FROM ($q) a; let $q=SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1 LIMIT 1; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval $q; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT ($q); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT 1 FROM ($q) a; let $q=SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1 ORDER BY 1; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval $q; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT ($q); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT 1 FROM ($q) a; let $q=SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1 LIMIT 1; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval $q; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT ($q); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT 1 FROM ($q) a; DROP TABLE t1; @@ -1047,3 +1047,277 @@ SELECT * FROM ( (SELECT a FROM t1 ORDER BY a) UNION (SELECT 1 as b ORDER BY b ) ) AS a1 WHERE a1.a = 1 OR a1.a = 2; DROP TABLE t1; + +--echo # +--echo # MDEV-10080 Derived tables allow double LIMIT clause +--echo # +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2),(3); +--error ER_PARSE_ERROR +SELECT * FROM (SELECT * FROM t1 LIMIT 1 LIMIT 2) t1; +DROP TABLE t1; + +--echo # +--echo # MDEV-10109 Disallow syntactically INSERT .. SELECT .. {ORDER BY ..| LIMIT ..} .. UNION .. +--echo # + +--error ER_PARSE_ERROR +INSERT INTO t1 SELECT 1 ORDER BY 1 UNION SELECT 2; +--error ER_PARSE_ERROR +INSERT INTO t1 SELECT 1 LIMIT 1 UNION SELECT 2; +--error ER_PARSE_ERROR +CREATE TABLE t1 AS SELECT 1 ORDER BY 1 UNION SELECT 2; +--error ER_PARSE_ERROR +CREATE TABLE t1 AS SELECT 1 LIMIT 1 UNION SELECT 2; + + +--echo # +--echo # MDEV-8909 union parser cleanup +--echo # + +--echo # UNION with a non-parenthesized term +--echo # The following two queries return a wrong result +--echo # This will change when MDEV-10120 is fixed +--echo # For now, we're testing the parser. +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20),(30); +SELECT 1 AS a UNION SELECT a FROM t1 GROUP BY a ORDER BY GROUP_CONCAT(a); +SELECT 1 AS a UNION SELECT a FROM t1 GROUP BY a ORDER BY GROUP_CONCAT(a ORDER BY a); +DROP TABLE t1; + +--echo # UNION with a parenthesed term +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20),(30); + +SELECT 1 AS a UNION (SELECT a FROM t1 GROUP BY a ORDER BY GROUP_CONCAT(a ORDER BY a) LIMIT 2); + +--error ER_INVALID_GROUP_FUNC_USE +SELECT 1 AS a UNION (SELECT a FROM t1 GROUP BY a ORDER BY GROUP_CONCAT(a)); +--error ER_INVALID_GROUP_FUNC_USE +SELECT 1 AS a UNION (SELECT a FROM t1 GROUP BY a ORDER BY GROUP_CONCAT(a)) LIMIT 1; +--error ER_INVALID_GROUP_FUNC_USE +SELECT 1 AS a UNION (SELECT a FROM t1 GROUP BY a ORDER BY GROUP_CONCAT(a)) ORDER BY a; +--error ER_INVALID_GROUP_FUNC_USE +SELECT 1 AS a UNION (SELECT a FROM t1 GROUP BY a ORDER BY GROUP_CONCAT(a)) ORDER BY a LIMIT 1; +DROP TABLE t1; + +--echo # UNION with a parenthesized term with ROLLUP + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20),(30); +SELECT 1 AS a UNION (SELECT a FROM t1 GROUP BY a WITH ROLLUP); +SELECT 1 AS a UNION (SELECT a FROM t1 GROUP BY a WITH ROLLUP) LIMIT 1; +SELECT 1 AS a UNION (SELECT a FROM t1 GROUP BY a WITH ROLLUP) ORDER BY a LIMIT 1; +SELECT 1 AS a UNION (SELECT a FROM t1 GROUP BY a WITH ROLLUP LIMIT 2); + + +--error ER_WRONG_USAGE +SELECT 1 AS a UNION (SELECT a FROM t1 GROUP BY a WITH ROLLUP ORDER BY a); +--error ER_WRONG_USAGE +SELECT 1 AS a UNION (SELECT a FROM t1 GROUP BY a WITH ROLLUP ORDER BY GROUP_CONCAT(a)); +--error ER_WRONG_USAGE +SELECT 1 AS a UNION (SELECT a FROM t1 GROUP BY a WITH ROLLUP ORDER BY GROUP_CONCAT(a ORDER BY a)); +DROP TABLE t1; + +--echo # UNION with a non-parethesized term with ROLLUP + +--echo # This will change after: MDEV-10120 Wrong result of UNION .. ORDER BY GROUP_CONCAT() +--echo # Currently we're testing the parser only + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20),(30); +SELECT 1 AS a UNION SELECT a FROM t1 GROUP BY a WITH ROLLUP ORDER BY GROUP_CONCAT(a); +SELECT 1 AS a UNION SELECT a FROM t1 GROUP BY a WITH ROLLUP ORDER BY GROUP_CONCAT(a ORDER BY a); +SELECT 1 AS a UNION SELECT a FROM t1 GROUP BY a WITH ROLLUP ORDER BY GROUP_CONCAT(a ORDER BY a) LIMIT 1; +DROP TABLE t1; + +--echo # Derived table with ROLLUP +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20),(30); + +SELECT * FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP) t1; +SELECT * FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP) t1 LIMIT 1; +SELECT * FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP) t1 ORDER BY a; +SELECT * FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP) t1 ORDER BY a LIMIT 1; +SELECT * FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP) t1 ORDER BY a DESC LIMIT 1; + +SELECT a, GROUP_CONCAT(a) FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP) t1 ORDER BY GROUP_CONCAT(a); +SELECT a, GROUP_CONCAT(a) FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP) t1 ORDER BY GROUP_CONCAT(a ORDER BY a); +SELECT a, GROUP_CONCAT(a) FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP) t1 ORDER BY GROUP_CONCAT(a) LIMIT 1; +SELECT a, GROUP_CONCAT(a) FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP) t1 ORDER BY GROUP_CONCAT(a ORDER BY a) LIMIT 1; + +SELECT a, GROUP_CONCAT(a) FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP) t1 GROUP BY a ORDER BY GROUP_CONCAT(a); +SELECT a, GROUP_CONCAT(a) FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP) t1 GROUP BY a ORDER BY GROUP_CONCAT(a ORDER BY a); +SELECT a, GROUP_CONCAT(a) FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP) t1 GROUP BY a ORDER BY GROUP_CONCAT(a) DESC; +SELECT a, GROUP_CONCAT(a) FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP) t1 GROUP BY a ORDER BY GROUP_CONCAT(a ORDER BY a) DESC; + +SELECT a, GROUP_CONCAT(a) FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP) t1 GROUP BY a ORDER BY GROUP_CONCAT(a) LIMIT 1; +SELECT a, GROUP_CONCAT(a) FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP) t1 GROUP BY a ORDER BY GROUP_CONCAT(a ORDER BY a) LIMIT 1; +SELECT a, GROUP_CONCAT(a) FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP) t1 GROUP BY a ORDER BY GROUP_CONCAT(a) DESC LIMIT 1; +SELECT a, GROUP_CONCAT(a) FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP) t1 GROUP BY a ORDER BY GROUP_CONCAT(a ORDER BY a) DESC LIMIT 1; + +--error ER_WRONG_USAGE +SELECT * FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP ORDER BY a) t1; +--error ER_WRONG_USAGE +SELECT * FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP ORDER BY a LIMIT 1) t1; +--error ER_WRONG_USAGE +SELECT * FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP ORDER BY GROUP_CONCAT(a)) t1; +--error ER_WRONG_USAGE +SELECT * FROM (SELECT * FROM t1 GROUP BY a WITH ROLLUP ORDER BY GROUP_CONCAT(a ORDER BY a)) t1; + +DROP TABLE t1; + +--echo # Subquery, one row, ROLLUP + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10); +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP HAVING a IS NULL); +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP HAVING a IS NOT NULL); +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP LIMIT 1); +SELECT (SELECT GROUP_CONCAT(a) FROM t1 GROUP BY a WITH ROLLUP LIMIT 1); +SELECT (SELECT GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP LIMIT 1); +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP HAVING a IS NULL) FROM t1; +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP HAVING a IS NOT NULL) FROM t1; +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP LIMIT 1) FROM t1; +SELECT (SELECT GROUP_CONCAT(a) FROM t1 GROUP BY a WITH ROLLUP LIMIT 1) FROM t1; +SELECT (SELECT GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP LIMIT 1) FROM t1; + +--error ER_SUBQUERY_NO_1_ROW +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP); +--error ER_SUBQUERY_NO_1_ROW +SELECT (SELECT GROUP_CONCAT(a) FROM t1 GROUP BY a WITH ROLLUP); +--error ER_SUBQUERY_NO_1_ROW +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP) FROM t1; +--error ER_SUBQUERY_NO_1_ROW +SELECT (SELECT GROUP_CONCAT(a) FROM t1 GROUP BY a WITH ROLLUP) FROM t1; + +--error ER_WRONG_USAGE +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP ORDER BY a); +--error ER_WRONG_USAGE +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP ORDER BY a LIMIT 1); +--error ER_WRONG_USAGE +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP ORDER BY GROUP_CONCAT(a)); +--error ER_WRONG_USAGE +SELECT (SELECT GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP ORDER BY a LIMIT 1) AS a; +--error ER_WRONG_USAGE +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP ORDER BY a) FROM t1; +--error ER_WRONG_USAGE +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP ORDER BY a LIMIT 1) FROM t1; +--error ER_WRONG_USAGE +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP ORDER BY GROUP_CONCAT(a)) FROM t1; +--error ER_WRONG_USAGE +SELECT (SELECT GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP ORDER BY a LIMIT 1) AS a FROM t1; + +DROP TABLE t1; + +--echo # Subquery, multiple rows, ROLLUP + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20),(30); +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP LIMIT 1); +SELECT (SELECT GROUP_CONCAT(a) FROM t1 GROUP BY a WITH ROLLUP LIMIT 1); +SELECT (SELECT GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP LIMIT 1); +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP LIMIT 1) FROM t1; +SELECT (SELECT GROUP_CONCAT(a) FROM t1 GROUP BY a WITH ROLLUP LIMIT 1) FROM t1; +SELECT (SELECT GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP LIMIT 1) FROM t1; + +--error ER_SUBQUERY_NO_1_ROW +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP); +--error ER_SUBQUERY_NO_1_ROW +SELECT (SELECT GROUP_CONCAT(a) FROM t1 GROUP BY a WITH ROLLUP); +--error ER_SUBQUERY_NO_1_ROW +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP) FROM t1; +--error ER_SUBQUERY_NO_1_ROW +SELECT (SELECT GROUP_CONCAT(a) FROM t1 GROUP BY a WITH ROLLUP) FROM t1; + +--error ER_WRONG_USAGE +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP ORDER BY a); +--error ER_WRONG_USAGE +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP ORDER BY a LIMIT 1); +--error ER_WRONG_USAGE +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP ORDER BY GROUP_CONCAT(a)); +--error ER_WRONG_USAGE +SELECT (SELECT GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP ORDER BY a LIMIT 1) AS a; + +--error ER_WRONG_USAGE +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP ORDER BY a) FROM t1; +--error ER_WRONG_USAGE +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP ORDER BY a LIMIT 1) FROM t1; +--error ER_WRONG_USAGE +SELECT (SELECT * FROM t1 GROUP BY a WITH ROLLUP ORDER BY GROUP_CONCAT(a)) FROM t1; +--error ER_WRONG_USAGE +SELECT (SELECT GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a WITH ROLLUP ORDER BY a LIMIT 1) AS a FROM t1; + +DROP TABLE t1; + + +--echo +--echo MDEV-10101 Wrong error message of SELECT 1 UNION (SELECT 1 FROM t1 GROUP BY 1 WITH ROLLUP) +--echo + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20),(30); + +SELECT 1 AS a UNION (SELECT a FROM t1 GROUP BY a WITH ROLLUP); +(SELECT a FROM t1 GROUP BY a WITH ROLLUP) UNION SELECT 1; +SELECT a FROM t1 GROUP BY a WITH ROLLUP UNION SELECT 1; + +SELECT 1 AS a UNION (SELECT a FROM t1 GROUP BY a WITH ROLLUP) LIMIT 1; +(SELECT a FROM t1 GROUP BY a WITH ROLLUP) UNION SELECT 1 LIMIT 1; +SELECT a FROM t1 GROUP BY a WITH ROLLUP UNION SELECT 1 LIMIT 1; + +SELECT 1 AS a UNION (SELECT a FROM t1 GROUP BY a WITH ROLLUP) ORDER BY a LIMIT 1; +(SELECT a FROM t1 GROUP BY a WITH ROLLUP) UNION SELECT 1 ORDER BY a LIMIT 1; +SELECT a FROM t1 GROUP BY a WITH ROLLUP UNION SELECT 1 ORDER BY a LIMIT 1; + +SELECT 1 AS a UNION (SELECT a FROM t1 GROUP BY a WITH ROLLUP LIMIT 2); +(SELECT a FROM t1 GROUP BY a WITH ROLLUP LIMIT 2) UNION SELECT 1; +DROP TABLE t1; + + +--echo # +--echo # MDEV-10779 Failing assertion lex->proc_list.elements == 0 or syntax error on PROCEDURE ANALYSE in UNION +--echo # + +CREATE TABLE t1 (i INT); +--error ER_WRONG_USAGE +(SELECT * FROM t1 PROCEDURE ANALYSE(10, 10)) +UNION +(SELECT * FROM t1 PROCEDURE ANALYSE(10, 10)); + +--error ER_WRONG_USAGE +(SELECT * FROM t1 PROCEDURE ANALYSE(10, 10)) +UNION +SELECT * FROM t1 PROCEDURE ANALYSE(10, 10); + +--error ER_WRONG_USAGE +(SELECT * FROM t1 PROCEDURE ANALYSE(10, 10)) +UNION +(SELECT 1); + +--error ER_WRONG_USAGE +(SELECT * FROM t1 PROCEDURE ANALYSE(10, 10)) +UNION +SELECT 1; + +--error ER_PARSE_ERROR +SELECT * FROM t1 PROCEDURE ANALYSE(10, 10) +UNION +(SELECT * FROM t1 PROCEDURE ANALYSE(10, 10)); + +--error ER_PARSE_ERROR +SELECT * FROM t1 PROCEDURE ANALYSE(10, 10) +UNION +SELECT * FROM t1 PROCEDURE ANALYSE(10, 10); + +--error ER_PARSE_ERROR +SELECT * FROM t1 PROCEDURE ANALYSE(10, 10) +UNION +(SELECT 1); + +--error ER_PARSE_ERROR +SELECT * FROM t1 PROCEDURE ANALYSE(10, 10) +UNION +SELECT 1; + +DROP TABLE t1; diff --git a/mysql-test/t/partition_bug18198.test b/mysql-test/t/partition_bug18198.test index 75544f58ce8..720d483e8ed 100644 --- a/mysql-test/t/partition_bug18198.test +++ b/mysql-test/t/partition_bug18198.test @@ -163,7 +163,7 @@ create table t1 (col1 date) partition by range(unix_timestamp(col1)) (partition p0 values less than (10), partition p1 values less than (30)); --- error ER_PARSE_ERROR +-- error ER_PARTITION_FUNCTION_IS_NOT_ALLOWED create table t1 (col1 datetime) partition by range(week(col1)) (partition p0 values less than (10), partition p1 values less than (30)); diff --git a/mysql-test/t/partition_debug_sync.test b/mysql-test/t/partition_debug_sync.test index 90f1d4173ff..f085ea3fb83 100644 --- a/mysql-test/t/partition_debug_sync.test +++ b/mysql-test/t/partition_debug_sync.test @@ -22,7 +22,6 @@ SET DEBUG_SYNC= 'RESET'; --echo # only until ALTER tries to upgrade its MDL lock, which ends up in MDL --echo # deadlock which is correctly reported. connect(con1, localhost, root,,); ---echo # Con 1 SET DEBUG_SYNC= 'RESET'; CREATE TABLE t1 (a INTEGER, @@ -38,12 +37,10 @@ SET DEBUG_SYNC= 'alter_table_before_create_table_no_lock SIGNAL removing_partiti SET DEBUG_SYNC= 'mdl_acquire_lock_wait SIGNAL waiting_for_upgrade'; --send ALTER TABLE t1 REMOVE PARTITIONING connection default; ---echo # Con default SET DEBUG_SYNC= 'now WAIT_FOR removing_partitioning'; SET DEBUG_SYNC= 'mdl_acquire_lock_wait SIGNAL waiting_for_alter'; SET DEBUG_SYNC= 'rm_table_no_locks_before_delete_table WAIT_FOR waiting_for_upgrade'; DROP TABLE IF EXISTS t1; ---echo # Con 1 connection con1; --error ER_LOCK_DEADLOCK --reap @@ -71,12 +68,10 @@ SET DEBUG_SYNC= 'alter_table_before_open_tables SIGNAL removing_partitions WAIT_ SET DEBUG_SYNC= 'alter_table_before_rename_result_table WAIT_FOR delete_done'; --send ALTER TABLE t2 REMOVE PARTITIONING connection default; ---echo # Con default SET DEBUG_SYNC= 'now WAIT_FOR removing_partitions'; SET DEBUG_SYNC= 'rm_table_no_locks_before_delete_table SIGNAL waiting_for_alter'; SET DEBUG_SYNC= 'rm_table_no_locks_before_binlog SIGNAL delete_done'; DROP TABLE IF EXISTS t2; ---echo # Con 1 connection con1; --error ER_NO_SUCH_TABLE --reap @@ -84,53 +79,6 @@ SET DEBUG_SYNC= 'RESET'; disconnect con1; --source include/wait_until_disconnected.inc connection default; ---echo # Con default SET DEBUG_SYNC= 'RESET'; --echo End of 5.1 tests - ---echo # ---echo # Coverage test for non pruned ha_partition::store_lock() ---echo # -CREATE TABLE t1 (a int) ENGINE = InnoDB; -CREATE TABLE t2 (a int PRIMARY KEY) -ENGINE = InnoDB PARTITION BY HASH (a) PARTITIONS 3; - -HANDLER t1 OPEN; - ---echo # Con1 -connect (con1, localhost, root,,); - -LOCK TABLES t1 WRITE, t2 READ; - ---echo # Default -connection default; - -SET DEBUG_SYNC="wait_for_lock SIGNAL locking"; -send INSERT INTO t2 VALUES (1), (2), (3); - ---echo # Con1 -connection con1; -SET DEBUG_SYNC="now WAIT_FOR locking"; - -send ALTER TABLE t1 ADD COLUMN b int; - ---echo # Default -connection default; ---error ER_LOCK_ABORTED ---reap - -SELECT 1; - ---echo # Con1 -connection con1; ---reap - -UNLOCK TABLES; ---disconnect con1 - ---echo # Default -connection default; -SET DEBUG_SYNC = 'RESET'; - -DROP TABLE t1, t2; diff --git a/mysql-test/t/partition_default.test b/mysql-test/t/partition_default.test new file mode 100644 index 00000000000..1110b311c29 --- /dev/null +++ b/mysql-test/t/partition_default.test @@ -0,0 +1,522 @@ + +--source include/have_partition.inc + +# +# expression lists +# +create table t1 (a int, b int) + PARTITION BY LIST (a) + ( + PARTITION p2 VALUES IN (4,5,6), + PARTITION p1 VALUES IN (1) + ) +; +--error ER_NO_PARTITION_FOR_GIVEN_VALUE +insert into t1 values (10,10); +drop table t1; +create table t1 (a int, b int) + PARTITION BY LIST (a) + ( + PARTITION p2 VALUES IN (4,5,6), + PARTITION p1 VALUES IN (1), + PARTITION p0 DEFAULT + ) +; +show create table t1; +insert into t1 values (10,10); +insert into t1 values (4,4); +select * from t1; +--sorted_result +select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1'; +drop table t1; + +--error ER_PARTITION_DEFAULT_ERROR +create table t1 (a int, b int) + PARTITION BY LIST (a) + ( + PARTITION p2 VALUES IN (4,5,6), + PARTITION p1 VALUES IN (1), + PARTITION p0 DEFAULT, + PARTITION p3 DEFAULT + ) +; +--error ER_PARTITION_DEFAULT_ERROR +create table t1 (a int, b int) + PARTITION BY LIST (a) + ( + PARTITION p0 DEFAULT, + PARTITION p2 VALUES IN (4,5,6), + PARTITION p1 VALUES IN (1), + PARTITION p3 DEFAULT + ) +; + +create table t1 (a int, b int) + PARTITION BY LIST (a) + ( + PARTITION p0 DEFAULT, + PARTITION p2 VALUES IN (4,5,6), + PARTITION p1 VALUES IN (1) + ) +; +show create table t1; +insert into t1 values (10,10); +select * from t1; +--sorted_result +select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1'; +drop table t1; + +# +# Default has its value as 0 check that they are not clash. +# +create table t1 (a int, b int) + PARTITION BY LIST (a) + ( + PARTITION p0 DEFAULT, + PARTITION p2 VALUES IN (4,5,6), + PARTITION p1 VALUES IN (1, 0) + ) +; +show create table t1; +insert into t1 values (10,10); +select * from t1; +--sorted_result +select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1'; +drop table t1; + +# +# columns lists +# +create table t1 (a int, b int) + PARTITION BY LIST COLUMNS(a,b) + ( + PARTITION p2 VALUES IN ((1,4),(2,5),(3,6)), + PARTITION p1 VALUES IN ((1,1),(0,0)), + PARTITION p0 DEFAULT + ) +; +show create table t1; +insert into t1 values (10,10); +select * from t1; +--sorted_result +select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1'; +drop table t1; + +--error ER_PARTITION_DEFAULT_ERROR +create table t1 (a int, b int) + PARTITION BY LIST COLUMNS(a,b) + ( + PARTITION p2 VALUES IN ((1,4),(2,5),(3,6)), + PARTITION p1 VALUES IN ((1,1),(0,0)), + PARTITION p0 DEFAULT, + PARTITION p3 DEFAULT + ) +; + +--error ER_PARTITION_DEFAULT_ERROR +create table t1 (a int, b int) + PARTITION BY LIST COLUMNS(a,b) + ( + PARTITION p0 DEFAULT, + PARTITION p2 VALUES IN ((1,4),(2,5),(3,6)), + PARTITION p1 VALUES IN ((1,1),(0,0)), + PARTITION p3 DEFAULT + ) +; + +# +# partititon prunning test +# + +create table t1 (a int, b int) + PARTITION BY LIST (a) + ( + PARTITION p2 VALUES IN (4,5,6), + PARTITION p1 VALUES IN (1,20), + PARTITION p0 default + ) +; +show create table t1; +insert into t1 values (10,10); +--sorted_result +select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1'; +select * from t1 where a=10; +select * from t1 where a<=10; +select * from t1 where a<=20; +select * from t1 where a>=10; +select * from t1 where a>=5; +insert into t1 values (20,20),(5,5); +--sorted_result +select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1'; +select * from t1 where a=10; +select * from t1 where a<=10; +select * from t1 where a<=20; +select * from t1 where a>=10; +select * from t1 where a>=5; +explain partitions select * from t1 where a=10; +explain partitions select * from t1 where a=5; +select * from t1 where a=10 or a=5; +explain partitions select * from t1 where a=10 or a=5; + +drop table t1; + +create table t1 (a int, b int) + PARTITION BY LIST COLUMNS(a,b) + ( + PARTITION p2 VALUES IN ((1,4),(2,5),(3,6),(5,5)), + PARTITION p1 VALUES IN ((1,1),(20,20)), + PARTITION p0 DEFAULT + ) +; +show create table t1; +insert into t1 values (10,10); +--sorted_result +select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1'; +select * from t1 where a=10 and b=10; +explain partitions select * from t1 where a=10 and b=10; +select * from t1 where a=10; +explain partitions select * from t1 where a=10; +select * from t1 where a<=10; +select * from t1 where a>=10; +insert into t1 values (20,20),(5,5); +--sorted_result +select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1'; +select * from t1 where a=10 and b=10; +explain partitions select * from t1 where a=10 and b=10; +select * from t1 where a=10 and b=10 or a=20 and b=20; +explain partitions select * from t1 where a=10 and b=10 or a=20 and b=20; +drop table t1; + +# +# partition pruning with expressions +# +create table t1 (a int, b int); + +insert into t1 values (10,10),(2,5),(0,0); + +select * from t1; + +alter table t1 + PARTITION BY LIST (a+b) + ( + PARTITION p2 VALUES IN (1,2,3,7), + PARTITION p1 VALUES IN (21,0), + PARTITION p0 DEFAULT + ) +; +show create table t1; +select * from t1; +explain partitions select * from t1 where a=2 and b=5; +explain partitions select * from t1 where a=10 and b=10; +drop table t1; + +create table t1 (a int, b int); + +insert into t1 values (10,10),(2,5),(0,0); + +select * from t1; + +alter table t1 + PARTITION BY LIST (a+5) + ( + PARTITION p2 VALUES IN (1,2,3,7), + PARTITION p1 VALUES IN (0), + PARTITION p0 DEFAULT + ) +; +show create table t1; +select * from t1; +--sorted_result +select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1'; +explain partitions select * from t1 where a>=2; +explain partitions select * from t1 where a>=2 and a<=3; +explain partitions select * from t1 where a=10; +drop table t1; + + + +CREATE TABLE t1 (a DATE, KEY(a)) +PARTITION BY LIST (TO_DAYS(a)) +(PARTITION `pDEF` DEFAULT, + PARTITION `p2001-01-01` VALUES IN (TO_DAYS('2001-01-01')), + PARTITION `pNULL` VALUES IN (NULL), + PARTITION `p0000-01-02` VALUES IN (TO_DAYS('0000-01-02')), + PARTITION `p1001-01-01` VALUES IN (TO_DAYS('1001-01-01'))); +if ($verify_without_partitions) +{ +ALTER TABLE t1 REMOVE PARTITIONING; +} +INSERT INTO t1 VALUES ('0000-00-00'), ('0000-01-02'), ('0001-01-01'), + ('1001-00-00'), ('1001-01-01'), ('1002-00-00'), ('2001-01-01'); +--source include/partition_date_range.inc +--echo # test without index +ALTER TABLE t1 DROP KEY a; +--source include/partition_date_range.inc +DROP TABLE t1; +--echo # TO_SECONDS, test of LIST and index +CREATE TABLE t1 (a DATE, KEY(a)) +PARTITION BY LIST (TO_SECONDS(a)) +(PARTITION `pDEF` DEFAULT, + PARTITION `p2001-01-01` VALUES IN (TO_SECONDS('2001-01-01')), + PARTITION `pNULL` VALUES IN (NULL), + PARTITION `p0000-01-02` VALUES IN (TO_SECONDS('0000-01-02')), + PARTITION `p1001-01-01` VALUES IN (TO_SECONDS('1001-01-01'))); +if ($verify_without_partitions) +{ +ALTER TABLE t1 REMOVE PARTITIONING; +} +INSERT INTO t1 VALUES ('0000-00-00'), ('0000-01-02'), ('0001-01-01'), + ('1001-00-00'), ('1001-01-01'), ('1002-00-00'), ('2001-01-01'); +--source include/partition_date_range.inc +--echo # test without index +ALTER TABLE t1 DROP KEY a; +--source include/partition_date_range.inc +DROP TABLE t1; + +# +# ALTER TABLE test +# + +create table t1 (a int, b int); + +insert into t1 values (10,10),(2,5),(0,0); + +select * from t1; + +alter table t1 + PARTITION BY LIST (a) + ( + PARTITION p2 VALUES IN (1,2,3), + PARTITION p1 VALUES IN (20,0), + PARTITION p0 DEFAULT + ) +; +show create table t1; +select * from t1; +--sorted_result +select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1'; +explain partitions select * from t1 where a=2 and b=5; +explain partitions select * from t1 where a=10 and b=10; +alter table t1 + PARTITION BY LIST (a) + ( + PARTITION p2 VALUES IN (1,2,3), + PARTITION p1 VALUES IN (20,0), + PARTITION p0 VALUES IN (10) + ) +; +show create table t1; +select * from t1; +--sorted_result +select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1'; +explain partitions select * from t1 where a=2 and b=5; +explain partitions select * from t1 where a=10 and b=10; +alter table t1 + PARTITION BY LIST (a) + ( + PARTITION p2 DEFAULT, + PARTITION p1 VALUES IN (20,0), + PARTITION p0 VALUES IN (10) + ) +; +show create table t1; +select * from t1; +--sorted_result +select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1'; +explain partitions select * from t1 where a=2 and b=5; +explain partitions select * from t1 where a=10 and b=10; + +--error ER_NO_PARTITION_FOR_GIVEN_VALUE +alter table t1 drop partition p2; +delete from t1 where a=2; +alter table t1 drop partition p2; +show create table t1; +select * from t1; +--sorted_result +select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1'; + +alter table t1 add partition (PARTITION pd DEFAULT); +show create table t1; +--error ER_PARTITION_DEFAULT_ERROR +alter table t1 add partition (PARTITION pdd DEFAULT); +alter table t1 drop partition pd; +--error ER_PARTITION_DEFAULT_ERROR +alter table t1 add partition (PARTITION pdd DEFAULT, + PARTITION pd DEFAULT); + +drop table t1; + +create table t1 (a int, b int); + +insert into t1 values (10,10),(2,5),(0,0); + +select * from t1; + +alter table t1 + PARTITION BY LIST COLUMNS(a,b) + ( + PARTITION p2 VALUES IN ((1,4),(2,5),(3,6)), + PARTITION p1 VALUES IN ((1,1),(0,0)), + PARTITION p0 DEFAULT + ) +; +show create table t1; +select * from t1; +--sorted_result +select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1'; +explain partitions select * from t1 where a=2 and b=5; +explain partitions select * from t1 where a=10 and b=10; +alter table t1 + PARTITION BY LIST COLUMNS(a,b) + ( + PARTITION p2 VALUES IN ((1,4),(2,5),(3,6)), + PARTITION p1 VALUES IN ((1,1),(0,0)), + PARTITION p0 VALUES IN ((10,10)) + ) +; +show create table t1; +select * from t1; +--sorted_result +select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1'; +explain partitions select * from t1 where a=2 and b=5; +explain partitions select * from t1 where a=10 and b=10; +alter table t1 + PARTITION BY LIST COLUMNS(a,b) + ( + PARTITION p2 DEFAULT, + PARTITION p1 VALUES IN ((1,1),(0,0)), + PARTITION p0 VALUES IN ((10,10)) + ) +; +show create table t1; +select * from t1; +--sorted_result +select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1'; +explain partitions select * from t1 where a=2 and b=5; +explain partitions select * from t1 where a=10 and b=10; + +--error ER_NO_PARTITION_FOR_GIVEN_VALUE +alter table t1 drop partition p2; +delete from t1 where a=2; +alter table t1 drop partition p2; +show create table t1; +select * from t1; +--sorted_result +select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1'; + +alter table t1 add partition (PARTITION pd DEFAULT); +show create table t1; +--error ER_PARTITION_DEFAULT_ERROR +alter table t1 add partition (PARTITION pdd DEFAULT); +alter table t1 drop partition pd; +--error ER_PARTITION_DEFAULT_ERROR +alter table t1 add partition (PARTITION pdd DEFAULT, + PARTITION pd DEFAULT); +drop table t1; + + +# +# Problem of reorganizing DEFAULT partition +# +create table t1 (a int) + PARTITION BY LIST (a) + ( + PARTITION p2 VALUES IN (4,5,6), + PARTITION p1 VALUES IN (1), + PARTITION pd DEFAULT + ) +; +insert into t1 values (1),(2),(3),(4); +--sorted_result +select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1'; + +alter table t1 add partition + (partition p0 VALUES IN (2,3)); + +--sorted_result +select partition_name, table_rows from INFORMATION_SCHEMA.PARTITIONS where table_name='t1'; + +drop table t1; + +# +# Check that first DEFAULT works in LIST COLUMN +# +create table t1 (a int, b int) + PARTITION BY LIST COLUMNS(a,b) + ( + PARTITION p0 DEFAULT, + PARTITION p2 VALUES IN ((1,4),(2,5),(3,6)), + PARTITION p1 VALUES IN ((1,1),(0,0)) + ) +; + +show create table t1; + +drop table t1; + +--echo # +--echo # MDEV-10765: Wrong result - query does not retrieve values from +--echo # default partition on a table partitioned by list columns +--echo # + +create table t1 (i int, j int) partition by list columns(i,j) (partition p1 values in ((10,10)), partition p2 default); +insert into t1 values (10,1); +select * from t1 where i = 10; +explain partitions +select * from t1 where i = 10; +select * from t1 where i = 10 and j=1; +explain partitions +select * from t1 where i = 10 and j=1; +insert into t1 values (10,10); +select * from t1 where i = 10 and j=10; +explain partitions +select * from t1 where i = 10 and j=10; +drop table t1; + +create table t1 +( + a int not null, + b int not null, + c int +) +partition by list columns(a,b) +( + partition p1 values in ((10,10)), + partition p2 values in ((10,20)), + partition p3 values in ((10,30)), + partition p4 values in ((10,40)), + partition p5 values in ((10,50)) +); + +insert into t1 values + (10,10,1234), + (10,20,1234), + (10,30,1234), + (10,40,1234), + (10,50,1234); + +explain partitions +select * from t1 +where a>=10 and (a <=10 and b <=30); +drop table t1; + +--echo # +--echo # MDEV-10763: Wrong result - server does not return NULL values +--echo # from default list partition after ALTER table +--echo # +create table t1 (i int) partition by list (i) ( partition p1 default); +insert into t1 values (null); +select * from t1 where i is null; +alter table t1 partition by list (i) ( partition p1 values in (1), partition p2 default); +select * from t1 where i is null; +explain partitions +select * from t1 where i is null; +alter table t1 partition by list (i) ( + partition p0 values in (NULL), + partition p1 values in (1), + partition p2 default); +select * from t1 where i is null; +explain partitions +select * from t1 where i is null; + +drop table t1; diff --git a/mysql-test/t/partition_exchange-master.opt b/mysql-test/t/partition_exchange-master.opt new file mode 100644 index 00000000000..5a0380b7a1d --- /dev/null +++ b/mysql-test/t/partition_exchange-master.opt @@ -0,0 +1 @@ +--loose-innodb_default_row_format=COMPACT diff --git a/mysql-test/t/partition_innodb-master.opt b/mysql-test/t/partition_innodb-master.opt new file mode 100644 index 00000000000..cf94b2d7dca --- /dev/null +++ b/mysql-test/t/partition_innodb-master.opt @@ -0,0 +1 @@ +--loose-innodb-large-prefix=OFF diff --git a/mysql-test/t/partition_innodb.test b/mysql-test/t/partition_innodb.test index d7f683aa9e9..62a9173b526 100644 --- a/mysql-test/t/partition_innodb.test +++ b/mysql-test/t/partition_innodb.test @@ -106,7 +106,6 @@ INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5); BEGIN; SELECT COUNT(*) FROM t1; ---echo # con1 --connect (con1,localhost,root,,) --echo # SEND a ALTER PARTITION which waits on the ongoing transaction. --send @@ -126,11 +125,11 @@ AND STATE = 'Waiting for table metadata lock'; SELECT COUNT(*) FROM t1; COMMIT; ---echo # con1, reaping ALTER. +--echo # reaping ALTER. --connection con1 --reap ---echo # Disconnecting con1 and switching to default. Cleaning up. +--echo # Cleaning up. --disconnect con1 --connection default @@ -170,7 +169,6 @@ SELECT * FROM t1 FOR UPDATE; UPDATE t1 SET name = 'Mattias' WHERE id = 7; SELECT * FROM t1 WHERE id = 7; --connect (con1, localhost, root,,) ---echo # Connection con1 SET lock_wait_timeout = 1; --echo # After the patch it will wait and fail on timeout. --error ER_LOCK_WAIT_TIMEOUT @@ -178,7 +176,6 @@ ALTER TABLE t1 DROP PARTITION p3; SHOW WARNINGS; --disconnect con1 --connection default ---echo # Connection default SELECT * FROM t1; --echo # No changes. COMMIT; @@ -609,7 +606,6 @@ START TRANSACTION; SELECT * FROM t1 FOR UPDATE; connect (con1, localhost, root,,); ---echo # Connection con1 --error ER_LOCK_WAIT_TIMEOUT ALTER TABLE t1 REORGANIZE PARTITION pMAX INTO (PARTITION p3 VALUES LESS THAN (3), @@ -626,7 +622,6 @@ SHOW WARNINGS; disconnect con1; connection default; ---echo # Connection default SELECT * FROM t1; COMMIT; DROP TABLE t1; @@ -871,10 +866,8 @@ CREATE TABLE t1 PARTITION BY HASH (a) PARTITIONS 3; START TRANSACTION WITH CONSISTENT SNAPSHOT; --connect (con1, localhost, root,,) - --echo # con1 ALTER TABLE t1 ADD INDEX idx1 (b); --connection default - --echo # con default --error ER_TABLE_DEF_CHANGED SELECT b FROM t1 WHERE b = 0; --error ER_TABLE_DEF_CHANGED @@ -889,11 +882,9 @@ CREATE TABLE t1 PRIMARY KEY (a)) ENGINE = InnoDB; START TRANSACTION WITH CONSISTENT SNAPSHOT; ---echo # con1 --connect (con1, localhost, root,,) ALTER TABLE t1 ADD INDEX idx1 (b); --connection default ---echo # con default --error ER_TABLE_DEF_CHANGED SELECT b FROM t1 WHERE b = 0; --error ER_TABLE_DEF_CHANGED diff --git a/mysql-test/t/partition_innodb_plugin.test b/mysql-test/t/partition_innodb_plugin.test index d25a4b95bf1..18ed0a27f96 100644 --- a/mysql-test/t/partition_innodb_plugin.test +++ b/mysql-test/t/partition_innodb_plugin.test @@ -3,6 +3,8 @@ let $MYSQLD_DATADIR= `SELECT @@datadir`; +call mtr.add_suppression("InnoDB: Table .* does not exist in the InnoDB internal data dictionary .*"); + --echo # --echo # Bug#11766879/Bug#60106: DIFF BETWEEN # OF INDEXES IN MYSQL VS INNODB, --echo # PARTITONING, ON INDEX CREATE @@ -34,14 +36,11 @@ call mtr.add_suppression("InnoDB: Error: table `test`.`t1` .* InnoDB internal"); --echo # --echo # Bug#55091: Server crashes on ADD PARTITION after a failed attempt --echo # -SET @old_innodb_file_format = @@global.innodb_file_format; SET @old_innodb_file_per_table = @@global.innodb_file_per_table; SET @old_innodb_strict_mode = @@global.innodb_strict_mode; -SET @@global.innodb_file_format = Barracuda, -@@global.innodb_file_per_table = ON, +SET @@global.innodb_file_per_table = ON, @@global.innodb_strict_mode = ON; ---echo # Connection con1 --connect(con1,localhost,root,,) CREATE TABLE t1 (id INT NOT NULL @@ -59,7 +58,6 @@ SET GLOBAL innodb_file_per_table = OFF; --disconnect con1 --connect(con2,localhost,root,,) ---echo # Connection con2 LOCK TABLE t1 WRITE; @@ -89,9 +87,7 @@ DROP TABLE t1; --disconnect con2 --connection default ---echo # Connection default SET @@global.innodb_strict_mode = @old_innodb_strict_mode; -SET @@global.innodb_file_format = @old_innodb_file_format; SET @@global.innodb_file_per_table = @old_innodb_file_per_table; # @@ -110,20 +106,16 @@ SUBPARTITION BY HASH (a) SUBPARTITION `sp3``\""e`)); INSERT INTO `t``\""e` VALUES (0), (2), (6), (10), (14), (18), (22); START TRANSACTION; ---echo # con1 connect(con1,localhost,root,,); SET NAMES utf8; START TRANSACTION; ---echo # default connection connection default; UPDATE `t``\""e` SET a = 16 WHERE a = 0; ---echo # con1 connection con1; UPDATE `t``\""e` SET a = 8 WHERE a = 22; let $id_1= `SELECT CONNECTION_ID()`; SEND; UPDATE `t``\""e` SET a = 12 WHERE a = 0; ---echo # default connection connection default; let $wait_condition= SELECT COUNT(*)=2 FROM INFORMATION_SCHEMA.INNODB_LOCKS; --source include/wait_condition.inc @@ -152,12 +144,9 @@ set sql_mode = 'ANSI_QUOTES'; --replace_regex /.*RECORD LOCKS space id [0-9]* page no [0-9]* n bits [0-9]* // / trx id .*// /.*index .* in // /trx table locks [0-9]* // /total table locks [0-9]* // SHOW ENGINE InnoDB STATUS; set @@sql_mode = @old_sql_mode; ---echo # con1 connection con1; REAP; ROLLBACK; disconnect con1; ---echo # default connection connection default; DROP TABLE `t``\""e`; -SET NAMES DEFAULT; diff --git a/mysql-test/t/partition_innodb_semi_consistent.test b/mysql-test/t/partition_innodb_semi_consistent.test index 7ab2527f0a5..7a1dfc36173 100644 --- a/mysql-test/t/partition_innodb_semi_consistent.test +++ b/mysql-test/t/partition_innodb_semi_consistent.test @@ -75,7 +75,6 @@ connect (con2,localhost,root,,); SET SESSION AUTOCOMMIT = 0; SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED; set binlog_format=mixed; ---echo # Switch to connection con1 connection con1; eval @@ -94,7 +93,6 @@ UPDATE t1 SET b = 12 WHERE a = 1; --disable_info SELECT * FROM t1; ---echo # Switch to connection con2 connection con2; --enable_info @@ -104,7 +102,6 @@ UPDATE t1 SET b = 21 WHERE a = 1; --disable_info ROLLBACK; ---echo # Switch to connection con1 connection con1; SELECT * FROM t1; ROLLBACK; @@ -140,12 +137,10 @@ UPDATE t1 SET b = CONCAT(b, '+con1') WHERE a = 1; --disable_info SELECT * FROM t1; ---echo # Switch to connection con2 connection con2; --send CALL p1; ---echo # Switch to connection con1 connection con1; SELECT * FROM t1; COMMIT; @@ -158,13 +153,11 @@ while ($bug31310) SELECT * FROM t1; ---echo # Switch to connection con2 connection con2; --reap SELECT * FROM t1; COMMIT; ---echo # Switch to connection con1 connection con1; --echo # 3. test for updated key column: @@ -180,12 +173,10 @@ UPDATE t1 SET a = 2, b = CONCAT(b, '+con1') WHERE a = 1; --disable_info SELECT * FROM t1; ---echo # Switch to connection con2 connection con2; --send CALL p1; ---echo # Switch to connection con1 connection con1; SELECT * FROM t1; COMMIT; @@ -198,7 +189,6 @@ while ($bug31310) SELECT * FROM t1; ---echo # Switch to connection con2 connection con2; reap; SELECT * FROM t1; diff --git a/mysql-test/t/partition_innodb_stmt.test b/mysql-test/t/partition_innodb_stmt.test index c6f30f41969..96a59cb9311 100644 --- a/mysql-test/t/partition_innodb_stmt.test +++ b/mysql-test/t/partition_innodb_stmt.test @@ -2,7 +2,6 @@ --source include/have_binlog_format_statement.inc --source include/have_innodb.inc ---echo # connection default SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; CREATE TABLE t1 @@ -28,14 +27,12 @@ SELECT * FROM t1; connect (con1, localhost, root,,); connection con1; ---echo #connection con1 SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; BEGIN; INSERT INTO t1 VALUES(7); COMMIT; connection default; ---echo # connection default COMMIT; FLUSH TABLES; @@ -47,7 +44,6 @@ SELECT * FROM t1; connection con1; ---echo # connection con1 SET TRANSACTION ISOLATION LEVEL READ COMMITTED; BEGIN; --error ER_BINLOG_STMT_MODE_AND_ROW_ENGINE diff --git a/mysql-test/t/partition_sync.test b/mysql-test/t/partition_sync.test index d5d60c176c5..fd704f35534 100644 --- a/mysql-test/t/partition_sync.test +++ b/mysql-test/t/partition_sync.test @@ -16,22 +16,18 @@ INSERT INTO t1 VALUES (0),(1); connect(con1,localhost,root); ---echo # Connection 2 connection con1; BEGIN; SELECT * FROM t1; ---echo # Connection 1 connection default; --error ER_DROP_PARTITION_NON_EXISTENT ALTER TABLE t1 DROP PARTITION p3; ---echo # Connection 2 connection con1; --echo # This failed with deadlock and should not do so. SELECT * FROM t1; ---echo # Connection 1 connection default; disconnect con1; DROP TABLE t1; @@ -53,34 +49,28 @@ INSERT INTO tbl_with_partitions VALUES (1); connect(con2,localhost,root); connect(con3,localhost,root); ---echo # Connection 3 connection con3; LOCK TABLE tbl_with_partitions READ; ---echo # Connection 1 --echo # Access table with disabled autocommit connection default; SET AUTOCOMMIT = 0; SELECT * FROM tbl_with_partitions; ---echo # Connection 2 --echo # Alter table, abort after prepare connection con2; set session debug_dbug="+d,abort_copy_table"; --error ER_LOCK_WAIT_TIMEOUT ALTER TABLE tbl_with_partitions ADD COLUMN f INT; ---echo # Connection 1 --echo # Try accessing the table after Alter aborted. --echo # This used to give ER_LOCK_DEADLOCK. connection default; SELECT * FROM tbl_with_partitions; ---echo # Connection 3 connection con3; UNLOCK TABLES; ---echo # Connection 1 --echo # Cleanup connection default; disconnect con2; diff --git a/mysql-test/t/plugin_auth_qa_1.test b/mysql-test/t/plugin_auth_qa_1.test index 55fef4254e1..b0b8ffb3544 100644 --- a/mysql-test/t/plugin_auth_qa_1.test +++ b/mysql-test/t/plugin_auth_qa_1.test @@ -99,22 +99,16 @@ CREATE USER plug_user IDENTIFIED WITH test_plugin_server AS 'plug_dest'; CREATE USER plug_dest IDENTIFIED BY 'plug_dest_passwd'; GRANT PROXY ON plug_dest TO plug_user; ---echo connect(plug_user,localhost,plug_user,plug_dest); connect(plug_user,localhost,plug_user,plug_dest); select USER(),CURRENT_USER(); ---echo connection default; connection default; ---echo disconnect plug_user; disconnect plug_user; RENAME USER plug_user TO new_user; ---echo connect(plug_user,localhost,new_user,plug_dest); connect(plug_user,localhost,new_user,plug_dest); select USER(),CURRENT_USER(); ---echo connection default; connection default; --sorted_result SELECT user,plugin,authentication_string FROM mysql.user WHERE user != 'root'; ---echo disconnect plug_user; disconnect plug_user; UPDATE mysql.user SET user='plug_user' WHERE user='new_user'; FLUSH PRIVILEGES; @@ -128,12 +122,9 @@ CREATE USER plug_user IDENTIFIED WITH test_plugin_server AS 'plug_dest'; CREATE USER plug_dest IDENTIFIED BY 'plug_dest_passwd'; GRANT PROXY ON plug_dest TO plug_user; ---echo connect(plug_user,localhost,plug_user,plug_dest); connect(plug_user,localhost,plug_user,plug_dest); select USER(),CURRENT_USER(); ---echo connection default; connection default; ---echo disconnect plug_user; disconnect plug_user; --sorted_result SELECT user,plugin,authentication_string FROM mysql.user WHERE user != 'root'; @@ -149,7 +140,6 @@ UPDATE mysql.user SET plugin='new_plugin_server' WHERE user='new_user'; FLUSH PRIVILEGES; --sorted_result SELECT user,plugin,authentication_string FROM mysql.user WHERE user != 'root'; ---echo connect(plug_user,localhost,new_user,new_dest); --disable_query_log --error ER_PLUGIN_IS_NOT_LOADED connect(plug_user,localhost,new_user,new_dest); @@ -160,12 +150,9 @@ FLUSH PRIVILEGES; GRANT PROXY ON new_dest TO new_user; --sorted_result SELECT user,plugin,authentication_string FROM mysql.user WHERE user != 'root'; ---echo connect(plug_user,localhost,new_user,new_dest); connect(plug_user,localhost,new_user,new_dest); select USER(),CURRENT_USER(); ---echo connection default; connection default; ---echo disconnect plug_user; disconnect plug_user; UPDATE mysql.user SET USER='plug_dest' WHERE user='new_dest'; FLUSH PRIVILEGES; @@ -173,12 +160,9 @@ CREATE USER new_dest IDENTIFIED BY 'new_dest_passwd'; --sorted_result SELECT user,plugin,authentication_string FROM mysql.user WHERE user != 'root'; GRANT ALL PRIVILEGES ON test.* TO new_user; ---echo connect(plug_user,localhost,new_dest,new_dest_passwd); connect(plug_user,localhost,new_dest,new_dest_passwd); select USER(),CURRENT_USER(); ---echo connection default; connection default; ---echo disconnect plug_user; disconnect plug_user; DROP USER new_user,new_dest,plug_dest; @@ -188,36 +172,26 @@ CREATE USER ''@'%%' IDENTIFIED WITH test_plugin_server AS 'proxied_user'; CREATE USER proxied_user IDENTIFIED BY 'proxied_user_passwd'; --sorted_result SELECT user,plugin,authentication_string FROM mysql.user WHERE user != 'root'; ---echo connect(proxy_con,localhost,proxied_user,proxied_user_passwd); connect(proxy_con,localhost,proxied_user,proxied_user_passwd); SELECT USER(),CURRENT_USER(); --echo ========== test 2.2.1 ====================================== SELECT @@proxy_user; ---echo connection default; connection default; ---echo disconnect proxy_con; disconnect proxy_con; ---echo connect(proxy_con,localhost,proxy_user,proxied_user); --disable_query_log --error ER_ACCESS_DENIED_ERROR : this should fail : no grant connect(proxy_con,localhost,proxy_user,proxied_user); --enable_query_log GRANT PROXY ON proxied_user TO ''@'%%'; ---echo connect(proxy_con,localhost,proxied_user,proxied_user_passwd); connect(proxy_con,localhost,proxied_user,proxied_user_passwd); SELECT USER(),CURRENT_USER(); ---echo connection default; connection default; ---echo disconnect proxy_con; disconnect proxy_con; ---echo connect(proxy_con,localhost,proxy_user,proxied_user); connect(proxy_con,localhost,proxy_user,proxied_user); SELECT USER(),CURRENT_USER(); --echo ========== test 2.2.1 ====================================== SELECT @@proxy_user; ---echo connection default; connection default; ---echo disconnect proxy_con; disconnect proxy_con; DROP USER ''@'%%',proxied_user; # @@ -226,34 +200,24 @@ GRANT ALL PRIVILEGES ON test_user_db.* TO ''@'%%' CREATE USER proxied_user IDENTIFIED BY 'proxied_user_passwd'; --sorted_result SELECT user,plugin,authentication_string FROM mysql.user WHERE user != 'root'; ---echo connect(proxy_con,localhost,proxied_user,proxied_user_passwd); connect(proxy_con,localhost,proxied_user,proxied_user_passwd); SELECT USER(),CURRENT_USER(); SELECT @@proxy_user; ---echo connection default; connection default; ---echo disconnect proxy_con; disconnect proxy_con; ---echo connect(proxy_con,localhost,proxy_user,proxied_user); --disable_query_log --error ER_ACCESS_DENIED_ERROR : this should fail : no grant connect(proxy_con,localhost,proxy_user,proxied_user); --enable_query_log GRANT PROXY ON proxied_user TO ''@'%%'; ---echo connect(proxy_con,localhost,proxied_user,proxied_user_passwd); connect(proxy_con,localhost,proxied_user,proxied_user_passwd); SELECT USER(),CURRENT_USER(); ---echo connection default; connection default; ---echo disconnect proxy_con; disconnect proxy_con; ---echo connect(proxy_con,localhost,proxy_user,proxied_user); connect(proxy_con,localhost,proxy_user,proxied_user); SELECT USER(),CURRENT_USER(); SELECT @@proxy_user; ---echo connection default; connection default; ---echo disconnect proxy_con; disconnect proxy_con; DROP USER ''@'%%',proxied_user; # @@ -270,47 +234,31 @@ GRANT PROXY ON proxied_user_4 TO ''@'%%'; GRANT PROXY ON proxied_user_5 TO ''@'%%'; --sorted_result SELECT user,plugin,authentication_string FROM mysql.user WHERE user != 'root'; ---echo connect(proxy_con_1,localhost,proxied_user_1,'proxied_user_1_pwd'); connect(proxy_con_1,localhost,proxied_user_1,'proxied_user_1_pwd'); ---echo connect(proxy_con_2,localhost,proxied_user_2,proxied_user_2_pwd); connect(proxy_con_2,localhost,proxied_user_2,proxied_user_2_pwd); ---echo connect(proxy_con_3,localhost,proxied_user_3,proxied_user_3_pwd); connect(proxy_con_3,localhost,proxied_user_3,proxied_user_3_pwd); ---echo connect(proxy_con_4,localhost,proxied_user_4,proxied_user_4_pwd); connect(proxy_con_4,localhost,proxied_user_4,proxied_user_4_pwd); ---echo connect(proxy_con_5,localhost,proxied_user_5,proxied_user_5_pwd); connect(proxy_con_5,localhost,proxied_user_5,proxied_user_5_pwd); ---echo connection proxy_con_1; connection proxy_con_1; SELECT USER(),CURRENT_USER(); SELECT @@proxy_user; ---echo connection proxy_con_2; connection proxy_con_2; SELECT USER(),CURRENT_USER(); SELECT @@proxy_user; ---echo connection proxy_con_3; connection proxy_con_3; SELECT USER(),CURRENT_USER(); SELECT @@proxy_user; ---echo connection proxy_con_4; connection proxy_con_4; SELECT USER(),CURRENT_USER(); SELECT @@proxy_user; ---echo connection proxy_con_5; connection proxy_con_5; SELECT USER(),CURRENT_USER(); SELECT @@proxy_user; ---echo connection default; connection default; ---echo disconnect proxy_con_1; disconnect proxy_con_1; ---echo disconnect proxy_con_2; disconnect proxy_con_2; ---echo disconnect proxy_con_3; disconnect proxy_con_3; ---echo disconnect proxy_con_4; disconnect proxy_con_4; ---echo disconnect proxy_con_5; disconnect proxy_con_5; DROP USER ''@'%%',proxied_user_1,proxied_user_2,proxied_user_3,proxied_user_4,proxied_user_5; diff --git a/mysql-test/t/progress_976225.test b/mysql-test/t/progress_976225.test index 32ded8b0ee0..885f9d69de2 100644 --- a/mysql-test/t/progress_976225.test +++ b/mysql-test/t/progress_976225.test @@ -1,4 +1,4 @@ ---source include/have_xtradb.inc +--source include/have_innodb.inc CREATE TABLE t1 (a INT) ENGINE=InnoDB; CREATE TABLE t2 (b INT) ENGINE=InnoDB; diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index 67f6f021434..00e0c4086bb 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -3697,5 +3697,593 @@ EXECUTE stmt; deallocate prepare stmt; drop table t1,t2,t3,t4; - --echo # End of 5.5 tests + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-10709 Expressions as parameters to Dynamic SQL +--echo # + +--echo # +--echo # Using a simple expressions as an EXECUTE parameter +--echo # + +PREPARE stmt FROM 'SELECT ? FROM DUAL'; +EXECUTE stmt USING 10; +DEALLOCATE PREPARE stmt; + +PREPARE stmt FROM 'SELECT ? FROM DUAL'; +EXECUTE stmt USING TO_BASE64('xxx'); +DEALLOCATE PREPARE stmt; + +PREPARE stmt FROM 'SELECT ?+? FROM DUAL'; +EXECUTE stmt USING 10, 10 + 10; +DEALLOCATE PREPARE stmt; + +PREPARE stmt FROM 'SELECT CONCAT(?,?) FROM DUAL'; +EXECUTE stmt USING 'xxx', CONCAT('yyy','zzz'); +DEALLOCATE PREPARE stmt; + +--echo # +--echo # Testing disallowed expressions in USING +--echo # + +PREPARE stmt FROM 'SELECT ? FROM DUAL'; +--error ER_PARSE_ERROR +EXECUTE stmt USING (SELECT 1); +DEALLOCATE PREPARE stmt; + +CREATE FUNCTION f1() RETURNS VARCHAR(10) RETURN 'test'; +PREPARE stmt FROM 'SELECT ? FROM DUAL'; +--error ER_SUBQUERIES_NOT_SUPPORTED +EXECUTE stmt USING f1(); +DEALLOCATE PREPARE stmt; +DROP FUNCTION f1; + +--echo # +--echo # Testing erroneous expressions in USING +--echo # + +PREPARE stmt FROM 'SELECT ?'; +--error ER_CANT_AGGREGATE_2COLLATIONS +EXECUTE stmt USING _latin1'a'=_latin2'a'; +DEALLOCATE PREPARE stmt; + +PREPARE stmt FROM 'SELECT ?'; +--error ER_OPERAND_COLUMNS +EXECUTE stmt USING ROW(1,2); +DEALLOCATE PREPARE stmt; + +--echo # +--echo # Creating tables from EXECUTE parameters +--echo # + +PREPARE stmt FROM 'CREATE TABLE t1 AS SELECT ? AS c1 FROM DUAL'; +EXECUTE stmt USING 10; +SHOW CREATE TABLE t1; +DROP TABLE t1; +EXECUTE stmt USING 10.123; +SHOW CREATE TABLE t1; +DROP TABLE t1; +EXECUTE stmt USING 10.123e0; +SHOW CREATE TABLE t1; +DROP TABLE t1; +EXECUTE stmt USING CURRENT_DATE; +SHOW CREATE TABLE t1; +DROP TABLE t1; +EXECUTE stmt USING CURRENT_TIMESTAMP; +SHOW CREATE TABLE t1; +DROP TABLE t1; +EXECUTE stmt USING CURRENT_TIMESTAMP(3); +SHOW CREATE TABLE t1; +DROP TABLE t1; +EXECUTE stmt USING CURRENT_TIMESTAMP(6); +SHOW CREATE TABLE t1; +DROP TABLE t1; +EXECUTE stmt USING CURRENT_TIME; +SHOW CREATE TABLE t1; +DROP TABLE t1; +EXECUTE stmt USING CURRENT_TIME(3); +SHOW CREATE TABLE t1; +DROP TABLE t1; +EXECUTE stmt USING CURRENT_TIME(6); +SHOW CREATE TABLE t1; +DROP TABLE t1; +DEALLOCATE PREPARE stmt; + + +--echo # +--echo # Using a user variable as an EXECUTE..USING out parameter +--echo # + +DELIMITER /; +CREATE PROCEDURE p1(OUT a INT) +BEGIN + SET a:= 10; +END; +/ +DELIMITER ;/ +SET @a=1; +CALL p1(@a); +SELECT @a; +SET @a=2; +PREPARE stmt FROM 'CALL p1(?)'; +EXECUTE stmt USING @a; +SELECT @a; +DROP PROCEDURE p1; + + +--echo # +--echo # Using an SP variable as an EXECUTE..USING out parameter +--echo # + +DELIMITER /; +CREATE PROCEDURE p1 (OUT a INT) +BEGIN + SET a=10; +END; +/ +CREATE PROCEDURE p2 (OUT a INT) +BEGIN + PREPARE stmt FROM 'CALL p1(?)'; + EXECUTE stmt USING a; +END; +/ +DELIMITER ;/ +SET @a= 1; +CALL p2(@a); +SELECT @a; +DROP PROCEDURE p2; +DROP PROCEDURE p1; + + +--echo # +--echo # Testing re-prepare on a table metadata update between PREPARE and EXECUTE +--echo # + +CREATE TABLE t1 (a INT); +DELIMITER /; +CREATE PROCEDURE p1(a INT) +BEGIN + INSERT INTO t1 VALUES (a); +END; +/ +DELIMITER ;/ +PREPARE stmt FROM 'CALL p1(?)'; +EXECUTE stmt USING 10; +SELECT * FROM t1; +CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET NEW.a=NEW.a+1; +EXECUTE stmt USING 20; +SELECT * FROM t1; +DEALLOCATE PREPARE stmt; +DROP PROCEDURE p1; +DROP TABLE t1; + +--echo # +--echo # End of MDEV-10709 Expressions as parameters to Dynamic SQL +--echo # + +--echo # +--echo # MDEV-10585 EXECUTE IMMEDIATE statement +--echo # + +EXECUTE IMMEDIATE 'SELECT 1 AS a'; +SET @a=10; +EXECUTE IMMEDIATE 'SELECT ? AS a' USING @a; +EXECUTE IMMEDIATE 'SELECT ? AS a' USING 20; + + +--echo # +--echo # Erroneous queries +--echo # + +--error ER_PARSE_ERROR +EXECUTE IMMEDIATE 'xxx'; + +--error ER_WRONG_ARGUMENTS +EXECUTE IMMEDIATE 'SELECT 1' USING @a; + +--error ER_WRONG_ARGUMENTS +EXECUTE IMMEDIATE 'SELECT ?'; + +--error ER_UNSUPPORTED_PS +EXECUTE IMMEDIATE 'EXECUTE IMMEDIATE "SELECT 1"'; + +--error ER_UNSUPPORTED_PS +EXECUTE IMMEDIATE 'PREPARE stmt FROM "SELECT 1"'; + +--error ER_UNSUPPORTED_PS +EXECUTE IMMEDIATE 'EXECUTE stmt'; + +--error ER_UNSUPPORTED_PS +EXECUTE IMMEDIATE 'DEALLOCATE PREPARE stmt'; + +--error ER_CANT_AGGREGATE_2COLLATIONS +EXECUTE IMMEDIATE 'SELECT ?' USING _latin1'a'=_latin2'a'; + +--error ER_OPERAND_COLUMNS +EXECUTE IMMEDIATE 'SELECT ?' USING ROW(1,2); + +--echo # +--echo # Testing disallowed expressions in USING +--echo # + +--error ER_PARSE_ERROR +EXECUTE IMMEDIATE 'SELECT ? FROM DUAL' USING (SELECT 1); + +CREATE FUNCTION f1() RETURNS VARCHAR(10) RETURN 'test'; +--error ER_SUBQUERIES_NOT_SUPPORTED +EXECUTE IMMEDIATE 'SELECT ? FROM DUAL' USING f1(); +DROP FUNCTION f1; + +--echo # +--echo # DDL +--echo # + +EXECUTE IMMEDIATE 'CREATE TABLE t1 (a INT)'; +EXECUTE IMMEDIATE 'SHOW CREATE TABLE t1'; +EXECUTE IMMEDIATE 'DROP TABLE t1'; + +SET @stmt= 'CREATE TABLE t1 (a INT)'; +EXECUTE IMMEDIATE @stmt; +SET @stmt= 'SHOW CREATE TABLE t1'; +EXECUTE IMMEDIATE @stmt; +SET @stmt= 'DROP TABLE t1'; +EXECUTE IMMEDIATE @stmt; + + +--echo # +--echo # DDL with parameters +--echo # + +SET @a= 10, @b= 10.1, @c= 10e0, @d='str'; +EXECUTE IMMEDIATE + 'CREATE TABLE t1 AS SELECT ? AS a,? AS b,? AS c,? AS d' + USING @a,@b,@c,@d; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +EXECUTE IMMEDIATE + 'CREATE TABLE t1 AS SELECT ? AS a,? AS b,? AS c,? AS d' + USING 10, 10.1, 10e0, 'str'; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +EXECUTE IMMEDIATE + 'CREATE TABLE t1 AS SELECT ? AS t1,? AS t2, ? AS d1,? AS dt1, ? AS dt2' + USING TIME'10:20:30', + TIME'10:20:30.123', + DATE'2001-01-01', + TIMESTAMP'2001-01-01 10:20:30', + TIMESTAMP'2001-01-01 10:20:30.123'; +SHOW CREATE TABLE t1; +DROP TABLE t1; + + +--echo # +--echo # Using a user variable as an EXECUTE IMMEDIATE..USING out parameter +--echo # + +DELIMITER /; +CREATE PROCEDURE p1(OUT a INT) +BEGIN + SET a:= 10; +END; +/ +DELIMITER ;/ +SET @a=1; +CALL p1(@a); +SELECT @a; +SET @a=2; +EXECUTE IMMEDIATE 'CALL p1(?)' USING @a; +SELECT @a; +DROP PROCEDURE p1; + + +--echo # +--echo # Using an SP variable as an EXECUTE IMMEDIATE..USING out parameter +--echo # + +DELIMITER /; +CREATE PROCEDURE p1 (OUT a INT) +BEGIN + SET a=10; +END; +/ +CREATE PROCEDURE p2 (OUT a INT) +BEGIN + EXECUTE IMMEDIATE 'CALL p1(?)' USING a; +END; +/ +DELIMITER ;/ +SET @a= 1; +CALL p2(@a); +SELECT @a; +DROP PROCEDURE p2; +DROP PROCEDURE p1; + + +--echo # +--echo # Changing user variables +--echo # + +SET @a=10; +EXECUTE IMMEDIATE 'SET @a=@a+1'; +SELECT @a; + + +--echo # +--echo # SET STATEMENT +--echo # + +SET @@max_sort_length=1024; +EXECUTE IMMEDIATE 'SET STATEMENT max_sort_length=1025 FOR SELECT @@max_sort_length'; +SELECT @@max_sort_length; +SET @@max_sort_length=DEFAULT; + + +--echo # +--echo # Similar to prepared EXECUTE, IMMEDIATE is not allowed in stored functions +--echo # +DELIMITER $$; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE FUNCTION f1() RETURNS INT +BEGIN + EXECUTE IMMEDIATE 'DO 1'; + RETURN 1; +END; +$$ +DELIMITER ;$$ + + +--echo # +--echo # Status variables +--echo # +CREATE FUNCTION get_status_var(name TEXT) RETURNS INT + RETURN (SELECT CAST(VARIABLE_VALUE AS INT) + FROM INFORMATION_SCHEMA.SESSION_STATUS + WHERE VARIABLE_NAME=name); +DELIMITER $$; +CREATE PROCEDURE test_status_var(name TEXT) +BEGIN + SET @cnt0=get_status_var(name); + EXECUTE IMMEDIATE 'DO 1'; + SET @cnt1=get_status_var(name); + SELECT @cnt1-@cnt0 AS increment; +END; +$$ +DELIMITER ;$$ +--echo # Note, EXECUTE IMMEDIATE does not increment COM_EXECUTE_SQL +--echo # It increments COM_EXECUTE_IMMEDIATE instead. +CALL test_status_var('COM_EXECUTE_SQL'); +CALL test_status_var('COM_EXECUTE_IMMEDIATE'); +CALL test_status_var('COM_STMT_PREPARE'); +CALL test_status_var('COM_STMT_EXECUTE'); +CALL test_status_var('COM_STMT_CLOSE'); + +DROP PROCEDURE test_status_var; +DROP FUNCTION get_status_var; + +--echo # +--echo # End of MDEV-10585 EXECUTE IMMEDIATE statement +--echo # + +--echo # +--echo # MDEV-10866 Extend PREPARE and EXECUTE IMMEDIATE to understand expressions +--echo # + +--echo # +--echo # Testing erroneous and diallowed prepare source +--echo # + +--error ER_CANT_AGGREGATE_2COLLATIONS +EXECUTE IMMEDIATE CONCAT(_latin1'SELECT 1 AS c FROM ', _latin2 'DUAL'); +--error ER_CANT_AGGREGATE_2COLLATIONS +PREPARE stmt FROM CONCAT(_latin1'SELECT 1 AS c FROM ', _latin2 'DUAL'); + +--error ER_PARSE_ERROR +EXECUTE IMMEDIATE (SELECT 'SELECT 1'); +--error ER_PARSE_ERROR +PREPARE stmt FROM (SELECT 'SELECT 1'); + +--error ER_BAD_FIELD_ERROR +EXECUTE IMMEDIATE a; +--error ER_BAD_FIELD_ERROR +PREPARE stmt FROM a; + +--error ER_PARSE_ERROR +EXECUTE IMMEDIATE NULL; +--error ER_PARSE_ERROR +PREPARE stmt FROM NULL; + +--error ER_PARSE_ERROR +EXECUTE IMMEDIATE CONCAT(NULL); +--error ER_PARSE_ERROR +PREPARE stmt FROM CONCAT(NULL); + +--error ER_PARSE_ERROR +EXECUTE IMMEDIATE ? USING 'SELECT 1'; + +--error ER_PARSE_ERROR +EXECUTE IMMEDIATE 10; + +--error ER_PARSE_ERROR +EXECUTE IMMEDIATE TIME'10:20:30'; + +--error ER_OPERAND_COLUMNS +EXECUTE IMMEDIATE ROW('SELECT 1','SELECT 2'); + +--error ER_INVALID_GROUP_FUNC_USE +EXECUTE IMMEDIATE MAX('SELECT 1 AS c'); + +--error ER_BAD_FIELD_ERROR +EXECUTE IMMEDIATE DEFAULT(a); + +--error ER_BAD_FIELD_ERROR +EXECUTE IMMEDIATE VALUES(a); + + +CREATE FUNCTION f1() RETURNS VARCHAR(64) RETURN 't1'; +--error ER_SUBQUERIES_NOT_SUPPORTED +EXECUTE IMMEDIATE f1(); +--error ER_SUBQUERIES_NOT_SUPPORTED +PREPARE stmt FROM f1(); +DROP FUNCTION f1; + +--error ER_SUBQUERIES_NOT_SUPPORTED +EXECUTE IMMEDIATE non_existent(); + + +--echo # +--echo # Testing literals in prepare source +--echo # +EXECUTE IMMEDIATE N'SELECT 1 AS c'; +EXECUTE IMMEDIATE _latin1'SELECT 1 AS c'; +EXECUTE IMMEDIATE 'SELECT ' '1' ' AS c' ' FROM ' 'DUAL'; +EXECUTE IMMEDIATE 0x53454C4543542031 /*This is 'SELECT 1'*/; + +--echo # +--echo # Testing user variables in prepare source +--echo # + +SET @stmt='SELECT 1 AS c FROM DUAL'; +EXECUTE IMMEDIATE @stmt; +PREPARE stmt FROM @stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; + +SET @table_name='DUAL'; +EXECUTE IMMEDIATE CONCAT('SELECT 1 AS a FROM ', @table_name); +PREPARE stmt FROM CONCAT('SELECT 1 AS a FROM ', @table_name); +EXECUTE stmt; +DEALLOCATE PREPARE stmt; + +--echo # +--echo # Testing SP parameters and variables in prepare source +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1(table_name VARCHAR(64)) +BEGIN + EXECUTE IMMEDIATE CONCAT('SELECT 1 AS c FROM ', table_name); +END; +$$ +DELIMITER ;$$ +CALL p1('DUAL'); +DROP PROCEDURE p1; + +DELIMITER $$; +CREATE PROCEDURE p1() +BEGIN + DECLARE table_name VARCHAR(64) DEFAULT 'DUAL'; + EXECUTE IMMEDIATE CONCAT('SELECT 1 AS c FROM ', table_name); +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP PROCEDURE p1; + + +--echo # +--echo # Testing complex expressions +--echo # +EXECUTE IMMEDIATE CONVERT('SELECT 1 AS c' USING utf8); +EXECUTE IMMEDIATE CAST('SELECT 1 AS c' AS CHAR); +EXECUTE IMMEDIATE _latin1'SELECT 1 AS c' COLLATE latin1_bin; +EXECUTE IMMEDIATE (((('SELECT 1 AS c')))); +EXECUTE IMMEDIATE CASE WHEN 1>2 THEN 'SELECT 1 AS c' ELSE 'SELECT 2 AS c' END; +EXECUTE IMMEDIATE TRIM('SELECT 1 AS c'); +EXECUTE IMMEDIATE SUBSTRING('SELECT 1 AS c' FROM 1); +EXECUTE IMMEDIATE COALESCE(NULL, 'SELECT 1 AS c'); + +--echo # +--echo # Testing SET STATEMENT and system variables +--echo # +CREATE TABLE t1 (a INT); +SET STATEMENT max_sort_length=1025 FOR EXECUTE IMMEDIATE CONCAT('INSERT INTO t1 VALUES (', @@max_sort_length, ')'); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # End of MDEV-10866 Extend PREPARE and EXECUTE IMMEDIATE to understand expressions +--echo # + +--echo # +--echo # End of 10.2 tests +--echo # + + +--echo # +--echo # MDEV-11360 Dynamic SQL: DEFAULT as a bind parameter +--echo # + +# Correct usage +CREATE TABLE t1 (a INT DEFAULT 10, b INT DEFAULT NULL); +EXECUTE IMMEDIATE 'INSERT INTO t1 VALUES (?,?)' USING DEFAULT, DEFAULT; +SELECT * FROM t1; +UPDATE t1 SET a=20, b=30; +SELECT * FROM t1; +EXECUTE IMMEDIATE 'UPDATE t1 SET a=?,b=?' USING DEFAULT, DEFAULT; +SELECT * FROM t1; +DROP TABLE t1; + +# Incorrect usage in a expression in INSERT..VALUES +CREATE TABLE t1 (a INT DEFAULT 10); +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'INSERT INTO t1 VALUES (?+1)' USING DEFAULT; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'INSERT INTO t1 VALUES (CONCAT(?,?))' USING DEFAULT, 'test'; +DROP TABLE t1; + +# Incorrect usage in UPDATE..SET +CREATE TABLE t1 (a INT DEFAULT 10); +INSERT INTO t1 VALUES (20); +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'UPDATE t1 SET a=?+1' USING DEFAULT; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'UPDATE t1 SET a=CONCAT(?,?)' USING DEFAULT, 'test'; +DROP TABLE t1; + +# Incorrect usage in not an UPDATE/INSERT query at all +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT CAST(? AS SIGNED)' USING DEFAULT; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT CAST(? AS DOUBLE)' USING DEFAULT; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT CAST(? AS CHAR)' USING DEFAULT; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT CAST(? AS DECIMAL(10,1))' USING DEFAULT; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT CAST(? AS TIME)' USING DEFAULT; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT CAST(? AS DATE)' USING DEFAULT; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT CAST(? AS DATETIME)' USING DEFAULT; + +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT ?+1' USING DEFAULT; +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT CONCAT(?,?)' USING DEFAULT,'test'; + +# Incorrect usage in the LIMIT clause +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT 1 LIMIT ?' USING DEFAULT; +CREATE TABLE t1 (a INT DEFAULT 10); +INSERT INTO t1 VALUES (1),(2),(3); +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'SELECT * FROM t1 LIMIT ?' USING DEFAULT; +DROP TABLE t1; + +--echo # The output of this query in 'Note' is a syntactically incorrect query. +--echo # But as it's never logged, it's ok. It should be human readable only. +EXECUTE IMMEDIATE 'EXPLAIN EXTENDED SELECT ?' USING DEFAULT; + +# This tests Item_param::eq() for DEFAULT as a bound value +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2),(3); +--error ER_INVALID_DEFAULT_PARAM +EXECUTE IMMEDIATE 'EXPLAIN EXTENDED SELECT * FROM t1 WHERE ?+a<=>?+a' USING DEFAULT,DEFAULT; +DROP TABLE t1; diff --git a/mysql-test/t/query_cache_28249.test b/mysql-test/t/query_cache_28249.test index b1be7c57343..a08371fe576 100644 --- a/mysql-test/t/query_cache_28249.test +++ b/mysql-test/t/query_cache_28249.test @@ -19,12 +19,10 @@ SET @query_cache_min_res_unit= @@global.query_cache_min_res_unit; SET @query_cache_size= @@global.query_cache_size; --echo # Bug#28249 Query Cache returns wrong result with concurrent insert/ certain lock ---echo # Establish connections user1,user2,user3 (user=root) connect (user1,localhost,root,,test,,); connect (user2,localhost,root,,test,,); connect (user3,localhost,root,,test,,); ---echo # Switch to connection user1 connection user1; SET GLOBAL query_cache_type=1; @@ -40,11 +38,9 @@ CREATE TABLE t1 (a INT); CREATE TABLE t2 (a INT); INSERT INTO t1 VALUES (1),(2),(3); ---echo # Switch to connection user2 connection user2; LOCK TABLE t2 WRITE; ---echo # Switch to connection user1 connection user1; --echo # "send" the next select, "reap" the result later. --echo # The select will be blocked by the write lock on the t1. @@ -53,7 +49,6 @@ SELECT *, (SELECT COUNT(*) FROM t2) FROM t1; send; eval $select_for_qc; ---echo # Switch to connection user3 connection user3; # Typical information_schema.processlist content after sufficient sleep time # ID USER COMMAND TIME STATE INFO @@ -73,11 +68,9 @@ WHERE state = 'Waiting for table metadata lock' AND info = '$select_for_qc'; INSERT INTO t1 VALUES (4); ---echo # Switch to connection user2 connection user2; UNLOCK TABLES; ---echo # Switch to connection user1 connection user1; # # Since the lock ordering rule in thr_multi_lock depends on @@ -95,13 +88,11 @@ connection user1; --reap --enable_result_log ---echo # Switch to connection user3 connection user3; --echo # The next select enforces that effects of "concurrent_inserts" like the --echo # record with a = 4 is missing in result sets can no more happen. SELECT 1 FROM t1 WHERE a = 4; ---echo # Switch to connection user1 connection user1; --echo # The next result set must contain 4 rows. # If not, we have a regression of Bug#28249 @@ -111,7 +102,6 @@ eval $select_for_qc; DROP TABLE t1,t2; ---echo # Switch to connection default + close connections user1,user2,user3 connection default; disconnect user1; disconnect user2; @@ -121,4 +111,3 @@ SET GLOBAL query_cache_type= @query_cache_type; SET GLOBAL query_cache_limit= @query_cache_limit; SET GLOBAL query_cache_min_res_unit= @query_cache_min_res_unit; SET GLOBAL query_cache_size= @query_cache_size; - diff --git a/mysql-test/t/query_cache_debug.test b/mysql-test/t/query_cache_debug.test index 5eba778cf9e..31f2d786efb 100644 --- a/mysql-test/t/query_cache_debug.test +++ b/mysql-test/t/query_cache_debug.test @@ -27,7 +27,7 @@ connection default; set debug_sync="now WAIT_FOR parked"; connection bug30887con2; ---echo On a second connection; clear the query cache. +--echo clear the query cache. show status like 'Qcache_queries_in_cache'; set global query_cache_size= 0; @@ -71,28 +71,23 @@ connect(con1,localhost,root,,test,,); connect(con2,localhost,root,,test,,); connection con1; ---echo # Switch to connection con1 SET DEBUG_SYNC = "wait_after_query_cache_invalidate SIGNAL parked WAIT_FOR go"; --echo # Send concurrent insert, will wait in the query cache table invalidate --send INSERT INTO t1 VALUES (4) connection default; ---echo # Switch to connection default --echo # Wait for concurrent insert to reach the debug point SET DEBUG_SYNC = "now WAIT_FOR parked"; connection con2; ---echo # Switch to connection con2 --echo # Send SELECT that shouldn't be cached SELECT * FROM t1; connection default; ---echo # Switch to connection default --echo # Notify the concurrent insert to proceed SET DEBUG_SYNC = "now SIGNAL go"; connection con1; ---echo # Switch to connection con1 --echo # Gather insert result --reap SHOW STATUS LIKE "Qcache_queries_in_cache"; @@ -100,7 +95,6 @@ SHOW STATUS LIKE "Qcache_queries_in_cache"; SELECT * FROM t1; SHOW STATUS LIKE "Qcache_queries_in_cache"; ---echo # Disconnect disconnect con1; disconnect con2; @@ -140,7 +134,6 @@ connect (thd3, localhost, root, ,test); connect (thd1, localhost, root, ,test); connection thd1; ---echo =================================== Connection thd1 --echo ** --echo ** Load Query Cache with a result set and one table. --echo ** @@ -162,13 +155,11 @@ SET DEBUG_SYNC="wait_in_query_cache_invalidate2 SIGNAL parked1_2 WAIT_FOR go1_2" --send DELETE FROM t1 WHERE a like '%a%'; connection default; ---echo =================================== Connection default --echo ** Assert that the expect process status is obtained. SET DEBUG_SYNC="now WAIT_FOR parked1_1"; -- echo ** connection thd2; ---echo =================================== Connection thd2 --echo ** On THD2: Insert a result into the cache. This attempt will be blocked --echo ** because of a debug hook placed just before the mutex lock after which --echo ** the first part of the result set is written. @@ -176,21 +167,18 @@ SET DEBUG_SYNC="wait_in_query_cache_insert SIGNAL parked2 WAIT_FOR go2 EXECUTE 1 --send SELECT SQL_CACHE * FROM t2 UNION SELECT * FROM t3 connection default; ---echo =================================== Connection default --echo ** Assert that the SELECT-stmt thread reaches the sync point. SET DEBUG_SYNC="now WAIT_FOR parked2"; --echo ** --echo ** connection thd3; ---echo =================================== Connection thd3 --echo ** On THD3: Insert another result into the cache and block on the same --echo ** debug hook. SET DEBUG_SYNC="wait_in_query_cache_insert SIGNAL parked3 WAIT_FOR go3 EXECUTE 1"; --send SELECT SQL_CACHE * FROM t4 UNION SELECT * FROM t5 connection default; ---echo =================================== Connection default --echo ** Assert that the SELECT-stmt thread reaches the sync point. SET DEBUG_SYNC="now WAIT_FOR parked3"; --echo ** @@ -225,20 +213,17 @@ SET DEBUG_SYNC="now SIGNAL go1_2"; --echo ************************************************************************* --echo ** No tables should be locked connection thd2; ---echo =================================== Connection thd2 reap; DELETE FROM t1; DELETE FROM t2; DELETE FROM t3; connection thd3; ---echo =================================== Connection thd3 reap; DELETE FROM t4; DELETE FROM t5; connection thd1; ---echo =================================== Connection thd1 reap; --echo ** Done. @@ -278,23 +263,19 @@ connect(con1,localhost,root,,test,,); connect(con2,localhost,root,,test,,); connection con1; ---echo # Switch to connection con1 SET DEBUG_SYNC = "wait_in_query_cache_invalidate2 SIGNAL parked WAIT_FOR go"; --echo # Send INSERT, will wait in the query cache table invalidation --send INSERT INTO t1 VALUES (4); connection default; ---echo # Switch to connection default --echo # Wait for insert to reach the debug point SET DEBUG_SYNC = "now WAIT_FOR parked"; connection con2; ---echo # Switch to connection con2 --echo # Send a query that should wait on the query cache lock --send RESET QUERY CACHE connection default; ---echo # Switch to connection default --echo # Wait for the state to be reflected in the processlist let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist @@ -304,12 +285,10 @@ let $wait_condition= SET DEBUG_SYNC="now SIGNAL go"; connection con1; ---echo # Reap con1 and disconnect --reap disconnect con1; connection con2; ---echo # Reap con2 and disconnect --reap disconnect con2; diff --git a/mysql-test/t/read_only.test b/mysql-test/t/read_only.test index 3e5d4fc8ce1..3e970fc6da7 100644 --- a/mysql-test/t/read_only.test +++ b/mysql-test/t/read_only.test @@ -18,15 +18,12 @@ DROP TABLE IF EXISTS t1,t2,t3; create user test@localhost; grant CREATE, SELECT, DROP on *.* to test@localhost; ---echo connect (con1,localhost,test,,test); connect (con1,localhost,test,,test); ---echo connection default; connection default; set global read_only=0; ---echo connection con1; connection con1; create table t1 (a int); @@ -36,7 +33,6 @@ insert into t1 values(1); create table t2 select * from t1; ---echo connection default; connection default; set global read_only=1; @@ -46,7 +42,6 @@ set global read_only=1; create table t3 (a int); drop table t3; ---echo connection con1; connection con1; select @@global.read_only; @@ -123,16 +118,13 @@ insert into t1 values(1); # - is an error in the same connection # - is ok in a different connection ---echo connection default; connection default; set global read_only=0; lock table t1 write; ---echo connection con1; connection con1; lock table t2 write; ---echo connection default; connection default; --error ER_LOCK_OR_ACTIVE_TRANSACTION set global read_only=1; @@ -142,7 +134,6 @@ unlock tables ; --echo send set global read_only=1; send set global read_only=1; ---echo connection con1; connection con1; select @@global.read_only; unlock tables ; @@ -150,7 +141,6 @@ let $wait_condition= SELECT @@global.read_only= 1; --source include/wait_condition.inc select @@global.read_only; ---echo connection default; connection default; --echo reap; reap; @@ -159,16 +149,13 @@ reap; # - is an error in the same connection # - is ok in a different connection ---echo connection default; connection default; set global read_only=0; lock table t1 read; ---echo connection con1; connection con1; lock table t2 read; ---echo connection default; connection default; --error ER_LOCK_OR_ACTIVE_TRANSACTION set global read_only=1; @@ -179,28 +166,23 @@ unlock tables ; set global read_only=1; select @@global.read_only; ---echo connection con1; connection con1; select @@global.read_only; unlock tables ; ---echo connection default; connection default; # pending transaction / READ_ONLY # - is an error in the same connection # - is ok in a different connection ---echo connection default; connection default; set global read_only=0; BEGIN; ---echo connection con1; connection con1; BEGIN; ---echo connection default; connection default; --error ER_LOCK_OR_ACTIVE_TRANSACTION set global read_only=1; @@ -208,7 +190,6 @@ ROLLBACK; set global read_only=1; ---echo connection con1; connection con1; select @@global.read_only; ROLLBACK; @@ -217,26 +198,21 @@ ROLLBACK; # - in the same SUPER connection # - in another SUPER connection ---echo connection default; connection default; set global read_only=0; flush tables with read lock; set global read_only=1; unlock tables; ---echo connect (root2,localhost,root,,test); connect (root2,localhost,root,,test); ---echo connection default; connection default; set global read_only=0; flush tables with read lock; ---echo connection root2; connection root2; set global read_only=1; ---echo connection default; connection default; select @@global.read_only; unlock tables; @@ -256,7 +232,6 @@ drop temporary table if exists ttt; # # Cleanup # ---echo connection default; connection default; set global read_only=0; disconnect con1; @@ -283,18 +258,14 @@ grant all on mysqltest_db2.* to `mysqltest_u1`@`%`; create database mysqltest_db1; grant all on mysqltest_db1.* to `mysqltest_u1`@`%`; flush privileges; ---echo connect (con_bug27440,127.0.0.1,mysqltest_u1,,test,MASTER_MYPORT,); connect (con_bug27440,127.0.0.1,mysqltest_u1,,test,$MASTER_MYPORT,); ---echo connection con_bug27440; connection con_bug27440; --error ER_OPTION_PREVENTS_STATEMENT create database mysqltest_db2; show databases like '%mysqltest_db2%'; --error ER_OPTION_PREVENTS_STATEMENT drop database mysqltest_db1; ---echo disconnect con_bug27440; disconnect con_bug27440; ---echo connection default; connection default; delete from mysql.user where User like 'mysqltest_%'; delete from mysql.db where User like 'mysqltest_%'; diff --git a/mysql-test/t/read_only_innodb.test b/mysql-test/t/read_only_innodb.test index f404ba17579..9ba3ccaca07 100644 --- a/mysql-test/t/read_only_innodb.test +++ b/mysql-test/t/read_only_innodb.test @@ -84,19 +84,15 @@ COMMIT; connection default; UNLOCK TABLES; ---echo connection con1; connection con1; lock table t1 read; ---echo connection default; connection default; set global read_only=1; ---echo connection con1; connection con1; unlock tables; ---echo connection default; connection default; SET GLOBAL read_only=0; @@ -127,7 +123,6 @@ GRANT CREATE TEMPORARY TABLES, DROP, INSERT, DELETE, UPDATE, SELECT, LOCK TABLES ON db1.* TO bug33669@localhost; SET GLOBAL READ_ONLY = ON; connect(con1,localhost,bug33669,,db1); ---echo # Connection con1 (user bug33669): --echo --echo # Create, insert and drop temporary table: diff --git a/mysql-test/t/reopen_temp_table.test b/mysql-test/t/reopen_temp_table.test new file mode 100644 index 00000000000..2aa6caa1655 --- /dev/null +++ b/mysql-test/t/reopen_temp_table.test @@ -0,0 +1,184 @@ +--source include/have_innodb.inc + +--echo # +--echo # MDEV-5535: Cannot reopen temporary table +--echo # + +--disable_warnings +DROP DATABASE IF EXISTS temp_db; +--enable_warnings + +CREATE DATABASE temp_db; +USE temp_db; + +--echo # +--echo # Reopen temporary table +--echo # + +CREATE TEMPORARY TABLE t1(i int)ENGINE=INNODB; +INSERT INTO t1 VALUES(1), (2); +SELECT * FROM t1 a, t1 b; +DROP TABLE t1; + +--echo # +--echo # CREATE & Stored routines +--echo # + +DELIMITER |; +CREATE FUNCTION f1() RETURNS INT +BEGIN + DROP TEMPORARY TABLE t1; + RETURN 1; +END| +DELIMITER ;| +--error ER_BAD_TABLE_ERROR +CREATE TEMPORARY TABLE t1 AS SELECT f1(); +DROP FUNCTION f1; + +DELIMITER |; +CREATE FUNCTION f2() RETURNS INT +BEGIN + CREATE TEMPORARY TABLE t2(i INT); + INSERT INTO t2 VALUES(1), (2); + RETURN 1; +END| +DELIMITER ;| +--error ER_TABLE_EXISTS_ERROR +CREATE TEMPORARY TABLE t2 AS SELECT f2(); +SELECT * FROM t2; +DROP TABLE t2; +DROP FUNCTION f2; + +CREATE TEMPORARY TABLE t3 AS SELECT 1 AS a; +DELIMITER |; +CREATE PROCEDURE p1() +BEGIN + DROP TEMPORARY TABLE t3; +end| +CREATE FUNCTION f3() RETURNS INT +BEGIN + CALL p1(); + RETURN 1; +END| +DELIMITER ;| +PREPARE STMT FROM "SELECT f3() AS my_Column, a FROM t3"; +--error ER_CANT_REOPEN_TABLE +EXECUTE STMT; +DROP TABLE t3; +DROP FUNCTION f3; +DROP PROCEDURE p1; + +CREATE TEMPORARY TABLE t4 (i INT); +INSERT INTO t4 VALUES(1), (2); +DELIMITER |; +CREATE FUNCTION f4() RETURNS INT +BEGIN + DROP TEMPORARY TABLE t4; + RETURN 1; +END| +DELIMITER ;| +--error ER_CANT_REOPEN_TABLE +SELECT f4() FROM t4; +SELECT * FROM t4; +DROP TABLE t4; +DROP FUNCTION f4; + +CREATE TEMPORARY TABLE t5 AS SELECT 1 AS a; +DELIMITER |; +CREATE PROCEDURE p2() +BEGIN + DROP TEMPORARY TABLE t5; +END| +CREATE FUNCTION f5() RETURNS INT +BEGIN + CALL p2(); + RETURN 1; +END| +DELIMITER ;| +--error ER_CANT_REOPEN_TABLE +SELECT f5() AS my_column, a FROM t5; +DROP TABLE t5; +DROP FUNCTION f5; +DROP PROCEDURE p2; + +--echo # +--echo # CTAS +--echo # + +CREATE TABLE t1(i INT); +INSERT INTO t1 VALUES(1), (2); +CREATE TEMPORARY TABLE t1 + SELECT temp_1.i a, temp_2.i b FROM t1 AS temp_1, t1 AS temp_2; +SELECT * FROM t1; +DROP TABLE t1; +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # HANDLER +--echo # + +CREATE TABLE t1 (a INT, KEY a(a)); +INSERT INTO t1 (a) VALUES (1), (2), (3), (4), (5); +CREATE TABLE t2 (a INT, KEY a (a)) SELECT * FROM t1; +CREATE TEMPORARY TABLE t3 (a INT, KEY a (a)) SELECT * FROM t2; +HANDLER t3 OPEN; +SELECT * FROM t1; +LOCK TABLE t1 READ; +--error ER_LOCK_OR_ACTIVE_TRANSACTION +HANDLER t3 OPEN; +UNLOCK TABLES; +--error ER_NONUNIQ_TABLE +HANDLER t3 OPEN; +HANDLER t3 READ NEXT; +HANDLER t3 OPEN AS t3_1; +HANDLER t3_1 READ NEXT; +HANDLER t3_1 READ NEXT; +HANDLER t3 CLOSE; +HANDLER t3_1 CLOSE; +DROP TEMPORARY TABLE t3; +DROP TABLE t1, t2; + +--echo # +--echo # INSERT-SELECT +--echo # + +CREATE TEMPORARY TABLE t4 (a INT) ENGINE=MYISAM; +INSERT INTO t4 VALUES(1), (2); +INSERT INTO t4 SELECT * FROM t4; +SELECT COUNT(*) FROM t4; +DROP TABLE t4; + +CREATE TABLE t5 (a INT) ENGINE=INNODB; +CREATE TEMPORARY TABLE t6 (a INT) ENGINE=INNODB; +INSERT INTO t5 VALUES(1), (2); +INSERT INTO t6 SELECT * FROM t5; +INSERT INTO t6 SELECT * FROM t6; +INSERT INTO t5 SELECT * FROM t6; +SELECT COUNT(*)=6 FROM t5; +SELECT COUNT(*)=4 FROM t6; +DROP TABLE t5, t6; + +--echo # +--echo # MDEV-10216: Assertion `strcmp(share->unique_file_name,filename) || +--echo # share->last_version' failed in myisam/mi_open.c:67: test_if_reopen +--echo # +CREATE TEMPORARY TABLE t7 (i INT) ENGINE=MYISAM; +INSERT INTO t7 VALUES(1); +ALTER TABLE t7 RENAME TO t; +SELECT * FROM t a, t b; +DROP TABLE t; + +CREATE TEMPORARY TABLE t7 (i INT) ENGINE=ARIA; +INSERT INTO t7 VALUES(1); +ALTER TABLE t7 RENAME TO t; +SELECT * FROM t a, t b; +DROP TABLE t; + +CREATE TEMPORARY TABLE t8 (i INT) ENGINE=ARIA; +ALTER TABLE t8 rename to t; +SELECT (SELECT 1 FROM t a1, t a2 ) AS f1, ( SELECT 2 FROM t a3 ) AS f2 FROM DUAL; +DROP TABLE t; + +--echo # Cleanup +DROP DATABASE temp_db; diff --git a/mysql-test/t/row-checksum-master.opt b/mysql-test/t/row-checksum-master.opt new file mode 100644 index 00000000000..990e4941ae9 --- /dev/null +++ b/mysql-test/t/row-checksum-master.opt @@ -0,0 +1 @@ +--loose-innodb-strict-mode=0 diff --git a/mysql-test/t/row-checksum-old-master.opt b/mysql-test/t/row-checksum-old-master.opt index 8e7b7f9e36f..40027795fff 100644 --- a/mysql-test/t/row-checksum-old-master.opt +++ b/mysql-test/t/row-checksum-old-master.opt @@ -1 +1,2 @@ --old +--loose-innodb-strict-mode=0 diff --git a/mysql-test/t/row-checksum.opt b/mysql-test/t/row-checksum.opt new file mode 100644 index 00000000000..977b569a781 --- /dev/null +++ b/mysql-test/t/row-checksum.opt @@ -0,0 +1 @@ +--loose-innodb-strict-mode=off diff --git a/mysql-test/t/rowid_order_innodb.test b/mysql-test/t/rowid_order_innodb.test index 1053b8bd7c2..152eb28d388 100644 --- a/mysql-test/t/rowid_order_innodb.test +++ b/mysql-test/t/rowid_order_innodb.test @@ -8,7 +8,7 @@ # main code t/rowid_order_innodb.test -> include/rowid_order.inc # ---source include/have_xtradb.inc +--source include/have_innodb.inc let $engine_type= InnoDB; --source include/rowid_order.inc diff --git a/mysql-test/t/schema.test b/mysql-test/t/schema.test index 6af7ee20b02..8f9047e2e3f 100644 --- a/mysql-test/t/schema.test +++ b/mysql-test/t/schema.test @@ -27,7 +27,6 @@ DROP SCHEMA IF EXISTS schema1; connect(con2, localhost, root); ---echo # Connection default connection default; CREATE SCHEMA schema1; @@ -36,11 +35,9 @@ CREATE TABLE schema1.t1 (a INT); SET autocommit= FALSE; INSERT INTO schema1.t1 VALUES (1); ---echo # Connection 2 connection con2; --send DROP SCHEMA schema1 ---echo # Connection default connection default; let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist WHERE state= 'Waiting for table metadata lock' @@ -52,11 +49,9 @@ let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist ALTER SCHEMA schema1 DEFAULT CHARACTER SET utf8; SET autocommit= TRUE; ---echo # Connection 2 connection con2; --reap ---echo # Connection default connection default; disconnect con2; @@ -71,17 +66,14 @@ DROP SCHEMA IF EXISTS schema1; connect (con2, localhost, root); ---echo # Connection default connection default; CREATE SCHEMA schema1; CREATE TABLE schema1.t1 (id INT); LOCK TABLE schema1.t1 WRITE; ---echo # Connection con2 connection con2; --send DROP SCHEMA schema1 ---echo # Connection default connection default; let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state='Waiting for schema metadata lock' and info='DROP SCHEMA schema1'; @@ -95,11 +87,9 @@ CREATE SCHEMA IF NOT EXISTS schema1; --echo # UNLOCK TABLES so DROP SCHEMA can continue. UNLOCK TABLES; ---echo # Connection con2 connection con2; --reap ---echo # Connection default connection default; disconnect con2; @@ -112,22 +102,18 @@ CREATE DATABASE db1; CREATE TABLE db1.t1 (a INT); INSERT INTO db1.t1 VALUES (1), (2); ---echo # Connection con1 connect (con1, localhost, root); HANDLER db1.t1 OPEN; ---echo # Connection default connection default; --echo # Sending: --send DROP DATABASE db1 ---echo # Connection con2 connect (con2, localhost, root); let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state='Waiting for table metadata lock' AND info='DROP DATABASE db1'; --source include/wait_condition.inc ---echo # Connection con1 connection con1; # All these statements before resulted in deadlock. CREATE DATABASE db2; @@ -135,7 +121,6 @@ ALTER DATABASE db2 DEFAULT CHARACTER SET utf8; DROP DATABASE db2; HANDLER t1 CLOSE; ---echo # Connection default connection default; --echo # Reaping: DROP DATABASE db1 --reap @@ -156,20 +141,17 @@ DROP DATABASE IF EXISTS db2; connect (con2, localhost, root); connect (con3, localhost, root); ---echo # Connection default connection default; CREATE DATABASE db1; CREATE TABLE db1.t1 (id INT); START TRANSACTION; INSERT INTO db1.t1 VALUES (1); ---echo # Connection 2 connection con2; --echo # DROP DATABASE should block due to the active transaction --echo # Sending: --send DROP DATABASE db1 ---echo # Connection 3 connection con3; let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state='Waiting for table metadata lock' and info='DROP DATABASE db1'; @@ -179,17 +161,14 @@ CREATE DATABASE db2; ALTER DATABASE db2 DEFAULT CHARACTER SET utf8; DROP DATABASE db2; ---echo # Connection default connection default; --echo # End the transaction so DROP DATABASE db1 can continue COMMIT; ---echo # Connection 2 connection con2; --echo # Reaping: DROP DATABASE db1 --reap ---echo # Connection default; connection default; disconnect con2; disconnect con3; diff --git a/mysql-test/t/show_check.test b/mysql-test/t/show_check.test index d9aed952fce..13ca9a528c6 100644 --- a/mysql-test/t/show_check.test +++ b/mysql-test/t/show_check.test @@ -774,6 +774,7 @@ SHOW COLUMNS FROM t1; --echo ---------------------------------------------------------------- +--replace_column 6 # SHOW TRIGGERS LIKE 't1'; --echo ---------------------------------------------------------------- @@ -799,6 +800,14 @@ SELECT FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_name = 't1_bi'; +# Metadata is different for the field "CREATED" with and without --ps +# So test it separately. + +--disable_ps_protocol +--replace_column 1 # +SELECT CREATED FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_name='t1_bi'; +--enable_ps_protocol + --echo ---------------------------------------------------------------- SHOW CREATE VIEW v1; @@ -1092,32 +1101,53 @@ CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a = 1; # Test. +--replace_column 7 # SHOW CREATE TRIGGER t1_bi; CREATE PROCEDURE p1() SHOW CREATE TRIGGER t1_bi; +--replace_column 7 # CALL p1(); +--replace_column 7 # CALL p1(); +--replace_column 7 # CALL p1(); +--replace_column 7 # CALL p1(); +--replace_column 7 # CALL p1(); +--replace_column 7 # CALL p1(); +--replace_column 7 # CALL p1(); +--replace_column 7 # CALL p1(); +--replace_column 7 # CALL p1(); +--replace_column 7 # CALL p1(); PREPARE stmt1 FROM 'SHOW CREATE TRIGGER t1_bi'; +--replace_column 7 # EXECUTE stmt1; +--replace_column 7 # EXECUTE stmt1; +--replace_column 7 # EXECUTE stmt1; +--replace_column 7 # EXECUTE stmt1; +--replace_column 7 # EXECUTE stmt1; +--replace_column 7 # EXECUTE stmt1; +--replace_column 7 # EXECUTE stmt1; +--replace_column 7 # EXECUTE stmt1; +--replace_column 7 # EXECUTE stmt1; +--replace_column 7 # EXECUTE stmt1; # Cleanup. @@ -1178,6 +1208,7 @@ SHOW CREATE PROCEDURE p1; SHOW CREATE FUNCTION f1; +--replace_column 7 # SHOW CREATE TRIGGER t1_bi; SHOW CREATE EVENT ev1; @@ -1232,7 +1263,6 @@ connection default; CREATE TABLE t1 (i INT PRIMARY KEY); LOCK TABLE t1 WRITE; ---echo # Switching to connection 'con1'. connection con1; --echo # This statement used to be blocked. SHOW CREATE TABLE t1; @@ -1240,7 +1270,6 @@ SHOW CREATE TABLE t1; disconnect con1; --source include/wait_until_disconnected.inc ---echo # Switching to connection 'default'. connection default; UNLOCK TABLES; DROP TABLE t1; @@ -1257,22 +1286,18 @@ DROP TABLE IF EXISTS t1; CREATE TABLE t1(a INT); ---echo # Connection con1 connect (con1,localhost,root); LOCK TABLE t1 WRITE; ---echo # Connection default connection default; START TRANSACTION; SHOW CREATE TABLE t1; ---echo # Connection con1 connection con1; # Used to block ALTER TABLE t1 CHARACTER SET = utf8; UNLOCK TABLES; ---echo # Connection default connection default; COMMIT; disconnect con1; @@ -1292,27 +1317,24 @@ CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW SET new.a = 1; --echo # Test 1: SHOW CREATE TRIGGER with WRITE locked table. ---echo # Connection con1 connect (con1, localhost, root); LOCK TABLE t1 WRITE; ---echo # Connection default connection default; # Should not block. +--replace_column 7 # SHOW CREATE TRIGGER t1_bi; ---echo # Connection con1 connection con1; UNLOCK TABLES; --echo # Test 2: ALTER TABLE with SHOW CREATE TRIGGER in transaction ---echo # Connection default connection default; START TRANSACTION; +--replace_column 7 # SHOW CREATE TRIGGER t1_bi; ---echo # Connection con1 connection con1; # Should not block. ALTER TABLE t1 CHARACTER SET = utf8; @@ -1320,7 +1342,6 @@ ALTER TABLE t1 CHARACTER SET = utf8; disconnect con1; --source include/wait_until_disconnected.inc ---echo # Connection default connection default; COMMIT; DROP TRIGGER t1_bi; diff --git a/mysql-test/t/show_create_user.test b/mysql-test/t/show_create_user.test new file mode 100644 index 00000000000..a10c8aeeda6 --- /dev/null +++ b/mysql-test/t/show_create_user.test @@ -0,0 +1,34 @@ +--source include/not_embedded.inc + +create user foo; +show create user foo; + +create user foo@test; +show create user foo@test; + +create user foo2@test identified by 'password'; +show create user foo2@test; + +alter user foo2@test identified with 'someplugin' as 'somepassword'; +show create user foo2@test; + +create user foo3@test require SSL; +show create user foo3@test; + +create user foo4@test require cipher 'text' issuer 'foo_issuer' subject 'foo_subject'; +show create user foo4@test; + +create user foo5@test require SSL + with MAX_QUERIES_PER_HOUR 10 + MAX_UPDATES_PER_HOUR 20 + MAX_CONNECTIONS_PER_HOUR 30 + MAX_USER_CONNECTIONS 40 + MAX_STATEMENT_TIME 0.5; +show create user foo5@test; + +drop user foo5@test; +drop user foo4@test; +drop user foo3@test; +drop user foo2@test; +drop user foo@test; +drop user foo; diff --git a/mysql-test/t/show_explain_ps.test b/mysql-test/t/show_explain_ps.test index 4ad1e4304de..b43cd559e09 100644 --- a/mysql-test/t/show_explain_ps.test +++ b/mysql-test/t/show_explain_ps.test @@ -6,6 +6,11 @@ # Like all other perfschema tests, we don't work on embedded server: --source include/not_embedded.inc +# There is a query below that selects from P_S tables. +# Remove possible history that could confuse it +truncate table performance_schema.events_statements_history_long; +truncate table performance_schema.events_stages_history_long; + --disable_warnings drop table if exists t0, t1; --enable_warnings @@ -45,7 +50,11 @@ reap; set debug_dbug=''; select event_name -from performance_schema.events_waits_history_long -where event_name='wait/synch/cond/sql/show_explain'; - +from +performance_schema.events_stages_history_long +where + event_name like '%show explain' and + thread_id in(select thread_id + from performance_schema.events_statements_history_long + where EVENT_NAME='statement/sql/show_explain'); drop table t0; diff --git a/mysql-test/t/show_grants_with_plugin-7985.test b/mysql-test/t/show_grants_with_plugin-7985.test index 9c05cb2e06d..84f71c72667 100644 --- a/mysql-test/t/show_grants_with_plugin-7985.test +++ b/mysql-test/t/show_grants_with_plugin-7985.test @@ -1,5 +1,4 @@ --source include/not_embedded.inc ---enable_connect_log call mtr.add_suppression("password and an authentication plugin"); --echo # diff --git a/mysql-test/t/shutdown.test b/mysql-test/t/shutdown.test index ac7f06b116d..7080f9a1a71 100644 --- a/mysql-test/t/shutdown.test +++ b/mysql-test/t/shutdown.test @@ -30,3 +30,10 @@ drop procedure try_shutdown; drop user user1@localhost; +--echo # +--echo # MDEV-8491 - On shutdown, report the user and the host executed that. +--echo # +--let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err +--let SEARCH_RANGE= -50000 +--let SEARCH_PATTERN=mysqld(\.exe)? \(root\[root\] @ localhost \[(::1)?\]\): Normal shutdown +--source include/search_pattern_in_file.inc diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test index a47fbe7a372..e30fc6e30d4 100644 --- a/mysql-test/t/sp-error.test +++ b/mysql-test/t/sp-error.test @@ -1093,7 +1093,7 @@ delimiter ;| # --error ER_SP_BADSTATEMENT CREATE PROCEDURE BUG_12490() HELP CONTENTS; ---error ER_SP_BADSTATEMENT +--error ER_PARSE_ERROR CREATE FUNCTION BUG_12490() RETURNS INT HELP CONTENTS; CREATE TABLE t_bug_12490(a int); --error ER_SP_BADSTATEMENT @@ -1785,17 +1785,17 @@ CREATE TABLE t1 (i INT); # We do not have to drop this procedure and view because they won't be # created. ---error ER_VIEW_SELECT_CLAUSE +--error ER_PARSE_ERROR CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO @a; ---error ER_VIEW_SELECT_CLAUSE +--error ER_PARSE_ERROR CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO DUMPFILE "file"; ---error ER_VIEW_SELECT_CLAUSE +--error ER_PARSE_ERROR CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO OUTFILE "file"; ---error ER_VIEW_SELECT_CLAUSE +--error ER_PARSE_ERROR CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT i FROM t1 PROCEDURE ANALYSE(); ---error ER_VIEW_SELECT_DERIVED -CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 FROM (SELECT 1) AS d1; +--error ER_PARSE_ERROR +CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 FROM (SELECT 1) AS d1 into @w; --error ER_VIEW_SELECT_VARIABLE CREATE PROCEDURE bug20953(i INT) CREATE VIEW v AS SELECT i; delimiter |; @@ -2231,7 +2231,7 @@ begin return 1; end| delimiter ;| ---error ER_CANT_REOPEN_TABLE +--error ER_BAD_TABLE_ERROR create temporary table t1 as select f1(); delimiter |; @@ -2241,7 +2241,7 @@ begin return 1; end| delimiter ;| ---error ER_CANT_REOPEN_TABLE +--error ER_BAD_TABLE_ERROR create temporary table t1 as select f2(); drop function f1; @@ -2259,7 +2259,7 @@ begin return 1; end| delimiter ;| ---error ER_CANT_REOPEN_TABLE +--error ER_BAD_TABLE_ERROR create temporary table t1 as select f2(); drop function f1; diff --git a/mysql-test/t/sp-lock.test b/mysql-test/t/sp-lock.test index a01c9e19908..83ea07d4bda 100644 --- a/mysql-test/t/sp-lock.test +++ b/mysql-test/t/sp-lock.test @@ -142,7 +142,6 @@ drop temporary table t1; --echo # connection, try to use the routine. --echo # That should block on the pending exclusive lock. --echo # ---echo # Establish helper connections. connect(con1, localhost, root,,); connect(con2, localhost, root,,); connect(con3, localhost, root,,); @@ -150,7 +149,6 @@ connect(con3, localhost, root,,); --echo # --echo # Test DROP PROCEDURE. --echo # ---echo # --> connection default connection default; create procedure p1() begin end; delimiter |; @@ -162,11 +160,9 @@ end| delimiter ;| begin; select f1(); ---echo # --> connection con1 connection con1; --echo # Sending 'drop procedure p1'... send drop procedure p1; ---echo # --> connection con2 connection con2; --echo # Waiting for 'drop procedure t1' to get blocked on MDL lock... let $wait_condition=select count(*)=1 from information_schema.processlist @@ -176,24 +172,19 @@ info='drop procedure p1'; --echo # Demonstrate that there is a pending exclusive lock. --echo # Sending 'select f1()'... send select f1(); ---echo # --> connection con3 connection con3; --echo # Waiting for 'select f1()' to get blocked by a pending MDL lock... let $wait_condition=select count(*)=1 from information_schema.processlist where state='Waiting for stored procedure metadata lock' and info='select f1()'; ---echo # --> connection default connection default; commit; ---echo # --> connection con1 connection con1; --echo # Reaping 'drop procedure p1'... reap; ---echo # --> connection con2 connection con2; --echo # Reaping 'select f1()' --error ER_SP_DOES_NOT_EXIST reap; ---echo # --> connection default connection default; --echo # @@ -202,11 +193,9 @@ connection default; create procedure p1() begin end; begin; select f1(); ---echo # --> connection con1 connection con1; --echo # Sending 'create procedure p1'... send create procedure p1() begin end; ---echo # --> connection con2 connection con2; --echo # Waiting for 'create procedure t1' to get blocked on MDL lock... let $wait_condition=select count(*)=1 from information_schema.processlist @@ -216,20 +205,16 @@ info='create procedure p1() begin end'; --echo # Demonstrate that there is a pending exclusive lock. --echo # Sending 'select f1()'... send select f1(); ---echo # --> connection con3 connection con3; --echo # Waiting for 'select f1()' to get blocked by a pending MDL lock... let $wait_condition=select count(*)=1 from information_schema.processlist where state='Waiting for stored procedure metadata lock' and info='select f1()'; ---echo # --> connection default connection default; commit; ---echo # --> connection con1 connection con1; --echo # Reaping 'create procedure p1'... --error ER_SP_ALREADY_EXISTS reap; ---echo # --> connection con2 connection con2; --echo # Reaping 'select f1()' reap; @@ -240,11 +225,9 @@ connection default; --echo # begin; select f1(); ---echo # --> connection con1 connection con1; --echo # Sending 'alter procedure p1'... send alter procedure p1 contains sql; ---echo # --> connection con2 connection con2; --echo # Waiting for 'alter procedure t1' to get blocked on MDL lock... let $wait_condition=select count(*)=1 from information_schema.processlist @@ -254,23 +237,18 @@ info='alter procedure p1 contains sql'; --echo # Demonstrate that there is a pending exclusive lock. --echo # Sending 'select f1()'... send select f1(); ---echo # --> connection con3 connection con3; --echo # Waiting for 'select f1()' to get blocked by a pending MDL lock... let $wait_condition=select count(*)=1 from information_schema.processlist where state='Waiting for stored procedure metadata lock' and info='select f1()'; ---echo # --> connection default connection default; commit; ---echo # --> connection con1 connection con1; --echo # Reaping 'alter procedure p1'... reap; ---echo # --> connection con2 connection con2; --echo # Reaping 'select f1()' reap; ---echo # --> connection default connection default; --echo # @@ -278,11 +256,9 @@ connection default; --echo # begin; select f1(); ---echo # --> connection con1 connection con1; --echo # Sending 'drop function f1'... send drop function f1; ---echo # --> connection con2 connection con2; --echo # Waiting for 'drop function f1' to get blocked on MDL lock... let $wait_condition=select count(*)=1 from information_schema.processlist @@ -292,24 +268,19 @@ info='drop function f1'; --echo # Demonstrate that there is a pending exclusive lock. --echo # Sending 'select f1()'... send select f1(); ---echo # --> connection con3 connection con3; --echo # Waiting for 'select f1()' to get blocked by a pending MDL lock... let $wait_condition=select count(*)=1 from information_schema.processlist where state='Waiting for stored function metadata lock' and info='select f1()'; ---echo # --> connection default connection default; commit; ---echo # --> connection con1 connection con1; --echo # Reaping 'drop function f1'... reap; ---echo # --> connection con2 connection con2; --echo # Reaping 'select f1()' --error ER_SP_DOES_NOT_EXIST reap; ---echo # --> connection default connection default; --echo # @@ -318,11 +289,9 @@ connection default; create function f1() returns int return 1; begin; select f1(); ---echo # --> connection con1 connection con1; --echo # Sending 'create function f1'... send create function f1() returns int return 2; ---echo # --> connection con2 connection con2; --echo # Waiting for 'create function f1' to get blocked on MDL lock... let $wait_condition=select count(*)=1 from information_schema.processlist @@ -332,24 +301,19 @@ info='create function f1() returns int return 2'; --echo # Demonstrate that there is a pending exclusive lock. --echo # Sending 'select f1()'... send select f1(); ---echo # --> connection con3 connection con3; --echo # Waiting for 'select f1()' to get blocked by a pending MDL lock... let $wait_condition=select count(*)=1 from information_schema.processlist where state='Waiting for stored function metadata lock' and info='select f1()'; ---echo # --> connection default connection default; commit; ---echo # --> connection con1 connection con1; --echo # Reaping 'create function f1'... --error ER_SP_ALREADY_EXISTS reap; ---echo # --> connection con2 connection con2; --echo # Reaping 'select f1()' reap; ---echo # --> connection default connection default; --echo # @@ -357,11 +321,9 @@ connection default; --echo # begin; select f1(); ---echo # --> connection con1 connection con1; --echo # Sending 'alter function f1'... send alter function f1 contains sql; ---echo # --> connection con2 connection con2; --echo # Waiting for 'alter function f1' to get blocked on MDL lock... let $wait_condition=select count(*)=1 from information_schema.processlist @@ -371,23 +333,18 @@ info='alter function f1 contains sql'; --echo # Demonstrate that there is a pending exclusive lock. --echo # Sending 'select f1()'... send select f1(); ---echo # --> connection con3 connection con3; --echo # Waiting for 'select f1()' to get blocked by a pending MDL lock... let $wait_condition=select count(*)=1 from information_schema.processlist where state='Waiting for stored function metadata lock' and info='select f1()'; ---echo # --> connection default connection default; commit; ---echo # --> connection con1 connection con1; --echo # Reaping 'alter function f1'... reap; ---echo # --> connection con2 connection con2; --echo # Reaping 'select f1()' reap; ---echo # --> connection default connection default; drop function f1; drop procedure p1; @@ -427,13 +384,11 @@ call p4(); prepare stmt from "call p4()"; execute stmt; execute stmt; ---echo # --> connection con1 connection con1; drop procedure p1; drop procedure p2; drop procedure p3; drop procedure p4; ---echo # --> connection default connection default; --echo # This is to verify there was no implicit commit. rollback to savepoint sv; @@ -456,25 +411,20 @@ create trigger t1_ai after insert on t1 for each row insert into t2 (a, b) values (new.a, f1()); begin; insert into t1 (a) values (1); ---echo # --> connection con1 connection con1; --echo # Sending 'drop function f1' send drop function f1; ---echo # --> connection con2 connection con2; --echo # Waiting for 'drop function f1' to get blocked on MDL lock... let $wait_condition=select count(*)=1 from information_schema.processlist where state='Waiting for stored function metadata lock' and info='drop function f1'; --source include/wait_condition.inc ---echo # --> connnection default connection default; commit; ---echo # --> connection con1 connection con1; --echo # Reaping 'drop function f1'... reap; ---echo # --> connection default connection default; --echo # --echo # A function is used from a view. @@ -483,25 +433,20 @@ create function f1() returns int return 1; create view v1 as select f1() as a; begin; select * from v1; ---echo # --> connection con1 connection con1; --echo # Sending 'drop function f1' send drop function f1; ---echo # --> connection con2 connection con2; --echo # Waiting for 'drop function f1' to get blocked on MDL lock... let $wait_condition=select count(*)=1 from information_schema.processlist where state='Waiting for stored function metadata lock' and info='drop function f1'; --source include/wait_condition.inc ---echo # --> connnection default connection default; commit; ---echo # --> connection con1 connection con1; --echo # Reaping 'drop function f1'... reap; ---echo # --> connection default connection default; --echo # --echo # A procedure is used from a function. @@ -517,25 +462,20 @@ delimiter ;| create procedure p1(out v_out int) set v_out=3; begin; select * from v1; ---echo # --> connection con1 connection con1; --echo # Sending 'drop procedure p1' send drop procedure p1; ---echo # --> connection con2 connection con2; --echo # Waiting for 'drop procedure p1' to get blocked on MDL lock... let $wait_condition=select count(*)=1 from information_schema.processlist where state='Waiting for stored procedure metadata lock' and info='drop procedure p1'; --source include/wait_condition.inc ---echo # --> connnection default connection default; commit; ---echo # --> connection con1 connection con1; --echo # Reaping 'drop procedure p1'... reap; ---echo # --> connection default connection default; --echo # @@ -549,25 +489,20 @@ create trigger t1_ai after insert on t1 for each row insert into t2 (a, b) values (new.a, (select max(a) from v1)); begin; insert into t1 (a) values (3); ---echo # --> connection con1 connection con1; --echo # Sending 'drop function f2' send drop function f2; ---echo # --> connection con2 connection con2; --echo # Waiting for 'drop function f2' to get blocked on MDL lock... let $wait_condition=select count(*)=1 from information_schema.processlist where state='Waiting for stored function metadata lock' and info='drop function f2'; --source include/wait_condition.inc ---echo # --> connnection default connection default; commit; ---echo # --> connection con1 connection con1; --echo # Reaping 'drop function f2'... reap; ---echo # --> connection default connection default; drop view v1; @@ -612,11 +547,9 @@ lock table v1 read; select * from v1; savepoint sv; select f2(); ---echo # --> connection con1 connection con1; --echo # Sending 'drop function f1'... send drop function f1; ---echo # --> connection con2 connection con2; --echo # Waiting for 'drop function f1' to get blocked on MDL lock... let $wait_condition=select count(*)=1 from information_schema.processlist @@ -625,7 +558,6 @@ info='drop function f1'; --source include/wait_condition.inc --echo # Sending 'drop function f2'... send drop function f2; ---echo # --> connection default connection default; --echo # Waiting for 'drop function f2' to get blocked on MDL lock... let $wait_condition=select count(*)=1 from information_schema.processlist @@ -633,18 +565,14 @@ where state='Waiting for stored function metadata lock' and info='drop function f2'; --source include/wait_condition.inc rollback to savepoint sv; ---echo # --> connection con2 connection con2; --echo # Reaping 'drop function f2'... reap; ---echo # --> connection default connection default; unlock tables; ---echo # --> connection con1 connection con1; --echo # Reaping 'drop function f1'... reap; ---echo # --> connection default connection default; --error ER_SP_DOES_NOT_EXIST drop function f1; @@ -683,18 +611,14 @@ begin execute stmt; end| delimiter ;| ---echo # --> connection con2 connection con2; prepare stmt from "select f2()"; ---echo # --> connection default connection default; begin; select f1(); ---echo # --> connection con1 connection con1; --echo # Sending 'alter function f1 ...'... send alter function f1 comment "comment"; ---echo # --> connection con2 connection con2; --echo # Waiting for 'alter function f1 ...' to get blocked on MDL lock... let $wait_condition=select count(*)=1 from information_schema.processlist @@ -711,16 +635,13 @@ info='select f1() into @var'; --source include/wait_condition.inc --echo # Let 'alter function f1 ...' go through... commit; ---echo # --> connection con1 connection con1; --echo # Reaping 'alter function f1 ...' reap; ---echo # --> connection con2 connection con2; --echo # Reaping 'call p1()'... reap; deallocate prepare stmt; ---echo # --> connection default connection default; drop function f1; drop function f2; @@ -739,11 +660,9 @@ drop procedure p1; create function f1() returns int return 1; begin; select f1(); ---echo # --> connection con1 connection con1; --echo # Sending 'alter function f1 ...'... send alter function f1 comment "comment"; ---echo # --> connection con2 connection con2; --echo # Waiting for 'alter function f1 ...' to get blocked on MDL lock... let $wait_condition=select count(*)=1 from information_schema.processlist @@ -781,15 +700,12 @@ info='select f1() into @var'; --source include/wait_condition.inc --echo # Let 'alter function f1 ...' go through... commit; ---echo # --> connection con1 connection con1; --echo # Reaping 'alter function f1 ...' reap; ---echo # --> connection con2 connection con2; --echo # Reaping 'call p1()'... reap; ---echo # --> connection default connection default; drop function f1; drop function f2; @@ -817,14 +733,11 @@ begin return res; end| delimiter ;| ---echo # --> connection con1 connection con1; select get_lock("30977", 0); ---echo # --> connection default connection default; --echo # Sending 'select f3()'... send select f3(); ---echo # --> connection con1 connection con1; --echo # Waiting for 'select f3()' to get blocked on the user level lock... let $wait_condition=select count(*)=1 from information_schema.processlist @@ -834,7 +747,6 @@ where state='User lock' and info='select f1() into @var'; create function f4() returns int return 4; drop function f4; select release_lock("30977"); ---echo # --> connection default connection default; --echo # Reaping 'select f3()'... --echo # Routine 'f2()' should exist and get executed successfully. @@ -880,19 +792,15 @@ drop procedure p1; drop function f1; set @@session.max_sp_recursion_depth=default; ---echo # --> connection con1 connection con1; disconnect con1; --source include/wait_until_disconnected.inc ---echo # --> connection con2 connection con2; disconnect con2; --source include/wait_until_disconnected.inc ---echo # --> connection con3 connection con3; disconnect con3; --source include/wait_until_disconnected.inc ---echo # --> connection default connection default; @@ -914,17 +822,14 @@ delimiter ;| connect (con2, localhost, root); connect (con3, localhost, root); ---echo # Connection default connection default; SELECT get_lock("test", 10); ---echo # Connection 2 connection con2; --echo # Will halt before executing SHOW CREATE PROCEDURE p1 --echo # Sending: --send CALL p1() ---echo # Connection 3 connection con3; let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state='User lock' and info='SELECT get_lock("test", 10)'; @@ -933,25 +838,20 @@ let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist DROP PROCEDURE p1; CREATE PROCEDURE p1() BEGIN END; ---echo # Connection default connection default; --echo # Resume CALL p1, now with new p1 SELECT release_lock("test"); ---echo # Connection 2 connection con2; --echo # Reaping: CALL p1() --reap ---echo # Connection 3 connection con3; disconnect con3; --source include/wait_until_disconnected.inc ---echo # Connection 2 connection con2; disconnect con2; --source include/wait_until_disconnected.inc ---echo # Connection default; connection default; DROP PROCEDURE p1; @@ -972,19 +872,16 @@ connect(con2, localhost, root); --echo # Test 1: Check that DROP DATABASE block if a function is used --echo # by an active transaction. ---echo # Connection default connection default; CREATE DATABASE db1; CREATE FUNCTION db1.f1() RETURNS INTEGER RETURN 1; START TRANSACTION; SELECT db1.f1(); ---echo # Connection con1 connection con1; --echo # Sending: --send DROP DATABASE db1 ---echo # Connection default connection default; --echo # Waiting for DROP DATABASE to be blocked by the lock on f1() let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist @@ -993,7 +890,6 @@ let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist --source include/wait_condition.inc COMMIT; ---echo # Connection con1 connection con1; --echo # Reaping: DROP DATABASE db1 --reap @@ -1001,7 +897,6 @@ connection con1; --echo # Test 2: Check that DROP DATABASE blocks if a procedure is --echo # used by an active transaction. ---echo # Connection default connection default; CREATE DATABASE db1; CREATE PROCEDURE db1.p1() BEGIN END; @@ -1015,12 +910,10 @@ delimiter ;| START TRANSACTION; SELECT f1(); ---echo # Connection con1 connection con1; --echo # Sending: --send DROP DATABASE db1 ---echo # Connection default connection default; --echo # Waiting for DROP DATABASE to be blocked by the lock on p1() let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist @@ -1029,7 +922,6 @@ let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist --source include/wait_condition.inc COMMIT; ---echo # Connection con1 connection con1; --echo # Reaping: DROP DATABASE db1 --reap @@ -1037,7 +929,6 @@ connection con1; --echo # Test 3: Check that DROP DATABASE is not selected as a victim if a --echo # deadlock is discovered with DML statements. ---echo # Connection default connection default; CREATE DATABASE db1; CREATE TABLE db1.t1 (a INT); @@ -1046,12 +937,10 @@ START TRANSACTION; # DROP DATABASE will lock tables (t1) before functions (f1) SELECT db1.f1(); ---echo # Connection con1 connection con1; --echo # Sending: --send DROP DATABASE db1 ---echo # Connection default connection default; --echo # Waiting for DROP DATABASE to be blocked by the lock on f1() let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist @@ -1062,14 +951,12 @@ let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist SELECT * FROM db1.t1; COMMIT; ---echo # Connection con1 connection con1; --echo # Reaping: DROP DATABASE db1 --reap --echo # Test 4: Check that active DROP DATABASE blocks stored routine DDL. ---echo # Connection default connection default; CREATE DATABASE db1; CREATE FUNCTION db1.f1() RETURNS INTEGER RETURN 1; @@ -1077,12 +964,10 @@ CREATE FUNCTION db1.f2() RETURNS INTEGER RETURN 2; START TRANSACTION; SELECT db1.f2(); ---echo # Connection con1 connection con1; --echo # Sending: --send DROP DATABASE db1 ---echo # Connection con2 connection con2; --echo # Waiting for DROP DATABASE to be blocked by the lock on f2() let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist @@ -1092,7 +977,6 @@ let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist --echo # Sending: --send ALTER FUNCTION db1.f1 COMMENT "test" ---echo # Connection default connection default; --echo # Waiting for ALTER FUNCTION to be blocked by the schema lock on db1 let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist @@ -1101,14 +985,12 @@ let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist --source include/wait_condition.inc COMMIT; ---echo # Connection con1 connection con1; --echo # Reaping: DROP DATABASE db1 --reap disconnect con1; --source include/wait_until_disconnected.inc ---echo # Connection con2 connection con2; --echo # Reaping: ALTER FUNCTION f1 COMMENT 'test' --error ER_SP_DOES_NOT_EXIST @@ -1116,7 +998,6 @@ connection con2; disconnect con2; --source include/wait_until_disconnected.inc ---echo # Connection default connection default; DROP FUNCTION f1; diff --git a/mysql-test/t/sp-security.test b/mysql-test/t/sp-security.test index a5df4859d6b..f719cbff11c 100644 --- a/mysql-test/t/sp-security.test +++ b/mysql-test/t/sp-security.test @@ -580,8 +580,6 @@ drop database db_bug14533; # Setup the environment. ---echo ---echo ---> connection: root --connection con1root --disable_warnings @@ -602,8 +600,6 @@ GRANT ALL PRIVILEGES ON mysqltest.* TO mysqltest_2@localhost; # test case (1). ---echo ---echo ---> connection: mysqltest_2_con --connection mysqltest_2_con USE mysqltest; @@ -614,8 +610,6 @@ CREATE FUNCTION wl2897_f1() RETURNS INT RETURN 1; # test case (2). ---echo ---echo ---> connection: mysqltest_1_con --connection mysqltest_1_con USE mysqltest; @@ -628,8 +622,6 @@ CREATE DEFINER=root@localhost FUNCTION wl2897_f2() RETURNS INT RETURN 2; # test case (3). ---echo ---echo ---> connection: mysqltest_2_con --connection mysqltest_2_con use mysqltest; @@ -640,8 +632,6 @@ CREATE DEFINER='a @ b @ c'@localhost FUNCTION wl2897_f3() RETURNS INT RETURN 3; # test case (4). ---echo ---echo ---> connection: con1root --connection con1root USE mysqltest; @@ -669,8 +659,6 @@ DROP DATABASE mysqltest; # Prepare environment. ---echo ---echo ---> connection: root --connection con1root --disable_warnings @@ -690,8 +678,6 @@ GRANT ALL PRIVILEGES ON mysqltest.* TO mysqltest_2@localhost; # Create a procedure/function under u1. ---echo ---echo ---> connection: mysqltest_1_con --connection mysqltest_1_con USE mysqltest; @@ -708,8 +694,6 @@ SELECT bug13198_f1(); # Check that u2 can call the procedure/function. ---echo ---echo ---> connection: mysqltest_2_con --connection mysqltest_2_con USE mysqltest; @@ -720,8 +704,6 @@ SELECT bug13198_f1(); # Drop user u1 (definer of the object); ---echo ---echo ---> connection: root --connection con1root --disconnect mysqltest_1_con @@ -730,8 +712,6 @@ DROP USER mysqltest_1@localhost; # Check that u2 can not call the procedure/function. ---echo ---echo ---> connection: mysqltest_2_con --connection mysqltest_2_con USE mysqltest; @@ -744,8 +724,6 @@ SELECT bug13198_f1(); # Cleanup. ---echo ---echo ---> connection: root --connection con1root --disconnect mysqltest_2_con @@ -767,8 +745,6 @@ user19857@localhost; SELECT Host,User,Password FROM mysql.user WHERE User='user19857'; --connect (mysqltest_2_con,localhost,user19857,meow,test) ---echo ---echo ---> connection: mysqltest_2_con --connection mysqltest_2_con USE test; @@ -790,8 +766,6 @@ SHOW CREATE PROCEDURE test.sp19857; DROP PROCEDURE IF EXISTS test.sp19857; ---echo ---echo ---> connection: root --connection con1root --disconnect mysqltest_2_con @@ -949,7 +923,6 @@ create database mysqltest_db; create user bug57061_user@localhost; create function mysqltest_db.f1() returns int return 0; create procedure mysqltest_db.p1() begin end; ---echo # Connect as user 'bug57061_user@localhost' connect (conn1, localhost, bug57061_user,,); --echo # Attempt to drop routine on which user doesn't have privileges --echo # should result in the same 'access denied' type of error whether @@ -962,7 +935,6 @@ drop procedure if exists mysqltest_db.p_does_not_exist; drop function if exists mysqltest_db.f1; --error ER_PROCACCESS_DENIED_ERROR drop procedure if exists mysqltest_db.p1; ---echo # Connection 'default'. connection default; disconnect conn1; drop user bug57061_user@localhost; @@ -983,23 +955,19 @@ CREATE PROCEDURE db1.p1() SELECT 1; CREATE USER user2@localhost IDENTIFIED BY ''; GRANT SELECT(db) ON mysql.proc TO user2@localhost; ---echo # Connection con2 as user2 connect (con2, localhost, user2); --echo # The statement below before disclosed info from body_utf8 column. --error ER_SP_DOES_NOT_EXIST SHOW CREATE PROCEDURE db1.p1; --echo # Check that SHOW works with SELECT grant on whole table ---echo # Connection default connection default; GRANT SELECT ON mysql.proc TO user2@localhost; ---echo # Connection con2 connection con2; --echo # This should work SHOW CREATE PROCEDURE db1.p1; ---echo # Connection default connection default; disconnect con2; DROP USER user2@localhost; @@ -1020,7 +988,6 @@ create procedure mysqltest_db.p1() begin end; --echo # Create user with no privileges on mysqltest_db database. create user bug12602983_user@localhost; ---echo # Connect as user 'bug12602983_user@localhost' connect (conn1, localhost, bug12602983_user,,); --echo # Attempt to execute routine on which user doesn't have privileges @@ -1041,7 +1008,6 @@ create view bug12602983_v1 as select mysqltest_db.f_does_not_exist(); --error ER_PROCACCESS_DENIED_ERROR create view bug12602983_v1 as select mysqltest_db.f1(); ---echo # Connection 'default'. connection default; disconnect conn1; drop user bug12602983_user@localhost; diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 3034f34d763..08f7fa5035b 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -1368,11 +1368,6 @@ select f10()| create table t4 as select 1 as id| select f10()| -# Practical cases which we don't handle well (yet) -# -# Function which does not work because of well-known and documented -# limitation of MySQL. We can't use the several instances of the -# same temporary table in statement. create function f11() returns int begin drop temporary table if exists t3; @@ -1380,9 +1375,7 @@ begin insert into t3 values (1), (2), (3); return (select count(*) from t3 as a, t3 as b); end| ---error ER_CANT_REOPEN_TABLE select f11()| ---error ER_CANT_REOPEN_TABLE select f11() from t1| # Test that using a single table instance at a time works create function f12_1() returns int @@ -1397,6 +1390,7 @@ create function f12_2() returns int drop temporary table t3| select f12_1()| +drop temporary table t3| select f12_1() from t1 limit 1| # Cleanup @@ -8278,7 +8272,6 @@ delimiter |; CREATE PROCEDURE p1 () BEGIN SELECT f1 FROM t3 AS A WHERE A.f1 IN ( SELECT f1 FROM t3 ) ; END| delimiter ;| ---error ER_CANT_REOPEN_TABLE CALL p1; CREATE VIEW t3 AS SELECT f1 FROM t2 A WHERE A.f1 IN ( SELECT f1 FROM t2 ); DROP TABLE t3; @@ -9518,3 +9511,40 @@ drop procedure sp1; --echo #End of 10.1 tests + +--echo # +--echo # MDEV-11081: CURSOR for query with GROUP BY +--echo # + +CREATE TABLE t1 (name VARCHAR(10), value INT); +INSERT INTO t1 VALUES ('b',1); +INSERT INTO t1 VALUES ('b',1); +INSERT INTO t1 VALUES ('c',1); +INSERT INTO t1 VALUES ('a',1); +INSERT INTO t1 VALUES ('a',1); +INSERT INTO t1 VALUES ('a',1); +DELIMITER |; +CREATE PROCEDURE p1 () +BEGIN + DECLARE done INT DEFAULT FALSE; + DECLARE v_name VARCHAR(10); + DECLARE v_total INT; + DECLARE c CURSOR FOR + SELECT name, SUM(value) AS total FROM t1 GROUP BY name; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + OPEN c; +read_loop: + LOOP + FETCH c INTO v_name, v_total; + IF done THEN + LEAVE read_loop; + END IF; + SELECT v_name, v_total; + END LOOP; + CLOSE c; +END; +| +DELIMITER ;| +CALL p1(); +DROP PROCEDURE p1; +DROP TABLE t1; diff --git a/mysql-test/t/sp_notembedded.test b/mysql-test/t/sp_notembedded.test index d7aaaa4340f..c620f415e22 100644 --- a/mysql-test/t/sp_notembedded.test +++ b/mysql-test/t/sp_notembedded.test @@ -331,7 +331,6 @@ FLUSH PRIVILEGES; --echo # SELECT GET_LOCK('Bug44521', 0); --connect (con1,localhost,root,,) ---echo ** Connection con1 delimiter $; CREATE PROCEDURE p() BEGIN @@ -342,7 +341,6 @@ END$ delimiter ;$ --send CALL p(); --connection default ---echo ** Default connection let $wait_condition= SELECT count(*) = 1 FROM information_schema.processlist WHERE state = "User lock" AND info = "SELECT GET_LOCK('Bug44521', 100)"; @@ -420,14 +418,12 @@ use `my.db`; CREATE FUNCTION f1(a int) RETURNS INT RETURN a; ---echo # Create new connection. connect (addcon, localhost, root,,); connection addcon; USE `my.db`; SELECT f1(1); SELECT `my.db`.f1(2); ---echo # Switching to default connection. connection default; disconnect addcon; DROP DATABASE `my.db`; diff --git a/mysql-test/t/sp_sync.test b/mysql-test/t/sp_sync.test index 589832bb570..a5682fc572f 100644 --- a/mysql-test/t/sp_sync.test +++ b/mysql-test/t/sp_sync.test @@ -24,7 +24,6 @@ SET DEBUG_SYNC= 'RESET'; connect (con2, localhost, root); ---echo # Connection default connection default; CREATE FUNCTION f1() RETURNS INT RETURN 1; --echo # Get f1 cached @@ -34,7 +33,6 @@ SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL before WAIT_FOR changed'; --echo # Sending: --send SELECT f1() ---echo # Connection 2 connection con2; SET DEBUG_SYNC= 'now WAIT_FOR before'; --echo # ... but before f1 is locked, change it. @@ -42,7 +40,6 @@ DROP FUNCTION f1; CREATE FUNCTION f1() RETURNS INT RETURN 2; SET DEBUG_SYNC= 'now SIGNAL changed'; ---echo # Connection default --echo # We should now get '2' and not '1'. connection default; --echo # Reaping: SELECT f1() @@ -66,25 +63,21 @@ DROP FUNCTION IF EXISTS f1; connect (con2, localhost, root); connect (con3, localhost, root); ---echo # Connection default connection default; CREATE FUNCTION f1() RETURNS INT RETURN 0; ---echo # Connection con2 connection con2; SET DEBUG_SYNC= 'after_wait_locked_pname SIGNAL locked WAIT_FOR issued'; --echo # con2 will now have an x-lock on f1 --echo # Sending: --send ALTER FUNCTION f1 COMMENT 'comment' ---echo # Connection default connection default; SET DEBUG_SYNC= 'now WAIT_FOR locked'; --disable_result_log --echo # This query will block due to the x-lock on f1 and back-off --send SHOW OPEN TABLES WHERE f1()=0 ---echo # Connection con3 connection con3; let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist WHERE state= 'Waiting for stored function metadata lock' @@ -93,7 +86,6 @@ let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist --echo # Check that the IS query is blocked before releasing the x-lock SET DEBUG_SYNC= 'now SIGNAL issued'; ---echo # Connection default connection default; --echo # Reaping: ALTER FUNCTION f1 COMMENT 'comment' --reap @@ -116,7 +108,6 @@ CREATE PROCEDURE p1() SELECT COUNT(f1(a)) FROM t1, t0; INSERT INTO t0 VALUES(1); INSERT INTO t1 VALUES(1), (2); ---echo # Connection 2 connect (con2, localhost, root); CALL p1(); @@ -128,7 +119,6 @@ SET DEBUG_SYNC= 'after_open_table_mdl_shared SIGNAL locked_t1 WAIT_FOR go_for_t0 --echo # Sending: --send CALL p1() ---echo # Connection default connection default; SET DEBUG_SYNC= 'now WAIT_FOR locked_t1'; --echo # Issue LOCK TABLES statement which will enter in MDL deadlock @@ -138,12 +128,10 @@ SET DEBUG_SYNC= 'mdl_acquire_lock_wait SIGNAL go_for_t0'; LOCK TABLES t0 WRITE, t1 WRITE; UNLOCK TABLES; ---echo # Connection 2 connection con2; --echo # Reaping: CALL p1() --reap; ---echo # Connection default connection default; disconnect con2; DROP PROCEDURE p1; diff --git a/mysql-test/t/ssl.test b/mysql-test/t/ssl.test index 9a08b273b6b..f2ac288db7a 100644 --- a/mysql-test/t/ssl.test +++ b/mysql-test/t/ssl.test @@ -33,8 +33,8 @@ connection default; disconnect ssl_con; create user mysqltest_1@localhost; -grant usage on mysqltest.* to mysqltest_1@localhost require cipher "EDH-RSA-DES-CBC3-SHA"; ---exec $MYSQL -umysqltest_1 --ssl-cipher=EDH-RSA-DES-CBC3-SHA -e "show status like 'ssl_cipher'" 2>&1 +grant usage on mysqltest.* to mysqltest_1@localhost require cipher "AES256-SHA"; +--exec $MYSQL -umysqltest_1 --ssl-cipher=AES256-SHA -e "show status like 'ssl_cipher'" 2>&1 drop user mysqltest_1@localhost; # Wait till all disconnects are completed diff --git a/mysql-test/t/ssl_7937.test b/mysql-test/t/ssl_7937.test index d593b9d936d..8e9d1901907 100644 --- a/mysql-test/t/ssl_7937.test +++ b/mysql-test/t/ssl_7937.test @@ -26,10 +26,10 @@ create procedure have_ssl() # we fake the test result for yassl let yassl=`select variable_value='Unknown' from information_schema.session_status where variable_name='Ssl_session_cache_mode'`; if (!$yassl) { + --replace_result "self signed certificate in certificate chain" "Failed to verify the server certificate" --exec $MYSQL --ssl --ssl-verify-server-cert -e "call test.have_ssl()" 2>&1 } if ($yassl) { --echo ERROR 2026 (HY000): SSL connection error: Failed to verify the server certificate } - drop procedure have_ssl; diff --git a/mysql-test/t/ssl_8k_key-master.opt b/mysql-test/t/ssl_8k_key-master.opt index 531c0abc9f1..856b33e95ee 100644 --- a/mysql-test/t/ssl_8k_key-master.opt +++ b/mysql-test/t/ssl_8k_key-master.opt @@ -1,3 +1,2 @@ --loose-ssl-key=$MYSQL_TEST_DIR/std_data/server8k-key.pem --loose-ssl-cert=$MYSQL_TEST_DIR/std_data/server8k-cert.pem ---loose-ssl-cipher=DHE-RSA-AES256-SHA diff --git a/mysql-test/t/ssl_8k_key.test b/mysql-test/t/ssl_8k_key.test index 27cffdce1f2..23267a3c611 100644 --- a/mysql-test/t/ssl_8k_key.test +++ b/mysql-test/t/ssl_8k_key.test @@ -5,7 +5,7 @@ # # Bug#29784 YaSSL assertion failure when reading 8k key. # ---exec $MYSQL --ssl --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem -e "SHOW STATUS LIKE 'ssl_Cipher'" 2>&1 +--exec $MYSQL --connect-timeout=180 --ssl --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem -e "SELECT (VARIABLE_VALUE <> '') as have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher'" 2>&1 ## This test file is for testing encrypted communication only, not other ## encryption routines that the SSL library happens to provide! diff --git a/mysql-test/t/ssl_ca.test b/mysql-test/t/ssl_ca.test index 8d830a75879..106da140130 100644 --- a/mysql-test/t/ssl_ca.test +++ b/mysql-test/t/ssl_ca.test @@ -6,27 +6,11 @@ --echo # --echo # try to connect with wrong '--ssl-ca' path : should fail + +--replace_regex /SSL connection error.*/SSL connection error: xxxx/ --error 1 ---exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/wrong-cacert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem test -e "SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher'" 2>&1 +--exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/wrong-cacert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem test -e "SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher';" 2>&1 +--echo --echo # try to connect with correct '--ssl-ca' path : should connect ---exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/cacert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem test -e "SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher'" - ---echo # ---echo # Bug#21920678: SSL-CA DOES NOT ACCEPT ~USER TILDE HOME DIRECTORY ---echo # PATH SUBSTITUTION ---echo # - ---let $mysql_test_dir_path= `SELECT IF(LENGTH('$HOME'), REPLACE('=$MYSQL_TEST_DIR', '=$HOME', '=~'), '=$MYSQL_TEST_DIR')` - ---echo # try to connect with '--ssl-ca' option using tilde home directoy ---echo # path substitution : should connect ---exec $MYSQL --ssl-ca$mysql_test_dir_path/std_data/cacert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem test -e "SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher'" - ---echo # try to connect with '--ssl-key' option using tilde home directoy ---echo # path substitution : should connect ---exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/cacert.pem --ssl-key$mysql_test_dir_path/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem test -e "SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher'" - ---echo # try to connect with '--ssl-cert' option using tilde home directoy ---echo # path substitution : should connect ---exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/cacert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert$mysql_test_dir_path/std_data/client-cert.pem test -e "SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher'" +--exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/cacert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem test -e "SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher';" diff --git a/mysql-test/t/ssl_connect.test b/mysql-test/t/ssl_connect.test index 05d6dc45c74..ce57e4f746d 100644 --- a/mysql-test/t/ssl_connect.test +++ b/mysql-test/t/ssl_connect.test @@ -4,12 +4,14 @@ # Repeat connect/disconnect let $i=100; +disable_connect_log; while ($i) { connect (test_con1,localhost,root,,,,,SSL); disconnect test_con1; dec $i; } +enable_connect_log; echo completed; ## This test file is for testing encrypted communication only, not other diff --git a/mysql-test/t/stat_tables_innodb_debug.test b/mysql-test/t/stat_tables_innodb_debug.test new file mode 100644 index 00000000000..f3652fc2312 --- /dev/null +++ b/mysql-test/t/stat_tables_innodb_debug.test @@ -0,0 +1,36 @@ +--source include/have_innodb.inc +--source include/have_sequence.inc +--source include/have_stat_tables.inc +--source include/have_debug_sync.inc +--source include/not_embedded.inc + +--echo # +--echo # MDEV-7901: re-implement analyze table for low impact +--echo # + +create table t1 (a int, b int, c int, key IDX1(a), key IDX2(a,b)) engine=innodb; +insert into t1 select seq/10, seq/2, seq from seq_0_to_9; + + +SET DEBUG_SYNC='statistics_collection_start1 SIGNAL analyzing WAIT_FOR written'; + +send analyze table t1 persistent for all; +connect (con1, localhost, root,,); +--connection con1 + +SET DEBUG_SYNC= 'now WAIT_FOR analyzing'; + +select count(*) from t1; +# insert will work even with MyISAM because it allow to append file +insert into t1 values (333,333,333); +# but update now hang for MyISAM bacause can't get lock (InnoDB/XtraDB works) +update t1 set a=1; + +SET DEBUG_SYNC= 'now SIGNAL written'; + +--connection default +--reap +select count(*) from t1; + +set debug_sync='RESET'; +drop table t1; diff --git a/mysql-test/t/stat_tables_myisam_debug.test b/mysql-test/t/stat_tables_myisam_debug.test new file mode 100644 index 00000000000..e8ef44325b9 --- /dev/null +++ b/mysql-test/t/stat_tables_myisam_debug.test @@ -0,0 +1,33 @@ +--source include/have_sequence.inc +--source include/have_stat_tables.inc +--source include/have_debug_sync.inc +--source include/not_embedded.inc + +--echo # +--echo # MDEV-7901: re-implement analyze table for low impact +--echo # + +create table t1 (a int, b int, c int, key IDX1(a), key IDX2(a,b)) engine=myisam; +insert into t1 select seq/10, seq/2, seq from seq_0_to_9; + + +SET DEBUG_SYNC='statistics_collection_start1 SIGNAL analyzing WAIT_FOR written'; + +send analyze table t1 persistent for all; +connect (con1, localhost, root,,); +--connection con1 + +SET DEBUG_SYNC= 'now WAIT_FOR analyzing'; + +select count(*) from t1; +# insert will work even with MyISAM because it allow to append file +insert into t1 values (333,333,333); + +SET DEBUG_SYNC= 'now SIGNAL written'; + +--connection default +--reap +select count(*) from t1; + +set debug_sync='RESET'; +drop table t1; diff --git a/mysql-test/t/statistics.test b/mysql-test/t/statistics.test index 3f08e2e133c..d75a01333cb 100644 --- a/mysql-test/t/statistics.test +++ b/mysql-test/t/statistics.test @@ -765,3 +765,21 @@ drop table t1, mysql.table_stats; rename table test.table_stats to mysql.table_stats; set use_stat_tables=@save_use_stat_tables; + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-10134 Add full support for DEFAULT +--echo # + +CREATE TABLE t1 (a BLOB, b TEXT DEFAULT DECODE_HISTOGRAM('SINGLE_PREC_HB',a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (0x0000000000000000000000000101010101010101010202020303030304040404050505050606070707080809090A0A0B0C0D0D0E0E0F10111213131415161718191B1C1E202224292A2E33373B4850575F6A76818C9AA7B9C4CFDADFE5EBF0F4F8FAFCFF); +SELECT b FROM t1; +DROP TABLE t1; + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/status.test b/mysql-test/t/status.test index 32b903c0265..7ab32241bcb 100644 --- a/mysql-test/t/status.test +++ b/mysql-test/t/status.test @@ -23,14 +23,13 @@ SET GLOBAL LOG_OUTPUT = 'FILE'; connect (con1,localhost,root,,); connect (con2,localhost,root,,); +connection default; flush status; show status like 'Table_lock%'; select * from information_schema.session_status where variable_name like 'Table_lock%'; -connection con1; ---echo # Switched to connection: con1 set sql_log_bin=0; set @old_general_log = @@global.general_log; set global general_log = 'OFF'; @@ -40,40 +39,46 @@ drop table if exists t1; create table t1(n int) engine=myisam; insert into t1 values(1); -# Execute dummy select in order to ensure that tables used in the -# previous statement are unlocked and closed. -select 1; +select get_lock('mysqltest_lock', 100); connection con2; ---echo # Switched to connection: con2 -lock tables t1 read; -unlock tables; -lock tables t1 read; +--echo # Sending: +--send update t1 set n = get_lock('mysqltest_lock', 100) connection con1; ---echo # Switched to connection: con1 +--echo # Wait for the first UPDATE to get blocked. +let $wait_condition= select count(*) from INFORMATION_SCHEMA.PROCESSLIST + where STATE = "User lock" and + INFO = "update t1 set n = get_lock('mysqltest_lock', 100)"; +--source include/wait_condition.inc + let $ID= `select connection_id()`; +--echo # Sending: --send update t1 set n = 3 -connection con2; ---echo # Switched to connection: con2 -# wait for the other query to start executing +connection default; +--echo # wait for the second UPDATE to get blocked let $wait_condition= select 1 from INFORMATION_SCHEMA.PROCESSLIST where ID = $ID and STATE = "Waiting for table level lock"; --source include/wait_condition.inc -unlock tables; +select release_lock('mysqltest_lock'); + +connection con2; +--echo # Reaping first UPDATE +--reap +select release_lock('mysqltest_lock'); connection con1; ---echo # Switched to connection: con1 +--echo # Reaping second UPDATE reap; show status like 'Table_locks_waited'; + +connection default; drop table t1; set global general_log = @old_general_log; disconnect con2; disconnect con1; -connection default; ---echo # Switched to connection: default # End of 4.1 tests diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index cfb5042299a..e02bf6aaecf 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -51,7 +51,7 @@ SELECT * FROM (SELECT 1 as id) b WHERE id IN (SELECT * FROM (SELECT 1 as id) c O SELECT * FROM (SELECT 1) a WHERE 1 IN (SELECT 1,1); SELECT 1 IN (SELECT 1); SELECT 1 FROM (SELECT 1 as a) b WHERE 1 IN (SELECT (SELECT a)); --- error ER_WRONG_USAGE +-- error ER_PARSE_ERROR select (SELECT 1 FROM (SELECT 1) a PROCEDURE ANALYSE(1)); -- error ER_PARSE_ERROR SELECT 1 FROM (SELECT 1) a PROCEDURE ANALYSE((SELECT 1)); @@ -569,7 +569,7 @@ drop table t1, t2; create table t1 (a float); -- error ER_NOT_SUPPORTED_YET select 10.5 IN (SELECT * from t1 LIMIT 1); --- error ER_WRONG_USAGE +-- error ER_PARSE_ERROR select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5); -- error ER_NOT_SUPPORTED_YET select 10.5 IN (SELECT * from t1 UNION SELECT 1.5 LIMIT 1); diff --git a/mysql-test/t/temp_table.test b/mysql-test/t/temp_table.test index 43621cf6ba1..fb44362b537 100644 --- a/mysql-test/t/temp_table.test +++ b/mysql-test/t/temp_table.test @@ -1,5 +1,6 @@ # mysqltest should be fixed --- source include/not_embedded.inc +--source include/not_embedded.inc +--source include/have_innodb.inc # # Test of temporary tables @@ -342,3 +343,255 @@ drop table t2; drop temporary table t3; show status like 'com_create%table'; show status like 'com_drop%table'; + +--echo # +--echo # Some more generic temporary table tests +--echo # added during MDEV-5535. +--echo # + +--disable_warnings +DROP DATABASE IF EXISTS temp_db; +--enable_warnings + +CREATE DATABASE temp_db; +USE temp_db; + +--echo # +--echo # SHOW TABLES do not list temporary tables. +--echo # + +CREATE TEMPORARY TABLE temp_t1(i INT) ENGINE=INNODB; +INSERT INTO temp_t1 VALUES(1); +SELECT * FROM temp_t1; +SHOW TABLES; +DROP TABLE temp_t1; + +--echo # +--echo # Create and drop a temporary table. +--echo # + +CREATE TEMPORARY TABLE temp_t1(i INT) ENGINE=INNODB; +INSERT INTO temp_t1 VALUES(1); +SELECT * FROM temp_t1; +DROP TABLE temp_t1; +--error ER_NO_SUCH_TABLE +SELECT * FROM temp_t1; + +--echo # +--echo # Create a temporary table and base table with same name and DROP TABLE. +--echo # + +CREATE TABLE t1(c1 VARCHAR(20)) ENGINE=INNODB; +INSERT INTO t1 VALUES("BASE TABLE"); +# Temporary table shadows the base table with the same name. +CREATE TEMPORARY TABLE t1(c1 VARCHAR(20)) ENGINE=INNODB; +INSERT INTO t1 VALUES("TEMPORARY TABLE"); +SELECT * FROM t1; +# Only temporary table should get dropped. +DROP TABLE t1; +SELECT * FROM t1; +DROP TABLE t1; +--error ER_NO_SUCH_TABLE +SELECT * FROM t1; + +--echo # +--echo # Create a temporary table and base table with same name and DROP TEMPORARY +--echo # TABLE. +--echo # + +CREATE TABLE t1(c1 VARCHAR(20)) ENGINE=INNODB; +INSERT INTO t1 VALUES("BASE TABLE"); +# Temporary table shadows the base table with the same name. +CREATE TEMPORARY TABLE t1(c1 VARCHAR(20)) ENGINE=INNODB; +INSERT INTO t1 VALUES("TEMPORARY TABLE"); +SELECT * FROM t1; +# Only temporary table should get dropped. +DROP TEMPORARY TABLE t1; +SELECT * FROM t1; +--error ER_BAD_TABLE_ERROR +DROP TEMPORARY TABLE t1; +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # Create a temporary table and drop its parent database. +--echo # + +USE temp_db; +CREATE TEMPORARY TABLE temp_t1(i INT) ENGINE=INNODB; +INSERT INTO temp_t1 VALUES (1); +# Drop database +DROP DATABASE temp_db; +CREATE DATABASE temp_db; +USE temp_db; +# Temporary tables are not physically tied to schemas +DROP TEMPORARY TABLE temp_t1; + +--echo # +--echo # Similar to above, but this time with a base table with same name. +--echo # + +USE temp_db; +CREATE TABLE t1(i INT)ENGINE=INNODB; +CREATE TEMPORARY TABLE t1(i INT) ENGINE=INNODB; +INSERT INTO t1 VALUES (1); +# Drop database +DROP DATABASE temp_db; +CREATE DATABASE temp_db; +USE temp_db; +# Temporary tables are not physically tied to schemas +DROP TEMPORARY TABLE t1; +--error ER_BAD_TABLE_ERROR +DROP TABLE t1; + +--echo # +--echo # Create a temporary table within a function. +--echo # + +USE temp_db; +delimiter |; +CREATE FUNCTION f1() RETURNS INT +BEGIN + DROP TEMPORARY TABLE IF EXISTS temp_t1; + CREATE TEMPORARY TABLE temp_t1(i INT) ENGINE=INNODB; + INSERT INTO `temp_t1` VALUES(1); + RETURN (SELECT COUNT(*) FROM temp_t1); +END| +delimiter ;| + +SELECT f1(); +SELECT * FROM temp_t1; + +DROP TABLE temp_t1; +CREATE TEMPORARY TABLE `temp_t1`(i INT) ENGINE=INNODB; +SELECT f1(); +SELECT * FROM temp_t1; +DROP FUNCTION f1; + +--echo # +--echo # Create and drop a temporary table within a function. +--echo # + +delimiter |; +--error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +CREATE FUNCTION f2() RETURNS INT +BEGIN + DROP TEMPORARY TABLE IF EXISTS temp_t1; + CREATE TEMPORARY TABLE temp_t1(i INT) ENGINE=INNODB; + INSERT INTO temp_t1 VALUES(1); + DROP TABLE temp_t1; + RETURN 0; +END| + +CREATE FUNCTION f2() RETURNS INT +BEGIN + DROP TEMPORARY TABLE IF EXISTS temp_t1; + CREATE TEMPORARY TABLE temp_t1(i INT) ENGINE=INNODB; + INSERT INTO temp_t1 VALUES(1); + DROP TEMPORARY TABLE temp_t1; + RETURN 0; +END| +delimiter ;| +SELECT f2(); +DROP FUNCTION f2; + +--echo # +--echo # Create a temporary table within a function and select it from another +--echo # function. +--echo # + +delimiter |; +CREATE FUNCTION f2() RETURNS INT +BEGIN + DROP TEMPORARY TABLE IF EXISTS temp_t1; + CREATE TEMPORARY TABLE temp_t1 (i INT) ENGINE=INNODB; + INSERT INTO temp_t1 VALUES (1); + RETURN f2_1(); +END| + +CREATE FUNCTION f2_1() RETURNS INT + RETURN (SELECT COUNT(*) FROM temp_t1)| +delimiter ;| + +SELECT f2(); +DROP TEMPORARY TABLE temp_t1; +DROP FUNCTION f2; + +--echo # +--echo # Create temporary table like base table. +--echo # + +CREATE TABLE t1(i INT) ENGINE=INNODB; +INSERT INTO t1 VALUES(1); +CREATE TEMPORARY TABLE temp_t1 LIKE t1; +SELECT * FROM temp_t1; +--error ER_NONUNIQ_TABLE +CREATE TEMPORARY TABLE t1 LIKE t1; +DROP TABLE temp_t1, t1; + +--echo # +--echo # Create temporary table as base table. +--echo # + +CREATE TABLE t1(i INT) ENGINE=INNODB; +INSERT INTO t1 VALUES(1); +CREATE TEMPORARY TABLE temp_t1 AS SELECT * FROM t1; +SELECT * FROM temp_t1; +DROP TABLE temp_t1, t1; + +--echo # +--echo # ALTER TABLE RENAME & ENABLE/DISABLE KEYS (shortcuts) +--echo # +CREATE TEMPORARY TABLE t1(i INT PRIMARY KEY) ENGINE=MYISAM; +INSERT INTO t1 VALUES(1); +SELECT COUNT(*)=1 FROM t1; + +ALTER TABLE t1 RENAME t2; +SELECT COUNT(*)=1 FROM t2; +ALTER TABLE t2 RENAME t1; + +ALTER TABLE t1 DISABLE KEYS; +ALTER TABLE t1 ENABLE KEYS; + +# LOCK TABLES is ignored for temporary tables. +LOCK TABLES t1 WRITE; +ALTER TABLE t1 RENAME t2; +SELECT COUNT(*)=1 FROM t2; +ALTER TABLE t2 RENAME t1; +ALTER TABLE t1 DISABLE KEYS; +ALTER TABLE t1 ENABLE KEYS; +UNLOCK TABLES; + +LOCK TABLES t1 READ; +ALTER TABLE t1 RENAME t2; +SELECT COUNT(*)=1 FROM t2; +ALTER TABLE t2 RENAME t1; +ALTER TABLE t1 DISABLE KEYS; +ALTER TABLE t1 ENABLE KEYS; +UNLOCK TABLES; + +FLUSH TABLES WITH READ LOCK; +ALTER TABLE t1 RENAME t2; +SELECT COUNT(*)=1 FROM t2; +ALTER TABLE t2 RENAME t1; +ALTER TABLE t1 DISABLE KEYS; +ALTER TABLE t1 ENABLE KEYS; +UNLOCK TABLES; + +ALTER TABLE t1 RENAME t2, LOCK SHARED; +ALTER TABLE t2 RENAME t1, LOCK EXCLUSIVE; + +DROP TABLE t1; + +--echo # +--echo # MDEV-10792: Assertion `thd->mdl_context.is_lock_owner +--echo # (MDL_key::TABLE, table->db, table->table_name, MDL_SHARED)' +--echo # failed in mysql_rm_table_no_locks +--echo # +CREATE TEMPORARY TABLE t1 (i INT); +--error ER_BAD_TABLE_ERROR +DROP TABLE nonexisting_table, t1; + +--echo # Cleanup +DROP DATABASE temp_db; + diff --git a/mysql-test/t/trans_read_only.test b/mysql-test/t/trans_read_only.test index f50fb7db376..38b2a833216 100644 --- a/mysql-test/t/trans_read_only.test +++ b/mysql-test/t/trans_read_only.test @@ -10,7 +10,7 @@ --echo # Check that the option was set by the .opt file. SELECT @@tx_read_only; ---echo # Also for new connections. Switching to con1 +--echo # Also for new connections. connect (con1, localhost, root); SELECT @@tx_read_only; SET SESSION TRANSACTION READ WRITE; @@ -18,7 +18,6 @@ SELECT @@tx_read_only; disconnect con1; --source include/wait_until_disconnected.inc ---echo # Connection default connection default; SELECT @@tx_read_only; diff --git a/mysql-test/t/trigger-compat.test b/mysql-test/t/trigger-compat.test index c627d1a6040..437df89b4b1 100644 --- a/mysql-test/t/trigger-compat.test +++ b/mysql-test/t/trigger-compat.test @@ -42,8 +42,6 @@ GRANT CREATE, TRIGGER ON mysqltest_db1.* TO mysqltest_dfn@localhost; --connect (wl2818_definer_con,localhost,mysqltest_dfn,,mysqltest_db1) --connection wl2818_definer_con ---echo ---echo ---> connection: wl2818_definer_con CREATE TABLE t1(num_value INT); CREATE TABLE t2(user_str TEXT); @@ -92,6 +90,7 @@ SELECT trigger_name, definer FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_n --echo +--replace_column 17 # SELECT * FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name; # Clean up @@ -183,6 +182,7 @@ FLUSH TABLE t2; CREATE TRIGGER tr16 AFTER UPDATE ON t1 FOR EACH ROW INSERT INTO t1 VALUES (1); --error ER_PARSE_ERROR CREATE TRIGGER tr22 BEFORE INSERT ON t2 FOR EACH ROW DELETE FROM non_existing_table; +--replace_column 6 # SHOW TRIGGERS; --error ER_PARSE_ERROR INSERT INTO t1 VALUES (1); @@ -195,6 +195,7 @@ UPDATE t1 SET a = 1 WHERE a = 1; SELECT * FROM t1; --error ER_PARSE_ERROR RENAME TABLE t1 TO t1_2; +--replace_column 6 # SHOW TRIGGERS; DROP TRIGGER tr11; @@ -203,6 +204,7 @@ DROP TRIGGER tr13; DROP TRIGGER tr14; DROP TRIGGER tr15; +--replace_column 6 # SHOW TRIGGERS; --echo # Make sure there is no trigger file left. @@ -259,7 +261,7 @@ INSERT INTO t2 VALUES (1), (2), (3); --echo # We write three trigger files. First trigger is syntaxically incorrect, next trigger is correct --echo # and last trigger is broken. ---echo # Next we try to execute SHOW CREATE TRGGIR command for broken trigger and then try to drop one. +--echo # Next we try to execute SHOW CREATE TRIGGER command for broken trigger and then try to drop one. --write_file $MYSQLD_DATADIR/test/tr11.TRN TYPE=TRIGGERNAME trigger_table=t1 diff --git a/mysql-test/t/trigger-trans.test b/mysql-test/t/trigger-trans.test index c17202055e1..17656c3516e 100644 --- a/mysql-test/t/trigger-trans.test +++ b/mysql-test/t/trigger-trans.test @@ -191,7 +191,6 @@ drop table t1,t2; --echo # AND TRIGGER HANDLERS TO BE IGNORED --echo #Code fixed in Bug#16041903 ---enable_connect_log CREATE TABLE t1 (id int unsigned PRIMARY KEY, val int DEFAULT 0) ENGINE=InnoDB; @@ -232,7 +231,5 @@ connection default; DROP TABLE t3, t2, t1; ---disable_connect_log - # Wait till we reached the initial number of concurrent sessions --source include/wait_until_count_sessions.inc diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test index a02dce34837..050bd5ea56e 100644 --- a/mysql-test/t/trigger.test +++ b/mysql-test/t/trigger.test @@ -324,8 +324,8 @@ create trigger trg before insert on t2 for each row set @a:=1; create trigger trg before insert on t1 for each row set @a:=1; --error ER_TRG_ALREADY_EXISTS create trigger trg after insert on t1 for each row set @a:=1; ---error ER_NOT_SUPPORTED_YET create trigger trg2 before insert on t1 for each row set @a:=1; +drop trigger trg2; --error ER_TRG_ALREADY_EXISTS create trigger trg before insert on t3 for each row set @a:=1; create trigger trg2 before insert on t3 for each row set @a:=1; @@ -2238,9 +2238,9 @@ create table t1 (i int, j int); create trigger t1_bi before insert on t1 for each row begin end; --error ER_TRG_ALREADY_EXISTS create trigger t1_bi before insert on t1 for each row begin end; ---error ER_NOT_SUPPORTED_YET create trigger t1_bi2 before insert on t1 for each row begin end; drop trigger t1_bi; +drop trigger t1_bi2; --error ER_TRG_DOES_NOT_EXIST drop trigger t1_bi; @@ -2392,6 +2392,7 @@ CREATE TABLE t2 (a INT); CREATE TRIGGER trg1 BEFORE INSERT ON t2 FOR EACH ROW INSERT/*!INTO*/t1 VALUES (1); --echo # Used to crash +--replace_column 6 # SHOW TRIGGERS IN db1; --error ER_PARSE_ERROR INSERT INTO t2 VALUES (1); @@ -2614,8 +2615,11 @@ DROP TABLE t1, t2; # # MDEV-4829 BEFORE INSERT triggers dont issue 1406 error +# Also check timestamp for trigger # +set time_zone="+00:00"; +SET TIMESTAMP=UNIX_TIMESTAMP('2001-01-01 10:20:30'); SET @@session.sql_mode = 'STRICT_ALL_TABLES,STRICT_TRANS_TABLES'; CREATE TABLE t1 (c CHAR(1) NOT NULL); DELIMITER |; @@ -2631,6 +2635,42 @@ DELIMITER ;| SET @@session.sql_mode = default; --error ER_DATA_TOO_LONG INSERT INTO t1 VALUES ('a'); +show create trigger t1_bi; DROP TRIGGER t1_bi; DROP TABLE t1; +SET TIMESTAMP=DEFAULT; +set time_zone= @@global.time_zone; + +# +# MDEV-10915 Count number of exceuted triggers +# + +create table t1 (i int); +create trigger tr1 after insert on t1 for each row set @a=@a+1; +create trigger tr2 after insert on t1 for each row set @a=@a+1; +create trigger tr3 after insert on t1 for each row set @a=@a+1; +flush status; +show status like 'Executed_triggers'; +set @a=0; +insert into t1 values (1); +show status like 'Executed_triggers'; +select @a; +drop table t1; + +# +# MDEV-10916 In trigger's CREATED time microseconds are misinterpreted +# +create table t1 (i int); +set time_zone="+0:00"; +SET TIMESTAMP=UNIX_TIMESTAMP('2016-01-01 10:10:10.33'); +select now(2); +create or replace trigger tr1 after insert on t1 for each row set @a=@a+1; +SET TIMESTAMP=UNIX_TIMESTAMP('2016-01-01 10:10:10.99'); +select now(2); +create or replace trigger tr2 after insert on t1 for each row set @a=@a+1; +select now(2); +select trigger_name, action_order, created from information_schema.triggers + where event_object_table = 't1' and trigger_schema='test'; +drop table t1; +set time_zone= @@global.time_zone; diff --git a/mysql-test/t/trigger_notembedded.test b/mysql-test/t/trigger_notembedded.test index f0c565be41f..a31594826e7 100644 --- a/mysql-test/t/trigger_notembedded.test +++ b/mysql-test/t/trigger_notembedded.test @@ -47,8 +47,6 @@ GRANT CREATE ON mysqltest_db1.* TO mysqltest_dfn@localhost; --connect (wl2818_definer_con,localhost,mysqltest_dfn,,mysqltest_db1) --connection wl2818_definer_con ---echo ---echo ---> connection: wl2818_definer_con CREATE TABLE t1(num_value INT); CREATE TABLE t2(user_str TEXT); @@ -56,8 +54,6 @@ CREATE TABLE t2(user_str TEXT); --disconnect wl2818_definer_con --connection default ---echo ---echo ---> connection: default GRANT INSERT, DROP ON mysqltest_db1.t1 TO mysqltest_dfn@localhost; GRANT INSERT, DROP ON mysqltest_db1.t2 TO mysqltest_dfn@localhost; @@ -67,15 +63,11 @@ GRANT INSERT, DROP ON mysqltest_db1.t2 TO mysqltest_dfn@localhost; # --connection default ---echo ---echo ---> connection: default GRANT SUPER ON *.* TO mysqltest_dfn@localhost; --connect (wl2818_definer_con,localhost,mysqltest_dfn,,mysqltest_db1) --connection wl2818_definer_con ---echo ---echo ---> connection: wl2818_definer_con --error ER_TABLEACCESS_DENIED_ERROR CREATE TRIGGER trg1 AFTER INSERT ON t1 @@ -89,15 +81,11 @@ CREATE TRIGGER trg1 AFTER INSERT ON t1 # --connection default ---echo ---echo ---> connection: default GRANT TRIGGER ON mysqltest_db1.t1 TO mysqltest_dfn@localhost; --connect (wl2818_definer_con,localhost,mysqltest_dfn,,mysqltest_db1) --connection wl2818_definer_con ---echo ---echo ---> connection: wl2818_definer_con CREATE TRIGGER trg1 AFTER INSERT ON t1 FOR EACH ROW @@ -106,15 +94,11 @@ CREATE TRIGGER trg1 AFTER INSERT ON t1 --disconnect wl2818_definer_con --connection default ---echo ---echo ---> connection: default REVOKE TRIGGER ON mysqltest_db1.t1 FROM mysqltest_dfn@localhost; --connect (wl2818_definer_con,localhost,mysqltest_dfn,,mysqltest_db1) --connection wl2818_definer_con ---echo ---echo ---> connection: wl2818_definer_con --error ER_TABLEACCESS_DENIED_ERROR DROP TRIGGER trg1; @@ -127,8 +111,6 @@ DROP TRIGGER trg1; --connect (wl2818_definer_con,localhost,mysqltest_dfn,,mysqltest_db1) --connection wl2818_definer_con ---echo ---echo ---> connection: wl2818_definer_con --error ER_TABLEACCESS_DENIED_ERROR INSERT INTO t1 VALUES(0); @@ -136,15 +118,11 @@ INSERT INTO t1 VALUES(0); --disconnect wl2818_definer_con --connection default ---echo ---echo ---> connection: default GRANT TRIGGER ON mysqltest_db1.t1 TO mysqltest_dfn@localhost; --connect (wl2818_definer_con,localhost,mysqltest_dfn,,mysqltest_db1) --connection wl2818_definer_con ---echo ---echo ---> connection: wl2818_definer_con INSERT INTO t1 VALUES(0); @@ -156,8 +134,6 @@ TRUNCATE TABLE t2; --disconnect wl2818_definer_con --connection default ---echo ---echo ---> connection: default REVOKE SUPER ON *.* FROM mysqltest_dfn@localhost; @@ -175,16 +151,12 @@ REVOKE SUPER ON *.* FROM mysqltest_dfn@localhost; --connect (wl2818_definer_con,localhost,mysqltest_dfn,,mysqltest_db1) --connection wl2818_definer_con ---echo ---echo ---> connection: wl2818_definer_con CREATE TRIGGER trg1 AFTER INSERT ON t1 FOR EACH ROW INSERT INTO t2 VALUES(CURRENT_USER()); --connection default ---echo ---echo ---> connection: default # Setup definer's privileges. @@ -200,8 +172,6 @@ GRANT SELECT ON mysqltest_db1.t2 TO 'mysqltest_inv'@localhost; --connection wl2818_definer_con ---echo ---echo ---> connection: wl2818_definer_con use mysqltest_db1; @@ -212,8 +182,6 @@ SELECT * FROM t2; --connect (wl2818_invoker_con,localhost,mysqltest_inv,,mysqltest_db1) --connection wl2818_invoker_con ---echo ---echo ---> connection: wl2818_invoker_con use mysqltest_db1; @@ -234,16 +202,12 @@ SELECT * FROM t2; # --connection default ---echo ---echo ---> connection: default use mysqltest_db1; REVOKE INSERT ON mysqltest_db1.t2 FROM mysqltest_dfn@localhost; --connection wl2818_invoker_con ---echo ---echo ---> connection: wl2818_invoker_con use mysqltest_db1; @@ -273,8 +237,6 @@ SELECT * FROM t2; # --connection wl2818_definer_con ---echo ---echo ---> connection: wl2818_definer_con use mysqltest_db1; @@ -289,8 +251,6 @@ CREATE DEFINER='mysqltest_inv'@'localhost' SET @new_sum = 0; --connection default ---echo ---echo ---> connection: default use mysqltest_db1; @@ -299,8 +259,6 @@ GRANT SUPER ON *.* TO mysqltest_dfn@localhost; --disconnect wl2818_definer_con --connect (wl2818_definer_con,localhost,mysqltest_dfn,,mysqltest_db1) --connection wl2818_definer_con ---echo ---echo ---> connection: wl2818_definer_con CREATE DEFINER='mysqltest_inv'@'localhost' TRIGGER trg1 BEFORE INSERT ON t1 @@ -323,6 +281,7 @@ INSERT INTO t1 VALUES(6); # Check that SHOW TRIGGERS statement provides "Definer" column. # +--replace_column 6 # SHOW TRIGGERS; # @@ -381,6 +340,7 @@ SELECT trigger_name, definer FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_n --echo +--replace_column 17 # SELECT * FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name; # @@ -388,8 +348,6 @@ SELECT * FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name; # --connection default ---echo ---echo ---> connection: default DROP USER mysqltest_dfn@localhost; DROP USER mysqltest_inv@localhost; @@ -445,8 +403,6 @@ SET @mysqltest_var = NULL; # NEW/OLD variables. --connection default ---echo ---echo ---> connection: default use mysqltest_db1; @@ -454,8 +410,6 @@ GRANT DELETE ON mysqltest_db1.* TO mysqltest_u1@localhost; SHOW GRANTS FOR mysqltest_u1@localhost; --connection bug15166_u1_con ---echo ---echo ---> connection: bug15166_u1_con use mysqltest_db1; @@ -468,8 +422,6 @@ CREATE TRIGGER t1_trg_after_delete AFTER DELETE ON t1 # - check that UPDATE is required to modify the value; --connection default ---echo ---echo ---> connection: default use mysqltest_db1; @@ -480,8 +432,6 @@ GRANT UPDATE(col) ON mysqltest_db1.t3 TO mysqltest_u1@localhost; GRANT UPDATE(col) ON mysqltest_db1.t4 TO mysqltest_u1@localhost; --connection bug15166_u1_con ---echo ---echo ---> connection: bug15166_u1_con use mysqltest_db1; @@ -530,8 +480,6 @@ CREATE TRIGGER t4_trg_before_insert BEFORE INSERT ON t4 # - check that SELECT is not enough to modify the value; --connection default ---echo ---echo ---> connection: default use mysqltest_db1; @@ -546,8 +494,6 @@ GRANT SELECT(col) on mysqltest_db1.t3 TO mysqltest_u1@localhost; GRANT SELECT(col) on mysqltest_db1.t4 TO mysqltest_u1@localhost; --connection bug15166_u1_con ---echo ---echo ---> connection: bug15166_u1_con use mysqltest_db1; @@ -604,8 +550,6 @@ DROP TRIGGER t4_trg_err_2; # - check that UPDATE is required to modify the value; --connection default ---echo ---echo ---> connection: default use mysqltest_db1; @@ -648,8 +592,6 @@ SELECT * FROM t4; # - check that SELECT is not enough to modify the value; --connection default ---echo ---echo ---> connection: default use mysqltest_db1; @@ -959,13 +901,10 @@ drop table if exists t1; create table t1 (i int); connect (flush,localhost,root,,test,,); connection default; ---echo connection: default lock tables t1 write; connection flush; ---echo connection: flush --send flush tables with read lock; connection default; ---echo connection: default let $wait_condition= select count(*) = 1 from information_schema.processlist where state = "Waiting for global read lock"; @@ -973,7 +912,6 @@ let $wait_condition= create trigger t1_bi before insert on t1 for each row begin end; unlock tables; connection flush; ---echo connection: flush --reap unlock tables; connection default; diff --git a/mysql-test/t/trigger_wl3253.test b/mysql-test/t/trigger_wl3253.test new file mode 100644 index 00000000000..3504eeaf889 --- /dev/null +++ b/mysql-test/t/trigger_wl3253.test @@ -0,0 +1,428 @@ +--echo # +--echo # WL#3253: multiple triggers per table +--echo # + +SET @binlog_format_saved = @@binlog_format; +SET binlog_format=ROW; +SET time_zone='+00:00'; + +--echo # +--echo # Test 1. +--echo # Check that the sequence of triggers for the same combination +--echo # of event type/action type can be created for a table +--echo # and is fired consequently in the order of its creation +--echo # during statement execution. +--echo # In this test we check BEFORE triggers. +--echo # + +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a INT, b INT AUTO_INCREMENT PRIMARY KEY); + +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a); +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a + 100); + +INSERT INTO t1 VALUES (1); + +SELECT * FROM t2 ORDER BY b; + +DROP TABLE t2; +DROP TABLE t1; + +--echo # +--echo # Test 2. +--echo # Check that the sequence of triggers for the same combination +--echo # of event type/action type can be created for a table +--echo # and is fired consequently in the order of its creation +--echo # during statement execution. +--echo # In this test we check AFTER triggers. +--echo # + +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a INT, b INT AUTO_INCREMENT PRIMARY KEY); + +CREATE TRIGGER tr1_bi AFTER INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a); +CREATE TRIGGER tr2_bi AFTER INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a + 100); + +INSERT INTO t1 VALUES (1); + +SELECT * FROM t2 ORDER BY b; + +DROP TABLE t2; +DROP TABLE t1; + +--echo # +--echo # Test 3. +--echo # Check that the sequences of triggers for the different event types +--echo # can be created for a table and are fired consequently +--echo # in the order of its creation during statement execution. +--echo # + +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a INT, b INT AUTO_INCREMENT PRIMARY KEY); + +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a); +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a + 100); + +CREATE TRIGGER tr1_bu BEFORE UPDATE ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a); +CREATE TRIGGER tr2_bu BEFORE UPDATE ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a + 300); + +INSERT INTO t1 VALUES (1); + +SELECT * FROM t2 ORDER BY b; + +UPDATE t1 SET a = 5; + +SELECT * FROM t2 ORDER BY b; + +DROP TABLE t2; +DROP TABLE t1; + +--echo # +--echo # Test 4. +--echo # Check that every new created trigger has unique action_order value +--echo # started from 1 and NOT NULL value for creation timestamp. +--echo # + +CREATE TABLE t1 (a INT); + +SET TIMESTAMP=UNIX_TIMESTAMP('2013-01-31 09:00:00'); +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +SET TIMESTAMP=UNIX_TIMESTAMP('2013-01-31 09:00:01'); +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=2; + +SELECT trigger_name, created, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +DROP TABLE t1; +SET TIMESTAMP=DEFAULT; + +--echo # +--echo # Test 5. +--echo # Check that action_order attribute isn't shown +--echo # in the output of SHOW TRIGGERS and SHOW CREATE TRIGGER +--echo # + +CREATE TABLE t1 (a INT); +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; + +--replace_column 6 # +SHOW TRIGGERS; + +--replace_column 17 # +SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_schema = 'test'; + +--replace_column 7 # +SHOW CREATE TRIGGER tr1_bi; + +DROP TABLE t1; + +--echo # +--echo # Test 6. +--echo # Check that action_order attribute is reused when trigger +--echo # are recreated. +--echo # + +CREATE TABLE t1 (a INT); +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; + +SELECT trigger_name, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +DROP TRIGGER tr1_bi; + +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=2; + +SELECT trigger_name, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +DROP TABLE t1; + +--echo # +--echo # Test 7. +--echo # Check that it is possible to create several triggers with +--echo # the same value for creation timestamp. +--echo # + +CREATE TABLE t1 (a INT); + +SET TIMESTAMP=UNIX_TIMESTAMP('2013-01-31 09:00:01'); +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=2; + +SELECT trigger_name, created, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +DROP TABLE t1; +SET TIMESTAMP=DEFAULT; + +--echo # +--echo # Test 8. +--echo # Check that SHOW CREATE TRIGGER outputs the CREATED attribute +--echo # and it is not NULL +--echo # + +CREATE TABLE t1 (a INT); + +SET TIMESTAMP=UNIX_TIMESTAMP('2013-01-31 09:00:01'); +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +SHOW CREATE TRIGGER tr1_bi; + +DROP TABLE t1; +SET TIMESTAMP=DEFAULT; + +--echo # +--echo # Test 9. +--echo # Check that SHOW TRIGGERS outputs the CREATED attribute +--echo # and it is not NULL. +--echo # + +CREATE TABLE t1 (a INT); + +SET TIMESTAMP=UNIX_TIMESTAMP('2013-01-31 09:00:01'); + +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; + +SHOW TRIGGERS; + +SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_schema = 'test'; + +DROP TABLE t1; + +SET TIMESTAMP=DEFAULT; + +--echo # +--echo # Test 10. +--echo # Check that FOLLOWS clause is supported and works correctly. +--echo # + +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a INT, b INT AUTO_INCREMENT PRIMARY KEY); + +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a + 100); +CREATE TRIGGER tr3_bi BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a + 300); +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW FOLLOWS tr1_bi INSERT INTO t2 (a) VALUES (NEW.a + 200); + +SELECT trigger_name, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +INSERT INTO t1 VALUES (1); +SELECT * FROM t2 ORDER BY b; + +DROP TABLE t2; +DROP TABLE t1; + +--echo # +--echo # Test 11. +--echo # Check that PRECEDES clause is supported and works correctly. +--echo # + +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a INT, b INT AUTO_INCREMENT PRIMARY KEY); + +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a + 100); +CREATE TRIGGER tr3_bi BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a + 300); +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW PRECEDES tr3_bi INSERT INTO t2 (a) VALUES (NEW.a + 200); + +SELECT trigger_name, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +INSERT INTO t1 VALUES (1); +SELECT * FROM t2 ORDER BY b; + +DROP TABLE t2; +DROP TABLE t1; + +--echo # +--echo # Test 12. +--echo # Check that the PRECEDES works properly for the 1st trigger in the chain. +--echo # + +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a INT, b INT AUTO_INCREMENT PRIMARY KEY); + +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 (a) VALUES (NEW.a + 100); +CREATE TRIGGER tr0_bi BEFORE INSERT ON t1 FOR EACH ROW PRECEDES tr1_bi INSERT INTO t2 (a) VALUES (NEW.a); + +SELECT trigger_name, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +INSERT INTO t1 VALUES (1); +SELECT * FROM t2 ORDER BY b; + +DROP TABLE t2; +DROP TABLE t1; + +--echo # +--echo # Test 13. +--echo # Check that error is reported if the FOLLOWS clause references to +--echo # non-existing trigger +--echo # + +CREATE TABLE t1 (a INT); + +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +CREATE TRIGGER tr3_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=3; + +--error ER_REFERENCED_TRG_DOES_NOT_EXIST +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW FOLLOWS tr0_bi SET @a:=2; + +SELECT trigger_name, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +DROP TABLE t1; + +--echo # +--echo # Test 14. +--echo # Check that error is reported if the PRECEDES clause references to +--echo # non-existing trigger +--echo # + +CREATE TABLE t1 (a INT); + +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +CREATE TRIGGER tr3_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=3; + +--error ER_REFERENCED_TRG_DOES_NOT_EXIST +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW PRECEDES tr0_bi SET @a:=2; + +SELECT trigger_name, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +DROP TABLE t1; + +--echo # +--echo # Test 15. +--echo # Check that action_order value is independent for each type of event +--echo # (INSERT/UPDATE/DELETE) +--echo # + +CREATE TABLE t1 (a INT); + +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=2; +CREATE TRIGGER tr1_bu BEFORE UPDATE ON t1 FOR EACH ROW SET @a:=3; + +SELECT trigger_name, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +CREATE TRIGGER tr3_bi BEFORE INSERT ON t1 FOR EACH ROW FOLLOWS tr2_bi SET @a:=3; +CREATE TRIGGER tr2_bu BEFORE UPDATE ON t1 FOR EACH ROW FOLLOWS tr1_bu SET @a:=3; + +SELECT trigger_name, action_order FROM information_schema.triggers WHERE trigger_schema='test'; + +DROP TABLE t1; + +--echo # +--echo # Test 16. +--echo # Check that the trigger in the clause FOLLOWS/PRECEDES can refences +--echo # only to the trigger for the same ACTION/TIMINMG +--echo # + +CREATE TABLE t1 (a INT); +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +CREATE TRIGGER tr1_bu BEFORE UPDATE ON t1 FOR EACH ROW SET @a:=3; + +--error ER_REFERENCED_TRG_DOES_NOT_EXIST +CREATE TRIGGER tr2_bu BEFORE UPDATE ON t1 FOR EACH ROW FOLLOWS tr1_bi SET @a:=3; + +--error ER_REFERENCED_TRG_DOES_NOT_EXIST +CREATE TRIGGER tr2_au AFTER UPDATE ON t1 FOR EACH ROW FOLLOWS tr1_bi SET @a:=3; + +--error ER_REFERENCED_TRG_DOES_NOT_EXIST +CREATE TRIGGER tr1_au AFTER UPDATE ON t1 FOR EACH ROW FOLLOWS tr1_bu SET @a:=3; + +--error ER_REFERENCED_TRG_DOES_NOT_EXIST +CREATE TRIGGER tr1_ai AFTER INSERT ON t1 FOR EACH ROW FOLLOWS tr1_bi SET @a:=3; + +--replace_column 6 # +SHOW TRIGGERS; + +--replace_column 17 # +SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_schema = 'test'; + +DROP TABLE t1; + +# Binlog is required +--source include/have_log_bin.inc + +--echo # +--echo # Test 17. Check that table's triggers are dumped correctly. +--echo # +CREATE TABLE t1 (a INT); +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=2; +CREATE TRIGGER tr1_bu BEFORE UPDATE ON t1 FOR EACH ROW SET @a:=3; + +# dump tables and triggers +--exec $MYSQL_DUMP --compact test + +DROP TABLE t1; + +--echo # +--echo # Test 18. Check that table's triggers are dumped in right order +--echo # taking into account the PRECEDES/FOLLOWS clauses. +--echo # + +CREATE TABLE t1 (a INT); +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=2; +CREATE TRIGGER tr0_bi BEFORE INSERT ON t1 FOR EACH ROW PRECEDES tr1_bi SET @a:=0; +CREATE TRIGGER tr1_1_bi BEFORE INSERT ON t1 FOR EACH ROW FOLLOWS tr1_bi SET @a:=0; + +--echo # Expected order of triggers in the dump is: tr0_bi, tr1_bi, tr1_1_bi, tr2_i. +# dump tables and triggers +--exec $MYSQL_DUMP --compact test + +DROP TABLE t1; + +--echo # +--echo # Test 19. Check that table's triggers are dumped correctly in xml. +--echo # + +CREATE TABLE t1 (a INT); +SET TIMESTAMP=UNIX_TIMESTAMP('2013-01-31 09:00:00'); +CREATE TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1; +CREATE TRIGGER tr2_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=2; +CREATE TRIGGER tr1_bu BEFORE UPDATE ON t1 FOR EACH ROW SET @a:=3; +SET TIMESTAMP=DEFAULT; + +# dump tables and triggers +--exec $MYSQL_DUMP --compact --no-create-info --xml test + +DROP TABLE t1; + +--echo # +--echo # Test 20. Check that the statement CHECK TABLE FOR UPGRADE outputs +--echo # the warnings for triggers created by a server without support for wl3253. +--echo # + +CREATE TABLE t1 (a INT); + +let $MYSQLD_DATADIR=`SELECT @@datadir`; +--write_file $MYSQLD_DATADIR/test/t1.TRG +TYPE=TRIGGERS +triggers='CREATE DEFINER=`root`@`localhost` TRIGGER tr1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1' 'CREATE DEFINER=`root`@`localhost` TRIGGER tr1_ai AFTER INSERT ON t1 FOR EACH ROW SET @a:=2' +sql_modes=1073741824 1073741824 +definers='root@localhost' 'root@localhost' +client_cs_names='latin1' 'latin1' +connection_cl_names='latin1_swedish_ci' 'latin1_swedish_ci' +db_cl_names='latin1_swedish_ci' 'latin1_swedish_ci' +EOF + +--write_file $MYSQLD_DATADIR/test/tr1_bi.TRN +TYPE=TRIGGERNAME +trigger_table=t1 +EOF + +--write_file $MYSQLD_DATADIR/test/tr1_ai.TRN +TYPE=TRIGGERNAME +trigger_table=t1 +EOF + +FLUSH TABLE t1; + +CHECK TABLE t1 FOR UPGRADE; + +SHOW TRIGGERS; + +SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_schema = 'test'; + +SHOW CREATE TRIGGER tr1_bi; +SHOW CREATE TRIGGER tr1_ai; + +DROP TABLE t1; + +SET binlog_format=@binlog_format_saved; + +--echo # End of tests. +--echo # diff --git a/mysql-test/t/truncate_coverage.test b/mysql-test/t/truncate_coverage.test index 6f5c773ac6a..3351ce84232 100644 --- a/mysql-test/t/truncate_coverage.test +++ b/mysql-test/t/truncate_coverage.test @@ -17,108 +17,6 @@ DROP TABLE IF EXISTS t1; --echo # Bug#20667 - Truncate table fails for a write locked table --echo # ######## -# Attack wait_while_table_is_used(). Kill query while trying to -# upgrade MDL. -# -CREATE TABLE t1 (c1 INT); -INSERT INTO t1 VALUES (1); -# -# Acquire a shared metadata lock on table by opening HANDLER for it and wait. -# TRUNCATE shall block on this metadata lock. -# We can't use normal DML as such statements would also block LOCK TABLES. -# ---echo # ---echo # connection con1 ---connect (con1, localhost, root,,) -HANDLER t1 OPEN; -# -# Get connection id of default connection. -# Lock the table and start TRUNCATE, which will block on MDL upgrade. -# ---echo # ---echo # connection default ---connection default -let $ID= `SELECT @id := CONNECTION_ID()`; -LOCK TABLE t1 WRITE; -SET DEBUG_SYNC='mdl_upgrade_lock SIGNAL waiting'; -send TRUNCATE TABLE t1; -# -# Get the default connection ID into a variable in an invisible statement. -# Kill the TRUNCATE query. This shall result in an error return -# from wait_while_table_is_used(). -# ---echo # ---echo # connection con2 ---connect (con2, localhost, root,,) -SET DEBUG_SYNC='now WAIT_FOR waiting'; -let $invisible_assignment_in_select = `SELECT @id := $ID`; -KILL QUERY @id; ---disconnect con2 ---echo # ---echo # connection default ---connection default ---error ER_QUERY_INTERRUPTED -reap; -UNLOCK TABLES; ---echo # ---echo # connection con1 ---connection con1 ---echo # Release shared metadata lock by closing HANDLER. -HANDLER t1 CLOSE; ---disconnect con1 ---echo # ---echo # connection default ---connection default -DROP TABLE t1; -SET DEBUG_SYNC='RESET'; -######## -# Attack reopen_tables(). Remove form file. -# -CREATE TABLE t1 (c1 INT); -INSERT INTO t1 VALUES (1); -# -# Acquire a shared metadata lock on table by opening HANDLER for it and wait. -# TRUNCATE shall block on this metadata lock. -# We can't use normal DML as such statements would also block LOCK TABLES. -# ---echo # ---echo # connection con1 ---connect (con1, localhost, root,,) -HANDLER t1 OPEN; -# -# Lock the table and start TRUNCATE, which will block on MDL upgrade. -# ---echo # ---echo # connection default ---connection default -LOCK TABLE t1 WRITE; -SET DEBUG_SYNC='mdl_upgrade_lock SIGNAL waiting'; -send TRUNCATE TABLE t1; -# -# Remove datafile. -# Commit to let TRUNCATE continue. -# ---echo # ---echo # connection con2 ---connect (con2, localhost, root,,) -SET DEBUG_SYNC='now WAIT_FOR waiting'; ---remove_file $MYSQLD_DATADIR/test/t1.frm ---disconnect con2 ---echo # ---echo # connection con1 ---connection con1 -HANDLER t1 CLOSE; ---disconnect con1 ---echo # ---echo # connection default ---connection default ---error ER_NO_SUCH_TABLE -reap; -UNLOCK TABLES; ---error ER_BAD_TABLE_ERROR -DROP TABLE t1; -SET DEBUG_SYNC='RESET'; -######## # Attack acquire_exclusive_locks(). Hold a global read lock. # Non-LOCK TABLE case. # @@ -128,8 +26,6 @@ INSERT INTO t1 VALUES (1); # Start a transaction and execute a DML in it. Since 5.4.4 this leaves # a shared meta data lock (MDL) behind. TRUNCATE shall block on it. # ---echo # ---echo # connection con1 --connect (con1, localhost, root,,) START TRANSACTION; INSERT INTO t1 VALUES (2); @@ -137,8 +33,6 @@ INSERT INTO t1 VALUES (2); # Get connection id of default connection. # Start TRUNCATE, which will block on acquire_exclusive_locks(). # ---echo # ---echo # connection default --connection default let $ID= `SELECT @id := CONNECTION_ID()`; SET DEBUG_SYNC='mdl_acquire_lock_wait SIGNAL waiting'; @@ -148,25 +42,17 @@ send TRUNCATE TABLE t1; # Kill the TRUNCATE query. This shall result in an error return # from wait_while_table_is_used(). # ---echo # ---echo # connection con1 --connection con1 SET DEBUG_SYNC='now WAIT_FOR waiting'; let $invisible_assignment_in_select = `SELECT @id := $ID`; KILL QUERY @id; ---echo # ---echo # connection default --connection default --error ER_QUERY_INTERRUPTED reap; ---echo # ---echo # connection con1 --connection con1 --echo # Release SW lock by committing transaction. COMMIT; --disconnect con1 ---echo # ---echo # connection default --connection default UNLOCK TABLES; DROP TABLE t1; @@ -187,19 +73,16 @@ CREATE TABLE t1(a INT) engine=memory; CREATE TABLE m1(a INT) engine=merge UNION(t1); connect(con2, localhost, root); ---echo # Connection con1 connect(con1, localhost, root); SET DEBUG_SYNC= 'open_tables_after_open_and_process_table SIGNAL opened WAIT_FOR dropped'; --echo # Sending: --send TRUNCATE TABLE m1 ---echo # Connection con2 connection con2; SET DEBUG_SYNC= 'now WAIT_FOR opened'; --echo # Sending: --send FLUSH TABLES ---echo # Connection default connection default; --echo # Waiting for FLUSH TABLES to be blocked. let $wait_condition= SELECT COUNT(*)=1 FROM information_schema.processlist @@ -207,7 +90,6 @@ let $wait_condition= SELECT COUNT(*)=1 FROM information_schema.processlist --source include/wait_condition.inc SET DEBUG_SYNC= 'now SIGNAL dropped'; ---echo # Connection con1 connection con1; --echo # Reaping: TRUNCATE TABLE m1 --error ER_WRONG_MRG_TABLE @@ -215,14 +97,12 @@ connection con1; disconnect con1; --source include/wait_until_disconnected.inc ---echo # Connection con2 connection con2; --echo # Reaping: FLUSH TABLES --reap disconnect con2; --source include/wait_until_disconnected.inc ---echo # Connection default connection default; SET DEBUG_SYNC= 'RESET'; DROP TABLE m1, t1; diff --git a/mysql-test/t/type_blob.test b/mysql-test/t/type_blob.test index a20173e231a..b818e1b451d 100644 --- a/mysql-test/t/type_blob.test +++ b/mysql-test/t/type_blob.test @@ -33,15 +33,12 @@ drop table t1,t2,t3,t4; CREATE TABLE t1 (a char(257) default "hello"); --error 1074 CREATE TABLE t2 (a char(256)); ---error 1074 CREATE TABLE t1 (a varchar(70000) default "hello"); ---error 1101 +SHOW CREATE TABLE t1; CREATE TABLE t2 (a blob default "hello"); +SHOW CREATE TABLE t2; -# Safety to be able to continue with other tests if above fails ---disable_warnings -drop table if exists t1,t2; ---enable_warnings +drop table t1,t2; # # test of full join with blob @@ -432,8 +429,9 @@ insert into t1 values (default); select * from t1; drop table t1; set @@sql_mode='TRADITIONAL'; ---error ER_BLOB_CANT_HAVE_DEFAULT create table t1 (a text default ''); +show create table t1; +drop table t1; set @@sql_mode=''; # @@ -515,7 +513,7 @@ CREATE TABLE b15776 (a char(2147483648)); --error ER_TOO_BIG_FIELDLENGTH CREATE TABLE b15776 (a char(4294967295)); # Even BLOB won't hold ---error ER_TOO_BIG_DISPLAYWIDTH +--error ER_TOO_BIG_FIELDLENGTH CREATE TABLE b15776 (a char(4294967296)); @@ -523,12 +521,14 @@ CREATE TABLE b15776 (a char(4294967296)); ## For year, widths not "2" or "4" are silently rewritten to "4". But ## When we complain about it, we say that the max is 255. We may be ## talking about different things. It's confusing. +--replace_result 4294967295 ? 0 ? CREATE TABLE b15776 (a year(4294967295)); INSERT INTO b15776 VALUES (42); SELECT * FROM b15776; DROP TABLE b15776; ---error ER_TOO_BIG_DISPLAYWIDTH CREATE TABLE b15776 (a year(4294967296)); +SHOW CREATE TABLE b15776; +DROP TABLE b15776; CREATE TABLE b15776 (a year(0)); # 0 is special case, means default size DROP TABLE b15776; --error ER_PARSE_ERROR @@ -539,7 +539,7 @@ CREATE TABLE b15776 (a year(-2)); CREATE TABLE b15776 (a timestamp(4294967294)); --error ER_TOO_BIG_PRECISION CREATE TABLE b15776 (a timestamp(4294967295)); ---error ER_TOO_BIG_DISPLAYWIDTH +--error ER_TOO_BIG_PRECISION CREATE TABLE b15776 (a timestamp(4294967296)); --error ER_PARSE_ERROR CREATE TABLE b15776 (a timestamp(-1)); @@ -550,10 +550,11 @@ CREATE TABLE b15776 (a timestamp(-2)); # widths that are too large to be interpreted cause DISPLAYWIDTH errors. --error ER_TOO_BIG_DISPLAYWIDTH CREATE TABLE b15776 (a int(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); ---error ER_TOO_BIG_DISPLAYWIDTH +--error ER_TOO_BIG_FIELDLENGTH CREATE TABLE b15776 (a char(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); ---error ER_TOO_BIG_DISPLAYWIDTH CREATE TABLE b15776 (a year(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); +SHOW CREATE TABLE b15776; +DROP TABLE b15776; ## Do not select, too much memory needed. CREATE TABLE b15776 select cast(null as char(4294967295)); diff --git a/mysql-test/t/type_datetime.test b/mysql-test/t/type_datetime.test index 6b752b1a978..b16d426ab70 100644 --- a/mysql-test/t/type_datetime.test +++ b/mysql-test/t/type_datetime.test @@ -703,3 +703,51 @@ DROP TABLE t1; --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9337 ALTER from DECIMAL and INT to DATETIME returns a wrong result +--echo # +CREATE TABLE t1 (a DATETIME); +INSERT INTO t1 VALUES (1000); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATETIME); +CREATE TABLE t2 (a INT); +INSERT INTO t2 VALUES (1000); +INSERT INTO t1 SELECT * FROM t2; +SELECT * FROM t1; +DROP TABLE t1,t2; + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1000); +ALTER TABLE t1 MODIFY a DATETIME; +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATETIME); +INSERT INTO t1 VALUES (1000.0); +SELECT * FROM t1; +DROP TABLE IF EXISTS t1; + +CREATE TABLE t1 (a DATETIME); +CREATE TABLE t2 (a DECIMAL(4,0)); +INSERT INTO t2 VALUES (1000); +INSERT INTO t1 SELECT * FROM t2; +SELECT * FROM t1; +DROP TABLE t1,t2; + +CREATE TABLE t1 (a DECIMAL(4,0)); +INSERT INTO t1 VALUES (1000); +ALTER TABLE t1 MODIFY a DATETIME; +SELECT * FROM t1; +DROP TABLE t1; + + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/type_enum.test b/mysql-test/t/type_enum.test index 314cb237dd3..63e9e9e7b09 100644 --- a/mysql-test/t/type_enum.test +++ b/mysql-test/t/type_enum.test @@ -388,3 +388,65 @@ DROP TABLE t1; --echo # --echo # End of 10.1 tests --echo # + + +--echo # +--echo # MDEV-9340 Copying from INT/DOUBLE to ENUM is inconsistent +--echo # + +# DOUBLE -> ENUM +CREATE TABLE t1 (a ENUM('9e200','9e100')); +CREATE TABLE t2 (a DOUBLE); +INSERT INTO t2 VALUES ('9e100'); +INSERT INTO t1 SELECT * FROM t2; +SELECT * FROM t1; +DROP TABLE t1,t2; + +CREATE TABLE t1 (a DOUBLE); +INSERT INTO t1 VALUES (9e100); +ALTER TABLE t1 MODIFY a ENUM('9e200','9e100'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a ENUM('200','100')); +CREATE TABLE t2 (a DOUBLE); +INSERT INTO t2 VALUES ('100'); +INSERT INTO t1 SELECT * FROM t2; +SELECT * FROM t1; +DROP TABLE t1,t2; + +# INT -> ENUM +CREATE TABLE t1 (a ENUM('200','100')); +CREATE TABLE t2 (a INT); +INSERT INTO t2 VALUES ('100'); +INSERT INTO t1 SELECT * FROM t2; +SELECT * FROM t1; +DROP TABLE t1,t2; + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES ('200'); +ALTER TABLE t1 MODIFY a ENUM('200','100'); +SELECT *FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a ENUM('200','100')); +CREATE TABLE t2 (a INT); +INSERT INTO t2 VALUES ('100'); +INSERT INTO t1 SELECT * FROM t2; +SELECT * FROM t1; +DROP TABLE t1,t2; + + +# YEAR -> ENUM +CREATE TABLE t1 (a ENUM('2001','2002')); +CREATE TABLE t2 (a YEAR); +INSERT INTO t2 VALUES ('2001'); +INSERT INTO t1 SELECT * FROM t2; +SELECT * FROM t1; +DROP TABLE t1,t2; + +CREATE TABLE t1 (a YEAR); +INSERT INTO t1 VALUES ('2001'); +ALTER TABLE t1 MODIFY a ENUM('2001','2002'); +SELECT * FROM t1; +DROP TABLE t1; diff --git a/mysql-test/t/type_float.test b/mysql-test/t/type_float.test index 3717dc028ba..f54eacf0595 100644 --- a/mysql-test/t/type_float.test +++ b/mysql-test/t/type_float.test @@ -458,3 +458,81 @@ DROP TABLE t1; --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-4102 Limitation on DOUBLE or REAL length is ignored with INSERT .. SELECT +--echo # +CREATE TABLE t1 (d1 DOUBLE(5,2), d2 DOUBLE(10,2)); +INSERT INTO t1 VALUES (10000000.55, 10000000.55); +INSERT INTO t1 SELECT d2, d2 FROM t1; +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # MDEV-9709 Unexpected modification of value and warning about out of range value upon ALTER +--echo # + +CREATE TABLE t1 ( + f FLOAT, + d10_10 DOUBLE PRECISION (10,10), + d53_10 DOUBLE(53,10) +); +INSERT INTO t1 (f,d10_10,d53_10) VALUES ( + -9999999999999999999999999999999999999999999.9999999999, + -9999999999999999999999999999999999999999999.9999999999, + -9999999999999999999999999999999999999999999.9999999999 +); +--vertical_results +SELECT * FROM t1; +INSERT INTO t1 (f,d10_10,d53_10) SELECT d53_10, d53_10, d53_10 FROM t1; +SELECT * FROM t1; +ALTER TABLE t1 ADD COLUMN i INT; +SELECT * FROM t1; +DROP TABLE t1; +--horizontal_results + +CREATE TABLE t1 (d10_10 DOUBLE (10,10)); +CREATE TABLE t2 (d53_10 DOUBLE (53,10)); +INSERT INTO t2 VALUES (-9999999999999999999999999999999999999999999.9999999999); +INSERT INTO t1 (d10_10) SELECT d53_10 FROM t2; +SELECT * FROM t1; +DROP TABLE t1,t2; + +CREATE TABLE t1 (d2_2 FLOAT (2,2)); +CREATE TABLE t2 (d4_2 FLOAT (4,2)); +INSERT INTO t2 VALUES (99.99); +INSERT INTO t1 (d2_2) SELECT d4_2 FROM t2; +SELECT * FROM t1; +DROP TABLE t1,t2; + +--echo # +--echo # Test of using wrong scale +--echo # + +create or replace table t1 (a double(40,30)); +--error ER_TOO_BIG_SCALE 1425 +create or replace table t1 (a double(40,31)); +create or replace table t1 as select 1.01e1; +show create table t1; +create or replace table t1 as select truncate(10.000000000001e1, 30) as t; +show create table t1; +create or replace table t1 as select truncate(10.000000000001e1, 31) as t; +show create table t1; +create or replace table t1 as select truncate(10.000000000001e1, 39) as t; +show create table t1; +create or replace table t1 as select truncate(10.000000000001e1, 51) as t; +show create table t1; +create or replace table t1 as select truncate(10.000000000001e1, 20)/2 as t; +show create table t1; +create or replace table t1 as select truncate(10.000000000001e1, 28)/2 as t; +show create table t1; + +drop table if exists t1; + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/type_int.test b/mysql-test/t/type_int.test index e8b9b2cffcd..271b4d5862a 100644 --- a/mysql-test/t/type_int.test +++ b/mysql-test/t/type_int.test @@ -26,3 +26,53 @@ DROP TABLE t1; --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9393 Split Copy_field::get_copy_func() into virtual methods in Field +--echo # + +# DECIMAL -> INT +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10.1),(10.9); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a DECIMAL(10,2)); +INSERT INTO t2 VALUES (10.1),(10.9); +INSERT INTO t1 SELECT a FROM t2; +SELECT * FROM t1; +DROP TABLE t1,t2; + +CREATE TABLE t1 (a DECIMAL(10,2)); +INSERT INTO t1 VALUES (10.1),(10.9); +ALTER TABLE t1 MODIFY a INT; +SELECT * FROM t1; +DROP TABLE t1; + +# TIME -> INT +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (TIME'00:00:10.1'),(TIME'00:00:10.9'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a TIME(1)); +INSERT INTO t2 VALUES (10.1),(10.9); +INSERT INTO t1 SELECT a FROM t2; +SELECT * FROM t1; +DROP TABLE t1,t2; + +CREATE TABLE t1 (a TIME(1)); +INSERT INTO t1 VALUES (10.1),(10.9); +ALTER TABLE t1 MODIFY a INT; +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/type_newdecimal.test b/mysql-test/t/type_newdecimal.test index b84d01e93be..152c3ade487 100644 --- a/mysql-test/t/type_newdecimal.test +++ b/mysql-test/t/type_newdecimal.test @@ -606,14 +606,14 @@ select round(99999999999999999.999,3); select round(-99999999999999999.999,3); #-- should return -100000000000000000.000 # -select truncate(99999999999999999999999999999999999999,31); +select truncate(99999999999999999999999999999999999999,49); #-- should return 99999999999999999999999999999999999999.000 # -select truncate(99.999999999999999999999999999999999999,31); +select truncate(99.999999999999999999999999999999999999,49); #-- should return 99.9999999999999999999999999999999 # select truncate(99999999999999999999999999999999999999,-31); -# should return 90000000000000000000000000000000 +# should return 99999990000000000000000000000000000000 # #-- 6. Set functions (AVG, SUM, COUNT) should work. # @@ -959,16 +959,18 @@ select cast(ln(14000) as decimal(2,3)) c1; --error 1426 create table t1 (sl decimal(70,30)); --error 1425 -create table t1 (sl decimal(32,31)); +create table t1 (sl decimal(32,39)); +--error 1426 +create table t1 (sl decimal(67,38)); --error 1425 -create table t1 (sl decimal(0,38)); +create table t1 (sl decimal(0,50)); --error 1427 create table t1 (sl decimal(0,30)); create table t1 (sl decimal(5, 5)); show create table t1; drop table t1; # Test limits -create table t1 (sl decimal(65, 30)); +create table t1 (sl decimal(65, 38)); show create table t1; drop table t1; @@ -1180,15 +1182,15 @@ SELECT CAST(1 AS decimal(65,10)); --error ER_TOO_BIG_PRECISION SELECT CAST(1 AS decimal(66,10)); -SELECT CAST(1 AS decimal(65,30)); +SELECT CAST(1 AS decimal(65,38)); --error ER_TOO_BIG_SCALE -SELECT CAST(1 AS decimal(65,31)); +SELECT CAST(1 AS decimal(65,39)); CREATE TABLE t1 (a int DEFAULT NULL, b int DEFAULT NULL); INSERT INTO t1 VALUES (3,30), (1,10), (2,10); SELECT a+CAST(1 AS decimal(65,30)) AS aa, SUM(b) FROM t1 GROUP BY aa; --error ER_TOO_BIG_SCALE -SELECT a+CAST(1 AS decimal(65,31)) AS aa, SUM(b) FROM t1 GROUP BY aa; +SELECT a+CAST(1 AS decimal(65,49)) AS aa, SUM(b) FROM t1 GROUP BY aa; DROP TABLE t1; @@ -1213,7 +1215,7 @@ DROP TABLE t1; # maxmimum precision of 30 places after the decimal point. Show that # temp field creation beyond that works and throws a truncation warning. # DECIMAL(37,36) should be adjusted to DECIMAL(31,30). -CREATE TABLE t1 SELECT 0.123456789012345678901234567890123456 AS f1; +CREATE TABLE t1 SELECT 0.1234567890123456789012345678901234567890123456789 AS f1; DESC t1; SELECT f1 FROM t1; DROP TABLE t1; @@ -1421,7 +1423,7 @@ DROP TABLE t1,t2; CREATE TABLE t1 (a DECIMAL(30,30)); INSERT INTO t1 VALUES (0.1),(0.2),(0.3); -CREATE TABLE t2 SELECT IFNULL(a + 0.0000000000000000000000000000001, NULL) AS c1 FROM t1; +CREATE TABLE t2 SELECT IFNULL(a + 0.00000000000000000000000000000000000000000000000001, NULL) AS c1 FROM t1; DESC t2; DROP TABLE t1,t2; @@ -1738,3 +1740,20 @@ DROP TABLE t1; --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Test CREATE .. SELECT +--echo + +create or replace table t1 as select 1.000000000000000000000000000000000 as a; +show create table t1; +create or replace table t1 as select 1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 as a; +show create table t1; +create or replace table t1 as select 1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 as a; +show create table t1; + +drop table t1; + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/type_num_innodb.test b/mysql-test/t/type_num_innodb.test new file mode 100644 index 00000000000..04bdd4c63b0 --- /dev/null +++ b/mysql-test/t/type_num_innodb.test @@ -0,0 +1,41 @@ +--source include/have_innodb.inc + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9391 InnoDB does not produce warnings when doing WHERE int_column=varchar_column +--echo # + +CREATE TABLE t1 ( + a DOUBLE, b VARCHAR(1), c INT, + KEY(a), KEY(b) +) ENGINE=InnoDB; +INSERT INTO t1 VALUES +(1,'v',9),(2,'v',8),(3,'c',7),(4,'m',6),(5,'x',5), +(6,'i',4),(7,'e',3),(8,'p',2),(9,'s',1),(10,'j',9), +(11,'z',8),(12,'c',7),(13,'a',6),(14,'q',5),(15,'y',4), +(16,'n',3),(17,'r',2),(18,'v',1),(19,'p',0); +CREATE TABLE t2 ( + pk INT, d VARCHAR(1), e INT, + PRIMARY KEY(pk), KEY(d,e) +) ENGINE=InnoDB; +INSERT INTO t2 VALUES +(1,'x',1),(2,'d',2),(3,'r',3),(4,'f',4),(5,'y',5), +(6,'u',6),(7,'m',7),(8,'k',8),(9,'o',9),(10,'w',1), +(11,'m',2),(12,'q',3),(13,'m',4),(14,'d',5), +(15,'g',6),(16,'x',7),(17,'f',8); +SELECT * FROM t1,t2 WHERE a=d; + +ALTER TABLE t1 MODIFY a DECIMAL(10,0); +SELECT * FROM t1,t2 WHERE a=d; + +ALTER TABLE t1 MODIFY a DOUBLE; +SELECT * FROM t1,t2 WHERE a=d; + +DROP TABLE t1,t2; + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/type_time.test b/mysql-test/t/type_time.test index 27679b9ec5a..c4b93d6dbb2 100644 --- a/mysql-test/t/type_time.test +++ b/mysql-test/t/type_time.test @@ -726,3 +726,25 @@ DROP TABLE t1; --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + + +--echo # +--echo # MDEV-9393 Split Copy_field::get_copy_func() into virtual methods in Field +--echo # + +CREATE TABLE t1 (a YEAR, b TIME, c YEAR); +CREATE TABLE t2 (a YEAR); +INSERT INTO t2 VALUES (0),(1999),(2000),(2030),(2050),(2070); +INSERT INTO t1 (a,b,c) SELECT a,a,a FROM t2; +ALTER TABLE t1 MODIFY c TIME; +SELECT * FROM t1; +DROP TABLE t1,t2; + + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/type_timestamp_hires.test b/mysql-test/t/type_timestamp_hires.test index 0a49056294f..0b05f81ef42 100644 --- a/mysql-test/t/type_timestamp_hires.test +++ b/mysql-test/t/type_timestamp_hires.test @@ -17,15 +17,26 @@ drop table t1; # # MDEV-438 Microseconds: Precision is ignored in CURRENT_TIMESTAMP(N) when it is given as a default column value # -create table t1 (a timestamp(5) default current_timestamp); drop table t1; -create table t1 (a timestamp(5) default current_timestamp()); drop table t1; ---error ER_INVALID_DEFAULT -create table t1 (a timestamp(5) default current_timestamp(2)); -create table t1 (a timestamp(5) default current_timestamp(5)); drop table t1; -create table t1 (a timestamp(5) default current_timestamp(6)); drop table t1; -create table t1 (a timestamp(5) on update current_timestamp); drop table t1; -create table t1 (a timestamp(5) on update current_timestamp()); drop table t1; +create or replace table t1 (a timestamp(5) default current_timestamp); +show create table t1; +create or replace table t1 (a timestamp(5) default current_timestamp()); +show create table t1; +create or replace table t1 (a timestamp(5) default current_timestamp(2)); +show create table t1; +insert t1 () values (); +select * from t1; +create or replace table t1 (a timestamp(5) default current_timestamp(5)); +show create table t1; +create or replace table t1 (a timestamp(5) default current_timestamp(6)); +show create table t1; +create or replace table t1 (a timestamp(5) on update current_timestamp); +show create table t1; +create or replace table t1 (a timestamp(5) on update current_timestamp()); +show create table t1; --error ER_INVALID_ON_UPDATE -create table t1 (a timestamp(5) on update current_timestamp(3)); -create table t1 (a timestamp(5) on update current_timestamp(5)); drop table t1; -create table t1 (a timestamp(5) on update current_timestamp(6)); drop table t1; +create or replace table t1 (a timestamp(5) on update current_timestamp(3)); +create or replace table t1 (a timestamp(5) on update current_timestamp(5)); +show create table t1; +create or replace table t1 (a timestamp(5) on update current_timestamp(6)); +show create table t1; +drop table t1; diff --git a/mysql-test/t/type_year.test b/mysql-test/t/type_year.test index d9fa2af1eb4..22f164a757c 100644 --- a/mysql-test/t/type_year.test +++ b/mysql-test/t/type_year.test @@ -210,3 +210,45 @@ DROP TABLE t1; --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-9392 Copying from DECIMAL to YEAR is not consistent about warnings +--echo # +CREATE TABLE t1 (a YEAR); +INSERT INTO t1 VALUES (-0.1); +DROP TABLE t1; + +CREATE TABLE t1 (a YEAR); +CREATE TABLE t2 (a DECIMAL(10,1)); +INSERT INTO t2 VALUES (-0.1); +INSERT INTO t1 SELECT * FROM t2; +DROP TABLE t1,t2; + +CREATE TABLE t1 (a DECIMAL(10,1)); +INSERT INTO t1 VALUES (-0.1); +ALTER TABLE t1 MODIFY a YEAR; +DROP TABLE t1; + +CREATE TABLE t1 (a YEAR); +INSERT INTO t1 VALUES (-0.1e0); +DROP TABLE t1; + +CREATE TABLE t1 (a YEAR); +CREATE TABLE t2 (a DOUBLE); +INSERT INTO t2 VALUES (-0.1); +INSERT INTO t1 SELECT * FROM t2; +DROP TABLE t1,t2; + +CREATE TABLE t1 (a DOUBLE); +INSERT INTO t1 VALUES (-0.1); +ALTER TABLE t1 MODIFY a YEAR; +DROP TABLE t1; + + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/udf.test b/mysql-test/t/udf.test index 4ee412f80d8..42a813b0782 100644 --- a/mysql-test/t/udf.test +++ b/mysql-test/t/udf.test @@ -512,3 +512,19 @@ DROP TABLE t1; --echo # --echo End of 5.1 tests. +--echo # +--echo # MDEV-10134 Add full support for DEFAULT +--echo # + +--replace_result $UDF_EXAMPLE_SO UDF_EXAMPLE_LIB +eval CREATE FUNCTION metaphon RETURNS STRING SONAME "$UDF_EXAMPLE_SO"; +SELECT METAPHON('Hello'); +CREATE TABLE t1 (a VARCHAR(10), b VARCHAR(10) DEFAULT METAPHON(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('Hello'); +SELECT * FROM t1; +DROP FUNCTION METAPHON; +# QQ: this should return an error +#INSERT INTO t1 (a) VALUES ('Hello'); +#SELECT * FROM t1; +DROP TABLE t1; diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test index 0580ee305c3..e0c011e3d20 100644 --- a/mysql-test/t/union.test +++ b/mysql-test/t/union.test @@ -50,13 +50,13 @@ explain select 1 union select a,b from t1 union select 1; --error 1222 explain select a,b from t1 union select 1 limit 0; ---error 1221 +--error ER_PARSE_ERROR select a,b from t1 into outfile 'skr' union select a,b from t2; ---error 1221 +--error ER_PARSE_ERROR select a,b from t1 order by a union select a,b from t2; ---error 1221 +--error ER_PARSE_ERROR insert into t3 select a from t1 order by a union select a from t2; --error 1222 @@ -236,7 +236,7 @@ SELECT COUNT(*) FROM ( select found_rows(); # In these case found_rows() should work ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1 UNION all SELECT * FROM t2 LIMIT 2; SELECT SQL_CALC_FOUND_ROWS * FROM t1 UNION all SELECT * FROM t2 LIMIT 2; select found_rows(); @@ -253,17 +253,17 @@ SELECT COUNT(*) FROM ( SELECT * FROM t1 UNION all SELECT * FROM t2) q; SELECT SQL_CALC_FOUND_ROWS * FROM t1 UNION SELECT * FROM t2 LIMIT 100; select found_rows(); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 100 UNION SELECT * FROM t2; SELECT COUNT(*) FROM ( (SELECT * FROM t1 LIMIT 100) UNION SELECT * FROM t2) q; (SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 100) UNION SELECT * FROM t2; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1 UNION SELECT * FROM t2; SELECT COUNT(*) FROM ( (SELECT * FROM t1 LIMIT 1) UNION SELECT * FROM t2) q; (SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1) UNION SELECT * FROM t2; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1 UNION SELECT * FROM t2 LIMIT 2; SELECT COUNT(*) FROM ( (SELECT * FROM t1 LIMIT 1) UNION SELECT * FROM t2) q; @@ -272,7 +272,7 @@ SELECT SQL_CALC_FOUND_ROWS * FROM t1 UNION SELECT * FROM t2 LIMIT 2,2; select found_rows(); SELECT COUNT(*) FROM ( SELECT * FROM t1 UNION SELECT * FROM t2) q; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR SELECT SQL_CALC_FOUND_ROWS * FROM t1 limit 2,2 UNION SELECT * FROM t2; SELECT COUNT(*) FROM ( (SELECT * FROM t1 limit 2,2) UNION SELECT * FROM t2) q; @@ -999,7 +999,7 @@ SELECT a,1 FROM t1 UNION (SELECT b, COUNT(*) FROM t2 GROUP BY b WITH ROLLUP ORDER BY a); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR SELECT a,1 FROM t1 UNION ALL SELECT b, COUNT(*) FROM t2 GROUP BY b WITH ROLLUP ORDER BY a @@ -1086,11 +1086,11 @@ SELECT a INTO DUMPFILE 'union.out.file2' FROM ( SELECT a FROM t1 UNION SELECT a INTO @v FROM t1; SELECT a FROM t1 UNION SELECT a INTO OUTFILE 'union.out.file5' FROM t1; SELECT a FROM t1 UNION SELECT a INTO OUTFILE 'union.out.file6' FROM t1; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR SELECT a INTO @v FROM t1 UNION SELECT a FROM t1; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR SELECT a INTO OUTFILE 'union.out.file7' FROM t1 UNION SELECT a FROM t1; ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR SELECT a INTO DUMPFILE 'union.out.file8' FROM t1 UNION SELECT a FROM t1; -- echo # Tests fix in parser rule query_expression_body. diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test index 8f29528ac25..ed6e92f145e 100644 --- a/mysql-test/t/variables.test +++ b/mysql-test/t/variables.test @@ -562,7 +562,6 @@ select @@lc_time_names; select @@global.lc_time_names, @@lc_time_names; set @@global.lc_time_names=fr_FR; select @@global.lc_time_names, @@lc_time_names; ---echo New connection connect (con1,localhost,root,,); connection con1; select @@global.lc_time_names, @@lc_time_names; @@ -570,7 +569,6 @@ set @@lc_time_names=ru_RU; select @@global.lc_time_names, @@lc_time_names; disconnect con1; connection default; ---echo Returnung to default connection select @@global.lc_time_names, @@lc_time_names; set lc_time_names=default; select @@global.lc_time_names, @@lc_time_names; @@ -1534,3 +1532,11 @@ show global status like 'foobar'; select * from information_schema.session_variables where variable_name='sql_mode'; --echo End of 5.5 tests + +# +# test Item_func_get_system_var::print() +# +explain extended select @@VERsion from dual where rand() > @@verSION; +explain extended select @@SESsion.SQL_mode from dual where rand() > @@sesSION.sql_MODE; +explain extended select @@GLObal.COLLATION_connection from dual where rand() > @@gloBAL.collation_CONNECTION; +explain extended select @@FOObar.KEY_BUFfer_size from dual where rand() > @@fooBAR.key_bufFER_SIZE; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index e9d091202d5..af509eb7b85 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -840,15 +840,16 @@ drop view v4, v3, v2, v1; # # VIEW over SELECT with prohibited clauses # --- error ER_VIEW_SELECT_CLAUSE +-- error ER_PARSE_ERROR create view v1 as select 5 into @w; --- error ER_VIEW_SELECT_CLAUSE +-- error ER_PARSE_ERROR create view v1 as select 5 into outfile 'ttt'; create table t1 (a int); --- error ER_VIEW_SELECT_CLAUSE +-- error ER_PARSE_ERROR create view v1 as select a from t1 procedure analyse(); --- error ER_VIEW_SELECT_DERIVED +# now derived tables are allowed create view v1 as select 1 from (select 1) as d1; +drop view v1; drop table t1; # @@ -3173,10 +3174,10 @@ DROP TABLE t1; DROP VIEW IF EXISTS v1; --enable_warnings -let $query = SELECT * FROM (SELECT 1) AS t; +let $query = SELECT * FROM (SELECT 1) AS t into @w; eval $query; ---error ER_VIEW_SELECT_DERIVED +--error ER_PARSE_ERROR eval CREATE VIEW v1 AS $query; --echo # Previously the following would fail. eval $query; @@ -4635,7 +4636,6 @@ DROP TABLE t1, t2; --echo # --disable_warnings -DROP TABLE IF EXISTS t1; DROP VIEW IF EXISTS v1; DROP PROCEDURE IF EXISTS p1; --enable_warnings @@ -4643,60 +4643,56 @@ DROP PROCEDURE IF EXISTS p1; connect (con2, localhost, root); connect (con3, localhost, root); ---echo # Connection default connection default; CREATE VIEW v1 AS SELECT schema_name FROM information_schema.schemata; -CREATE TABLE t1 (str VARCHAR(50)); -CREATE PROCEDURE p1() INSERT INTO t1 SELECT * FROM v1; +CREATE PROCEDURE p1() SELECT COUNT(*), GET_LOCK('blocker', 100) FROM v1; --echo # CALL p1() so the view is merged. +--disable_result_log CALL p1(); +--enable_result_log +SELECT RELEASE_LOCK('blocker'); ---echo # Connection 3 connection con3; -LOCK TABLE t1 READ; +SELECT GET_LOCK('blocker', 100); ---echo # Connection default connection default; ---echo # Try to CALL p1() again, this time it should block for t1. +--echo # Try to CALL p1() again, this time it should block on "blocker". --echo # Sending: --send CALL p1() ---echo # Connection 2 connection con2; let $wait_condition= SELECT COUNT(*) = 1 from information_schema.processlist - WHERE state = "Waiting for table level lock" AND - info = "INSERT INTO t1 SELECT * FROM v1"; + WHERE state = "User lock" AND + info = "SELECT COUNT(*), GET_LOCK('blocker', 100) FROM v1"; --source include/wait_condition.inc --echo # ... then try to drop the view. This should block. --echo # Sending: --send DROP VIEW v1 ---echo # Connection 3 connection con3; let $wait_condition= SELECT COUNT(*) = 1 from information_schema.processlist WHERE state = "Waiting for table metadata lock" AND info = "DROP VIEW v1"; --source include/wait_condition.inc --echo # Now allow CALL p1() to complete -UNLOCK TABLES; +SELECT RELEASE_LOCK('blocker'); ---echo # Connection default connection default; --echo # Reaping: CALL p1() +--disable_result_log --reap +--enable_result_log +SELECT RELEASE_LOCK('blocker'); ---echo # Connection 2 connection con2; --echo # Reaping: DROP VIEW v1 --reap ---echo # Connection default connection default; DROP PROCEDURE p1; -DROP TABLE t1; disconnect con2; disconnect con3; @@ -5805,3 +5801,269 @@ drop table t1; --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # Checking that SHOW CREATE VIEW preserve parentheses + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (10),(20),(30); + +CREATE VIEW v1 AS SELECT 1 AS a UNION SELECT a FROM t1; +SHOW CREATE VIEW v1; +SELECT * FROM v1; +DROP VIEW v1; + +CREATE VIEW v1 AS SELECT 1 AS a UNION SELECT a FROM t1 LIMIT 1; +SHOW CREATE VIEW v1; +SELECT * FROM v1; +DROP VIEW v1; + +CREATE VIEW v1 AS SELECT 1 AS a UNION (SELECT a FROM t1); +SHOW CREATE VIEW v1; +SELECT * FROM v1; +DROP VIEW v1; + +CREATE VIEW v1 AS SELECT 1 AS a UNION (SELECT a FROM t1 LIMIT 1); +SHOW CREATE VIEW v1; +SELECT * FROM v1; +DROP VIEW v1; + +CREATE VIEW v1 AS SELECT 1 AS a UNION (SELECT a FROM t1) LIMIT 1; +SHOW CREATE VIEW v1; +SELECT * FROM v1; +DROP VIEW v1; + +DROP TABLE t1; + + +--echo # +--echo # MDEV-9408 CREATE TABLE SELECT MAX(int_column) creates different columns for table vs view +--echo # +CREATE TABLE t1 ( + id int(11) NOT NULL PRIMARY KEY, + country varchar(32), + code int(11) default NULL +); +INSERT INTO t1 VALUES (1,'ITALY',100),(2,'ITALY',200),(3,'FRANCE',100), (4,'ITALY',100); +CREATE VIEW v1 AS SELECT * FROM t1; +CREATE TABLE t2 AS +SELECT code, COUNT(DISTINCT country), MAX(id) FROM t1 GROUP BY code ORDER BY MAX(id); +SHOW CREATE TABLE t2; +CREATE TABLE t3 AS +SELECT code, COUNT(DISTINCT country), MAX(id) FROM v1 GROUP BY code ORDER BY MAX(id); +SHOW CREATE TABLE t3; +DROP VIEW v1; +DROP TABLE t1,t2,t3; + +--echo # +--echo # MDEV-3944: Allow derived tables in VIEWS +--echo # +create table t1 (s1 int); +insert into t1 values (1),(2),(3); + +CREATE VIEW v1 AS SELECT * FROM (SELECT s1 FROM t1 WHERE s1>1) AS x; +CREATE VIEW v2 AS SELECT * FROM (SELECT s1 FROM t1 WHERE s1<3) AS x; + +--sorted_result +select * from v1; +--sorted_result +select * from v2; +--sorted_result +select * from v1 natural join v2; +--sorted_result +select * from v1 natural join t1; +--sorted_result +select * from v1 natural join (SELECT s1 FROM t1 WHERE s1<3) as x; +--sorted_result +select * from v1 left join v2 on (v1.s1=v2.s1); +--sorted_result +select * from v1 left join t1 on (v1.s1=t1.s1); +--sorted_result +select * from t1 left join v2 on (t1.s1=v2.s1); +--sorted_result +select * from v1 left join (SELECT s1 FROM t1 WHERE s1<3) as x on (v1.s1=x.s1); +--sorted_result +select * from (SELECT s1 FROM t1 WHERE s1>1) AS x left join v2 on (x.s1=v2.s1); + +drop view v1,v2; + +CREATE VIEW v1 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1 +< 100) as xx WHERE s1>1) AS x; +CREATE VIEW v2 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1 +> -100) as xx WHERE s1<3) AS x; +insert into t1 values (200),(-200); +--sorted_result +select * from t1; +--sorted_result +select * from v1; +--sorted_result +select * from v2; +--sorted_result +select * from v1 natural join v2; +--sorted_result +select * from v1 natural join t1; +--sorted_result +select * from v1 natural join (SELECT s1 FROM t1 WHERE s1<3) as x; +--sorted_result +select * from v1 left join v2 on (v1.s1=v2.s1); +--sorted_result +select * from v1 left join t1 on (v1.s1=t1.s1); +--sorted_result +select * from t1 left join v2 on (t1.s1=v2.s1); +--sorted_result +select * from v1 left join (SELECT s1 FROM t1 WHERE s1<3) as x on (v1.s1=x.s1); +--sorted_result +select * from (SELECT s1 FROM t1 WHERE s1>1) AS x left join v2 on (x.s1=v2.s1); + +drop view v1,v2; + +CREATE algorithm=temptable VIEW v1 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1 +< 100) as xx WHERE s1>1) AS x; +CREATE algorithm=temptable VIEW v2 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1 +> -100) as xx WHERE s1<3) AS x; +--sorted_result +select * from t1; +--sorted_result +select * from v1; +--sorted_result +select * from v2; +--sorted_result +select * from v1 natural join v2; +--sorted_result +select * from v1 natural join t1; +--sorted_result +select * from v1 natural join (SELECT s1 FROM t1 WHERE s1<3) as x; +--sorted_result +select * from v1 left join v2 on (v1.s1=v2.s1); +--sorted_result +select * from v1 left join t1 on (v1.s1=t1.s1); +--sorted_result +select * from t1 left join v2 on (t1.s1=v2.s1); +--sorted_result +select * from v1 left join (SELECT s1 FROM t1 WHERE s1<3) as x on (v1.s1=x.s1); +--sorted_result +select * from (SELECT s1 FROM t1 WHERE s1>1) AS x left join v2 on (x.s1=v2.s1); + +drop view v1,v2; + +CREATE VIEW v1 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1 +< 100) as xx WHERE s1>1) AS x; + +--error ER_NON_INSERTABLE_TABLE +insert into v1 values (-300); +--error ER_NON_UPDATABLE_TABLE +update v1 set s1=s1+1; + +drop view v1; + +CREATE VIEW v1 AS SELECT s1,s2 FROM (SELECT s1 as s2 FROM t1 WHERE s1 < +100) x, t1 WHERE t1.s1=x.s2; +select * from v1; + +insert into v1 (s1) values (-300); +update v1 set s1=s1+1; +select * from v1; +select * from t1; +--error ER_NON_INSERTABLE_TABLE +insert into v1(s2) values (-300); +--error ER_NON_UPDATABLE_TABLE +update v1 set s2=s2+1; + +drop view v1; + +CREATE VIEW v1 AS SELECT * FROM (SELECT s1 FROM t1 WHERE s1 +< 100) AS x; + +--error ER_NON_INSERTABLE_TABLE +insert into v1 values (-300); +--error ER_NON_UPDATABLE_TABLE +update v1 set s1=s1+1; + +drop view v1; + +CREATE VIEW v1 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1 +< 100) as xx WHERE s1>1) AS x; + +--error ER_NON_INSERTABLE_TABLE +insert into v1 values (-300); +--error ER_NON_UPDATABLE_TABLE +update v1 set s1=s1+1; + +create view v2 as select * from v1; + +--error ER_NON_INSERTABLE_TABLE +insert into v2 values (-300); +--error ER_NON_UPDATABLE_TABLE +update v2 set s1=s1+1; + +drop view v1, v2; +drop table t1; + +--echo # +--echo # MDEV-9671:Wrong result upon select from a view with a FROM subquery +--echo # +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (3),(2); + +CREATE TABLE t2 (j INT); +INSERT INTO t2 VALUES (8),(3),(3); + +CREATE TABLE t3 (k INT); +INSERT INTO t3 VALUES (1),(8); + +CREATE VIEW v1 AS SELECT * FROM t1 LEFT JOIN ( SELECT t2.* FROM t2 INNER JOIN t3 ON ( k = j ) ) AS alias1 ON ( i = j ); + +show create view v1; + +SELECT * FROM t1 LEFT JOIN ( SELECT t2.* FROM t2 INNER JOIN t3 ON ( k = j ) ) AS alias1 ON ( i = j ); + +SELECT * FROM v1; + +DROP VIEW v1; +DROP TABLE t1, t2, t3; + +--echo # +--echo # MDEV-10035: DBUG_ASSERT on CREATE VIEW v1 AS SELECT * FROM t1 +--echo # FOR UPDATE +--echo # + +CREATE TABLE t1 (a INT); +insert into t1 values (1),(2); + +CREATE VIEW v1 AS SELECT * FROM t1 FOR UPDATE; +SHOW CREATE VIEW v1; +select * from v1; +DROP VIEW v1; + +CREATE VIEW v1 AS SELECT * FROM t1 LOCK IN SHARE MODE; +SHOW CREATE VIEW v1; +select * from v1; +DROP VIEW v1; + +DROP TABLE t1; + +--echo # +--echo # MDEV-10724:Assertion `vcol_table == 0 || vcol_table == table' +--echo # failed in fill_record(THD*, TABLE*, List<Item>&, List<Item>&, +--echo # bool, bool) +--echo # + +CREATE TABLE t1 (f1 INT); +CREATE TABLE t2 (f2 INT); +CREATE TABLE t3 (f3 INT); + +CREATE ALGORITHM = MERGE VIEW v AS SELECT f1, f3 FROM t1, +( SELECT f3 FROM t2, t3 ) AS sq; + +--error ER_VIEW_MULTIUPDATE +INSERT INTO v (f1, f3) VALUES (1,1), (2,2); + +drop view v; +drop tables t1,t2,t3; + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/view_grant.test b/mysql-test/t/view_grant.test index 6d0cd8e5c28..a70241138aa 100644 --- a/mysql-test/t/view_grant.test +++ b/mysql-test/t/view_grant.test @@ -1197,8 +1197,6 @@ GRANT SELECT, DELETE ON mysqltest1.t4 TO mysqltest_u1@localhost; GRANT ALL PRIVILEGES ON mysqltest2.* TO mysqltest_u1@localhost; --connect (bug24040_con,localhost,mysqltest_u1,,mysqltest2) ---echo ---echo ---> connection: bug24040_con SELECT * FROM mysqltest1.t1; INSERT INTO mysqltest1.t2 VALUES(25); @@ -1238,8 +1236,6 @@ CREATE VIEW v42 AS SELECT c4, c2 FROM mysqltest1.t4, mysqltest1.t2; CREATE VIEW v43 AS SELECT c4, c3 FROM mysqltest1.t4, mysqltest1.t3; --connection default ---echo ---echo ---> connection: default SELECT * FROM mysqltest1.t1; SELECT * FROM mysqltest1.t2; @@ -1965,13 +1961,9 @@ GRANT SELECT ON t1 TO 'mysqluser1'@'%'; GRANT SELECT ON t2 TO 'mysqluser1'@'%'; GRANT SELECT ON v1_uses_t1 TO 'mysqluser1'@'%'; GRANT SELECT ON v1_uses_t2 TO 'mysqluser1'@'%'; ---echo # ---echo # Connection 'mysqluser1'. --connect (mysqluser1, localhost, mysqluser1,,mysqltest1) CREATE SQL SECURITY DEFINER VIEW v2_uses_t1 AS SELECT * FROM v1_uses_t1; CREATE SQL SECURITY DEFINER VIEW v2_uses_t2 AS SELECT * FROM v1_uses_t2; ---echo # ---echo # Connection 'default'. --connection default CREATE USER 'mysqluser2'@'%'; GRANT SELECT ON v2_uses_t1 TO 'mysqluser2'@'%'; @@ -1980,8 +1972,6 @@ GRANT SELECT ON t2 TO 'mysqluser2'@'%'; GRANT CREATE VIEW ON mysqltest1.* TO 'mysqluser2'@'%'; --echo # Make 'mysqluser1' unable to access t2. REVOKE SELECT ON t2 FROM 'mysqluser1'@'%'; ---echo # ---echo # Connection 'mysqluser2'. --connect (mysqluser2, localhost, mysqluser2,,mysqltest1) --echo # The below statement should succeed thanks to suid nature of v2_uses_t1. SELECT * FROM v2_uses_t1; @@ -1990,8 +1980,6 @@ SELECT * FROM v2_uses_t1; SELECT * FROM v2_uses_t2; --echo # --echo # 2) INVOKER-security view uses INVOKER-security view. ---echo # ---echo # Connection 'default'. --connection default DROP VIEW v2_uses_t1, v2_uses_t2; CREATE SQL SECURITY INVOKER VIEW v2_uses_t1 AS SELECT * FROM v1_uses_t1; @@ -2000,15 +1988,11 @@ GRANT SELECT ON v2_uses_t1 TO 'mysqluser1'@'%'; GRANT SELECT ON v2_uses_t2 TO 'mysqluser1'@'%'; GRANT SELECT ON v1_uses_t1 TO 'mysqluser2'@'%'; GRANT SELECT ON v1_uses_t2 TO 'mysqluser2'@'%'; ---echo # ---echo # Connection 'mysqluser1'. --connection mysqluser1 --echo # For both versions of 'v2' 'mysqluser1' privileges should be used. SELECT * FROM v2_uses_t1; --error ER_VIEW_INVALID SELECT * FROM v2_uses_t2; ---echo # ---echo # Connection 'mysqluser2'. --connection mysqluser2 --echo # And now for both versions of 'v2' 'mysqluser2' privileges should --echo # be used. @@ -2017,24 +2001,16 @@ SELECT * FROM v2_uses_t1; SELECT * FROM v2_uses_t2; --echo # --echo # 3) INVOKER-security view uses DEFINER-security view. ---echo # ---echo # Connection 'default'. --connection default DROP VIEW v1_uses_t1, v1_uses_t2; --echo # To be able create 'v1_uses_t2' we also need select on t2. GRANT SELECT ON t2 TO 'mysqluser1'@'%'; ---echo # ---echo # Connection 'mysqluser1'. --connection mysqluser1 CREATE SQL SECURITY DEFINER VIEW v1_uses_t1 AS SELECT * FROM t1; CREATE SQL SECURITY DEFINER VIEW v1_uses_t2 AS SELECT * FROM t2; ---echo # ---echo # Connection 'default'. --connection default --echo # Make 'mysqluser1' unable to access t2. REVOKE SELECT ON t2 FROM 'mysqluser1'@'%'; ---echo # ---echo # Connection 'mysqluser2'. --connection mysqluser2 --echo # Due to suid nature of v1_uses_t1 and v1_uses_t2 the first --echo # select should succeed and the second select should fail. @@ -2043,24 +2019,16 @@ SELECT * FROM v2_uses_t1; SELECT * FROM v2_uses_t2; --echo # --echo # 4) DEFINER-security view uses DEFINER-security view. ---echo # ---echo # Connection 'default'. --connection default DROP VIEW v2_uses_t1, v2_uses_t2; --echo # To be able create 'v2_uses_t2' we also need select on t2. GRANT SELECT ON t2 TO 'mysqluser1'@'%'; ---echo # ---echo # Connection 'mysqluser2'. --connection mysqluser2 CREATE SQL SECURITY DEFINER VIEW v2_uses_t1 AS SELECT * FROM v1_uses_t1; CREATE SQL SECURITY DEFINER VIEW v2_uses_t2 AS SELECT * FROM v1_uses_t2; ---echo # ---echo # Connection 'default'. --connection default --echo # Make 'mysqluser1' unable to access t2. REVOKE SELECT ON t2 FROM 'mysqluser1'@'%'; ---echo # ---echo # Connection 'mysqluser2'. --connection mysqluser2 --echo # Again privileges of creator of innermost views should apply. SELECT * FROM v2_uses_t1; @@ -2132,8 +2100,6 @@ create sql security invoker view v42 as where t2.id = v2.id; ---echo # ---echo # Connect as user_11766767 connect (conn_11766767, localhost, user_11766767,,); --echo # @@ -2231,7 +2197,6 @@ update mysqltest1.t11 as t11, mysqltest2.v42 as v4 set v4.val= 'test20' --echo # --echo # Clean-up. --echo # ---echo # Switching to connection 'default'. disconnect conn_11766767; connection default; drop user user_11766767; diff --git a/mysql-test/t/wait_timeout.test b/mysql-test/t/wait_timeout.test index 68c0957347d..4ece5fd1749 100644 --- a/mysql-test/t/wait_timeout.test +++ b/mysql-test/t/wait_timeout.test @@ -19,14 +19,12 @@ let $start_value= `SELECT @@global.wait_timeout`; SET @@global.wait_timeout= 2; ---echo disconnect default; disconnect default; # Connect with another connection and reset counters ---disable_query_log connect (wait_con,localhost,root,,test,,); ---echo connection wait_con; connection wait_con; +--disable_query_log SET SESSION wait_timeout=100; let $retries=300; SET @aborted_clients= 0; @@ -34,16 +32,14 @@ SET @aborted_clients= 0; # Disable reconnect and do the query connect (default,localhost,root,,test,,); ---echo connection default; connection default; --echo --disable_reconnect; --disable_reconnect SELECT 1; # Switch to wait_con and wait until server has aborted the connection ---disable_query_log ---echo connection wait_con; connection wait_con; +--disable_query_log while (!`select @aborted_clients`) { real_sleep 0.1; @@ -61,7 +57,6 @@ while (!`select @aborted_clients`) # the disconnect has reached client let $wait_condition= SELECT COUNT(*)=1 FROM information_schema.processlist; --source include/wait_condition.inc ---echo connection default; connection default; # When the connection is closed in this way, the error code should # be consistent see Bug#2845 for an explanation @@ -73,7 +68,6 @@ SELECT 2; SELECT 3; # Disconnect so that we will not be confused by a future abort from this # connection. ---echo disconnection default; disconnect default; # @@ -81,24 +75,21 @@ disconnect default; # (which we get by specifying an ip adress) # Connect with another connection and reset counters ---disable_query_log ---echo connection wait_con; connection wait_con; +--disable_query_log FLUSH STATUS; # Reset counters let $retries=300; SET @aborted_clients= 0; --enable_query_log ---echo connection con1; connect (con1,127.0.0.1,root,,test,$MASTER_MYPORT,); --echo --disable_reconnect; --disable_reconnect SELECT 1; # Switch to wait_con and wait until server has aborted the connection ---disable_query_log ---echo connection wait_con; connection wait_con; +--disable_query_log while (!`select @aborted_clients`) { real_sleep 0.1; @@ -118,7 +109,6 @@ let $wait_condition= SELECT COUNT(*)=1 FROM information_schema.processlist; --source include/wait_condition.inc disconnect wait_con; ---echo connection con1; connection con1; # When the connection is closed in this way, the error code should # be consistent see Bug#2845 for an explanation @@ -130,7 +120,6 @@ SELECT 2; SELECT 3; --replace_result $start_value <start_value> eval SET @@global.wait_timeout= $start_value; ---echo disconnection con1; disconnect con1; diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test new file mode 100644 index 00000000000..7052368cf9c --- /dev/null +++ b/mysql-test/t/win.test @@ -0,0 +1,1428 @@ +# +# Window Functions Tests +# + +--disable_warnings +drop table if exists t1,t2; +drop view if exists v1; +--enable_warnings + +--echo # ######################################################################## +--echo # # Parser tests +--echo # ######################################################################## +--echo # +--echo # Check what happens when one attempts to use window function without OVER clause +create table t1 (a int, b int); +insert into t1 values (1,1),(2,2); + +--error ER_PARSE_ERROR +select row_number() from t1; +--error ER_PARSE_ERROR +select rank() from t1; + +--echo # Attempt to use window function in the WHERE clause +--error ER_WRONG_PLACEMENT_OF_WINDOW_FUNCTION +select * from t1 where 1=rank() over (order by a); +--error ER_WRONG_PLACEMENT_OF_WINDOW_FUNCTION +select * from t1 where 1>row_number() over (partition by b order by a); +drop table t1; + +--echo # ######################################################################## +--echo # # Functionality tests +--echo # ######################################################################## +--echo # +--echo # Check if ROW_NUMBER() works in basic cases +create table t1(a int, b int, x char(32)); +insert into t1 values (2, 10, 'xx'); +insert into t1 values (2, 10, 'zz'); +insert into t1 values (2, 20, 'yy'); +insert into t1 values (3, 10, 'xxx'); +insert into t1 values (3, 20, 'vvv'); + +--sorted_result +select a, row_number() over (partition by a order by b) from t1; + +select a, b, x, row_number() over (partition by a order by x) from t1; + +drop table t1; + +create table t1 (pk int primary key, a int, b int); +insert into t1 values + (1, 10, 22), + (2, 11, 21), + (3, 12, 20), + (4, 13, 19), + (5, 14, 18); + +select + pk, a, b, + row_number() over (order by a), + row_number() over (order by b) +from t1; + +drop table t1; + +--echo # +--echo # Try RANK() function +--echo # +create table t2 ( + pk int primary key, + a int +); + +insert into t2 values +( 1 , 0), +( 2 , 0), +( 3 , 1), +( 4 , 1), +( 8 , 2), +( 5 , 2), +( 6 , 2), +( 7 , 2), +( 9 , 4), +(10 , 4); + +--sorted_result +select pk, a, rank() over (order by a) from t2; +--sorted_result +select pk, a, rank() over (order by a desc) from t2; + +drop table t2; + +--echo # +--echo # Try Aggregates as window functions. With frames. +--echo # +create table t0 (a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t1 (pk int, c int); +insert into t1 select a+1,1 from t0; +update t1 set c=2 where pk not in (1,2,3,4); +select * from t1; + +select + pk, c, + count(*) over (partition by c order by pk + rows between 2 preceding and 2 following) as CNT +from t1; + +select + pk, c, + count(*) over (partition by c order by pk + rows between 1 preceding and 2 following) as CNT +from t1; + +select + pk, c, + count(*) over (partition by c order by pk + rows between 2 preceding and current row) as CNT +from t1; + +select + pk,c, + count(*) over (partition by c order by pk rows + between 1 following and 2 following) as CNT +from t1; + +select + pk,c, + count(*) over (partition by c order by pk rows + between 2 preceding and 1 preceding) as CNT +from t1; + +select + pk, c, + count(*) over (partition by c order by pk + rows between current row and 1 following) as CNT +from t1; + +--echo # Check ORDER BY DESC +select + pk, c, + count(*) over (partition by c order by pk desc + rows between 2 preceding and 2 following) as CNT +from t1; + +drop table t0,t1; + +--echo # +--echo # Resolution of window names +--echo # + +create table t0 (a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t1 (pk int, c int); +insert into t1 select a+1,1 from t0; +update t1 set c=2 where pk not in (1,2,3,4); +select * from t1; + +select + pk, c, + count(*) over w1 as CNT +from t1 +window w1 as (partition by c order by pk + rows between 2 preceding and 2 following); + +select + pk, c, + count(*) over (w1 rows between 2 preceding and 2 following) as CNT +from t1 +window w1 as (partition by c order by pk); + +select + pk, c, + count(*) over (w1 order by pk rows between 2 preceding and 2 following) as CNT +from t1 +window w1 as (partition by c); + +select + pk, c, + count(*) over (w2 rows between 2 preceding and 2 following) as CNT +from t1 +window w1 as (partition by c), w2 as (w1 order by pk); + +select + pk, c, + count(*) over w3 as CNT +from t1 +window + w1 as (partition by c), + w2 as (w1 order by pk), + w3 as (w2 rows between 2 preceding and 2 following); + +--error ER_WRONG_WINDOW_SPEC_NAME +select + pk, c, + count(*) over w as CNT +from t1 +window w1 as (partition by c order by pk + rows between 2 preceding and 2 following); + +--error ER_DUP_WINDOW_NAME +select + pk, c, + count(*) over (w2 rows between 2 preceding and 2 following) as CNT +from t1 +window w1 as (partition by c), w1 as (order by pk); + +--error ER_WRONG_WINDOW_SPEC_NAME +select + pk, c, + count(*) over (w2 rows between 2 preceding and 2 following) as CNT +from t1 +window w1 as (partition by c), w2 as (w partition by c order by pk); + +--error ER_PARTITION_LIST_IN_REFERENCING_WINDOW_SPEC +select + pk, c, + count(*) over (w2 rows between 2 preceding and 2 following) as CNT +from t1 +window w1 as (partition by c), w2 as (w1 partition by c order by pk); + +--error ER_ORDER_LIST_IN_REFERENCING_WINDOW_SPEC +select + pk, c, + count(*) over (w2 rows between 2 preceding and 2 following) as CNT +from t1 +window w1 as (partition by c order by pk), w2 as (w1 order by pk); + +--error ER_WINDOW_FRAME_IN_REFERENCED_WINDOW_SPEC +select + pk, c, + count(*) over w3 as CNT +from t1 +window + w1 as (partition by c), + w2 as (w1 order by pk rows between 3 preceding and 2 following), + w3 as (w2 rows between 2 preceding and 2 following); + +--error ER_BAD_COMBINATION_OF_WINDOW_FRAME_BOUND_SPECS +select + pk, c, + count(*) over w1 as CNT +from t1 +window w1 as (partition by c order by pk + rows between unbounded following and 2 following); + +--error ER_BAD_COMBINATION_OF_WINDOW_FRAME_BOUND_SPECS +select + pk, c, + count(*) over (w1 rows between 2 preceding and unbounded preceding) as CNT +from t1 +window w1 as (partition by c order by pk); + +--error ER_BAD_COMBINATION_OF_WINDOW_FRAME_BOUND_SPECS +select + pk, c, + count(*) over (w1 order by pk rows between current row and 2 preceding) as CNT +from t1 +window w1 as (partition by c); + +--error ER_BAD_COMBINATION_OF_WINDOW_FRAME_BOUND_SPECS +select + pk, c, + count(*) over (w2 rows between 2 following and current row) as CNT +from t1 +window w1 as (partition by c), w2 as (w1 order by pk); + +--error ER_WRONG_PLACEMENT_OF_WINDOW_FUNCTION +select + pk, c +from t1 where rank() over w1 > 2 +window w1 as (partition by c order by pk); + +--error ER_WRONG_PLACEMENT_OF_WINDOW_FUNCTION +select + c, max(pk) as m +from t1 + group by c + rank() over w1 +window w1 as (order by m); + +--error ER_WRONG_PLACEMENT_OF_WINDOW_FUNCTION +select + c, max(pk) as m, rank() over w1 as r +from t1 + group by c+r +window w1 as (order by m); + +--error ER_WRONG_PLACEMENT_OF_WINDOW_FUNCTION +select + c, max(pk) as m, rank() over w1 as r +from t1 + group by c having c+r > 3 +window w1 as (order by m); + +--error ER_WINDOW_FUNCTION_IN_WINDOW_SPEC +select + c, max(pk) as m, rank() over w1 as r, + rank() over (partition by r+1 order by m) +from t1 + group by c +window w1 as (order by m); + +--error ER_WINDOW_FUNCTION_IN_WINDOW_SPEC +select + c, max(pk) as m, rank() over w1 as r, + rank() over (partition by m order by r) +from t1 + group by c +window w1 as (order by m); + +--error ER_WINDOW_FUNCTION_IN_WINDOW_SPEC +select + c, max(pk) as m, rank() over w1 as r, dense_rank() over w2 as dr +from t1 + group by c +window w1 as (order by m), w2 as (partition by r order by m); + +--error ER_NOT_ALLOWED_WINDOW_FRAME +select + pk, c, + row_number() over (partition by c order by pk + range between unbounded preceding and current row) as r +from t1; + +--error ER_NOT_ALLOWED_WINDOW_FRAME +select + pk, c, + rank() over w1 as r +from t1 +window w1 as (partition by c order by pk + rows between 2 preceding and 2 following); + +--error ER_NOT_ALLOWED_WINDOW_FRAME +select + pk, c, + dense_rank() over (partition by c order by pk + rows between 1 preceding and 1 following) as r +from t1; + +--error ER_NO_ORDER_LIST_IN_WINDOW_SPEC +select + pk, c, + rank() over w1 as r +from t1 +window w1 as (partition by c); + +--error ER_NO_ORDER_LIST_IN_WINDOW_SPEC +select + pk, c, + dense_rank() over (partition by c) as r +from t1; + +drop table t0,t1; + +--echo # +--echo # MDEV-9634: Window function produces incorrect value +--echo # + +create table t0 (a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t2 (part_id int, pk int, a int); +insert into t2 select + if(a<5, 0, 1), a, if(a<5, NULL, 1) from t0; +select * from t2; + +select + part_id, pk, a, + count(a) over (partition by part_id order by pk + rows between 1 preceding and 1 following) as CNT +from t2; + +drop table t0, t2; + +--echo # +--echo # RANGE-type bounds +--echo # + +create table t3 ( + pk int, + val int +); + +insert into t3 values +(0, 1), +(1, 1), +(2, 1), +(3, 2), +(4, 2), +(5, 2), +(6, 2); + +select + pk, + val, + count(val) over (order by val + range between current row and + current row) + as CNT +from t3; + +insert into t3 values +(7, 3), +(8, 3); + +select + pk, + val, + count(val) over (order by val + range between current row and + current row) + as CNT +from t3; + +drop table t3; + +--echo # Now, check with PARTITION BY +create table t4 ( + part_id int, + pk int, + val int +); + +insert into t4 values +(1234, 100, 1), +(1234, 101, 1), +(1234, 102, 1), +(1234, 103, 2), +(1234, 104, 2), +(1234, 105, 2), +(1234, 106, 2), +(1234, 107, 3), +(1234, 108, 3), + +(5678, 200, 1), +(5678, 201, 1), +(5678, 202, 1), +(5678, 203, 2), +(5678, 204, 2), +(5678, 205, 2), +(5678, 206, 2), +(5678, 207, 3), +(5678, 208, 3); + +select + part_id, + pk, + val, + count(val) over (partition by part_id + order by val + range between current row and + current row) + as CNT +from t4; + +--echo # +--echo # Try RANGE UNBOUNDED PRECEDING | FOLLOWING +--echo # +select + part_id, + pk, + val, + count(val) over (partition by part_id + order by val + range between unbounded preceding and + current row) + as CNT +from t4; + +select + part_id, + pk, + val, + count(val) over (partition by part_id + order by val + range between current row and + unbounded following) + as CNT +from t4; + +select + part_id, + pk, + val, + count(val) over (partition by part_id + order by val + range between unbounded preceding and + unbounded following) + as CNT +from t4; + +drop table t4; + +--echo # +--echo # MDEV-9695: Wrong window frame when using RANGE BETWEEN N FOLLOWING AND PRECEDING +--echo # +create table t1 (pk int, a int, b int); +insert into t1 values +( 1 , 0, 1), +( 2 , 0, 2), +( 3 , 1, 4), +( 4 , 1, 8), +( 5 , 2, 32), +( 6 , 2, 64), +( 7 , 2, 128), +( 8 , 2, 16); + +select pk, a, b, +bit_or(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as bit_or +from t1; + +--echo # Extra ROWS n PRECEDING tests +select pk, a, b, +bit_or(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) as bit_or +from t1; +drop table t1; + + +create table t2 ( + pk int, + a int, + b int +); + +insert into t2 values +( 1, 0, 1), +( 2, 0, 2), +( 3, 0, 4), +( 4, 0, 8), +( 5, 1, 16), +( 6, 1, 32), +( 7, 1, 64), +( 8, 1, 128), +( 9, 2, 256), +(10, 2, 512), +(11, 2, 1024), +(12, 2, 2048); + +select pk, a, b, +bit_or(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) as bit_or +from t2; + +select pk, a, b, +bit_or(b) over (partition by a order by pk ROWS BETWEEN 2 PRECEDING AND 2 PRECEDING) as bit_or +from t2; + +select pk, a, b, +bit_or(b) over (partition by a order by pk ROWS BETWEEN 2 PRECEDING AND 1 PRECEDING) as bit_or +from t2; + +--echo # Check CURRENT ROW + +select pk, a, b, +bit_or(b) over (partition by a order by pk ROWS BETWEEN CURRENT ROW AND CURRENT ROW) as bit_or +from t2; + +drop table t2; + +--echo # +--echo # Try RANGE PRECEDING|FOLLWING n +--echo # +create table t1 ( + part_id int, + pk int, + a int +); + +insert into t1 values +(10, 1, 1), +(10, 2, 2), +(10, 3, 4), +(10, 4, 8), +(10, 5,26), +(10, 6,27), +(10, 7,40), +(10, 8,71), +(10, 9,72); + +select + pk, a, + count(a) over (ORDER BY a + RANGE BETWEEN UNBOUNDED PRECEDING + AND 10 FOLLOWING) as cnt +from t1; + +select + pk, a, + count(a) over (ORDER BY a DESC + RANGE BETWEEN UNBOUNDED PRECEDING + AND 10 FOLLOWING) as cnt +from t1; + +select + pk, a, + count(a) over (ORDER BY a + RANGE BETWEEN UNBOUNDED PRECEDING + AND 1 FOLLOWING) as cnt +from t1; + +select + pk, a, + count(a) over (ORDER BY a + RANGE BETWEEN UNBOUNDED PRECEDING + AND 10 PRECEDING) as cnt +from t1; + +select + pk, a, + count(a) over (ORDER BY a DESC + RANGE BETWEEN UNBOUNDED PRECEDING + AND 10 PRECEDING) as cnt +from t1; + +select + pk, a, + count(a) over (ORDER BY a + RANGE BETWEEN UNBOUNDED PRECEDING + AND 1 PRECEDING) as cnt +from t1; + +# Try bottom bound +select + pk, a, + count(a) over (ORDER BY a + RANGE BETWEEN 1 PRECEDING + AND CURRENT ROW) as cnt +from t1; + +select + pk, a, + count(a) over (ORDER BY a DESC + RANGE BETWEEN 1 PRECEDING + AND CURRENT ROW) as cnt +from t1; + +select + pk, a, + count(a) over (ORDER BY a + RANGE BETWEEN 1 FOLLOWING + AND 3 FOLLOWING) as cnt +from t1; + +--echo # Try CURRENT ROW with[out] DESC +select + pk, a, + count(a) over (ORDER BY a + RANGE BETWEEN CURRENT ROW + AND 1 FOLLOWING) as cnt +from t1; + +select + pk, a, + count(a) over (order by a desc + range between current row + and 1 following) as cnt +from t1; + + +# Try with partitions +insert into t1 select 22, pk, a from t1; +select + part_id, pk, a, + count(a) over (PARTITION BY part_id + ORDER BY a + RANGE BETWEEN UNBOUNDED PRECEDING + AND 10 FOLLOWING) as cnt +from t1; + +select + pk, a, + count(a) over (PARTITION BY part_id + ORDER BY a + RANGE BETWEEN UNBOUNDED PRECEDING + AND 1 PRECEDING) as cnt +from t1; + +drop table t1; + +--echo # Try a RANGE frame over non-integer datatype: + +create table t1 ( + col1 int, + a decimal(5,3) +); + +insert into t1 values (1, 0.45); +insert into t1 values (1, 0.5); +insert into t1 values (1, 0.55); +insert into t1 values (1, 1.21); +insert into t1 values (1, 1.22); +insert into t1 values (1, 3.33); + +select + a, + count(col1) over (order by a + range between 0.1 preceding + and 0.1 following) +from t1; + +drop table t1; + +--echo # +--echo # RANGE-type frames and NULL values +--echo # +create table t1 ( + pk int, + a int, + b int +); + +insert into t1 values (1, NULL,1); +insert into t1 values (2, NULL,1); +insert into t1 values (3, NULL,1); +insert into t1 values (4, 10 ,1); +insert into t1 values (5, 11 ,1); +insert into t1 values (6, 12 ,1); +insert into t1 values (7, 13 ,1); +insert into t1 values (8, 14 ,1); + + +select + pk, a, + count(b) over (order by a + range between 2 preceding + and 2 following) as CNT +from t1; +drop table t1; + +--echo # +--echo # Try ranges that have bound1 > bound2. The standard actually allows them +--echo # + +create table t0 (a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t1 (pk int, c int); +insert into t1 select a+1,1 from t0; +update t1 set c=2 where pk not in (1,2,3,4); +select * from t1; + +select + pk, c, + count(*) over (partition by c + order by pk + rows between 1 preceding + and 2 preceding) + as cnt +from t1; + +select + pk, c, + sum(c) over (partition by c + order by pk + rows between 1 preceding + and 2 preceding) + as sum +from t1; + +select + pk, c, + sum(c) over (partition by c + order by pk + rows between 2 following + and 1 following) + as sum +from t1; + + +select + pk, c, + count(*) over (partition by c + order by pk + range between 1 preceding + and 2 preceding) + as cnt +from t1; +drop table t0, t1; + +--echo # +--echo # Error checking for frame bounds +--echo # + +create table t1 (a int, b int, c varchar(32)); +insert into t1 values (1,1,'foo'); +insert into t1 values (2,2,'bar'); +--error ER_RANGE_FRAME_NEEDS_SIMPLE_ORDERBY +select + count(*) over (order by a,b + range between unbounded preceding and current row) +from t1; + +--error ER_WRONG_TYPE_FOR_RANGE_FRAME +select + count(*) over (order by c + range between unbounded preceding and current row) +from t1; + +--error ER_WRONG_TYPE_FOR_RANGE_FRAME +select + count(*) over (order by a + range between 'abcd' preceding and current row) +from t1; + +--error ER_WRONG_TYPE_FOR_RANGE_FRAME +select + count(*) over (order by a + range between current row and 'foo' following) +from t1; + +--echo # Try range frame with invalid bounds +--error ER_WRONG_TYPE_FOR_ROWS_FRAME +select + count(*) over (order by a + rows between 0.5 preceding and current row) +from t1; + +--error ER_WRONG_TYPE_FOR_ROWS_FRAME +select + count(*) over (order by a + rows between current row and 3.14 following) +from t1; + +--echo # +--echo # EXCLUDE clause is parsed but not supported +--echo # + +--error ER_FRAME_EXCLUSION_NOT_SUPPORTED +select + count(*) over (order by a + rows between 1 preceding and 1 following + exclude current row) +from t1; + +--error ER_FRAME_EXCLUSION_NOT_SUPPORTED +select + count(*) over (order by a + range between 1 preceding and 1 following + exclude ties) +from t1; + +--error ER_FRAME_EXCLUSION_NOT_SUPPORTED +select + count(*) over (order by a + range between 1 preceding and 1 following + exclude group) +from t1; + +# EXCLUDE NO OTHERS means 'don't exclude anything' +select + count(*) over (order by a + rows between 1 preceding and 1 following + exclude no others) +from t1; + +drop table t1; + +--echo # +--echo # Window function in grouping query +--echo # + +create table t1 ( + username varchar(32), + amount int +); + +insert into t1 values +('user1',1), +('user1',5), +('user1',3), +('user2',10), +('user2',20), +('user2',30); + +select + username, + sum(amount) as s, + rank() over (order by s desc) +from t1 +group by username; + +drop table t1; + +--echo # +--echo # mdev-9719: Window function in prepared statement +--echo # + +create table t1(a int, b int, x char(32)); +insert into t1 values (2, 10, 'xx'); +insert into t1 values (2, 10, 'zz'); +insert into t1 values (2, 20, 'yy'); +insert into t1 values (3, 10, 'xxx'); +insert into t1 values (3, 20, 'vvv'); + +prepare stmt from 'select a, row_number() over (partition by a order by b) from t1'; +--sorted_result +execute stmt; + +drop table t1; + +--echo # +--echo # mdev-9754: Window name resolution in prepared statement +--echo # + +create table t0 (a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t1 (pk int, c int); +insert into t1 select a+1,1 from t0; +update t1 set c=2 where pk not in (1,2,3,4); +select * from t1; + +prepare stmt from +'select + pk, c, + count(*) over w1 as CNT +from t1 +window w1 as (partition by c order by pk + rows between 2 preceding and 2 following)'; +execute stmt; + +drop table t0,t1; + +--echo # +--echo # EXPLAIN FORMAT=JSON support for window functions +--echo # +create table t0 (a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +explain format=json select rank() over (order by a) from t0; + +create table t1 (a int, b int, c int); +insert into t1 select a,a,a from t0; + +explain format=json +select + a, + rank() over (order by sum(b)) +from t1 +group by a; + +explain format=json +select + a, + rank() over (order by sum(b)) +from t1 +group by a +order by null; + +--echo # +--echo # Check how window function works together with GROUP BY and HAVING +--echo # + +select b,max(a) as MX, rank() over (order by b) from t1 group by b having MX in (3,5,7); +explain format=json +select b,max(a) as MX, rank() over (order by b) from t1 group by b having MX in (3,5,7); + +drop table t1; +drop table t0; + +--echo # +--echo # Building ordering index for window functions +--echo # + +create table t1 ( + pk int primary key, + a int, + b int, + c int +); + +insert into t1 values +(101 , 0, 10, 1), +(102 , 0, 10, 2), +(103 , 1, 10, 3), +(104 , 1, 10, 4), +(108 , 2, 10, 5), +(105 , 2, 20, 6), +(106 , 2, 20, 7), +(107 , 2, 20, 8), +(109 , 4, 20, 9), +(110 , 4, 20, 10), +(111 , 5, NULL, 11), +(112 , 5, 1, 12), +(113 , 5, NULL, 13), +(114 , 5, NULL, 14), +(115 , 5, NULL, 15), +(116 , 6, 1, NULL), +(117 , 6, 1, 10), +(118 , 6, 1, 1), +(119 , 6, 1, NULL), +(120 , 6, 1, NULL), +(121 , 6, 1, NULL), +(122 , 6, 1, 2), +(123 , 6, 1, 20), +(124 , 6, 1, -10), +(125 , 6, 1, NULL), +(126 , 6, 1, NULL), +(127 , 6, 1, NULL); + +--sorted_result +select sum(b) over (partition by a order by b,pk + rows between unbounded preceding and current row) as c1, + avg(b) over (w1 rows between 1 preceding and 1 following) as c2, + sum(c) over (w2 rows between 1 preceding and 1 following) as c5, + avg(b) over (w1 rows between 5 preceding and 5 following) as c3, + sum(b) over (w1 rows between 1 preceding and 1 following) as c4 +from t1 +window w1 as (partition by a order by b,pk), + w2 as (partition by b order by c,pk); + +drop table t1; + + +--echo # +--echo # MDEV-9848: Window functions: reuse sorting and/or scanning +--echo # + +create table t1 (a int, b int, c int); +insert into t1 values +(1,3,1), +(2,2,1), +(3,1,1); + +--echo # Check using counters +flush status; +select + rank() over (partition by c order by a), + rank() over (partition by c order by b) +from t1; +show status like '%sort%'; + +flush status; +select + rank() over (partition by c order by a), + rank() over (partition by c order by a) +from t1; +show status like '%sort%'; + +# Check using EXPLAIN FORMAT=JSON +explain format=json +select + rank() over (partition by c order by a), + rank() over (partition by c order by a) +from t1; + +explain format=json +select + rank() over (order by a), + row_number() over (order by a) +from t1; + +explain format=json +select + rank() over (partition by c order by a), + count(*) over (partition by c) +from t1; + +explain format=json +select + count(*) over (partition by c), + rank() over (partition by c order by a) +from t1; + +drop table t1; + + +--echo # +--echo # MDEV-9847: Window functions: crash with big_tables=1 +--echo # +create table t1(a int); +insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +set @tmp=@@big_tables; +set big_tables=1; +select rank() over (order by a) from t1; +set big_tables=@tmp; +drop table t1; + +--echo # +--echo # Check if "ORDER BY window_func" works +--echo # + +create table t1 (s1 int, s2 char(5)); +insert into t1 values (1,'a'); +insert into t1 values (null,null); +insert into t1 values (1,null); +insert into t1 values (null,'a'); +insert into t1 values (2,'b'); +insert into t1 values (-1,''); + +explain format=json +select *, row_number() over (order by s1, s2) as X from t1 order by X desc; +select *, row_number() over (order by s1, s2) as X from t1 order by X desc; +drop table t1; + +--echo # +--echo # Try window functions that are not directly present in the select list +--echo # +create table t1 (a int, b int); +insert into t1 values + (1,3), + (2,2), + (3,1); + +select + a, b, + rank() over (order by a), rank() over (order by b), + rank() over (order by a) - rank() over (order by b) as diff +from + t1; + +drop table t1; + +create table t1 (i int); +insert into t1 values (1),(2); +SELECT MAX(i) OVER (PARTITION BY (i)) FROM t1; +drop table t1; + +--echo # +--echo # Check the 0 in ROWS 0 PRECEDING +--echo # + +create table t1 ( + part_id int, + pk int, + a int +); + +insert into t1 values (1, 1, 1); +insert into t1 values (1, 2, 2); +insert into t1 values (1, 3, 4); +insert into t1 values (1, 4, 8); + +select + pk, a, + sum(a) over (order by pk rows between 0 preceding and current row) +from t1; + +select + pk, a, + sum(a) over (order by pk rows between 1 preceding and 0 preceding) +from t1; + +insert into t1 values (200, 1, 1); +insert into t1 values (200, 2, 2); +insert into t1 values (200, 3, 4); +insert into t1 values (200, 4, 8); +select + part_id, pk, a, + sum(a) over (partition by part_id order by pk rows between 0 preceding and current row) +from t1; + +select + part_id, pk, a, + sum(a) over (partition by part_id order by pk rows between 1 preceding and 0 preceding) +from t1; + +drop table t1; +--echo # +--echo # MDEV-9780, The "DISTINCT must not bet converted into GROUP BY when +--echo # window functions are present" part +--echo # + +create table t1 (part_id int, a int); +insert into t1 values +(100, 1), +(100, 2), +(100, 2), +(100, 3), +(2000, 1), +(2000, 2), +(2000, 3), +(2000, 3), +(2000, 3); + +select rank() over (partition by part_id order by a) from t1; +select distinct rank() over (partition by part_id order by a) from t1; +explain format=json +select distinct rank() over (partition by part_id order by a) from t1; + +drop table t1; + +--echo # +--echo # MDEV-9893: Window functions with different ORDER BY lists, +--echo # one of these lists containing an expression +--echo # + +create table t1 (s1 int, s2 char(5)); +insert into t1 values (1,'a'); +insert into t1 values (null,null); +insert into t1 values (3,null); +insert into t1 values (4,'a'); +insert into t1 values (2,'b'); +insert into t1 values (-1,''); + +select + *, + ROW_NUMBER() OVER (order by s1), + CUME_DIST() OVER (order by -s1) +from t1; + +drop table t1; + + +--echo # +--echo # MDEV-9925: Wrong result with aggregate function as a window function +--echo # +create table t1 (i int); +insert into t1 values (1),(2); +select i, sum(i) over (partition by i) from t1; +drop table t1; + +--echo # +--echo # MDEV-9922: Assertion `!join->only_const_tables() && fsort' failed in int create_sort_index +--echo # +create view v1 as select 1 as i; +select rank() over (order by i) from v1; +drop view v1; + +--echo # +--echo # MDEV-10097: Assertion `count > 0' failed in Item_sum_sum::add_helper(bool) +--echo # +CREATE TABLE `orders` ( + `o_orderkey` int(11) NOT NULL, + `o_custkey` int(11) DEFAULT NULL, + PRIMARY KEY (`o_orderkey`) + ) DEFAULT CHARSET=latin1; + +INSERT INTO `orders` VALUES (59908,242); +INSERT INTO `orders` VALUES (59940,238); + +SELECT o_custkey, avg(o_custkey) OVER (PARTITION BY abs(o_custkey) + ORDER BY o_custkey + RANGE BETWEEN 15 FOLLOWING + AND 15 FOLLOWING) from orders; +DROP table orders; + +--echo # +--echo # MDEV-10842: window functions with the same order column +--echo # but different directions +--echo # + +create table t1 ( + pk int primary key, + a int, + b int, + c char(10) +); + +insert into t1 values +( 1, 0, 1, 'one'), +( 2, 0, 2, 'two'), +( 3, 0, 3, 'three'), +( 4, 1, 1, 'one'), +( 5, 1, 1, 'two'), +( 6, 1, 2, 'three'), +( 7, 2, NULL, 'n_one'), +( 8, 2, 1, 'n_two'), +( 9, 2, 2, 'n_three'), +(10, 2, 0, 'n_four'), +(11, 2, 10, NULL); + +select pk, + row_number() over (order by pk desc) as r_desc, + row_number() over (order by pk asc) as r_asc +from t1; + +drop table t1; + +--echo # +--echo # MDEV-10874: two window functions with ccompatible sorting +--echo # + +create table t1 ( +pk int primary key, +a int, +b int, +c char(10), +d decimal(10, 3), +e real +); +insert into t1 values +( 1, 0, 1, 'one', 0.1, 0.001), +( 2, 0, 2, 'two', 0.2, 0.002), +( 3, 0, 3, 'three', 0.3, 0.003), +( 4, 1, 2, 'three', 0.4, 0.004), +( 5, 1, 1, 'two', 0.5, 0.005), +( 6, 1, 1, 'one', 0.6, 0.006), +( 7, 2, NULL, 'n_one', 0.5, 0.007), +( 8, 2, 1, 'n_two', NULL, 0.008), +( 9, 2, 2, NULL, 0.7, 0.009), +(10, 2, 0, 'n_four', 0.8, 0.010), +(11, 2, 10, NULL, 0.9, NULL); + +select pk, a, d, + sum(d) over (partition by a order by pk + ROWS between 1 preceding and current row) as sum_1, + sum(d) over (order by a + ROWS BETWEEN 1 preceding and 2 following) as sum_2 +from t1; +explain format=json +select pk, a, d, + sum(d) over (partition by a order by pk + ROWS between 1 preceding and current row) as sum_1, + sum(d) over (order by a + ROWS BETWEEN 1 preceding and 2 following) as sum_2 +from t1; + +select pk, a, d, + sum(d) over (partition by a order by pk desc + ROWS between 1 preceding and current row) as sum_1, + sum(d) over (order by a + ROWS BETWEEN 1 preceding and 2 following) as sum_2 +from t1; + +drop table t1; + +--echo # +--echo # MDEV-9941: two window functions with compatible partitions +--echo # + +create table t1 ( + a int, + b int, + c int +); + +insert into t1 values + (10, 1, 1), + (10, 3, 10), + (10, 1, 10), + (10, 3, 100), + (10, 5, 1000), + (10, 1, 100); + +explain format=json +select + a,b,c, + row_number() over (partition by a), + row_number() over (partition by a, b) +from t1; + +drop table t1; + +--echo # +--echo # MDEV-10815: Window Function Expressions Wrong Results +--echo # +create table t(a decimal(35,10), b int); +insert into t(a,b) values(1,1); +insert into t(a,b) values(2,1); +insert into t(a,b) values(0,1); +insert into t(a,b) values(1, 2); +insert into t(a,b) values(1.5,2); +insert into t(a,b) values(3, 2); +insert into t(a,b) values(4.5,2); +select a, b, + sum(t.a) over (partition by t.b order by a) as simple_sum, + sum(t.a) over (partition by t.b order by a) + 1 as sum_and_const, + sum(t.b) over (partition by t.b order by a) + sum(t.a) over (partition by t.b order by a) as sum_and_sum +from t +order by t.b, t.a; +drop table t; + +--echo # +--echo # MDEV-10669: Crash in SELECT with window function used +--echo # +create table t(a decimal(35,10), b int); +insert into t(a,b) values(1,1); +insert into t(a,b) values(2,1); +insert into t(a,b) values(0,1); +SELECT (CASE WHEN sum(t.a) over (partition by t.b)=0 THEN null ELSE null END) AS a FROM t; +SELECT ifnull(((t.a) / CASE WHEN sum(t.a) over(partition by t.b) =0 then null else null end) ,0) from t; +SELECT sum(t.a) over (partition by t.b order by a), + sqrt(ifnull((sum(t.a) over (partition by t.b order by a)), 0)) +from t; +drop table t; + +--echo # +--echo # MDEV-10868: view definitions with window functions +--echo # + +create table t0 (a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t1 (pk int, c int); +insert into t1 select a+1,1 from t0; +update t1 set c=2 where pk not in (1,2,3,4); +select * from t1; + +let $q= +select pk, c, c/count(*) over (partition by c order by pk + rows between 1 preceding and 2 following) as CNT +from t1; + +eval $q; +eval create view v1 as $q; +show create view v1; +select * from v1; + +let $q= +select pk, c, c/count(*) over w1 as CNT from t1 + window w1 as (partition by c order by pk rows between 1 preceding and 2 following); + +eval $q; +eval create view v2 as $q; +show create view v2; +select * from v2; + +let $q= +select pk, c, c/count(*) over w1 as CNT from t1 + window w1 as (partition by c order by pk rows unbounded preceding); + +eval $q; +eval create view v3 as $q; +show create view v3; +select * from v3; + +let $q= +select pk, c, c/count(*) over (partition by c order by pk + range between 3 preceding and current row) as CNT +from t1; + +eval $q; +eval create view v4 as $q; +show create view v4; +select * from v4; + +drop view v1,v2,v3,v4; +drop table t0,t1; diff --git a/mysql-test/t/win_avg.test b/mysql-test/t/win_avg.test new file mode 100644 index 00000000000..23a3652d943 --- /dev/null +++ b/mysql-test/t/win_avg.test @@ -0,0 +1,47 @@ +create table t1 ( + pk int primary key, + a int, + b int, + c real +); + + +insert into t1 values +(101 , 0, 10, 1.1), +(102 , 0, 10, 2.1), +(103 , 1, 10, 3.1), +(104 , 1, 10, 4.1), +(108 , 2, 10, 5.1), +(105 , 2, 20, 6.1), +(106 , 2, 20, 7.1), +(107 , 2, 20, 8.15), +(109 , 4, 20, 9.15), +(110 , 4, 20, 10.15), +(111 , 5, NULL, 11.15), +(112 , 5, 1, 12.25), +(113 , 5, NULL, 13.35), +(114 , 5, NULL, 14.50), +(115 , 5, NULL, 15.65), +(116 , 6, 1, NULL), +(117 , 6, 1, 10), +(118 , 6, 1, 1.1), +(119 , 6, 1, NULL), +(120 , 6, 1, NULL), +(121 , 6, 1, NULL), +(122 , 6, 1, 2.2), +(123 , 6, 1, 20.1), +(124 , 6, 1, -10.4), +(125 , 6, 1, NULL), +(126 , 6, 1, NULL), +(127 , 6, 1, NULL); + + +--sorted_result +select pk, a, b, avg(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) +from t1; + +--sorted_result +select pk, a, c, avg(c) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) +from t1; + +drop table t1; diff --git a/mysql-test/t/win_big.test b/mysql-test/t/win_big.test new file mode 100644 index 00000000000..09c8d640b09 --- /dev/null +++ b/mysql-test/t/win_big.test @@ -0,0 +1,123 @@ +# +# Tests for window functions over big datasets. +# "Big" here is "big enough so that filesort result doesn't fit in a +# memory buffer". +# +# + +create table t0 (a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t1(a int); +insert into t1 select A.a + B.a* 10 + C.a * 100 from t0 A, t0 B, t0 C; + +create table t10 (a int, b int, c int); +insert into t10 +select + A.a + 1000*B.a, + A.a + 1000*B.a, + A.a + 1000*B.a +from t1 A, t0 B +order by A.a+1000*B.a; + +--echo ################################################################# +--echo ## Try a basic example +flush status; +create table t21 as +select + sum(b) over (order by a rows between 2 preceding and 2 following) as SUM_B +from + t10; +select variable_name, + case when variable_value > 0 then 'WITH PASSES' else 'NO PASSES' end +from information_schema.session_status +where variable_name like 'Sort_merge_passes'; + +set sort_buffer_size=1024; +flush status; +create table t22 as +select + sum(b) over (order by a rows between 2 preceding and 2 following) as SUM_B +from + t10; +select variable_name, + case when variable_value > 0 then 'WITH PASSES' else 'NO PASSES' end +from information_schema.session_status +where variable_name like 'Sort_merge_passes'; + +let $diff_tables= t21, t22; +source include/diff_tables.inc; +drop table t21, t22; + +--echo ################################################################# +--echo # Try many cursors +set sort_buffer_size=default; +flush status; +create table t21 as +select + sum(b) over (order by a rows between 2 preceding and 2 following) as SUM_B1, + sum(b) over (order by a rows between 5 preceding and 5 following) as SUM_B2, + sum(b) over (order by a rows between 20 preceding and 20 following) as SUM_B3 +from + t10; +select variable_name, + case when variable_value > 0 then 'WITH PASSES' else 'NO PASSES' end +from information_schema.session_status +where variable_name like 'Sort_merge_passes'; + +set sort_buffer_size=1024; +flush status; +create table t22 as +select + sum(b) over (order by a rows between 2 preceding and 2 following) as SUM_B1, + sum(b) over (order by a rows between 5 preceding and 5 following) as SUM_B2, + sum(b) over (order by a rows between 20 preceding and 20 following) as SUM_B3 +from + t10; +select variable_name, + case when variable_value > 0 then 'WITH PASSES' else 'NO PASSES' end +from information_schema.session_status +where variable_name like 'Sort_merge_passes'; + +let $diff_tables= t21, t22; +source include/diff_tables.inc; +drop table t21, t22; + +--echo ################################################################# +--echo # Try having cursors pointing at different IO_CACHE pages +--echo # in the IO_CACHE +set sort_buffer_size=default; +flush status; +create table t21 as +select + a, + sum(b) over (order by a range between 5000 preceding and 5000 following) as SUM_B1 +from + t10; + +select variable_name, + case when variable_value > 0 then 'WITH PASSES' else 'NO PASSES' end +from information_schema.session_status +where variable_name like 'Sort_merge_passes'; + +set sort_buffer_size=1024; +flush status; +create table t22 as +select + a, + sum(b) over (order by a range between 5000 preceding and 5000 following) as SUM_B1 +from + t10; +select variable_name, + case when variable_value > 0 then 'WITH PASSES' else 'NO PASSES' end +from information_schema.session_status +where variable_name like 'Sort_merge_passes'; + +let $diff_tables= t21, t22; +source include/diff_tables.inc; +drop table t21, t22; +--echo ################################################################# + +drop table t10; +drop table t0,t1; + diff --git a/mysql-test/t/win_bit.test b/mysql-test/t/win_bit.test new file mode 100644 index 00000000000..f077d0d67a0 --- /dev/null +++ b/mysql-test/t/win_bit.test @@ -0,0 +1,89 @@ +create table t1 ( + pk int primary key, + a int, + b int +); + +create table t2 ( + pk int primary key, + a int, + b int +); + + + +insert into t1 values +( 1 , 0, 1), +( 2 , 0, 2), +( 3 , 1, 4), +( 4 , 1, 8), +( 5 , 2, 32), +( 6 , 2, 64), +( 7 , 2, 128), +( 8 , 2, 16); + +insert into t2 values +( 1 , 0, 2), +( 2 , 0, 2), +( 3 , 1, 4), +( 4 , 1, 4), +( 5 , 2, 16), +( 6 , 2, 64), +( 7 , 2, 128), +( 8 , 2, 16); + + + +--echo # Test bit functions on only one partition. +select pk, a, b, + bit_or(b) over (order by pk) as bit_or, + bit_and(b) over (order by pk) as bit_and, + bit_xor(b) over (order by pk) as bit_xor +from t1; + +select pk, a, b, + bit_or(b) over (order by pk) as bit_or, + bit_and(b) over (order by pk) as bit_and, + bit_xor(b) over (order by pk) as bit_xor +from t2; + +--echo # Test multiple partitions with bit functions. +select pk, a, b, + bit_or(b) over (partition by a order by pk) as bit_or, + bit_and(b) over (partition by a order by pk) as bit_and, + bit_xor(b) over (partition by a order by pk) as bit_xor +from t1; + +select pk, a, b, + bit_or(b) over (partition by a order by pk) as bit_or, + bit_and(b) over (partition by a order by pk) as bit_and, + bit_xor(b) over (partition by a order by pk) as bit_xor +from t2; + +--echo # Test remove function for bit functions using a sliding window. +select pk, a, b, + bit_or(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as bit_or, + bit_and(b) over (partition by a order by pk) as bit_and, + bit_xor(b) over (partition by a order by pk) as bit_xor +from t1; + +select pk, a, b, + bit_or(b) over (partition by a order by pk) as bit_or, + bit_and(b) over (partition by a order by pk) as bit_and, + bit_xor(b) over (partition by a order by pk) as bit_xor +from t2; + + + + + + + +#select pk, a, b, bit_or(b) over (order by a) as count from t1 order by a, pk; +#select pk, a, b, bit_and(b) over (order by a ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as count from t1 order by a, pk; +#select pk, a, b, bit_xor(b) over (order by a, pk ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as count from t2 order by pk; +#select pk, a, b, bit_or(b) over (order by a, pk ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as count from t2 order by pk; +#select pk, a, b, bit_and(b) over (order by a, pk ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) as count from t3 order by pk; + +drop table t1; +drop table t2; diff --git a/mysql-test/t/win_empty_over.test b/mysql-test/t/win_empty_over.test new file mode 100644 index 00000000000..91344d76865 --- /dev/null +++ b/mysql-test/t/win_empty_over.test @@ -0,0 +1,66 @@ +create table t1 ( + pk int primary key, + a int, + b int, + c char(10), + d decimal(10, 3), + e real +); + +insert into t1 values +( 1, 0, 1, 'one', 0.1, 0.001), +( 2, 0, 2, 'two', 0.2, 0.002), +( 3, 0, 3, 'three', 0.3, 0.003), +( 4, 1, 2, 'three', 0.4, 0.004), +( 5, 1, 1, 'two', 0.5, 0.005), +( 6, 1, 1, 'one', 0.6, 0.006), +( 7, 2, NULL, 'n_one', 0.5, 0.007), +( 8, 2, 1, 'n_two', NULL, 0.008), +( 9, 2, 2, NULL, 0.7, 0.009), +(10, 2, 0, 'n_four', 0.8, 0.010), +(11, 2, 10, NULL, 0.9, NULL); + +select pk, row_number() over () from t1; +explain FORMAT=JSON select pk, row_number() over () from t1; +explain FORMAT=JSON select row_number() over (), pk from t1; + +select row_number() over () from (select 4) as t; + +--sorted_result +select min(a) over (), max(a) over (), a, row_number() over () +from t1 +where a = 0; + +--sorted_result +select a, min(a) over (), max(a) over (), row_number() over () +from t1 +where a = 0; + +--sorted_result +select min(a) over () + 1, max(a) over (), row_number() over () +from t1 +where a = 0; + +--sorted_result +select min(a) over () + a, max(a) over (), row_number() over () +from t1 +where a = 1; + +--sorted_result +select a + min(a) over (), max(a) over (), row_number() over () +from t1 +where a = 1; + +select a + min(a) over () from t1 where a = 1; + +create view win_view +as (select a, min(a) over () from t1 where a = 1); +select * from win_view; +drop view win_view; + +create view win_view +as (select a, max(a + 1) over () from t1 where a = 1); +select * from win_view; +drop view win_view; + +drop table t1; diff --git a/mysql-test/t/win_first_last_value.test b/mysql-test/t/win_first_last_value.test new file mode 100644 index 00000000000..5948cefe18a --- /dev/null +++ b/mysql-test/t/win_first_last_value.test @@ -0,0 +1,58 @@ +create table t1 ( + pk int primary key, + a int, + b int, + c char(10), + d decimal(10, 3), + e real +); + +insert into t1 values +( 1, 0, 1, 'one', 0.1, 0.001), +( 2, 0, 2, 'two', 0.2, 0.002), +( 3, 0, 3, 'three', 0.3, 0.003), +( 4, 1, 2, 'three', 0.4, 0.004), +( 5, 1, 1, 'two', 0.5, 0.005), +( 6, 1, 1, 'one', 0.6, 0.006), +( 7, 2, NULL, 'n_one', 0.5, 0.007), +( 8, 2, 1, 'n_two', NULL, 0.008), +( 9, 2, 2, NULL, 0.7, 0.009), +(10, 2, 0, 'n_four', 0.8, 0.010), +(11, 2, 10, NULL, 0.9, NULL); + +select pk, first_value(pk) over (order by pk), + last_value(pk) over (order by pk), + first_value(pk) over (order by pk desc), + last_value(pk) over (order by pk desc) +from t1 +order by pk desc; + +select pk, + first_value(pk) over (order by pk + RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING), + last_value(pk) over (order by pk + RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING), + first_value(pk) over (order by pk desc + RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING), + last_value(pk) over (order by pk desc + RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) +from t1 +order by pk; + +select pk, + first_value(pk) over (order by pk desc), + last_value(pk) over (order by pk desc) +from t1; + +select pk, a, b, c, d, e, + first_value(b) over (partition by a order by pk) as fst_b, + last_value(b) over (partition by a order by pk) as lst_b, + first_value(c) over (partition by a order by pk) as fst_c, + last_value(c) over (partition by a order by pk) as lst_c, + first_value(d) over (partition by a order by pk) as fst_d, + last_value(d) over (partition by a order by pk) as lst_d, + first_value(e) over (partition by a order by pk) as fst_e, + last_value(e) over (partition by a order by pk) as lst_e +from t1; + +drop table t1; diff --git a/mysql-test/t/win_i_s.test b/mysql-test/t/win_i_s.test new file mode 100644 index 00000000000..d9b0f190285 --- /dev/null +++ b/mysql-test/t/win_i_s.test @@ -0,0 +1,18 @@ +show status like '%window%'; + +create table t1 (a int, b int); +insert into t1 values (1, 10), (2, 20), (3, 30); + +select a, b, rank() over (order by a) from t1; +show status like '%window%'; + +select a, b, rank() over (order by a), sum(a) over (order by a) from t1; +show status like '%window%'; + +--sorted_result +select t_a.r1, t_b.r2 +from (select a, b, rank() over (order by a) as r1 from t1) t_a, + (select a, b, row_number() over (order by a) as r2 from t1) t_b; +show status like '%window%'; + +drop table t1; diff --git a/mysql-test/t/win_lead_lag.test b/mysql-test/t/win_lead_lag.test new file mode 100644 index 00000000000..2824f83789c --- /dev/null +++ b/mysql-test/t/win_lead_lag.test @@ -0,0 +1,110 @@ +create table t1 ( + pk int primary key, + a int, + b int, + c char(10), + d decimal(10, 3), + e real +); + +insert into t1 values +( 1, 0, 1, 'one', 0.1, 0.001), +( 2, 0, 2, 'two', 0.2, 0.002), +( 3, 0, 3, 'three', 0.3, 0.003), +( 4, 1, 2, 'three', 0.4, 0.004), +( 5, 1, 1, 'two', 0.5, 0.005), +( 6, 1, 1, 'one', 0.6, 0.006), +( 7, 2, NULL, 'n_one', 0.5, 0.007), +( 8, 2, 1, 'n_two', NULL, 0.008), +( 9, 2, 2, NULL, 0.7, 0.009), +(10, 2, 0, 'n_four', 0.8, 0.010), +(11, 2, 10, NULL, 0.9, NULL); + +select pk, + lead(pk) over (order by pk), + lead(pk, 1) over (order by pk), + lead(pk, 2) over (order by pk), + lead(pk, 0) over (order by pk), + lead(pk, -1) over (order by pk), + lead(pk, -2) over (order by pk) +from t1 +order by pk asc; + +select pk, + lag(pk) over (order by pk), + lag(pk, 1) over (order by pk), + lag(pk, 2) over (order by pk), + lag(pk, 0) over (order by pk), + lag(pk, -1) over (order by pk), + lag(pk, -2) over (order by pk) +from t1 +order by pk asc; + +select pk, pk - 2, + lag(pk, pk - 2) over (order by pk), + lead(pk, pk - 2) over (order by pk) +from t1 +order by pk asc; + +select pk, pk - 2, + lag(pk, pk + 2) over (order by pk), + lead(pk, pk + 2) over (order by pk) +from t1 +order by pk asc; + +select pk, a, + lead(pk) over (partition by a order by pk), + lead(pk, 1) over (partition by a order by pk), + lead(pk, 2) over (partition by a order by pk), + lead(pk, 0) over (partition by a order by pk), + lead(pk, -1) over (partition by a order by pk), + lead(pk, -2) over (partition by a order by pk) +from t1 +order by pk asc; + +select pk, a, + lag(pk) over (partition by a order by pk), + lag(pk, 1) over (partition by a order by pk), + lag(pk, 2) over (partition by a order by pk), + lag(pk, 0) over (partition by a order by pk), + lag(pk, -1) over (partition by a order by pk), + lag(pk, -2) over (partition by a order by pk) +from t1 +order by pk asc; + +select pk, a, pk - 2, + lag(pk, pk - 2) over (partition by a order by pk), + lead(pk, pk - 2) over (partition by a order by pk), + lag(pk, a - 2) over (partition by a order by pk), + lead(pk, a - 2) over (partition by a order by pk) +from t1 +order by pk asc; + +select pk, a, pk - 2, + lag(pk, pk + 2) over (partition by a order by pk), + lead(pk, pk + 2) over (partition by a order by pk), + lag(pk, a + 2) over (partition by a order by pk), + lead(pk, a + 2) over (partition by a order by pk) +from t1 +order by pk asc; + +select pk, a, b, c, d, e, + lag(a) over (partition by a order by pk), + lag(b) over (partition by a order by pk), + lag(c) over (partition by a order by pk), + lag(d) over (partition by a order by pk), + lag(e) over (partition by a order by pk) +from t1 +order by pk asc; + +select pk, a, b, a+b, + lag(a + b) over (partition by a order by pk) +from t1 +order by pk asc; + +select pk, a, b, a+b, + lag(a + b) over (partition by a order by pk) + pk +from t1 +order by pk asc; + +drop table t1; diff --git a/mysql-test/t/win_min_max.test b/mysql-test/t/win_min_max.test new file mode 100644 index 00000000000..8efde87ffdf --- /dev/null +++ b/mysql-test/t/win_min_max.test @@ -0,0 +1,370 @@ +create table t1 ( + pk int primary key, + a int, + b int, + c real +); + + +insert into t1 values +(101 , 0, 10, 1.1), +(102 , 0, 10, 2.1), +(103 , 1, 10, 3.1), +(104 , 1, 10, 4.1), +(108 , 2, 10, 5.1), +(105 , 2, 20, 6.1), +(106 , 2, 20, 7.1), +(107 , 2, 20, 8.15), +(109 , 4, 20, 9.15), +(110 , 4, 20, 10.15), +(111 , 5, NULL, 11.15), +(112 , 5, 1, 12.25), +(113 , 5, NULL, 13.35), +(114 , 5, NULL, 14.50), +(115 , 5, NULL, 15.65), +(116 , 6, 1, NULL), +(117 , 6, 1, 10), +(118 , 6, 1, 1.1), +(119 , 6, 1, NULL), +(120 , 6, 1, NULL), +(121 , 6, 1, NULL), +(122 , 6, 1, 2.2), +(123 , 6, 1, 20.1), +(124 , 6, 1, -10.4), +(125 , 6, 1, NULL), +(126 , 6, 1, NULL), +(127 , 6, 1, NULL); + + +--sorted_result +select pk, a, b, min(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as min, + max(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as max +from t1; + +--sorted_result +select pk, a, c, min(c) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as min, + max(c) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as max +from t1; + +create table t2 ( + pk int primary key, + a int, + b int, + c char(10) +); + +insert into t2 values +( 1, 0, 1, 'one'), +( 2, 0, 2, 'two'), +( 3, 0, 3, 'three'), +( 4, 1, 20, 'four'), +( 5, 1, 10, 'five'), +( 6, 1, 40, 'six'), +( 7, 1, 30, 'seven'), +( 8, 4,300, 'eight'), +( 9, 4,100, 'nine'), +(10, 4,200, 'ten'), +(11, 4,200, 'eleven'); + +--echo # First try some invalid argument queries. +select pk, a, b, c, + min(c) over (order by pk), + max(c) over (order by pk), + min(c) over (partition by a order by pk), + max(c) over (partition by a order by pk) +from t2; + + + +--echo # Empty frame + +select pk, a, b, c, + min(b) over (order by pk rows between 2 following and 1 following) as min1, + max(b) over (order by pk rows between 2 following and 1 following) as max1, + min(b) over (partition by a order by pk rows between 2 following and 1 following) as min2, + max(b) over (partition by a order by pk rows between 2 following and 1 following) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk range between 2 following and 1 following) as min1, + max(b) over (order by pk range between 2 following and 1 following) as max1, + min(b) over (partition by a order by pk range between 2 following and 1 following) as min2, + max(b) over (partition by a order by pk range between 2 following and 1 following) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk rows between 1 preceding and 2 preceding) as min1, + max(b) over (order by pk rows between 1 preceding and 2 preceding) as max1, + min(b) over (partition by a order by pk rows between 1 preceding and 2 preceding) as min2, + max(b) over (partition by a order by pk rows between 1 preceding and 2 preceding) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk range between 1 preceding and 2 preceding) as min1, + max(b) over (order by pk range between 1 preceding and 2 preceding) as max1, + min(b) over (partition by a order by pk range between 1 preceding and 2 preceding) as min2, + max(b) over (partition by a order by pk range between 1 preceding and 2 preceding) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk rows between 1 following and 0 following) as min1, + max(b) over (order by pk rows between 1 following and 0 following) as max1, + min(b) over (partition by a order by pk rows between 1 following and 0 following) as min2, + max(b) over (partition by a order by pk rows between 1 following and 0 following) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk range between 1 following and 0 following) as min1, + max(b) over (order by pk range between 1 following and 0 following) as max1, + min(b) over (partition by a order by pk range between 1 following and 0 following) as min2, + max(b) over (partition by a order by pk range between 1 following and 0 following) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk rows between 1 following and 0 preceding) as min1, + max(b) over (order by pk rows between 1 following and 0 preceding) as max1, + min(b) over (partition by a order by pk rows between 1 following and 0 preceding) as min2, + max(b) over (partition by a order by pk rows between 1 following and 0 preceding) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk range between 1 following and 0 preceding) as min1, + max(b) over (order by pk range between 1 following and 0 preceding) as max1, + min(b) over (partition by a order by pk range between 1 following and 0 preceding) as min2, + max(b) over (partition by a order by pk range between 1 following and 0 preceding) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk rows between 0 following and 1 preceding) as min1, + max(b) over (order by pk rows between 0 following and 1 preceding) as max1, + min(b) over (partition by a order by pk rows between 0 following and 1 preceding) as min2, + max(b) over (partition by a order by pk rows between 0 following and 1 preceding) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk range between 0 following and 1 preceding) as min1, + max(b) over (order by pk range between 0 following and 1 preceding) as max1, + min(b) over (partition by a order by pk range between 0 following and 1 preceding) as min2, + max(b) over (partition by a order by pk range between 0 following and 1 preceding) as max2 +from t2; + +--echo # 1 row frame. +select pk, a, b, c, + min(b) over (order by pk rows between current row and current row) as min1, + max(b) over (order by pk rows between current row and current row) as max1, + min(b) over (partition by a order by pk rows between current row and current row) as min2, + max(b) over (partition by a order by pk rows between current row and current row) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk rows between 0 preceding and current row) as min1, + max(b) over (order by pk rows between 0 preceding and current row) as max1, + min(b) over (partition by a order by pk rows between 0 preceding and current row) as min2, + max(b) over (partition by a order by pk rows between 0 preceding and current row) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk rows between 0 preceding and 0 preceding) as min1, + max(b) over (order by pk rows between 0 preceding and 0 preceding) as max1, + min(b) over (partition by a order by pk rows between 0 preceding and 0 preceding) as min2, + max(b) over (partition by a order by pk rows between 0 preceding and 0 preceding) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk rows between 1 preceding and 1 preceding) as min1, + max(b) over (order by pk rows between 1 preceding and 1 preceding) as max1, + min(b) over (partition by a order by pk rows between 1 preceding and 1 preceding) as min2, + max(b) over (partition by a order by pk rows between 1 preceding and 1 preceding) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk rows between 1 following and 1 following) as min1, + max(b) over (order by pk rows between 1 following and 1 following) as max1, + min(b) over (partition by a order by pk rows between 1 following and 1 following) as min2, + max(b) over (partition by a order by pk rows between 1 following and 1 following) as max2 +from t2; + +--echo # Try a larger offset. +select pk, a, b, c, + min(b) over (order by pk rows between 3 following and 3 following) as min1, + max(b) over (order by pk rows between 3 following and 3 following) as max1, + min(b) over (partition by a order by pk rows between 3 following and 3 following) as min2, + max(b) over (partition by a order by pk rows between 3 following and 3 following) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk rows between 3 preceding and 3 preceding) as min1, + max(b) over (order by pk rows between 3 preceding and 3 preceding) as max1, + min(b) over (partition by a order by pk rows between 3 preceding and 3 preceding) as min2, + max(b) over (partition by a order by pk rows between 3 preceding and 3 preceding) as max2 +from t2; + +--echo # 2 row frame. +select pk, a, b, c, + min(b) over (order by pk rows between current row and 1 following) as min1, + max(b) over (order by pk rows between current row and 1 following) as max1, + min(b) over (partition by a order by pk rows between current row and 1 following) as min2, + max(b) over (partition by a order by pk rows between current row and 1 following) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk rows between 0 preceding and 1 following) as min1, + max(b) over (order by pk rows between 0 preceding and 1 following) as max1, + min(b) over (partition by a order by pk rows between 0 preceding and 1 following) as min2, + max(b) over (partition by a order by pk rows between 0 preceding and 1 following) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk rows between 1 preceding and current row) as min1, + max(b) over (order by pk rows between 1 preceding and current row) as max1, + min(b) over (partition by a order by pk rows between 1 preceding and current row) as min2, + max(b) over (partition by a order by pk rows between 1 preceding and current row) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk rows between 1 preceding and 0 preceding) as min1, + max(b) over (order by pk rows between 1 preceding and 0 preceding) as max1, + min(b) over (partition by a order by pk rows between 1 preceding and 0 preceding) as min2, + max(b) over (partition by a order by pk rows between 1 preceding and 0 preceding) as max2 +from t2; + +--echo # Try a larger frame/offset. +select pk, a, b, c, + min(b) over (order by pk rows between current row and 3 following) as min1, + max(b) over (order by pk rows between current row and 3 following) as max1, + min(b) over (partition by a order by pk rows between current row and 3 following) as min2, + max(b) over (partition by a order by pk rows between current row and 3 following) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk rows between 2 preceding and 1 following) as min1, + max(b) over (order by pk rows between 2 preceding and 1 following) as max1, + min(b) over (partition by a order by pk rows between 2 preceding and 1 following) as min2, + max(b) over (partition by a order by pk rows between 2 preceding and 1 following) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk rows between 3 preceding and current row) as min1, + max(b) over (order by pk rows between 3 preceding and current row) as max1, + min(b) over (partition by a order by pk rows between 3 preceding and current row) as min2, + max(b) over (partition by a order by pk rows between 3 preceding and current row) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk rows between 3 preceding and 0 preceding) as min1, + max(b) over (order by pk rows between 3 preceding and 0 preceding) as max1, + min(b) over (partition by a order by pk rows between 3 preceding and 0 preceding) as min2, + max(b) over (partition by a order by pk rows between 3 preceding and 0 preceding) as max2 +from t2; + +--echo # Check range frame bounds +select pk, a, b, c, + min(b) over (order by pk range between current row and current row) as min1, + max(b) over (order by pk range between current row and current row) as max1, + min(b) over (partition by a order by pk range between current row and current row) as min2, + max(b) over (partition by a order by pk range between current row and current row) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk range between 0 preceding and current row) as min1, + max(b) over (order by pk range between 0 preceding and current row) as max1, + min(b) over (partition by a order by pk range between 0 preceding and current row) as min2, + max(b) over (partition by a order by pk range between 0 preceding and current row) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk range between 0 preceding and 0 preceding) as min1, + max(b) over (order by pk range between 0 preceding and 0 preceding) as max1, + min(b) over (partition by a order by pk range between 0 preceding and 0 preceding) as min2, + max(b) over (partition by a order by pk range between 0 preceding and 0 preceding) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk range between 1 preceding and 1 preceding) as min1, + max(b) over (order by pk range between 1 preceding and 1 preceding) as max1, + min(b) over (partition by a order by pk range between 1 preceding and 1 preceding) as min2, + max(b) over (partition by a order by pk range between 1 preceding and 1 preceding) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk range between 1 following and 1 following) as min1, + max(b) over (order by pk range between 1 following and 1 following) as max1, + min(b) over (partition by a order by pk range between 1 following and 1 following) as min2, + max(b) over (partition by a order by pk range between 1 following and 1 following) as max2 +from t2; + +--echo # Try a larger offset. +select pk, a, b, c, + min(b) over (order by pk range between 3 following and 3 following) as min1, + max(b) over (order by pk range between 3 following and 3 following) as max1, + min(b) over (partition by a order by pk range between 3 following and 3 following) as min2, + max(b) over (partition by a order by pk range between 3 following and 3 following) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk range between 3 preceding and 3 preceding) as min1, + max(b) over (order by pk range between 3 preceding and 3 preceding) as max1, + min(b) over (partition by a order by pk range between 3 preceding and 3 preceding) as min2, + max(b) over (partition by a order by pk range between 3 preceding and 3 preceding) as max2 +from t2; + +--echo # 2 row frame. +select pk, a, b, c, + min(b) over (order by pk range between current row and 1 following) as min1, + max(b) over (order by pk range between current row and 1 following) as max1, + min(b) over (partition by a order by pk range between current row and 1 following) as min2, + max(b) over (partition by a order by pk range between current row and 1 following) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk range between 0 preceding and 1 following) as min1, + max(b) over (order by pk range between 0 preceding and 1 following) as max1, + min(b) over (partition by a order by pk range between 0 preceding and 1 following) as min2, + max(b) over (partition by a order by pk range between 0 preceding and 1 following) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk range between 1 preceding and current row) as min1, + max(b) over (order by pk range between 1 preceding and current row) as max1, + min(b) over (partition by a order by pk range between 1 preceding and current row) as min2, + max(b) over (partition by a order by pk range between 1 preceding and current row) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk range between 1 preceding and 0 preceding) as min1, + max(b) over (order by pk range between 1 preceding and 0 preceding) as max1, + min(b) over (partition by a order by pk range between 1 preceding and 0 preceding) as min2, + max(b) over (partition by a order by pk range between 1 preceding and 0 preceding) as max2 +from t2; + +--echo # Try a larger frame/offset. +select pk, a, b, c, + min(b) over (order by pk range between current row and 3 following) as min1, + max(b) over (order by pk range between current row and 3 following) as max1, + min(b) over (partition by a order by pk range between current row and 3 following) as min2, + max(b) over (partition by a order by pk range between current row and 3 following) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk range between 2 preceding and 1 following) as min1, + max(b) over (order by pk range between 2 preceding and 1 following) as max1, + min(b) over (partition by a order by pk range between 2 preceding and 1 following) as min2, + max(b) over (partition by a order by pk range between 2 preceding and 1 following) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk range between 3 preceding and current row) as min1, + max(b) over (order by pk range between 3 preceding and current row) as max1, + min(b) over (partition by a order by pk range between 3 preceding and current row) as min2, + max(b) over (partition by a order by pk range between 3 preceding and current row) as max2 +from t2; + +select pk, a, b, c, + min(b) over (order by pk range between 3 preceding and 0 preceding) as min1, + max(b) over (order by pk range between 3 preceding and 0 preceding) as max1, + min(b) over (partition by a order by pk range between 3 preceding and 0 preceding) as min2, + max(b) over (partition by a order by pk range between 3 preceding and 0 preceding) as max2 +from t2; + +drop table t2; +drop table t1; diff --git a/mysql-test/t/win_nth_value.test b/mysql-test/t/win_nth_value.test new file mode 100644 index 00000000000..b9764d1e9d7 --- /dev/null +++ b/mysql-test/t/win_nth_value.test @@ -0,0 +1,67 @@ +create table t1 ( + pk int primary key, + a int, + b int, + c char(10), + d decimal(10, 3), + e real +); + +insert into t1 values +( 1, 0, 1, 'one', 0.1, 0.001), +( 2, 0, 2, 'two', 0.2, 0.002), +( 3, 0, 3, 'three', 0.3, 0.003), +( 4, 1, 2, 'three', 0.4, 0.004), +( 5, 1, 1, 'two', 0.5, 0.005), +( 6, 1, 1, 'one', 0.6, 0.006), +( 7, 2, NULL, 'n_one', 0.5, 0.007), +( 8, 2, 1, 'n_two', NULL, 0.008), +( 9, 2, 2, NULL, 0.7, 0.009), +(10, 2, 0, 'n_four', 0.8, 0.010), +(11, 2, 10, NULL, 0.9, NULL); + +select pk, + nth_value(pk, 1) over (order by pk), + nth_value(pk, 2) over (order by pk), + nth_value(pk, 0) over (order by pk), + nth_value(pk, -1) over (order by pk), + nth_value(pk, -2) over (order by pk) +from t1 +order by pk asc; + +select pk, + nth_value(pk, pk) over (order by pk), + nth_value(pk / 0.1, pk) over (order by pk) +from t1 +order by pk asc; + +select pk, + a, + nth_value(pk, pk) over (partition by a order by pk), + nth_value(pk, a + 1) over (partition by a order by pk) +from t1 +order by pk asc; + +select pk, + a, + nth_value(pk, 1) over (partition by a order by pk ROWS between 1 preceding and 1 following) +from t1; + +select pk, + a, + nth_value(a, 1) over (order by a RANGE BETWEEN 1 preceding and 1 following), + nth_value(a, 2) over (order by a RANGE BETWEEN 1 preceding and 1 following), + nth_value(a, 3) over (order by a RANGE BETWEEN 1 preceding and 1 following), + nth_value(a, 4) over (order by a RANGE BETWEEN 1 preceding and 1 following), + nth_value(a, 5) over (order by a RANGE BETWEEN 1 preceding and 1 following), + nth_value(a, 6) over (order by a RANGE BETWEEN 1 preceding and 1 following), + nth_value(a, 7) over (order by a RANGE BETWEEN 1 preceding and 1 following), + nth_value(a, 8) over (order by a RANGE BETWEEN 1 preceding and 1 following), + nth_value(a, 9) over (order by a RANGE BETWEEN 1 preceding and 1 following), + nth_value(a, 10) over (order by a RANGE BETWEEN 1 preceding and 1 following), + nth_value(a, 11) over (order by a RANGE BETWEEN 1 preceding and 1 following), + nth_value(a, 12) over (order by a RANGE BETWEEN 1 preceding and 1 following) +from t1 +order by pk asc; + +drop table t1; diff --git a/mysql-test/t/win_ntile.test b/mysql-test/t/win_ntile.test new file mode 100644 index 00000000000..6f12e1f4005 --- /dev/null +++ b/mysql-test/t/win_ntile.test @@ -0,0 +1,171 @@ +create table t1 ( + pk int primary key, + a int, + b int +); + + +insert into t1 values +(11 , 0, 10), +(12 , 0, 10), +(13 , 1, 10), +(14 , 1, 10), +(18 , 2, 10), +(15 , 2, 20), +(16 , 2, 20), +(17 , 2, 20), +(19 , 4, 20), +(20 , 4, 20); + +# TODO Try invalid queries too. + +--error ER_INVALID_NTILE_ARGUMENT +select pk, a, b, ntile(-1) over (order by a) +from t1; + +--error ER_INVALID_NTILE_ARGUMENT +select pk, a, b, + ntile(0) over (order by a) +from t1; + +--sorted_result +select pk, a, b, + ntile(1) over (order by pk) +from t1; + +--sorted_result +select pk, a, b, + ntile(2) over (order by pk) +from t1; + +--sorted_result +select pk, a, b, + ntile(3) over (order by pk) +from t1; + +--sorted_result +select pk, a, b, + ntile(4) over (order by pk) +from t1; + +--sorted_result +select pk, a, b, + ntile(5) over (order by pk) +from t1; + +--sorted_result +select pk, a, b, + ntile(6) over (order by pk) +from t1; + +--sorted_result +select pk, a, b, + ntile(7) over (order by pk) +from t1; + +--sorted_result +select pk, a, b, + ntile(8) over (order by pk) +from t1; + +--sorted_result +select pk, a, b, + ntile(9) over (order by pk) +from t1; + +--sorted_result +select pk, a, b, + ntile(10) over (order by pk) +from t1; + +--sorted_result +select pk, a, b, + ntile(11) over (order by pk) +from t1; + +--sorted_result +select pk, a, b, + ntile(20) over (order by pk) +from t1; + + +select pk, a, b, + ntile(1) over (partition by b order by pk) +from t1; + +select pk, a, b, + ntile(2) over (partition by b order by pk) +from t1; + +select pk, a, b, + ntile(3) over (partition by b order by pk) +from t1; + +select pk, a, b, + ntile(4) over (partition by b order by pk) +from t1; + +select pk, a, b, + ntile(5) over (partition by b order by pk) +from t1; + +select pk, a, b, + ntile(6) over (partition by b order by pk) +from t1; + +select pk, a, b, + ntile(7) over (partition by b order by pk) +from t1; + +select pk, a, b, + ntile(8) over (partition by b order by pk) +from t1; + +select pk, a, b, + ntile(9) over (partition by b order by pk) +from t1; + +select pk, a, b, + ntile(10) over (partition by b order by pk) +from t1; + +select pk, a, b, + ntile(11) over (partition by b order by pk) +from t1; + +select pk, a, b, + ntile(20) over (partition by b order by pk) +from t1; + +select pk, a, b, + ntile(1 + 3) over (partition by b order by pk) +from t1; + +select pk, a, b, + ntile((select 4)) over (partition by b order by pk) +from t1; + +select t1.a from t1 where pk = 11; +--error ER_INVALID_NTILE_ARGUMENT +select pk, a, b, + ntile((select a from t1 where pk=11)) over (partition by b order by pk) +from t1; + +select t1.a from t1 where pk = 13; +select pk, a, b, + ntile((select a from t1 where pk=13)) over (partition by b order by pk) +from t1; + +explain +select pk, a, b, + ntile((select a from t1 where pk=13)) over (partition by b order by pk) +from t1; + +select a from t1; +--error ER_SUBQUERY_NO_1_ROW +select pk, a, b, + ntile((select a from t1)) over (partition by b order by pk) +from t1; + + +drop table t1; diff --git a/mysql-test/t/win_orderby.test b/mysql-test/t/win_orderby.test new file mode 100644 index 00000000000..0d42c606486 --- /dev/null +++ b/mysql-test/t/win_orderby.test @@ -0,0 +1,32 @@ +# +# Tests for window functions and ORDER BY +# + +--disable_warnings +drop table if exists t0,t1; +--enable_warnings + +create table t0(a int primary key); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t1( + pk int, + a int, + key(pk) +); + +insert into t1 +select + A.a + B.a* 10 + C.a * 100, + 1 +from t0 A, t0 B, t0 C; + +select + pk, + count(a) over (order by pk rows between 2 preceding and 2 following) +from t1 +where pk between 1 and 30 +order by pk desc +limit 4; + +drop table t0,t1; diff --git a/mysql-test/t/win_percent_cume.test b/mysql-test/t/win_percent_cume.test new file mode 100644 index 00000000000..b851185cb32 --- /dev/null +++ b/mysql-test/t/win_percent_cume.test @@ -0,0 +1,36 @@ +create table t1 ( + pk int primary key, + a int, + b int +); + + +insert into t1 values +( 1 , 0, 10), +( 2 , 0, 10), +( 3 , 1, 10), +( 4 , 1, 10), +( 8 , 2, 10), +( 5 , 2, 20), +( 6 , 2, 20), +( 7 , 2, 20), +( 9 , 4, 20), +(10 , 4, 20); + +select pk, a, b, + percent_rank() over (order by a), + cume_dist() over (order by a) +from t1; + +select pk, a, b, + percent_rank() over (order by pk), + cume_dist() over (order by pk) +from t1 order by pk; + +select pk, a, b, + percent_rank() over (partition by a order by a), + cume_dist() over (partition by a order by a) +from t1; + +drop table t1; + diff --git a/mysql-test/t/win_rank.test b/mysql-test/t/win_rank.test new file mode 100644 index 00000000000..eda1f458205 --- /dev/null +++ b/mysql-test/t/win_rank.test @@ -0,0 +1,58 @@ +--echo # +--echo # Try DENSE_RANK() function +--echo # + +create table t1 ( + pk int primary key, + a int, + b int +); + +insert into t1 values +( 1 , 0, 10), +( 2 , 0, 10), +( 3 , 1, 10), +( 4 , 1, 10), +( 8 , 2, 10), +( 5 , 2, 20), +( 6 , 2, 20), +( 7 , 2, 20), +( 9 , 4, 20), +(10 , 4, 20); + +select pk, a, b, rank() over (order by a) as rank, + dense_rank() over (order by a) as dense_rank +from t1; +select pk, a, b, rank() over (partition by b order by a) as rank, + dense_rank() over (partition by b order by a) as dense_rank +from t1; + +drop table t1; + +--echo # +--echo # Test with null values in the table. +--echo # + +create table t2 (s1 int, s2 char(5)); +insert into t2 values (1,'a'); +insert into t2 values (null,null); +insert into t2 values (1,null); +insert into t2 values (null,'a'); +insert into t2 values (null,'c'); +insert into t2 values (2,'b'); +insert into t2 values (-1,''); + +select *, rank() over (order by s1) as rank, + dense_rank() over (order by s1) as dense_rank +from t2; +select *, rank() over (partition by s2 order by s1) as rank, + dense_rank() over (partition by s2 order by s1) as dense_rank +from t2; +select *, rank() over (order by s2) as rank, + dense_rank() over (order by s2) as dense_rank +from t2; +select *, rank() over (partition by s1 order by s2) as rank, + dense_rank() over (partition by s1 order by s2) as dense_rank +from t2; + +drop table t2; diff --git a/mysql-test/t/win_std.test b/mysql-test/t/win_std.test new file mode 100644 index 00000000000..5ed999431c0 --- /dev/null +++ b/mysql-test/t/win_std.test @@ -0,0 +1,136 @@ +create table t1 ( + pk int primary key, + a int, + b int +); + +create table t2 ( + pk int primary key, + a int, + b int, + c char(10) +); + +insert into t2 values +( 1, 0, 1, 'one'), +( 2, 0, 2, 'two'), +( 3, 0, 3, 'three'), +( 4, 1, 1, 'one'), +( 5, 1, 1, 'two'), +( 6, 1, 2, 'three'); + +--disable_warnings +--echo # First try some invalid queries. +select std(c) over (order by a) +from t2; +--enable_warnings + +--echo # Empty frame. +select std(b) over (order by a rows between 2 following and 1 following) +from t2; + +select std(b) over (order by a range between 2 following and 1 following) +from t2; + +select std(b) over (order by a rows between 1 preceding and 2 preceding) +from t2; + +select std(b) over (order by a range between 1 preceding and 2 preceding) +from t2; + +select std(b) over (order by a rows between 1 following and 0 following) +from t2; + +select std(b) over (order by a range between 1 following and 0 following) +from t2; + +select std(b) over (order by a rows between 1 following and 0 preceding) +from t2; + +select std(b) over (order by a range between 1 following and 0 preceding) +from t2; + +select std(b) over (order by a rows between 0 following and 1 preceding) +from t2; + +select std(b) over (order by a range between 0 following and 1 preceding) +from t2; + +--echo # 1 row frame. +select std(b) over (order by a rows between current row and current row) +from t2; + +select std(b) over (order by a rows between 0 preceding and current row) +from t2; + +select std(b) over (order by a rows between 0 preceding and 0 preceding) +from t2; + +select std(b) over (order by a rows between 0 preceding and 0 following) +from t2; + +select std(b) over (order by a rows between 0 following and 0 preceding) +from t2; + +--error ER_BAD_COMBINATION_OF_WINDOW_FRAME_BOUND_SPECS +select std(b) over (order by a rows between 0 following and current row) +from t2; + +select std(b) over (order by a rows between current row and 0 following) +from t2; + +--echo # Only peers frame. +select a, b, std(b) over (order by a range between 0 preceding and 0 preceding) +from t2; + +select a, b, std(b) over (order by a range between 0 preceding and current row) +from t2; + +--error ER_BAD_COMBINATION_OF_WINDOW_FRAME_BOUND_SPECS +select a, b, std(b) over (order by a range between current row and 0 preceding) +from t2; + +select a, b, std(b) over (order by a range between current row and 0 following) +from t2; + +select a, b, std(b) over (order by a range between 0 following and 0 following) +from t2; + +--echo # 2 rows frame. + +--sorted_result +select pk, a, b, std(b) over (order by a, b, pk rows between 1 preceding and current row) +from t2; + +--sorted_result +select pk, a, b, std(b) over (order by a, b, pk rows between 1 preceding and 0 preceding) +from t2; + +--sorted_result +select pk, a, b, std(b) over (order by a, b, pk rows between current row and 1 following) +from t2; + +--sorted_result +select pk, a, b, std(b) over (order by a, b, pk rows between 0 following and 1 following) +from t2; + +--echo # 2 peers frame. + +--sorted_result +select pk, a, b, std(b) over (order by a range between 1 preceding and current row) +from t2; + +--sorted_result +select pk, a, b, std(b) over (order by a range between 1 preceding and 0 preceding) +from t2; + +--sorted_result +select pk, a, b, std(b) over (order by a range between current row and 1 following) +from t2; + +--sorted_result +select pk, a, b, std(b) over (order by a range between 0 following and 1 following) +from t2; + +drop table t1; +drop table t2; diff --git a/mysql-test/t/win_sum.test b/mysql-test/t/win_sum.test new file mode 100644 index 00000000000..aa4965bfd5a --- /dev/null +++ b/mysql-test/t/win_sum.test @@ -0,0 +1,47 @@ +create table t1 ( + pk int primary key, + a int, + b int, + c real +); + + +insert into t1 values +(101 , 0, 10, 1.1), +(102 , 0, 10, 2.1), +(103 , 1, 10, 3.1), +(104 , 1, 10, 4.1), +(108 , 2, 10, 5.1), +(105 , 2, 20, 6.1), +(106 , 2, 20, 7.1), +(107 , 2, 20, 8.15), +(109 , 4, 20, 9.15), +(110 , 4, 20, 10.15), +(111 , 5, NULL, 11.15), +(112 , 5, 1, 12.25), +(113 , 5, NULL, 13.35), +(114 , 5, NULL, 14.50), +(115 , 5, NULL, 15.65), +(116 , 6, 1, NULL), +(117 , 6, 1, 10), +(118 , 6, 1, 1.1), +(119 , 6, 1, NULL), +(120 , 6, 1, NULL), +(121 , 6, 1, NULL), +(122 , 6, 1, 2.2), +(123 , 6, 1, 20.1), +(124 , 6, 1, -10.4), +(125 , 6, 1, NULL), +(126 , 6, 1, NULL), +(127 , 6, 1, NULL); + + +--sorted_result +select pk, a, b, sum(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) +from t1; + +--sorted_result +select pk, a, c, sum(c) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) +from t1; + +drop table t1; diff --git a/mysql-test/t/xa.test b/mysql-test/t/xa.test index 1709886eb0c..f1576f021ec 100644 --- a/mysql-test/t/xa.test +++ b/mysql-test/t/xa.test @@ -258,19 +258,16 @@ DROP TABLE IF EXISTS t1; CREATE TABLE t1(a INT, b INT, PRIMARY KEY(a)) engine=InnoDB; INSERT INTO t1 VALUES (1, 1), (2, 2); ---echo # Connection con1 connect (con1, localhost, root); XA START 'a'; UPDATE t1 SET b= 3 WHERE a=1; ---echo # Connection default connection default; XA START 'b'; UPDATE t1 SET b=4 WHERE a=2; --echo # Sending: --send UPDATE t1 SET b=5 WHERE a=1 ---echo # Connection con1 connection con1; --sleep 1 --error ER_LOCK_DEADLOCK @@ -279,7 +276,6 @@ UPDATE t1 SET b=6 WHERE a=2; --error ER_XA_RBDEADLOCK XA COMMIT 'a'; ---echo # Connection default connection default; --echo # Reaping: UPDATE t1 SET b=5 WHERE a=1 --reap @@ -343,13 +339,11 @@ CREATE TABLE t2 (a INT) ENGINE=InnoDB; START TRANSACTION; INSERT INTO t1 VALUES (1); ---echo # Connection con2 --connect (con2,localhost,root) XA START 'xid1'; --echo # Sending: --send INSERT INTO t2 SELECT a FROM t1 ---echo # Connection default --connection default let $wait_condition= SELECT COUNT(*) = 1 FROM information_schema.processlist @@ -360,7 +354,6 @@ let $wait_condition= --sleep 0.1 DELETE FROM t1; ---echo # Connection con2 --connection con2 --echo # Reaping: INSERT INTO t2 SELECT a FROM t1 --error ER_LOCK_DEADLOCK @@ -368,12 +361,10 @@ DELETE FROM t1; --error ER_XA_RBDEADLOCK XA COMMIT 'xid1'; ---echo # Connection default connection default; COMMIT; ---echo # Connection con2 connection con2; # This caused the assert to be triggered XA START 'xid1'; @@ -382,7 +373,6 @@ XA END 'xid1'; XA PREPARE 'xid1'; XA ROLLBACK 'xid1'; ---echo # Connection default connection default; DROP TABLE t1, t2; disconnect con2; diff --git a/mysql-test/t/xml.test b/mysql-test/t/xml.test index 3e7c9b78673..417c206f6dc 100644 --- a/mysql-test/t/xml.test +++ b/mysql-test/t/xml.test @@ -754,3 +754,24 @@ DROP TABLE t1; --echo # --echo # End of 10.0 tests --echo # + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-10134 Add full support for DEFAULT +--echo # +CREATE TABLE t1 (a TEXT, b TEXT DEFAULT ExtractValue(a, '/a/b')); +INSERT INTO t1 (a) VALUES ('<a><b>bbb</b></a>'); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TEXT, b TEXT DEFAULT UpdateXML(a, '/a/b','<b>xxx</b>')); +INSERT INTO t1 (a) VALUES ('<a><b>bbb</b></a>'); +SELECT b FROM t1; +DROP TABLE t1; + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/mysql-test/t/xtradb_mrr.test b/mysql-test/t/xtradb_mrr.test index d994c182ccc..b56cbb0459f 100644 --- a/mysql-test/t/xtradb_mrr.test +++ b/mysql-test/t/xtradb_mrr.test @@ -1,4 +1,4 @@ --- source include/have_xtradb.inc +-- source include/have_innodb.inc --disable_warnings drop table if exists t1,t2,t3,t4; |
