Skip to content

Commit

Permalink
MDEV-31237 Assertion `!(tab->select && tab->select->quick)' failed in…
Browse files Browse the repository at this point in the history
… make_join_readinfo

The problem was a wrong assert. I changed it to match the code in
best_access_path().

The given test case was a bit tricky for the optimizer, which first
decided on using a index scan (because of force index), but then
test_if_skip_sort_order() decided to use range anyway to handle
distinct.
  • Loading branch information
montywi committed May 27, 2023
1 parent 6611419 commit aac88fc
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
15 changes: 15 additions & 0 deletions mysql-test/main/range.result
Original file line number Diff line number Diff line change
Expand Up @@ -3824,5 +3824,20 @@ id MIN(id)
8 8
DROP TABLE t1;
#
# MDEV-31237 Assertion `!(tab->select && tab->select->quick)' failed
# in make_join_readinfo
#
CREATE TABLE lineitem (l_orderkey int, l_linenumber int, l_receiptDATE date DEFAULT NULL, PRIMARY KEY (l_orderkey,l_linenumber), KEY i_l_receiptdate (l_receiptDATE), KEY i_l_orderkey (l_orderkey)) ENGINE=InnoDB;
INSERT INTO lineitem VALUES (291,1,'1994-06-23'),(291,2,'1994-06-19'),
(291,3,'1994-03-24'),(292,1,'1992-03-18'),(292,2,'1992-04-20');
EXPLAIN SELECT DISTINCT l_orderkey FROM lineitem FORCE KEY (i_l_orderkey, i_l_receiptdate) WHERE l_orderkey > 1 ORDER BY l_receiptdate;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE lineitem range i_l_orderkey i_l_orderkey 4 NULL 5 Using where; Using temporary; Using filesort
SELECT DISTINCT l_orderkey FROM lineitem FORCE KEY (i_l_orderkey, i_l_receiptdate) WHERE l_orderkey > 1 ORDER BY l_receiptdate;
l_orderkey
292
291
DROP TABLE lineitem;
#
# End of 11.0 tests
#
12 changes: 12 additions & 0 deletions mysql-test/main/range.test
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,18 @@ WHERE (b > 'TX' OR b BETWEEN 'NE' AND 'SC') AND id IN (1,7,8) AND a = 5
GROUP BY id;
DROP TABLE t1;

--echo #
--echo # MDEV-31237 Assertion `!(tab->select && tab->select->quick)' failed
--echo # in make_join_readinfo
--echo #

CREATE TABLE lineitem (l_orderkey int, l_linenumber int, l_receiptDATE date DEFAULT NULL, PRIMARY KEY (l_orderkey,l_linenumber), KEY i_l_receiptdate (l_receiptDATE), KEY i_l_orderkey (l_orderkey)) ENGINE=InnoDB;
INSERT INTO lineitem VALUES (291,1,'1994-06-23'),(291,2,'1994-06-19'),
(291,3,'1994-03-24'),(292,1,'1992-03-18'),(292,2,'1992-04-20');
EXPLAIN SELECT DISTINCT l_orderkey FROM lineitem FORCE KEY (i_l_orderkey, i_l_receiptdate) WHERE l_orderkey > 1 ORDER BY l_receiptdate;
SELECT DISTINCT l_orderkey FROM lineitem FORCE KEY (i_l_orderkey, i_l_receiptdate) WHERE l_orderkey > 1 ORDER BY l_receiptdate;
DROP TABLE lineitem;

--echo #
--echo # End of 11.0 tests
--echo #
15 changes: 15 additions & 0 deletions mysql-test/main/range_mrr_icp.result
Original file line number Diff line number Diff line change
Expand Up @@ -3821,6 +3821,21 @@ id MIN(id)
8 8
DROP TABLE t1;
#
# MDEV-31237 Assertion `!(tab->select && tab->select->quick)' failed
# in make_join_readinfo
#
CREATE TABLE lineitem (l_orderkey int, l_linenumber int, l_receiptDATE date DEFAULT NULL, PRIMARY KEY (l_orderkey,l_linenumber), KEY i_l_receiptdate (l_receiptDATE), KEY i_l_orderkey (l_orderkey)) ENGINE=InnoDB;
INSERT INTO lineitem VALUES (291,1,'1994-06-23'),(291,2,'1994-06-19'),
(291,3,'1994-03-24'),(292,1,'1992-03-18'),(292,2,'1992-04-20');
EXPLAIN SELECT DISTINCT l_orderkey FROM lineitem FORCE KEY (i_l_orderkey, i_l_receiptdate) WHERE l_orderkey > 1 ORDER BY l_receiptdate;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE lineitem range i_l_orderkey i_l_orderkey 4 NULL 5 Using where; Using temporary; Using filesort
SELECT DISTINCT l_orderkey FROM lineitem FORCE KEY (i_l_orderkey, i_l_receiptdate) WHERE l_orderkey > 1 ORDER BY l_receiptdate;
l_orderkey
292
291
DROP TABLE lineitem;
#
# End of 11.0 tests
#
set optimizer_switch=@mrr_icp_extra_tmp;
11 changes: 10 additions & 1 deletion sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15373,7 +15373,16 @@ make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after)
push_index_cond(tab, tab->ref.key);
break;
case JT_NEXT: // Index scan
DBUG_ASSERT(!(tab->select && tab->select->quick));
DBUG_ASSERT(!tab->quick);
if (tab->select)
{
/*
select->quick may be set if there was a possible range and
it had a higher cost than a table scan.
*/
delete tab->select->quick;
tab->select->quick=0;
}
if (tab->use_quick == 2)
{
join->thd->set_status_no_good_index_used();
Expand Down

0 comments on commit aac88fc

Please sign in to comment.