Commit 50150fd6 authored by Mattias Jonsson's avatar Mattias Jonsson

Bug#53806: Wrong estimates for range query in partitioned MyISAM table

Bug#46754: 'rows' field doesn't reflect partition pruning

The EXPLAIN's result in 'rows' field
was evaluated to number of rows when the table was opened
(not from the table cache) and only the partitions left
after pruning was updated with its correct number
of rows.

The evaluation of the 'rows' field was using handler::records()
which is a potentially expensive call, and ignores the partitioning
pruning.

The fix was to use the handlers stats.records after updating it
with ::info(HA_STATUS_VARIABLE) instead.
parent 6973c354
This diff is collapsed.
......@@ -8,6 +8,30 @@
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
--enable_warnings
--echo #
--echo # Bug#53806: Wrong estimates for range query in partitioned MyISAM table
--echo # Bug#46754: 'rows' field doesn't reflect partition pruning
--echo #
CREATE TABLE t1 (a INT PRIMARY KEY)
PARTITION BY RANGE (a) (
PARTITION p0 VALUES LESS THAN (1),
PARTITION p1 VALUES LESS THAN (2),
PARTITION p2 VALUES LESS THAN (3),
PARTITION p3 VALUES LESS THAN (4),
PARTITION p4 VALUES LESS THAN (5),
PARTITION p5 VALUES LESS THAN (6),
PARTITION max VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (-1),(0),(1),(2),(3),(4),(5),(6),(7),(8);
--replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 11 #
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1;
--replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 11 #
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 7;
--replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 11 #
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1;
DROP TABLE t1;
--echo #
--echo # Bug#49742: Partition Pruning not working correctly for RANGE
--echo #
......
......@@ -16640,7 +16640,15 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
if (tab->select && tab->select->quick)
examined_rows= tab->select->quick->records;
else if (tab->type == JT_NEXT || tab->type == JT_ALL)
examined_rows= tab->limit ? tab->limit : tab->table->file->records();
{
if (tab->limit)
examined_rows= tab->limit;
else
{
tab->table->file->info(HA_STATUS_VARIABLE);
examined_rows= tab->table->file->stats.records;
}
}
else
examined_rows=(ha_rows)join->best_positions[i].records_read;
......
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