From 07b8aefe90ca830d2de068f2966cd2288b158a88 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Wed, 3 Feb 2016 00:15:49 +0300 Subject: [PATCH] MDEV-9504: ANALYZE TABLE shows wrong 'rows' value for ORDER BY query Revert the patch for MDEV-9504. It causes test failures, attempt to fix these causes more failures. The source of all this is that the code in test_if_skip_sort_order() has a peculiar way of treating select_limit parameter: Correct value is computed when the query plan is changed. In other cases, we use an approximation that ignores the presence of GROUP BY clause, or JOINs, or both. A patch that fixes all of the above would be too big to do in 10.1 --- mysql-test/r/analyze_stmt_orderby.result | 26 +----------------------- mysql-test/t/analyze_stmt_orderby.test | 25 +---------------------- sql/sql_select.cc | 6 ++---- 3 files changed, 4 insertions(+), 53 deletions(-) diff --git a/mysql-test/r/analyze_stmt_orderby.result b/mysql-test/r/analyze_stmt_orderby.result index 643c0318f95..be1f01a2a52 100644 --- a/mysql-test/r/analyze_stmt_orderby.result +++ b/mysql-test/r/analyze_stmt_orderby.result @@ -583,28 +583,4 @@ ANALYZE } } drop table t2; -drop table t1; -# -# MDEV-9504: ANALYZE TABLE shows wrong 'rows' value for ORDER BY query -# -create table t1 ( -a int, -filler1 char(128), -filler2 char(128), -key(a) -); -insert into t1 -select A.a+10*B.a+100*C.a, repeat('abc-',32), repeat('abc-',32) -from t0 A, t0 B, t0 C; -analyze table t1; -Table Op Msg_type Msg_text -test.t1 analyze status Table is already up to date -explain select a from t1 order by a limit 10; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL a 5 NULL 10 Using index -# 'rows' in ANALYZE output must match 'rows' in EXPLAIN: -analyze select a from t1 order by a limit 10; -id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE t1 index NULL a 5 NULL 10 10.00 100.00 100.00 Using index -drop table t1; -drop table t0; +drop table t0,t1; diff --git a/mysql-test/t/analyze_stmt_orderby.test b/mysql-test/t/analyze_stmt_orderby.test index dc63fcaa285..a40f34805d1 100644 --- a/mysql-test/t/analyze_stmt_orderby.test +++ b/mysql-test/t/analyze_stmt_orderby.test @@ -174,27 +174,4 @@ select col1 f1, col2 f2, col1 f3 from t2 group by f1; drop table t2; -drop table t1; - ---echo # ---echo # MDEV-9504: ANALYZE TABLE shows wrong 'rows' value for ORDER BY query ---echo # -create table t1 ( - a int, - filler1 char(128), - filler2 char(128), - key(a) -); - -insert into t1 -select A.a+10*B.a+100*C.a, repeat('abc-',32), repeat('abc-',32) -from t0 A, t0 B, t0 C; -analyze table t1; - -explain select a from t1 order by a limit 10; ---echo # 'rows' in ANALYZE output must match 'rows' in EXPLAIN: -analyze select a from t1 order by a limit 10; - -drop table t1; -drop table t0; - +drop table t0,t1; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index de5f29d9bf4..ea30bf96f06 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -21031,14 +21031,12 @@ check_reverse_order: } table->file->ha_index_or_rnd_end(); - - if (select_limit < table->stat_records()) - tab->limit= select_limit; - if (tab->join->select_options & SELECT_DESCRIBE) { tab->ref.key= -1; tab->ref.key_parts= 0; + if (select_limit < table->stat_records()) + tab->limit= select_limit; table->disable_keyread(); } }