Commit e6dee57f authored by Sergei Petrunia's avatar Sergei Petrunia

MDEV-9504: ANALYZE TABLE shows wrong 'rows' value for ORDER BY query

- Legacy code would set JOIN_TAB::limit only for EXPLAIN queries (this
  variable is only used when producing EXPLAIN output)

- ANALYZE/SHOW EXPLAIN need to produce EXPLAIN output for non-EXPLAIN
  queries, too, so we should always set JOIN_TAB::limit.
parent 91ff0172
......@@ -583,4 +583,28 @@ ANALYZE
}
}
drop table t2;
drop table t0,t1;
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;
......@@ -174,4 +174,27 @@ select col1 f1, col2 f2, col1 f3 from t2 group by f1;
drop table t2;
drop table t0,t1;
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;
......@@ -21031,12 +21031,14 @@ 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();
}
}
......
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