1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

Merge mwl253 -> 10.0-base

This commit is contained in:
Igor Babaev
2013-04-21 22:44:19 -07:00
25 changed files with 1118 additions and 10 deletions

View File

@ -499,6 +499,9 @@ The following options may be given as the first argument:
optimizer will switch to the original find_best search.
NOTE: The value 63 and its associated behaviour is
deprecated
--optimizer-selectivity-sampling-limit=#
Controls number of record samples to check condition
selectivity
--optimizer-switch=name
optimizer_switch=option=val[,option=val...], where option
is one of {derived_merge, derived_with_keys, firstmatch,
@ -527,7 +530,9 @@ The following options may be given as the first argument:
any index to calculate the cardinality of a partial join,
4 - use histograms to calculate selectivity of range
conditions that are not backed by any index to calculate
the cardinality of a partial join.
the cardinality of a partial join.5 - additionally use
selectivity of certain non-range predicates calculated on
record samples
--performance-schema
Enable the performance schema.
--performance-schema-events-waits-history-long-size=#
@ -1053,6 +1058,7 @@ old-passwords FALSE
old-style-user-limits FALSE
optimizer-prune-level 1
optimizer-search-depth 62
optimizer-selectivity-sampling-limit 100
optimizer-switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on
optimizer-use-condition-selectivity 1
performance-schema FALSE

View File

@ -37,6 +37,89 @@ set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivit
DROP DATABASE IF EXISTS dbt3_s001;
CREATE DATABASE dbt3_s001;
use dbt3_s001;
=== Q2 ===
set optimizer_use_condition_selectivity=5;
explain extended
select
s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment
from
part, supplier, partsupp, nation, region
where
p_partkey = ps_partkey
and s_suppkey = ps_suppkey
and p_size = 9
and p_type like '%TIN'
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'ASIA'
and ps_supplycost = (
select
min(ps_supplycost)
from
partsupp, supplier, nation, region
where
p_partkey = ps_partkey
and s_suppkey = ps_suppkey
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'ASIA'
)
order by
s_acctbal desc, n_name, s_name, p_partkey;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 0.31 Using where; Using temporary; Using filesort
1 PRIMARY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where; Using join buffer (flat, BNL join)
1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where
1 PRIMARY supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 80.00 Using where; Using join buffer (flat, BNL join)
1 PRIMARY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where
2 DEPENDENT SUBQUERY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where
2 DEPENDENT SUBQUERY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00
2 DEPENDENT SUBQUERY supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.partsupp.ps_suppkey 1 100.00 Using where
2 DEPENDENT SUBQUERY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.part.p_partkey' of SELECT #2 was resolved in SELECT #1
Note 1003 select `dbt3_s001`.`supplier`.`s_acctbal` AS `s_acctbal`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`nation`.`n_name` AS `n_name`,`dbt3_s001`.`part`.`p_partkey` AS `p_partkey`,`dbt3_s001`.`part`.`p_mfgr` AS `p_mfgr`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`dbt3_s001`.`supplier`.`s_comment` AS `s_comment` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where ((`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`part`.`p_size` = 9) and (`dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey`) and (`dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey`) and (`dbt3_s001`.`region`.`r_name` = 'ASIA') and (`dbt3_s001`.`part`.`p_type` like '%TIN') and (`dbt3_s001`.`partsupp`.`ps_supplycost` = <expr_cache><`dbt3_s001`.`part`.`p_partkey`>((select min(`dbt3_s001`.`partsupp`.`ps_supplycost`) from `dbt3_s001`.`partsupp` join `dbt3_s001`.`supplier` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where ((`dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey`) and (`dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey`) and (`dbt3_s001`.`region`.`r_name` = 'ASIA') and (`dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`)))))) order by `dbt3_s001`.`supplier`.`s_acctbal` desc,`dbt3_s001`.`nation`.`n_name`,`dbt3_s001`.`supplier`.`s_name`,`dbt3_s001`.`part`.`p_partkey`
set optimizer_use_condition_selectivity=4;
explain extended
select
s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment
from
part, supplier, partsupp, nation, region
where
p_partkey = ps_partkey
and s_suppkey = ps_suppkey
and p_size = 9
and p_type like '%TIN'
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'ASIA'
and ps_supplycost = (
select
min(ps_supplycost)
from
partsupp, supplier, nation, region
where
p_partkey = ps_partkey
and s_suppkey = ps_suppkey
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'ASIA'
)
order by
s_acctbal desc, n_name, s_name, p_partkey;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where; Using temporary; Using filesort
1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 2.08 Using where; Using join buffer (flat, BNL join)
1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where
1 PRIMARY supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 80.00 Using where; Using join buffer (flat, BNL join)
1 PRIMARY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where
2 DEPENDENT SUBQUERY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where
2 DEPENDENT SUBQUERY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00
2 DEPENDENT SUBQUERY supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.partsupp.ps_suppkey 1 100.00 Using where
2 DEPENDENT SUBQUERY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.part.p_partkey' of SELECT #2 was resolved in SELECT #1
Note 1003 select `dbt3_s001`.`supplier`.`s_acctbal` AS `s_acctbal`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`nation`.`n_name` AS `n_name`,`dbt3_s001`.`part`.`p_partkey` AS `p_partkey`,`dbt3_s001`.`part`.`p_mfgr` AS `p_mfgr`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`dbt3_s001`.`supplier`.`s_comment` AS `s_comment` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where ((`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`part`.`p_size` = 9) and (`dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey`) and (`dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey`) and (`dbt3_s001`.`region`.`r_name` = 'ASIA') and (`dbt3_s001`.`part`.`p_type` like '%TIN') and (`dbt3_s001`.`partsupp`.`ps_supplycost` = <expr_cache><`dbt3_s001`.`part`.`p_partkey`>((select min(`dbt3_s001`.`partsupp`.`ps_supplycost`) from `dbt3_s001`.`partsupp` join `dbt3_s001`.`supplier` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where ((`dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey`) and (`dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey`) and (`dbt3_s001`.`region`.`r_name` = 'ASIA') and (`dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`)))))) order by `dbt3_s001`.`supplier`.`s_acctbal` desc,`dbt3_s001`.`nation`.`n_name`,`dbt3_s001`.`supplier`.`s_name`,`dbt3_s001`.`part`.`p_partkey`
=== Q15 ===
create view revenue0 (supplier_no, total_revenue) as
select l_suppkey, sum(l_extendedprice * (1 - l_discount))
@ -1011,4 +1094,38 @@ f1 f2 f2
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
DROP TABLE t1,t2;
set use_stat_tables=@save_use_stat_tables;
#
# Bug mdev-4406: range condition for non-nullable column
# when optimizer_use_condition_selectivity=3
#
create table t1 (a int not null);
insert into t1 values
(7), (6), (4), (9), (1), (5), (2), (1), (3), (8);
set use_stat_tables='preferably';
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
flush table t1;
set optimizer_use_condition_selectivity=3;
select count(*) from t1 where a between 5 and 7;
count(*)
3
explain extended select * from t1 where a between 5 and 7;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 25.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` between 5 and 7)
alter table t1 change column a a int;
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
flush table t1;
explain extended select * from t1 where a between 5 and 7;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 25.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` between 5 and 7)
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
drop table t1;
set use_stat_tables=@save_use_stat_tables;
set use_stat_tables=@save_use_stat_tables;

