Commit daaa5834 authored by Igor Babaev's avatar Igor Babaev

Fixed bug mdev-4370.

Don't try to a histogram if it is not read into the cache for statistical data.
It may happen so if optimizer_use_condition_selectivity is set to 3. This 
setting orders the optimizer not use histograms to calculate selectivity.
parent 4079a5dc
......@@ -794,4 +794,32 @@ SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10;
1
DROP TABLE t1,t2;
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
#
# Bug mdev-4370: Histograms have bean created, but the query is run after
# FLUSH TABLES with optimizer_use_condition_selectivity=3
#
set use_stat_tables=PREFERABLY;
set histogram_size=10;
set histogram_type='SINGLE_PREC_HB';
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (9), (1);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
FLUSH TABLES;
set optimizer_use_condition_selectivity=3;
EXPLAIN EXTENDED
SELECT * FROM t1 WHERE a > 3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 75.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 3)
SELECT * FROM t1 WHERE a > 3;
a
9
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
DROP TABLE t1;
set histogram_size=@save_histogram_size;
set histogram_type=@save_histogram_type;
set use_stat_tables=@save_use_stat_tables;
set use_stat_tables=@save_use_stat_tables;
......@@ -801,6 +801,34 @@ SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10;
1
DROP TABLE t1,t2;
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
#
# Bug mdev-4370: Histograms have bean created, but the query is run after
# FLUSH TABLES with optimizer_use_condition_selectivity=3
#
set use_stat_tables=PREFERABLY;
set histogram_size=10;
set histogram_type='SINGLE_PREC_HB';
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (9), (1);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
FLUSH TABLES;
set optimizer_use_condition_selectivity=3;
EXPLAIN EXTENDED
SELECT * FROM t1 WHERE a > 3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 75.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 3)
SELECT * FROM t1 WHERE a > 3;
a
9
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
DROP TABLE t1;
set histogram_size=@save_histogram_size;
set histogram_type=@save_histogram_type;
set use_stat_tables=@save_use_stat_tables;
set use_stat_tables=@save_use_stat_tables;
set optimizer_switch=@save_optimizer_switch_for_selectivity_test;
SET SESSION STORAGE_ENGINE=DEFAULT;
......@@ -384,5 +384,32 @@ DROP TABLE t1,t2;
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
--echo #
--echo # Bug mdev-4370: Histograms have bean created, but the query is run after
--echo # FLUSH TABLES with optimizer_use_condition_selectivity=3
--echo #
set use_stat_tables=PREFERABLY;
set histogram_size=10;
set histogram_type='SINGLE_PREC_HB';
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (9), (1);
ANALYZE TABLE t1;
FLUSH TABLES;
set optimizer_use_condition_selectivity=3;
EXPLAIN EXTENDED
SELECT * FROM t1 WHERE a > 3;
SELECT * FROM t1 WHERE a > 3;
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
DROP TABLE t1;
set histogram_size=@save_histogram_size;
set histogram_type=@save_histogram_type;
set use_stat_tables=@save_use_stat_tables;
set use_stat_tables=@save_use_stat_tables;
......@@ -3369,7 +3369,7 @@ double get_column_range_cardinality(Field *field,
col_stats->min_value && col_stats->max_value)
{
Histogram *hist= &col_stats->histogram;
if (hist->get_size() > 0)
if (hist->is_available())
{
double pos= field->middle_point_pos(col_stats->min_value,
col_stats->max_value);
......@@ -3406,7 +3406,7 @@ double get_column_range_cardinality(Field *field,
max_mp_pos= 1.0;
Histogram *hist= &col_stats->histogram;
if (hist->get_size() == 0)
if (!hist->is_available())
sel= (max_mp_pos - min_mp_pos);
else
sel= hist->range_selectivity(min_mp_pos, max_mp_pos);
......
......@@ -195,6 +195,8 @@ class Histogram
void set_values (uchar *vals) { values= (uchar *) vals; }
bool is_available() { return get_size() > 0 && get_values(); }
void set_value(uint i, double val)
{
switch (type) {
......
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