1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

fixed bug in used_tables() report of left expression of IN subquery

fixed number of rows of external field reported to optimizer
added check of choosen key (checked left expression tag)
(SCRUM fix for simple IN optimisation)


mysql-test/r/subselect.result:
  new EXPLAIN results ufter fixing used_tables() of Item_cache
sql/item_cmpfunc.cc:
  fixed used_tables asignment
sql/item_subselect.cc:
  added left expression referenca tag
sql/item_subselect.h:
  fixed layout
sql/mysql_priv.h:
  left expression reference tag
sql/mysqld.cc:
  left expression reference tag
sql/sql_select.cc:
  checked left expression reference tag
  fixed number of rows in outer reference (it should be constant)
This commit is contained in:
unknown
2003-08-07 11:16:02 +03:00
parent 4a8ab8ac56
commit 57e31f158b
7 changed files with 43 additions and 29 deletions

View File

@ -772,7 +772,8 @@ JOIN::optimize()
if (!having)
{
Item *where= 0;
if (join_tab[0].type == JT_EQ_REF)
if (join_tab[0].type == JT_EQ_REF &&
join_tab[0].ref.items[0]->name == in_left_expr_name)
{
if (test_in_subselect(&where))
{
@ -785,7 +786,8 @@ JOIN::optimize()
where)));
}
}
else if (join_tab[0].type == JT_REF)
else if (join_tab[0].type == JT_REF &&
join_tab[0].ref.items[0]->name == in_left_expr_name)
{
if (test_in_subselect(&where))
{
@ -800,6 +802,7 @@ JOIN::optimize()
}
}
} else if (join_tab[0].type == JT_REF_OR_NULL &&
join_tab[0].ref.items[0]->name == in_left_expr_name &&
having->type() == Item::FUNC_ITEM &&
((Item_func *) having)->functype() ==
Item_func::ISNOTNULLTEST_FUNC)
@ -2347,7 +2350,8 @@ sort_keyuse(KEYUSE *a,KEYUSE *b)
if (a->keypart != b->keypart)
return (int) (a->keypart - b->keypart);
// Place const values before other ones
if ((res= test(a->used_tables) - test(b->used_tables)))
if ((res= test((a->used_tables & ~OUTER_REF_TABLE_BIT)) -
test((b->used_tables & ~OUTER_REF_TABLE_BIT))))
return res;
/* Place rows that are not 'OPTIMIZE_REF_OR_NULL' first */
return (int) ((a->optimize & KEY_OPTIMIZE_REF_OR_NULL) -
@ -2478,6 +2482,12 @@ static void optimize_keyuse(JOIN *join, DYNAMIC_ARRAY *keyuse_array)
keyuse->ref_table_rows= max(tmp_table->file->records, 100);
}
}
/*
Outer reference (external field) is constant for single executing
of subquery
*/
if (keyuse->used_tables == OUTER_REF_TABLE_BIT)
keyuse->ref_table_rows= 1;
}
}