Commit ae4eb6b5 authored by igor@rurik.mysql.com's avatar igor@rurik.mysql.com

Fixed bug #14292: performance degradation for a benchmark query.

This performance degradation was due to the fact that some
cost evaluation code added into 4.1 in the function find_best was
not merged into the code of the function best_access_path added
together with other code for greedy optimizer.
Added a parameter to the function print_plan. The parameter contains
accumulated cost for a given partial join.
 
The patch does not include a special test case since this performance
degradation is hard to reproduse with a simple example.

TODO: make the function find_best use the function best_access_path
in order to remove duplication of code which might result in incomplete
merges in the future.
parent 806564d7
......@@ -186,8 +186,8 @@ a b a b a b
explain select * from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3
1 SIMPLE t2 index PRIMARY PRIMARY 8 NULL 3 Using where; Using index
1 SIMPLE t3 index PRIMARY PRIMARY 8 NULL 3 Using where; Using index
1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.a 1 Using index
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 8 test.t2.b,test.t1.b 1 Using index
delete t2.*,t3.* from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
select * from t3;
a b
......
......@@ -1354,10 +1354,10 @@ a
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 index NULL a 5 NULL 4 Using where; Using index
2 DEPENDENT SUBQUERY t3 index a a 5 NULL 3 Using index
2 DEPENDENT SUBQUERY t1 ref a a 10 func,test.t3.a 1167 Using where; Using index
2 DEPENDENT SUBQUERY t1 ref a a 5 func 1001 Using where; Using index
2 DEPENDENT SUBQUERY t3 index a a 5 NULL 3 Using where; Using index
Warnings:
Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(select 1 AS `Not_used` from `test`.`t1` join `test`.`t3` where ((`test`.`t1`.`b` = `test`.`t3`.`a`) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))
Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`a`,<exists>(select 1 AS `Not_used` from `test`.`t1` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t1`.`b`) and (<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`))))
insert into t1 values (3,31);
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
a
......
......@@ -1066,8 +1066,8 @@ pthread_handler_t handle_manager(void *arg);
void print_where(COND *cond,const char *info);
void print_cached_tables(void);
void TEST_filesort(SORT_FIELD *sortorder,uint s_length);
void print_plan(JOIN* join, double read_time, double record_count,
uint idx, const char *info);
void print_plan(JOIN* join,uint idx, double record_count, double read_time,
double current_read_time, const char *info);
#endif
void mysql_print_status();
/* key.cc */
......
This diff is collapsed.
......@@ -230,8 +230,8 @@ TEST_join(JOIN *join)
*/
void
print_plan(JOIN* join, double read_time, double record_count,
uint idx, const char *info)
print_plan(JOIN* join, uint idx, double record_count, double read_time,
double current_read_time, const char *info)
{
uint i;
POSITION pos;
......@@ -245,13 +245,15 @@ print_plan(JOIN* join, double read_time, double record_count,
DBUG_LOCK_FILE;
if (join->best_read == DBL_MAX)
{
fprintf(DBUG_FILE,"%s; idx:%u, best: DBL_MAX, current:%g\n",
info, idx, read_time);
fprintf(DBUG_FILE,
"%s; idx:%u, best: DBL_MAX, atime: %g, itime: %g, count: %g\n",
info, idx, current_read_time, read_time, record_count);
}
else
{
fprintf(DBUG_FILE,"%s; idx: %u, best: %g, current: %g\n",
info, idx, join->best_read, read_time);
fprintf(DBUG_FILE,
"%s; idx:%u, best: %g, atime: %g, itime: %g, count: %g\n",
info, idx, join->best_read, current_read_time, read_time, record_count);
}
/* Print the tables in JOIN->positions */
......
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