summaryrefslogtreecommitdiff
path: root/mysql-test/main/key.test
diff options
context:
space:
mode:
authorVarun Gupta <varun.gupta@mariadb.com>2020-04-21 12:16:10 +0530
committerVarun Gupta <varun.gupta@mariadb.com>2020-05-01 15:17:10 +0530
commit644d9f38b97b198ec356aadfc390e0fef97c53f0 (patch)
tree841be926c58ac3b8689d856eb482c71f5fdb8bcd /mysql-test/main/key.test
parent7f9dc0d84aeef01747389a3ef074217acdcb2410 (diff)
downloadmariadb-git-644d9f38b97b198ec356aadfc390e0fef97c53f0.tar.gz
MDEV-21480: Unique key using ref access though eq_ref access can be used
For a unique key if all the keyparts are NOT NULL or the predicates involving the keyparts is NULL rejecting, then we can use EQ_REF access instead of ref access with the unique key
Diffstat (limited to 'mysql-test/main/key.test')
-rw-r--r--mysql-test/main/key.test21
1 files changed, 21 insertions, 0 deletions
diff --git a/mysql-test/main/key.test b/mysql-test/main/key.test
index 0695dc2eecb..b386f1298fd 100644
--- a/mysql-test/main/key.test
+++ b/mysql-test/main/key.test
@@ -1,6 +1,7 @@
--disable_warnings
drop table if exists t1,t2,t3;
--enable_warnings
+--source include/have_sequence.inc
SET SQL_WARNINGS=1;
#
@@ -581,3 +582,23 @@ EXPLAIN SELECT a, SUM( b ) FROM t1 FORCE INDEX( a ) GROUP BY a;
SHOW STATUS LIKE 'Last_query_cost';
DROP TABLE t1;
+
+--echo #
+--echo # MDEV-21480: Unique key using ref access though eq_ref access can be used
+--echo #
+
+create table t1(a int, b int,c int, primary key(a), unique key(b,c));
+insert into t1 select seq, seq, seq from seq_1_to_10;
+
+create table t2(a int, b int,c int);
+insert into t2 select seq, seq, seq+1 from seq_1_to_100;
+
+EXPLAIN SELECT t1.c, t2.c FROM t1, t2 WHERE t1.b=t2.a and t1.c=t2.b;
+SELECT t1.c, t2.c FROM t1, t2 WHERE t1.b=t2.a and t1.c=t2.b;
+
+alter table t1 drop PRIMARY KEY;
+alter table t1 add PRIMARY KEY(b,c);
+EXPLAIN SELECT t1.c, t2.c FROM t1, t2 WHERE t1.b=t2.a and t1.c=t2.b;
+SELECT t1.c, t2.c FROM t1, t2 WHERE t1.b=t2.a and t1.c=t2.b;
+
+drop table t1,t2;