diff options
author | Igor Babaev <igor@askmonty.org> | 2013-04-17 10:18:04 -0700 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2013-04-17 10:18:04 -0700 |
commit | a1cd28e2e54d32dc70280875bab7f0d35e9370c4 (patch) | |
tree | ceb810aa1bd2619efec70cb60d4adbac05e35a42 /mysql-test | |
parent | 0e7410a154560486ce4e0c975f122a0b15853bb1 (diff) | |
parent | 43fe53acc225a2cea07188d142c1c0f8364cc43b (diff) | |
download | mariadb-git-a1cd28e2e54d32dc70280875bab7f0d35e9370c4.tar.gz |
Merge 10.0-base -> 10.0
Diffstat (limited to 'mysql-test')
21 files changed, 3901 insertions, 231 deletions
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index fdf06bfd327..7d263878bac 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -4786,6 +4786,9 @@ sub extract_warning_lines ($$) { qr|Warning: io_setup\(\) failed|, qr|Warning: io_setup\(\) attempt|, qr|setrlimit could not change the size of core files to 'infinity';|, + qr|feedback plugin: failed to retrieve the MAC address|, + qr|Plugin 'FEEDBACK' init function returned error|, + qr|Plugin 'FEEDBACK' registration as a INFORMATION SCHEMA failed|, ); my $matched_lines= []; diff --git a/mysql-test/r/myisam-metadata.result b/mysql-test/r/myisam-metadata.result index 5192253d5d1..4d49bac9436 100644 --- a/mysql-test/r/myisam-metadata.result +++ b/mysql-test/r/myisam-metadata.result @@ -5,7 +5,10 @@ a VARCHAR(100), INDEX(a) ) ENGINE=MyISAM; ALTER TABLE t1 DISABLE KEYS; +SET debug_sync= 'myisam_after_repair_by_sort SIGNAL waiting WAIT_FOR go'; ALTER TABLE t1 ENABLE KEYS; +SET debug_sync= 'now WAIT_FOR waiting'; +SET debug_sync= 'now SIGNAL go'; SHOW TABLE STATUS LIKE 't1'; Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment t1 MyISAM 10 Dynamic 100000 27 # # # 0 NULL # # # latin1_swedish_ci NULL diff --git a/mysql-test/r/mysqld--help.result b/mysql-test/r/mysqld--help.result index a928c16bcb8..a3f402b7568 100644 --- a/mysql-test/r/mysqld--help.result +++ b/mysql-test/r/mysqld--help.result @@ -208,6 +208,13 @@ The following options may be given as the first argument: use a distinct domain_id. For simple tree-shaped replication topologies, it can be left at its default, 0. -?, --help Display this help and exit. + --histogram-size=# Number of bytes used for a histogram. If set to 0, no + histograms are created by ANALYZE. + --histogram-type=name + Specifies type of the histograms created by ANALYZE. + Possible values are: SINGLE_PREC_HB - single precision + height-balanced, DOUBLE_PREC_HB - double precision + height-balanced. --ignore-builtin-innodb Disable initialization of builtin InnoDB plugin --ignore-db-dirs=name @@ -504,6 +511,21 @@ The following options may be given as the first argument: partial_match_table_scan, semijoin, semijoin_with_cache, subquery_cache, table_elimination, extended_keys, exists_to_in } and val is one of {on, off, default} + --optimizer-use-condition-selectivity=# + Controls selectivity of which conditions the optimizer + takes into account to calculate cardinality of a partial + join when it searches for the best execution plan + Meaning: 1 - use selectivity of index backed range + conditions to calculate the cardinality of a partial join + if the last joined table is accessed by full table scan + or an index scan, 2 - use selectivity of index backed + range conditions to calculate the cardinality of a + partial join in any case, 3 - additionally always use + selectivity of range conditions that are not backed by + 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. --performance-schema Enable the performance schema. --performance-schema-accounts-size=# @@ -1016,6 +1038,8 @@ general-log FALSE group-concat-max-len 1024 gtid-domain-id 0 help TRUE +histogram-size 0 +histogram-type SINGLE_PREC_HB ignore-builtin-innodb FALSE ignore-db-dirs init-connect @@ -1106,6 +1130,7 @@ old-style-user-limits FALSE optimizer-prune-level 1 optimizer-search-depth 62 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 performance-schema-accounts-size 100 performance-schema-consumer-events-stages-current FALSE diff --git a/mysql-test/r/selectivity.result b/mysql-test/r/selectivity.result new file mode 100644 index 00000000000..8371b0eb0b6 --- /dev/null +++ b/mysql-test/r/selectivity.result @@ -0,0 +1,1014 @@ +select @@global.use_stat_tables; +@@global.use_stat_tables +COMPLEMENTARY +select @@session.use_stat_tables; +@@session.use_stat_tables +COMPLEMENTARY +set @save_use_stat_tables=@@use_stat_tables; +set use_stat_tables='preferably'; +set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity; +set @save_histogram_size=@@histogram_size; +set @save_histogram_type=@@histogram_type; +set optimizer_use_condition_selectivity=3; +create table t1 (a int); +insert into t1 values +(9), (3), (2), (NULL), (NULL), (2), (NULL), (1), (5), (NULL); +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +select * from mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 1 9 0.4000 4.0000 1.2000 0 NULL NULL +flush table t1; +explain extended +select * from t1 where a is null; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 40.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where isnull(`test`.`t1`.`a`) +explain extended +select * from t1 where a is not null; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 60.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` is not null) +drop table t1; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP DATABASE IF EXISTS dbt3_s001; +CREATE DATABASE dbt3_s001; +use dbt3_s001; +=== Q15 === +create view revenue0 (supplier_no, total_revenue) as +select l_suppkey, sum(l_extendedprice * (1 - l_discount)) +from lineitem +where +l_shipdate >= '1995-08-01' + and l_shipdate < date_add('1995-08-01', interval 90 day) +group by l_suppkey; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED select s_suppkey, s_name, s_address, s_phone, total_revenue +from supplier, revenue0 +where s_suppkey = supplier_no +and total_revenue = (select max(total_revenue) from revenue0) +order by s_suppkey; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY supplier ALL PRIMARY NULL NULL NULL 10 100.00 Using filesort +1 PRIMARY <derived3> ref key0 key0 5 dbt3_s001.supplier.s_suppkey 10 100.00 Using where +3 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 268 100.00 Using where; Using temporary; Using filesort +2 SUBQUERY <derived4> ALL NULL NULL NULL NULL 268 100.00 +4 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 268 100.00 Using where; Using temporary; Using filesort +Warnings: +Note 1003 select `dbt3_s001`.`supplier`.`s_suppkey` AS `s_suppkey`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`revenue0`.`total_revenue` AS `total_revenue` from `dbt3_s001`.`supplier` join `dbt3_s001`.`revenue0` where ((`revenue0`.`supplier_no` = `dbt3_s001`.`supplier`.`s_suppkey`) and (`revenue0`.`total_revenue` = (select max(`revenue0`.`total_revenue`) from `dbt3_s001`.`revenue0`))) order by `dbt3_s001`.`supplier`.`s_suppkey` +select s_suppkey, s_name, s_address, s_phone, total_revenue +from supplier, revenue0 +where s_suppkey = supplier_no +and total_revenue = (select max(total_revenue) from revenue0) +order by s_suppkey; +s_suppkey s_name s_address s_phone total_revenue +1 Supplier#000000001 N kD4on9OM Ipw3,gf0JBoQDd7tgrzrddZ 27-918-335-1736 729084.7773 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED select s_suppkey, s_name, s_address, s_phone, total_revenue +from supplier, revenue0 +where s_suppkey = supplier_no +and total_revenue = (select max(total_revenue) from revenue0) +order by s_suppkey; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY supplier ALL PRIMARY NULL NULL NULL 10 100.00 Using filesort +1 PRIMARY <derived3> ref key0 key0 5 dbt3_s001.supplier.s_suppkey 10 100.00 Using where +3 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 268 0.20 Using where; Using temporary; Using filesort +2 SUBQUERY <derived4> ALL NULL NULL NULL NULL 268 100.00 +4 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 268 0.20 Using where; Using temporary; Using filesort +Warnings: +Note 1003 select `dbt3_s001`.`supplier`.`s_suppkey` AS `s_suppkey`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`revenue0`.`total_revenue` AS `total_revenue` from `dbt3_s001`.`supplier` join `dbt3_s001`.`revenue0` where ((`revenue0`.`supplier_no` = `dbt3_s001`.`supplier`.`s_suppkey`) and (`revenue0`.`total_revenue` = (select max(`revenue0`.`total_revenue`) from `dbt3_s001`.`revenue0`))) order by `dbt3_s001`.`supplier`.`s_suppkey` +select s_suppkey, s_name, s_address, s_phone, total_revenue +from supplier, revenue0 +where s_suppkey = supplier_no +and total_revenue = (select max(total_revenue) from revenue0) +order by s_suppkey; +s_suppkey s_name s_address s_phone total_revenue +1 Supplier#000000001 N kD4on9OM Ipw3,gf0JBoQDd7tgrzrddZ 27-918-335-1736 729084.7773 +set optimizer_switch=@save_optimizer_switch; +drop view revenue0; +=== Q16 === +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 100.00 Using where; Using temporary; Using filesort +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where; Using index +2 MATERIALIZED supplier ALL PRIMARY NULL NULL NULL 10 100.00 Using where +Warnings: +Note 1003 select `dbt3_s001`.`part`.`p_brand` AS `p_brand`,`dbt3_s001`.`part`.`p_type` AS `p_type`,`dbt3_s001`.`part`.`p_size` AS `p_size`,count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) AS `supplier_cnt` from `dbt3_s001`.`partsupp` join `dbt3_s001`.`part` where ((`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`part`.`p_brand` <> 'Brand#11') and (not((`dbt3_s001`.`part`.`p_type` like 'SMALL POLISHED%'))) and (`dbt3_s001`.`part`.`p_size` in (49,37,27,5,40,6,22,8)) and (not(<expr_cache><`dbt3_s001`.`partsupp`.`ps_suppkey`>(<in_optimizer>(`dbt3_s001`.`partsupp`.`ps_suppkey`,`dbt3_s001`.`partsupp`.`ps_suppkey` in ( <materialize> (select `dbt3_s001`.`supplier`.`s_suppkey` from `dbt3_s001`.`supplier` where (`dbt3_s001`.`supplier`.`s_comment` like '%Customer%Complaints%') ), <primary_index_lookup>(`dbt3_s001`.`partsupp`.`ps_suppkey` in <temporary table> on distinct_key where ((`dbt3_s001`.`partsupp`.`ps_suppkey` = `<subquery2>`.`s_suppkey`))))))))) group by `dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` order by count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) desc,`dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` +select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +p_brand p_type p_size supplier_cnt +Brand#21 MEDIUM ANODIZED TIN 8 4 +Brand#22 PROMO PLATED TIN 5 4 +Brand#24 MEDIUM BURNISHED NICKEL 6 4 +Brand#24 SMALL ANODIZED STEEL 40 4 +Brand#32 MEDIUM BURNISHED BRASS 49 4 +Brand#33 MEDIUM POLISHED BRASS 49 4 +Brand#41 STANDARD BRUSHED NICKEL 40 4 +Brand#44 PROMO POLISHED STEEL 5 4 +Brand#45 PROMO ANODIZED BRASS 22 4 +Brand#53 STANDARD BRUSHED STEEL 27 4 +Brand#54 MEDIUM POLISHED BRASS 22 4 +Brand#54 STANDARD ANODIZED BRASS 22 4 +Brand#13 LARGE BRUSHED STEEL 8 2 +Brand#25 ECONOMY BURNISHED COPPER 27 2 +Brand#44 STANDARD PLATED TIN 37 1 +Brand#51 ECONOMY POLISHED STEEL 49 1 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 16.67 Using where; Using temporary; Using filesort +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where; Using index +2 MATERIALIZED supplier ALL PRIMARY NULL NULL NULL 10 100.00 Using where +Warnings: +Note 1003 select `dbt3_s001`.`part`.`p_brand` AS `p_brand`,`dbt3_s001`.`part`.`p_type` AS `p_type`,`dbt3_s001`.`part`.`p_size` AS `p_size`,count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) AS `supplier_cnt` from `dbt3_s001`.`partsupp` join `dbt3_s001`.`part` where ((`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`part`.`p_brand` <> 'Brand#11') and (not((`dbt3_s001`.`part`.`p_type` like 'SMALL POLISHED%'))) and (`dbt3_s001`.`part`.`p_size` in (49,37,27,5,40,6,22,8)) and (not(<expr_cache><`dbt3_s001`.`partsupp`.`ps_suppkey`>(<in_optimizer>(`dbt3_s001`.`partsupp`.`ps_suppkey`,`dbt3_s001`.`partsupp`.`ps_suppkey` in ( <materialize> (select `dbt3_s001`.`supplier`.`s_suppkey` from `dbt3_s001`.`supplier` where (`dbt3_s001`.`supplier`.`s_comment` like '%Customer%Complaints%') ), <primary_index_lookup>(`dbt3_s001`.`partsupp`.`ps_suppkey` in <temporary table> on distinct_key where ((`dbt3_s001`.`partsupp`.`ps_suppkey` = `<subquery2>`.`s_suppkey`))))))))) group by `dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` order by count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) desc,`dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` +select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +p_brand p_type p_size supplier_cnt +Brand#21 MEDIUM ANODIZED TIN 8 4 +Brand#22 PROMO PLATED TIN 5 4 +Brand#24 MEDIUM BURNISHED NICKEL 6 4 +Brand#24 SMALL ANODIZED STEEL 40 4 +Brand#32 MEDIUM BURNISHED BRASS 49 4 +Brand#33 MEDIUM POLISHED BRASS 49 4 +Brand#41 STANDARD BRUSHED NICKEL 40 4 +Brand#44 PROMO POLISHED STEEL 5 4 +Brand#45 PROMO ANODIZED BRASS 22 4 +Brand#53 STANDARD BRUSHED STEEL 27 4 +Brand#54 MEDIUM POLISHED BRASS 22 4 +Brand#54 STANDARD ANODIZED BRASS 22 4 +Brand#13 LARGE BRUSHED STEEL 8 2 +Brand#25 ECONOMY BURNISHED COPPER 27 2 +Brand#44 STANDARD PLATED TIN 37 1 +Brand#51 ECONOMY POLISHED STEEL 49 1 +set optimizer_use_condition_selectivity=4; +EXPLAIN EXTENDED select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 16.67 Using where; Using temporary; Using filesort +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where; Using index +2 MATERIALIZED supplier ALL PRIMARY NULL NULL NULL 10 100.00 Using where +Warnings: +Note 1003 select `dbt3_s001`.`part`.`p_brand` AS `p_brand`,`dbt3_s001`.`part`.`p_type` AS `p_type`,`dbt3_s001`.`part`.`p_size` AS `p_size`,count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) AS `supplier_cnt` from `dbt3_s001`.`partsupp` join `dbt3_s001`.`part` where ((`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`part`.`p_brand` <> 'Brand#11') and (not((`dbt3_s001`.`part`.`p_type` like 'SMALL POLISHED%'))) and (`dbt3_s001`.`part`.`p_size` in (49,37,27,5,40,6,22,8)) and (not(<expr_cache><`dbt3_s001`.`partsupp`.`ps_suppkey`>(<in_optimizer>(`dbt3_s001`.`partsupp`.`ps_suppkey`,`dbt3_s001`.`partsupp`.`ps_suppkey` in ( <materialize> (select `dbt3_s001`.`supplier`.`s_suppkey` from `dbt3_s001`.`supplier` where (`dbt3_s001`.`supplier`.`s_comment` like '%Customer%Complaints%') ), <primary_index_lookup>(`dbt3_s001`.`partsupp`.`ps_suppkey` in <temporary table> on distinct_key where ((`dbt3_s001`.`partsupp`.`ps_suppkey` = `<subquery2>`.`s_suppkey`))))))))) group by `dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` order by count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) desc,`dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` +select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +p_brand p_type p_size supplier_cnt +Brand#21 MEDIUM ANODIZED TIN 8 4 +Brand#22 PROMO PLATED TIN 5 4 +Brand#24 MEDIUM BURNISHED NICKEL 6 4 +Brand#24 SMALL ANODIZED STEEL 40 4 +Brand#32 MEDIUM BURNISHED BRASS 49 4 +Brand#33 MEDIUM POLISHED BRASS 49 4 +Brand#41 STANDARD BRUSHED NICKEL 40 4 +Brand#44 PROMO POLISHED STEEL 5 4 +Brand#45 PROMO ANODIZED BRASS 22 4 +Brand#53 STANDARD BRUSHED STEEL 27 4 +Brand#54 MEDIUM POLISHED BRASS 22 4 +Brand#54 STANDARD ANODIZED BRASS 22 4 +Brand#13 LARGE BRUSHED STEEL 8 2 +Brand#25 ECONOMY BURNISHED COPPER 27 2 +Brand#44 STANDARD PLATED TIN 37 1 +Brand#51 ECONOMY POLISHED STEEL 49 1 +=== Q18 === +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED select +c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) +from customer, orders, lineitem +where +o_orderkey in (select l_orderkey from lineitem +group by l_orderkey having sum(l_quantity) > 250) +and c_custkey = o_custkey +and o_orderkey = l_orderkey +group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice +order by o_totalprice desc, o_orderdate; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY orders ALL PRIMARY,i_o_custkey NULL NULL NULL 1500 100.00 Using where; Using temporary; Using filesort +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.orders.o_orderkey 1 100.00 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 100.00 +1 PRIMARY lineitem ref PRIMARY,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey_quantity 4 dbt3_s001.orders.o_orderkey 4 100.00 Using index +2 MATERIALIZED lineitem index NULL i_l_orderkey_quantity 13 NULL 6005 100.00 Using index +Warnings: +Note 1003 select `dbt3_s001`.`customer`.`c_name` AS `c_name`,`dbt3_s001`.`customer`.`c_custkey` AS `c_custkey`,`dbt3_s001`.`orders`.`o_orderkey` AS `o_orderkey`,`dbt3_s001`.`orders`.`o_orderDATE` AS `o_orderdate`,`dbt3_s001`.`orders`.`o_totalprice` AS `o_totalprice`,sum(`dbt3_s001`.`lineitem`.`l_quantity`) AS `sum(l_quantity)` from <materialize> (select `dbt3_s001`.`lineitem`.`l_orderkey` from `dbt3_s001`.`lineitem` group by `dbt3_s001`.`lineitem`.`l_orderkey` having (sum(`dbt3_s001`.`lineitem`.`l_quantity`) > 250)) join `dbt3_s001`.`customer` join `dbt3_s001`.`orders` join `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`customer`.`c_custkey` = `dbt3_s001`.`orders`.`o_custkey`) and (`<subquery2>`.`l_orderkey` = `dbt3_s001`.`orders`.`o_orderkey`) and (`dbt3_s001`.`lineitem`.`l_orderkey` = `dbt3_s001`.`orders`.`o_orderkey`)) group by `dbt3_s001`.`customer`.`c_name`,`dbt3_s001`.`customer`.`c_custkey`,`dbt3_s001`.`orders`.`o_orderkey`,`dbt3_s001`.`orders`.`o_orderDATE`,`dbt3_s001`.`orders`.`o_totalprice` order by `dbt3_s001`.`orders`.`o_totalprice` desc,`dbt3_s001`.`orders`.`o_orderDATE` +select +c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) +from customer, orders, lineitem +where +o_orderkey in (select l_orderkey from lineitem +group by l_orderkey having sum(l_quantity) > 250) +and c_custkey = o_custkey +and o_orderkey = l_orderkey +group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice +order by o_totalprice desc, o_orderdate; +c_name c_custkey o_orderkey o_orderdate o_totalprice sum(l_quantity) +Customer#000000070 70 2567 1998-02-27 263411.29 266 +Customer#000000010 10 4421 1997-04-04 258779.02 255 +Customer#000000082 82 3460 1995-10-03 245976.74 254 +Customer#000000068 68 2208 1995-05-01 245388.06 256 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED select +c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) +from customer, orders, lineitem +where +o_orderkey in (select l_orderkey from lineitem +group by l_orderkey having sum(l_quantity) > 250) +and c_custkey = o_custkey +and o_orderkey = l_orderkey +group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice +order by o_totalprice desc, o_orderdate; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY orders ALL PRIMARY,i_o_custkey NULL NULL NULL 1500 100.00 Using where; Using temporary; Using filesort +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.orders.o_orderkey 1 100.00 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 100.00 +1 PRIMARY lineitem ref PRIMARY,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey_quantity 4 dbt3_s001.orders.o_orderkey 4 100.00 Using index +2 MATERIALIZED lineitem index NULL i_l_orderkey_quantity 13 NULL 6005 100.00 Using index +Warnings: +Note 1003 select `dbt3_s001`.`customer`.`c_name` AS `c_name`,`dbt3_s001`.`customer`.`c_custkey` AS `c_custkey`,`dbt3_s001`.`orders`.`o_orderkey` AS `o_orderkey`,`dbt3_s001`.`orders`.`o_orderDATE` AS `o_orderdate`,`dbt3_s001`.`orders`.`o_totalprice` AS `o_totalprice`,sum(`dbt3_s001`.`lineitem`.`l_quantity`) AS `sum(l_quantity)` from <materialize> (select `dbt3_s001`.`lineitem`.`l_orderkey` from `dbt3_s001`.`lineitem` group by `dbt3_s001`.`lineitem`.`l_orderkey` having (sum(`dbt3_s001`.`lineitem`.`l_quantity`) > 250)) join `dbt3_s001`.`customer` join `dbt3_s001`.`orders` join `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`customer`.`c_custkey` = `dbt3_s001`.`orders`.`o_custkey`) and (`<subquery2>`.`l_orderkey` = `dbt3_s001`.`orders`.`o_orderkey`) and (`dbt3_s001`.`lineitem`.`l_orderkey` = `dbt3_s001`.`orders`.`o_orderkey`)) group by `dbt3_s001`.`customer`.`c_name`,`dbt3_s001`.`customer`.`c_custkey`,`dbt3_s001`.`orders`.`o_orderkey`,`dbt3_s001`.`orders`.`o_orderDATE`,`dbt3_s001`.`orders`.`o_totalprice` order by `dbt3_s001`.`orders`.`o_totalprice` desc,`dbt3_s001`.`orders`.`o_orderDATE` +select +c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) +from customer, orders, lineitem +where +o_orderkey in (select l_orderkey from lineitem +group by l_orderkey having sum(l_quantity) > 250) +and c_custkey = o_custkey +and o_orderkey = l_orderkey +group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice +order by o_totalprice desc, o_orderdate; +c_name c_custkey o_orderkey o_orderdate o_totalprice sum(l_quantity) +Customer#000000070 70 2567 1998-02-27 263411.29 266 +Customer#000000010 10 4421 1997-04-04 258779.02 255 +Customer#000000082 82 3460 1995-10-03 245976.74 254 +Customer#000000068 68 2208 1995-05-01 245388.06 256 +=== Q22 === +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal +from ( +select substr(c_phone, 1, 2) as cntrycode, c_acctbal +from customer +where +substr(c_phone, 1, 2) in ('10', '20', '14', '19', '11', '28', '25') +and c_acctbal > (select avg(c_acctbal) from customer +where c_acctbal > 0.00 +and substr(c_phone, 1, 2) in +('10', '20', '14', '19', '11', '28', '25')) +and not exists (select * from orders where o_custkey = c_custkey) +) as vip +group by cntrycode +order by cntrycode; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE customer ALL NULL NULL NULL NULL 150 100.00 Using where; Using temporary; Using filesort +4 DEPENDENT SUBQUERY orders ref i_o_custkey i_o_custkey 5 dbt3_s001.customer.c_custkey 15 100.00 Using index +3 SUBQUERY customer ALL NULL NULL NULL NULL 150 100.00 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.customer.c_custkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select substr(`dbt3_s001`.`customer`.`c_phone`,1,2) AS `cntrycode`,count(0) AS `numcust`,sum(`dbt3_s001`.`customer`.`c_acctbal`) AS `totacctbal` from `dbt3_s001`.`customer` where ((substr(`dbt3_s001`.`customer`.`c_phone`,1,2) in ('10','20','14','19','11','28','25')) and (`dbt3_s001`.`customer`.`c_acctbal` > (select avg(`dbt3_s001`.`customer`.`c_acctbal`) from `dbt3_s001`.`customer` where ((`dbt3_s001`.`customer`.`c_acctbal` > 0.00) and (substr(`dbt3_s001`.`customer`.`c_phone`,1,2) in ('10','20','14','19','11','28','25'))))) and (not(exists(select 1 from `dbt3_s001`.`orders` where (`dbt3_s001`.`orders`.`o_custkey` = `dbt3_s001`.`customer`.`c_custkey`))))) group by substr(`dbt3_s001`.`customer`.`c_phone`,1,2) order by substr(`dbt3_s001`.`customer`.`c_phone`,1,2) +select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal +from ( +select substr(c_phone, 1, 2) as cntrycode, c_acctbal +from customer +where +substr(c_phone, 1, 2) in ('10', '20', '14', '19', '11', '28', '25') +and c_acctbal > (select avg(c_acctbal) from customer +where c_acctbal > 0.00 +and substr(c_phone, 1, 2) in +('10', '20', '14', '19', '11', '28', '25')) +and not exists (select * from orders where o_custkey = c_custkey) +) as vip +group by cntrycode +order by cntrycode; +cntrycode numcust totacctbal +11 4 29942.58 +19 2 17120.35 +20 1 9091.82 +28 2 14755.5 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal +from ( +select substr(c_phone, 1, 2) as cntrycode, c_acctbal +from customer +where +substr(c_phone, 1, 2) in ('10', '20', '14', '19', '11', '28', '25') +and c_acctbal > (select avg(c_acctbal) from customer +where c_acctbal > 0.00 +and substr(c_phone, 1, 2) in +('10', '20', '14', '19', '11', '28', '25')) +and not exists (select * from orders where o_custkey = c_custkey) +) as vip +group by cntrycode +order by cntrycode; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE customer ALL NULL NULL NULL NULL 150 100.00 Using where; Using temporary; Using filesort +4 DEPENDENT SUBQUERY orders ref i_o_custkey i_o_custkey 5 dbt3_s001.customer.c_custkey 15 100.00 Using index +3 SUBQUERY customer ALL NULL NULL NULL NULL 150 91.00 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.customer.c_custkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select substr(`dbt3_s001`.`customer`.`c_phone`,1,2) AS `cntrycode`,count(0) AS `numcust`,sum(`dbt3_s001`.`customer`.`c_acctbal`) AS `totacctbal` from `dbt3_s001`.`customer` where ((substr(`dbt3_s001`.`customer`.`c_phone`,1,2) in ('10','20','14','19','11','28','25')) and (`dbt3_s001`.`customer`.`c_acctbal` > (select avg(`dbt3_s001`.`customer`.`c_acctbal`) from `dbt3_s001`.`customer` where ((`dbt3_s001`.`customer`.`c_acctbal` > 0.00) and (substr(`dbt3_s001`.`customer`.`c_phone`,1,2) in ('10','20','14','19','11','28','25'))))) and (not(exists(select 1 from `dbt3_s001`.`orders` where (`dbt3_s001`.`orders`.`o_custkey` = `dbt3_s001`.`customer`.`c_custkey`))))) group by substr(`dbt3_s001`.`customer`.`c_phone`,1,2) order by substr(`dbt3_s001`.`customer`.`c_phone`,1,2) +select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal +from ( +select substr(c_phone, 1, 2) as cntrycode, c_acctbal +from customer +where +substr(c_phone, 1, 2) in ('10', '20', '14', '19', '11', '28', '25') +and c_acctbal > (select avg(c_acctbal) from customer +where c_acctbal > 0.00 +and substr(c_phone, 1, 2) in +('10', '20', '14', '19', '11', '28', '25')) +and not exists (select * from orders where o_custkey = c_custkey) +) as vip +group by cntrycode +order by cntrycode; +cntrycode numcust totacctbal +11 4 29942.58 +19 2 17120.35 +20 1 9091.82 +28 2 14755.5 +=== Q20 === +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 100.00 Using where; Using filesort +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +1 PRIMARY nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where +2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 100.00 Using where +2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 100.00 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where ((`dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey`) and (`dbt3_s001`.`nation`.`n_name` = 'UNITED STATES') and (`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((select (0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`)) from `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`) and (`dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date))) and (`dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>((cast('1993-01-01' as date) + interval '1' year))))))) and (`dbt3_s001`.`part`.`p_name` like 'g%')) order by `dbt3_s001`.`supplier`.`s_name` limit 10 +select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +s_name s_address +Supplier#000000010 Saygah3gYWMp72i PY +SELECT ((SELECT COUNT(*) FROM part WHERE p_name LIKE 'g%') / +(SELECT COUNT(*) FROM part)) AS sel; +sel +0.0600 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 4.17 Using where +2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 15.14 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where ((`dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey`) and (`dbt3_s001`.`nation`.`n_name` = 'UNITED STATES') and (`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((select (0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`)) from `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`) and (`dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date))) and (`dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>((cast('1993-01-01' as date) + interval '1' year))))))) and (`dbt3_s001`.`part`.`p_name` like 'g%')) order by `dbt3_s001`.`supplier`.`s_name` limit 10 +select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +s_name s_address +Supplier#000000010 Saygah3gYWMp72i PY +set histogram_size=127; +ANALYZE TABLE part PERSISTENT FOR COLUMNS(p_name) INDEXES(); +Table Op Msg_type Msg_text +dbt3_s001.part analyze status Table is already up to date +flush table part; +set optimizer_use_condition_selectivity=4; +EXPLAIN EXTENDED select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00 +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 7.03 Using where +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_partkey 4 dbt3_s001.part.p_partkey 3 100.00 Using where; FirstMatch(supplier) +4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 15.14 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where ((`dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey`) and (`dbt3_s001`.`nation`.`n_name` = 'UNITED STATES') and (`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`partsupp`.`ps_suppkey` = `dbt3_s001`.`supplier`.`s_suppkey`) and (`dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((select (0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`)) from `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`) and (`dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date))) and (`dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>((cast('1993-01-01' as date) + interval '1' year))))))) and (`dbt3_s001`.`part`.`p_name` like 'g%')) order by `dbt3_s001`.`supplier`.`s_name` limit 10 +select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +s_name s_address +Supplier#000000010 Saygah3gYWMp72i PY +set histogram_type='DOUBLE_PREC_HB'; +set histogram_size=126; +ANALYZE TABLE part PERSISTENT FOR COLUMNS(p_name) INDEXES(); +Table Op Msg_type Msg_text +dbt3_s001.part analyze status Table is already up to date +flush table part; +EXPLAIN EXTENDED select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00 +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 7.81 Using where +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_partkey 4 dbt3_s001.part.p_partkey 3 100.00 Using where; FirstMatch(supplier) +4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 15.14 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where ((`dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey`) and (`dbt3_s001`.`nation`.`n_name` = 'UNITED STATES') and (`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`partsupp`.`ps_suppkey` = `dbt3_s001`.`supplier`.`s_suppkey`) and (`dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((select (0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`)) from `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`) and (`dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date))) and (`dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>((cast('1993-01-01' as date) + interval '1' year))))))) and (`dbt3_s001`.`part`.`p_name` like 'g%')) order by `dbt3_s001`.`supplier`.`s_name` limit 10 +select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +s_name s_address +Supplier#000000010 Saygah3gYWMp72i PY +set histogram_type='SINGLE_PREC_HB'; +set histogram_size=24; +ANALYZE TABLE nation PERSISTENT FOR COLUMNS(n_name) INDEXES(); +Table Op Msg_type Msg_text +dbt3_s001.nation analyze status Table is already up to date +flush table nation; +EXPLAIN EXTENDED select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00 +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 7.81 Using where +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_partkey 4 dbt3_s001.part.p_partkey 3 100.00 Using where; FirstMatch(supplier) +4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 15.14 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where ((`dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey`) and (`dbt3_s001`.`nation`.`n_name` = 'UNITED STATES') and (`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`partsupp`.`ps_suppkey` = `dbt3_s001`.`supplier`.`s_suppkey`) and (`dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((select (0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`)) from `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`) and (`dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date))) and (`dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>((cast('1993-01-01' as date) + interval '1' year))))))) and (`dbt3_s001`.`part`.`p_name` like 'g%')) order by `dbt3_s001`.`supplier`.`s_name` limit 10 +select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +s_name s_address +Supplier#000000010 Saygah3gYWMp72i PY +DROP DATABASE dbt3_s001; +set histogram_type=@save_histogram_type; +set histogram_size=@save_histogram_size; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +use test; +# +# Bug mdev-4348: using view with use_condition_selectivity > 1 +# +set @tmp_use_stat_tables=@@use_stat_tables; +set use_stat_tables='never'; +set optimizer_use_condition_selectivity=3; +CREATE TABLE t1 (a int, b int); +INSERT t1 VALUES (7,1), (0,7); +CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1; +CREATE TABLE t2 (c int, d int, index idx(d)); +INSERT INTO t2 VALUES +(0,4), (8,6), (1,3), (8,5), (9,3), (2,2), (6,2), +(1,9), (6,3), (2,8), (4,1), (0,7), (4,8), (4,5); +EXPLAIN EXTENDED +SELECT * FROM v1 INNER JOIN t2 ON ( a = c AND b = d ); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +1 SIMPLE t2 ref idx idx 5 test.t1.b 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`c` = `test`.`t1`.`a`) and (`test`.`t2`.`d` = `test`.`t1`.`b`)) +SELECT * FROM v1 INNER JOIN t2 ON ( a = c AND b = d ); +a b c d +0 7 0 7 +DROP VIEW v1; +DROP TABLE t1,t2; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +set use_stat_tables=@tmp_use_stat_tables; +# +# Bug mdev-4349: impossible range for non-indexed column +# +set optimizer_use_condition_selectivity=3; +create table t1 (a int); +insert into t1 values +(3), (7), (2), (5), (7), (1), (2), (2); +set optimizer_use_condition_selectivity=1; +explain extended +select * from t1 where a < 1 and a > 7; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` < 1) and (`test`.`t1`.`a` > 7)) +select * from t1 where a < 1 and a > 7; +a +set optimizer_use_condition_selectivity=3; +explain extended +select * from t1 where a < 1 and a > 7; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where 0 +select * from t1 where a < 1 and a > 7; +a +drop table t1; +create table t1 (a int); +insert into t1 values (1); +create table t2 (b int); +insert into t2 values (2),(3); +explain extended +select * from t1 where a in ( select b from t2 ) AND ( a > 3 ); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select 1 AS `a` from (`test`.`t2`) where 0 +select * from t1 where a in ( select b from t2 ) AND ( a > 3 ); +a +drop table t1,t2; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +# +# Bug mdev-4350: erroneous negative selectivity +# +create table t1 (a int); +insert into t1 values (1), (1); +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 values (0); +select count(*) from t1; +count(*) +1025 +set use_stat_tables='preferably'; +set histogram_size=127; +set histogram_type='SINGLE_PREC_HB'; +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +flush table t1; +set optimizer_use_condition_selectivity=4; +explain extended select * from t1 where a=0; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 1025 49.61 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 0) +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: 2-way join with an empty 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; +# +# Bug mdev-4366: impossible condition on an indexed column discovered after +# substitution of constant tables +# with optimizer_use_condition_selectivity=3 +# +CREATE TABLE t1 (pk int PRIMARY KEY, a int); +INSERT INTO t1 VALUES +(1,4), (2,6), (3,3), (4,5); +CREATE TABLE t2 (b int); +INSERT INTO t2 VALUES (1), (7); +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED +SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select 1 AS `1` from `test`.`t1` join `test`.`t2` where 0 +SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10; +1 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED +SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select 1 AS `1` from `test`.`t1` join `test`.`t2` where 0 +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; +# +# Bug mdev-4371: Join with condition supported by index on an empty table +# with optimizer_use_condition_selectivity=3 +# +set use_stat_tables=PREFERABLY; +CREATE TABLE t1 (a int, b int, INDEX(a)); +CREATE TABLE t2 (c int); +INSERT INTO t2 VALUES (1),(2),(3),(4),(5),(6),(7),(8); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +test.t2 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=3; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; +EXPLAIN EXTENDED +SELECT * FROM t1, t2 WHERE a > 9; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select NULL AS `a`,NULL AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t1` join `test`.`t2` where 0 +SELECT * FROM t1, t2 WHERE a > 9; +a b c +set optimizer_switch=@save_optimizer_switch; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4373: condition on a short varchar column +# with optimizer_use_condition_selectivity=3 +# +set use_stat_tables=PREFERABLY; +CREATE TABLE t1 (a varchar(1)); +INSERT INTO t1 VALUES ('x'), ('y'); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=3; +SELECT * FROM t1 WHERE a <= 'w'; +a +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4372: exists subquery in WHERE +# with optimizer_use_condition_selectivity=3 +# +set use_stat_tables = PREFERABLY; +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES +(1),(7),(4),(7),(0),(2),(9),(4),(0),(9),(1),(3),(8),(8); +CREATE TABLE t2 (b int); +INSERT INTO t2 VALUES (4),(5),(2),(5),(1),(1),(2); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED +SELECT * FROM t1, t2 WHERE EXISTS ( SELECT 1 FROM t1, t2 ) AND a != b OR a <= 4; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 7 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 14 100.00 Using where; Using join buffer (flat, BNL join) +2 SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 14 100.00 Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where ((exists(select 1 from `test`.`t1` join `test`.`t2`) and (`test`.`t1`.`a` <> `test`.`t2`.`b`)) or (`test`.`t1`.`a` <= 4)) +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4363: selectivity of the condition a IS NULL OR IS NOT NULL +# with optimizer_use_condition_selectivity=3 +# +set use_stat_tables = PREFERABLY; +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES +(1),(7),(4),(7),(NULL),(2),(NULL),(4),(NULL),(NULL),(1),(3),(8),(8); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +FLUSH TABLE t1; +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a IS NULL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 14 28.57 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where isnull(`test`.`t1`.`a`) +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a IS NOT NULL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 14 71.43 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` is not null) +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a IS NULL OR a IS NOT NULL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 14 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (isnull(`test`.`t1`.`a`) or (`test`.`t1`.`a` is not null)) +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a IS NULL OR a < 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 14 69.39 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (isnull(`test`.`t1`.`a`) or (`test`.`t1`.`a` < 5)) +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4378: 2-way join with a materialized IN subquery in WHERE +# when optimizer_use_condition_selectivity=4 +# +set use_stat_tables=PREFERABLY; +set histogram_size=50; +set histogram_type=SINGLE_PREC_HB; +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (8),(9),(6); +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (8),(1),(8),(9),(24),(6),(1),(6),(2),(4); +CREATE TABLE t3 (ln VARCHAR(16)) ENGINE=MyISAM; +INSERT INTO t3 VALUES +('smith'),('black'),('white'),('jones'), +('brown'),('taylor'),('anderson'),('taylor'); +ANALYZE TABLE t1, t2, t3; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +test.t3 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=4; +SELECT * FROM t1, t2 WHERE 'garcia' IN ( SELECT MIN( ln ) FROM t3 WHERE ln = 'sun' ); +a b +set histogram_size=@save_histogram_size; +set histogram_type=@save_histogram_type; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2,t3; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4380: 2-way join with a materialized IN subquery in WHERE +# when optimizer_use_condition_selectivity=3 +# +set use_stat_tables=PREFERABLY; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (5),(9); +CREATE TABLE t2 (b VARCHAR(8)); +INSERT INTO t2 VALUES ('red'),('blue'); +CREATE TABLE t3 (c VARCHAR(8), d VARCHAR(8)); +INSERT INTO t3 VALUES ('white','black'),('cyan','yellow'); +ANALYZE TABLE t1, t2, t3; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +test.t3 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=3; +SELECT * FROM t1, t2 WHERE ( 'orange', 'green' ) IN ( +SELECT MAX(c), MAX(d) FROM t3, t2 WHERE c >= d AND b = c +); +a b +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2,t3; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4389: join with degenerated range condition in WHERE +# when optimizer_use_condition_selectivity=3 +# +set use_stat_tables=PREFERABLY; +CREATE TABLE t1 (f1 VARCHAR(1)); +INSERT t1 VALUES ('p'),('q'); +CREATE TABLE t2 (f2 VARCHAR(1)); +INSERT INTO t2 VALUES +('o'),('v'),('f'),('f'),('e'),('l'),('j'),('p'),('r'),('j'), +('j'),('u'),('i'),('r'),('x'),('a'),('x'),('s'); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +FLUSH TABLES; +SET optimizer_use_condition_selectivity=3; +SELECT * FROM t1, t2 AS t2a, t2 AS t2b WHERE f1 <= 'a' AND t2a.f2 = f1; +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; +set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/r/selectivity_innodb.result b/mysql-test/r/selectivity_innodb.result new file mode 100644 index 00000000000..eba0ed2f32a --- /dev/null +++ b/mysql-test/r/selectivity_innodb.result @@ -0,0 +1,1024 @@ +SET SESSION STORAGE_ENGINE='InnoDB'; +set @save_optimizer_switch_for_selectivity_test=@@optimizer_switch; +set optimizer_switch='extended_keys=on'; +select @@global.use_stat_tables; +@@global.use_stat_tables +COMPLEMENTARY +select @@session.use_stat_tables; +@@session.use_stat_tables +COMPLEMENTARY +set @save_use_stat_tables=@@use_stat_tables; +set use_stat_tables='preferably'; +set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity; +set @save_histogram_size=@@histogram_size; +set @save_histogram_type=@@histogram_type; +set optimizer_use_condition_selectivity=3; +create table t1 (a int); +insert into t1 values +(9), (3), (2), (NULL), (NULL), (2), (NULL), (1), (5), (NULL); +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +select * from mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 1 9 0.4000 4.0000 1.2000 0 NULL NULL +flush table t1; +explain extended +select * from t1 where a is null; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 40.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where isnull(`test`.`t1`.`a`) +explain extended +select * from t1 where a is not null; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 60.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` is not null) +drop table t1; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP DATABASE IF EXISTS dbt3_s001; +CREATE DATABASE dbt3_s001; +use dbt3_s001; +=== Q15 === +create view revenue0 (supplier_no, total_revenue) as +select l_suppkey, sum(l_extendedprice * (1 - l_discount)) +from lineitem +where +l_shipdate >= '1995-08-01' + and l_shipdate < date_add('1995-08-01', interval 90 day) +group by l_suppkey; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED select s_suppkey, s_name, s_address, s_phone, total_revenue +from supplier, revenue0 +where s_suppkey = supplier_no +and total_revenue = (select max(total_revenue) from revenue0) +order by s_suppkey; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY supplier index PRIMARY PRIMARY 4 NULL 10 100.00 +1 PRIMARY <derived3> ref key0 key0 5 dbt3_s001.supplier.s_suppkey 10 100.00 Using where +3 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 228 100.00 Using where; Using temporary; Using filesort +2 SUBQUERY <derived4> ALL NULL NULL NULL NULL 228 100.00 +4 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 228 100.00 Using where; Using temporary; Using filesort +Warnings: +Note 1003 select `dbt3_s001`.`supplier`.`s_suppkey` AS `s_suppkey`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`revenue0`.`total_revenue` AS `total_revenue` from `dbt3_s001`.`supplier` join `dbt3_s001`.`revenue0` where ((`revenue0`.`supplier_no` = `dbt3_s001`.`supplier`.`s_suppkey`) and (`revenue0`.`total_revenue` = (select max(`revenue0`.`total_revenue`) from `dbt3_s001`.`revenue0`))) order by `dbt3_s001`.`supplier`.`s_suppkey` +select s_suppkey, s_name, s_address, s_phone, total_revenue +from supplier, revenue0 +where s_suppkey = supplier_no +and total_revenue = (select max(total_revenue) from revenue0) +order by s_suppkey; +s_suppkey s_name s_address s_phone total_revenue +1 Supplier#000000001 N kD4on9OM Ipw3,gf0JBoQDd7tgrzrddZ 27-918-335-1736 729084.7773 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED select s_suppkey, s_name, s_address, s_phone, total_revenue +from supplier, revenue0 +where s_suppkey = supplier_no +and total_revenue = (select max(total_revenue) from revenue0) +order by s_suppkey; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY supplier index PRIMARY PRIMARY 4 NULL 10 100.00 +1 PRIMARY <derived3> ref key0 key0 5 dbt3_s001.supplier.s_suppkey 10 100.00 Using where +3 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 228 0.14 Using where; Using temporary; Using filesort +2 SUBQUERY <derived4> ALL NULL NULL NULL NULL 228 100.00 +4 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 228 0.14 Using where; Using temporary; Using filesort +Warnings: +Note 1003 select `dbt3_s001`.`supplier`.`s_suppkey` AS `s_suppkey`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`revenue0`.`total_revenue` AS `total_revenue` from `dbt3_s001`.`supplier` join `dbt3_s001`.`revenue0` where ((`revenue0`.`supplier_no` = `dbt3_s001`.`supplier`.`s_suppkey`) and (`revenue0`.`total_revenue` = (select max(`revenue0`.`total_revenue`) from `dbt3_s001`.`revenue0`))) order by `dbt3_s001`.`supplier`.`s_suppkey` +select s_suppkey, s_name, s_address, s_phone, total_revenue +from supplier, revenue0 +where s_suppkey = supplier_no +and total_revenue = (select max(total_revenue) from revenue0) +order by s_suppkey; +s_suppkey s_name s_address s_phone total_revenue +1 Supplier#000000001 N kD4on9OM Ipw3,gf0JBoQDd7tgrzrddZ 27-918-335-1736 729084.7773 +set optimizer_switch=@save_optimizer_switch; +drop view revenue0; +=== Q16 === +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 100.00 Using where; Using temporary; Using filesort +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey i_ps_partkey 4 dbt3_s001.part.p_partkey 3 100.00 Using where; Using index +2 MATERIALIZED supplier ALL PRIMARY NULL NULL NULL 10 100.00 Using where +Warnings: +Note 1003 select `dbt3_s001`.`part`.`p_brand` AS `p_brand`,`dbt3_s001`.`part`.`p_type` AS `p_type`,`dbt3_s001`.`part`.`p_size` AS `p_size`,count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) AS `supplier_cnt` from `dbt3_s001`.`partsupp` join `dbt3_s001`.`part` where ((`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`part`.`p_brand` <> 'Brand#11') and (not((`dbt3_s001`.`part`.`p_type` like 'SMALL POLISHED%'))) and (`dbt3_s001`.`part`.`p_size` in (49,37,27,5,40,6,22,8)) and (not(<expr_cache><`dbt3_s001`.`partsupp`.`ps_suppkey`>(<in_optimizer>(`dbt3_s001`.`partsupp`.`ps_suppkey`,`dbt3_s001`.`partsupp`.`ps_suppkey` in ( <materialize> (select `dbt3_s001`.`supplier`.`s_suppkey` from `dbt3_s001`.`supplier` where (`dbt3_s001`.`supplier`.`s_comment` like '%Customer%Complaints%') ), <primary_index_lookup>(`dbt3_s001`.`partsupp`.`ps_suppkey` in <temporary table> on distinct_key where ((`dbt3_s001`.`partsupp`.`ps_suppkey` = `<subquery2>`.`s_suppkey`))))))))) group by `dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` order by count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) desc,`dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` +select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +p_brand p_type p_size supplier_cnt +Brand#21 MEDIUM ANODIZED TIN 8 4 +Brand#22 PROMO PLATED TIN 5 4 +Brand#24 MEDIUM BURNISHED NICKEL 6 4 +Brand#24 SMALL ANODIZED STEEL 40 4 +Brand#32 MEDIUM BURNISHED BRASS 49 4 +Brand#33 MEDIUM POLISHED BRASS 49 4 +Brand#41 STANDARD BRUSHED NICKEL 40 4 +Brand#44 PROMO POLISHED STEEL 5 4 +Brand#45 PROMO ANODIZED BRASS 22 4 +Brand#53 STANDARD BRUSHED STEEL 27 4 +Brand#54 MEDIUM POLISHED BRASS 22 4 +Brand#54 STANDARD ANODIZED BRASS 22 4 +Brand#13 LARGE BRUSHED STEEL 8 2 +Brand#25 ECONOMY BURNISHED COPPER 27 2 +Brand#44 STANDARD PLATED TIN 37 1 +Brand#51 ECONOMY POLISHED STEEL 49 1 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 16.67 Using where; Using temporary; Using filesort +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey i_ps_partkey 4 dbt3_s001.part.p_partkey 3 100.00 Using where; Using index +2 MATERIALIZED supplier ALL PRIMARY NULL NULL NULL 10 100.00 Using where +Warnings: +Note 1003 select `dbt3_s001`.`part`.`p_brand` AS `p_brand`,`dbt3_s001`.`part`.`p_type` AS `p_type`,`dbt3_s001`.`part`.`p_size` AS `p_size`,count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) AS `supplier_cnt` from `dbt3_s001`.`partsupp` join `dbt3_s001`.`part` where ((`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`part`.`p_brand` <> 'Brand#11') and (not((`dbt3_s001`.`part`.`p_type` like 'SMALL POLISHED%'))) and (`dbt3_s001`.`part`.`p_size` in (49,37,27,5,40,6,22,8)) and (not(<expr_cache><`dbt3_s001`.`partsupp`.`ps_suppkey`>(<in_optimizer>(`dbt3_s001`.`partsupp`.`ps_suppkey`,`dbt3_s001`.`partsupp`.`ps_suppkey` in ( <materialize> (select `dbt3_s001`.`supplier`.`s_suppkey` from `dbt3_s001`.`supplier` where (`dbt3_s001`.`supplier`.`s_comment` like '%Customer%Complaints%') ), <primary_index_lookup>(`dbt3_s001`.`partsupp`.`ps_suppkey` in <temporary table> on distinct_key where ((`dbt3_s001`.`partsupp`.`ps_suppkey` = `<subquery2>`.`s_suppkey`))))))))) group by `dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` order by count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) desc,`dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` +select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +p_brand p_type p_size supplier_cnt +Brand#21 MEDIUM ANODIZED TIN 8 4 +Brand#22 PROMO PLATED TIN 5 4 +Brand#24 MEDIUM BURNISHED NICKEL 6 4 +Brand#24 SMALL ANODIZED STEEL 40 4 +Brand#32 MEDIUM BURNISHED BRASS 49 4 +Brand#33 MEDIUM POLISHED BRASS 49 4 +Brand#41 STANDARD BRUSHED NICKEL 40 4 +Brand#44 PROMO POLISHED STEEL 5 4 +Brand#45 PROMO ANODIZED BRASS 22 4 +Brand#53 STANDARD BRUSHED STEEL 27 4 +Brand#54 MEDIUM POLISHED BRASS 22 4 +Brand#54 STANDARD ANODIZED BRASS 22 4 +Brand#13 LARGE BRUSHED STEEL 8 2 +Brand#25 ECONOMY BURNISHED COPPER 27 2 +Brand#44 STANDARD PLATED TIN 37 1 +Brand#51 ECONOMY POLISHED STEEL 49 1 +set optimizer_use_condition_selectivity=4; +EXPLAIN EXTENDED select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 16.67 Using where; Using temporary; Using filesort +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey i_ps_partkey 4 dbt3_s001.part.p_partkey 3 100.00 Using where; Using index +2 MATERIALIZED supplier ALL PRIMARY NULL NULL NULL 10 100.00 Using where +Warnings: +Note 1003 select `dbt3_s001`.`part`.`p_brand` AS `p_brand`,`dbt3_s001`.`part`.`p_type` AS `p_type`,`dbt3_s001`.`part`.`p_size` AS `p_size`,count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) AS `supplier_cnt` from `dbt3_s001`.`partsupp` join `dbt3_s001`.`part` where ((`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`part`.`p_brand` <> 'Brand#11') and (not((`dbt3_s001`.`part`.`p_type` like 'SMALL POLISHED%'))) and (`dbt3_s001`.`part`.`p_size` in (49,37,27,5,40,6,22,8)) and (not(<expr_cache><`dbt3_s001`.`partsupp`.`ps_suppkey`>(<in_optimizer>(`dbt3_s001`.`partsupp`.`ps_suppkey`,`dbt3_s001`.`partsupp`.`ps_suppkey` in ( <materialize> (select `dbt3_s001`.`supplier`.`s_suppkey` from `dbt3_s001`.`supplier` where (`dbt3_s001`.`supplier`.`s_comment` like '%Customer%Complaints%') ), <primary_index_lookup>(`dbt3_s001`.`partsupp`.`ps_suppkey` in <temporary table> on distinct_key where ((`dbt3_s001`.`partsupp`.`ps_suppkey` = `<subquery2>`.`s_suppkey`))))))))) group by `dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` order by count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) desc,`dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` +select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +p_brand p_type p_size supplier_cnt +Brand#21 MEDIUM ANODIZED TIN 8 4 +Brand#22 PROMO PLATED TIN 5 4 +Brand#24 MEDIUM BURNISHED NICKEL 6 4 +Brand#24 SMALL ANODIZED STEEL 40 4 +Brand#32 MEDIUM BURNISHED BRASS 49 4 +Brand#33 MEDIUM POLISHED BRASS 49 4 +Brand#41 STANDARD BRUSHED NICKEL 40 4 +Brand#44 PROMO POLISHED STEEL 5 4 +Brand#45 PROMO ANODIZED BRASS 22 4 +Brand#53 STANDARD BRUSHED STEEL 27 4 +Brand#54 MEDIUM POLISHED BRASS 22 4 +Brand#54 STANDARD ANODIZED BRASS 22 4 +Brand#13 LARGE BRUSHED STEEL 8 2 +Brand#25 ECONOMY BURNISHED COPPER 27 2 +Brand#44 STANDARD PLATED TIN 37 1 +Brand#51 ECONOMY POLISHED STEEL 49 1 +=== Q18 === +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED select +c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) +from customer, orders, lineitem +where +o_orderkey in (select l_orderkey from lineitem +group by l_orderkey having sum(l_quantity) > 250) +and c_custkey = o_custkey +and o_orderkey = l_orderkey +group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice +order by o_totalprice desc, o_orderdate; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY orders ALL PRIMARY,i_o_custkey NULL NULL NULL 1500 100.00 Using where; Using temporary; Using filesort +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.orders.o_orderkey 1 100.00 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 100.00 +1 PRIMARY lineitem ref PRIMARY,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey_quantity 4 dbt3_s001.orders.o_orderkey 4 100.00 Using index +2 MATERIALIZED lineitem index NULL PRIMARY 8 NULL 6005 100.00 +Warnings: +Note 1003 select `dbt3_s001`.`customer`.`c_name` AS `c_name`,`dbt3_s001`.`customer`.`c_custkey` AS `c_custkey`,`dbt3_s001`.`orders`.`o_orderkey` AS `o_orderkey`,`dbt3_s001`.`orders`.`o_orderDATE` AS `o_orderdate`,`dbt3_s001`.`orders`.`o_totalprice` AS `o_totalprice`,sum(`dbt3_s001`.`lineitem`.`l_quantity`) AS `sum(l_quantity)` from <materialize> (select `dbt3_s001`.`lineitem`.`l_orderkey` from `dbt3_s001`.`lineitem` group by `dbt3_s001`.`lineitem`.`l_orderkey` having (sum(`dbt3_s001`.`lineitem`.`l_quantity`) > 250)) join `dbt3_s001`.`customer` join `dbt3_s001`.`orders` join `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`customer`.`c_custkey` = `dbt3_s001`.`orders`.`o_custkey`) and (`<subquery2>`.`l_orderkey` = `dbt3_s001`.`orders`.`o_orderkey`) and (`dbt3_s001`.`lineitem`.`l_orderkey` = `dbt3_s001`.`orders`.`o_orderkey`)) group by `dbt3_s001`.`customer`.`c_name`,`dbt3_s001`.`customer`.`c_custkey`,`dbt3_s001`.`orders`.`o_orderkey`,`dbt3_s001`.`orders`.`o_orderDATE`,`dbt3_s001`.`orders`.`o_totalprice` order by `dbt3_s001`.`orders`.`o_totalprice` desc,`dbt3_s001`.`orders`.`o_orderDATE` +select +c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) +from customer, orders, lineitem +where +o_orderkey in (select l_orderkey from lineitem +group by l_orderkey having sum(l_quantity) > 250) +and c_custkey = o_custkey +and o_orderkey = l_orderkey +group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice +order by o_totalprice desc, o_orderdate; +c_name c_custkey o_orderkey o_orderdate o_totalprice sum(l_quantity) +Customer#000000070 70 2567 1998-02-27 263411.29 266 +Customer#000000010 10 4421 1997-04-04 258779.02 255 +Customer#000000082 82 3460 1995-10-03 245976.74 254 +Customer#000000068 68 2208 1995-05-01 245388.06 256 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED select +c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) +from customer, orders, lineitem +where +o_orderkey in (select l_orderkey from lineitem +group by l_orderkey having sum(l_quantity) > 250) +and c_custkey = o_custkey +and o_orderkey = l_orderkey +group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice +order by o_totalprice desc, o_orderdate; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY orders ALL PRIMARY,i_o_custkey NULL NULL NULL 1500 100.00 Using where; Using temporary; Using filesort +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.orders.o_orderkey 1 100.00 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 100.00 +1 PRIMARY lineitem ref PRIMARY,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey_quantity 4 dbt3_s001.orders.o_orderkey 4 100.00 Using index +2 MATERIALIZED lineitem index NULL PRIMARY 8 NULL 6005 100.00 +Warnings: +Note 1003 select `dbt3_s001`.`customer`.`c_name` AS `c_name`,`dbt3_s001`.`customer`.`c_custkey` AS `c_custkey`,`dbt3_s001`.`orders`.`o_orderkey` AS `o_orderkey`,`dbt3_s001`.`orders`.`o_orderDATE` AS `o_orderdate`,`dbt3_s001`.`orders`.`o_totalprice` AS `o_totalprice`,sum(`dbt3_s001`.`lineitem`.`l_quantity`) AS `sum(l_quantity)` from <materialize> (select `dbt3_s001`.`lineitem`.`l_orderkey` from `dbt3_s001`.`lineitem` group by `dbt3_s001`.`lineitem`.`l_orderkey` having (sum(`dbt3_s001`.`lineitem`.`l_quantity`) > 250)) join `dbt3_s001`.`customer` join `dbt3_s001`.`orders` join `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`customer`.`c_custkey` = `dbt3_s001`.`orders`.`o_custkey`) and (`<subquery2>`.`l_orderkey` = `dbt3_s001`.`orders`.`o_orderkey`) and (`dbt3_s001`.`lineitem`.`l_orderkey` = `dbt3_s001`.`orders`.`o_orderkey`)) group by `dbt3_s001`.`customer`.`c_name`,`dbt3_s001`.`customer`.`c_custkey`,`dbt3_s001`.`orders`.`o_orderkey`,`dbt3_s001`.`orders`.`o_orderDATE`,`dbt3_s001`.`orders`.`o_totalprice` order by `dbt3_s001`.`orders`.`o_totalprice` desc,`dbt3_s001`.`orders`.`o_orderDATE` +select +c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) +from customer, orders, lineitem +where +o_orderkey in (select l_orderkey from lineitem +group by l_orderkey having sum(l_quantity) > 250) +and c_custkey = o_custkey +and o_orderkey = l_orderkey +group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice +order by o_totalprice desc, o_orderdate; +c_name c_custkey o_orderkey o_orderdate o_totalprice sum(l_quantity) +Customer#000000070 70 2567 1998-02-27 263411.29 266 +Customer#000000010 10 4421 1997-04-04 258779.02 255 +Customer#000000082 82 3460 1995-10-03 245976.74 254 +Customer#000000068 68 2208 1995-05-01 245388.06 256 +=== Q22 === +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal +from ( +select substr(c_phone, 1, 2) as cntrycode, c_acctbal +from customer +where +substr(c_phone, 1, 2) in ('10', '20', '14', '19', '11', '28', '25') +and c_acctbal > (select avg(c_acctbal) from customer +where c_acctbal > 0.00 +and substr(c_phone, 1, 2) in +('10', '20', '14', '19', '11', '28', '25')) +and not exists (select * from orders where o_custkey = c_custkey) +) as vip +group by cntrycode +order by cntrycode; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE customer ALL NULL NULL NULL NULL 150 100.00 Using where; Using temporary; Using filesort +4 DEPENDENT SUBQUERY orders ref i_o_custkey i_o_custkey 5 dbt3_s001.customer.c_custkey 15 100.00 Using index +3 SUBQUERY customer ALL NULL NULL NULL NULL 150 100.00 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.customer.c_custkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select substr(`dbt3_s001`.`customer`.`c_phone`,1,2) AS `cntrycode`,count(0) AS `numcust`,sum(`dbt3_s001`.`customer`.`c_acctbal`) AS `totacctbal` from `dbt3_s001`.`customer` where ((substr(`dbt3_s001`.`customer`.`c_phone`,1,2) in ('10','20','14','19','11','28','25')) and (`dbt3_s001`.`customer`.`c_acctbal` > (select avg(`dbt3_s001`.`customer`.`c_acctbal`) from `dbt3_s001`.`customer` where ((`dbt3_s001`.`customer`.`c_acctbal` > 0.00) and (substr(`dbt3_s001`.`customer`.`c_phone`,1,2) in ('10','20','14','19','11','28','25'))))) and (not(exists(select 1 from `dbt3_s001`.`orders` where (`dbt3_s001`.`orders`.`o_custkey` = `dbt3_s001`.`customer`.`c_custkey`))))) group by substr(`dbt3_s001`.`customer`.`c_phone`,1,2) order by substr(`dbt3_s001`.`customer`.`c_phone`,1,2) +select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal +from ( +select substr(c_phone, 1, 2) as cntrycode, c_acctbal +from customer +where +substr(c_phone, 1, 2) in ('10', '20', '14', '19', '11', '28', '25') +and c_acctbal > (select avg(c_acctbal) from customer +where c_acctbal > 0.00 +and substr(c_phone, 1, 2) in +('10', '20', '14', '19', '11', '28', '25')) +and not exists (select * from orders where o_custkey = c_custkey) +) as vip +group by cntrycode +order by cntrycode; +cntrycode numcust totacctbal +11 4 29942.58 +19 2 17120.35 +20 1 9091.82 +28 2 14755.5 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal +from ( +select substr(c_phone, 1, 2) as cntrycode, c_acctbal +from customer +where +substr(c_phone, 1, 2) in ('10', '20', '14', '19', '11', '28', '25') +and c_acctbal > (select avg(c_acctbal) from customer +where c_acctbal > 0.00 +and substr(c_phone, 1, 2) in +('10', '20', '14', '19', '11', '28', '25')) +and not exists (select * from orders where o_custkey = c_custkey) +) as vip +group by cntrycode +order by cntrycode; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE customer ALL NULL NULL NULL NULL 150 100.00 Using where; Using temporary; Using filesort +4 DEPENDENT SUBQUERY orders ref i_o_custkey i_o_custkey 5 dbt3_s001.customer.c_custkey 15 100.00 Using index +3 SUBQUERY customer ALL NULL NULL NULL NULL 150 91.00 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.customer.c_custkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select substr(`dbt3_s001`.`customer`.`c_phone`,1,2) AS `cntrycode`,count(0) AS `numcust`,sum(`dbt3_s001`.`customer`.`c_acctbal`) AS `totacctbal` from `dbt3_s001`.`customer` where ((substr(`dbt3_s001`.`customer`.`c_phone`,1,2) in ('10','20','14','19','11','28','25')) and (`dbt3_s001`.`customer`.`c_acctbal` > (select avg(`dbt3_s001`.`customer`.`c_acctbal`) from `dbt3_s001`.`customer` where ((`dbt3_s001`.`customer`.`c_acctbal` > 0.00) and (substr(`dbt3_s001`.`customer`.`c_phone`,1,2) in ('10','20','14','19','11','28','25'))))) and (not(exists(select 1 from `dbt3_s001`.`orders` where (`dbt3_s001`.`orders`.`o_custkey` = `dbt3_s001`.`customer`.`c_custkey`))))) group by substr(`dbt3_s001`.`customer`.`c_phone`,1,2) order by substr(`dbt3_s001`.`customer`.`c_phone`,1,2) +select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal +from ( +select substr(c_phone, 1, 2) as cntrycode, c_acctbal +from customer +where +substr(c_phone, 1, 2) in ('10', '20', '14', '19', '11', '28', '25') +and c_acctbal > (select avg(c_acctbal) from customer +where c_acctbal > 0.00 +and substr(c_phone, 1, 2) in +('10', '20', '14', '19', '11', '28', '25')) +and not exists (select * from orders where o_custkey = c_custkey) +) as vip +group by cntrycode +order by cntrycode; +cntrycode numcust totacctbal +11 4 29942.58 +19 2 17120.35 +20 1 9091.82 +28 2 14755.5 +=== Q20 === +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 100.00 Using where; Using filesort +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +1 PRIMARY nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where +2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 100.00 Using where +2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 100.00 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where ((`dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey`) and (`dbt3_s001`.`nation`.`n_name` = 'UNITED STATES') and (`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((select (0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`)) from `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`) and (`dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date))) and (`dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>((cast('1993-01-01' as date) + interval '1' year))))))) and (`dbt3_s001`.`part`.`p_name` like 'g%')) order by `dbt3_s001`.`supplier`.`s_name` limit 10 +select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +s_name s_address +Supplier#000000010 Saygah3gYWMp72i PY +SELECT ((SELECT COUNT(*) FROM part WHERE p_name LIKE 'g%') / +(SELECT COUNT(*) FROM part)) AS sel; +sel +0.0600 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 4.17 Using where +2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 14.37 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where ((`dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey`) and (`dbt3_s001`.`nation`.`n_name` = 'UNITED STATES') and (`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((select (0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`)) from `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`) and (`dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date))) and (`dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>((cast('1993-01-01' as date) + interval '1' year))))))) and (`dbt3_s001`.`part`.`p_name` like 'g%')) order by `dbt3_s001`.`supplier`.`s_name` limit 10 +select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +s_name s_address +Supplier#000000010 Saygah3gYWMp72i PY +set histogram_size=127; +ANALYZE TABLE part PERSISTENT FOR COLUMNS(p_name) INDEXES(); +Table Op Msg_type Msg_text +dbt3_s001.part analyze status OK +flush table part; +set optimizer_use_condition_selectivity=4; +EXPLAIN EXTENDED select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 7.03 Using where +2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 14.37 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where ((`dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey`) and (`dbt3_s001`.`nation`.`n_name` = 'UNITED STATES') and (`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((select (0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`)) from `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`) and (`dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date))) and (`dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>((cast('1993-01-01' as date) + interval '1' year))))))) and (`dbt3_s001`.`part`.`p_name` like 'g%')) order by `dbt3_s001`.`supplier`.`s_name` limit 10 +select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +s_name s_address +Supplier#000000010 Saygah3gYWMp72i PY +set histogram_type='DOUBLE_PREC_HB'; +set histogram_size=126; +ANALYZE TABLE part PERSISTENT FOR COLUMNS(p_name) INDEXES(); +Table Op Msg_type Msg_text +dbt3_s001.part analyze status OK +flush table part; +EXPLAIN EXTENDED select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 7.81 Using where +2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 14.37 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where ((`dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey`) and (`dbt3_s001`.`nation`.`n_name` = 'UNITED STATES') and (`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((select (0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`)) from `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`) and (`dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date))) and (`dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>((cast('1993-01-01' as date) + interval '1' year))))))) and (`dbt3_s001`.`part`.`p_name` like 'g%')) order by `dbt3_s001`.`supplier`.`s_name` limit 10 +select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +s_name s_address +Supplier#000000010 Saygah3gYWMp72i PY +set histogram_type='SINGLE_PREC_HB'; +set histogram_size=24; +ANALYZE TABLE nation PERSISTENT FOR COLUMNS(n_name) INDEXES(); +Table Op Msg_type Msg_text +dbt3_s001.nation analyze status OK +flush table nation; +EXPLAIN EXTENDED select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 7.81 Using where +2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 14.37 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where ((`dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey`) and (`dbt3_s001`.`nation`.`n_name` = 'UNITED STATES') and (`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((select (0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`)) from `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`) and (`dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date))) and (`dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>((cast('1993-01-01' as date) + interval '1' year))))))) and (`dbt3_s001`.`part`.`p_name` like 'g%')) order by `dbt3_s001`.`supplier`.`s_name` limit 10 +select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +s_name s_address +Supplier#000000010 Saygah3gYWMp72i PY +DROP DATABASE dbt3_s001; +set histogram_type=@save_histogram_type; +set histogram_size=@save_histogram_size; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +use test; +# +# Bug mdev-4348: using view with use_condition_selectivity > 1 +# +set @tmp_use_stat_tables=@@use_stat_tables; +set use_stat_tables='never'; +set optimizer_use_condition_selectivity=3; +CREATE TABLE t1 (a int, b int); +INSERT t1 VALUES (7,1), (0,7); +CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1; +CREATE TABLE t2 (c int, d int, index idx(d)); +INSERT INTO t2 VALUES +(0,4), (8,6), (1,3), (8,5), (9,3), (2,2), (6,2), +(1,9), (6,3), (2,8), (4,1), (0,7), (4,8), (4,5); +EXPLAIN EXTENDED +SELECT * FROM v1 INNER JOIN t2 ON ( a = c AND b = d ); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +1 SIMPLE t2 ref idx idx 5 test.t1.b 1 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`c` = `test`.`t1`.`a`) and (`test`.`t2`.`d` = `test`.`t1`.`b`)) +SELECT * FROM v1 INNER JOIN t2 ON ( a = c AND b = d ); +a b c d +0 7 0 7 +DROP VIEW v1; +DROP TABLE t1,t2; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +set use_stat_tables=@tmp_use_stat_tables; +# +# Bug mdev-4349: impossible range for non-indexed column +# +set optimizer_use_condition_selectivity=3; +create table t1 (a int); +insert into t1 values +(3), (7), (2), (5), (7), (1), (2), (2); +set optimizer_use_condition_selectivity=1; +explain extended +select * from t1 where a < 1 and a > 7; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` < 1) and (`test`.`t1`.`a` > 7)) +select * from t1 where a < 1 and a > 7; +a +set optimizer_use_condition_selectivity=3; +explain extended +select * from t1 where a < 1 and a > 7; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where 0 +select * from t1 where a < 1 and a > 7; +a +drop table t1; +create table t1 (a int); +insert into t1 values (1); +create table t2 (b int); +insert into t2 values (2),(3); +explain extended +select * from t1 where a in ( select b from t2 ) AND ( a > 3 ); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 1 0.00 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 0 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`b` = `test`.`t1`.`a`) and (`test`.`t1`.`a` > 3)) +select * from t1 where a in ( select b from t2 ) AND ( a > 3 ); +a +drop table t1,t2; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +# +# Bug mdev-4350: erroneous negative selectivity +# +create table t1 (a int); +insert into t1 values (1), (1); +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 values (0); +select count(*) from t1; +count(*) +1025 +set use_stat_tables='preferably'; +set histogram_size=127; +set histogram_type='SINGLE_PREC_HB'; +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +flush table t1; +set optimizer_use_condition_selectivity=4; +explain extended select * from t1 where a=0; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 1025 49.61 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 0) +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: 2-way join with an empty 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; +# +# Bug mdev-4366: impossible condition on an indexed column discovered after +# substitution of constant tables +# with optimizer_use_condition_selectivity=3 +# +CREATE TABLE t1 (pk int PRIMARY KEY, a int); +INSERT INTO t1 VALUES +(1,4), (2,6), (3,3), (4,5); +CREATE TABLE t2 (b int); +INSERT INTO t2 VALUES (1), (7); +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED +SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select 1 AS `1` from `test`.`t1` join `test`.`t2` where 0 +SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10; +1 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED +SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select 1 AS `1` from `test`.`t1` join `test`.`t2` where 0 +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; +# +# Bug mdev-4371: Join with condition supported by index on an empty table +# with optimizer_use_condition_selectivity=3 +# +set use_stat_tables=PREFERABLY; +CREATE TABLE t1 (a int, b int, INDEX(a)); +CREATE TABLE t2 (c int); +INSERT INTO t2 VALUES (1),(2),(3),(4),(5),(6),(7),(8); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=3; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; +EXPLAIN EXTENDED +SELECT * FROM t1, t2 WHERE a > 9; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range a a 5 NULL 1 0.00 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 8 100.00 Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t1` join `test`.`t2` where (`test`.`t1`.`a` > 9) +SELECT * FROM t1, t2 WHERE a > 9; +a b c +set optimizer_switch=@save_optimizer_switch; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4373: condition on a short varchar column +# with optimizer_use_condition_selectivity=3 +# +set use_stat_tables=PREFERABLY; +CREATE TABLE t1 (a varchar(1)); +INSERT INTO t1 VALUES ('x'), ('y'); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=3; +SELECT * FROM t1 WHERE a <= 'w'; +a +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4372: exists subquery in WHERE +# with optimizer_use_condition_selectivity=3 +# +set use_stat_tables = PREFERABLY; +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES +(1),(7),(4),(7),(0),(2),(9),(4),(0),(9),(1),(3),(8),(8); +CREATE TABLE t2 (b int); +INSERT INTO t2 VALUES (4),(5),(2),(5),(1),(1),(2); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED +SELECT * FROM t1, t2 WHERE EXISTS ( SELECT 1 FROM t1, t2 ) AND a != b OR a <= 4; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 7 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 14 100.00 Using where; Using join buffer (flat, BNL join) +2 SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 14 100.00 Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where ((exists(select 1 from `test`.`t1` join `test`.`t2`) and (`test`.`t1`.`a` <> `test`.`t2`.`b`)) or (`test`.`t1`.`a` <= 4)) +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4363: selectivity of the condition a IS NULL OR IS NOT NULL +# with optimizer_use_condition_selectivity=3 +# +set use_stat_tables = PREFERABLY; +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES +(1),(7),(4),(7),(NULL),(2),(NULL),(4),(NULL),(NULL),(1),(3),(8),(8); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +FLUSH TABLE t1; +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a IS NULL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 14 28.57 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where isnull(`test`.`t1`.`a`) +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a IS NOT NULL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 14 71.43 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` is not null) +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a IS NULL OR a IS NOT NULL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 14 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (isnull(`test`.`t1`.`a`) or (`test`.`t1`.`a` is not null)) +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a IS NULL OR a < 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 14 69.39 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (isnull(`test`.`t1`.`a`) or (`test`.`t1`.`a` < 5)) +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4378: 2-way join with a materialized IN subquery in WHERE +# when optimizer_use_condition_selectivity=4 +# +set use_stat_tables=PREFERABLY; +set histogram_size=50; +set histogram_type=SINGLE_PREC_HB; +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (8),(9),(6); +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (8),(1),(8),(9),(24),(6),(1),(6),(2),(4); +CREATE TABLE t3 (ln VARCHAR(16)) ENGINE=MyISAM; +INSERT INTO t3 VALUES +('smith'),('black'),('white'),('jones'), +('brown'),('taylor'),('anderson'),('taylor'); +ANALYZE TABLE t1, t2, t3; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +test.t3 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=4; +SELECT * FROM t1, t2 WHERE 'garcia' IN ( SELECT MIN( ln ) FROM t3 WHERE ln = 'sun' ); +a b +set histogram_size=@save_histogram_size; +set histogram_type=@save_histogram_type; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2,t3; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4380: 2-way join with a materialized IN subquery in WHERE +# when optimizer_use_condition_selectivity=3 +# +set use_stat_tables=PREFERABLY; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (5),(9); +CREATE TABLE t2 (b VARCHAR(8)); +INSERT INTO t2 VALUES ('red'),('blue'); +CREATE TABLE t3 (c VARCHAR(8), d VARCHAR(8)); +INSERT INTO t3 VALUES ('white','black'),('cyan','yellow'); +ANALYZE TABLE t1, t2, t3; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +test.t3 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=3; +SELECT * FROM t1, t2 WHERE ( 'orange', 'green' ) IN ( +SELECT MAX(c), MAX(d) FROM t3, t2 WHERE c >= d AND b = c +); +a b +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2,t3; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4389: join with degenerated range condition in WHERE +# when optimizer_use_condition_selectivity=3 +# +set use_stat_tables=PREFERABLY; +CREATE TABLE t1 (f1 VARCHAR(1)); +INSERT t1 VALUES ('p'),('q'); +CREATE TABLE t2 (f2 VARCHAR(1)); +INSERT INTO t2 VALUES +('o'),('v'),('f'),('f'),('e'),('l'),('j'),('p'),('r'),('j'), +('j'),('u'),('i'),('r'),('x'),('a'),('x'),('s'); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +FLUSH TABLES; +SET optimizer_use_condition_selectivity=3; +SELECT * FROM t1, t2 AS t2a, t2 AS t2b WHERE f1 <= 'a' AND t2a.f2 = f1; +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; +set use_stat_tables=@save_use_stat_tables; +set optimizer_switch=@save_optimizer_switch_for_selectivity_test; +SET SESSION STORAGE_ENGINE=DEFAULT; diff --git a/mysql-test/r/statistics.result b/mysql-test/r/statistics.result index ba0390f98db..20469c01a2e 100644 --- a/mysql-test/r/statistics.result +++ b/mysql-test/r/statistics.result @@ -64,13 +64,13 @@ SELECT * FROM mysql.table_stats; db_name table_name cardinality test t1 40 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -87,8 +87,8 @@ COUNT(*) 40 SELECT * FROM mysql.column_stats WHERE db_name='test' AND table_name='t1' AND column_name='a'; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL SELECT MIN(t1.a), MAX(t1.a), (SELECT COUNT(*) FROM t1 WHERE t1.b IS NULL) / (SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.a)", @@ -99,8 +99,8 @@ MIN(t1.a) MAX(t1.a) NULLS_RATIO(t1.a) AVG_FREQUENCY(t1.a) 0 49 0.2000 1.0000 SELECT * FROM mysql.column_stats WHERE db_name='test' AND table_name='t1' AND column_name='b'; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL SELECT MIN(t1.b), MAX(t1.b), (SELECT COUNT(*) FROM t1 WHERE t1.b IS NULL) / (SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.b)", @@ -111,8 +111,8 @@ MIN(t1.b) MAX(t1.b) NULLS_RATIO(t1.b) AVG_FREQUENCY(t1.b) vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 6.4000 SELECT * FROM mysql.column_stats WHERE db_name='test' AND table_name='t1' AND column_name='c'; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL SELECT MIN(t1.c), MAX(t1.c), (SELECT COUNT(*) FROM t1 WHERE t1.c IS NULL) / (SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.c)", @@ -123,8 +123,8 @@ MIN(t1.c) MAX(t1.c) NULLS_RATIO(t1.c) AVG_FREQUENCY(t1.c) aaaa dddddddd 0.1250 7.0000 SELECT * FROM mysql.column_stats WHERE db_name='test' AND table_name='t1' AND column_name='d'; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL SELECT MIN(t1.d), MAX(t1.d), (SELECT COUNT(*) FROM t1 WHERE t1.d IS NULL) / (SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.d)", @@ -135,8 +135,8 @@ MIN(t1.d) MAX(t1.d) NULLS_RATIO(t1.d) AVG_FREQUENCY(t1.d) 1989-03-12 1999-07-23 0.1500 8.5000 SELECT * FROM mysql.column_stats WHERE db_name='test' AND table_name='t1' AND column_name='e'; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL SELECT MIN(t1.e), MAX(t1.e), (SELECT COUNT(*) FROM t1 WHERE t1.e IS NULL) / (SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.e)", @@ -206,6 +206,47 @@ WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL AND t1.d IS NOT NULL) AS 'ARITY 3'; ARITY 1 ARITY 2 ARITY 3 6.2000 1.6875 1.1304 +DELETE FROM mysql.column_stats; +set histogram_size=4; +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +SELECT db_name, table_name, column_name, +min_value, max_value, +nulls_ratio, avg_frequency, +hist_size, hist_type, HEX(histogram) +FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_frequency hist_size hist_type HEX(histogram) +test t1 a 0 49 0.0000 1.0000 4 SINGLE_PREC_HB 2E62A1D0 +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 6.4000 4 SINGLE_PREC_HB 003FBFFF +test t1 c aaaa dddddddd 0.1250 7.0000 4 SINGLE_PREC_HB 0055AAFF +test t1 d 1989-03-12 1999-07-23 0.1500 8.5000 4 SINGLE_PREC_HB 009393FF +test t1 e 0.01 0.112 0.2250 6.2000 4 SINGLE_PREC_HB 000564E1 +test t1 f 1 5 0.2000 6.4000 4 SINGLE_PREC_HB 3F7FBFBF +DELETE FROM mysql.column_stats; +set histogram_size=8; +set histogram_type='DOUBLE_PREC_HB'; +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +SELECT db_name, table_name, column_name, +min_value, max_value, +nulls_ratio, avg_frequency, +hist_size, hist_type, HEX(histogram) +FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_frequency hist_size hist_type HEX(histogram) +test t1 a 0 49 0.0000 1.0000 8 DOUBLE_PREC_HB 052F4363F4A1F9D0 +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 6.4000 8 DOUBLE_PREC_HB 0000FF3FFFBFFFFF +test t1 c aaaa dddddddd 0.1250 7.0000 8 DOUBLE_PREC_HB 00005555AAAAFFFF +test t1 d 1989-03-12 1999-07-23 0.1500 8.5000 8 DOUBLE_PREC_HB 000026942694FFFF +test t1 e 0.01 0.112 0.2250 6.2000 8 DOUBLE_PREC_HB 000005056464E1E1 +test t1 f 1 5 0.2000 6.4000 8 DOUBLE_PREC_HB FF3FFF7FFFBFFFBF +DELETE FROM mysql.column_stats; +set histogram_size= 0; +set histogram_type=default; +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date CREATE TABLE t3 ( a int NOT NULL PRIMARY KEY, b varchar(32), @@ -238,16 +279,16 @@ db_name table_name cardinality test t1 40 test t3 17 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 -test t3 a 0 38 0.0000 4.0000 1.0000 -test t3 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.1765 18.0714 2.8000 -test t3 c aaaa dddddddd 0.1176 6.4000 3.7500 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +test t3 a 0 38 0.0000 4.0000 1.0000 0 NULL NULL +test t3 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.1765 18.0714 2.8000 0 NULL NULL +test t3 c aaaa dddddddd 0.1176 6.4000 3.7500 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -267,16 +308,16 @@ db_name table_name cardinality test s1 40 test t3 17 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test s1 a 0 49 0.0000 4.0000 1.0000 -test s1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 -test s1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test s1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test s1 e 0.01 0.112 0.2250 8.0000 6.2000 -test s1 f 1 5 0.2000 1.0000 6.4000 -test t3 a 0 38 0.0000 4.0000 1.0000 -test t3 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.1765 18.0714 2.8000 -test t3 c aaaa dddddddd 0.1176 6.4000 3.7500 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test s1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test s1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test s1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test s1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test s1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test s1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +test t3 a 0 38 0.0000 4.0000 1.0000 0 NULL NULL +test t3 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.1765 18.0714 2.8000 0 NULL NULL +test t3 c aaaa dddddddd 0.1176 6.4000 3.7500 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test s1 PRIMARY 1 1.0000 @@ -296,16 +337,16 @@ db_name table_name cardinality test t1 40 test t3 17 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 -test t3 a 0 38 0.0000 4.0000 1.0000 -test t3 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.1765 18.0714 2.8000 -test t3 c aaaa dddddddd 0.1176 6.4000 3.7500 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +test t3 a 0 38 0.0000 4.0000 1.0000 0 NULL NULL +test t3 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.1765 18.0714 2.8000 0 NULL NULL +test t3 c aaaa dddddddd 0.1176 6.4000 3.7500 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -324,13 +365,13 @@ SELECT * FROM mysql.table_stats; db_name table_name cardinality test t1 40 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -365,13 +406,13 @@ t1 CREATE TABLE `t1` ( KEY `idx4` (`y`,`x`,`d`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 x vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 y 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 x vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 y 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL ALTER TABLE t1 CHANGE COLUMN x b varchar(32), CHANGE COLUMN y e double; SHOW CREATE TABLE t1; @@ -390,13 +431,13 @@ t1 CREATE TABLE `t1` ( KEY `idx4` (`e`,`b`,`d`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL ALTER TABLE t1 RENAME TO s1, CHANGE COLUMN b x varchar(32); SHOW CREATE TABLE s1; Table Create Table @@ -417,13 +458,13 @@ SELECT * FROM mysql.table_stats; db_name table_name cardinality test s1 40 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test s1 a 0 49 0.0000 4.0000 1.0000 -test s1 x vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 -test s1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test s1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test s1 e 0.01 0.112 0.2250 8.0000 6.2000 -test s1 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test s1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test s1 x vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test s1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test s1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test s1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test s1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test s1 PRIMARY 1 1.0000 @@ -455,13 +496,13 @@ SELECT * FROM mysql.table_stats; db_name table_name cardinality test t1 40 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -490,12 +531,12 @@ t1 CREATE TABLE `t1` ( KEY `idx4` (`e`,`x`,`d`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -519,12 +560,12 @@ t1 CREATE TABLE `t1` ( KEY `idx4` (`e`,`b`,`d`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -535,13 +576,13 @@ ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx4); Table Op Msg_type Msg_text test.t1 analyze status OK SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -576,12 +617,12 @@ t1 CREATE TABLE `t1` ( KEY `idx4` (`e`,`x`,`d`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -605,12 +646,12 @@ t1 CREATE TABLE `t1` ( KEY `idx4` (`e`,`b`,`d`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -624,13 +665,13 @@ LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/save_index_stats' INTO TABLE mysql.index_stats FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'; SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -658,12 +699,12 @@ t1 CREATE TABLE `t1` ( KEY `idx4` (`e`,`d`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -721,12 +762,12 @@ t1 CREATE TABLE `t1` ( KEY `idx4` (`e`,`b`,`d`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -735,13 +776,13 @@ ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx2, idx4); Table Op Msg_type Msg_text test.t1 analyze status OK SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 b NULL NULL 1.0000 NULL NULL -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b NULL NULL 1.0000 NULL NULL 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -758,13 +799,13 @@ ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx2, idx4); Table Op Msg_type Msg_text test.t1 analyze status OK SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -790,12 +831,12 @@ t1 CREATE TABLE `t1` ( KEY `idx3` (`d`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -820,12 +861,12 @@ t1 CREATE TABLE `t1` ( KEY `idx4` (`e`,`b`,`d`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -834,13 +875,13 @@ ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx2, idx4); Table Op Msg_type Msg_text test.t1 analyze status OK SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -862,7 +903,7 @@ SELECT * FROM mysql.table_stats; db_name table_name cardinality test t1 40 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(c,e,b) INDEXES(idx2,idx4); @@ -872,10 +913,10 @@ SELECT * FROM mysql.table_stats; db_name table_name cardinality test t1 40 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 idx2 1 7.0000 @@ -912,13 +953,13 @@ SELECT * FROM mysql.table_stats; db_name table_name cardinality test t1 40 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 -test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -942,19 +983,19 @@ db_name table_name cardinality test t1 40 test t2 40 SELECT * FROM mysql.column_stats ORDER BY column_name; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t2 a 0 49 0.0000 4.0000 1.0000 -test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 -test t2 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t2 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t2 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t2 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 -test t2 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t2 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t2 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t2 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t2 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t2 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +test t2 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -986,13 +1027,13 @@ SELECT * FROM mysql.table_stats; db_name table_name cardinality test t2 40 SELECT * FROM mysql.column_stats ORDER BY column_name; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t2 a 0 49 0.0000 4.0000 1.0000 -test t2 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 -test t2 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t2 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t2 e 0.01 0.112 0.2250 8.0000 6.2000 -test t2 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t2 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t2 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t2 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t2 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t2 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t2 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name; db_name table_name index_name prefix_arity avg_frequency test t2 PRIMARY 1 1.0000 @@ -1122,12 +1163,12 @@ MODIFY COLUMN b text, ADD INDEX idx1 (b(4), e), ADD INDEX idx4 (e, b(4), d); SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t2 a 0 49 0.0000 4.0000 1.0000 -test t2 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t2 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t2 e 0.01 0.112 0.2250 8.0000 6.2000 -test t2 f 1 5 0.2000 1.0000 6.4000 +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t2 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t2 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t2 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t2 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t2 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t2 idx3 1 8.5000 @@ -1143,18 +1184,18 @@ ANALYZE TABLE t1; Table Op Msg_type Msg_text test.t1 analyze status OK SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t2 a 0 49 0.0000 4.0000 1.0000 -test t2 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t2 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t2 e 0.01 0.112 0.2250 8.0000 6.2000 -test t2 f 1 5 0.2000 1.0000 6.4000 -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 -test t1 b NULL NULL 0.2000 17.1250 NULL +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t2 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t2 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t2 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t2 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t2 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +test t1 b NULL NULL 0.2000 17.1250 NULL NULL NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t2 idx3 1 8.5000 @@ -1187,7 +1228,7 @@ mysql.column_stats analyze status OK SELECT * FROM mysql.table_stats; db_name table_name cardinality SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency set use_stat_tables='never'; @@ -1198,13 +1239,13 @@ SELECT * FROM mysql.table_stats; db_name table_name cardinality test t1 40 SELECT * FROM mysql.column_stats; -db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency -test t1 a 0 49 0.0000 4.0000 1.0000 -test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 -test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 -test t1 e 0.01 0.112 0.2250 8.0000 6.2000 -test t1 f 1 5 0.2000 1.0000 6.4000 -test t1 b NULL NULL 0.2000 17.1250 NULL +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +test t1 b NULL NULL 0.2000 17.1250 NULL NULL NULL NULL SELECT * FROM mysql.index_stats; db_name table_name index_name prefix_arity avg_frequency test t1 PRIMARY 1 1.0000 @@ -1426,4 +1467,87 @@ UPPER(db_name) UPPER(table_name) index_name prefix_arity avg_frequency DELETE FROM mysql.table_stats; DELETE FROM mysql.column_stats; DELETE FROM mysql.index_stats; +# +# Bug mdev-4357: empty string as a value of the HIST_SIZE column +# from mysql.column_stats +# +create table t1 (a int); +insert into t1 values (1),(2),(3); +set histogram_size=10; +analyze table t1 persistent for all; +Table Op Msg_type Msg_text +test.t1 analyze status OK +select db_name, table_name, column_name, +min_value, max_value, +nulls_ratio, avg_frequency, +hist_size, hist_type, HEX(histogram) +FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_frequency hist_size hist_type HEX(histogram) +test t1 a 1 3 0.0000 1.0000 10 SINGLE_PREC_HB 0000007F7F7F7FFFFFFF +set histogram_size=default; +drop table t1; +# +# Bug mdev-4359: wrong setting of the HIST_SIZE column +# (see also mdev-4357) from mysql.column_stats +# +create table t1 ( a int); +insert into t1 values (1),(2),(3),(4),(5); +set histogram_size=10; +set histogram_type='double_prec_hb'; +show variables like 'histogram%'; +Variable_name Value +histogram_size 10 +histogram_type DOUBLE_PREC_HB +analyze table t1 persistent for all; +Table Op Msg_type Msg_text +test.t1 analyze status OK +select db_name, table_name, column_name, +min_value, max_value, +nulls_ratio, avg_frequency, +hist_size, hist_type, HEX(histogram) +FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_frequency hist_size hist_type HEX(histogram) +test t1 a 1 5 0.0000 1.0000 10 DOUBLE_PREC_HB 0000FF3FFF7FFFBFFFFF +set histogram_size=default; +set histogram_type=default; +drop table t1; +# +# Bug mdev-4369: histogram for a column with many distinct values +# +CREATE TABLE t1 (id int); +CREATE TABLE t2 (id int); +INSERT INTO t1 (id) VALUES (1), (1), (1),(1); +INSERT INTO t1 (id) SELECT id FROM t1; +INSERT INTO t1 SELECT id+1 FROM t1; +INSERT INTO t1 SELECT id+2 FROM t1; +INSERT INTO t1 SELECT id+4 FROM t1; +INSERT INTO t1 SELECT id+8 FROM t1; +INSERT INTO t1 SELECT id+16 FROM t1; +INSERT INTO t1 SELECT id+32 FROM t1; +INSERT INTO t1 SELECT id+64 FROM t1; +INSERT INTO t1 SELECT id+128 FROM t1; +INSERT INTO t1 SELECT id+256 FROM t1; +INSERT INTO t1 SELECT id+512 FROM t1; +INSERT INTO t2 SELECT id FROM t1 ORDER BY id*rand(); +SELECT COUNT(*) FROM t2; +COUNT(*) +8192 +SELECT COUNT(DISTINCT id) FROM t2; +COUNT(DISTINCT id) +1024 +set @@tmp_table_size=1024*16; +set @@max_heap_table_size=1024*16; +set histogram_size=63; +analyze table t2 persistent for all; +Table Op Msg_type Msg_text +test.t2 analyze status OK +select db_name, table_name, column_name, +min_value, max_value, +nulls_ratio, avg_frequency, +hist_size, hist_type, HEX(histogram) +FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_frequency hist_size hist_type HEX(histogram) +test t2 id 1 1024 0.0000 8.0000 63 SINGLE_PREC_HB 03070B0F13171B1F23272B2F33373B3F43474B4F53575B5F63676B6F73777B7F83878B8F93979B9FA3A7ABAFB3B7BBBFC3C7CBCFD3D7DBDFE3E7EBEFF3F7FB +set histogram_size=default; +drop table t1, t2; set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/r/subselect_sj_mat.result b/mysql-test/r/subselect_sj_mat.result index 717d6832415..549282c9dbe 100644 --- a/mysql-test/r/subselect_sj_mat.result +++ b/mysql-test/r/subselect_sj_mat.result @@ -94,7 +94,7 @@ a1 a2 explain extended select * from t1i where a1 in (select b1 from t2i where b1 > '0'); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2i index it2i1,it2i3 it2i1 # NULL 5 50.00 Using where; Using index; LooseScan +1 PRIMARY t2i index it2i1,it2i3 it2i1 # NULL 5 40.00 Using where; Using index; LooseScan 1 PRIMARY t1i ref _it1_idx _it1_idx # _ref_ 1 100.00 Warnings: Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) where ((`test`.`t1i`.`a1` = `test`.`t2i`.`b1`) and (`test`.`t2i`.`b1` > '0')) @@ -117,7 +117,7 @@ a1 a2 explain extended select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0'); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2i index it2i1,it2i2,it2i3 it2i3 # NULL 5 50.00 Using where; Using index; LooseScan +1 PRIMARY t2i index it2i1,it2i2,it2i3 it2i3 # NULL 5 40.00 Using where; Using index; LooseScan 1 PRIMARY t1i ref _it1_idx _it1_idx # _ref_ 1 100.00 Warnings: Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) where ((`test`.`t1i`.`a1` = `test`.`t2i`.`b1`) and (`test`.`t1i`.`a2` = `test`.`t2i`.`b2`) and (`test`.`t2i`.`b1` > '0')) @@ -319,7 +319,7 @@ where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and (a1, a2) in (select c1, c2 from t3i where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2i index it2i1,it2i2,it2i3 # # # 5 50.00 # +1 PRIMARY t2i index it2i1,it2i2,it2i3 # # # 5 40.00 # 1 PRIMARY t1i ref it1i1,it1i2,it1i3 # # # 1 100.00 # 1 PRIMARY t3i ref it3i1,it3i2,it3i3 # # # 1 100.00 # 1 PRIMARY t2i ref it2i1,it2i2,it2i3 # # # 2 100.00 # @@ -407,7 +407,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 MATERIALIZED t2 ALL NULL # # # 5 100.00 # 4 MATERIALIZED t3 ALL NULL # # # 4 100.00 # 3 MATERIALIZED t3 ALL NULL # # # 4 100.00 # -7 UNION t2i index it2i1,it2i2,it2i3 # # # 5 50.00 # +7 UNION t2i index it2i1,it2i2,it2i3 # # # 5 40.00 # 7 UNION t1i ref it1i1,it1i2,it1i3 # # # 1 100.00 # 7 UNION t3i ref it3i1,it3i2,it3i3 # # # 1 100.00 # 7 UNION t2i ref it2i1,it2i2,it2i3 # # # 2 100.00 # diff --git a/mysql-test/r/system_mysql_db.result b/mysql-test/r/system_mysql_db.result index dddd549c48f..f481f981aba 100644 --- a/mysql-test/r/system_mysql_db.result +++ b/mysql-test/r/system_mysql_db.result @@ -292,6 +292,9 @@ column_stats CREATE TABLE `column_stats` ( `nulls_ratio` decimal(12,4) DEFAULT NULL, `avg_length` decimal(12,4) DEFAULT NULL, `avg_frequency` decimal(12,4) DEFAULT NULL, + `hist_size` tinyint(3) unsigned DEFAULT NULL, + `hist_type` enum('SINGLE_PREC_HB','DOUBLE_PREC_HB') COLLATE utf8_bin DEFAULT NULL, + `histogram` varbinary(255) DEFAULT NULL, PRIMARY KEY (`db_name`,`table_name`,`column_name`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Columns' show create table index_stats; diff --git a/mysql-test/suite/funcs_1/r/is_columns_mysql.result b/mysql-test/suite/funcs_1/r/is_columns_mysql.result index c1e13d0791b..e8782890e0c 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_mysql.result +++ b/mysql-test/suite/funcs_1/r/is_columns_mysql.result @@ -13,6 +13,9 @@ def mysql column_stats avg_frequency 8 NULL YES decimal NULL NULL 12 4 NULL NULL def mysql column_stats avg_length 7 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) select,insert,update,references def mysql column_stats column_name 3 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references def mysql column_stats db_name 1 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI select,insert,update,references +def mysql column_stats histogram 11 NULL YES varbinary 255 255 NULL NULL NULL NULL NULL varbinary(255) select,insert,update,references +def mysql column_stats hist_size 9 NULL YES tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned select,insert,update,references +def mysql column_stats hist_type 10 NULL YES enum 14 42 NULL NULL NULL utf8 utf8_bin enum('SINGLE_PREC_HB','DOUBLE_PREC_HB') select,insert,update,references def mysql column_stats max_value 5 NULL YES varchar 255 765 NULL NULL NULL utf8 utf8_bin varchar(255) select,insert,update,references def mysql column_stats min_value 4 NULL YES varchar 255 765 NULL NULL NULL utf8 utf8_bin varchar(255) select,insert,update,references def mysql column_stats nulls_ratio 6 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) select,insert,update,references @@ -304,6 +307,7 @@ ORDER BY CHARACTER_SET_NAME, COLLATION_NAME, COL_CML; COL_CML DATA_TYPE CHARACTER_SET_NAME COLLATION_NAME 1.0000 blob NULL NULL 1.0000 longblob NULL NULL +1.0000 varbinary NULL NULL 1.0000 char latin1 latin1_bin 1.0000 char latin1 latin1_swedish_ci 1.0000 varchar latin1 latin1_swedish_ci @@ -377,6 +381,9 @@ NULL mysql columns_priv Timestamp timestamp NULL NULL NULL NULL timestamp NULL mysql column_stats nulls_ratio decimal NULL NULL NULL NULL decimal(12,4) NULL mysql column_stats avg_length decimal NULL NULL NULL NULL decimal(12,4) NULL mysql column_stats avg_frequency decimal NULL NULL NULL NULL decimal(12,4) +NULL mysql column_stats hist_size tinyint NULL NULL NULL NULL tinyint(3) unsigned +3.0000 mysql column_stats hist_type enum 14 42 utf8 utf8_bin enum('SINGLE_PREC_HB','DOUBLE_PREC_HB') +1.0000 mysql column_stats histogram varbinary 255 255 NULL NULL varbinary(255) 3.0000 mysql db Host char 60 180 utf8 utf8_bin char(60) 3.0000 mysql db Db char 64 192 utf8 utf8_bin char(64) 3.0000 mysql db User char 16 48 utf8 utf8_bin char(16) diff --git a/mysql-test/suite/funcs_1/r/is_columns_mysql_embedded.result b/mysql-test/suite/funcs_1/r/is_columns_mysql_embedded.result index 32852b527d1..c3d718ea7d6 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_mysql_embedded.result +++ b/mysql-test/suite/funcs_1/r/is_columns_mysql_embedded.result @@ -13,6 +13,9 @@ def mysql column_stats avg_frequency 8 NULL YES decimal NULL NULL 12 4 NULL NULL def mysql column_stats avg_length 7 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) def mysql column_stats column_name 3 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI def mysql column_stats db_name 1 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_bin varchar(64) PRI +def mysql column_stats histogram 11 NULL YES varbinary 255 255 NULL NULL NULL NULL NULL varbinary(255) +def mysql column_stats hist_size 9 NULL YES tinyint NULL NULL 3 0 NULL NULL NULL tinyint(3) unsigned +def mysql column_stats hist_type 10 NULL YES enum 14 42 NULL NULL NULL utf8 utf8_bin enum('SINGLE_PREC_HB','DOUBLE_PREC_HB') def mysql column_stats max_value 5 NULL YES varchar 255 765 NULL NULL NULL utf8 utf8_bin varchar(255) def mysql column_stats min_value 4 NULL YES varchar 255 765 NULL NULL NULL utf8 utf8_bin varchar(255) def mysql column_stats nulls_ratio 6 NULL YES decimal NULL NULL 12 4 NULL NULL NULL decimal(12,4) @@ -304,6 +307,7 @@ ORDER BY CHARACTER_SET_NAME, COLLATION_NAME, COL_CML; COL_CML DATA_TYPE CHARACTER_SET_NAME COLLATION_NAME 1.0000 blob NULL NULL 1.0000 longblob NULL NULL +1.0000 varbinary NULL NULL 1.0000 char latin1 latin1_bin 1.0000 char latin1 latin1_swedish_ci 1.0000 varchar latin1 latin1_swedish_ci @@ -377,6 +381,9 @@ NULL mysql columns_priv Timestamp timestamp NULL NULL NULL NULL timestamp NULL mysql column_stats nulls_ratio decimal NULL NULL NULL NULL decimal(12,4) NULL mysql column_stats avg_length decimal NULL NULL NULL NULL decimal(12,4) NULL mysql column_stats avg_frequency decimal NULL NULL NULL NULL decimal(12,4) +NULL mysql column_stats hist_size tinyint NULL NULL NULL NULL tinyint(3) unsigned +3.0000 mysql column_stats hist_type enum 14 42 utf8 utf8_bin enum('SINGLE_PREC_HB','DOUBLE_PREC_HB') +1.0000 mysql column_stats histogram varbinary 255 255 NULL NULL varbinary(255) 3.0000 mysql db Host char 60 180 utf8 utf8_bin char(60) 3.0000 mysql db Db char 64 192 utf8 utf8_bin char(64) 3.0000 mysql db User char 16 48 utf8 utf8_bin char(16) diff --git a/mysql-test/suite/innodb/t/innodb_bug51920.test b/mysql-test/suite/innodb/t/innodb_bug51920.test index 0d4715712b0..c83e00db22a 100644 --- a/mysql-test/suite/innodb/t/innodb_bug51920.test +++ b/mysql-test/suite/innodb/t/innodb_bug51920.test @@ -36,7 +36,7 @@ let $wait_condition = # depending on platform. # connection con1; --- error 1317, 2006, 2013 +-- error 1317, 2006, 2013, ER_CONNECTION_KILLED reap; connection default; DROP TABLE bug51920; diff --git a/mysql-test/suite/sys_vars/r/histogram_size_basic.result b/mysql-test/suite/sys_vars/r/histogram_size_basic.result new file mode 100644 index 00000000000..1f310600d00 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/histogram_size_basic.result @@ -0,0 +1,136 @@ +SET @start_global_value = @@global.histogram_size; +SELECT @start_global_value; +@start_global_value +0 +SET @start_session_value = @@session.histogram_size; +SELECT @start_session_value; +@start_session_value +0 +'#--------------------FN_DYNVARS_053_01-------------------------#' +SET @@global.histogram_size = DEFAULT; +SELECT @@global.histogram_size; +@@global.histogram_size +0 +SET @@session.histogram_size = DEFAULT; +SELECT @@session.histogram_size; +@@session.histogram_size +0 +'#--------------------FN_DYNVARS_053_03-------------------------#' +SET @@global.histogram_size = 1; +SELECT @@global.histogram_size; +@@global.histogram_size +1 +SET @@global.histogram_size = 31; +SELECT @@global.histogram_size; +@@global.histogram_size +31 +SET @@global.histogram_size = 255; +SELECT @@global.histogram_size; +@@global.histogram_size +255 +'#--------------------FN_DYNVARS_053_04-------------------------#' +SET @@session.histogram_size = 1; +SELECT @@session.histogram_size; +@@session.histogram_size +1 +SET @@session.histogram_size = 31; +SELECT @@session.histogram_size; +@@session.histogram_size +31 +SET @@session.histogram_size = 255; +SELECT @@session.histogram_size; +@@session.histogram_size +255 +'#------------------FN_DYNVARS_053_05-----------------------#' +SET @@global.histogram_size = -1; +Warnings: +Warning 1292 Truncated incorrect histogram_size value: '-1' +SELECT @@global.histogram_size; +@@global.histogram_size +0 +SET @@global.histogram_size = 256; +Warnings: +Warning 1292 Truncated incorrect histogram_size value: '256' +SELECT @@global.histogram_size; +@@global.histogram_size +255 +SET @@global.histogram_size = 1024; +Warnings: +Warning 1292 Truncated incorrect histogram_size value: '1024' +SELECT @@global.histogram_size; +@@global.histogram_size +255 +SET @@global.histogram_size = 4.5; +ERROR 42000: Incorrect argument type to variable 'histogram_size' +SELECT @@global.histogram_size; +@@global.histogram_size +255 +SET @@global.histogram_size = test; +ERROR 42000: Incorrect argument type to variable 'histogram_size' +SELECT @@global.histogram_size; +@@global.histogram_size +255 +SET @@session.histogram_size = -1; +Warnings: +Warning 1292 Truncated incorrect histogram_size value: '-1' +SELECT @@session.histogram_size; +@@session.histogram_size +0 +SET @@session.histogram_size = 256; +Warnings: +Warning 1292 Truncated incorrect histogram_size value: '256' +SELECT @@session.histogram_size; +@@session.histogram_size +255 +SET @@session.histogram_size = 1024; +Warnings: +Warning 1292 Truncated incorrect histogram_size value: '1024' +SELECT @@session.histogram_size; +@@session.histogram_size +255 +SET @@session.histogram_size = 4.5; +ERROR 42000: Incorrect argument type to variable 'histogram_size' +SELECT @@session.histogram_size; +@@session.histogram_size +255 +SET @@session.histogram_size = test; +ERROR 42000: Incorrect argument type to variable 'histogram_size' +SELECT @@session.histogram_size; +@@session.histogram_size +255 +'#------------------FN_DYNVARS_053_06-----------------------#' +SELECT @@global.histogram_size = VARIABLE_VALUE +FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES +WHERE VARIABLE_NAME='histogram_size'; +@@global.histogram_size = VARIABLE_VALUE +1 +'#------------------FN_DYNVARS_053_07-----------------------#' +SELECT @@session.histogram_size = VARIABLE_VALUE +FROM INFORMATION_SCHEMA.SESSION_VARIABLES +WHERE VARIABLE_NAME='histogram_size'; +@@session.histogram_size = VARIABLE_VALUE +1 +'#------------------FN_DYNVARS_053_08-----------------------#' +SET @@global.histogram_size = TRUE; +SET @@global.histogram_size = FALSE; +'#---------------------FN_DYNVARS_001_09----------------------#' +SET @@global.histogram_size = 10; +SELECT @@histogram_size = @@global.histogram_size; +@@histogram_size = @@global.histogram_size +0 +'#---------------------FN_DYNVARS_001_10----------------------#' +SET @@histogram_size = 100; +SELECT @@histogram_size = @@local.histogram_size; +@@histogram_size = @@local.histogram_size +1 +SELECT @@local.histogram_size = @@session.histogram_size; +@@local.histogram_size = @@session.histogram_size +1 +SET @@global.histogram_size = @start_global_value; +SELECT @@global.histogram_size; +@@global.histogram_size +0 +SET @@session.histogram_size = @start_session_value; +SELECT @@session.histogram_size; +@@session.histogram_size +0 diff --git a/mysql-test/suite/sys_vars/r/histogram_type_basic.result b/mysql-test/suite/sys_vars/r/histogram_type_basic.result new file mode 100644 index 00000000000..f688a2a15fd --- /dev/null +++ b/mysql-test/suite/sys_vars/r/histogram_type_basic.result @@ -0,0 +1,79 @@ +SET @start_global_value = @@global.histogram_type; +SELECT @start_global_value; +@start_global_value +SINGLE_PREC_HB +SET @start_session_value = @@session.histogram_type; +SELECT @start_session_value; +@start_session_value +SINGLE_PREC_HB +SET @@global.histogram_type = 1; +SET @@global.histogram_type = DEFAULT; +SELECT @@global.histogram_type; +@@global.histogram_type +SINGLE_PREC_HB +SET @@global.histogram_type = 0; +SELECT @@global.histogram_type; +@@global.histogram_type +SINGLE_PREC_HB +SET @@global.histogram_type = 1; +SELECT @@global.histogram_type; +@@global.histogram_type +DOUBLE_PREC_HB +SET @@global.histogram_type = SINGLE_PREC_HB; +SELECT @@global.histogram_type; +@@global.histogram_type +SINGLE_PREC_HB +SET @@global.histogram_type = DOUBLE_PREC_HB; +SELECT @@global.histogram_type; +@@global.histogram_type +DOUBLE_PREC_HB +SET @@session.histogram_type = 0; +SELECT @@session.histogram_type; +@@session.histogram_type +SINGLE_PREC_HB +SET @@session.histogram_type = 1; +SELECT @@session.histogram_type; +@@session.histogram_type +DOUBLE_PREC_HB +SET @@session.histogram_type = SINGLE_PREC_HB; +SELECT @@session.histogram_type; +@@session.histogram_type +SINGLE_PREC_HB +SET @@session.histogram_type = DOUBLE_PREC_HB; +SELECT @@session.histogram_type; +@@session.histogram_type +DOUBLE_PREC_HB +set sql_mode=TRADITIONAL; +SET @@global.histogram_type = 10; +ERROR 42000: Variable 'histogram_type' can't be set to the value of '10' +SET @@global.histogram_type = -1024; +ERROR 42000: Variable 'histogram_type' can't be set to the value of '-1024' +SET @@global.histogram_type = 2.4; +ERROR 42000: Incorrect argument type to variable 'histogram_type' +SET @@global.histogram_type = OFF; +ERROR 42000: Variable 'histogram_type' can't be set to the value of 'OFF' +SET @@session.histogram_type = 10; +ERROR 42000: Variable 'histogram_type' can't be set to the value of '10' +SET @@session.histogram_type = -2; +ERROR 42000: Variable 'histogram_type' can't be set to the value of '-2' +SET @@session.histogram_type = 1.2; +ERROR 42000: Incorrect argument type to variable 'histogram_type' +SET @@session.histogram_type = ON; +ERROR 42000: Variable 'histogram_type' can't be set to the value of 'ON' +SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES +WHERE VARIABLE_NAME='histogram_type'; +VARIABLE_NAME VARIABLE_VALUE +HISTOGRAM_TYPE DOUBLE_PREC_HB +SELECT * FROM INFORMATION_SCHEMA.SESSION_VARIABLES +WHERE VARIABLE_NAME='histogram_type'; +VARIABLE_NAME VARIABLE_VALUE +HISTOGRAM_TYPE DOUBLE_PREC_HB +SET @@global.histogram_type = @start_global_value; +SELECT @@global.histogram_type; +@@global.histogram_type +SINGLE_PREC_HB +SET @@session.histogram_type = @start_session_value; +SELECT @@session.histogram_type; +@@session.histogram_type +SINGLE_PREC_HB +set sql_mode=''; diff --git a/mysql-test/suite/sys_vars/r/optimizer_use_condition_selectivity_basic.result b/mysql-test/suite/sys_vars/r/optimizer_use_condition_selectivity_basic.result new file mode 100644 index 00000000000..418c221b5aa --- /dev/null +++ b/mysql-test/suite/sys_vars/r/optimizer_use_condition_selectivity_basic.result @@ -0,0 +1,109 @@ +SET @start_global_value = @@global.optimizer_use_condition_selectivity; +SELECT @start_global_value; +@start_global_value +1 +SET @start_session_value = @@session.optimizer_use_condition_selectivity; +SELECT @start_session_value; +@start_session_value +1 +'#--------------------FN_DYNVARS_115_01-------------------------#' +SET @@global.optimizer_use_condition_selectivity = DEFAULT; +SELECT @@global.optimizer_use_condition_selectivity; +@@global.optimizer_use_condition_selectivity +1 +SET @@session.optimizer_use_condition_selectivity = DEFAULT; +SELECT @@session.optimizer_use_condition_selectivity; +@@session.optimizer_use_condition_selectivity +1 +'#--------------------FN_DYNVARS_115_02-------------------------#' +SET @@global.optimizer_use_condition_selectivity = DEFAULT; +SELECT @@global.optimizer_use_condition_selectivity = 1; +@@global.optimizer_use_condition_selectivity = 1 +1 +SET @@session.optimizer_use_condition_selectivity = DEFAULT; +SELECT @@session.optimizer_use_condition_selectivity = 1; +@@session.optimizer_use_condition_selectivity = 1 +1 +'#--------------------FN_DYNVARS_115_03-------------------------#' +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 +1 +SET @@global.optimizer_use_condition_selectivity = 2; +SELECT @@global.optimizer_use_condition_selectivity; +@@global.optimizer_use_condition_selectivity +2 +SET @@global.optimizer_use_condition_selectivity = 3; +SELECT @@global.optimizer_use_condition_selectivity; +@@global.optimizer_use_condition_selectivity +3 +SET @@global.optimizer_use_condition_selectivity = 4; +SELECT @@global.optimizer_use_condition_selectivity; +@@global.optimizer_use_condition_selectivity +4 +'#--------------------FN_DYNVARS_115_04-------------------------#' +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 +1 +SET @@session.optimizer_use_condition_selectivity = 2; +SELECT @@session.optimizer_use_condition_selectivity; +@@session.optimizer_use_condition_selectivity +2 +SET @@session.optimizer_use_condition_selectivity = 3; +SELECT @@session.optimizer_use_condition_selectivity; +@@session.optimizer_use_condition_selectivity +3 +SET @@session.optimizer_use_condition_selectivity = 4; +SELECT @@session.optimizer_use_condition_selectivity; +@@session.optimizer_use_condition_selectivity +4 +'#------------------FN_DYNVARS_115_05-----------------------#' +SET @@global.optimizer_use_condition_selectivity = ON; +ERROR 42000: Incorrect argument type to variable 'optimizer_use_condition_selectivity' +SET @@global.optimizer_use_condition_selectivity = OFF; +ERROR 42000: Incorrect argument type to variable 'optimizer_use_condition_selectivity' +SET @@session.optimizer_use_condition_selectivity = 65530.34; +ERROR 42000: Incorrect argument type to variable 'optimizer_use_condition_selectivity' +SET @@session.optimizer_use_condition_selectivity = test; +ERROR 42000: Incorrect argument type to variable 'optimizer_use_condition_selectivity' +'#------------------FN_DYNVARS_115_06-----------------------#' +SELECT @@global.optimizer_use_condition_selectivity = VARIABLE_VALUE +FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES +WHERE VARIABLE_NAME='optimizer_use_condition_selectivity'; +@@global.optimizer_use_condition_selectivity = VARIABLE_VALUE +1 +'#------------------FN_DYNVARS_115_07-----------------------#' +SELECT @@session.optimizer_use_condition_selectivity = VARIABLE_VALUE +FROM INFORMATION_SCHEMA.SESSION_VARIABLES +WHERE VARIABLE_NAME='optimizer_use_condition_selectivity'; +@@session.optimizer_use_condition_selectivity = VARIABLE_VALUE +1 +'#---------------------FN_DYNVARS_115_08----------------------#' +SET @@optimizer_use_condition_selectivity = 1; +SET @@global.optimizer_use_condition_selectivity = 3; +SELECT @@optimizer_use_condition_selectivity = @@global.optimizer_use_condition_selectivity; +@@optimizer_use_condition_selectivity = @@global.optimizer_use_condition_selectivity +0 +'#---------------------FN_DYNVARS_115_09----------------------#' +SET @@optimizer_use_condition_selectivity = 2; +SELECT @@optimizer_use_condition_selectivity = @@local.optimizer_use_condition_selectivity; +@@optimizer_use_condition_selectivity = @@local.optimizer_use_condition_selectivity +1 +SELECT @@local.optimizer_use_condition_selectivity = @@session.optimizer_use_condition_selectivity; +@@local.optimizer_use_condition_selectivity = @@session.optimizer_use_condition_selectivity +1 +SET @@global.optimizer_use_condition_selectivity = @start_global_value; +SELECT @@global.optimizer_use_condition_selectivity; +@@global.optimizer_use_condition_selectivity +1 +SET @@session.optimizer_use_condition_selectivity = @start_session_value; +SELECT @@session.optimizer_use_condition_selectivity; +@@session.optimizer_use_condition_selectivity +1 diff --git a/mysql-test/suite/sys_vars/t/histogram_size_basic.test b/mysql-test/suite/sys_vars/t/histogram_size_basic.test new file mode 100644 index 00000000000..d65936e3616 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/histogram_size_basic.test @@ -0,0 +1,142 @@ +--source include/load_sysvars.inc + +############################################################## +# START OF histogram_size TESTS # +############################################################## + + +############################################################# +# Save initial value # +############################################################# + +SET @start_global_value = @@global.histogram_size; +SELECT @start_global_value; +SET @start_session_value = @@session.histogram_size; +SELECT @start_session_value; + +--echo '#--------------------FN_DYNVARS_053_01-------------------------#' +################################################################ +# Display the DEFAULT value of histogram_size # +################################################################ + +SET @@global.histogram_size = DEFAULT; +SELECT @@global.histogram_size; + +SET @@session.histogram_size = DEFAULT; +SELECT @@session.histogram_size; + +--echo '#--------------------FN_DYNVARS_053_03-------------------------#' +######################################################################## +# Change the value of histogram_size to a valid value for GLOBAL Scope # +######################################################################## + +SET @@global.histogram_size = 1; +SELECT @@global.histogram_size; +SET @@global.histogram_size = 31; +SELECT @@global.histogram_size; +SET @@global.histogram_size = 255; +SELECT @@global.histogram_size; + +--echo '#--------------------FN_DYNVARS_053_04-------------------------#' +######################################################################### +# Change the value of histogram_size to a valid value for SESSION Scope # +######################################################################### + +SET @@session.histogram_size = 1; +SELECT @@session.histogram_size; +SET @@session.histogram_size = 31; +SELECT @@session.histogram_size; +SET @@session.histogram_size = 255; +SELECT @@session.histogram_size; + +--echo '#------------------FN_DYNVARS_053_05-----------------------#' +########################################################## +# Change the value of histogram_size to an invalid value # +########################################################### + +SET @@global.histogram_size = -1; +SELECT @@global.histogram_size; +SET @@global.histogram_size = 256; +SELECT @@global.histogram_size; +SET @@global.histogram_size = 1024; +SELECT @@global.histogram_size; + +--Error ER_WRONG_TYPE_FOR_VAR +SET @@global.histogram_size = 4.5; +SELECT @@global.histogram_size; +--Error ER_WRONG_TYPE_FOR_VAR +SET @@global.histogram_size = test; +SELECT @@global.histogram_size; + +SET @@session.histogram_size = -1; +SELECT @@session.histogram_size; +SET @@session.histogram_size = 256; +SELECT @@session.histogram_size; +SET @@session.histogram_size = 1024; +SELECT @@session.histogram_size; + +--Error ER_WRONG_TYPE_FOR_VAR +SET @@session.histogram_size = 4.5; +SELECT @@session.histogram_size; +--Error ER_WRONG_TYPE_FOR_VAR +SET @@session.histogram_size = test; +SELECT @@session.histogram_size; + +--echo '#------------------FN_DYNVARS_053_06-----------------------#' +#################################################################### +# Check if the value in GLOBAL Table matches value in variable # +#################################################################### + +SELECT @@global.histogram_size = VARIABLE_VALUE +FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES +WHERE VARIABLE_NAME='histogram_size'; + +--echo '#------------------FN_DYNVARS_053_07-----------------------#' +#################################################################### +# Check if the value in SESSION Table matches value in variable # +#################################################################### + +SELECT @@session.histogram_size = VARIABLE_VALUE +FROM INFORMATION_SCHEMA.SESSION_VARIABLES +WHERE VARIABLE_NAME='histogram_size'; + + +--echo '#------------------FN_DYNVARS_053_08-----------------------#' +#################################################################### +# Check if TRUE and FALSE values can be used on variable # +#################################################################### + +SET @@global.histogram_size = TRUE; +SET @@global.histogram_size = FALSE; + +--echo '#---------------------FN_DYNVARS_001_09----------------------#' +################################################################################# +# Check if accessing variable with and without GLOBAL point to same variable # +################################################################################# + +SET @@global.histogram_size = 10; +SELECT @@histogram_size = @@global.histogram_size; + +--echo '#---------------------FN_DYNVARS_001_10----------------------#' +######################################################################################################## +# Check if accessing variable with SESSION,LOCAL and without SCOPE points to same session variable # +######################################################################################################## + +SET @@histogram_size = 100; +SELECT @@histogram_size = @@local.histogram_size; +SELECT @@local.histogram_size = @@session.histogram_size; + +#################################### +# Restore initial value # +#################################### + +SET @@global.histogram_size = @start_global_value; +SELECT @@global.histogram_size; +SET @@session.histogram_size = @start_session_value; +SELECT @@session.histogram_size; + + +################################################### +# END OF histogram_size TESTS # +################################################### + diff --git a/mysql-test/suite/sys_vars/t/histogram_type_basic.test b/mysql-test/suite/sys_vars/t/histogram_type_basic.test new file mode 100644 index 00000000000..bf1ef5ef700 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/histogram_type_basic.test @@ -0,0 +1,92 @@ +--source include/load_sysvars.inc + +############################################################# +# Save initial value # +############################################################# + +SET @start_global_value = @@global.histogram_type; +SELECT @start_global_value; +SET @start_session_value = @@session.histogram_type; +SELECT @start_session_value; + +############################################################## +# Display the DEFAULT value of histogram_type # +############################################################## + +SET @@global.histogram_type = 1; +SET @@global.histogram_type = DEFAULT; +SELECT @@global.histogram_type; + +################################################################################# +# Change the value of histogram_type to a valid value for GLOBAL Scope # +################################################################################# + +SET @@global.histogram_type = 0; +SELECT @@global.histogram_type; +SET @@global.histogram_type = 1; +SELECT @@global.histogram_type; + +SET @@global.histogram_type = SINGLE_PREC_HB; +SELECT @@global.histogram_type; +SET @@global.histogram_type = DOUBLE_PREC_HB; +SELECT @@global.histogram_type; + +################################################################################### +# Change the value of histogram_type to a valid value for SESSION Scope # +################################################################################### + +SET @@session.histogram_type = 0; +SELECT @@session.histogram_type; +SET @@session.histogram_type = 1; +SELECT @@session.histogram_type; + +SET @@session.histogram_type = SINGLE_PREC_HB; +SELECT @@session.histogram_type; +SET @@session.histogram_type = DOUBLE_PREC_HB; +SELECT @@session.histogram_type; + +#################################################################### +# Change the value of histogram_type to an invalid value # +#################################################################### + +set sql_mode=TRADITIONAL; +--Error ER_WRONG_VALUE_FOR_VAR +SET @@global.histogram_type = 10; +--Error ER_WRONG_VALUE_FOR_VAR +SET @@global.histogram_type = -1024; +--Error ER_WRONG_TYPE_FOR_VAR +SET @@global.histogram_type = 2.4; +--Error ER_WRONG_VALUE_FOR_VAR +SET @@global.histogram_type = OFF; +--Error ER_WRONG_VALUE_FOR_VAR +SET @@session.histogram_type = 10; +--Error ER_WRONG_VALUE_FOR_VAR +SET @@session.histogram_type = -2; +--Error ER_WRONG_TYPE_FOR_VAR +SET @@session.histogram_type = 1.2; +--Error ER_WRONG_VALUE_FOR_VAR +SET @@session.histogram_type = ON; + +############################################################################### +# Check if the value in GLOBAL & SESSION Tables matches value in variable # +############################################################################### + +SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES +WHERE VARIABLE_NAME='histogram_type'; + +SELECT * FROM INFORMATION_SCHEMA.SESSION_VARIABLES +WHERE VARIABLE_NAME='histogram_type'; + +#################################### +# Restore initial value # +#################################### + +SET @@global.histogram_type = @start_global_value; +SELECT @@global.histogram_type; +SET @@session.histogram_type = @start_session_value; +SELECT @@session.histogram_type; +set sql_mode=''; + +##################################################### +# END OF histogram_type TESTS # +#####################################################
\ No newline at end of file diff --git a/mysql-test/suite/sys_vars/t/optimizer_use_condition_selectivity_basic.test b/mysql-test/suite/sys_vars/t/optimizer_use_condition_selectivity_basic.test new file mode 100644 index 00000000000..58a1af4b975 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/optimizer_use_condition_selectivity_basic.test @@ -0,0 +1,142 @@ + +--source include/load_sysvars.inc + +################################################################# +# START OF optimizer_use_condition_selectivity TESTS # +################################################################# + + +############################################################# +# Save initial value # +############################################################# + +SET @start_global_value = @@global.optimizer_use_condition_selectivity; +SELECT @start_global_value; +SET @start_session_value = @@session.optimizer_use_condition_selectivity; +SELECT @start_session_value; + + +--echo '#--------------------FN_DYNVARS_115_01-------------------------#' +######################################################################### +# Display the DEFAULT value of optimizer_use_condition_selectivity # +######################################################################### + +SET @@global.optimizer_use_condition_selectivity = DEFAULT; +SELECT @@global.optimizer_use_condition_selectivity; + +SET @@session.optimizer_use_condition_selectivity = DEFAULT; +SELECT @@session.optimizer_use_condition_selectivity; + + +--echo '#--------------------FN_DYNVARS_115_02-------------------------#' +######################################################################### +# Check the DEFAULT value of optimizer_use_condition_selectivity # +######################################################################### + +SET @@global.optimizer_use_condition_selectivity = DEFAULT; +SELECT @@global.optimizer_use_condition_selectivity = 1; + +SET @@session.optimizer_use_condition_selectivity = DEFAULT; +SELECT @@session.optimizer_use_condition_selectivity = 1; + + +--echo '#--------------------FN_DYNVARS_115_03-------------------------#' +############################################################################################# +# 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 = 1; +SELECT @@global.optimizer_use_condition_selectivity; +SET @@global.optimizer_use_condition_selectivity = 2; +SELECT @@global.optimizer_use_condition_selectivity; +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; + + +--echo '#--------------------FN_DYNVARS_115_04-------------------------#' +############################################################################################# +# 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 = 1; +SELECT @@session.optimizer_use_condition_selectivity; +SET @@session.optimizer_use_condition_selectivity = 2; +SELECT @@session.optimizer_use_condition_selectivity; +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; + + +--echo '#------------------FN_DYNVARS_115_05-----------------------#' +############################################################################### +# Change the value of optimizer_use_condition_selectivity to an invalid value # +############################################################################## + +--Error ER_WRONG_TYPE_FOR_VAR +SET @@global.optimizer_use_condition_selectivity = ON; +--Error ER_WRONG_TYPE_FOR_VAR +SET @@global.optimizer_use_condition_selectivity = OFF; +--Error ER_WRONG_TYPE_FOR_VAR +SET @@session.optimizer_use_condition_selectivity = 65530.34; +--Error ER_WRONG_TYPE_FOR_VAR +SET @@session.optimizer_use_condition_selectivity = test; + +--echo '#------------------FN_DYNVARS_115_06-----------------------#' +#################################################################### +# Check if the value in GLOBAL Table matches value in variable # +#################################################################### + + +SELECT @@global.optimizer_use_condition_selectivity = VARIABLE_VALUE +FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES +WHERE VARIABLE_NAME='optimizer_use_condition_selectivity'; + +--echo '#------------------FN_DYNVARS_115_07-----------------------#' +#################################################################### +# Check if the value in SESSION Table matches value in variable # +#################################################################### + +SELECT @@session.optimizer_use_condition_selectivity = VARIABLE_VALUE +FROM INFORMATION_SCHEMA.SESSION_VARIABLES +WHERE VARIABLE_NAME='optimizer_use_condition_selectivity'; + + +--echo '#---------------------FN_DYNVARS_115_08----------------------#' +############################################################################### +# Check if global and session variable are independent of each other # +############################################################################### + +SET @@optimizer_use_condition_selectivity = 1; +SET @@global.optimizer_use_condition_selectivity = 3; +SELECT @@optimizer_use_condition_selectivity = @@global.optimizer_use_condition_selectivity; + + +--echo '#---------------------FN_DYNVARS_115_09----------------------#' +############################################################################### +# Check if accessing variable with SESSION,LOCAL and without SCOPE points # +# to same session variable # +############################################################################### + +SET @@optimizer_use_condition_selectivity = 2; +SELECT @@optimizer_use_condition_selectivity = @@local.optimizer_use_condition_selectivity; +SELECT @@local.optimizer_use_condition_selectivity = @@session.optimizer_use_condition_selectivity; + + +#################################### +# Restore initial value # +#################################### + +SET @@global.optimizer_use_condition_selectivity = @start_global_value; +SELECT @@global.optimizer_use_condition_selectivity; +SET @@session.optimizer_use_condition_selectivity = @start_session_value; +SELECT @@session.optimizer_use_condition_selectivity; + +######################################################################## +# END OF optimizer_use_condition_selectivity TESTS # +######################################################################## + diff --git a/mysql-test/t/myisam-metadata.test b/mysql-test/t/myisam-metadata.test index c5327aa3a71..2bbcc89a702 100644 --- a/mysql-test/t/myisam-metadata.test +++ b/mysql-test/t/myisam-metadata.test @@ -3,6 +3,7 @@ # --source include/big_test.inc +--source include/have_debug_sync.inc --disable_warnings DROP TABLE IF EXISTS t1; @@ -29,15 +30,18 @@ while ($1) --enable_query_log --connect(con1,localhost,root,,) ---send +SET debug_sync= 'myisam_after_repair_by_sort SIGNAL waiting WAIT_FOR go'; +send ALTER TABLE t1 ENABLE KEYS; --connection default ---let $wait_timeout=10 +--let $wait_timeout=60 --let $show_statement= SHOW PROCESSLIST --let $field= State --let $condition= = 'Repair by sorting' --source include/wait_show_condition.inc +SET debug_sync= 'now WAIT_FOR waiting'; +SET debug_sync= 'now SIGNAL go'; --replace_column 7 # 8 # 9 # 12 # 13 # 14 # SHOW TABLE STATUS LIKE 't1'; diff --git a/mysql-test/t/selectivity.test b/mysql-test/t/selectivity.test new file mode 100644 index 00000000000..56908e50c65 --- /dev/null +++ b/mysql-test/t/selectivity.test @@ -0,0 +1,623 @@ +--source include/have_stat_tables.inc + +select @@global.use_stat_tables; +select @@session.use_stat_tables; + +set @save_use_stat_tables=@@use_stat_tables; + +set use_stat_tables='preferably'; + +set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity; +set @save_histogram_size=@@histogram_size; +set @save_histogram_type=@@histogram_type; + +# check that statistics on nulls is used + +set optimizer_use_condition_selectivity=3; + +create table t1 (a int); +insert into t1 values + (9), (3), (2), (NULL), (NULL), (2), (NULL), (1), (5), (NULL); + +analyze table t1; + +select * from mysql.column_stats; + +flush table t1; + +explain extended +select * from t1 where a is null; + +explain extended +select * from t1 where a is not null; + +drop table t1; + +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; + +--disable_warnings +DROP DATABASE IF EXISTS dbt3_s001; +--enable_warnings + +CREATE DATABASE dbt3_s001; + +use dbt3_s001; + +--disable_query_log +--disable_result_log +--disable_warnings +--source include/dbt3_s001.inc + +ANALYZE TABLE +customer, lineitem, nation, orders, part, partsupp, region, supplier; +FLUSH TABLE +customer, lineitem, nation, orders, part, partsupp, region, supplier; +--enable_warnings +--enable_result_log +--enable_query_log + + +--echo === Q15 === + +create view revenue0 (supplier_no, total_revenue) as + select l_suppkey, sum(l_extendedprice * (1 - l_discount)) + from lineitem + where + l_shipdate >= '1995-08-01' + and l_shipdate < date_add('1995-08-01', interval 90 day) + group by l_suppkey; + +let $Q15= +select s_suppkey, s_name, s_address, s_phone, total_revenue +from supplier, revenue0 +where s_suppkey = supplier_no + and total_revenue = (select max(total_revenue) from revenue0) +order by s_suppkey; + +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; + +set optimizer_use_condition_selectivity=1; +eval EXPLAIN EXTENDED $Q15; +eval $Q15; + +set optimizer_use_condition_selectivity=3; +eval EXPLAIN EXTENDED $Q15; +eval $Q15; + +set optimizer_switch=@save_optimizer_switch; + +drop view revenue0; + + +--echo === Q16 === + +let $Q16= +select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey + and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) + and ps_suppkey not in (select s_suppkey from supplier + where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; + +set optimizer_use_condition_selectivity=1; +eval EXPLAIN EXTENDED $Q16; +eval $Q16; + +set optimizer_use_condition_selectivity=3; +eval EXPLAIN EXTENDED $Q16; +eval $Q16; + +set optimizer_use_condition_selectivity=4; +eval EXPLAIN EXTENDED $Q16; +eval $Q16; + + +--echo === Q18 === + +let $Q18= +select + c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) +from customer, orders, lineitem +where + o_orderkey in (select l_orderkey from lineitem + group by l_orderkey having sum(l_quantity) > 250) + and c_custkey = o_custkey + and o_orderkey = l_orderkey +group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice +order by o_totalprice desc, o_orderdate; + +set optimizer_use_condition_selectivity=1; +eval EXPLAIN EXTENDED $Q18; +eval $Q18; + +set optimizer_use_condition_selectivity=3; +eval EXPLAIN EXTENDED $Q18; +eval $Q18; + + +--echo === Q22 === + +let $Q22= +select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal +from ( + select substr(c_phone, 1, 2) as cntrycode, c_acctbal + from customer + where + substr(c_phone, 1, 2) in ('10', '20', '14', '19', '11', '28', '25') + and c_acctbal > (select avg(c_acctbal) from customer + where c_acctbal > 0.00 + and substr(c_phone, 1, 2) in + ('10', '20', '14', '19', '11', '28', '25')) + and not exists (select * from orders where o_custkey = c_custkey) + ) as vip +group by cntrycode +order by cntrycode; + +set optimizer_use_condition_selectivity=1; +eval EXPLAIN EXTENDED $Q22; +eval $Q22; + +set optimizer_use_condition_selectivity=3; +eval EXPLAIN EXTENDED $Q22; +eval $Q22; + + +--echo === Q20 === + +let $Q20= +select sql_calc_found_rows + s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp + where ps_partkey in (select p_partkey from part + where p_name like 'g%') + and ps_availqty > + (select 0.5 * sum(l_quantity) + from lineitem + where l_partkey = ps_partkey + and l_suppkey = ps_suppkey + and l_shipdate >= date('1993-01-01') + and l_shipdate < date('1993-01-01') + + interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; + +set optimizer_use_condition_selectivity=1; +eval EXPLAIN EXTENDED $Q20; +eval $Q20; + +SELECT ((SELECT COUNT(*) FROM part WHERE p_name LIKE 'g%') / + (SELECT COUNT(*) FROM part)) AS sel; + +set optimizer_use_condition_selectivity=3; +eval EXPLAIN EXTENDED $Q20; +eval $Q20; + +set histogram_size=127; + +ANALYZE TABLE part PERSISTENT FOR COLUMNS(p_name) INDEXES(); + +flush table part; + +set optimizer_use_condition_selectivity=4; +eval EXPLAIN EXTENDED $Q20; +eval $Q20; + +set histogram_type='DOUBLE_PREC_HB'; +set histogram_size=126; + +ANALYZE TABLE part PERSISTENT FOR COLUMNS(p_name) INDEXES(); + +flush table part; + +eval EXPLAIN EXTENDED $Q20; +eval $Q20; + +set histogram_type='SINGLE_PREC_HB'; +set histogram_size=24; + +ANALYZE TABLE nation PERSISTENT FOR COLUMNS(n_name) INDEXES(); + +flush table nation; + +eval EXPLAIN EXTENDED $Q20; +eval $Q20; + + +DROP DATABASE dbt3_s001; + +set histogram_type=@save_histogram_type; +set histogram_size=@save_histogram_size; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; + +use test; + +--echo # +--echo # Bug mdev-4348: using view with use_condition_selectivity > 1 +--echo # + +set @tmp_use_stat_tables=@@use_stat_tables; +set use_stat_tables='never'; +set optimizer_use_condition_selectivity=3; + +CREATE TABLE t1 (a int, b int); +INSERT t1 VALUES (7,1), (0,7); +CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1; + +CREATE TABLE t2 (c int, d int, index idx(d)); +INSERT INTO t2 VALUES + (0,4), (8,6), (1,3), (8,5), (9,3), (2,2), (6,2), + (1,9), (6,3), (2,8), (4,1), (0,7), (4,8), (4,5); + +EXPLAIN EXTENDED +SELECT * FROM v1 INNER JOIN t2 ON ( a = c AND b = d ); + +SELECT * FROM v1 INNER JOIN t2 ON ( a = c AND b = d ); + +DROP VIEW v1; +DROP TABLE t1,t2; + +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +set use_stat_tables=@tmp_use_stat_tables; + +--echo # +--echo # Bug mdev-4349: impossible range for non-indexed column +--echo # + +set optimizer_use_condition_selectivity=3; + +create table t1 (a int); +insert into t1 values + (3), (7), (2), (5), (7), (1), (2), (2); + +set optimizer_use_condition_selectivity=1; +explain extended +select * from t1 where a < 1 and a > 7; +select * from t1 where a < 1 and a > 7; + +set optimizer_use_condition_selectivity=3; +explain extended +select * from t1 where a < 1 and a > 7; +select * from t1 where a < 1 and a > 7; + +drop table t1; + +create table t1 (a int); +insert into t1 values (1); + +create table t2 (b int); +insert into t2 values (2),(3); + +explain extended +select * from t1 where a in ( select b from t2 ) AND ( a > 3 ); +select * from t1 where a in ( select b from t2 ) AND ( a > 3 ); + +drop table t1,t2; + +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; + +--echo # +--echo # Bug mdev-4350: erroneous negative selectivity +--echo # + +create table t1 (a int); +insert into t1 values (1), (1); +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 values (0); +select count(*) from t1; + +set use_stat_tables='preferably'; +set histogram_size=127; +set histogram_type='SINGLE_PREC_HB'; +analyze table t1; +flush table t1; + +set optimizer_use_condition_selectivity=4; +explain extended select * from t1 where a=0; + +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; + +--echo # +--echo # Bug mdev-4367: 2-way join with an empty 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; + +--echo # +--echo # Bug mdev-4366: impossible condition on an indexed column discovered after +--echo # substitution of constant tables +--echo # with optimizer_use_condition_selectivity=3 +--echo # + +CREATE TABLE t1 (pk int PRIMARY KEY, a int); +INSERT INTO t1 VALUES + (1,4), (2,6), (3,3), (4,5); + +CREATE TABLE t2 (b int); +INSERT INTO t2 VALUES (1), (7); + +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED +SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10; +SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10; + +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED +SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10; +SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10; + +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; + +--echo # +--echo # Bug mdev-4371: Join with condition supported by index on an empty table +--echo # with optimizer_use_condition_selectivity=3 +--echo # + +set use_stat_tables=PREFERABLY; + +CREATE TABLE t1 (a int, b int, INDEX(a)); + +CREATE TABLE t2 (c int); +INSERT INTO t2 VALUES (1),(2),(3),(4),(5),(6),(7),(8); + +ANALYZE TABLE t1, t2; +FLUSH TABLES; + +set optimizer_use_condition_selectivity=3; + +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; + +EXPLAIN EXTENDED +SELECT * FROM t1, t2 WHERE a > 9; +SELECT * FROM t1, t2 WHERE a > 9; + +set optimizer_switch=@save_optimizer_switch; + +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; + +DROP TABLE t1,t2; + +set use_stat_tables=@save_use_stat_tables; + +--echo # +--echo # Bug mdev-4373: condition on a short varchar column +--echo # with optimizer_use_condition_selectivity=3 +--echo # + +set use_stat_tables=PREFERABLY; + +CREATE TABLE t1 (a varchar(1)); +INSERT INTO t1 VALUES ('x'), ('y'); + +ANALYZE TABLE t1; +FLUSH TABLES; + +set optimizer_use_condition_selectivity=3; + +SELECT * FROM t1 WHERE a <= 'w'; + +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; + +DROP TABLE t1; + +set use_stat_tables=@save_use_stat_tables; + +--echo # +--echo # Bug mdev-4372: exists subquery in WHERE +--echo # with optimizer_use_condition_selectivity=3 +--echo # + +set use_stat_tables = PREFERABLY; + +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES + (1),(7),(4),(7),(0),(2),(9),(4),(0),(9),(1),(3),(8),(8); +CREATE TABLE t2 (b int); +INSERT INTO t2 VALUES (4),(5),(2),(5),(1),(1),(2); + +ANALYZE TABLE t1, t2; +FLUSH TABLES; + +set optimizer_use_condition_selectivity=3; + +EXPLAIN EXTENDED +SELECT * FROM t1, t2 WHERE EXISTS ( SELECT 1 FROM t1, t2 ) AND a != b OR a <= 4; + +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; + +DROP TABLE t1,t2; + +set use_stat_tables=@save_use_stat_tables; + + +--echo # +--echo # Bug mdev-4363: selectivity of the condition a IS NULL OR IS NOT NULL +--echo # with optimizer_use_condition_selectivity=3 +--echo # + +set use_stat_tables = PREFERABLY; + +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES + (1),(7),(4),(7),(NULL),(2),(NULL),(4),(NULL),(NULL),(1),(3),(8),(8); + +ANALYZE TABLE t1; +FLUSH TABLE t1; + +set optimizer_use_condition_selectivity=3; + +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a IS NULL; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a IS NOT NULL; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a IS NULL OR a IS NOT NULL; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a IS NULL OR a < 5; + +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; + +DROP TABLE t1; + +set use_stat_tables=@save_use_stat_tables; + +--echo # +--echo # Bug mdev-4378: 2-way join with a materialized IN subquery in WHERE +--echo # when optimizer_use_condition_selectivity=4 +--echo # + +set use_stat_tables=PREFERABLY; +set histogram_size=50; +set histogram_type=SINGLE_PREC_HB; + +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (8),(9),(6); + +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (8),(1),(8),(9),(24),(6),(1),(6),(2),(4); + +CREATE TABLE t3 (ln VARCHAR(16)) ENGINE=MyISAM; +INSERT INTO t3 VALUES +('smith'),('black'),('white'),('jones'), +('brown'),('taylor'),('anderson'),('taylor'); + +ANALYZE TABLE t1, t2, t3; +FLUSH TABLES; + +set optimizer_use_condition_selectivity=4; + +SELECT * FROM t1, t2 WHERE 'garcia' IN ( SELECT MIN( ln ) FROM t3 WHERE ln = 'sun' ); + +set histogram_size=@save_histogram_size; +set histogram_type=@save_histogram_type; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; + +DROP TABLE t1,t2,t3; + +set use_stat_tables=@save_use_stat_tables; + +--echo # +--echo # Bug mdev-4380: 2-way join with a materialized IN subquery in WHERE +--echo # when optimizer_use_condition_selectivity=3 +--echo # + +set use_stat_tables=PREFERABLY; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (5),(9); + +CREATE TABLE t2 (b VARCHAR(8)); +INSERT INTO t2 VALUES ('red'),('blue'); + +CREATE TABLE t3 (c VARCHAR(8), d VARCHAR(8)); +INSERT INTO t3 VALUES ('white','black'),('cyan','yellow'); + +ANALYZE TABLE t1, t2, t3; +FLUSH TABLES; + +set optimizer_use_condition_selectivity=3; + +SELECT * FROM t1, t2 WHERE ( 'orange', 'green' ) IN ( + SELECT MAX(c), MAX(d) FROM t3, t2 WHERE c >= d AND b = c +); + +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; + +DROP TABLE t1,t2,t3; + +set use_stat_tables=@save_use_stat_tables; + +--echo # +--echo # Bug mdev-4389: join with degenerated range condition in WHERE +--echo # when optimizer_use_condition_selectivity=3 +--echo # + +set use_stat_tables=PREFERABLY; + +CREATE TABLE t1 (f1 VARCHAR(1)); +INSERT t1 VALUES ('p'),('q'); + +CREATE TABLE t2 (f2 VARCHAR(1)); +INSERT INTO t2 VALUES + ('o'),('v'),('f'),('f'),('e'),('l'),('j'),('p'),('r'),('j'), + ('j'),('u'),('i'),('r'),('x'),('a'),('x'),('s'); + +ANALYZE TABLE t1, t2; +FLUSH TABLES; + +SET optimizer_use_condition_selectivity=3; + +SELECT * FROM t1, t2 AS t2a, t2 AS t2b WHERE f1 <= 'a' AND t2a.f2 = f1; + +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; + +DROP TABLE t1,t2; + +set use_stat_tables=@save_use_stat_tables; + + +set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/t/selectivity_innodb.test b/mysql-test/t/selectivity_innodb.test new file mode 100644 index 00000000000..6b67e2d0529 --- /dev/null +++ b/mysql-test/t/selectivity_innodb.test @@ -0,0 +1,12 @@ +--source include/have_innodb.inc + +SET SESSION STORAGE_ENGINE='InnoDB'; + +set @save_optimizer_switch_for_selectivity_test=@@optimizer_switch; +set optimizer_switch='extended_keys=on'; + +--source selectivity.test + +set optimizer_switch=@save_optimizer_switch_for_selectivity_test; + +SET SESSION STORAGE_ENGINE=DEFAULT; diff --git a/mysql-test/t/statistics.test b/mysql-test/t/statistics.test index 4f2d0510c11..b2a052fd3e8 100644 --- a/mysql-test/t/statistics.test +++ b/mysql-test/t/statistics.test @@ -165,6 +165,37 @@ SELECT WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL AND t1.d IS NOT NULL) AS 'ARITY 3'; + +DELETE FROM mysql.column_stats; + +set histogram_size=4; +ANALYZE TABLE t1; + +SELECT db_name, table_name, column_name, + min_value, max_value, + nulls_ratio, avg_frequency, + hist_size, hist_type, HEX(histogram) + FROM mysql.column_stats; + +DELETE FROM mysql.column_stats; + +set histogram_size=8; +set histogram_type='DOUBLE_PREC_HB'; +ANALYZE TABLE t1; + +SELECT db_name, table_name, column_name, + min_value, max_value, + nulls_ratio, avg_frequency, + hist_size, hist_type, HEX(histogram) + FROM mysql.column_stats; + +DELETE FROM mysql.column_stats; + +set histogram_size= 0; +set histogram_type=default; +ANALYZE TABLE t1; + + CREATE TABLE t3 ( a int NOT NULL PRIMARY KEY, b varchar(32), @@ -559,6 +590,96 @@ DELETE FROM mysql.table_stats; DELETE FROM mysql.column_stats; DELETE FROM mysql.index_stats; +--echo # +--echo # Bug mdev-4357: empty string as a value of the HIST_SIZE column +--echo # from mysql.column_stats +--echo # + +create table t1 (a int); +insert into t1 values (1),(2),(3); + +set histogram_size=10; + +analyze table t1 persistent for all; + +select db_name, table_name, column_name, + min_value, max_value, + nulls_ratio, avg_frequency, + hist_size, hist_type, HEX(histogram) + FROM mysql.column_stats; + +set histogram_size=default; + +drop table t1; + +--echo # +--echo # Bug mdev-4359: wrong setting of the HIST_SIZE column +--echo # (see also mdev-4357) from mysql.column_stats +--echo # + +create table t1 ( a int); +insert into t1 values (1),(2),(3),(4),(5); + +set histogram_size=10; +set histogram_type='double_prec_hb'; + +show variables like 'histogram%'; + +analyze table t1 persistent for all; + +select db_name, table_name, column_name, + min_value, max_value, + nulls_ratio, avg_frequency, + hist_size, hist_type, HEX(histogram) + FROM mysql.column_stats; + +set histogram_size=default; +set histogram_type=default; + +drop table t1; + +--echo # +--echo # Bug mdev-4369: histogram for a column with many distinct values +--echo # + + +CREATE TABLE t1 (id int); +CREATE TABLE t2 (id int); + +INSERT INTO t1 (id) VALUES (1), (1), (1),(1); +INSERT INTO t1 (id) SELECT id FROM t1; +INSERT INTO t1 SELECT id+1 FROM t1; +INSERT INTO t1 SELECT id+2 FROM t1; +INSERT INTO t1 SELECT id+4 FROM t1; +INSERT INTO t1 SELECT id+8 FROM t1; +INSERT INTO t1 SELECT id+16 FROM t1; +INSERT INTO t1 SELECT id+32 FROM t1; +INSERT INTO t1 SELECT id+64 FROM t1; +INSERT INTO t1 SELECT id+128 FROM t1; +INSERT INTO t1 SELECT id+256 FROM t1; +INSERT INTO t1 SELECT id+512 FROM t1; + +INSERT INTO t2 SELECT id FROM t1 ORDER BY id*rand(); + +SELECT COUNT(*) FROM t2; +SELECT COUNT(DISTINCT id) FROM t2; + +set @@tmp_table_size=1024*16; +set @@max_heap_table_size=1024*16; + +set histogram_size=63; + +analyze table t2 persistent for all; + +select db_name, table_name, column_name, + min_value, max_value, + nulls_ratio, avg_frequency, + hist_size, hist_type, HEX(histogram) + FROM mysql.column_stats; + +set histogram_size=default; + +drop table t1, t2; + set use_stat_tables=@save_use_stat_tables; -
\ No newline at end of file |