View File

@ -40,6 +40,89 @@ set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivit
DROP DATABASE IF EXISTS dbt3_s001;
CREATE DATABASE dbt3_s001;
use dbt3_s001;
=== Q2 ===
set optimizer_use_condition_selectivity=5;
explain extended
select
s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment
from
part, supplier, partsupp, nation, region
where
p_partkey = ps_partkey
and s_suppkey = ps_suppkey
and p_size = 9
and p_type like '%TIN'
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'ASIA'
and ps_supplycost = (
select
min(ps_supplycost)
from
partsupp, supplier, nation, region
where
p_partkey = ps_partkey
and s_suppkey = ps_suppkey
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'ASIA'
)
order by
s_acctbal desc, n_name, s_name, p_partkey;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 0.31 Using where; Using temporary; Using filesort
1 PRIMARY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where; Using join buffer (flat, BNL join)
1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where
1 PRIMARY supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 80.00 Using where; Using join buffer (flat, BNL join)
1 PRIMARY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where
2 DEPENDENT SUBQUERY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where
2 DEPENDENT SUBQUERY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00
2 DEPENDENT SUBQUERY supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.partsupp.ps_suppkey 1 100.00 Using where
2 DEPENDENT SUBQUERY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.part.p_partkey' of SELECT #2 was resolved in SELECT #1
Note 1003 select `dbt3_s001`.`supplier`.`s_acctbal` AS `s_acctbal`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`nation`.`n_name` AS `n_name`,`dbt3_s001`.`part`.`p_partkey` AS `p_partkey`,`dbt3_s001`.`part`.`p_mfgr` AS `p_mfgr`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`dbt3_s001`.`supplier`.`s_comment` AS `s_comment` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where ((`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`part`.`p_size` = 9) and (`dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey`) and (`dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey`) and (`dbt3_s001`.`region`.`r_name` = 'ASIA') and (`dbt3_s001`.`part`.`p_type` like '%TIN') and (`dbt3_s001`.`partsupp`.`ps_supplycost` = <expr_cache><`dbt3_s001`.`part`.`p_partkey`>((select min(`dbt3_s001`.`partsupp`.`ps_supplycost`) from `dbt3_s001`.`partsupp` join `dbt3_s001`.`supplier` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where ((`dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey`) and (`dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey`) and (`dbt3_s001`.`region`.`r_name` = 'ASIA') and (`dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`)))))) order by `dbt3_s001`.`supplier`.`s_acctbal` desc,`dbt3_s001`.`nation`.`n_name`,`dbt3_s001`.`supplier`.`s_name`,`dbt3_s001`.`part`.`p_partkey`
set optimizer_use_condition_selectivity=4;
explain extended
select
s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment
from
part, supplier, partsupp, nation, region
where
p_partkey = ps_partkey
and s_suppkey = ps_suppkey
and p_size = 9
and p_type like '%TIN'
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'ASIA'
and ps_supplycost = (
select
min(ps_supplycost)
from
partsupp, supplier, nation, region
where
p_partkey = ps_partkey
and s_suppkey = ps_suppkey
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'ASIA'
)
order by
s_acctbal desc, n_name, s_name, p_partkey;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where; Using temporary; Using filesort
1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 2.08 Using where; Using join buffer (flat, BNL join)
1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where
1 PRIMARY supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 80.00 Using where; Using join buffer (flat, BNL join)
1 PRIMARY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where
2 DEPENDENT SUBQUERY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where
2 DEPENDENT SUBQUERY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00
2 DEPENDENT SUBQUERY supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.partsupp.ps_suppkey 1 100.00 Using where
2 DEPENDENT SUBQUERY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.part.p_partkey' of SELECT #2 was resolved in SELECT #1
Note 1003 select `dbt3_s001`.`supplier`.`s_acctbal` AS `s_acctbal`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`nation`.`n_name` AS `n_name`,`dbt3_s001`.`part`.`p_partkey` AS `p_partkey`,`dbt3_s001`.`part`.`p_mfgr` AS `p_mfgr`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`dbt3_s001`.`supplier`.`s_comment` AS `s_comment` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where ((`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`part`.`p_size` = 9) and (`dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey`) and (`dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey`) and (`dbt3_s001`.`region`.`r_name` = 'ASIA') and (`dbt3_s001`.`part`.`p_type` like '%TIN') and (`dbt3_s001`.`partsupp`.`ps_supplycost` = <expr_cache><`dbt3_s001`.`part`.`p_partkey`>((select min(`dbt3_s001`.`partsupp`.`ps_supplycost`) from `dbt3_s001`.`partsupp` join `dbt3_s001`.`supplier` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where ((`dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey`) and (`dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey`) and (`dbt3_s001`.`region`.`r_name` = 'ASIA') and (`dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`)))))) order by `dbt3_s001`.`supplier`.`s_acctbal` desc,`dbt3_s001`.`nation`.`n_name`,`dbt3_s001`.`supplier`.`s_name`,`dbt3_s001`.`part`.`p_partkey`
=== Q15 ===
create view revenue0 (supplier_no, total_revenue) as
select l_suppkey, sum(l_extendedprice * (1 - l_discount))
@ -1019,6 +1102,40 @@ f1 f2 f2
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
DROP TABLE t1,t2;
set use_stat_tables=@save_use_stat_tables;
#
# Bug mdev-4406: range condition for non-nullable column
# when optimizer_use_condition_selectivity=3
#
create table t1 (a int not null);
insert into t1 values
(7), (6), (4), (9), (1), (5), (2), (1), (3), (8);
set use_stat_tables='preferably';
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
flush table t1;
set optimizer_use_condition_selectivity=3;
select count(*) from t1 where a between 5 and 7;
count(*)
3
explain extended select * from t1 where a between 5 and 7;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 25.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` between 5 and 7)
alter table t1 change column a a int;
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
flush table t1;
explain extended select * from t1 where a between 5 and 7;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 25.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` between 5 and 7)
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
drop table t1;
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;

