Commit 494acc19 authored by Monty's avatar Monty

MDEV-30325 Wrong result upon range query using index condition wrong result...

MDEV-30325 Wrong result upon range query using index condition wrong result upon range query using index condition

This was caused by a bug in key_or() when SEL_ARG* key1 has been cloned
and is overlapping with SEL_ARG *key2

Cloning of SEL_ARG's happens only in very special cases, which is why this
bug has remained undetected for years.

It happend in the following query:

SELECT COUNT(*) FROM lineitem force index
(i_l_orderkey_quantity,i_l_shipdate) WHERE
l_shipdate < '1994-01-01' AND l_orderkey < 800 OR
l_quantity > 3 AND l_orderkey NOT IN ( 157, 1444 );

Because there are two different indexes that can be used and the code for
IN causes a 'tree_or', which causes all SEL_ARG's to be cloned.

Other things:
- While checking the code, I found a bug in SEL_ARG::SEL_ARG(SEL_ARG &arg)
 - This was incrementing next_key_part->use_count as part of creating a
   copy of an existing SEL_ARG.
   This is however not enough as the 'reverse operation' when the copy is
   not needed is 'key2_cpy.increment_use_count(-1)', which does something
   completely different.
   Fixed by calling increment_use_count(1) in SEL_ARG::SEL_ARG.
parent f8f74754
set default_storage_engine=Aria;
CREATE DATABASE dbt3_s001;
use dbt3_s001;
#
# MDEV-30325 Wrong result upon range query using index condition
#
SELECT COUNT(*) FROM lineitem force index (i_l_orderkey_quantity,i_l_shipdate) WHERE l_shipdate < '1994-01-01' AND l_orderkey < 800 OR l_quantity > 3 AND l_orderkey NOT IN ( 157, 1444 );
COUNT(*)
5056
#
# End of 10.5 tests
#
DROP DATABASE dbt3_s001;
#
# This is generic tests using dbt3_s001 tables
# This file uses the Aria storage engine
#
set default_storage_engine=Aria;
CREATE DATABASE dbt3_s001;
use dbt3_s001;
--disable_query_log
--source include/dbt3_s001.inc
--enable_query_log
--echo #
--echo # MDEV-30325 Wrong result upon range query using index condition
--echo #
SELECT COUNT(*) FROM lineitem force index (i_l_orderkey_quantity,i_l_shipdate) WHERE l_shipdate < '1994-01-01' AND l_orderkey < 800 OR l_quantity > 3 AND l_orderkey NOT IN ( 157, 1444 );
--echo #
--echo # End of 10.5 tests
--echo #
DROP DATABASE dbt3_s001;
......@@ -1890,7 +1890,7 @@ SEL_ARG::SEL_ARG(SEL_ARG &arg) :Sql_alloc()
next= 0;
if (next_key_part)
{
++next_key_part->use_count;
next_key_part->increment_use_count(1);
weight += next_key_part->weight;
}
}
......@@ -10607,8 +10607,7 @@ key_or(RANGE_OPT_PARAM *param, SEL_ARG *key1,SEL_ARG *key2)
Move on to next range in key2
*/
key2->increment_use_count(-1); // Free not used tree
key2=key2_next;
continue;
key2= key2_next;
}
else
{
......@@ -10622,8 +10621,9 @@ key_or(RANGE_OPT_PARAM *param, SEL_ARG *key1,SEL_ARG *key2)
tmp: [---------]
*/
key2->copy_max_to_min(tmp);
continue;
key2= key2_next;
}
continue;
}
/*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment