Commit eecf0687 authored by Gleb Shchepa's avatar Gleb Shchepa

Bug #44886: SIGSEGV in test_if_skip_sort_order() -

            uninitialized variable used as subscript

Grouping select from a "constant" InnoDB table (a table
of a single row) joined with other tables caused a crash.
parent 69e78274
......@@ -2120,4 +2120,21 @@ a b
4 14
5 5
DROP TABLE t1, t2, t3, t4;
#
# Bug#44886: SIGSEGV in test_if_skip_sort_order() -
# uninitialized variable used as subscript
#
CREATE TABLE t1 (a INT, b INT, c INT, d INT, PRIMARY KEY (b), KEY (a,c))
ENGINE=InnoDB;
INSERT INTO t1 VALUES (1,1,1,0);
CREATE TABLE t2 (a INT, b INT, e INT, KEY (e)) ENGINE=InnoDB;
INSERT INTO t2 VALUES (1,1,2);
CREATE TABLE t3 (a INT, b INT) ENGINE=MyISAM;
INSERT INTO t3 VALUES (1, 1);
SELECT * FROM t1, t2, t3
WHERE t1.a = t3.a AND (t1.b = t3.b OR t1.d) AND t2.b = t1.b AND t2.e = 2
GROUP BY t1.b;
a b c d a b e a b
1 1 1 0 1 1 2 1 1
DROP TABLE t1, t2, t3;
End of 5.1 tests
......@@ -359,4 +359,25 @@ SELECT * FROM t4;
DROP TABLE t1, t2, t3, t4;
--echo #
--echo # Bug#44886: SIGSEGV in test_if_skip_sort_order() -
--echo # uninitialized variable used as subscript
--echo #
CREATE TABLE t1 (a INT, b INT, c INT, d INT, PRIMARY KEY (b), KEY (a,c))
ENGINE=InnoDB;
INSERT INTO t1 VALUES (1,1,1,0);
CREATE TABLE t2 (a INT, b INT, e INT, KEY (e)) ENGINE=InnoDB;
INSERT INTO t2 VALUES (1,1,2);
CREATE TABLE t3 (a INT, b INT) ENGINE=MyISAM;
INSERT INTO t3 VALUES (1, 1);
SELECT * FROM t1, t2, t3
WHERE t1.a = t3.a AND (t1.b = t3.b OR t1.d) AND t2.b = t1.b AND t2.e = 2
GROUP BY t1.b;
DROP TABLE t1, t2, t3;
--echo End of 5.1 tests
......@@ -12658,7 +12658,10 @@ static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx,
one row). The sorting doesn't matter.
*/
if (key_part == key_part_end && reverse == 0)
{
*used_key_parts= 0;
DBUG_RETURN(1);
}
}
else
DBUG_RETURN(0);
......@@ -13155,7 +13158,8 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
select_limit= table_records;
if (group)
{
rec_per_key= keyinfo->rec_per_key[used_key_parts-1];
rec_per_key= used_key_parts ? keyinfo->rec_per_key[used_key_parts-1]
: 1;
set_if_bigger(rec_per_key, 1);
/*
With a grouping query each group containing on average
......
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