View File

@ -1416,6 +1416,90 @@ WORLD_INNODB CITY Country 1 17.5819
WORLD_INNODB COUNTRYLANGUAGE PRIMARY 1 4.2232
WORLD_INNODB COUNTRYLANGUAGE PRIMARY 2 1.0000
WORLD_INNODB COUNTRYLANGUAGE Percentage 1 2.7640
set use_stat_tables='preferably';
set histogram_size=100;
set histogram_type='SINGLE_PREC_HB';
ANALYZE TABLE CountryLanguage;
set histogram_size=254;
set histogram_type='DOUBLE_PREC_HB';
ANALYZE TABLE City;
FLUSH TABLES;
select db_name,table_name,column_name,min_value,max_value,nulls_ratio,avg_length,avg_frequency,hist_size,hist_type,hex(histogram),decode_histogram(histogram,hist_type) from mysql.column_stats where column_name = 'Percentage';;
db_name world
table_name CountryLanguage
column_name Percentage
min_value 0.0
max_value 99.9
nulls_ratio 0.0000
avg_length 4.0000
avg_frequency 2.7640
hist_size 0
hist_type NULL
hex(histogram) NULL
decode_histogram(histogram,hist_type) NULL
db_name world_innodb
table_name CountryLanguage
column_name Percentage
min_value 0.0
max_value 99.9
nulls_ratio 0.0000
avg_length 4.0000
avg_frequency 2.7640
hist_size 100
hist_type SINGLE_PREC_HB
hex(histogram) 0000000000000000000000000101010101010101010202020303030304040404050505050606070707080809090A0A0B0C0D0D0E0E0F10111213131415161718191B1C1E202224292A2E33373B4850575F6A76818C9AA7B9C4CFDADFE5EBF0F4F8FAFCFF
decode_histogram(histogram,hist_type) 0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.004,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.004,0.000,0.000,0.004,0.000,0.000,0.000,0.004,0.000,0.000,0.000,0.004,0.000,0.000,0.000,0.004,0.000,0.004,0.000,0.000,0.004,0.000,0.004,0.000,0.004,0.000,0.004,0.004,0.004,0.000,0.004,0.000,0.004,0.004,0.004,0.004,0.004,0.000,0.004,0.004,0.004,0.004,0.004,0.004,0.008,0.004,0.008,0.008,0.008,0.008,0.020,0.004,0.016,0.020,0.016,0.016,0.051,0.031,0.027,0.031,0.043,0.047,0.043,0.043,0.055,0.051,0.071,0.043,0.043,0.043,0.020,0.024,0.024,0.020,0.016,0.016,0.008,0.008,0.012,0.000
select db_name,table_name,column_name,min_value,max_value,nulls_ratio,avg_length,avg_frequency,hist_size,hist_type,hex(histogram),decode_histogram(histogram,hist_type) from mysql.column_stats where column_name = 'Population';;
db_name world
table_name Country
column_name Population
min_value 0
max_value 1277558000
nulls_ratio 0.0000
avg_length 4.0000
avg_frequency 1.0575
hist_size 0
hist_type NULL
hex(histogram) NULL
decode_histogram(histogram,hist_type) NULL
db_name world
table_name City
column_name Population
min_value 42
max_value 10500000
nulls_ratio 0.0000
avg_length 4.0000
avg_frequency 1.0467
hist_size 0
hist_type NULL
hex(histogram) NULL
decode_histogram(histogram,hist_type) NULL
db_name world_innodb
table_name Country
column_name Population
min_value 0
max_value 1277558000
nulls_ratio 0.0000
avg_length 4.0000
avg_frequency 1.0575
hist_size 0
hist_type NULL
hex(histogram) NULL
decode_histogram(histogram,hist_type) NULL
db_name world_innodb
table_name City
column_name Population
min_value 42
max_value 10500000
nulls_ratio 0.0000
avg_length 4.0000
avg_frequency 1.0467
hist_size 254
hist_type DOUBLE_PREC_HB
hex(histogram) 1F00A1002B023002350238023F02430249024E02520258025D02630268026E02720276027B02800285028C02920297029D02A102A802AC02B402BC02C402CC02D302DA02E302EA02F102F802010305030C03120319031F03290333033D0343034F03590363036D037803840390039A03A603B303C303D103E003F203020412042404330440045304600472047F049104A204B804C804DE04F2040A0526053F0558056F058E05B305D905F4051306380667068406AB06DA06020731075C079407C507F8072E085E08A508DF0824096909CC092E0A760AD50A400BA90B150CAD0C310D240E130F0E103B11B9126B14F0166B192F1CB71FFF240630483FC567
decode_histogram(histogram,hist_type) 0.00047,0.00198,0.00601,0.00008,0.00008,0.00005,0.00011,0.00006,0.00009,0.00008,0.00006,0.00009,0.00008,0.00009,0.00008,0.00009,0.00006,0.00006,0.00008,0.00008,0.00008,0.00011,0.00009,0.00008,0.00009,0.00006,0.00011,0.00006,0.00012,0.00012,0.00012,0.00012,0.00011,0.00011,0.00014,0.00011,0.00011,0.00011,0.00014,0.00006,0.00011,0.00009,0.00011,0.00009,0.00015,0.00015,0.00015,0.00009,0.00018,0.00015,0.00015,0.00015,0.00017,0.00018,0.00018,0.00015,0.00018,0.00020,0.00024,0.00021,0.00023,0.00027,0.00024,0.00024,0.00027,0.00023,0.00020,0.00029,0.00020,0.00027,0.00020,0.00027,0.00026,0.00034,0.00024,0.00034,0.00031,0.00037,0.00043,0.00038,0.00038,0.00035,0.00047,0.00056,0.00058,0.00041,0.00047,0.00056,0.00072,0.00044,0.00060,0.00072,0.00061,0.00072,0.00066,0.00085,0.00075,0.00078,0.00082,0.00073,0.00108,0.00089,0.00105,0.00105,0.00151,0.00150,0.00110,0.00145,0.00163,0.00160,0.00165,0.00232,0.00201,0.00371,0.00365,0.00383,0.00459,0.00583,0.00662,0.00984,0.00969,0.01080,0.01379,0.02063,0.04308,0.05960,0.15816,0.59464
set histogram_type=default;
set histogram_size=default;
use test;
DROP DATABASE world;
SELECT UPPER(db_name), UPPER(table_name), cardinality

