mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 12:32:27 +01:00
Fixed bug mdev-4367.
When calculating selectivity of conditions one should take into account the cases when some tables to be joined are empty.
This commit is contained in:
parent
d62ee4e970
commit
50d4d1ca18
5 changed files with 57 additions and 7 deletions
|
@ -750,4 +750,18 @@ drop table t1;
|
|||
set histogram_size=@save_histogram_size;
|
||||
set histogram_type=@save_histogram_type;
|
||||
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
|
||||
#
|
||||
# Bug mdev-4367: join of a merged empty derived table
|
||||
# when optimizer_use_condition_selectivity=3
|
||||
#
|
||||
SET optimizer_use_condition_selectivity=3;
|
||||
CREATE TABLE t1 (a varchar(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES ('j'),('k');
|
||||
CREATE TABLE t2 (b varchar(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES ('x'),('y');
|
||||
CREATE TABLE t3 (c varchar(1), KEY(c)) ENGINE=MyISAM;
|
||||
SELECT * FROM t1 STRAIGHT_JOIN (t2 JOIN t3 ON c = b AND b > 'z');
|
||||
a b c
|
||||
DROP TABLE t1,t2,t3;
|
||||
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
|
||||
set use_stat_tables=@save_use_stat_tables;
|
||||
|
|
|
@ -757,6 +757,20 @@ drop table t1;
|
|||
set histogram_size=@save_histogram_size;
|
||||
set histogram_type=@save_histogram_type;
|
||||
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
|
||||
#
|
||||
# Bug mdev-4367: join of a merged empty derived table
|
||||
# when optimizer_use_condition_selectivity=3
|
||||
#
|
||||
SET optimizer_use_condition_selectivity=3;
|
||||
CREATE TABLE t1 (a varchar(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES ('j'),('k');
|
||||
CREATE TABLE t2 (b varchar(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES ('x'),('y');
|
||||
CREATE TABLE t3 (c varchar(1), KEY(c)) ENGINE=MyISAM;
|
||||
SELECT * FROM t1 STRAIGHT_JOIN (t2 JOIN t3 ON c = b AND b > 'z');
|
||||
a b c
|
||||
DROP TABLE t1,t2,t3;
|
||||
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
|
||||
set use_stat_tables=@save_use_stat_tables;
|
||||
set optimizer_switch=@save_optimizer_switch_for_selectivity_test;
|
||||
SET SESSION STORAGE_ENGINE=DEFAULT;
|
||||
|
|
|
@ -336,4 +336,26 @@ set histogram_size=@save_histogram_size;
|
|||
set histogram_type=@save_histogram_type;
|
||||
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
|
||||
|
||||
--echo #
|
||||
--echo # Bug mdev-4367: join of a merged empty derived table
|
||||
--echo # when optimizer_use_condition_selectivity=3
|
||||
--echo #
|
||||
|
||||
SET optimizer_use_condition_selectivity=3;
|
||||
|
||||
CREATE TABLE t1 (a varchar(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES ('j'),('k');
|
||||
|
||||
CREATE TABLE t2 (b varchar(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES ('x'),('y');
|
||||
|
||||
CREATE TABLE t3 (c varchar(1), KEY(c)) ENGINE=MyISAM;
|
||||
|
||||
SELECT * FROM t1 STRAIGHT_JOIN (t2 JOIN t3 ON c = b AND b > 'z');
|
||||
|
||||
DROP TABLE t1,t2,t3;
|
||||
|
||||
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
|
||||
|
||||
|
||||
set use_stat_tables=@save_use_stat_tables;
|
||||
|
|
|
@ -3324,6 +3324,12 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item *cond)
|
|||
DBUG_ENTER("calculate_cond_selectivity_for_table");
|
||||
|
||||
table->cond_selectivity= 1.0;
|
||||
|
||||
#if 0
|
||||
#else
|
||||
if (table_records == 0)
|
||||
DBUG_RETURN(FALSE);
|
||||
#endif
|
||||
|
||||
if (thd->variables.optimizer_use_condition_selectivity > 2 &&
|
||||
!bitmap_is_clear_all(used_fields))
|
||||
|
@ -3363,11 +3369,6 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item *cond)
|
|||
double rows;
|
||||
if (*key)
|
||||
{
|
||||
#if 0
|
||||
rows= records_in_column_ranges(¶m, idx, *key);
|
||||
if (rows != HA_POS_ERROR)
|
||||
(*key)->field->cond_selectivity= rows/table_records;
|
||||
#else
|
||||
table->reginfo.impossible_range= 0;
|
||||
if ((*key)->type == SEL_ARG::IMPOSSIBLE)
|
||||
{
|
||||
|
@ -3381,7 +3382,6 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item *cond)
|
|||
if (rows != HA_POS_ERROR)
|
||||
(*key)->field->cond_selectivity= rows/table_records;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3795,7 +3795,7 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list,
|
|||
*/
|
||||
add_group_and_distinct_keys(join, s);
|
||||
|
||||
table->cond_selectivity= 1.0;
|
||||
s->table->cond_selectivity= 1.0;
|
||||
|
||||
/*
|
||||
Perform range analysis if there are keys it could use (1).
|
||||
|
|
Loading…
Reference in a new issue