summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2012-01-18 03:31:20 -0800
committerIgor Babaev <igor@askmonty.org>2012-01-18 03:31:20 -0800
commit746dbbe583f8528b34065b0669136842128e27b2 (patch)
tree7f368922928ea854c3c5d6531cc2d757bd63f570 /sql
parent296b450d3b58ded0fd4d4972161414c6cc7a80e5 (diff)
downloadmariadb-git-746dbbe583f8528b34065b0669136842128e27b2.tar.gz
Fixed LP bug #917990.
If the expression for a derived table of a query contained a LIMIT clause the estimate of the number of rows in this derived table returned by the EXPLAIN command could be badly off since the optimizer ignored the limit number from the LIMIT clause when getting the estimate. The call of the method SELECT_LEX_UNIT->set_limit added in the code of mysql_derived_optimize() will be needed also in maria-5.5 where parameters in the LIMIT clause are supported.
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_derived.cc1
-rw-r--r--sql/sql_select.cc1
2 files changed, 2 insertions, 0 deletions
diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc
index 0e104520fac..0955f9c0982 100644
--- a/sql/sql_derived.cc
+++ b/sql/sql_derived.cc
@@ -753,6 +753,7 @@ bool mysql_derived_optimize(THD *thd, LEX *lex, TABLE_LIST *derived)
if (!derived->is_merged_derived())
{
JOIN *join= first_select->join;
+ unit->set_limit(first_select);
unit->optimized= TRUE;
if ((res= join->optimize()))
goto err;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index fe52bc05465..dc13e1ddcab 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -3581,6 +3581,7 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list,
for (i= 0; i < join->table_count ; i++)
records*= join->best_positions[i].records_read ?
(ha_rows)join->best_positions[i].records_read : 1;
+ set_if_smaller(records, unit->select_limit_cnt);
join->select_lex->increase_derived_records(records);
}
}