View File

@ -0,0 +1,141 @@
SET @start_global_value = @@global.optimizer_selectivity_sampling_limit;
SELECT @start_global_value;
@start_global_value
100
SET @start_session_value = @@session.optimizer_selectivity_sampling_limit;
SELECT @start_session_value;
@start_session_value
100
'#--------------------FN_DYNVARS_115_01-------------------------#'
SET @@global.optimizer_selectivity_sampling_limit = DEFAULT;
SELECT @@global.optimizer_selectivity_sampling_limit;
@@global.optimizer_selectivity_sampling_limit
100
SET @@session.optimizer_selectivity_sampling_limit = DEFAULT;
SELECT @@session.optimizer_selectivity_sampling_limit;
@@session.optimizer_selectivity_sampling_limit
100
'#--------------------FN_DYNVARS_115_02-------------------------#'
SET @@global.optimizer_selectivity_sampling_limit = DEFAULT;
SELECT @@global.optimizer_selectivity_sampling_limit = 100;
@@global.optimizer_selectivity_sampling_limit = 100
1
SET @@session.optimizer_selectivity_sampling_limit = DEFAULT;
SELECT @@session.optimizer_selectivity_sampling_limit = 100;
@@session.optimizer_selectivity_sampling_limit = 100
1
'#--------------------FN_DYNVARS_115_03-------------------------#'
SELECT @@global.optimizer_selectivity_sampling_limit;
@@global.optimizer_selectivity_sampling_limit
100
SET @@global.optimizer_selectivity_sampling_limit = 9;
Warnings:
Warning 1292 Truncated incorrect optimizer_selectivity_sampling_l value: '9'
SELECT @@global.optimizer_selectivity_sampling_limit;
@@global.optimizer_selectivity_sampling_limit
10
SET @@global.optimizer_selectivity_sampling_limit = 10;
SELECT @@global.optimizer_selectivity_sampling_limit;
@@global.optimizer_selectivity_sampling_limit
10
SET @@global.optimizer_selectivity_sampling_limit = 11;
SELECT @@global.optimizer_selectivity_sampling_limit;
@@global.optimizer_selectivity_sampling_limit
11
SET @@global.optimizer_selectivity_sampling_limit = 7777;
SELECT @@global.optimizer_selectivity_sampling_limit;
@@global.optimizer_selectivity_sampling_limit
7777
SET @@global.optimizer_selectivity_sampling_limit = 4294967294;
SELECT @@global.optimizer_selectivity_sampling_limit;
@@global.optimizer_selectivity_sampling_limit
4294967294
SET @@global.optimizer_selectivity_sampling_limit = 4294967295;
SELECT @@global.optimizer_selectivity_sampling_limit;
@@global.optimizer_selectivity_sampling_limit
4294967295
SET @@global.optimizer_selectivity_sampling_limit = 4294967296;
Warnings:
Warning 1292 Truncated incorrect optimizer_selectivity_sampling_l value: '4294967296'
SELECT @@global.optimizer_selectivity_sampling_limit;
@@global.optimizer_selectivity_sampling_limit
4294967295
'#--------------------FN_DYNVARS_115_04-------------------------#'
SELECT @@session.optimizer_selectivity_sampling_limit;
@@session.optimizer_selectivity_sampling_limit
100
SET @@session.optimizer_selectivity_sampling_limit = 9;
Warnings:
Warning 1292 Truncated incorrect optimizer_selectivity_sampling_l value: '9'
SELECT @@session.optimizer_selectivity_sampling_limit;
@@session.optimizer_selectivity_sampling_limit
10
SET @@session.optimizer_selectivity_sampling_limit = 10;
SELECT @@session.optimizer_selectivity_sampling_limit;
@@session.optimizer_selectivity_sampling_limit
10
SET @@session.optimizer_selectivity_sampling_limit = 11;
SELECT @@session.optimizer_selectivity_sampling_limit;
@@session.optimizer_selectivity_sampling_limit
11
SET @@session.optimizer_selectivity_sampling_limit = 7777;
SELECT @@session.optimizer_selectivity_sampling_limit;
@@session.optimizer_selectivity_sampling_limit
7777
SET @@session.optimizer_selectivity_sampling_limit = 4294967294;
SELECT @@session.optimizer_selectivity_sampling_limit;
@@session.optimizer_selectivity_sampling_limit
4294967294
SET @@session.optimizer_selectivity_sampling_limit = 4294967295;
SELECT @@session.optimizer_selectivity_sampling_limit;
@@session.optimizer_selectivity_sampling_limit
4294967295
SET @@session.optimizer_selectivity_sampling_limit = 4294967296;
Warnings:
Warning 1292 Truncated incorrect optimizer_selectivity_sampling_l value: '4294967296'
SELECT @@session.optimizer_selectivity_sampling_limit;
@@session.optimizer_selectivity_sampling_limit
4294967295
'#------------------FN_DYNVARS_115_05-----------------------#'
SET @@global.optimizer_selectivity_sampling_limit = ON;
ERROR 42000: Incorrect argument type to variable 'optimizer_selectivity_sampling_limit'
SET @@global.optimizer_selectivity_sampling_limit = OFF;
ERROR 42000: Incorrect argument type to variable 'optimizer_selectivity_sampling_limit'
SET @@session.optimizer_selectivity_sampling_limit = 65530.34;
ERROR 42000: Incorrect argument type to variable 'optimizer_selectivity_sampling_limit'
SET @@session.optimizer_selectivity_sampling_limit = test;
ERROR 42000: Incorrect argument type to variable 'optimizer_selectivity_sampling_limit'
'#------------------FN_DYNVARS_115_06-----------------------#'
SELECT @@global.optimizer_selectivity_sampling_limit = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME='optimizer_selectivity_sampling_limit';
@@global.optimizer_selectivity_sampling_limit = VARIABLE_VALUE
1
'#------------------FN_DYNVARS_115_07-----------------------#'
SELECT @@session.optimizer_selectivity_sampling_limit = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.SESSION_VARIABLES
WHERE VARIABLE_NAME='optimizer_selectivity_sampling_limit';
@@session.optimizer_selectivity_sampling_limit = VARIABLE_VALUE
1
'#---------------------FN_DYNVARS_115_08----------------------#'
SET @@optimizer_selectivity_sampling_limit = 10;
SET @@global.optimizer_selectivity_sampling_limit = 30;
SELECT @@optimizer_selectivity_sampling_limit = @@global.optimizer_selectivity_sampling_limit;
@@optimizer_selectivity_sampling_limit = @@global.optimizer_selectivity_sampling_limit
0
'#---------------------FN_DYNVARS_115_09----------------------#'
SET @@optimizer_selectivity_sampling_limit = 20;
SELECT @@optimizer_selectivity_sampling_limit = @@local.optimizer_selectivity_sampling_limit;
@@optimizer_selectivity_sampling_limit = @@local.optimizer_selectivity_sampling_limit
1
SELECT @@local.optimizer_selectivity_sampling_limit = @@session.optimizer_selectivity_sampling_limit;
@@local.optimizer_selectivity_sampling_limit = @@session.optimizer_selectivity_sampling_limit
1
SET @@global.optimizer_selectivity_sampling_limit = @start_global_value;
SELECT @@global.optimizer_selectivity_sampling_limit;
@@global.optimizer_selectivity_sampling_limit
100
SET @@session.optimizer_selectivity_sampling_limit = @start_session_value;
SELECT @@session.optimizer_selectivity_sampling_limit;
@@session.optimizer_selectivity_sampling_limit
100

