Commit 6a716d68 authored by Igor Babaev's avatar Igor Babaev

Fixed LP bug #870046.

This bug is a consequence of the fix in the function add_ref_to_table_cond
for LP bug 826935 that turned out to be not quite correct: it tried to AND
the same generated condition with two different other conditions.
This patch creates a copy of the generated condition if the condition needs
to be ANDed with two different items.
parent e7818137
......@@ -238,4 +238,26 @@ SELECT b FROM t1 WHERE a != 1 AND c IS NULL ORDER BY 1;
b
byluovkgwoukfxedyeffsedajyqkyhpaqqpozn
DROP TABLE t1;
#
# Bug#870046: ICP for a GROUP BY query
#
CREATE TABLE t1 (a int, b varchar(1), c varchar(1), INDEX idx(b));
INSERT INTO t1 VALUES (2,'x','x'), (5,'x','y');
SET SESSION optimizer_switch='index_condition_pushdown=off';
EXPLAIN
SELECT a, MIN(c) FROM t1 WHERE b = 'x' AND c > 'x' GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref idx idx 4 const 1 Using where; Using temporary; Using filesort
SELECT a, MIN(c) FROM t1 WHERE b = 'x' AND c > 'x' GROUP BY a;
a MIN(c)
5 y
SET SESSION optimizer_switch='index_condition_pushdown=on';
EXPLAIN
SELECT a, MIN(c) FROM t1 WHERE b = 'x' AND c > 'x' GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref idx idx 4 const 1 Using index condition; Using where; Using temporary; Using filesort
SELECT a, MIN(c) FROM t1 WHERE b = 'x' AND c > 'x' GROUP BY a;
a MIN(c)
5 y
DROP TABLE t1;
set optimizer_switch=@myisam_icp_tmp;
......@@ -209,4 +209,22 @@ INSERT INTO t1 VALUES
SELECT b FROM t1 WHERE a != 1 AND c IS NULL ORDER BY 1;
DROP TABLE t1;
--echo #
--echo # Bug#870046: ICP for a GROUP BY query
--echo #
CREATE TABLE t1 (a int, b varchar(1), c varchar(1), INDEX idx(b));
INSERT INTO t1 VALUES (2,'x','x'), (5,'x','y');
SET SESSION optimizer_switch='index_condition_pushdown=off';
EXPLAIN
SELECT a, MIN(c) FROM t1 WHERE b = 'x' AND c > 'x' GROUP BY a;
SELECT a, MIN(c) FROM t1 WHERE b = 'x' AND c > 'x' GROUP BY a;
SET SESSION optimizer_switch='index_condition_pushdown=on';
EXPLAIN
SELECT a, MIN(c) FROM t1 WHERE b = 'x' AND c > 'x' GROUP BY a;
SELECT a, MIN(c) FROM t1 WHERE b = 'x' AND c > 'x' GROUP BY a;
DROP TABLE t1;
set optimizer_switch=@myisam_icp_tmp;
......@@ -19895,6 +19895,7 @@ static bool add_ref_to_table_cond(THD *thd, JOIN_TAB *join_tab)
DBUG_RETURN(FALSE);
Item_cond_and *cond=new Item_cond_and();
Item *cond_copy;
TABLE *table=join_tab->table;
int error= 0;
if (!cond)
......@@ -19909,13 +19910,14 @@ static bool add_ref_to_table_cond(THD *thd, JOIN_TAB *join_tab)
}
if (thd->is_fatal_error)
DBUG_RETURN(TRUE);
if (!cond->fixed)
{
Item *tmp_item= (Item*) cond;
cond->fix_fields(thd, &tmp_item);
DBUG_ASSERT(cond == tmp_item);
}
if (join_tab->select->pre_idx_push_select_cond)
cond_copy= cond->copy_andor_structure(thd);
if (join_tab->select)
{
if (join_tab->select->cond)
......@@ -19923,7 +19925,7 @@ static bool add_ref_to_table_cond(THD *thd, JOIN_TAB *join_tab)
join_tab->select->cond= cond;
if (join_tab->select->pre_idx_push_select_cond)
{
Item *new_cond= and_conds(join_tab->select->pre_idx_push_select_cond, cond);
Item *new_cond= and_conds(cond_copy, join_tab->select->pre_idx_push_select_cond);
if (!new_cond->fixed && new_cond->fix_fields(thd, &new_cond))
error= 1;
join_tab->select->pre_idx_push_select_cond= new_cond;
......
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