Commit 80a38b92 authored by Igor Babaev's avatar Igor Babaev

Fixed bug mdev-5630.

The function calculate_cond_selectivity_for_table() must consider
the case when the key range tree returned by the call of get_mm_tree()
is of the type SEL_TREE::ALWAYS.
parent 50323f12
...@@ -1166,3 +1166,21 @@ set optimizer_use_condition_selectivity = 3; ...@@ -1166,3 +1166,21 @@ set optimizer_use_condition_selectivity = 3;
SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE SQL_MODE != ''; SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE SQL_MODE != '';
TRIGGER_CATALOG TRIGGER_SCHEMA TRIGGER_NAME EVENT_MANIPULATION EVENT_OBJECT_CATALOG EVENT_OBJECT_SCHEMA EVENT_OBJECT_TABLE ACTION_ORDER ACTION_CONDITION ACTION_STATEMENT ACTION_ORIENTATION ACTION_TIMING ACTION_REFERENCE_OLD_TABLE ACTION_REFERENCE_NEW_TABLE ACTION_REFERENCE_OLD_ROW ACTION_REFERENCE_NEW_ROW CREATED SQL_MODE DEFINER CHARACTER_SET_CLIENT COLLATION_CONNECTION DATABASE_COLLATION TRIGGER_CATALOG TRIGGER_SCHEMA TRIGGER_NAME EVENT_MANIPULATION EVENT_OBJECT_CATALOG EVENT_OBJECT_SCHEMA EVENT_OBJECT_TABLE ACTION_ORDER ACTION_CONDITION ACTION_STATEMENT ACTION_ORIENTATION ACTION_TIMING ACTION_REFERENCE_OLD_TABLE ACTION_REFERENCE_NEW_TABLE ACTION_REFERENCE_OLD_ROW ACTION_REFERENCE_NEW_ROW CREATED SQL_MODE DEFINER CHARACTER_SET_CLIENT COLLATION_CONNECTION DATABASE_COLLATION
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
#
# Bug mdev-5630: always true conjunctive condition
# when optimizer_use_condition_selectivity=3
#
set use_stat_tables = 'preferably';
set optimizer_use_condition_selectivity = 3;
CREATE TABLE t1 (a int) ENGINE=MyISAM;
INSERT INTO t1 VALUES (10);
CREATE TABLE t2 (id int, flag char(1), INDEX(id)) ENGINE=MyISAM;
INSERT INTO t2 VALUES (100,'0'),(101,'1');
ANALYZE TABLE t1, t2;
Table Op Msg_type Msg_text
test.t1 analyze status OK
test.t2 analyze status OK
SELECT * FROM t1, t2 WHERE id = a AND ( a = 16 OR flag AND a != 6 );
a id flag
DROP TABLE t1,t2;
set use_stat_tables=@save_use_stat_tables;
...@@ -1174,5 +1174,23 @@ set optimizer_use_condition_selectivity = 3; ...@@ -1174,5 +1174,23 @@ set optimizer_use_condition_selectivity = 3;
SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE SQL_MODE != ''; SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE SQL_MODE != '';
TRIGGER_CATALOG TRIGGER_SCHEMA TRIGGER_NAME EVENT_MANIPULATION EVENT_OBJECT_CATALOG EVENT_OBJECT_SCHEMA EVENT_OBJECT_TABLE ACTION_ORDER ACTION_CONDITION ACTION_STATEMENT ACTION_ORIENTATION ACTION_TIMING ACTION_REFERENCE_OLD_TABLE ACTION_REFERENCE_NEW_TABLE ACTION_REFERENCE_OLD_ROW ACTION_REFERENCE_NEW_ROW CREATED SQL_MODE DEFINER CHARACTER_SET_CLIENT COLLATION_CONNECTION DATABASE_COLLATION TRIGGER_CATALOG TRIGGER_SCHEMA TRIGGER_NAME EVENT_MANIPULATION EVENT_OBJECT_CATALOG EVENT_OBJECT_SCHEMA EVENT_OBJECT_TABLE ACTION_ORDER ACTION_CONDITION ACTION_STATEMENT ACTION_ORIENTATION ACTION_TIMING ACTION_REFERENCE_OLD_TABLE ACTION_REFERENCE_NEW_TABLE ACTION_REFERENCE_OLD_ROW ACTION_REFERENCE_NEW_ROW CREATED SQL_MODE DEFINER CHARACTER_SET_CLIENT COLLATION_CONNECTION DATABASE_COLLATION
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
#
# Bug mdev-5630: always true conjunctive condition
# when optimizer_use_condition_selectivity=3
#
set use_stat_tables = 'preferably';
set optimizer_use_condition_selectivity = 3;
CREATE TABLE t1 (a int) ENGINE=MyISAM;
INSERT INTO t1 VALUES (10);
CREATE TABLE t2 (id int, flag char(1), INDEX(id)) ENGINE=MyISAM;
INSERT INTO t2 VALUES (100,'0'),(101,'1');
ANALYZE TABLE t1, t2;
Table Op Msg_type Msg_text
test.t1 analyze status OK
test.t2 analyze status OK
SELECT * FROM t1, t2 WHERE id = a AND ( a = 16 OR flag AND a != 6 );
a id flag
DROP TABLE t1,t2;
set use_stat_tables=@save_use_stat_tables;
set optimizer_switch=@save_optimizer_switch_for_selectivity_test; set optimizer_switch=@save_optimizer_switch_for_selectivity_test;
SET SESSION STORAGE_ENGINE=DEFAULT; SET SESSION STORAGE_ENGINE=DEFAULT;
...@@ -750,3 +750,25 @@ SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE SQL_MODE != ''; ...@@ -750,3 +750,25 @@ SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE SQL_MODE != '';
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
--echo #
--echo # Bug mdev-5630: always true conjunctive condition
--echo # when optimizer_use_condition_selectivity=3
--echo #
set use_stat_tables = 'preferably';
set optimizer_use_condition_selectivity = 3;
CREATE TABLE t1 (a int) ENGINE=MyISAM;
INSERT INTO t1 VALUES (10);
CREATE TABLE t2 (id int, flag char(1), INDEX(id)) ENGINE=MyISAM;
INSERT INTO t2 VALUES (100,'0'),(101,'1');
ANALYZE TABLE t1, t2;
SELECT * FROM t1, t2 WHERE id = a AND ( a = 16 OR flag AND a != 6 );
DROP TABLE t1,t2;
set use_stat_tables=@save_use_stat_tables;
...@@ -3460,6 +3460,11 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item *cond) ...@@ -3460,6 +3460,11 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item *cond)
table->reginfo.impossible_range= 1; table->reginfo.impossible_range= 1;
goto free_alloc; goto free_alloc;
} }
else if (tree->type == SEL_TREE::ALWAYS)
{
rows= table_records;
goto free_alloc;
}
else if (tree->type == SEL_TREE::MAYBE) else if (tree->type == SEL_TREE::MAYBE)
{ {
rows= table_records; rows= table_records;
......
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