View File

@ -28,6 +28,12 @@ SELECT @@session.optimizer_use_condition_selectivity = 1;
SELECT @@global.optimizer_use_condition_selectivity;
@@global.optimizer_use_condition_selectivity
1
SET @@global.optimizer_use_condition_selectivity = 0;
Warnings:
Warning 1292 Truncated incorrect optimizer_use_condition_selectiv value: '0'
SELECT @@global.optimizer_use_condition_selectivity;
@@global.optimizer_use_condition_selectivity
1
SET @@global.optimizer_use_condition_selectivity = 1;
SELECT @@global.optimizer_use_condition_selectivity;
@@global.optimizer_use_condition_selectivity
@ -44,10 +50,26 @@ SET @@global.optimizer_use_condition_selectivity = 4;
SELECT @@global.optimizer_use_condition_selectivity;
@@global.optimizer_use_condition_selectivity
4
SET @@global.optimizer_use_condition_selectivity = 5;
SELECT @@global.optimizer_use_condition_selectivity;
@@global.optimizer_use_condition_selectivity
5
SET @@global.optimizer_use_condition_selectivity = 6;
Warnings:
Warning 1292 Truncated incorrect optimizer_use_condition_selectiv value: '6'
SELECT @@global.optimizer_use_condition_selectivity;
@@global.optimizer_use_condition_selectivity
5
'#--------------------FN_DYNVARS_115_04-------------------------#'
SELECT @@session.optimizer_use_condition_selectivity;
@@session.optimizer_use_condition_selectivity
1
SET @@session.optimizer_use_condition_selectivity = 0;
Warnings:
Warning 1292 Truncated incorrect optimizer_use_condition_selectiv value: '0'
SELECT @@session.optimizer_use_condition_selectivity;
@@session.optimizer_use_condition_selectivity
1
SET @@session.optimizer_use_condition_selectivity = 1;
SELECT @@session.optimizer_use_condition_selectivity;
@@session.optimizer_use_condition_selectivity
@ -64,6 +86,16 @@ SET @@session.optimizer_use_condition_selectivity = 4;
SELECT @@session.optimizer_use_condition_selectivity;
@@session.optimizer_use_condition_selectivity
4
SET @@session.optimizer_use_condition_selectivity = 5;
SELECT @@session.optimizer_use_condition_selectivity;
@@session.optimizer_use_condition_selectivity
5
SET @@session.optimizer_use_condition_selectivity = 6;
Warnings:
Warning 1292 Truncated incorrect optimizer_use_condition_selectiv value: '6'
SELECT @@session.optimizer_use_condition_selectivity;
@@session.optimizer_use_condition_selectivity
5
'#------------------FN_DYNVARS_115_05-----------------------#'
SET @@global.optimizer_use_condition_selectivity = ON;
ERROR 42000: Incorrect argument type to variable 'optimizer_use_condition_selectivity'

