1
0
mirror of https://github.com/MariaDB/server.git synced 2025-12-24 11:21:21 +03:00

MDEV-214 lp:967242 Wrong result with JOIN, AND in ON condition, multi-part key, GROUP BY, subquery and OR in WHERE

The problem was in the code (update_const_equal_items()) which marked
index parts constant independently of the place where the equality was used.
In the test suite it marked t2_1.c part constant despite the fact that
it connected by OR with other expression.

Solution is to mark constant only top equalities connected with AND.
This commit is contained in:
Oleksandr Byelkin
2012-05-02 18:11:02 +02:00
parent b192f7a2e7
commit 8fe40c50db
4 changed files with 98 additions and 6 deletions

View File

@@ -8554,9 +8554,10 @@ static COND* substitute_for_best_equal_field(COND *cond,
@param cond condition whose multiple equalities are to be checked
@param table constant table that has been read
@param const_key mark key parts as constant
*/
static void update_const_equal_items(COND *cond, JOIN_TAB *tab)
static void update_const_equal_items(COND *cond, JOIN_TAB *tab, bool const_key)
{
if (!(cond->used_tables() & tab->table->map))
return;
@@ -8567,7 +8568,10 @@ static void update_const_equal_items(COND *cond, JOIN_TAB *tab)
List_iterator_fast<Item> li(*cond_list);
Item *item;
while ((item= li++))
update_const_equal_items(item, tab);
update_const_equal_items(item, tab,
(((Item_cond*) cond)->top_level() &&
((Item_cond*) cond)->functype() ==
Item_func::COND_AND_FUNC));
}
else if (cond->type() == Item::FUNC_ITEM &&
((Item_cond*) cond)->functype() == Item_func::MULT_EQUAL_FUNC)
@@ -8598,7 +8602,8 @@ static void update_const_equal_items(COND *cond, JOIN_TAB *tab)
TABLE *tab= field->table;
KEYUSE *use;
for (use= stat->keyuse; use && use->table == tab; use++)
if (possible_keys.is_set(use->key) &&
if (const_key &&
possible_keys.is_set(use->key) &&
tab->key_info[use->key].key_part[use->keypart].field ==
field)
tab->const_key_parts[use->key]|= use->keypart_map;
@@ -12236,7 +12241,7 @@ join_read_const_table(JOIN_TAB *tab, POSITION *pos)
/* Check appearance of new constant items in Item_equal objects */
JOIN *join= tab->join;
if (join->conds)
update_const_equal_items(join->conds, tab);
update_const_equal_items(join->conds, tab, TRUE);
TABLE_LIST *tbl;
for (tbl= join->select_lex->leaf_tables; tbl; tbl= tbl->next_leaf)
{
@@ -12246,7 +12251,7 @@ join_read_const_table(JOIN_TAB *tab, POSITION *pos)
{
embedded= embedding;
if (embedded->on_expr)
update_const_equal_items(embedded->on_expr, tab);
update_const_equal_items(embedded->on_expr, tab, TRUE);
embedding= embedded->embedding;
}
while (embedding &&
@@ -13799,7 +13804,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
int ref_key;
uint ref_key_parts;
int order_direction= 0;
uint used_key_parts;
uint used_key_parts= 0;
TABLE *table=tab->table;
SQL_SELECT *select=tab->select;
key_map usable_keys;