From b261ec393a3a82a1b6a5d51af632b9fa72016115 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Tue, 14 Oct 2014 15:11:06 +0400 Subject: [PATCH] MDEV-6484: Assertion `tab->ref.use_count' failed on query with joins, constant table, multi-part key - test_if_skip_sort_order()/create_ref_for_key() may change table access from EQ_REF(index1) to REF(index2). - Doing so doesn't make much sense from optimization POV, but since they are doing it, they should update tab->read_record.unlock_row accordingly. --- mysql-test/r/group_by.result | 11 +++++++++++ mysql-test/t/group_by.test | 14 ++++++++++++++ sql/sql_select.cc | 3 +++ 3 files changed, 28 insertions(+) diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result index 3de20ac6df4..57f21a5e0eb 100644 --- a/mysql-test/r/group_by.result +++ b/mysql-test/r/group_by.result @@ -2482,3 +2482,14 @@ test 1 2 SET sql_mode=''; +# +# MDEV-6484: Assertion `tab->ref.use_count' failed on query with joins, constant table, multi-part key +# +CREATE TABLE t1 (i1 INT, c1 VARCHAR(1)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (6,'b'); +CREATE TABLE t2 (pk2 INT, i2 INT, c2 VARCHAR(1), PRIMARY KEY(pk2), KEY(pk2,i2)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1,2,'s'),(2,4,'r'),(3,8,'m'),(4,4,'b'),(5,4,'x'),(6,7,'g'),(7,4,'p'); +SELECT i2 FROM t1 AS t1a STRAIGHT_JOIN ( t2 INNER JOIN t1 AS t1b ON (t1b.c1 = c2) ) ON (t1b.i1 = pk2 ) +WHERE t1a.c1 = c2 GROUP BY i2; +i2 +DROP TABLE t1,t2; diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test index 5aadf0693a1..92d1c18ee13 100644 --- a/mysql-test/t/group_by.test +++ b/mysql-test/t/group_by.test @@ -1651,6 +1651,20 @@ SET sql_mode='ONLY_FULL_GROUP_BY'; SELECT 1 AS test UNION SELECT 2 AS test ORDER BY test IS NULL ASC; SET sql_mode=''; +--echo # +--echo # MDEV-6484: Assertion `tab->ref.use_count' failed on query with joins, constant table, multi-part key +--echo # +CREATE TABLE t1 (i1 INT, c1 VARCHAR(1)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (6,'b'); + +CREATE TABLE t2 (pk2 INT, i2 INT, c2 VARCHAR(1), PRIMARY KEY(pk2), KEY(pk2,i2)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1,2,'s'),(2,4,'r'),(3,8,'m'),(4,4,'b'),(5,4,'x'),(6,7,'g'),(7,4,'p'); + +SELECT i2 FROM t1 AS t1a STRAIGHT_JOIN ( t2 INNER JOIN t1 AS t1b ON (t1b.c1 = c2) ) ON (t1b.i1 = pk2 ) +WHERE t1a.c1 = c2 GROUP BY i2; + +DROP TABLE t1,t2; + # # End of MariaDB 5.5 tests # diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 3b960d457a7..a7ba1c734e9 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -8178,6 +8178,9 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j, } else j->type=JT_EQ_REF; + + j->read_record.unlock_row= (j->type == JT_EQ_REF)? + join_read_key_unlock_row : rr_unlock_row; DBUG_RETURN(0); }