View File

@ -0,0 +1,154 @@
--source include/load_sysvars.inc
#################################################################
# START OF optimizer_selectivity_sampling_limit TESTS #
#################################################################
#############################################################
# Save initial value #
#############################################################
SET @start_global_value = @@global.optimizer_selectivity_sampling_limit;
SELECT @start_global_value;
SET @start_session_value = @@session.optimizer_selectivity_sampling_limit;
SELECT @start_session_value;
--echo '#--------------------FN_DYNVARS_115_01-------------------------#'
#########################################################################
# Display the DEFAULT value of optimizer_selectivity_sampling_limit #
#########################################################################
SET @@global.optimizer_selectivity_sampling_limit = DEFAULT;
SELECT @@global.optimizer_selectivity_sampling_limit;
SET @@session.optimizer_selectivity_sampling_limit = DEFAULT;
SELECT @@session.optimizer_selectivity_sampling_limit;
--echo '#--------------------FN_DYNVARS_115_02-------------------------#'
#########################################################################
# Check the DEFAULT value of optimizer_selectivity_sampling_limit #
#########################################################################
SET @@global.optimizer_selectivity_sampling_limit = DEFAULT;
SELECT @@global.optimizer_selectivity_sampling_limit = 100;
SET @@session.optimizer_selectivity_sampling_limit = DEFAULT;
SELECT @@session.optimizer_selectivity_sampling_limit = 100;
--echo '#--------------------FN_DYNVARS_115_03-------------------------#'
#############################################################################################
# Change the value of optimizer_selectivity_sampling_limit to a valid value for GLOBAL Scope #
#############################################################################################
SELECT @@global.optimizer_selectivity_sampling_limit;
SET @@global.optimizer_selectivity_sampling_limit = 9;
SELECT @@global.optimizer_selectivity_sampling_limit;
SET @@global.optimizer_selectivity_sampling_limit = 10;
SELECT @@global.optimizer_selectivity_sampling_limit;
SET @@global.optimizer_selectivity_sampling_limit = 11;
SELECT @@global.optimizer_selectivity_sampling_limit;
SET @@global.optimizer_selectivity_sampling_limit = 7777;
SELECT @@global.optimizer_selectivity_sampling_limit;
SET @@global.optimizer_selectivity_sampling_limit = 4294967294;
SELECT @@global.optimizer_selectivity_sampling_limit;
SET @@global.optimizer_selectivity_sampling_limit = 4294967295;
SELECT @@global.optimizer_selectivity_sampling_limit;
SET @@global.optimizer_selectivity_sampling_limit = 4294967296;
SELECT @@global.optimizer_selectivity_sampling_limit;
--echo '#--------------------FN_DYNVARS_115_04-------------------------#'
#############################################################################################
# Change the value of optimizer_selectivity_sampling_limit to a valid value for SESSION Scope#
#############################################################################################
SELECT @@session.optimizer_selectivity_sampling_limit;
SET @@session.optimizer_selectivity_sampling_limit = 9;
SELECT @@session.optimizer_selectivity_sampling_limit;
SET @@session.optimizer_selectivity_sampling_limit = 10;
SELECT @@session.optimizer_selectivity_sampling_limit;
SET @@session.optimizer_selectivity_sampling_limit = 11;
SELECT @@session.optimizer_selectivity_sampling_limit;
SET @@session.optimizer_selectivity_sampling_limit = 7777;
SELECT @@session.optimizer_selectivity_sampling_limit;
SET @@session.optimizer_selectivity_sampling_limit = 4294967294;
SELECT @@session.optimizer_selectivity_sampling_limit;
SET @@session.optimizer_selectivity_sampling_limit = 4294967295;
SELECT @@session.optimizer_selectivity_sampling_limit;
SET @@session.optimizer_selectivity_sampling_limit = 4294967296;
SELECT @@session.optimizer_selectivity_sampling_limit;
--echo '#------------------FN_DYNVARS_115_05-----------------------#'
###############################################################################
# Change the value of optimizer_selectivity_sampling_limit to an invalid value #
##############################################################################
--Error ER_WRONG_TYPE_FOR_VAR
SET @@global.optimizer_selectivity_sampling_limit = ON;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@global.optimizer_selectivity_sampling_limit = OFF;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@session.optimizer_selectivity_sampling_limit = 65530.34;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@session.optimizer_selectivity_sampling_limit = test;
--echo '#------------------FN_DYNVARS_115_06-----------------------#'
####################################################################
# Check if the value in GLOBAL Table matches value in variable #
####################################################################
SELECT @@global.optimizer_selectivity_sampling_limit = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME='optimizer_selectivity_sampling_limit';
--echo '#------------------FN_DYNVARS_115_07-----------------------#'
####################################################################
# Check if the value in SESSION Table matches value in variable #
####################################################################
SELECT @@session.optimizer_selectivity_sampling_limit = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.SESSION_VARIABLES
WHERE VARIABLE_NAME='optimizer_selectivity_sampling_limit';
--echo '#---------------------FN_DYNVARS_115_08----------------------#'
###############################################################################
# Check if global and session variable are independent of each other #
###############################################################################
SET @@optimizer_selectivity_sampling_limit = 10;
SET @@global.optimizer_selectivity_sampling_limit = 30;
SELECT @@optimizer_selectivity_sampling_limit = @@global.optimizer_selectivity_sampling_limit;
--echo '#---------------------FN_DYNVARS_115_09----------------------#'
###############################################################################
# Check if accessing variable with SESSION,LOCAL and without SCOPE points #
# to same session variable #
###############################################################################
SET @@optimizer_selectivity_sampling_limit = 20;
SELECT @@optimizer_selectivity_sampling_limit = @@local.optimizer_selectivity_sampling_limit;
SELECT @@local.optimizer_selectivity_sampling_limit = @@session.optimizer_selectivity_sampling_limit;
####################################
# Restore initial value #
####################################
SET @@global.optimizer_selectivity_sampling_limit = @start_global_value;
SELECT @@global.optimizer_selectivity_sampling_limit;
SET @@session.optimizer_selectivity_sampling_limit = @start_session_value;
SELECT @@session.optimizer_selectivity_sampling_limit;
########################################################################
# END OF optimizer_selectivity_sampling_limit TESTS #
########################################################################

View File

@ -45,6 +45,8 @@ SELECT @@session.optimizer_use_condition_selectivity = 1;
# Change the value of optimizer_use_condition_selectivity to a valid value for GLOBAL Scope #
#############################################################################################
SELECT @@global.optimizer_use_condition_selectivity;
SET @@global.optimizer_use_condition_selectivity = 0;
SELECT @@global.optimizer_use_condition_selectivity;
SET @@global.optimizer_use_condition_selectivity = 1;
SELECT @@global.optimizer_use_condition_selectivity;
@ -54,6 +56,10 @@ SET @@global.optimizer_use_condition_selectivity = 3;
SELECT @@global.optimizer_use_condition_selectivity;
SET @@global.optimizer_use_condition_selectivity = 4;
SELECT @@global.optimizer_use_condition_selectivity;
SET @@global.optimizer_use_condition_selectivity = 5;
SELECT @@global.optimizer_use_condition_selectivity;
SET @@global.optimizer_use_condition_selectivity = 6;
SELECT @@global.optimizer_use_condition_selectivity;
--echo '#--------------------FN_DYNVARS_115_04-------------------------#'
@ -61,6 +67,8 @@ SELECT @@global.optimizer_use_condition_selectivity;
# Change the value of optimizer_use_condition_selectivity to a valid value for SESSION Scope#
#############################################################################################
SELECT @@session.optimizer_use_condition_selectivity;
SET @@session.optimizer_use_condition_selectivity = 0;
SELECT @@session.optimizer_use_condition_selectivity;
SET @@session.optimizer_use_condition_selectivity = 1;
SELECT @@session.optimizer_use_condition_selectivity;
@ -70,6 +78,10 @@ SET @@session.optimizer_use_condition_selectivity = 3;
SELECT @@session.optimizer_use_condition_selectivity;
SET @@session.optimizer_use_condition_selectivity = 4;
SELECT @@session.optimizer_use_condition_selectivity;
SET @@session.optimizer_use_condition_selectivity = 5;
SELECT @@session.optimizer_use_condition_selectivity;
SET @@session.optimizer_use_condition_selectivity = 6;
SELECT @@session.optimizer_use_condition_selectivity;
--echo '#------------------FN_DYNVARS_115_05-----------------------#'

View File

@ -56,6 +56,64 @@ customer, lineitem, nation, orders, part, partsupp, region, supplier;
--enable_result_log
--enable_query_log
--echo === Q2 ===
set optimizer_use_condition_selectivity=5;
explain extended
select
s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment
from
part, supplier, partsupp, nation, region
where
p_partkey = ps_partkey
and s_suppkey = ps_suppkey
and p_size = 9
and p_type like '%TIN'
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'ASIA'
and ps_supplycost = (
select
min(ps_supplycost)
from
partsupp, supplier, nation, region
where
p_partkey = ps_partkey
and s_suppkey = ps_suppkey
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'ASIA'
)
order by
s_acctbal desc, n_name, s_name, p_partkey;
set optimizer_use_condition_selectivity=4;
explain extended
select
s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment
from
part, supplier, partsupp, nation, region
where
p_partkey = ps_partkey
and s_suppkey = ps_suppkey
and p_size = 9
and p_type like '%TIN'
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'ASIA'
and ps_supplycost = (
select
min(ps_supplycost)
from
partsupp, supplier, nation, region
where
p_partkey = ps_partkey
and s_suppkey = ps_suppkey
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'ASIA'
)
order by
s_acctbal desc, n_name, s_name, p_partkey;
--echo === Q15 ===
@ -230,7 +288,6 @@ flush table nation;
eval EXPLAIN EXTENDED $Q20;
eval $Q20;
DROP DATABASE dbt3_s001;
set histogram_type=@save_histogram_type;
@ -619,5 +676,36 @@ DROP TABLE t1,t2;
set use_stat_tables=@save_use_stat_tables;
--echo #
--echo # Bug mdev-4406: range condition for non-nullable column
--echo # when optimizer_use_condition_selectivity=3
--echo #
create table t1 (a int not null);
insert into t1 values
(7), (6), (4), (9), (1), (5), (2), (1), (3), (8);
set use_stat_tables='preferably';
analyze table t1;
flush table t1;
set optimizer_use_condition_selectivity=3;
select count(*) from t1 where a between 5 and 7;
explain extended select * from t1 where a between 5 and 7;
alter table t1 change column a a int;
analyze table t1;
flush table t1;
explain extended select * from t1 where a between 5 and 7;
set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
drop table t1;
set use_stat_tables=@save_use_stat_tables;
set use_stat_tables=@save_use_stat_tables;

View File

@ -564,6 +564,23 @@ SELECT UPPER(db_name), UPPER(table_name),
index_name, prefix_arity, avg_frequency
FROM mysql.index_stats;
set use_stat_tables='preferably';
--disable_result_log
set histogram_size=100;
set histogram_type='SINGLE_PREC_HB';
ANALYZE TABLE CountryLanguage;
set histogram_size=254;
set histogram_type='DOUBLE_PREC_HB';
ANALYZE TABLE City;
FLUSH TABLES;
--enable_result_log
--query_vertical select db_name,table_name,column_name,min_value,max_value,nulls_ratio,avg_length,avg_frequency,hist_size,hist_type,hex(histogram),decode_histogram(histogram,hist_type) from mysql.column_stats where column_name = 'Percentage';
--query_vertical select db_name,table_name,column_name,min_value,max_value,nulls_ratio,avg_length,avg_frequency,hist_size,hist_type,hex(histogram),decode_histogram(histogram,hist_type) from mysql.column_stats where column_name = 'Population';
set histogram_type=default;
set histogram_size=default;
use test;
DROP DATABASE world;