From 727491b72adcf3c10b252a61579f70c7ec2246be Mon Sep 17 00:00:00 2001 From: Monty Date: Tue, 4 Oct 2022 16:16:06 +0300 Subject: [PATCH] Added test cases for preceding test This includes all test changes from "Changing all cost calculation to be given in milliseconds" and forwards. Some of the things that caused changes in the result files: - As part of fixing tests, I added 'echo' to some comments to be able to easier find out where things where wrong. - MATERIALIZED has now a higher cost compared to X than before. Because of this some MATERIALIZED types have changed to DEPENDEND SUBQUERY. - Some test cases that required MATERIALIZED to repeat a bug was changed by adding more rows to force MATERIALIZED to happen. - 'Filtered' in SHOW EXPLAIN has in many case changed from 100.00 to something smaller. This is because now filtered also takes into account the smallest possible ref access and filters, even if they where not used. Another reason for 'Filtered' being smaller is that we now also take into account implicit filtering done for subqueries using FIRSTMATCH. (main.subselect_no_exists_to_in) This is caluculated in best_access_path() and stored in records_out. - Table orders has changed because more accurate costs. - 'index' and 'ALL' for small tables has changed to use 'range' or 'ref' because of optimizer_scan_setup_cost. - index can be changed to 'range' as 'range' optimizer assumes we don't have to read the blocks from disk that range optimizer has already read. This can be confusing in the case where there is no obvious where clause but instead there is a hidden 'key_column > NULL' added by the optimizer. (main.subselect_no_exists_to_in) - Scan on primary clustered key does not report 'Using Index' anymore (It's a table scan, not an index scan). - For derived tables, the number of rows is now 100 instead of 2, which can be seen in EXPLAIN. - More tests have "Using index for group by" as the cost of this optimization is now more correct (lower). - A primary key could be preferred for a normal key, even if it would access more rows, as it's faster to do 1 lokoup and 3 'index_next' on a clustered primary key than one lookup trough a secondary. (main.stat_tables_innodb) Notes: - There was a 4.7% more calls to best_extension_by_limited_search() in the main.greedy_optimizer test. However examining the test results it looked that the plans where slightly better (eq_ref where more chained together) so I assume this is ok. - I have verified a few test cases where there was notable/unexpected changes in the plan and in all cases the new optimizer plans where faster. (main.greedy_optimizer and some others) --- mysql-test/include/common-tests.inc | 20 +- mysql-test/include/explain_non_select.inc | 10 +- mysql-test/include/icp_tests.inc | 6 +- mysql-test/include/mix1.inc | 8 +- .../percona_nonflushing_analyze_debug.inc | 2 +- .../include/rowid_filter_debug_kill.inc | 23 +- mysql-test/main/analyze_format_json.result | 13 +- mysql-test/main/analyze_format_json.test | 1 + .../main/analyze_stmt_privileges2.result | 78 +- mysql-test/main/compress.result | 19 +- mysql-test/main/costs.result | 42 +- mysql-test/main/cte_nonrecursive.result | 14 +- mysql-test/main/cte_recursive.result | 47 +- mysql-test/main/ctype_ucs.result | 4 +- mysql-test/main/delete.result | 8 + mysql-test/main/delete.test | 7 +- mysql-test/main/delete_innodb.result | 2 +- mysql-test/main/derived.result | 24 +- mysql-test/main/derived.test | 2 +- mysql-test/main/derived_cond_pushdown.result | 228 +- mysql-test/main/derived_cond_pushdown.test | 7 +- mysql-test/main/derived_opt.result | 2 +- mysql-test/main/derived_split_innodb.result | 24 +- mysql-test/main/derived_view.result | 22 +- mysql-test/main/desc_index_range.result | 2 +- mysql-test/main/distinct.result | 12 +- mysql-test/main/explain.result | 16 +- mysql-test/main/explain_innodb.result | 2 +- mysql-test/main/explain_json.result | 80 +- mysql-test/main/explain_json.test | 7 +- mysql-test/main/explain_json_innodb.result | 3 +- mysql-test/main/fetch_first.result | 9 +- mysql-test/main/fetch_first.test | 7 +- mysql-test/main/fulltext.result | 7 +- mysql-test/main/fulltext.test | 2 + mysql-test/main/fulltext_order_by.test | 1 - mysql-test/main/func_group.result | 8 +- mysql-test/main/func_group_innodb.result | 6 +- mysql-test/main/func_group_innodb.test | 2 +- mysql-test/main/func_in.result | 16 +- mysql-test/main/greedy_optimizer.result | 246 +- mysql-test/main/greedy_optimizer.test | 2 +- mysql-test/main/group_by.result | 8 +- mysql-test/main/group_min_max.result | 24 +- mysql-test/main/group_min_max.test | 1 + mysql-test/main/group_min_max_innodb.result | 22 +- mysql-test/main/ignored_index.result | 14 +- mysql-test/main/ignored_index.test | 8 +- mysql-test/main/index_intersect.result | 4 +- mysql-test/main/index_intersect_innodb.result | 14 +- mysql-test/main/index_merge_innodb.result | 8 +- mysql-test/main/index_merge_myisam.result | 14 +- mysql-test/main/information_schema-big.result | 2 + mysql-test/main/information_schema.result | 3 +- mysql-test/main/innodb_ext_key,off.rdiff | 39 +- mysql-test/main/innodb_ext_key.result | 29 +- mysql-test/main/innodb_ext_key.test | 16 +- mysql-test/main/innodb_icp.result | 22 +- mysql-test/main/innodb_mysql_lock2.test | 1 + mysql-test/main/invisible_field_debug.result | 6 +- mysql-test/main/join.result | 40 +- mysql-test/main/join.test | 8 +- mysql-test/main/join_cache.result | 62 +- mysql-test/main/join_nested.result | 6 +- mysql-test/main/join_nested_jcl6.result | 28 +- mysql-test/main/join_outer.result | 10 +- mysql-test/main/join_outer.test | 2 +- mysql-test/main/join_outer_innodb.result | 30 +- mysql-test/main/join_outer_jcl6.result | 14 +- mysql-test/main/key.result | 6 +- mysql-test/main/key_cache.result | 20 +- mysql-test/main/key_cache.test | 12 +- mysql-test/main/limit_rows_examined.result | 60 +- mysql-test/main/limit_rows_examined.test | 6 +- mysql-test/main/mrr_derived_crash_4610.result | 2 +- mysql-test/main/myisam.result | 3 + mysql-test/main/myisam.test | 1 + .../main/myisam_explain_non_select_all.result | 71 +- mysql-test/main/myisam_icp.result | 32 +- mysql-test/main/myisam_mrr.result | 5 +- mysql-test/main/myisam_mrr.test | 5 +- mysql-test/main/mysqld--help.result | 6 + mysql-test/main/named_pipe.result | 19 +- mysql-test/main/negation_elimination.result | 6 +- mysql-test/main/opt_trace.result | 3791 ++++++++++------- mysql-test/main/opt_trace.test | 67 +- mysql-test/main/opt_trace_index_merge.result | 164 +- .../main/opt_trace_index_merge_innodb.result | 35 +- mysql-test/main/opt_trace_security.result | 24 +- mysql-test/main/opt_trace_selectivity.result | 39 +- mysql-test/main/opt_tvc.result | 6 +- mysql-test/main/optimizer_costs.result | 347 ++ mysql-test/main/optimizer_costs.test | 187 + mysql-test/main/optimizer_costs2-master.opt | 1 + mysql-test/main/optimizer_costs2.result | 8 + mysql-test/main/optimizer_costs2.test | 6 + mysql-test/main/order_by.result | 188 +- mysql-test/main/order_by.test | 17 +- mysql-test/main/order_by_innodb.result | 2 +- mysql-test/main/partition.result | 4 +- .../main/partition_explicit_prune.result | 4 +- mysql-test/main/partition_mrr_aria.result | 4 +- mysql-test/main/partition_mrr_innodb.result | 4 +- mysql-test/main/partition_mrr_myisam.result | 6 +- mysql-test/main/partition_pruning.result | 40 +- mysql-test/main/partition_range.result | 69 +- mysql-test/main/partition_range.test | 31 +- .../percona_nonflushing_analyze_debug.result | 2 +- mysql-test/main/pool_of_threads.result | 19 +- mysql-test/main/range.result | 159 +- mysql-test/main/range.test | 22 +- mysql-test/main/range_innodb.result | 6 +- .../main/range_interrupted-13751.result | 14 +- mysql-test/main/range_interrupted-13751.test | 14 +- mysql-test/main/range_mrr_icp.result | 87 +- mysql-test/main/range_notembedded.result | 8 +- mysql-test/main/range_vs_index_merge.result | 75 +- mysql-test/main/range_vs_index_merge.test | 14 +- .../main/range_vs_index_merge_innodb.result | 77 +- mysql-test/main/rowid_filter.result | 473 +- mysql-test/main/rowid_filter.test | 14 +- mysql-test/main/rowid_filter_innodb.result | 642 ++- mysql-test/main/rowid_filter_innodb.test | 8 +- .../main/rowid_filter_innodb_debug.result | 19 +- .../main/rowid_filter_myisam_debug.result | 19 +- mysql-test/main/select.result | 72 +- mysql-test/main/select.test | 36 +- mysql-test/main/select_jcl6.result | 80 +- mysql-test/main/select_pkeycache.result | 72 +- mysql-test/main/select_safe.result | 4 +- mysql-test/main/selectivity.result | 62 +- mysql-test/main/selectivity.test | 16 +- mysql-test/main/selectivity_innodb.result | 74 +- mysql-test/main/selectivity_no_engine.result | 4 +- mysql-test/main/show_explain.result | 2 +- mysql-test/main/sp.result | 2 +- mysql-test/main/ssl.result | 19 +- mysql-test/main/ssl_compress.result | 19 +- mysql-test/main/stat_tables.result | 51 +- mysql-test/main/stat_tables.test | 2 +- mysql-test/main/stat_tables_innodb.result | 59 +- mysql-test/main/statistics_json.result | 2 +- mysql-test/main/status.result | 18 +- mysql-test/main/subselect.result | 118 +- mysql-test/main/subselect.test | 49 +- mysql-test/main/subselect2.result | 10 +- mysql-test/main/subselect2.test | 4 +- mysql-test/main/subselect3.result | 12 +- mysql-test/main/subselect3_jcl6.result | 10 +- mysql-test/main/subselect4.result | 18 +- mysql-test/main/subselect_exists2in.result | 24 +- mysql-test/main/subselect_exists2in.test | 4 + .../main/subselect_exists2in_costmat.result | 4 +- mysql-test/main/subselect_innodb.result | 4 +- mysql-test/main/subselect_mat.result | 85 +- mysql-test/main/subselect_mat_cost.result | 49 +- mysql-test/main/subselect_mat_cost.test | 31 +- .../main/subselect_mat_cost_bugs.result | 26 +- .../main/subselect_no_exists_to_in.result | 111 +- mysql-test/main/subselect_no_mat.result | 119 +- mysql-test/main/subselect_no_opts.result | 89 +- mysql-test/main/subselect_no_scache.result | 118 +- mysql-test/main/subselect_no_semijoin.result | 117 +- .../main/subselect_partial_match.result | 10 +- mysql-test/main/subselect_partial_match.test | 6 +- mysql-test/main/subselect_sj.result | 71 +- mysql-test/main/subselect_sj.test | 4 +- mysql-test/main/subselect_sj2.result | 49 +- mysql-test/main/subselect_sj2.test | 15 +- mysql-test/main/subselect_sj2_jcl6.result | 78 +- mysql-test/main/subselect_sj2_jcl6.test | 3 + mysql-test/main/subselect_sj2_mat.result | 98 +- mysql-test/main/subselect_sj_jcl6.result | 125 +- mysql-test/main/subselect_sj_jcl6.test | 19 +- mysql-test/main/subselect_sj_mat.result | 184 +- mysql-test/main/subselect_sj_mat.test | 23 +- mysql-test/main/subselect_sj_nonmerged.result | 4 +- mysql-test/main/type_blob.result | 14 +- mysql-test/main/type_datetime.result | 2 +- mysql-test/main/view.result | 38 +- mysql-test/main/view.test | 6 + mysql-test/suite/archive/archive.result | 4 + mysql-test/suite/archive/archive.test | 3 +- .../suite/funcs_1/r/is_columns_is.result | 26 + .../funcs_1/r/is_columns_is_embedded.result | 26 + .../suite/funcs_1/r/is_tables_is.result | 50 + .../funcs_1/r/is_tables_is_embedded.result | 50 + .../suite/galera/r/galera_many_indexes.result | 2 +- .../suite/gcol/r/gcol_ins_upd_innodb.result | 2 +- .../suite/gcol/r/gcol_select_innodb.result | 34 +- .../suite/gcol/r/gcol_select_myisam.result | 34 +- mysql-test/suite/heap/heap.result | 2 +- mysql-test/suite/heap/heap_btree.result | 2 +- mysql-test/suite/innodb/r/innodb-index.result | 4 +- .../suite/innodb/r/innodb-isolation.result | 2 +- mysql-test/suite/innodb/r/innodb.result | 6 +- .../suite/innodb/r/innodb_bug30423.result | 4 +- mysql-test/suite/innodb/r/innodb_mysql.result | 59 +- .../innodb/r/table_index_statistics.result | 3 - .../suite/innodb/r/temporary_table.result | 2 +- .../r/temporary_table_optimization.result | 2 +- mysql-test/suite/innodb_fts/r/fulltext.result | 7 +- .../suite/innodb_fts/r/fulltext_misc.result | 20 +- mysql-test/suite/innodb_fts/t/fulltext.test | 2 + .../innodb_gis/r/create_spatial_index.result | 103 +- mysql-test/suite/innodb_gis/r/rtree.result | 10 +- .../suite/innodb_gis/r/rtree_multi_pk.result | 8 +- .../innodb_gis/t/create_spatial_index.test | 2 + .../suite/innodb_gis/t/rtree_multi_pk.test | 1 + .../suite/json/r/json_table_mysql.result | 3 +- mysql-test/suite/maria/icp.result | 30 +- mysql-test/suite/maria/mrr.result | 10 +- .../suite/parts/inc/partition_decimal.inc | 4 + .../suite/parts/inc/partition_double.inc | 4 + .../suite/parts/inc/partition_key_16col.inc | 1 + .../suite/parts/inc/partition_key_32col.inc | 1 + .../suite/parts/inc/partition_key_4col.inc | 1 + .../suite/parts/inc/partition_key_8col.inc | 1 + mysql-test/suite/parts/inc/partition_time.inc | 2 +- .../suite/parts/inc/partition_timestamp.inc | 5 + mysql-test/suite/parts/r/optimizer.result | 8 +- .../parts/r/partition_char_innodb.result | Bin 50530 -> 50530 bytes .../parts/r/partition_datetime_innodb.result | 1012 ++--- .../parts/r/partition_datetime_myisam.result | 122 +- .../parts/r/partition_decimal_innodb.result | 28 +- .../parts/r/partition_decimal_myisam.result | 28 +- .../parts/r/partition_double_innodb.result | 16 +- .../parts/r/partition_double_myisam.result | 16 +- .../parts/r/partition_float_innodb.result | 10 +- .../parts/r/partition_special_innodb.result | 8 +- .../parts/r/partition_special_myisam.result | 8 +- .../percona_nonflushing_analyze_debug.result | 12 +- .../perfschema/r/batch_table_io_func.result | 11 +- .../r/table_aggregate_global_2u_2t.result | 190 +- .../r/table_aggregate_global_2u_3t.result | 190 +- .../r/table_aggregate_global_4u_2t.result | 190 +- .../r/table_aggregate_global_4u_3t.result | 190 +- .../r/table_aggregate_hist_2u_2t.result | 354 +- .../r/table_aggregate_hist_2u_3t.result | 354 +- .../r/table_aggregate_hist_4u_2t.result | 354 +- .../r/table_aggregate_hist_4u_3t.result | 354 +- .../r/table_aggregate_thread_2u_2t.result | 314 +- .../r/table_aggregate_thread_2u_3t.result | 314 +- .../r/table_aggregate_thread_4u_2t.result | 314 +- .../r/table_aggregate_thread_4u_3t.result | 314 +- .../r/table_io_aggregate_global_2u_2t.result | 190 +- .../r/table_io_aggregate_global_2u_3t.result | 190 +- .../r/table_io_aggregate_global_4u_2t.result | 190 +- .../r/table_io_aggregate_global_4u_3t.result | 190 +- .../r/table_io_aggregate_hist_2u_2t.result | 354 +- .../r/table_io_aggregate_hist_2u_3t.result | 354 +- .../r/table_io_aggregate_hist_4u_2t.result | 354 +- .../r/table_io_aggregate_hist_4u_3t.result | 354 +- .../r/table_io_aggregate_thread_2u_2t.result | 314 +- .../r/table_io_aggregate_thread_2u_3t.result | 314 +- .../r/table_io_aggregate_thread_4u_2t.result | 314 +- .../r/table_io_aggregate_thread_4u_3t.result | 314 +- .../sys_vars/r/max_join_size_basic.result | 8 +- .../sys_vars/r/sysvars_server_embedded.result | 106 +- .../r/sysvars_server_notembedded.result | 106 +- .../suite/sys_vars/t/max_join_size_basic.test | 2 +- .../pr_statement_performance_analyzer.result | 7 +- .../r/v_schema_redundant_indexes.result | 2 +- .../t/v_schema_redundant_indexes.test | 1 + mysql-test/suite/vcol/inc/vcol_ins_upd.inc | 3 + .../suite/vcol/r/vcol_ins_upd_innodb.result | 1 + .../suite/vcol/r/vcol_ins_upd_myisam.result | 1 + .../suite/vcol/r/vcol_select_innodb.result | 2 +- .../suite/vcol/r/vcol_select_myisam.result | 6 +- mysql-test/suite/versioning/r/cte.result | 2 +- sql/handler.cc | 3 + .../connect/mysql-test/connect/r/index.result | 29 +- .../connect/mysql-test/connect/t/index.test | 7 +- ...mization_count_skip_index_not_equal.result | 5 +- ...timization_count_skip_index_not_equal.test | 1 + .../wrapper/r/geometry_contains.result | 2 +- .../rocksdb/r/mariadb_port_fixes.result | 4 +- .../mysql-test/rocksdb/r/rocksdb.result | 4 +- .../rocksdb/r/type_char_indexes.result | 2 +- .../rocksdb/r/type_date_time_indexes.result | 2 +- .../rocksdb/r/type_enum_indexes.result | 2 +- .../rocksdb/r/type_float_indexes.result | 4 +- .../rocksdb/t/mariadb_port_fixes.test | 4 +- .../mysql-test/sequence/group_by.result | 2 +- .../spider/bugfix/r/mdev_21884.result | 7 +- .../spider/bugfix/r/quick_mode_1.result | 4 + .../spider/bugfix/t/mdev_22246.test | 1 + .../spider/bugfix/t/quick_mode_1.test | 1 + .../r/direct_left_right_join_nullable.result | 2 +- ...rect_right_left_right_join_nullable.result | 2 +- 290 files changed, 10927 insertions(+), 8874 deletions(-) create mode 100644 mysql-test/main/optimizer_costs.result create mode 100644 mysql-test/main/optimizer_costs.test create mode 100644 mysql-test/main/optimizer_costs2-master.opt create mode 100644 mysql-test/main/optimizer_costs2.result create mode 100644 mysql-test/main/optimizer_costs2.test diff --git a/mysql-test/include/common-tests.inc b/mysql-test/include/common-tests.inc index 9c6b29858c8..9b54b049f8b 100644 --- a/mysql-test/include/common-tests.inc +++ b/mysql-test/include/common-tests.inc @@ -13,6 +13,11 @@ drop table if exists t1,t2,t3,t4; --enable_warnings +# We have to use Aria instead of MyISAM as MyISAM has a very high row +# access cost which causes some tests to use use join_cache instead of eq_ref + +set @@default_storage_engine="aria"; + CREATE TABLE t1 ( Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL, Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL @@ -1429,7 +1434,7 @@ set tmp_memory_table_size=default; select distinct fld3,repeat("a",length(fld3)),count(*) from t2 group by companynr,fld3 limit 100,10; # -# A big order by that should trigger a merge in filesort +# A big order by that should traigger a merge in filesort # select distinct companynr,rtrim(space(512+companynr)) from t3 order by 1,2; @@ -1446,9 +1451,9 @@ select distinct fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr orde explain select t3.t2nr,fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by t3.t2nr,fld3; -# -# Some test with ORDER BY and limit -# +--echo # +--echo # Some test with ORDER BY and limit +--echo # explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period; explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10; @@ -1501,7 +1506,7 @@ create table t4 ( companyname char(30) NOT NULL default '', PRIMARY KEY (companynr), UNIQUE KEY companyname(companyname) -) ENGINE=MyISAM MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames'; +) ENGINE=aria MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames'; --disable_query_log INSERT INTO t4 (companynr, companyname) VALUES (29,'company 1'); @@ -1555,8 +1560,9 @@ explain select companynr,companyname from t2 left join t4 using (companynr) wher explain select companynr,companyname from t4 left join t2 using (companynr) where companynr is null; delete from t2 where fld1=999999; -# -# Test left join optimization +--echo # +--echo # Test left join optimization +--echo # explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0; explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0; diff --git a/mysql-test/include/explain_non_select.inc b/mysql-test/include/explain_non_select.inc index 9ce620a72de..8e60f582f9e 100644 --- a/mysql-test/include/explain_non_select.inc +++ b/mysql-test/include/explain_non_select.inc @@ -1,6 +1,7 @@ # This file is a collection of regression and coverage tests # for WL#4897: Add EXPLAIN INSERT/UPDATE/DELETE. +-- source include/have_sequence.inc -- disable_query_log -- disable_result_log # SET GLOBAL innodb_stats_persistent=0; @@ -78,10 +79,13 @@ CREATE TABLE t1 (a INT); INSERT INTO t1 VALUES (1), (2), (3); CREATE TABLE t2 (b INT); INSERT INTO t2 VALUES (1), (2), (3), (1000); ---let $query = UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3) ---let $select = SELECT * FROM t1, t2 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3) +CREATE TABLE t3 like t2; +insert into t3 select * from t2; +insert into t3 select seq from seq_1001_to_2000; +--let $query = UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t3 WHERE t3.b < 3) +--let $select = SELECT * FROM t1, t2 WHERE a IN (SELECT b FROM t3 WHERE t3.b < 3) --source include/explain_utils.inc -DROP TABLE t1, t2; +DROP TABLE t1, t2, t3; --echo #8 CREATE TABLE t1 (a INT); diff --git a/mysql-test/include/icp_tests.inc b/mysql-test/include/icp_tests.inc index d78fe0dd209..b37f59b46c5 100644 --- a/mysql-test/include/icp_tests.inc +++ b/mysql-test/include/icp_tests.inc @@ -486,7 +486,7 @@ CREATE TABLE t1 ( ); INSERT INTO t1 VALUES (1,9),(2,7),(3,6),(4,3),(5,1); - +insert into t1 select seq,seq from seq_100_to_110; EXPLAIN SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3); SET SESSION optimizer_switch='index_condition_pushdown=off'; @@ -723,7 +723,6 @@ DROP TABLE t1; CREATE TABLE t1 (b int NOT NULL, c int, a varchar(1024), PRIMARY KEY (b)); INSERT INTO t1 VALUES (1,4,'Ill'); -insert into t1 select seq+100,5,seq from seq_1_to_100; CREATE TABLE t2 (a varchar(1024), KEY (a(512))); INSERT INTO t2 VALUES @@ -856,6 +855,8 @@ ANALYZE TABLE t1,t2; SET @save_optimize_switch=@@optimizer_switch; SET optimizer_switch='materialization=on'; +set @save_optimizer_where_cost=@@optimizer_where_cost; +set @@optimizer_where_cost=1; EXPLAIN SELECT COUNT(*) FROM t1 AS t, t2 @@ -873,6 +874,7 @@ WHERE c = g OR a = 0 AND h < 'z' ); SET optimizer_switch=@save_optimizer_switch; +set @@optimizer_where_cost=@save_optimizer_where_cost; DROP TABLE t1,t2; diff --git a/mysql-test/include/mix1.inc b/mysql-test/include/mix1.inc index 2ec0868c39e..cbb79668b2a 100644 --- a/mysql-test/include/mix1.inc +++ b/mysql-test/include/mix1.inc @@ -1183,14 +1183,14 @@ set @my_innodb_autoextend_increment=@@global.innodb_autoextend_increment; set global innodb_autoextend_increment=8; set global innodb_autoextend_increment=@my_innodb_autoextend_increment; -# -# Bug #37830: ORDER BY ASC/DESC - no difference -# +--echo # +--echo # Bug #37830: ORDER BY ASC/DESC - no difference +--echo # CREATE TABLE t1 (a int, b int, c int, PRIMARY KEY (a), KEY t1_b (b)) ENGINE=InnoDB; -INSERT INTO t1 (a,b,c) VALUES (1,1,1), (2,1,1), (3,1,1), (4,1,1); +INSERT INTO t1 (a,b,c) VALUES (1,1,1), (2,1,1), (3,1,1), (4,1,1), (100,2,2); INSERT INTO t1 (a,b,c) SELECT a+4,b,c FROM t1; -- disable_query_log diff --git a/mysql-test/include/percona_nonflushing_analyze_debug.inc b/mysql-test/include/percona_nonflushing_analyze_debug.inc index 95621c70d5c..8cdf6218609 100644 --- a/mysql-test/include/percona_nonflushing_analyze_debug.inc +++ b/mysql-test/include/percona_nonflushing_analyze_debug.inc @@ -8,7 +8,7 @@ --connect con1,localhost,root -SET DEBUG_SYNC="handler_ha_index_next_end SIGNAL idx_scan_in_progress WAIT_FOR finish_scan"; +SET DEBUG_SYNC="handler_rnd_next_end SIGNAL idx_scan_in_progress WAIT_FOR finish_scan"; send_eval SELECT * FROM $percona_nonflushing_analyze_table; diff --git a/mysql-test/include/rowid_filter_debug_kill.inc b/mysql-test/include/rowid_filter_debug_kill.inc index 513efed8a4c..c672954fc7c 100644 --- a/mysql-test/include/rowid_filter_debug_kill.inc +++ b/mysql-test/include/rowid_filter_debug_kill.inc @@ -2,13 +2,18 @@ --source include/have_debug_sync.inc --source include/have_sequence.inc --source include/count_sessions.inc +--source include/have_sequence.inc +--source include/no_valgrind_without_big.inc --echo # --echo # MDEV-22761 KILL QUERY during rowid_filter, crashes --echo # +create table t1(a int); +insert into t1 select seq from seq_1_to_1000; + create table t2(a int); -insert into t2 select * from seq_0_to_99; +insert into t2 select seq from seq_1_to_100; # 10K rows CREATE TABLE t3 ( @@ -18,22 +23,16 @@ CREATE TABLE t3 ( KEY (key1), KEY (key2) ); +insert into t3 select seq,seq, 'filler-data-filler-data' from seq_1_to_2000; + select engine from information_schema.tables where table_schema=database() and table_name='t3'; - -insert into t3 -select - A.seq, - B.seq, - 'filler-data-filler-data' -from seq_0_to_99 A, seq_0_to_99 B; - analyze table t2,t3; explain select * from t2, t3 where - t3.key1=t2.a and t3.key2 in (2,3); + t3.key1=t2.a and t3.key2 in (2,3,4,5,6,7,8,9,10); let $target_id= `select connection_id()`; @@ -41,7 +40,7 @@ set debug_sync='handler_rowid_filter_check SIGNAL at_rowid_filter_check WAIT_FOR send select * from t2, t3 where - t3.key1=t2.a and t3.key2 in (2,3); + t3.key1=t2.a and t3.key2 in (2,3,4,5,6,7,8,9,10); connect (con1, localhost, root,,); set debug_sync='now WAIT_FOR at_rowid_filter_check'; @@ -55,5 +54,5 @@ disconnect con1; reap; set debug_sync='RESET'; -drop table t2,t3; +drop table t1,t2,t3; --source include/wait_until_count_sessions.inc diff --git a/mysql-test/main/analyze_format_json.result b/mysql-test/main/analyze_format_json.result index 7fd783e4355..99ac42d34bd 100644 --- a/mysql-test/main/analyze_format_json.result +++ b/mysql-test/main/analyze_format_json.result @@ -771,12 +771,12 @@ ANALYZE "r_other_time_ms": "REPLACED", "filtered": 100, "r_filtered": 0, - "attached_condition": "(t2.b,(subquery#2))" + "attached_condition": "(t2.b,t2.b in (subquery#2))" }, "buffer_type": "flat", "buffer_size": "65", "join_type": "BNL", - "attached_condition": "(t2.b,(subquery#2))", + "attached_condition": "(t2.b,t2.b in (subquery#2))", "r_filtered": null, "r_unpack_time_ms": "REPLACED" } @@ -786,21 +786,20 @@ ANALYZE { "query_block": { "select_id": 2, - "r_loops": 2, + "r_loops": 1, "r_total_time_ms": "REPLACED", "nested_loop": [ { "table": { "table_name": "t1", "access_type": "ALL", - "r_loops": 2, + "r_loops": 1, "rows": 2, "r_rows": 2, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", "filtered": 100, - "r_filtered": 0, - "attached_condition": "4 = t1.a" + "r_filtered": 100 } } ] @@ -809,6 +808,8 @@ ANALYZE ] } } +SELECT STRAIGHT_JOIN * FROM t1, t2 WHERE b IN ( SELECT a FROM t1 ); +a b drop table t1,t2; # # MDEV-8864: Server crash #2 in Item_field::print on ANALYZE FORMAT=JSON diff --git a/mysql-test/main/analyze_format_json.test b/mysql-test/main/analyze_format_json.test index 3f3324e9eec..8c0948daac9 100644 --- a/mysql-test/main/analyze_format_json.test +++ b/mysql-test/main/analyze_format_json.test @@ -190,6 +190,7 @@ INSERT INTO t2 VALUES (3),(4); --source include/analyze-format.inc ANALYZE FORMAT=JSON SELECT STRAIGHT_JOIN * FROM t1, t2 WHERE b IN ( SELECT a FROM t1 ); +SELECT STRAIGHT_JOIN * FROM t1, t2 WHERE b IN ( SELECT a FROM t1 ); drop table t1,t2; diff --git a/mysql-test/main/analyze_stmt_privileges2.result b/mysql-test/main/analyze_stmt_privileges2.result index 4a499e0c7ef..0dec4722802 100644 --- a/mysql-test/main/analyze_stmt_privileges2.result +++ b/mysql-test/main/analyze_stmt_privileges2.result @@ -377,13 +377,11 @@ a b EXPLAIN SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) ANALYZE SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 4.00 100.00 100.00 -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 0.00 100.00 100.00 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 3.00 100.00 0.00 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) #------------------------------------------------------------------------ # I/R/U/D/S on the inner view # Expectation: Can run everything @@ -492,13 +490,11 @@ a b EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join) #------------------------------------------------------------------------ # I/R/U/D/S on the outer view # Expectation: Can run everything @@ -599,13 +595,11 @@ a b EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 12 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 12 12.00 100.00 0.00 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join) #======================================================================== # Test: Grant INSERT on the table @@ -1592,13 +1586,11 @@ a b EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join) #------------------------------------------------------------------------ # I/R/U/D/S on the outer view # Expectation: Can run everything: SELECT access to the column `a` @@ -1709,13 +1701,11 @@ a b EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join) #======================================================================== # Test: Grant SELECT, INSERT, UPDATE, DELETE on the table @@ -1941,13 +1931,11 @@ a b EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join) #------------------------------------------------------------------------ # I/R/U/D/S on the outer view # Expectation: Can run everything @@ -2049,13 +2037,11 @@ a b EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join) ######################################################################### # Inner view permission tests @@ -2698,13 +2684,11 @@ a b EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 14 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 14 14.00 100.00 0.00 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join) #------------------------------------------------------------------------ # I/R/U/D/S on the outer view # Expectation: Can run everything @@ -2805,13 +2789,11 @@ a b EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 18 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 18 18.00 100.00 0.00 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join) #======================================================================== # Test: Grant INSERT on the inner view @@ -3988,13 +3970,11 @@ a b EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 35 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 35 35.00 100.00 0.00 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join) #------------------------------------------------------------------------ # I/R/U/D/S on the outer view # Expectation: Can run everything @@ -4095,13 +4075,11 @@ a b EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 39 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 39 39.00 100.00 0.00 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join) ######################################################################### # Outer view permission tests @@ -4615,13 +4593,11 @@ a b EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 39 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 39 39.00 100.00 0.00 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join) #======================================================================== # Test: Grant INSERT on the outer view @@ -5222,13 +5198,11 @@ a b EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 44 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 44 44.00 100.00 0.00 Using where -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join) disconnect con1; connection default; DROP USER 'privtest'@localhost; diff --git a/mysql-test/main/compress.result b/mysql-test/main/compress.result index 24979346149..f5c85d3eb6f 100644 --- a/mysql-test/main/compress.result +++ b/mysql-test/main/compress.result @@ -6,6 +6,7 @@ select * from information_schema.session_status where variable_name= 'COMPRESSIO VARIABLE_NAME VARIABLE_VALUE COMPRESSION ON drop table if exists t1,t2,t3,t4; +set @@default_storage_engine="aria"; CREATE TABLE t1 ( Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL, Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL @@ -606,6 +607,9 @@ explain select t3.t2nr,fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL fld1 NULL NULL NULL 1199 Using where; Using temporary; Using filesort 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.fld1 1 Using where; Using index +# +# Some test with ORDER BY and limit +# explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using filesort @@ -1295,7 +1299,7 @@ companynr tinyint(2) unsigned zerofill NOT NULL default '00', companyname char(30) NOT NULL default '', PRIMARY KEY (companynr), UNIQUE KEY companyname(companyname) -) ENGINE=MyISAM MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames'; +) ENGINE=aria MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames'; select STRAIGHT_JOIN t2.companynr,companyname from t4,t2 where t2.companynr=t4.companynr group by t2.companynr; companynr companyname 00 Unknown @@ -1385,6 +1389,9 @@ explain select companynr,companyname from t4 left join t2 using (companynr) wher id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE delete from t2 where fld1=999999; +# +# Test left join optimization +# explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where @@ -1399,15 +1406,15 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t4 range PRIMARY PRIMARY 1 NULL 12 Using index condition 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t4 range PRIMARY PRIMARY 1 NULL 12 Using index condition 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 and companynr > 0; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t4 range PRIMARY PRIMARY 1 NULL 12 Using index condition 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr is null; id select_type table type possible_keys key key_len ref rows Extra @@ -1423,11 +1430,11 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr is null; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t4 range PRIMARY PRIMARY 1 NULL 12 Using index condition 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0 or companynr > 0; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t4 range PRIMARY PRIMARY 1 NULL 12 Using index condition 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where explain select companynr,companyname from t4 left join t2 using (companynr) where ifnull(companynr,1)>0; id select_type table type possible_keys key key_len ref rows Extra diff --git a/mysql-test/main/costs.result b/mysql-test/main/costs.result index 879d586790b..8349bcf886f 100644 --- a/mysql-test/main/costs.result +++ b/mysql-test/main/costs.result @@ -7,11 +7,11 @@ insert into t1 values(20,2,2,2,2),(21,3,4,5,6); explain select sum(e) as "table_scan" from t1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 12 -Last_query_cost 5.500000 +Last_query_cost 0.012556 explain select sum(a) as "index scan" from t1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL PRIMARY 4 NULL 12 Using index -Last_query_cost 3.202929 +Last_query_cost 0.007441 # # Range scans should be used if we don't examine all rows in the table # @@ -21,71 +21,71 @@ id select_type table type possible_keys key key_len ref rows Extra Last_query_cost 0.000000 explain select count(*) from t1 where a > 0; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 12 Using where; Using index -Last_query_cost 3.202929 +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 12 Using where; Using index +Last_query_cost 0.002795 explain select count(*) from t1 where a > 1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 12 Using where; Using index -Last_query_cost 3.202929 +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 12 Using where; Using index +Last_query_cost 0.002795 explain select count(*) from t1 where a > 2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 11 Using where; Using index -Last_query_cost 2.997685 +Last_query_cost 0.002665 # # Shorter indexes are prefered over longer indexs # explain select sum(a+b) from t1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL ba 9 NULL 12 Using index -Last_query_cost 3.204394 +Last_query_cost 0.007441 explain select count(*) from t1 where b between 5 and 10; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range ba,bda ba 5 NULL 6 Using where; Using index -Last_query_cost 1.872197 +Last_query_cost 0.002015 explain select sum(b+c) from t1 where b between 5 and 6 and c between 5 and 6; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range ba,bda,cba,cb cb 10 NULL 2 Using where; Using index -Last_query_cost 0.970781 +1 SIMPLE t1 range ba,bda,cba,cb cba 10 NULL 2 Using where; Using index +Last_query_cost 0.001494 # Cost of 'd' should be slightly smaller as key 'ba' is longer than 'd' explain select count(*) from t1 where b > 6; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range ba,bda ba 5 NULL 5 Using where; Using index -Last_query_cost 1.646831 +Last_query_cost 0.001885 explain select count(*) from t1 where d > 6; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range d d 5 NULL 5 Using where; Using index -Last_query_cost 1.646343 +Last_query_cost 0.001885 # # Check covering index usage # explain select a,b,c from t1 where a=b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL cba 14 NULL 12 Using where; Using index -Last_query_cost 3.205859 +Last_query_cost 0.007441 # # Prefer ref keys over ranges # explain select count(*) from t1 where b=2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref ba,bda ba 5 const 2 Using index -Last_query_cost 0.950732 +Last_query_cost 0.001059 explain select count(*) from t1 where b=2 and c=2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref ba,bda,cba,cb cb 10 const,const 2 Using index -Last_query_cost 0.950781 +1 SIMPLE t1 ref ba,bda,cba,cb cba 10 const,const 2 Using index +Last_query_cost 0.001059 explain select count(*) from t1 where b=3 and c between 3 and 4; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range ba,bda,cba,cb cb 10 NULL 2 Using where; Using index -Last_query_cost 0.970781 +1 SIMPLE t1 range ba,bda,cba,cb cba 10 NULL 2 Using where; Using index +Last_query_cost 0.001494 # # Prefer eq keys over ref keys # explain select a,b,e from t1 where a=10 or a=11; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using index condition -Last_query_cost 2.520488 +Last_query_cost 0.003126 explain select a,b,e from t1 where d=10 or d=11; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range d d 5 NULL 2 Using index condition -Last_query_cost 2.520537 +Last_query_cost 0.003126 drop table t1; diff --git a/mysql-test/main/cte_nonrecursive.result b/mysql-test/main/cte_nonrecursive.result index 58418cc7d9d..cadaa5f819a 100644 --- a/mysql-test/main/cte_nonrecursive.result +++ b/mysql-test/main/cte_nonrecursive.result @@ -150,16 +150,14 @@ explain with t as (select a from t1 where a<5) select * from t2 where c in (select a from t); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 ALL NULL NULL NULL NULL 4 -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 -3 MATERIALIZED t1 ALL NULL NULL NULL NULL 8 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where; FirstMatch(t2); Using join buffer (flat, BNL join) explain select * from t2 where c in (select a from (select a from t1 where a<5) as t); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 ALL NULL NULL NULL NULL 4 -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t1 ALL NULL NULL NULL NULL 8 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where; FirstMatch(t2); Using join buffer (flat, BNL join) # materialized t is used in a subquery with t as (select count(*) as c from t1 where b >= 'c' group by a) select * from t2 where c in (select c from t); @@ -2300,14 +2298,14 @@ WHERE col1 IN ( SELECT col FROM t ); SELECT * FROM tt; col2 2018-10-01 -2018-10-01 2017-10-01 +2018-10-01 SELECT t4.col1 FROM tt, t4 WHERE t4.col2 = tt.col2 AND t4.col1 IN ( SELECT col FROM t ); col1 -8 4 +8 DROP TABLE t,tt; CALL SP1(); col1 diff --git a/mysql-test/main/cte_recursive.result b/mysql-test/main/cte_recursive.result index a7b73b80845..f6a71b2f53c 100644 --- a/mysql-test/main/cte_recursive.result +++ b/mysql-test/main/cte_recursive.result @@ -692,10 +692,10 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY ref key0 key0 5 c.h_id 2 100.00 1 PRIMARY ref key0 key0 5 c.w_id 2 100.00 3 DERIVED folks ALL NULL NULL NULL NULL 12 100.00 Using where -4 RECURSIVE UNION p ALL NULL NULL NULL NULL 12 100.00 -4 RECURSIVE UNION ALL NULL NULL NULL NULL 2 75.00 Using where; Using join buffer (flat, BNL join) -5 RECURSIVE UNION p ALL NULL NULL NULL NULL 12 100.00 -5 RECURSIVE UNION ALL NULL NULL NULL NULL 2 75.00 Using where; Using join buffer (flat, BNL join) +4 RECURSIVE UNION p ALL NULL NULL NULL NULL 12 100.00 Using where +4 RECURSIVE UNION ref key0 key0 5 test.p.id 2 100.00 +5 RECURSIVE UNION p ALL NULL NULL NULL NULL 12 100.00 Using where +5 RECURSIVE UNION ref key0 key0 5 test.p.id 2 100.00 NULL UNION RESULT ALL NULL NULL NULL NULL NULL NULL 2 DERIVED ALL NULL NULL NULL NULL 12 100.00 Using where Warnings: @@ -3854,8 +3854,8 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where 1 PRIMARY ref key0 key0 23 test.t1.a1 1 FirstMatch(t1) 3 DERIVED t2 const PRIMARY PRIMARY 22 const 1 Using index -4 RECURSIVE UNION ALL NULL NULL NULL NULL 2 Using where -4 RECURSIVE UNION tt2 ref b1 b1 23 cte.a2 2 +4 RECURSIVE UNION tt2 ALL b1 NULL NULL NULL 14 Using where +4 RECURSIVE UNION ref key0 key0 23 test.tt2.b1 1 NULL UNION RESULT ALL NULL NULL NULL NULL NULL analyze format=json select fv from (select t1.a1, f1(t1.a2) fv from t1) dt @@ -3946,30 +3946,31 @@ ANALYZE "nested_loop": [ { "table": { - "table_name": "", + "table_name": "tt2", "access_type": "ALL", + "possible_keys": ["b1"], "r_loops": 1, - "rows": 2, - "r_rows": 1, + "rows": 14, + "r_rows": 14, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", "filtered": 100, "r_filtered": 100, - "attached_condition": "cte.a2 is not null" + "attached_condition": "tt2.b1 is not null" } }, { "table": { - "table_name": "tt2", + "table_name": "", "access_type": "ref", - "possible_keys": ["b1"], - "key": "b1", + "possible_keys": ["key0"], + "key": "key0", "key_length": "23", - "used_key_parts": ["b1"], - "ref": ["cte.a2"], - "r_loops": 1, - "rows": 2, - "r_rows": 1, + "used_key_parts": ["a2"], + "ref": ["test.tt2.b1"], + "r_loops": 14, + "rows": 1, + "r_rows": 0.071428571, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", "filtered": 100, @@ -4032,8 +4033,8 @@ FROM cte JOIN t3 ON t3.tm BETWEEN cte.st AND cte.fn) SELECT t1.* FROM t1 JOIN cte2 USING (YEAR) JOIN cte3 USING (YEAR); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 -1 PRIMARY ref key0 key0 5 const 0 0.00 -1 PRIMARY ref key0 key0 5 const 0 0.00 +1 PRIMARY ref key0 key0 5 const 0 100.00 +1 PRIMARY ref key0 key0 5 const 0 100.00 2 DERIVED t1 system NULL NULL NULL NULL 1 100.00 3 RECURSIVE UNION t1 system NULL NULL NULL NULL 1 100.00 3 RECURSIVE UNION ALL NULL NULL NULL NULL 2 100.00 Using where @@ -4467,9 +4468,9 @@ NULL UNION RESULT ALL NULL NULL NULL NULL NULL 3 DERIVED v ALL NULL NULL NULL NULL 12 Using where 3 DERIVED h ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 3 DERIVED w ALL NULL NULL NULL NULL 12 Using where; Using join buffer (incremental, BNL join) -2 RECURSIVE UNION h ALL NULL NULL NULL NULL 12 -2 RECURSIVE UNION ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) -2 RECURSIVE UNION w ALL NULL NULL NULL NULL 12 Using where; Using join buffer (incremental, BNL join) +2 RECURSIVE UNION h ALL NULL NULL NULL NULL 12 Using where +2 RECURSIVE UNION ref key0 key0 5 test.h.id 2 +2 RECURSIVE UNION w ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) NULL UNION RESULT ALL NULL NULL NULL NULL NULL prepare stmt from "with recursive ancestor_couples(h_id, h_name, h_dob, h_father, h_mother, diff --git a/mysql-test/main/ctype_ucs.result b/mysql-test/main/ctype_ucs.result index ce8e1c2e83b..e53b00806f1 100644 --- a/mysql-test/main/ctype_ucs.result +++ b/mysql-test/main/ctype_ucs.result @@ -1569,7 +1569,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range a a 23 NULL 1 Using where; Using index EXPLAIN SELECT * FROM t1 WHERE a LIKE 'c%'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index a a 23 NULL 31 Using where; Using index +1 SIMPLE t1 range a a 23 NULL 31 Using where; Using index SELECT * FROM t1 WHERE a LIKE 'c%'; a ca @@ -1585,7 +1585,7 @@ ch ALTER TABLE t1 MODIFY a VARCHAR(10) CHARACTER SET ucs2 COLLATE ucs2_croatian_ci; EXPLAIN SELECT * FROM t1 WHERE a LIKE 'd%'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index a a 23 NULL 31 Using where; Using index +1 SIMPLE t1 range a a 23 NULL 31 Using where; Using index SELECT hex(concat('d',_ucs2 0x017E,'%')); hex(concat('d',_ucs2 0x017E,'%')) 0064017E0025 diff --git a/mysql-test/main/delete.result b/mysql-test/main/delete.result index 77a1f8c9813..830f60aa3c7 100644 --- a/mysql-test/main/delete.result +++ b/mysql-test/main/delete.result @@ -92,6 +92,9 @@ select * from t1; a b 1 apple drop table t1; +# +# IGNORE option +# create table t11 (a int NOT NULL, b int, primary key (a)); create table t12 (a int NOT NULL, b int, primary key (a)); create table t2 (a int NOT NULL, b int, primary key (a)); @@ -125,6 +128,11 @@ a b 33 10 0 11 2 12 +explain delete ignore t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t12 ALL PRIMARY NULL NULL NULL 3 +1 PRIMARY t11 eq_ref PRIMARY PRIMARY 4 test.t12.a 1 Using where +2 DEPENDENT SUBQUERY t2 ALL PRIMARY NULL NULL NULL 3 Using where delete ignore t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a); Warnings: Warning 1242 Subquery returns more than 1 row diff --git a/mysql-test/main/delete.test b/mysql-test/main/delete.test index c82420640c2..b95919ee4a4 100644 --- a/mysql-test/main/delete.test +++ b/mysql-test/main/delete.test @@ -106,9 +106,9 @@ delete t1 from t1, t1 as t2 where t1.b = t2.b and t1.a > t2.a; select * from t1; drop table t1; -# -# IGNORE option -# +--echo # +--echo # IGNORE option +--echo # create table t11 (a int NOT NULL, b int, primary key (a)); create table t12 (a int NOT NULL, b int, primary key (a)); create table t2 (a int NOT NULL, b int, primary key (a)); @@ -122,6 +122,7 @@ select * from t2; delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a); select * from t11; select * from t12; +explain delete ignore t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a); delete ignore t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a); select * from t11; select * from t12; diff --git a/mysql-test/main/delete_innodb.result b/mysql-test/main/delete_innodb.result index b9f4c8bdaf5..ae9b415152f 100644 --- a/mysql-test/main/delete_innodb.result +++ b/mysql-test/main/delete_innodb.result @@ -17,7 +17,7 @@ a b EXPLAIN DELETE b FROM t1 AS a JOIN t1 AS b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE a index NULL PRIMARY 255 NULL 3 Using index +1 SIMPLE a ALL NULL NULL NULL NULL 3 1 SIMPLE b ALL NULL NULL NULL NULL 3 DELETE b FROM t1 AS a JOIN t1 AS b; SELECT * FROM t1; diff --git a/mysql-test/main/derived.result b/mysql-test/main/derived.result index b3acbdfce16..422b2b07230 100644 --- a/mysql-test/main/derived.result +++ b/mysql-test/main/derived.result @@ -237,7 +237,7 @@ count(*) explain select count(*) from t1 INNER JOIN (SELECT A.E1, A.E2, A.E3 FROM t1 AS A WHERE A.E3 = (SELECT MAX(B.E3) FROM t1 AS B WHERE A.E2 = B.E2)) AS THEMAX ON t1.E1 = THEMAX.E2 AND t1.E1 = t1.E2; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY ALL NULL NULL NULL NULL 2 -1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 THEMAX.E2 1 Using where 2 DERIVED A ALL NULL NULL NULL NULL 2 Using where 3 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 2 Using where drop table t1; @@ -1346,7 +1346,7 @@ DROP TABLE t1; # Test of "Derived tables and union can now create distinct keys" # create table t1 (a int); -insert into t1 values (100),(100); +insert into t1 values (100),(100),(100),(100),(100),(100),(100),(100),(100),(100); create table duplicates_tbl (a int); insert into duplicates_tbl select seq/100 from seq_1_to_10000; explain @@ -1360,7 +1360,7 @@ where T.a=5 ) as 'A' from t1; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 +1 PRIMARY t1 ALL NULL NULL NULL NULL 10 2 MATERIALIZED ALL NULL NULL NULL NULL 10000 Using where 3 DERIVED duplicates_tbl ALL NULL NULL NULL NULL 10000 select @@ -1375,6 +1375,14 @@ from t1; A 1 1 +1 +1 +1 +1 +1 +1 +1 +1 explain select t1.a = all ( SELECT COUNT(*) @@ -1386,7 +1394,7 @@ where T.a=5 ) as 'A' from t1; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 +1 PRIMARY t1 ALL NULL NULL NULL NULL 10 2 DEPENDENT SUBQUERY ALL NULL NULL NULL NULL 10000 Using where 3 DERIVED duplicates_tbl ALL NULL NULL NULL NULL 10000 select @@ -1401,6 +1409,14 @@ from t1; A 1 1 +1 +1 +1 +1 +1 +1 +1 +1 drop table t1, duplicates_tbl; # # End of 11.0 tests diff --git a/mysql-test/main/derived.test b/mysql-test/main/derived.test index 8c76fe50fe7..3bb52e603f9 100644 --- a/mysql-test/main/derived.test +++ b/mysql-test/main/derived.test @@ -1156,7 +1156,7 @@ DROP TABLE t1; --echo # create table t1 (a int); -insert into t1 values (100),(100); +insert into t1 values (100),(100),(100),(100),(100),(100),(100),(100),(100),(100); create table duplicates_tbl (a int); insert into duplicates_tbl select seq/100 from seq_1_to_10000; diff --git a/mysql-test/main/derived_cond_pushdown.result b/mysql-test/main/derived_cond_pushdown.result index ce0338bee1f..bf3b8591f0f 100644 --- a/mysql-test/main/derived_cond_pushdown.result +++ b/mysql-test/main/derived_cond_pushdown.result @@ -8174,7 +8174,7 @@ EXPLAIN "table_name": "t2", "access_type": "ALL", "rows": 2, - "filtered": 100, + "filtered": 50, "attached_condition": "t2.b = 2", "first_match": "t1" } @@ -8272,7 +8272,7 @@ EXPLAIN "table_name": "t2", "access_type": "ALL", "rows": 2, - "filtered": 100, + "filtered": 50, "attached_condition": "t2.b = 2", "first_match": "t1" } @@ -8799,8 +8799,8 @@ EXPLAIN "table": { "table_name": "", "access_type": "system", - "rows": 1, - "filtered": 100, + "rows": 0, + "filtered": 0, "materialized": { "unique": 1, "query_block": { @@ -8869,8 +8869,8 @@ EXPLAIN "table": { "table_name": "", "access_type": "system", - "rows": 1, - "filtered": 100, + "rows": 0, + "filtered": 0, "materialized": { "unique": 1, "query_block": { @@ -8969,8 +8969,8 @@ EXPLAIN "table": { "table_name": "", "access_type": "system", - "rows": 1, - "filtered": 100, + "rows": 0, + "filtered": 0, "materialized": { "unique": 1, "query_block": { @@ -9036,8 +9036,8 @@ EXPLAIN "table": { "table_name": "", "access_type": "system", - "rows": 1, - "filtered": 100, + "rows": 0, + "filtered": 0, "materialized": { "unique": 1, "query_block": { @@ -9098,8 +9098,8 @@ EXPLAIN "table": { "table_name": "", "access_type": "system", - "rows": 1, - "filtered": 100, + "rows": 0, + "filtered": 0, "materialized": { "unique": 1, "query_block": { @@ -9160,8 +9160,8 @@ EXPLAIN "table": { "table_name": "", "access_type": "system", - "rows": 1, - "filtered": 100, + "rows": 0, + "filtered": 0, "materialized": { "unique": 1, "query_block": { @@ -9224,8 +9224,8 @@ EXPLAIN "table": { "table_name": "", "access_type": "system", - "rows": 1, - "filtered": 100, + "rows": 0, + "filtered": 0, "materialized": { "unique": 1, "query_block": { @@ -9286,8 +9286,8 @@ EXPLAIN "table": { "table_name": "", "access_type": "system", - "rows": 1, - "filtered": 100, + "rows": 0, + "filtered": 0, "materialized": { "unique": 1, "query_block": { @@ -9348,8 +9348,8 @@ EXPLAIN "table": { "table_name": "", "access_type": "system", - "rows": 1, - "filtered": 100, + "rows": 0, + "filtered": 0, "materialized": { "unique": 1, "query_block": { @@ -17526,7 +17526,7 @@ on t1.a=t.a where t1.b < 3; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 range idx_b idx_b 5 NULL 4 100.00 Using index condition; Using where -1 PRIMARY ref key0 key0 5 test.t1.a 2 100.00 +1 PRIMARY ref key0 key0 5 test.t1.a 2 50.00 2 LATERAL DERIVED t2 ref idx_a idx_a 5 test.t1.a 1 100.00 Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`t`.`s` AS `s`,`t`.`m` AS `m` from `test`.`t1` join (/* select#2 */ select `test`.`t2`.`a` AS `a`,sum(`test`.`t2`.`b`) AS `s`,min(`test`.`t2`.`c`) AS `m` from `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` group by `test`.`t2`.`a`) `t` where `t`.`a` = `test`.`t1`.`a` and `test`.`t1`.`b` < 3 @@ -17564,7 +17564,7 @@ EXPLAIN "used_key_parts": ["a"], "ref": ["test.t1.a"], "rows": 2, - "filtered": 100, + "filtered": 50, "materialized": { "lateral": 1, "query_block": { @@ -17647,7 +17647,7 @@ on t1.a=t.a where t1.b <= 5; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL idx_b NULL NULL NULL 12 83.33 Using where -1 PRIMARY ref key0 key0 5 test.t1.a 2 100.00 +1 PRIMARY ref key0 key0 5 test.t1.a 2 50.00 2 LATERAL DERIVED t2 ref idx_a idx_a 5 test.t1.a 1 100.00 Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`t`.`s` AS `s`,`t`.`m` AS `m` from `test`.`t1` join (/* select#2 */ select `test`.`t2`.`a` AS `a`,sum(`test`.`t2`.`b`) AS `s`,min(`test`.`t2`.`b`) AS `m` from `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` group by `test`.`t2`.`a`) `t` where `t`.`a` = `test`.`t1`.`a` and `test`.`t1`.`b` <= 5 @@ -17681,7 +17681,7 @@ EXPLAIN "used_key_parts": ["a"], "ref": ["test.t1.a"], "rows": 2, - "filtered": 100, + "filtered": 50, "materialized": { "lateral": 1, "query_block": { @@ -17762,7 +17762,7 @@ from t1 left join on t1.a=t.a; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 12 100.00 -1 PRIMARY ref key0 key0 5 test.t1.a 2 100.00 Using where +1 PRIMARY ref key0 key0 5 test.t1.a 2 50.00 Using where 2 LATERAL DERIVED t2 ref idx_a idx_a 5 test.t1.a 1 100.00 Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`t`.`max` AS `max`,`t`.`min` AS `min` from `test`.`t1` left join (/* select#2 */ select `test`.`t2`.`a` AS `a`,max(`test`.`t2`.`b`) AS `max`,min(`test`.`t2`.`b`) AS `min` from `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` group by `test`.`t2`.`a`) `t` on(`t`.`a` = `test`.`t1`.`a` and `test`.`t1`.`a` is not null) where 1 @@ -17794,7 +17794,7 @@ EXPLAIN "used_key_parts": ["a"], "ref": ["test.t1.a"], "rows": 2, - "filtered": 100, + "filtered": 50, "attached_condition": "trigcond(trigcond(t1.a is not null))", "materialized": { "lateral": 1, @@ -17953,10 +17953,10 @@ on t3.a=t.a and t3.c=t.c where t3.b <= 15; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t3 ALL idx_b NULL NULL NULL 12 83.33 Using where -1 PRIMARY ref key0 key0 133 test.t3.a,test.t3.c 4 100.00 -2 DERIVED t4 ALL idx NULL NULL NULL 40 100.00 Using temporary; Using filesort +1 PRIMARY ref key0 key0 133 test.t3.a,test.t3.c 2 50.00 +2 LATERAL DERIVED t4 ref idx idx 133 test.t3.a,test.t3.c 1 100.00 Warnings: -Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`c` AS `c`,`t`.`max` AS `max`,`t`.`min` AS `min` from `test`.`t3` join (/* select#2 */ select `test`.`t4`.`a` AS `a`,`test`.`t4`.`c` AS `c`,max(`test`.`t4`.`b`) AS `max`,min(`test`.`t4`.`b`) AS `min` from `test`.`t4` group by `test`.`t4`.`a`,`test`.`t4`.`c`) `t` where `t`.`a` = `test`.`t3`.`a` and `t`.`c` = `test`.`t3`.`c` and `test`.`t3`.`b` <= 15 +Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`c` AS `c`,`t`.`max` AS `max`,`t`.`min` AS `min` from `test`.`t3` join (/* select#2 */ select `test`.`t4`.`a` AS `a`,`test`.`t4`.`c` AS `c`,max(`test`.`t4`.`b`) AS `max`,min(`test`.`t4`.`b`) AS `min` from `test`.`t4` where `test`.`t4`.`a` = `test`.`t3`.`a` and `test`.`t4`.`c` = `test`.`t3`.`c` group by `test`.`t4`.`a`,`test`.`t4`.`c`) `t` where `t`.`a` = `test`.`t3`.`a` and `t`.`c` = `test`.`t3`.`c` and `test`.`t3`.`b` <= 15 explain format=json select t3.a,t3.c,t.max,t.min from t3 join (select a, c, max(b) max, min(b) min from t4 group by a,c) t @@ -17986,27 +17986,28 @@ EXPLAIN "key_length": "133", "used_key_parts": ["a", "c"], "ref": ["test.t3.a", "test.t3.c"], - "rows": 4, - "filtered": 100, + "rows": 2, + "filtered": 50, "materialized": { + "lateral": 1, "query_block": { "select_id": 2, - "filesort": { - "sort_key": "t4.a, t4.c", - "temporary_table": { - "nested_loop": [ - { - "table": { - "table_name": "t4", - "access_type": "ALL", - "possible_keys": ["idx"], - "rows": 40, - "filtered": 100 - } - } - ] + "outer_ref_condition": "t3.a is not null and t3.c is not null", + "nested_loop": [ + { + "table": { + "table_name": "t4", + "access_type": "ref", + "possible_keys": ["idx"], + "key": "idx", + "key_length": "133", + "used_key_parts": ["a", "c"], + "ref": ["test.t3.a", "test.t3.c"], + "rows": 1, + "filtered": 100 + } } - } + ] } } } @@ -18126,10 +18127,10 @@ on t3.a=t.a and t3.c=t.c where t3.b <= 15; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t3 ALL idx_b NULL NULL NULL 12 83.33 Using where -1 PRIMARY ref key0 key0 133 test.t3.a,test.t3.c 4 100.00 -2 DERIVED t4 ALL idx NULL NULL NULL 40 100.00 Using temporary; Using filesort +1 PRIMARY ref key0 key0 133 test.t3.a,test.t3.c 2 50.00 +2 LATERAL DERIVED t4 ref idx idx 133 test.t3.a,test.t3.c 1 100.00 Warnings: -Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`c` AS `c`,`t`.`max` AS `max`,`t`.`min` AS `min` from `test`.`t3` join (/* select#2 */ select `test`.`t4`.`a` AS `a`,`test`.`t4`.`c` AS `c`,max(`test`.`t4`.`b`) AS `max`,min(`test`.`t4`.`b`) AS `min` from `test`.`t4` group by `test`.`t4`.`c`,`test`.`t4`.`a`) `t` where `t`.`a` = `test`.`t3`.`a` and `t`.`c` = `test`.`t3`.`c` and `test`.`t3`.`b` <= 15 +Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`c` AS `c`,`t`.`max` AS `max`,`t`.`min` AS `min` from `test`.`t3` join (/* select#2 */ select `test`.`t4`.`a` AS `a`,`test`.`t4`.`c` AS `c`,max(`test`.`t4`.`b`) AS `max`,min(`test`.`t4`.`b`) AS `min` from `test`.`t4` where `test`.`t4`.`a` = `test`.`t3`.`a` and `test`.`t4`.`c` = `test`.`t3`.`c` group by `test`.`t4`.`c`,`test`.`t4`.`a`) `t` where `t`.`a` = `test`.`t3`.`a` and `t`.`c` = `test`.`t3`.`c` and `test`.`t3`.`b` <= 15 explain format=json select t3.a,t3.c,t.max,t.min from t3 join (select a, c, max(b) max, min(b) min from t4 group by c,a) t @@ -18159,27 +18160,28 @@ EXPLAIN "key_length": "133", "used_key_parts": ["a", "c"], "ref": ["test.t3.a", "test.t3.c"], - "rows": 4, - "filtered": 100, + "rows": 2, + "filtered": 50, "materialized": { + "lateral": 1, "query_block": { "select_id": 2, - "filesort": { - "sort_key": "t4.c, t4.a", - "temporary_table": { - "nested_loop": [ - { - "table": { - "table_name": "t4", - "access_type": "ALL", - "possible_keys": ["idx"], - "rows": 40, - "filtered": 100 - } - } - ] + "outer_ref_condition": "t3.a is not null and t3.c is not null", + "nested_loop": [ + { + "table": { + "table_name": "t4", + "access_type": "ref", + "possible_keys": ["idx"], + "key": "idx", + "key_length": "133", + "used_key_parts": ["a", "c"], + "ref": ["test.t3.a", "test.t3.c"], + "rows": 1, + "filtered": 100 + } } - } + ] } } } @@ -19022,7 +19024,7 @@ a c explain extended SELECT * FROM t4 WHERE c IN ( SELECT c FROM v1 ) and a < 2; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t4 range a a 5 NULL 1 100.00 Using index condition; Using where -1 PRIMARY ref key0 key0 128 test.t4.c 2 100.00 FirstMatch(t4) +1 PRIMARY ref key0 key0 128 test.t4.c 2 50.00 FirstMatch(t4) 3 LATERAL DERIVED t3 ref c c 128 test.t4.c 2 100.00 3 LATERAL DERIVED eq_ref distinct_key distinct_key 4 func 1 100.00 4 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 100.00 @@ -19059,7 +19061,7 @@ EXPLAIN "used_key_parts": ["c"], "ref": ["test.t4.c"], "rows": 2, - "filtered": 100, + "filtered": 50, "first_match": "t4", "materialized": { "lateral": 1, @@ -19413,7 +19415,7 @@ GROUP BY t1.b,t2.c) dt WHERE t3.d = dt.b; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t3 ALL NULL NULL NULL NULL 5 100.00 Using where -1 PRIMARY ref key0 key0 5 test.t3.d 2 100.00 +1 PRIMARY ref key0 key0 5 test.t3.d 2 50.00 2 LATERAL DERIVED t1 ref idx_b idx_b 5 test.t3.d 1 100.00 Using index; Using temporary; Using filesort 2 LATERAL DERIVED t2 ALL NULL NULL NULL NULL 5 100.00 Using join buffer (flat, BNL join) Warnings: @@ -19503,7 +19505,7 @@ id a explain extended select id, a from t1 where id in (select id from v1); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 20 100.00 -1 PRIMARY ref key0 key0 4 test.t1.id 2 100.00 FirstMatch(t1) +1 PRIMARY ref key0 key0 4 test.t1.id 2 50.00 FirstMatch(t1) 3 DERIVED t1 ALL PRIMARY NULL NULL NULL 20 100.00 Using temporary; Using filesort 3 DERIVED t2 ref ro_id ro_id 4 test.t1.id 1 100.00 Using where Warnings: @@ -19541,7 +19543,7 @@ on (t1.id = t2.ro_id AND t2.flag = 1) group by t1.id) dt); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 20 100.00 -1 PRIMARY ref key1 key1 4 test.t1.id 2 100.00 FirstMatch(t1) +1 PRIMARY ref key1 key1 4 test.t1.id 2 50.00 FirstMatch(t1) 3 DERIVED t1 ALL PRIMARY NULL NULL NULL 20 100.00 Using temporary; Using filesort 3 DERIVED t2 ref ro_id ro_id 4 test.t1.id 1 100.00 Using where Warnings: @@ -19724,6 +19726,7 @@ insert into t1 values (17,1),(17,3010),(17,3013),(17,3053),(21,2446),(21,2467),(21,2); create table t2 (a int) engine=myisam; insert into t2 values (1),(2),(3),(1000),(2000),(3000); +insert into t2 select 5000 from seq_5000_to_6000; create table t3 (id int) engine=myisam; insert into t3 values (1),(2); analyze table t1,t2,t3; @@ -19747,8 +19750,8 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ref a a 5 test.t3.id 1 1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY ref key0 key0 5 test.t3.id 2 -3 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 -2 DERIVED cp2 index NULL a 5 NULL 7 Using index +3 MATERIALIZED t2 ALL NULL NULL NULL NULL 1007 +2 DERIVED cp2 range NULL a 5 NULL 7 Using index for group-by explain format=json select * from t1, (select a from t1 cp2 group by a) dt, t3 where dt.a = t1.a and t1.a = t3.id and t1.a in (select a from t2); EXPLAIN @@ -19798,7 +19801,7 @@ EXPLAIN "table": { "table_name": "t2", "access_type": "ALL", - "rows": 6, + "rows": 1007, "filtered": 100 } } @@ -19825,13 +19828,13 @@ EXPLAIN { "table": { "table_name": "cp2", - "access_type": "index", + "access_type": "range", "key": "a", "key_length": "5", "used_key_parts": ["a"], "rows": 7, "filtered": 100, - "using_index": true + "using_index_for_group_by": true } } ] @@ -19855,7 +19858,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ref a a 5 test.t3.id 1 1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY ref key0 key0 5 test.t3.id 2 -3 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 +3 MATERIALIZED t2 ALL NULL NULL NULL NULL 1007 2 LATERAL DERIVED cp2 ref a a 5 test.t1.a 1 Using where; Using index explain format=json select * from t1, (select a from t1 cp2 group by a) dt, t3 where dt.a = t1.a and t1.a = t3.id and t1.a in (select a from t2); @@ -19906,7 +19909,7 @@ EXPLAIN "table": { "table_name": "t2", "access_type": "ALL", - "rows": 6, + "rows": 1007, "filtered": 100 } } @@ -19968,7 +19971,7 @@ id a a id deallocate prepare stmt; drop table t1,t2,t3; # -# MDEV-MDEV-27132: Splittable derived with equality in WHERE +# MDEV-27132: Splittable derived with equality in WHERE # CREATE TABLE t1 ( id int PRIMARY KEY @@ -20009,6 +20012,7 @@ INSERT INTO t2(deleted, t1_id, email, reporting_person) SELECT deleted, t1_id+80000, email, reporting_person FROM t2; INSERT INTO t2(deleted, t1_id, email, reporting_person) SELECT deleted, t1_id+160000, email, reporting_person FROM t2; +insert into t2 (id,t1_id) select -seq,-seq from seq_1_to_1000; CREATE TABLE t3 ( id int PRIMARY KEY, deleted int, @@ -20059,10 +20063,10 @@ JOIN (SELECT t1_id FROM t2 WHERE reporting_person = 1 GROUP BY t1_id) tx ON tx.t1_id = t1.id WHERE t1.id BETWEEN 200 AND 100000; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t3 index t1_id t1_id 15 NULL 47 Using where; Using index +1 PRIMARY t3 range t1_id t1_id 5 NULL 47 Using where; Using index 1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t3.t1_id 1 Using index 1 PRIMARY ref key0 key0 5 test.t3.t1_id 2 -2 LATERAL DERIVED t2 ref t1_id t1_id 5 test.t1.id 3 Using index condition; Using where +2 LATERAL DERIVED t2 ref t1_id t1_id 5 test.t1.id 1 Using index condition; Using where EXPLAIN FORMAT=JSON SELECT t1.id FROM t1 JOIN t3 @@ -20078,11 +20082,11 @@ EXPLAIN { "table": { "table_name": "t3", - "access_type": "index", + "access_type": "range", "possible_keys": ["t1_id"], "key": "t1_id", - "key_length": "15", - "used_key_parts": ["t1_id", "YEAR", "quarter"], + "key_length": "5", + "used_key_parts": ["t1_id"], "rows": 47, "filtered": 100, "attached_condition": "t3.t1_id between 200 and 100000 and t3.t1_id is not null", @@ -20113,7 +20117,7 @@ EXPLAIN "used_key_parts": ["t1_id"], "ref": ["test.t3.t1_id"], "rows": 2, - "filtered": 100, + "filtered": 50, "materialized": { "lateral": 1, "query_block": { @@ -20128,8 +20132,8 @@ EXPLAIN "key_length": "5", "used_key_parts": ["t1_id"], "ref": ["test.t1.id"], - "rows": 3, - "filtered": 59.09090805, + "rows": 1, + "filtered": 34.55045319, "index_condition": "t2.t1_id between 200 and 100000 and t2.t1_id = t3.t1_id", "attached_condition": "t2.reporting_person = 1" } @@ -20151,6 +20155,18 @@ JOIN (SELECT t1_id FROM t2 WHERE reporting_person = 1 GROUP BY t1_id) tx ON tx.t1_id = t1.id WHERE t1.id BETWEEN 200 AND 100000; id +EXPLAIN SELECT t1.id +FROM t1 +JOIN t3 +ON t3.t1_id = t1.id +JOIN (SELECT t1_id FROM t2 WHERE reporting_person = 1 GROUP BY t1_id) tx +ON tx.t1_id = t1.id +WHERE t1.id BETWEEN 200 AND 100000; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t3 range t1_id t1_id 5 NULL 47 Using where; Using index +1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t3.t1_id 1 Using index +1 PRIMARY ref key0 key0 5 test.t3.t1_id 10 +2 DERIVED t2 ALL t1_id NULL NULL NULL 2408 Using where; Using temporary; Using filesort set optimizer_switch='split_materialized=default'; DROP TABLE t1,t2,t3; # @@ -20273,7 +20289,7 @@ ON from_agg_items.charge_id = charges.id AND from_agg_items.ledger_id = charges.from_ledger_id WHERE charges.to_ledger_id = 2; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY charges ALL PRIMARY,fk_charge_from_ledger,fk_charge_to_ledger NULL NULL NULL 20 Using where +1 PRIMARY charges ref PRIMARY,fk_charge_from_ledger,fk_charge_to_ledger fk_charge_to_ledger 8 const 8 1 PRIMARY ref key0 key0 17 test.charges.from_ledger_id,test.charges.id 2 2 LATERAL DERIVED transaction_items ref fk_items_transaction,fk_items_charge fk_items_charge 9 test.charges.id 2 2 LATERAL DERIVED transactions eq_ref PRIMARY,fk_transactions_ledger PRIMARY 8 test.transaction_items.transaction_id 1 Using where @@ -20303,15 +20319,18 @@ EXPLAIN { "table": { "table_name": "charges", - "access_type": "ALL", + "access_type": "ref", "possible_keys": [ "PRIMARY", "fk_charge_from_ledger", "fk_charge_to_ledger" ], - "rows": 20, - "filtered": 40, - "attached_condition": "charges.to_ledger_id = 2" + "key": "fk_charge_to_ledger", + "key_length": "8", + "used_key_parts": ["to_ledger_id"], + "ref": ["const"], + "rows": 8, + "filtered": 100 } }, { @@ -20412,10 +20431,10 @@ ON from_agg_items.charge_id = charges.id AND from_agg_items.ledger_id = charges.from_ledger_id WHERE charges.to_ledger_id = 2; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY charges ALL PRIMARY,fk_charge_from_ledger,fk_charge_to_ledger NULL NULL NULL 20 Using where +1 PRIMARY charges ref PRIMARY,fk_charge_from_ledger,fk_charge_to_ledger fk_charge_to_ledger 8 const 8 1 PRIMARY ref key0 key0 17 test.charges.from_ledger_id,test.charges.id 4 -2 DERIVED transactions ALL PRIMARY NULL NULL NULL 40 Using temporary; Using filesort -2 DERIVED transaction_items ref fk_items_transaction fk_items_transaction 8 test.transactions.id 1 +2 DERIVED transaction_items ALL fk_items_transaction NULL NULL NULL 40 Using temporary; Using filesort +2 DERIVED transactions eq_ref PRIMARY PRIMARY 8 test.transaction_items.transaction_id 1 INSERT INTO charges (id, from_ledger_id, to_ledger_id, amount) VALUES (101, 4, 2, 100), (102, 7, 2, 200); set optimizer_switch='split_materialized=on'; @@ -20467,7 +20486,7 @@ ON from_agg_items.charge_id = charges.id AND from_agg_items.ledger_id = charges.from_ledger_id WHERE charges.to_ledger_id = 2; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY charges ALL fk_charge_to_ledger NULL NULL NULL 20 Using where +1 PRIMARY charges ref fk_charge_to_ledger fk_charge_to_ledger 8 const 10 1 PRIMARY ref key0 key0 18 test.charges.from_ledger_id,test.charges.id 2 2 LATERAL DERIVED transaction_items ref fk_items_transaction,fk_items_charge fk_items_charge 9 test.charges.id 2 2 LATERAL DERIVED transactions eq_ref PRIMARY,fk_transactions_ledger PRIMARY 8 test.transaction_items.transaction_id 1 Using where @@ -20497,11 +20516,14 @@ EXPLAIN { "table": { "table_name": "charges", - "access_type": "ALL", + "access_type": "ref", "possible_keys": ["fk_charge_to_ledger"], - "rows": 20, - "filtered": 50, - "attached_condition": "charges.to_ledger_id = 2" + "key": "fk_charge_to_ledger", + "key_length": "8", + "used_key_parts": ["to_ledger_id"], + "ref": ["const"], + "rows": 10, + "filtered": 100 } }, { @@ -20604,10 +20626,10 @@ ON from_agg_items.charge_id = charges.id AND from_agg_items.ledger_id = charges.from_ledger_id WHERE charges.to_ledger_id = 2; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY charges ALL fk_charge_to_ledger NULL NULL NULL 20 Using where +1 PRIMARY charges ref fk_charge_to_ledger fk_charge_to_ledger 8 const 10 1 PRIMARY ref key0 key0 18 test.charges.from_ledger_id,test.charges.id 4 -2 DERIVED transactions ALL PRIMARY NULL NULL NULL 40 Using temporary; Using filesort -2 DERIVED transaction_items ref fk_items_transaction fk_items_transaction 8 test.transactions.id 1 +2 DERIVED transaction_items ALL fk_items_transaction NULL NULL NULL 40 Using temporary; Using filesort +2 DERIVED transactions eq_ref PRIMARY PRIMARY 8 test.transaction_items.transaction_id 1 set optimizer_switch='split_materialized=default'; DROP TABLE transaction_items; DROP TABLE transactions; diff --git a/mysql-test/main/derived_cond_pushdown.test b/mysql-test/main/derived_cond_pushdown.test index 83e784c3450..55ccd9b4839 100644 --- a/mysql-test/main/derived_cond_pushdown.test +++ b/mysql-test/main/derived_cond_pushdown.test @@ -3602,6 +3602,7 @@ insert into t1 values create table t2 (a int) engine=myisam; insert into t2 values (1),(2),(3),(1000),(2000),(3000); +insert into t2 select 5000 from seq_5000_to_6000; create table t3 (id int) engine=myisam; insert into t3 values (1),(2); @@ -3630,7 +3631,7 @@ deallocate prepare stmt; drop table t1,t2,t3; --echo # ---echo # MDEV-MDEV-27132: Splittable derived with equality in WHERE +--echo # MDEV-27132: Splittable derived with equality in WHERE --echo # CREATE TABLE t1 ( @@ -3677,6 +3678,9 @@ INSERT INTO t2(deleted, t1_id, email, reporting_person) INSERT INTO t2(deleted, t1_id, email, reporting_person) SELECT deleted, t1_id+160000, email, reporting_person FROM t2; +insert into t2 (id,t1_id) select -seq,-seq from seq_1_to_1000; + + CREATE TABLE t3 ( id int PRIMARY KEY, deleted int, @@ -3724,6 +3728,7 @@ eval EXPLAIN FORMAT=JSON $q; set optimizer_switch='split_materialized=off'; eval $q; +eval EXPLAIN $q; set optimizer_switch='split_materialized=default'; diff --git a/mysql-test/main/derived_opt.result b/mysql-test/main/derived_opt.result index 051360ffe8c..7d02990fb5d 100644 --- a/mysql-test/main/derived_opt.result +++ b/mysql-test/main/derived_opt.result @@ -111,7 +111,7 @@ count(*) explain select count(*) from t1 INNER JOIN (SELECT A.E1, A.E2, A.E3 FROM t1 AS A WHERE A.E3 = (SELECT MAX(B.E3) FROM t1 AS B WHERE A.E2 = B.E2)) AS THEMAX ON t1.E1 = THEMAX.E2 AND t1.E1 = t1.E2; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY A ALL NULL NULL NULL NULL 2 Using where -1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.A.E2 1 Using where 3 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 2 Using where drop table t1; create table t1 (a int); diff --git a/mysql-test/main/derived_split_innodb.result b/mysql-test/main/derived_split_innodb.result index be3de7dbc02..c326a895a38 100644 --- a/mysql-test/main/derived_split_innodb.result +++ b/mysql-test/main/derived_split_innodb.result @@ -21,7 +21,7 @@ WHERE t.n1 = t1.n1 AND t.n2 = t1.n2 AND c1 = 'a' GROUP BY n1; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ref c1,n1_c1_n2 c1 1 const 2 Using index condition; Using where; Using temporary; Using filesort 1 PRIMARY ref key0 key0 8 test.t1.n1,test.t1.n2 2 -2 DERIVED t1 ref c1,n1_c1_n2 c1 1 const 2 Using index condition; Using where; Using temporary; Using filesort +2 LATERAL DERIVED t1 ref c1,n1_c1_n2 n1_c1_n2 4 test.t1.n1 1 Using where; Using index SELECT t1.n1 FROM t1, (SELECT n1, n2 FROM t1 WHERE c1 = 'a' GROUP BY n1) as t WHERE t.n1 = t1.n1 AND t.n2 = t1.n2 AND c1 = 'a' GROUP BY n1; n1 @@ -128,8 +128,8 @@ left join (v1 join t1 as t on v1.f1=t.f1 and t.f2 = null) on t1.f1=t.f1; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t const f2 NULL NULL NULL 1 Impossible ON condition -1 PRIMARY const key1 NULL NULL NULL 1 Impossible ON condition +1 PRIMARY t const f2 NULL NULL NULL 0 Impossible ON condition +1 PRIMARY const key1 NULL NULL NULL 0 Impossible ON condition 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 2 DERIVED t2 ALL PRIMARY NULL NULL NULL 3 Using temporary; Using filesort set statement optimizer_switch='split_materialized=off' for explain select t.f2 @@ -138,8 +138,8 @@ left join (v1 join t1 as t on v1.f1=t.f1 and t.f2 = null) on t1.f1=t.f1; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t const f2 NULL NULL NULL 1 Impossible ON condition -1 PRIMARY const key1 NULL NULL NULL 1 Impossible ON condition +1 PRIMARY t const f2 NULL NULL NULL 0 Impossible ON condition +1 PRIMARY const key1 NULL NULL NULL 0 Impossible ON condition 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 3 DERIVED t2 index NULL PRIMARY 4 NULL 3 drop view v1; @@ -157,26 +157,26 @@ set statement optimizer_switch='split_materialized=off' for EXPLAIN SELECT * FROM t1 JOIN -(SELECT t1.a, t1.b FROM t1, t2 WHERE t1.b = t2.c GROUP BY t1.a, t1.b) as dt +(SELECT t1_inner.a, t1_inner.b FROM t1 as t1_inner, t2 as t2_inner WHERE t1_inner.b = t2_inner.c GROUP BY t1_inner.a, t1_inner.b) as dt WHERE t1.a = dt.a; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 index a,a_2 a_2 10 NULL 6 Using where; Using index 1 PRIMARY ref key0 key0 5 test.t1.a 2 -3 DERIVED t1 index NULL a_2 10 NULL 6 Using where; Using index -3 DERIVED t2 ref c c 5 test.t1.b 1 Using index +3 DERIVED t1_inner index NULL a_2 10 NULL 6 Using where; Using index +3 DERIVED t2_inner ref c c 5 test.t1_inner.b 1 Using index set statement optimizer_switch='split_materialized=on' for EXPLAIN SELECT * FROM t1 JOIN -(SELECT t1.a, t1.b FROM t1, t2 WHERE t1.b = t2.c GROUP BY t1.a, t1.b) as dt +(SELECT t1_inner.a, t1_inner.b FROM t1 as t1_inner, t2 as t2_inner WHERE t1_inner.b = t2_inner.c GROUP BY t1_inner.a, t1_inner.b) as dt WHERE t1.a = dt.a; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 index a,a_2 a_2 10 NULL 6 Using where; Using index 1 PRIMARY ref key0 key0 5 test.t1.a 2 -3 DERIVED t1 index a,a_2 a_2 10 NULL 6 Using where; Using index; Using temporary; Using filesort -3 DERIVED t2 ref c c 5 test.t1.b 1 Using index +3 DERIVED t1_inner index a,a_2 a_2 10 NULL 6 Using where; Using index +3 DERIVED t2_inner ref c c 5 test.t1_inner.b 1 Using index DROP TABLE t1, t2; # # Bug mdev-25714: usage non-splitting covering index is cheaper than @@ -210,7 +210,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 1 1 PRIMARY t1 ref idx idx 4 test.t2.id 1 1 PRIMARY ref key0 key0 9 test.t2.id,test.t1.id 2 -2 LATERAL DERIVED t3 ref idx1,idx2 idx2 4 test.t1.itemid 1 Using index condition; Using where +2 DERIVED t3 ref idx1,idx2 idx1 4 const 5 Using where; Using index select t1.id, t1.itemid, dt.id, t2.id from t1, (select itemid, max(id) as id from t3 where userid = 1 group by itemid) dt, diff --git a/mysql-test/main/derived_view.result b/mysql-test/main/derived_view.result index a64894441c8..dd74d2953b0 100644 --- a/mysql-test/main/derived_view.result +++ b/mysql-test/main/derived_view.result @@ -1216,11 +1216,11 @@ SELECT * FROM t3 WHERE t3.a IN (SELECT v1.a FROM v1, t2 WHERE t2.a = v1.b); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t3 ALL NULL NULL NULL NULL 4 100.00 Using where -2 DEPENDENT SUBQUERY ref key1 key1 5 func 2 100.00 -2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY ref key0 key0 5 test.t2.a 2 100.00 Using where 3 DERIVED t1 ALL NULL NULL NULL NULL 3 100.00 Using temporary; Using filesort Warnings: -Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a` from `test`.`t3` where <`test`.`t3`.`a`>((`test`.`t3`.`a`,(/* select#2 */ select `v1`.`a` from `test`.`v1` join `test`.`t2` where `test`.`t2`.`a` = `v1`.`b` and (`test`.`t3`.`a`) = `v1`.`a`))) +Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a` from `test`.`t3` where <`test`.`t3`.`a`>((`test`.`t3`.`a`,(/* select#2 */ select `v1`.`a` from `test`.`v1` join `test`.`t2` where `v1`.`b` = `test`.`t2`.`a` and (`test`.`t3`.`a`) = `v1`.`a`))) SELECT * FROM t3 WHERE t3.a IN (SELECT v1.a FROM v1, t2 WHERE t2.a = v1.b); a @@ -1248,9 +1248,9 @@ SELECT t.f1 AS f FROM (SELECT DISTINCT t1.* FROM t1,t2 WHERE t2.f2 = t1.f2) t,t3,t4 WHERE t4.f2 = t3.f2 AND t4.f2 = t.f1 ORDER BY f; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY ALL NULL NULL NULL NULL 2 Using where; Using filesort -1 PRIMARY t4 ref f2 f2 4 t.f1 1 Using index -1 PRIMARY t3 ref f2 f2 4 t.f1 2 Using index +1 PRIMARY t4 index f2 f2 9 NULL 2 Using where; Using index; Using temporary; Using filesort +1 PRIMARY t3 ref f2 f2 4 test.t4.f2 2 Using index +1 PRIMARY ref key0 key0 4 test.t4.f2 2 2 DERIVED t2 system NULL NULL NULL NULL 1 Using temporary 2 DERIVED t1 ref f2 f2 4 const 2 Using where SELECT t.f1 AS f @@ -1917,7 +1917,7 @@ WHERE t2.c = v1.c AND t2.c = v1.b AND v1.b = t3.c); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 system NULL NULL NULL NULL 1 1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where -1 PRIMARY ALL NULL NULL NULL NULL 3 Using where; Start temporary; End temporary +1 PRIMARY ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t3) 3 DERIVED t1 ALL NULL NULL NULL NULL 3 Using where SELECT * FROM t3 WHERE t3.b IN (SELECT v1.b FROM v1, t2 @@ -2370,7 +2370,7 @@ GROUP BY TABLE_SCHEMA) AS UNIQUES ON ( COLUMNS.TABLE_SCHEMA = UNIQUES.TABLE_SCHEMA); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY COLUMNS ALL NULL NULL NULL NULL NULL Open_frm_only; Scanned all databases -1 PRIMARY ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +1 PRIMARY ref key0 key0 194 information_schema.COLUMNS.TABLE_SCHEMA 10 2 DERIVED STATISTICS ALL NULL NULL NULL NULL NULL Open_frm_only; Scanned all databases; Using filesort SELECT COUNT(*) > 0 FROM INFORMATION_SCHEMA.COLUMNS @@ -2463,8 +2463,6 @@ SELECT * FROM t1; a 1 1 -1 -1 drop table t1,t2; set optimizer_switch=@save968720_optimizer_switch; # @@ -3081,7 +3079,7 @@ SELECT * FROM t1 LEFT JOIN v2 ON t1.id=v2.order_pk; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index 1 PRIMARY ref key0 key0 5 test.t1.id 2 100.00 -2 DERIVED t1 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index; Using filesort +2 LATERAL DERIVED t1 eq_ref PRIMARY PRIMARY 4 test.t1.id 1 100.00 Using where; Using index Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`v2`.`order_pk` AS `order_pk` from `test`.`t1` left join `test`.`v2` on(`v2`.`order_pk` = `test`.`t1`.`id`) where 1 SELECT * FROM t1 LEFT JOIN v3 ON t1.id=v3.order_pk; @@ -3095,7 +3093,7 @@ SELECT * FROM t1 LEFT JOIN v3 ON t1.id=v3.order_pk; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index 1 PRIMARY ref key0 key0 5 test.t1.id 2 100.00 -2 DERIVED t1 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index; Using filesort +2 LATERAL DERIVED t1 eq_ref PRIMARY PRIMARY 4 test.t1.id 1 100.00 Using where; Using index Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`v3`.`order_pk` AS `order_pk` from `test`.`t1` left join `test`.`v3` on(`v3`.`order_pk` = `test`.`t1`.`id`) where 1 DROP VIEW v1,v2,v3; diff --git a/mysql-test/main/desc_index_range.result b/mysql-test/main/desc_index_range.result index a540efe33d6..1dc17702a9f 100644 --- a/mysql-test/main/desc_index_range.result +++ b/mysql-test/main/desc_index_range.result @@ -146,7 +146,7 @@ CREATE TABLE t1 (p int NOT NULL, a int NOT NULL, PRIMARY KEY (p,a desc)); insert into t1 select 2,seq from seq_0_to_1000; EXPLAIN select MIN(a) from t1 where p = 2 group by p; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index PRIMARY PRIMARY 8 NULL 1001 Using where; Using index +1 SIMPLE t1 ref PRIMARY PRIMARY 4 const 1000 Using index select json_detailed(json_extract(trace, '$**.potential_group_range_indexes')) from information_schema.optimizer_trace; json_detailed(json_extract(trace, '$**.potential_group_range_indexes')) diff --git a/mysql-test/main/distinct.result b/mysql-test/main/distinct.result index 3064e062781..d789066ac3b 100644 --- a/mysql-test/main/distinct.result +++ b/mysql-test/main/distinct.result @@ -173,9 +173,9 @@ INSERT INTO t2 values (1),(2),(3); INSERT INTO t3 VALUES (1,'1'),(2,'2'),(1,'1'),(2,'2'); explain SELECT distinct t3.a FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 4 Using where; Using temporary +1 SIMPLE t2 index a a 4 NULL 5 Using index; Using temporary +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 Using where 1 SIMPLE t3 ref a a 5 test.t1.b 2 Using index -1 SIMPLE t2 ref a a 4 test.t1.a 2 Using index; Distinct SELECT distinct t3.a FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a; a 1 @@ -522,8 +522,8 @@ id select_type table type possible_keys key key_len ref rows Extra EXPLAIN SELECT DISTINCT t1_1.a, t1_1.b FROM t1 t1_1, t1 t1_2 WHERE t1_1.a = t1_2.a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1_1 ALL PRIMARY NULL NULL NULL 3 Using temporary -1 SIMPLE t1_2 eq_ref PRIMARY PRIMARY 4 test.t1_1.a 1 Using index; Distinct +1 SIMPLE t1_2 index PRIMARY PRIMARY 4 NULL 3 Using index; Using temporary +1 SIMPLE t1_1 eq_ref PRIMARY PRIMARY 4 test.t1_2.a 1 EXPLAIN SELECT a FROM t1 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL PRIMARY 4 NULL 3 Using index @@ -538,10 +538,10 @@ PRIMARY KEY (a,b)); INSERT INTO t2 VALUES (1,1,1,50), (1,2,3,40), (2,1,3,4); EXPLAIN SELECT DISTINCT a FROM t2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL PRIMARY 8 NULL 3 Using index +1 SIMPLE t2 range NULL PRIMARY 4 NULL 3 Using index for group-by EXPLAIN SELECT DISTINCT a,a FROM t2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL PRIMARY 8 NULL 3 Using index +1 SIMPLE t2 range NULL PRIMARY 4 NULL 3 Using index for group-by EXPLAIN SELECT DISTINCT b,a FROM t2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 index NULL PRIMARY 8 NULL 3 Using index diff --git a/mysql-test/main/explain.result b/mysql-test/main/explain.result index a5ad9fad4ba..1e546d42d0a 100644 --- a/mysql-test/main/explain.result +++ b/mysql-test/main/explain.result @@ -333,9 +333,7 @@ WHERE t1.f1 GROUP BY t1.f1)); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1 -2 SUBQUERY t1 index unique,fulltext unique 8 NULL 1 Using where; Using index -Warnings: -Warning 1292 Truncated incorrect DECIMAL value: 'test' +2 SUBQUERY t1 fulltext unique,fulltext fulltext 0 1 Using where PREPARE stmt FROM 'EXPLAIN SELECT 1 FROM t1 WHERE 1 > ALL((SELECT t1.f1 FROM t1 RIGHT OUTER JOIN t1 a @@ -345,16 +343,12 @@ EXECUTE stmt; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1 -2 SUBQUERY t1 index unique,fulltext unique 8 NULL 1 Using where; Using index -Warnings: -Warning 1292 Truncated incorrect DECIMAL value: 'test' +2 SUBQUERY t1 fulltext unique,fulltext fulltext 0 1 Using where EXECUTE stmt; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1 -2 SUBQUERY t1 index unique,fulltext unique 8 NULL 1 Using where; Using index -Warnings: -Warning 1292 Truncated incorrect DECIMAL value: 'test' +2 SUBQUERY t1 fulltext unique,fulltext fulltext 0 1 Using where DEALLOCATE PREPARE stmt; PREPARE stmt FROM 'EXPLAIN SELECT 1 FROM t1 @@ -365,9 +359,7 @@ EXECUTE stmt; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1 -2 SUBQUERY t1 index unique,fulltext unique 8 NULL 1 Using where; Using index -Warnings: -Warning 1292 Truncated incorrect DECIMAL value: 'test' +2 SUBQUERY t1 fulltext unique,fulltext fulltext 0 1 Using where INSERT into t1 values('test1'),('test2'),('test3'),('test4'),('test5'); EXECUTE stmt; id select_type table type possible_keys key key_len ref rows Extra diff --git a/mysql-test/main/explain_innodb.result b/mysql-test/main/explain_innodb.result index fe51e45e35d..0bdd5a44985 100644 --- a/mysql-test/main/explain_innodb.result +++ b/mysql-test/main/explain_innodb.result @@ -15,6 +15,6 @@ explain SELECT * FROM (SELECT id FROM t1 GROUP BY id) dt WHERE 1=0; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE -2 DERIVED t1 index NULL id 53 NULL 1 Using index +2 DERIVED t1 range NULL id 53 NULL 1 Using index for group-by SET GLOBAL slow_query_log = @sql_tmp; drop table t1; diff --git a/mysql-test/main/explain_json.result b/mysql-test/main/explain_json.result index d861eff05f1..d2a8f38c33e 100644 --- a/mysql-test/main/explain_json.result +++ b/mysql-test/main/explain_json.result @@ -713,12 +713,11 @@ EXPLAIN create table t2 like t1; insert into t2 select * from t1; explain format=json -select * from t1,t2 where t1.a in ( select a from t0); +select * from t1,t2 where t1.a in ( select seq+0 from seq_1_to_100); EXPLAIN { "query_block": { "select_id": 1, - "const_condition": "1", "nested_loop": [ { "table": { @@ -734,11 +733,12 @@ EXPLAIN "access_type": "eq_ref", "possible_keys": ["distinct_key"], "key": "distinct_key", - "key_length": "4", - "used_key_parts": ["a"], + "key_length": "8", + "used_key_parts": ["seq+0"], "ref": ["func"], "rows": 1, "filtered": 100, + "attached_condition": "t1.a = seq_1_to_100.seq + 0", "materialized": { "unique": 1, "query_block": { @@ -746,10 +746,14 @@ EXPLAIN "nested_loop": [ { "table": { - "table_name": "t0", - "access_type": "ALL", - "rows": 10, - "filtered": 100 + "table_name": "seq_1_to_100", + "access_type": "index", + "key": "PRIMARY", + "key_length": "8", + "used_key_parts": ["seq"], + "rows": 100, + "filtered": 100, + "using_index": true } } ] @@ -766,7 +770,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "1Kb", + "buffer_size": "19Kb", "join_type": "BNL" } } @@ -847,7 +851,7 @@ EXPLAIN "table_name": "t1", "access_type": "ALL", "rows": 10, - "filtered": 100 + "filtered": 10 }, "buffer_type": "flat", "buffer_size": "206", @@ -1225,12 +1229,18 @@ analyze table t1; Table Op Msg_type Msg_text test.t1 analyze status Engine-independent statistics collected test.t1 analyze status Table is already up to date +select count(*) from t1; +count(*) +128 explain select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 147 NULL 17 Using where; Using index for group-by +1 SIMPLE t1 range NULL idx_t1_2 147 NULL 17 Using where; Using index for group-by explain select count(distinct a1,a2,b,c) from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx_t1_1 163 NULL 65 Using where; Using index for group-by +1 SIMPLE t1 index NULL idx_t1_1 163 NULL 128 Using where; Using index +explain select count(distinct a1,a2,b) from t1 where a1 >= "" and (a2 >= 'b') and (b = 'a'); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 1 Using where; Using index for group-by explain format=json select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a'); EXPLAIN { @@ -1241,7 +1251,7 @@ EXPLAIN "table": { "table_name": "t1", "access_type": "range", - "key": "idx_t1_1", + "key": "idx_t1_2", "key_length": "147", "used_key_parts": ["a1", "a2", "b"], "rows": 17, @@ -1262,13 +1272,36 @@ EXPLAIN { "table": { "table_name": "t1", - "access_type": "range", + "access_type": "index", "key": "idx_t1_1", "key_length": "163", "used_key_parts": ["a1", "a2", "b", "c"], - "rows": 65, - "filtered": 100, + "rows": 128, + "filtered": 0.198364258, "attached_condition": "t1.b = 'a' and t1.c = 'i121' and t1.a2 >= 'b'", + "using_index": true + } + } + ] + } +} +explain format=json select count(distinct a1,a2,b) from t1 where a1 >= "" and (a2 >= 'b') and (b = 'a'); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "nested_loop": [ + { + "table": { + "table_name": "t1", + "access_type": "range", + "possible_keys": ["idx_t1_0", "idx_t1_1", "idx_t1_2"], + "key": "idx_t1_1", + "key_length": "147", + "used_key_parts": ["a1", "a2", "b"], + "rows": 1, + "filtered": 100, + "attached_condition": "t1.b = 'a' and t1.a1 >= '' and t1.a2 >= 'b'", "using_index_for_group_by": true } } @@ -1470,7 +1503,7 @@ insert into t2 values (1),(2); explain select * from t1 left join t2 on t2.pk > 10 and t2.pk < 0; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 const PRIMARY NULL NULL NULL 1 Impossible ON condition +1 SIMPLE t2 const PRIMARY NULL NULL NULL 0 Impossible ON condition 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 explain format=json select * from t1 left join t2 on t2.pk > 10 and t2.pk < 0; @@ -1485,8 +1518,8 @@ EXPLAIN "table_name": "t2", "access_type": "const", "possible_keys": ["PRIMARY"], - "rows": 1, - "filtered": 100, + "rows": 0, + "filtered": 0, "impossible_on_condition": true } }, @@ -1520,9 +1553,9 @@ ANALYZE "access_type": "const", "possible_keys": ["PRIMARY"], "r_loops": 0, - "rows": 1, + "rows": 0, "r_rows": null, - "filtered": 100, + "filtered": 0, "r_filtered": null, "impossible_on_condition": true } @@ -1832,7 +1865,8 @@ ANALYZE "buffer_size": "400", "join_type": "BKA", "mrr_type": "Rowid-ordered scan", - "r_filtered": 100 + "r_filtered": 100, + "r_unpack_time_ms": "REPLACED" } } ] @@ -2004,7 +2038,7 @@ EXPLAIN "table_name": "t3", "access_type": "ALL", "rows": 2, - "filtered": 100 + "filtered": 25 }, "buffer_type": "incremental", "buffer_size": "109", diff --git a/mysql-test/main/explain_json.test b/mysql-test/main/explain_json.test index baf1aa988a2..be077b22f48 100644 --- a/mysql-test/main/explain_json.test +++ b/mysql-test/main/explain_json.test @@ -2,6 +2,7 @@ # EXPLAIN FORMAT=JSON tests. These are tests developed for MariaDB. # --source include/default_optimizer_switch.inc +--source include/have_sequence.inc --disable_warnings drop table if exists t0,t1,t2; @@ -117,7 +118,7 @@ select * from t1 where a in (select max(a) from t1 group by b); create table t2 like t1; insert into t2 select * from t1; explain format=json -select * from t1,t2 where t1.a in ( select a from t0); +select * from t1,t2 where t1.a in ( select seq+0 from seq_1_to_100); --echo # --echo # First-Match @@ -271,13 +272,17 @@ create index idx_t1_0 on t1 (a1); create index idx_t1_1 on t1 (a1,a2,b,c); create index idx_t1_2 on t1 (a1,a2,b); analyze table t1; +select count(*) from t1; explain select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a'); explain select count(distinct a1,a2,b,c) from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121'); +explain select count(distinct a1,a2,b) from t1 where a1 >= "" and (a2 >= 'b') and (b = 'a'); explain format=json select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a'); + explain format=json select count(distinct a1,a2,b,c) from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121'); +explain format=json select count(distinct a1,a2,b) from t1 where a1 >= "" and (a2 >= 'b') and (b = 'a'); drop table t1; --echo # diff --git a/mysql-test/main/explain_json_innodb.result b/mysql-test/main/explain_json_innodb.result index 871c0d6a258..9d2529471ae 100644 --- a/mysql-test/main/explain_json_innodb.result +++ b/mysql-test/main/explain_json_innodb.result @@ -54,8 +54,7 @@ EXPLAIN ], "rows": 1, "filtered": 100, - "attached_condition": "tbl_alias2.c = tbl_alias1.column_name_2", - "using_index": true + "attached_condition": "tbl_alias2.c = tbl_alias1.column_name_2" } } ] diff --git a/mysql-test/main/fetch_first.result b/mysql-test/main/fetch_first.result index c277362739a..f8309f51832 100644 --- a/mysql-test/main/fetch_first.result +++ b/mysql-test/main/fetch_first.result @@ -834,6 +834,14 @@ fetch first 2 rows with ties; first_name last_name Alice Fowler Bob Trasc +explain select first_name, last_name +from t1 +where first_name != 'John' +group by first_name, last_name +order by first_name +fetch first 2 rows with ties; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range t1_name t1_name 206 NULL 3 Using where; Using index for group-by select first_name, last_name from t1 where first_name != 'John' @@ -843,7 +851,6 @@ fetch first 2 rows with ties; first_name last_name Alice Fowler Bob Trasc -Silvia Ganush # # Test CTE support. # diff --git a/mysql-test/main/fetch_first.test b/mysql-test/main/fetch_first.test index 614c91d9ee5..3cec50257fe 100644 --- a/mysql-test/main/fetch_first.test +++ b/mysql-test/main/fetch_first.test @@ -621,7 +621,12 @@ where first_name != 'John' order by first_name fetch first 2 rows with ties; - +explain select first_name, last_name +from t1 +where first_name != 'John' +group by first_name, last_name +order by first_name +fetch first 2 rows with ties; select first_name, last_name from t1 diff --git a/mysql-test/main/fulltext.result b/mysql-test/main/fulltext.result index 3acde6121ec..3a338fdc847 100644 --- a/mysql-test/main/fulltext.result +++ b/mysql-test/main/fulltext.result @@ -594,6 +594,9 @@ CREATE TABLE t2 (a int, b2 char(10), FULLTEXT KEY b2 (b2)); INSERT INTO t2 VALUES (1,'Scargill'); CREATE TABLE t3 (a int, b int); INSERT INTO t3 VALUES (1,1), (2,1); +SELECT * FROM t2 where MATCH(b2) AGAINST('scargill' IN BOOLEAN MODE); +a b2 +1 Scargill # t2 should use full text index EXPLAIN SELECT count(*) FROM t1 WHERE @@ -603,8 +606,8 @@ WHERE t3.a=t1.a AND MATCH(b2) AGAINST('scargill' IN BOOLEAN MODE) ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where -2 MATERIALIZED t2 fulltext b2 b2 0 1 Using where -2 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 Using where +2 DEPENDENT SUBQUERY t2 fulltext b2 b2 0 1 Using where +2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 Using where # should return 0 SELECT count(*) FROM t1 WHERE not exists( diff --git a/mysql-test/main/fulltext.test b/mysql-test/main/fulltext.test index 8b90c9cd81d..ef690be2314 100644 --- a/mysql-test/main/fulltext.test +++ b/mysql-test/main/fulltext.test @@ -547,6 +547,8 @@ INSERT INTO t2 VALUES (1,'Scargill'); CREATE TABLE t3 (a int, b int); INSERT INTO t3 VALUES (1,1), (2,1); +SELECT * FROM t2 where MATCH(b2) AGAINST('scargill' IN BOOLEAN MODE); + --echo # t2 should use full text index EXPLAIN SELECT count(*) FROM t1 WHERE diff --git a/mysql-test/main/fulltext_order_by.test b/mysql-test/main/fulltext_order_by.test index 4c0333d0afb..9fddf3b2fec 100644 --- a/mysql-test/main/fulltext_order_by.test +++ b/mysql-test/main/fulltext_order_by.test @@ -36,7 +36,6 @@ SELECT IF(a=7,'match',IF(a=4,'match', 'no-match')), MATCH (message) AGAINST ('st # for fulltext searches too # alter table t1 add key m (message); -show create table t1; explain SELECT message FROM t1 WHERE MATCH (message) AGAINST ('steve') ORDER BY message; SELECT message FROM t1 WHERE MATCH (message) AGAINST ('steve') ORDER BY message desc; diff --git a/mysql-test/main/func_group.result b/mysql-test/main/func_group.result index 5d9b1df58ba..e31d85df358 100644 --- a/mysql-test/main/func_group.result +++ b/mysql-test/main/func_group.result @@ -607,7 +607,7 @@ id select_type table type possible_keys key key_len ref rows Extra explain select min(a1) from t1 where (a1 < 'KKK' or a1 > 'KKK'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index PRIMARY PRIMARY 3 NULL 15 Using where; Using index +1 SIMPLE t1 range PRIMARY PRIMARY 3 NULL 14 Using where; Using index explain select max(a3) from t1 where a2 < 2 and a3 < 'SEA'; id select_type table type possible_keys key key_len ref rows Extra @@ -652,7 +652,7 @@ id select_type table type possible_keys key key_len ref rows Extra explain select concat(min(t1.a1),min(t2.a4)) from t1, t2 where t2.a4 <> 'AME'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index k2 k2 4 NULL 7 Using where; Using index +1 SIMPLE t2 range k2 k2 4 NULL 6 Using where; Using index 1 SIMPLE t1 index NULL PRIMARY 3 NULL 15 Using index; Using join buffer (flat, BNL join) drop table t1, t2; create table t1 (a char(10)); @@ -1336,7 +1336,7 @@ INSERT INTO t2 ( a, b, c ) VALUES ( 1, NULL, 2 ), ( 1, 3, 4 ), ( 1, 4, 4 ), ( 2, NULL, 2 ), ( 2, 3, 4 ), ( 2, 4, 4 ); EXPLAIN SELECT MIN(b), MIN(c) FROM t2 WHERE a = 1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL a NULL NULL NULL 6 Using where +1 SIMPLE t2 ref a a 5 const 3 SELECT MIN(b), MIN(c) FROM t2 WHERE a = 1; MIN(b) MIN(c) 3 2 @@ -1856,7 +1856,7 @@ NULL EXPLAIN EXTENDED SELECT MAX(a) FROM t1 WHERE (1,2) IN (SELECT a,b FROM t2 WHERE b<5) and a<10; id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; FirstMatch +1 PRIMARY t2 ALL NULL NULL NULL NULL 5 20.00 Using where; FirstMatch 1 PRIMARY t1 range a a 4 NULL 3 100.00 Using where; Using index; Using join buffer (flat, BNL join) Warnings: Note 1003 select max(`test`.`t1`.`a`) AS `MAX(a)` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`a` = 1 and `test`.`t2`.`b` = 2 and `test`.`t1`.`a` < 10 diff --git a/mysql-test/main/func_group_innodb.result b/mysql-test/main/func_group_innodb.result index f5a823e4638..9f69f424f33 100644 --- a/mysql-test/main/func_group_innodb.result +++ b/mysql-test/main/func_group_innodb.result @@ -246,12 +246,12 @@ INSERT INTO t1(a, b, c) VALUES ('', 'a', 1), ('', 'a', 1), ('', 'a', 2), ('', 'a', 2), ('', 'a', 3), ('', 'a', 3), ('', 'a', 4), ('', 'a', 4), ('', 'a', 5), ('', 'a', 5); ANALYZE TABLE t1; -SELECT MIN(c) FROM t1 GROUP BY b; -MIN(c) -0 EXPLAIN SELECT MIN(c) FROM t1 GROUP BY b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range NULL b 263 NULL 2 Using index for group-by +SELECT MIN(c) FROM t1 GROUP BY b; +MIN(c) +0 DROP TABLE t1; # # MDEV-17589: Stack-buffer-overflow with indexed varchar (utf8) field diff --git a/mysql-test/main/func_group_innodb.test b/mysql-test/main/func_group_innodb.test index b1f9a28b190..ca6b083848c 100644 --- a/mysql-test/main/func_group_innodb.test +++ b/mysql-test/main/func_group_innodb.test @@ -199,8 +199,8 @@ INSERT INTO t1(a, b, c) VALUES ANALYZE TABLE t1; -- enable_result_log -SELECT MIN(c) FROM t1 GROUP BY b; EXPLAIN SELECT MIN(c) FROM t1 GROUP BY b; +SELECT MIN(c) FROM t1 GROUP BY b; DROP TABLE t1; diff --git a/mysql-test/main/func_in.result b/mysql-test/main/func_in.result index 13eb9501599..175e23ec65f 100644 --- a/mysql-test/main/func_in.result +++ b/mysql-test/main/func_in.result @@ -521,7 +521,7 @@ a b explain select f1 from t1 where f1 in ('a','b'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index t1f1_idx t1f1_idx 2 NULL 3 Using where; Using index +1 SIMPLE t1 range t1f1_idx t1f1_idx 2 NULL 2 Using where; Using index select f1 from t1 where f1 in (2,1); f1 1 @@ -957,7 +957,7 @@ a # Conversion to equality is impossible due to different values EXPLAIN SELECT * FROM t1 WHERE a IN (1,1,2); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 3 Using where; Using index +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using where; Using index SELECT * FROM t1 WHERE a IN (1,NULL,1); a 1 @@ -1030,7 +1030,7 @@ a b # No conversion due to different values EXPLAIN SELECT * FROM t2 WHERE (a,b) IN ((2,'def'),(2,'def'),(2,'XYZ')); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index PRIMARY PRIMARY 16 NULL 3 Using where; Using index +1 SIMPLE t2 range PRIMARY PRIMARY 16 NULL 2 Using where; Using index SELECT * FROM t2 WHERE (a,b) IN ((2,'def'),(2,'def'),(2,NULL)); a b 2 def @@ -1078,7 +1078,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t3 const PRIMARY PRIMARY 4 const 1 Using index EXECUTE stmt USING 2,3,4; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 index PRIMARY PRIMARY 4 NULL 3 Using where; Using index +1 SIMPLE t3 range PRIMARY PRIMARY 4 NULL 3 Using where; Using index DEALLOCATE PREPARE stmt; DROP TABLE t1, t2, t3; # Nested joins @@ -1104,7 +1104,7 @@ AND t3.a IN (1,2); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 2 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -1 SIMPLE t3 index PRIMARY PRIMARY 4 NULL 4 Using where; Using index; Using join buffer (incremental, BNL join) +1 SIMPLE t3 range PRIMARY PRIMARY 4 NULL 2 Using where; Using index; Using join buffer (incremental, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 2 Using join buffer (incremental, BNL join) # Conversion to equalities EXPLAIN SELECT * FROM t1 LEFT JOIN ((t2, t3) LEFT JOIN t4 ON t2.a = t4.a) @@ -1118,7 +1118,7 @@ id select_type table type possible_keys key key_len ref rows Extra EXPLAIN SELECT * FROM t1 LEFT JOIN ((t2, t3) LEFT JOIN t4 ON t2.a = t4.a) ON t1.a = t2.a WHERE t1.a IN (1,3); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using index condition 1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 1 SIMPLE t4 ALL NULL NULL NULL NULL 2 Using where 1 SIMPLE t3 index NULL PRIMARY 4 NULL 4 Using index @@ -1131,7 +1131,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 const PRIMARY PRIMARY 4 const 1 EXPLAIN SELECT * FROM v1 WHERE a IN (1,2,3); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 Using index condition 1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 # Stored procedures CREATE PROCEDURE p1(pa INT, pb INT) @@ -1141,7 +1141,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 CALL p1(2,1); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using index condition DROP TABLE t1, t2, t3, t4; DROP VIEW v1; DROP PROCEDURE p1; diff --git a/mysql-test/main/greedy_optimizer.result b/mysql-test/main/greedy_optimizer.result index 40add445c3c..2bf67d5f6d8 100644 --- a/mysql-test/main/greedy_optimizer.result +++ b/mysql-test/main/greedy_optimizer.result @@ -127,7 +127,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 2445.013350 +Last_query_cost 1.650935 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 @@ -139,11 +139,11 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 2445.013350 +Last_query_cost 1.650935 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 6 -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index @@ -151,11 +151,11 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1330.797643 +Last_query_cost 0.602062 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 6 -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index @@ -163,11 +163,11 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1330.797643 +Last_query_cost 0.602062 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 6 -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where @@ -175,11 +175,11 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1334.341393 +Last_query_cost 0.621783 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 6 -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where @@ -187,7 +187,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1334.341393 +Last_query_cost 0.621783 set optimizer_prune_level=0; select @@optimizer_prune_level; @@optimizer_prune_level @@ -198,108 +198,108 @@ select @@optimizer_search_depth; 0 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where -1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 +1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) -1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 Using where +1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 2437.438350 +Last_query_cost 1.405838 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where -1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 +1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) -1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index +1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 Using where +1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 Using where show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 2437.438350 +Last_query_cost 1.405838 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using join buffer (flat, BNL join) +1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index -1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 653.372751 +Last_query_cost 0.494824 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using join buffer (flat, BNL join) +1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index -1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 653.372751 +Last_query_cost 0.494824 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where -1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 662.822751 +Last_query_cost 0.453844 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where -1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 662.822751 +Last_query_cost 0.453844 set optimizer_search_depth=1; select @@optimizer_search_depth; @@optimizer_search_depth 1 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 +1 SIMPLE t7 index PRIMARY PRIMARY 4 NULL 21 Using index +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) -1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 2445.013350 +Last_query_cost 34.291074 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 +1 SIMPLE t7 index PRIMARY PRIMARY 4 NULL 21 Using index +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) -1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 2445.013350 +Last_query_cost 34.291074 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where -1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index +1 SIMPLE t3 index PRIMARY PRIMARY 4 NULL 9 Using index +1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) @@ -307,19 +307,19 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1762.798851 +Last_query_cost 14.789792 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where +1 SIMPLE t3 index PRIMARY PRIMARY 4 NULL 9 Using index +1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index -1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1762.798851 +Last_query_cost 14.789792 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where @@ -331,7 +331,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1767.523851 +Last_query_cost 1.698747 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where @@ -343,83 +343,83 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1767.523851 +Last_query_cost 1.698747 set optimizer_search_depth=62; select @@optimizer_search_depth; @@optimizer_search_depth 62 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where -1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 +1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) -1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 Using where +1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 2437.438350 +Last_query_cost 1.405838 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where -1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 +1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) -1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index +1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 Using where +1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 Using where show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 2437.438350 +Last_query_cost 1.405838 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using join buffer (flat, BNL join) +1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index -1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 653.372751 +Last_query_cost 0.494824 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using join buffer (flat, BNL join) +1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index -1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 653.372751 +Last_query_cost 0.494824 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where -1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 662.822751 +Last_query_cost 0.453844 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where -1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 662.822751 +Last_query_cost 0.453844 set optimizer_prune_level=2; select @@optimizer_prune_level; @@optimizer_prune_level @@ -439,7 +439,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 2445.013350 +Last_query_cost 1.650935 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 @@ -451,11 +451,11 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 2445.013350 +Last_query_cost 1.650935 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 6 -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index @@ -463,23 +463,23 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1330.797643 +Last_query_cost 0.602062 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 6 -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) -1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index -1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index +1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index +1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index +1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1330.797643 +Last_query_cost 0.602062 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 6 -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where @@ -487,51 +487,51 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1334.341393 +Last_query_cost 0.621783 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 6 -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) -1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where -1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where +1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where +1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1334.341393 +Last_query_cost 0.621783 set optimizer_search_depth=1; select @@optimizer_search_depth; @@optimizer_search_depth 1 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 +1 SIMPLE t7 index PRIMARY PRIMARY 4 NULL 21 Using index +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) -1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 2445.013350 +Last_query_cost 34.291074 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 +1 SIMPLE t7 index PRIMARY PRIMARY 4 NULL 21 Using index +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) -1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 2445.013350 +Last_query_cost 34.291074 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where -1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index +1 SIMPLE t3 index PRIMARY PRIMARY 4 NULL 9 Using index +1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) @@ -539,19 +539,19 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1762.798851 +Last_query_cost 14.789792 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where +1 SIMPLE t3 index PRIMARY PRIMARY 4 NULL 9 Using index +1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index -1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1762.798851 +Last_query_cost 14.789792 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where @@ -563,7 +563,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1767.523851 +Last_query_cost 1.698747 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where @@ -575,7 +575,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1767.523851 +Last_query_cost 1.698747 set optimizer_search_depth=62; select @@optimizer_search_depth; @@optimizer_search_depth @@ -591,7 +591,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 2445.013350 +Last_query_cost 1.650935 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 @@ -603,11 +603,11 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 2445.013350 +Last_query_cost 1.650935 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 6 -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index @@ -615,23 +615,23 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1330.797643 +Last_query_cost 0.602062 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 6 -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) -1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index -1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index +1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index +1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index +1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1330.797643 +Last_query_cost 0.602062 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 6 -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where @@ -639,19 +639,19 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1334.341393 +Last_query_cost 0.621783 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 6 -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) -1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where -1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where +1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where +1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1334.341393 +Last_query_cost 0.621783 drop table t1,t2,t3,t4,t5,t6,t7; CREATE TABLE t1 (a int, b int, d int, i int); INSERT INTO t1 VALUES (1,1,1,1); @@ -1195,13 +1195,13 @@ COUNT(*) 9000 ### NOTE: Handler_reads: 9030, expected: 9045 ### flush status; -EXPLAIN SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t10000 x,t10000 y +EXPLAIN SELECT STRAIGHT_JOIN COUNT(*) FROM t10000 y, t10, t10000 x WHERE x.k=t10.i; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t10 index IX IX 5 NULL 10 Using where; Using index +1 SIMPLE y index NULL PRIMARY 4 NULL 10000 Using index +1 SIMPLE t10 range IX IX 5 NULL 10 Using where; Using index; Using join buffer (flat, BNL join) 1 SIMPLE x eq_ref PRIMARY PRIMARY 4 test.t10.I 1 Using index -1 SIMPLE y index NULL PRIMARY 4 NULL 10000 Using index; Using join buffer (flat, BNL join) -SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t10000 x,t10000 y +SELECT STRAIGHT_JOIN COUNT(*) FROM t10000 y, t10, t10000 x WHERE x.k=t10.i; COUNT(*) 90000 @@ -1209,9 +1209,9 @@ flush status; EXPLAIN SELECT COUNT(*) FROM t10,t10000 x,t10000 y WHERE x.k=t10.i; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t10 index IX IX 5 NULL 10 Using where; Using index +1 SIMPLE y index NULL PRIMARY 4 NULL 10000 Using index +1 SIMPLE t10 range IX IX 5 NULL 10 Using where; Using index; Using join buffer (flat, BNL join) 1 SIMPLE x eq_ref PRIMARY PRIMARY 4 test.t10.I 1 Using index -1 SIMPLE y index NULL PRIMARY 4 NULL 10000 Using index; Using join buffer (flat, BNL join) SELECT COUNT(*) FROM t10,t10000 x,t10000 y WHERE x.k=t10.i; COUNT(*) @@ -1220,9 +1220,9 @@ flush status; EXPLAIN SELECT COUNT(*) FROM t10,t10000 y,t10000 x WHERE x.k=t10.i; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t10 index IX IX 5 NULL 10 Using where; Using index +1 SIMPLE y index NULL PRIMARY 4 NULL 10000 Using index +1 SIMPLE t10 range IX IX 5 NULL 10 Using where; Using index; Using join buffer (flat, BNL join) 1 SIMPLE x eq_ref PRIMARY PRIMARY 4 test.t10.I 1 Using index -1 SIMPLE y index NULL PRIMARY 4 NULL 10000 Using index; Using join buffer (flat, BNL join) SELECT COUNT(*) FROM t10,t10000 y,t10000 x WHERE x.k=t10.i; COUNT(*) @@ -2913,7 +2913,7 @@ EXPLAIN SELECT COUNT(*) FROM t1 AS x JOIN t1 ON t1.K=x.I JOIN t2 ON t2.K=x.I JOI DROP TABLE t100, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61; show status like "optimizer%"; Variable_name Value -Optimizer_join_prefixes_check_calls 60210 +Optimizer_join_prefixes_check_calls 63164 SET OPTIMIZER_SEARCH_DEPTH = DEFAULT; # # Bug found when testing greedy optimizer tests diff --git a/mysql-test/main/greedy_optimizer.test b/mysql-test/main/greedy_optimizer.test index f2731087cd8..04f765e815a 100644 --- a/mysql-test/main/greedy_optimizer.test +++ b/mysql-test/main/greedy_optimizer.test @@ -662,7 +662,7 @@ WHERE t100.K=t10.I ## Expect this QEP, cost & #handler_read # Expected QEP: 'join EQ_REF(X) on X.K=t10.I' before 'cross' ALL(Y) let $query= -SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t10000 x,t10000 y +SELECT STRAIGHT_JOIN COUNT(*) FROM t10000 y, t10, t10000 x WHERE x.k=t10.i; --source include/expect_qep.inc diff --git a/mysql-test/main/group_by.result b/mysql-test/main/group_by.result index 460a3cd9357..95ec41c048b 100644 --- a/mysql-test/main/group_by.result +++ b/mysql-test/main/group_by.result @@ -1718,7 +1718,7 @@ NULL insert into t2 SELECT NULL, NULL from seq_1_to_10; EXPLAIN SELECT b from t2 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL a 10 NULL 16 Using index +1 SIMPLE t2 range NULL a 5 NULL 9 Using index for group-by # Expect: Using index for group-by analyze table t2; Table Op Msg_type Msg_text @@ -2263,11 +2263,11 @@ INSERT INTO t2(col1, col2) VALUES explain select col1 f1, col2 f2, col1 f3 from t2 group by f1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx 10 NULL 20 Using index +1 SIMPLE t2 range NULL idx 5 NULL 7 Using index for group-by explain select SQL_BIG_RESULT col1 f1, col2 f2, col1 f3 from t2 group by f1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx 10 NULL 20 Using index; Using filesort +1 SIMPLE t2 range NULL idx 5 NULL 7 Using index for group-by explain select col1 f1, col2 f2, col1 f3 from t2 group by f1, f2; id select_type table type possible_keys key key_len ref rows Extra @@ -2275,7 +2275,7 @@ id select_type table type possible_keys key key_len ref rows Extra explain select col1 f1, col1 f2 from t2 group by f1, 1+1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index NULL idx 10 NULL 20 Using index +1 SIMPLE t2 range NULL idx 5 NULL 7 Using index for group-by explain select col1 f1, col2 f2, col1 f3 from t2 group by f1, f2, f3+0; id select_type table type possible_keys key key_len ref rows Extra diff --git a/mysql-test/main/group_min_max.result b/mysql-test/main/group_min_max.result index c1030cf9271..f97f6d41ab2 100644 --- a/mysql-test/main/group_min_max.result +++ b/mysql-test/main/group_min_max.result @@ -2080,7 +2080,7 @@ id select_type table type possible_keys key key_len ref rows Extra explain extended select a1,a2,min(b),max(b) from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (c > 'a111') group by a1,a2; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 276 100.00 Using where; Using index +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 276 96.30 Using where; Using index Warnings: Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,min(`test`.`t1`.`b`) AS `min(b)`,max(`test`.`t1`.`b`) AS `max(b)` from `test`.`t1` where (`test`.`t1`.`a1` = 'b' or `test`.`t1`.`a1` = 'd' or `test`.`t1`.`a1` = 'a' or `test`.`t1`.`a1` = 'c') and `test`.`t1`.`a2` > 'a' and `test`.`t1`.`c` > 'a111' group by `test`.`t1`.`a1`,`test`.`t1`.`a2` explain extended select a1,a2,b,min(c),max(c) from t1 @@ -2100,7 +2100,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 index NULL idx_t2_1 163 NULL 548 Using where; Using index explain extended select a1,a2,b from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (c > 'a111') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 276 100.00 Using where; Using index +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 276 96.30 Using where; Using index Warnings: Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a1` = 'b' or `test`.`t1`.`a1` = 'd' or `test`.`t1`.`a1` = 'a' or `test`.`t1`.`a1` = 'c') and `test`.`t1`.`a2` > 'a' and `test`.`t1`.`c` > 'a111' group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b` explain select a1,a2,min(b),c from t2 where (a2 = 'a') and (c = 'a111') group by a1; @@ -2230,7 +2230,7 @@ a BB EXPLAIN SELECT a FROM t1 WHERE a='AA' GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref PRIMARY PRIMARY 7 const 4 Using where; Using index +1 SIMPLE t1 range PRIMARY PRIMARY 7 NULL 1 Using where; Using index for group-by EXPLAIN SELECT a FROM t1 WHERE a='BB' GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref PRIMARY PRIMARY 7 const 1 Using where; Using index @@ -2368,11 +2368,11 @@ CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a,b,c)); INSERT INTO t2 SELECT a,b,b FROM t1; explain SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a,b a 10 NULL 2 Using where; Using index for group-by +1 SIMPLE t1 range a,b a 10 NULL 1 Using where; Using index for group-by insert into t1 select 1,seq from seq_1_to_100; explain SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a,b a 10 NULL 2 Using where; Using index for group-by +1 SIMPLE t1 range a,b a 10 NULL 1 Using where; Using index for group-by analyze table t1; Table Op Msg_type Msg_text test.t1 analyze status Engine-independent statistics collected @@ -2388,7 +2388,7 @@ MIN(b) a 2 1 explain SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range PRIMARY PRIMARY 12 NULL 1 Using where; Using index +1 SIMPLE t2 range PRIMARY PRIMARY 12 NULL 1 Using where; Using index for group-by SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a; MIN(c) 2 @@ -2678,7 +2678,7 @@ a b 3 13 explain extended select sql_buffer_result a, max(b)+1 from t1 where a = 0 group by a; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 range a,index a 5 NULL 3 100.00 Using where; Using index for group-by; Using temporary +1 SIMPLE t1 range a,index a 5 NULL 1 100.00 Using where; Using index for group-by; Using temporary Warnings: Note 1003 select sql_buffer_result `test`.`t1`.`a` AS `a`,max(`test`.`t1`.`b`) + 1 AS `max(b)+1` from `test`.`t1` where `test`.`t1`.`a` = 0 group by `test`.`t1`.`a` drop table t1; @@ -3579,7 +3579,7 @@ a c COUNT(DISTINCT c, a, b) EXPLAIN SELECT COUNT(DISTINCT c, a, b) FROM t2 WHERE a > 5 AND b BETWEEN 10 AND 20 GROUP BY a, b, c; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range a a 5 NULL 1 Using where; Using index +1 SIMPLE t2 range a a 15 NULL 1 Using where; Using index for group-by SELECT COUNT(DISTINCT c, a, b) FROM t2 WHERE a > 5 AND b BETWEEN 10 AND 20 GROUP BY a, b, c; COUNT(DISTINCT c, a, b) @@ -3673,7 +3673,7 @@ insert into t1 values(1,'A'),(1 , 'B'), (1, 'C'), (2, 'A'), (3, 'A'), (3, 'B'), (3, 'C'), (3, 'D'); explain SELECT f1, COUNT(DISTINCT f2) FROM t1 GROUP BY f1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL f1 5 NULL 8 Using index for group-by (scanning) +1 SIMPLE t1 range NULL f1 5 NULL 8 Using index for group-by SELECT f1, COUNT(DISTINCT f2) FROM t1 GROUP BY f1; f1 COUNT(DISTINCT f2) 1 3 @@ -4036,10 +4036,10 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away explain select min(a) from t1 where a between "a" and "Cafeeeeeeeeeeeeeeeeeeeeeeeeee"; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index a a 13 NULL 2 Using where; Using index +1 SIMPLE t1 range a a 13 NULL 2 Using where; Using index explain select min(a) from t1 where a between "abbbbbbbbbbbbbbbbbbbb" and "Cafe2"; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index a a 13 NULL 2 Using where; Using index +1 SIMPLE t1 range a a 13 NULL 2 Using where; Using index drop table t1; # # MDEV-15433: Optimizer does not use group by optimization with distinct @@ -4126,7 +4126,7 @@ CREATE TABLE t1 (p int NOT NULL, a int NOT NULL, PRIMARY KEY (p,a)); insert into t1 select 2,seq from seq_0_to_1000; EXPLAIN select MIN(a) from t1 where p = 2 group by p; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 10 Using where; Using index for group-by +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 Using where; Using index for group-by SELECT MIN(a) from t1 where p = 2 group by p; MIN(a) 0 diff --git a/mysql-test/main/group_min_max.test b/mysql-test/main/group_min_max.test index 3fe951b7817..d230cd15749 100644 --- a/mysql-test/main/group_min_max.test +++ b/mysql-test/main/group_min_max.test @@ -1392,6 +1392,7 @@ SELECT a, c, COUNT(DISTINCT c, a, b) FROM t2 GROUP BY a, b, c; EXPLAIN SELECT COUNT(DISTINCT c, a, b) FROM t2 WHERE a > 5 AND b BETWEEN 10 AND 20 GROUP BY a, b, c; + SELECT COUNT(DISTINCT c, a, b) FROM t2 WHERE a > 5 AND b BETWEEN 10 AND 20 GROUP BY a, b, c; diff --git a/mysql-test/main/group_min_max_innodb.result b/mysql-test/main/group_min_max_innodb.result index 9671e835934..2b42ac1cbe1 100644 --- a/mysql-test/main/group_min_max_innodb.result +++ b/mysql-test/main/group_min_max_innodb.result @@ -73,10 +73,10 @@ insert into t1 values ( 1,"e"),(2,"a"),( 3,"c"),(4,"d"); alter table t1 drop primary key, add primary key (f2, f1); explain select distinct f1 a, f1 b from t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL PRIMARY 5 NULL 4 Using index; Using temporary +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using temporary explain select distinct f1, f2 from t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL PRIMARY 5 NULL 4 Using index +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 drop table t1; create table t1(pk int primary key) engine=innodb; create view v1 as select pk from t1 where pk < 20; @@ -108,7 +108,7 @@ CREATE TABLE t1 (a CHAR(1), b CHAR(1), PRIMARY KEY (a,b)) ENGINE=InnoDB; INSERT INTO t1 VALUES ('a', 'b'), ('c', 'd'); EXPLAIN SELECT COUNT(DISTINCT a) FROM t1 WHERE b = 'b'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL PRIMARY 2 NULL 2 Using where; Using index +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where SELECT COUNT(DISTINCT a) FROM t1 WHERE b = 'b'; COUNT(DISTINCT a) 1 @@ -118,7 +118,7 @@ ENGINE=InnoDB; INSERT INTO t1 VALUES ('a', 'b'), ('c', 'd'); EXPLAIN SELECT COUNT(DISTINCT a) FROM t1 WHERE b = 'b'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL a 2 NULL 2 Using where; Using index +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where SELECT COUNT(DISTINCT a) FROM t1 WHERE b = 'b'; COUNT(DISTINCT a) 1 @@ -162,7 +162,7 @@ ANALYZE TABLE t2; EXPLAIN SELECT c1, max(i2) FROM t1 WHERE (c1 = 'C' AND i2 = 17) OR ( c1 = 'F') GROUP BY c1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range k1 k1 5 NULL 31 Using where; Using index +1 SIMPLE t1 range k1 k1 5 NULL 31 Using where SELECT c1, max(i2) FROM t1 WHERE (c1 = 'C' AND i2 = 17) OR ( c1 = 'F') GROUP BY c1; c1 max(i2) @@ -171,7 +171,7 @@ F 30 EXPLAIN SELECT c1, max(i2) FROM t1 WHERE (c1 = 'C' OR ( c1 = 'F' AND i2 = 17)) GROUP BY c1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range k1 k1 5 NULL 31 Using where; Using index +1 SIMPLE t1 range k1 k1 5 NULL 31 Using where SELECT c1, max(i2) FROM t1 WHERE (c1 = 'C' OR ( c1 = 'F' AND i2 = 17)) GROUP BY c1; c1 max(i2) @@ -180,7 +180,7 @@ F 17 EXPLAIN SELECT c1, max(i2) FROM t1 WHERE (c1 = 'C' OR c1 = 'F' ) AND ( i2 = 17 ) GROUP BY c1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range k1 k1 5 NULL 2 Using where; Using index for group-by +1 SIMPLE t1 range k1 k1 5 NULL 2 Using where SELECT c1, max(i2) FROM t1 WHERE (c1 = 'C' OR c1 = 'F' ) AND ( i2 = 17 ) GROUP BY c1; c1 max(i2) @@ -190,7 +190,7 @@ EXPLAIN SELECT c1, max(i2) FROM t1 WHERE ((c1 = 'C' AND (i2 = 40 OR i2 = 30)) OR ( c1 = 'F' AND (i2 = 40 ))) GROUP BY c1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range k1 k1 5 NULL 3 Using where; Using index +1 SIMPLE t1 range k1 k1 5 NULL 3 Using where SELECT c1, max(i2) FROM t1 WHERE ((c1 = 'C' AND (i2 = 40 OR i2 = 30)) OR ( c1 = 'F' AND (i2 = 40 ))) GROUP BY c1; @@ -200,7 +200,7 @@ EXPLAIN SELECT c1, i1, max(i2) FROM t2 WHERE (c1 = 'C' OR ( c1 = 'F' AND i1 < 35)) AND ( i2 = 17 ) GROUP BY c1,i1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range k2 k2 5 NULL 60 Using where; Using index +1 SIMPLE t2 range k2 k2 5 NULL 60 Using where SELECT c1, i1, max(i2) FROM t2 WHERE (c1 = 'C' OR ( c1 = 'F' AND i1 < 35)) AND ( i2 = 17 ) GROUP BY c1,i1; @@ -211,7 +211,7 @@ EXPLAIN SELECT c1, i1, max(i2) FROM t2 WHERE (((c1 = 'C' AND i1 < 40) OR ( c1 = 'F' AND i1 < 35)) AND ( i2 = 17 )) GROUP BY c1,i1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range k2 k2 5 NULL 60 Using where; Using index +1 SIMPLE t2 range k2 k2 5 NULL 60 Using where SELECT c1, i1, max(i2) FROM t2 WHERE (((c1 = 'C' AND i1 < 40) OR ( c1 = 'F' AND i1 < 35)) AND ( i2 = 17 )) GROUP BY c1,i1; @@ -222,7 +222,7 @@ EXPLAIN SELECT c1, i1, max(i2) FROM t2 WHERE ((c1 = 'C' AND i1 < 40) OR ( c1 = 'F' AND i1 < 35) OR ( i2 = 17 )) GROUP BY c1,i1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index k2 k2 9 NULL 180 Using where; Using index +1 SIMPLE t2 index k2 k2 9 NULL 180 Using where SELECT c1, i1, max(i2) FROM t2 WHERE ((c1 = 'C' AND i1 < 40) OR ( c1 = 'F' AND i1 < 35) OR ( i2 = 17 )) GROUP BY c1,i1; diff --git a/mysql-test/main/ignored_index.result b/mysql-test/main/ignored_index.result index 03748d48098..176ca61decd 100644 --- a/mysql-test/main/ignored_index.result +++ b/mysql-test/main/ignored_index.result @@ -255,17 +255,15 @@ DROP TABLE t1; # IGNORED fulltext indexes. # CREATE TABLE t1 (a VARCHAR(200), b TEXT, FULLTEXT (a,b)); -INSERT INTO t1 VALUES('Some data', 'for full-text search'); -ANALYZE TABLE t1; -Table Op Msg_type Msg_text -test.t1 analyze status Engine-independent statistics collected -test.t1 analyze Warning Engine-independent statistics are not collected for column 'b' -test.t1 analyze status OK -EXPLAIN SELECT * FROM t1 WHERE MATCH(a, b) AGAINST ("collections"); +INSERT INTO t1 VALUES('Some data', 'for full-text search'),("hello","hello world"),("mars","here I come"); +SELECT * FROM t1 WHERE MATCH(a, b) AGAINST ("search"); +a b +Some data for full-text search +EXPLAIN SELECT * FROM t1 WHERE MATCH(a, b) AGAINST ("search"); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 fulltext a a 0 1 Using where ALTER TABLE t1 ALTER INDEX a IGNORED; -EXPLAIN SELECT * FROM t1 WHERE MATCH(a, b) AGAINST ("collections"); +SELECT * FROM t1 WHERE MATCH(a, b) AGAINST ("search"); ERROR HY000: Can't find FULLTEXT index matching the column list DROP TABLE t1; # diff --git a/mysql-test/main/ignored_index.test b/mysql-test/main/ignored_index.test index a3d46fe6046..b2fadcd5862 100644 --- a/mysql-test/main/ignored_index.test +++ b/mysql-test/main/ignored_index.test @@ -222,13 +222,11 @@ DROP TABLE t1; --echo # IGNORED fulltext indexes. --echo # CREATE TABLE t1 (a VARCHAR(200), b TEXT, FULLTEXT (a,b)); -INSERT INTO t1 VALUES('Some data', 'for full-text search'); -ANALYZE TABLE t1; - -let $query= -EXPLAIN SELECT * FROM t1 WHERE MATCH(a, b) AGAINST ("collections"); +INSERT INTO t1 VALUES('Some data', 'for full-text search'),("hello","hello world"),("mars","here I come"); +let $query=SELECT * FROM t1 WHERE MATCH(a, b) AGAINST ("search"); --eval $query +--eval EXPLAIN $query ALTER TABLE t1 ALTER INDEX a IGNORED; --error ER_FT_MATCHING_KEY_NOT_FOUND diff --git a/mysql-test/main/index_intersect.result b/mysql-test/main/index_intersect.result index 1f31636860f..c6332591ff5 100644 --- a/mysql-test/main/index_intersect.result +++ b/mysql-test/main/index_intersect.result @@ -75,7 +75,7 @@ EXPLAIN SELECT * FROM City WHERE Name LIKE 'M%' AND Population > 300000; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge Population,Name Name,Population 35,4 NULL # Using sort_intersect(Name,Population); Using where +1 SIMPLE City range Population,Name Name 35 NULL # Using index condition; Using where EXPLAIN SELECT * FROM City WHERE Name LIKE 'M%' AND Population > 7000000; @@ -712,7 +712,7 @@ EXPLAIN SELECT * FROM City WHERE Name BETWEEN 'G' AND 'J' AND Population > 500000 AND Country LIKE 'C%'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge Population,Country,Name Name,Country 35,3 NULL # Using sort_intersect(Name,Country); Using where +1 SIMPLE City range Population,Country,Name Name 35 NULL # Using index condition; Using where EXPLAIN SELECT * FROM City WHERE ID BETWEEN 1 AND 500 AND Population > 700000 AND Country LIKE 'C%'; diff --git a/mysql-test/main/index_intersect_innodb.result b/mysql-test/main/index_intersect_innodb.result index efe74389119..2aba9dc6fcf 100644 --- a/mysql-test/main/index_intersect_innodb.result +++ b/mysql-test/main/index_intersect_innodb.result @@ -378,7 +378,7 @@ EXPLAIN SELECT * FROM City WHERE Name BETWEEN 'G' AND 'K' AND Population > 500000 AND Country LIKE 'C%'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge Population,Name,Country Name,Population,Country # NULL # Using sort_intersect(Name,Population,Country); Using where +1 SIMPLE City index_merge Population,Name,Country Name,Population # NULL # Using sort_intersect(Name,Population); Using where SELECT * FROM City USE INDEX () WHERE Name BETWEEN 'M' AND 'N' AND Population > 1000000 AND Country LIKE 'C%'; ID Name Country Population @@ -469,12 +469,12 @@ EXPLAIN SELECT * FROM City WHERE ID BETWEEN 501 AND 1000 AND Population > 700000 AND Country LIKE 'C%'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge PRIMARY,Population,Country PRIMARY,Population 4,4 NULL # Using sort_intersect(PRIMARY,Population); Using where +1 SIMPLE City range PRIMARY,Population,Country PRIMARY 4 NULL # Using where EXPLAIN SELECT * FROM City WHERE ID BETWEEN 1 AND 500 AND Population > 700000 AND Country LIKE 'C%'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge PRIMARY,Population,Country PRIMARY,Population 4,4 NULL # Using sort_intersect(PRIMARY,Population); Using where +1 SIMPLE City range PRIMARY,Population,Country PRIMARY 4 NULL # Using where EXPLAIN SELECT * FROM City WHERE ID BETWEEN 2001 AND 2500 AND Population > 300000 AND Country LIKE 'H%'; @@ -491,7 +491,7 @@ SELECT * FROM City WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000 AND Country BETWEEN 'S' AND 'Z' ; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge PRIMARY,Population,Country PRIMARY,Population,Country 4,4,7 NULL # Using sort_intersect(PRIMARY,Population,Country); Using where +1 SIMPLE City index_merge PRIMARY,Population,Country PRIMARY,Population 4,4 NULL # Using sort_intersect(PRIMARY,Population); Using where SELECT * FROM City USE INDEX () WHERE ID BETWEEN 501 AND 1000 AND Population > 700000 AND Country LIKE 'C%'; ID Name Country Population @@ -708,7 +708,7 @@ EXPLAIN SELECT * FROM City WHERE Name LIKE 'M%' AND Population > 1500000; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge Population,Name Population,Name 4,35 NULL # Using sort_intersect(Population,Name); Using where +1 SIMPLE City range Population,Name Population 4 NULL # Using index condition; Using where EXPLAIN SELECT * FROM City WHERE Name BETWEEN 'G' AND 'K' AND Population > 1000000 AND Country LIKE 'J%'; @@ -723,13 +723,13 @@ EXPLAIN SELECT * FROM City WHERE ID BETWEEN 1 AND 500 AND Population > 700000 AND Country LIKE 'C%'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge PRIMARY,Population,Country PRIMARY,Population 4,4 NULL # Using sort_intersect(PRIMARY,Population); Using where +1 SIMPLE City range PRIMARY,Population,Country PRIMARY 4 NULL # Using where EXPLAIN SELECT * FROM City WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000 AND Country BETWEEN 'S' AND 'Z'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge PRIMARY,Population,Country PRIMARY,Population,Country 4,4,7 NULL # Using sort_intersect(PRIMARY,Population,Country); Using where +1 SIMPLE City range PRIMARY,Population,Country PRIMARY 4 NULL # Using where SELECT * FROM City WHERE Name LIKE 'C%' AND Population > 1000000; ID Name Country Population diff --git a/mysql-test/main/index_merge_innodb.result b/mysql-test/main/index_merge_innodb.result index d9be08a0540..6f1daf7552c 100644 --- a/mysql-test/main/index_merge_innodb.result +++ b/mysql-test/main/index_merge_innodb.result @@ -582,7 +582,7 @@ set @tmp_index_merge_ror_cpk=@@optimizer_switch; set optimizer_switch='extended_keys=off'; explain select * from t1 where pk1 < 7500 and key1 = 10; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index_merge PRIMARY,key1 key1,PRIMARY 4,4 NULL ROWS Using intersect(key1,PRIMARY); Using where +1 SIMPLE t1 ref PRIMARY,key1 key1 4 const ROWS Using index condition set optimizer_switch=@tmp_index_merge_ror_cpk; explain select * from t1 where pktail1ok=1 and key1=10; id select_type table type possible_keys key key_len ref rows Extra @@ -654,7 +654,7 @@ f1 EXPLAIN SELECT t1.f1 FROM t1 WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1 Using index +1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1 2 SUBQUERY t2 index_merge f2,f3 f3,f2 2,5 NULL 1 Using intersect(f3,f2); Using where; Using index DROP TABLE t1,t2; # @@ -827,13 +827,13 @@ INDEX (b) INSERT INTO t1 SELECT seq, seq, seq from seq_1_to_100; EXPLAIN SELECT * FROM t1 WHERE a='1' OR b < 5; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index_merge PRIMARY,b b,PRIMARY 5,3074 NULL 5 Using sort_union(b,PRIMARY); Using where +1 SIMPLE t1 ALL PRIMARY,b NULL NULL NULL 100 Using where SELECT * FROM t1 WHERE a='1' OR b < 5; a b c +1 1 1 2 2 2 3 3 3 4 4 4 -1 1 1 DROP TABLE t1; SET sort_buffer_size= @save_sort_buffer_size; disconnect disable_purge; diff --git a/mysql-test/main/index_merge_myisam.result b/mysql-test/main/index_merge_myisam.result index 30bda34ec0b..2c84086d17d 100644 --- a/mysql-test/main/index_merge_myisam.result +++ b/mysql-test/main/index_merge_myisam.result @@ -232,7 +232,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 index i1_3,i2_3 i321 12 NULL 1024 Using where; Using index explain select key7 from t2 where key1 <100 or key2 < 100; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index_merge i1_3,i2_3 i1_3,i2_3 4,4 NULL 186 Using sort_union(i1_3,i2_3); Using where +1 SIMPLE t2 ALL i1_3,i2_3 NULL NULL NULL 1024 Using where create table t4 ( key1a int not null, key1b int not null, @@ -405,8 +405,8 @@ from t0 as A straight_join t0 as B where (A.key1 = 1 and A.key2 = 1 and A.key3 = 1 and A.key4=1 and A.key5=1 and A.key6=1 and A.key7 = 1 or A.key8=1) and (B.key1 = 1 and B.key2 = 1 and B.key3 = 1 and B.key4=1 and B.key5=1 and B.key6=1 and B.key7 = 1 or B.key8=1); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE A index_merge i1,i2,i3,i4,i5,i6,i7?,i8 i2,i3,i4,i5,i6,i7?,i8 X NULL # Using union(intersect(i2,i3,i4,i5,i6,i7?),i8); Using where -1 SIMPLE B index_merge i1,i2,i3,i4,i5,i6,i7?,i8 i2,i3,i4,i5,i6,i7?,i8 X NULL # Using union(intersect(i2,i3,i4,i5,i6,i7?),i8); Using where; Using join buffer (flat, BNL join) +1 SIMPLE A ALL i1,i2,i3,i4,i5,i6,i7?,i8 NULL NULL NULL # Using where +1 SIMPLE B ALL i1,i2,i3,i4,i5,i6,i7?,i8 NULL NULL NULL # Using where; Using join buffer (flat, BNL join) select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5) from t0 as A straight_join t0 as B where (A.key1 = 1 and A.key2 = 1 and A.key3 = 1 and A.key4=1 and A.key5=1 and A.key6=1 and A.key7 = 1 or A.key8=1) @@ -762,13 +762,13 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index_merge sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,st_a,stb_swt1a_2b,stb_swt1b,st_b st_a,st_b 4,4 NULL 3515 Using intersect(st_a,st_b); Using where; Using index explain select st_a from t1 ignore index (st_a) where st_a=1 and st_b=1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,stb_swt1a_2b,stb_swt1b,st_b st_b 4 const 15094 Using where +1 SIMPLE t1 ALL sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,stb_swt1a_2b,stb_swt1b,st_b NULL NULL NULL 64806 Using where explain select * from t1 where st_a=1 and swt1a=1 and swt2a=1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,st_a sta_swt21a 12 const,const,const 971 explain select * from t1 where st_b=1 and swt1b=1 and swt2b=1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref stb_swt1a_2b,stb_swt1b,st_b stb_swt1b 8 const,const 3885 Using where +1 SIMPLE t1 ref stb_swt1a_2b,stb_swt1b,st_b stb_swt1a_2b 8 const,const 3879 Using where explain select * from t1 where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index_merge sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,st_a,stb_swt1a_2b,stb_swt1b,st_b sta_swt12a,stb_swt1a_2b 12,12 NULL 58 Using intersect(sta_swt12a,stb_swt1a_2b); Using where @@ -783,7 +783,7 @@ id select_type table type possible_keys key key_len ref rows Extra explain select * from t1 ignore index (sta_swt21a, sta_swt12a, stb_swt1a_2b, stb_swt1b) where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index_merge sta_swt1a,sta_swt2a,st_a,st_b sta_swt1a,sta_swt2a,st_b 8,8,4 NULL 223 Using intersect(sta_swt1a,sta_swt2a,st_b); Using where +1 SIMPLE t1 index_merge sta_swt1a,sta_swt2a,st_a,st_b sta_swt1a,sta_swt2a 8,8 NULL 960 Using intersect(sta_swt1a,sta_swt2a); Using where explain select * from t1 where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1; id select_type table type possible_keys key key_len ref rows Extra @@ -1558,7 +1558,7 @@ This should be intersect: set optimizer_switch=default; explain select * from t1 where a=10 and b=10; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index_merge a,b a,b 5,5 NULL 1 Using intersect(a,b); Using where +1 SIMPLE t1 ref|filter a,b a|b 5|5 const 49 (1%) Using where; Using rowid filter No intersect when index_merge is disabled: set optimizer_switch='default,index_merge=off,rowid_filter=off'; explain select * from t1 where a=10 and b=10; diff --git a/mysql-test/main/information_schema-big.result b/mysql-test/main/information_schema-big.result index 5c519014800..94c8d274fad 100644 --- a/mysql-test/main/information_schema-big.result +++ b/mysql-test/main/information_schema-big.result @@ -37,6 +37,7 @@ INDEX_STATISTICS TABLE_SCHEMA KEYWORDS WORD KEY_CACHES KEY_CACHE_NAME KEY_COLUMN_USAGE CONSTRAINT_SCHEMA +OPTIMIZER_COSTS ENGINE PARAMETERS SPECIFIC_SCHEMA PARTITIONS TABLE_SCHEMA PLUGINS PLUGIN_NAME @@ -97,6 +98,7 @@ INDEX_STATISTICS TABLE_SCHEMA KEYWORDS WORD KEY_CACHES KEY_CACHE_NAME KEY_COLUMN_USAGE CONSTRAINT_SCHEMA +OPTIMIZER_COSTS ENGINE PARAMETERS SPECIFIC_SCHEMA PARTITIONS TABLE_SCHEMA PLUGINS PLUGIN_NAME diff --git a/mysql-test/main/information_schema.result b/mysql-test/main/information_schema.result index e46014e44b9..0c952886d63 100644 --- a/mysql-test/main/information_schema.result +++ b/mysql-test/main/information_schema.result @@ -71,6 +71,7 @@ INDEX_STATISTICS KEYWORDS KEY_CACHES KEY_COLUMN_USAGE +OPTIMIZER_COSTS OPTIMIZER_TRACE PARAMETERS PARTITIONS @@ -1434,7 +1435,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE tables ALL NULL NULL NULL NULL NULL Open_frm_only; Scanned all databases; Using filesort explain select * from (select table_name from information_schema.tables) as a; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY ALL NULL NULL NULL NULL 2 +1 PRIMARY ALL NULL NULL NULL NULL 100 2 DERIVED tables ALL NULL NULL NULL NULL NULL Skip_open_table; Scanned all databases set optimizer_switch=@tmp_optimizer_switch; drop view v1; diff --git a/mysql-test/main/innodb_ext_key,off.rdiff b/mysql-test/main/innodb_ext_key,off.rdiff index 274d1cc47e4..8a1a251e88f 100644 --- a/mysql-test/main/innodb_ext_key,off.rdiff +++ b/mysql-test/main/innodb_ext_key,off.rdiff @@ -5,16 +5,13 @@ select count(*) from lineitem where l_orderkey=130 and l_shipdate='1992-07-01'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 8 const,const 1 Using index -+1 SIMPLE lineitem index_merge PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey,i_l_shipdate 4,4 NULL 1 Using intersect(i_l_orderkey,i_l_shipdate); Using where; Using index ++1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 const 6 Using where; Using index flush status; select count(*) from lineitem where l_orderkey=130 and l_shipdate='1992-07-01'; count(*) -@@ -17,9 +17,9 @@ - show status like 'handler_read%'; - Variable_name Value +@@ -19,7 +19,7 @@ Handler_read_first 0 --Handler_read_key 1 -+Handler_read_key 2 + Handler_read_key 1 Handler_read_last 0 -Handler_read_next 1 +Handler_read_next 6 @@ -98,16 +95,13 @@ where l_shipdate='1992-07-01' and l_orderkey=130; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -+1 SIMPLE lineitem index_merge PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey,i_l_shipdate 4,4 NULL 1 Using intersect(i_l_orderkey,i_l_shipdate); Using where; Using index ++1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 const 6 Using where; Using index flush status; select max(l_linenumber) from lineitem where l_shipdate='1992-07-01' and l_orderkey=130; -@@ -143,9 +143,9 @@ - show status like 'handler_read%'; - Variable_name Value +@@ -145,7 +145,7 @@ Handler_read_first 0 --Handler_read_key 1 -+Handler_read_key 2 + Handler_read_key 1 Handler_read_last 0 -Handler_read_next 0 +Handler_read_next 6 @@ -178,7 +172,7 @@ where l_partkey between 1 and 10 group by l_partkey; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem range i_l_suppkey_partkey,i_l_partkey i_l_partkey 5 NULL # Using where; Using index for group-by -+1 SIMPLE lineitem range i_l_suppkey_partkey,i_l_partkey i_l_partkey 5 NULL # Using where; Using index ++1 SIMPLE lineitem range i_l_suppkey_partkey,i_l_partkey i_l_suppkey_partkey 5 NULL # Using where; Using index flush status; select max(l_orderkey) from lineitem where l_partkey between 1 and 10 group by l_partkey; @@ -236,17 +230,17 @@ Handler_read_retry 0 Handler_read_rnd 0 @@ -314,8 +314,8 @@ - select * from t0, part ignore index (primary) + select straight_join * from t0, part ignore index (primary) where p_partkey=t0.a and p_size=1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t0 ALL NULL NULL NULL NULL 5 Using where -1 SIMPLE part eq_ref i_p_size i_p_size 9 const,dbt3_s001.t0.a 1 +1 SIMPLE t0 ALL NULL NULL NULL NULL 5 +1 SIMPLE part ref i_p_size i_p_size 5 const 5 Using index condition - select * from t0, part ignore index (primary) + select straight_join * from t0, part ignore index (primary) where p_partkey=t0.a and p_size=1; a p_partkey p_name p_mfgr p_brand p_type p_size p_container p_retailprice p_comment -@@ -494,7 +494,7 @@ +@@ -495,7 +495,7 @@ select * from t1, t3 where t3.col1=t1.a and t3.col2=t1.a and t3.pk1=t1.a; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where @@ -255,7 +249,7 @@ drop table t1,t2,t3; # # Bug mdev-4340: performance regression with extended_keys=on -@@ -725,13 +725,13 @@ +@@ -726,13 +726,13 @@ select * from t1 force index(index_date_updated) where index_date_updated= 10 and index_id < 800; id select_type table type possible_keys key key_len ref rows Extra @@ -271,7 +265,7 @@ drop table t0,t1,t2; # # MDEV-11196: Error:Run-Time Check Failure #2 - Stack around the variable 'key_buff' -@@ -766,13 +766,14 @@ +@@ -769,11 +769,12 @@ { "table": { "table_name": "t1", @@ -285,12 +279,9 @@ + "used_key_parts": ["f2"], + "ref": ["const"], "rows": 1, -- "filtered": 50, -+ "filtered": 100, + "filtered": 100, "index_condition": "t1.pk1 <= 5 and t1.pk2 <= 5 and t1.f2 = 'abc'", - "attached_condition": "t1.f1 <= '3'" - } -@@ -799,8 +800,8 @@ +@@ -806,8 +807,8 @@ "access_type": "range", "possible_keys": ["k1"], "key": "k1", @@ -299,5 +290,5 @@ + "key_length": "3007", + "used_key_parts": ["pk1", "f2"], "rows": 1, - "filtered": 50, + "filtered": 100, "index_condition": "t1.f2 <= 5 and t1.pk2 <= 5 and t1.pk1 = 'abc'", diff --git a/mysql-test/main/innodb_ext_key.result b/mysql-test/main/innodb_ext_key.result index 62b143726b2..ad27ad6b5ea 100644 --- a/mysql-test/main/innodb_ext_key.result +++ b/mysql-test/main/innodb_ext_key.result @@ -308,15 +308,15 @@ Handler_read_rnd_next 0 # when extended_keys=on # create table t0 (a int); -insert into t0 values (1), (2), (3), (4), (5); +insert into t0 select seq from seq_1_to_5; create index i_p_size on part(p_size); explain -select * from t0, part ignore index (primary) +select straight_join * from t0, part ignore index (primary) where p_partkey=t0.a and p_size=1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t0 ALL NULL NULL NULL NULL 5 Using where 1 SIMPLE part eq_ref i_p_size i_p_size 9 const,dbt3_s001.t0.a 1 -select * from t0, part ignore index (primary) +select straight_join * from t0, part ignore index (primary) where p_partkey=t0.a and p_size=1; a p_partkey p_name p_mfgr p_brand p_type p_size p_container p_retailprice p_comment 2 2 blush rosy metallic lemon navajo Manufacturer#1 Brand#13 LARGE BRUSHED BRASS 1 LG CASE 902 final platelets hang f @@ -381,17 +381,18 @@ INSERT INTO t2 VALUES (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (24); EXPLAIN -SELECT a FROM t1 AS t, t2 -WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b); +SELECT a FROM t1 AS t, t2 as t2_out +WHERE t2_out.c = t.a AND t.b IN (SELECT b FROM t1, t2 WHERE b = t.b); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t index a,b b 7 NULL 10 Using index -1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t.a 1 Using index -1 PRIMARY t1 ref b b 3 test.t.b 2 Using index -1 PRIMARY t2 index NULL PRIMARY 4 NULL 11 Using index; FirstMatch(t2) -SELECT a FROM t1 AS t, t2 -WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b); +1 PRIMARY t1 index b b 7 NULL 10 Using index; Start temporary +1 PRIMARY t ref a,b b 3 test.t1.b 2 Using index +1 PRIMARY t2 index NULL PRIMARY 4 NULL 11 Using index; End temporary; Using join buffer (flat, BNL join) +1 PRIMARY t2_out eq_ref PRIMARY PRIMARY 4 test.t.a 1 Using index +SELECT a FROM t1 AS t, t2 as t2_out +WHERE t2_out.c = t.a AND t.b IN (SELECT b FROM t1, t2 WHERE b = t.b); a 24 +Last_query_cost 0.119652 DROP TABLE t1,t2; # # LP Bug #923236: hash join + extended_keys = on @@ -638,7 +639,7 @@ test.t2 analyze status Engine-independent statistics collected test.t2 analyze status OK explain select a from t1 where b is null order by a desc limit 2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range b b 9 NULL 3 Using where; Using filesort +1 SIMPLE t1 index b PRIMARY 8 NULL 2 Using where select a from t1 where b is null order by a desc limit 2; a 3 @@ -774,7 +775,7 @@ EXPLAIN "key_length": "3070", "used_key_parts": ["f2", "pk1"], "rows": 1, - "filtered": 50, + "filtered": 100, "index_condition": "t1.pk1 <= 5 and t1.pk2 <= 5 and t1.f2 = 'abc'", "attached_condition": "t1.f1 <= '3'" } @@ -808,7 +809,7 @@ EXPLAIN "key_length": "3011", "used_key_parts": ["pk1", "f2", "pk2"], "rows": 1, - "filtered": 50, + "filtered": 100, "index_condition": "t1.f2 <= 5 and t1.pk2 <= 5 and t1.pk1 = 'abc'", "attached_condition": "t1.f1 <= '3'" } diff --git a/mysql-test/main/innodb_ext_key.test b/mysql-test/main/innodb_ext_key.test index 41a55232001..2b868154bd3 100644 --- a/mysql-test/main/innodb_ext_key.test +++ b/mysql-test/main/innodb_ext_key.test @@ -4,6 +4,7 @@ --source include/innodb_prefix_index_cluster_optimization.inc --source include/no_valgrind_without_big.inc +--source include/have_sequence.inc SET SESSION DEFAULT_STORAGE_ENGINE='InnoDB'; @@ -156,14 +157,14 @@ show status like 'handler_read%'; --echo # create table t0 (a int); -insert into t0 values (1), (2), (3), (4), (5); +insert into t0 select seq from seq_1_to_5; create index i_p_size on part(p_size); explain -select * from t0, part ignore index (primary) +select straight_join * from t0, part ignore index (primary) where p_partkey=t0.a and p_size=1; -select * from t0, part ignore index (primary) +select straight_join * from t0, part ignore index (primary) where p_partkey=t0.a and p_size=1; drop table t0; @@ -240,10 +241,11 @@ INSERT INTO t2 VALUES (15), (16), (17), (18), (19), (24); EXPLAIN -SELECT a FROM t1 AS t, t2 - WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b); -SELECT a FROM t1 AS t, t2 - WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b); +SELECT a FROM t1 AS t, t2 as t2_out + WHERE t2_out.c = t.a AND t.b IN (SELECT b FROM t1, t2 WHERE b = t.b); +SELECT a FROM t1 AS t, t2 as t2_out + WHERE t2_out.c = t.a AND t.b IN (SELECT b FROM t1, t2 WHERE b = t.b); +--source include/last_query_cost.inc DROP TABLE t1,t2; diff --git a/mysql-test/main/innodb_icp.result b/mysql-test/main/innodb_icp.result index e08faa142cf..bdbc2f6ccc1 100644 --- a/mysql-test/main/innodb_icp.result +++ b/mysql-test/main/innodb_icp.result @@ -414,7 +414,7 @@ WHERE (pk BETWEEN 4 AND 5 OR pk < 2) AND c1 < 240 ORDER BY c1 LIMIT 1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY,k1 PRIMARY 4 NULL 3 Using where; Using filesort +1 SIMPLE t1 range PRIMARY,k1 k1 5 NULL 4 Using where; Using index DROP TABLE t1; # # @@ -437,7 +437,7 @@ WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10 id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where 2 DEPENDENT SUBQUERY it eq_ref PRIMARY PRIMARY 4 func # Using where -2 DEPENDENT SUBQUERY t2 index NULL PRIMARY 4 NULL # Using index; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL # Using join buffer (flat, BNL join) SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10); pk i @@ -455,9 +455,10 @@ c1 INT NOT NULL, PRIMARY KEY (pk) ); INSERT INTO t1 VALUES (1,9),(2,7),(3,6),(4,3),(5,1); +insert into t1 select seq,seq from seq_100_to_110; EXPLAIN SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using where +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 15 Using where SET SESSION optimizer_switch='index_condition_pushdown=off'; SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3); pk c1 @@ -465,6 +466,17 @@ pk c1 2 7 4 3 5 1 +100 100 +101 101 +102 102 +103 103 +104 104 +105 105 +106 106 +107 107 +108 108 +109 109 +110 110 DROP TABLE t1; set optimizer_switch= @save_optimizer_switch; # @@ -682,7 +694,6 @@ DROP TABLE t1; # CREATE TABLE t1 (b int NOT NULL, c int, a varchar(1024), PRIMARY KEY (b)); INSERT INTO t1 VALUES (1,4,'Ill'); -insert into t1 select seq+100,5,seq from seq_1_to_100; CREATE TABLE t2 (a varchar(1024), KEY (a(512))); INSERT INTO t2 VALUES ('Ill'), ('eckqzsflbzaffti'), ('w'), ('she'), ('gxbwypqtjzwywwer'), ('w'); @@ -816,6 +827,8 @@ test.t2 analyze status Engine-independent statistics collected test.t2 analyze status OK SET @save_optimize_switch=@@optimizer_switch; SET optimizer_switch='materialization=on'; +set @save_optimizer_where_cost=@@optimizer_where_cost; +set @@optimizer_where_cost=1; EXPLAIN SELECT COUNT(*) FROM t1 AS t, t2 WHERE c = g @@ -839,6 +852,7 @@ OR a = 0 AND h < 'z' ); COUNT(*) 1478 SET optimizer_switch=@save_optimizer_switch; +set @@optimizer_where_cost=@save_optimizer_where_cost; DROP TABLE t1,t2; # check "Handler_pushed" status varuiables CREATE TABLE t1 ( diff --git a/mysql-test/main/innodb_mysql_lock2.test b/mysql-test/main/innodb_mysql_lock2.test index 09298a900b1..e5bb4bd9565 100644 --- a/mysql-test/main/innodb_mysql_lock2.test +++ b/mysql-test/main/innodb_mysql_lock2.test @@ -833,6 +833,7 @@ insert into t1 values (1), (2), (3), (4), (5); begin; --echo # Acquire SR metadata lock on t1. +--sorted_result select * from t1; connection con1; diff --git a/mysql-test/main/invisible_field_debug.result b/mysql-test/main/invisible_field_debug.result index 344a0b860fc..8cc1ee4db9c 100644 --- a/mysql-test/main/invisible_field_debug.result +++ b/mysql-test/main/invisible_field_debug.result @@ -346,7 +346,7 @@ invisible a b 9 7 7 explain select * from t1 where invisible =9; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL invisible NULL NULL NULL 7 Using where +1 SIMPLE t1 ref invisible invisible 5 const 7 alter table t1 add x int default 3; select invisible, a ,b from t1; invisible a b @@ -368,11 +368,11 @@ drop index invisible on t1; ERROR 42000: Can't DROP INDEX `invisible`; check that it exists explain select * from t1 where invisible =9; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL invisible NULL NULL NULL 7 Using where +1 SIMPLE t1 ref invisible invisible 5 const 7 create index invisible on t1(c); explain select * from t1 where invisible =9; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL invisible_2 NULL NULL NULL 7 Using where +1 SIMPLE t1 ref invisible_2 invisible_2 5 const 7 show indexes in t1; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored t1 1 b 1 b A NULL NULL NULL YES BTREE NO diff --git a/mysql-test/main/join.result b/mysql-test/main/join.result index b56f35f475e..c35ec009587 100644 --- a/mysql-test/main/join.result +++ b/mysql-test/main/join.result @@ -65,7 +65,7 @@ id id NULL 75 explain select t1.id,t2.id from t2 left join t1 on t1.id>=74 and t1.id<=0 where t2.id=75 and t1.id is null; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 const PRIMARY NULL NULL NULL 1 Impossible ON condition +1 SIMPLE t1 const PRIMARY NULL NULL NULL 0 Impossible ON condition 1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using where explain select t1.id, t2.id from t1, t2 where t2.id = t1.id and t1.id <0 and t1.id > 0; id select_type table type possible_keys key key_len ref rows Extra @@ -880,10 +880,10 @@ select @a:= A.a + 10*(B.a + 10*C.a), @a, 'filler' from t1 A, t1 B, t1 C; insert into t3 select * from t2 where a < 800; explain select * from t2,t3 where t2.a < 200 and t2.b=t3.b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range a,b a 5 NULL 198 Using index condition; Using where +1 SIMPLE t2 ALL a,b NULL NULL NULL 1000 Using where 1 SIMPLE t3 ref b b 5 test.t2.b 1 drop table t1, t2, t3; -create table t1 (a int); +create table t1 (a int) engine=myisam; insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); create table t2 (a int, b int, primary key(a)); insert into t2 select @v:=A.a+10*B.a, @v from t1 A, t1 B; @@ -892,14 +892,17 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 3.508545 +Last_query_cost 0.011600 select 'The cost of accessing t1 (dont care if it changes' '^'; The cost of accessing t1 (dont care if it changes The cost of accessing t1 (dont care if it changes^ select 'vv: Following query must use ALL(t1), eq_ref(A), eq_ref(B): vv' Z; Z vv: Following query must use ALL(t1), eq_ref(A), eq_ref(B): vv -set @@optimizer_cache_hit_ratio=0; +select @@myisam.optimizer_disk_read_ratio; +@@myisam.optimizer_disk_read_ratio +0.020000 +set global myisam.optimizer_disk_read_ratio=0; explain select * from t1, t2 A, t2 B where A.a = t1.a and B.a=A.b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where @@ -907,11 +910,14 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE B eq_ref PRIMARY PRIMARY 4 test.A.b 1 show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 48.527829 +Last_query_cost 0.046590 select '^^: The above should be ~= 40 + cost(select * from t1). Value less than 40 is an error' Z; Z ^^: The above should be ~= 40 + cost(select * from t1). Value less than 40 is an error -set @@optimizer_cache_hit_ratio=default; +set global myisam.optimizer_disk_read_ratio=default; +select @@myisam.optimizer_disk_read_ratio; +@@myisam.optimizer_disk_read_ratio +0.020000 drop table t1, t2; CREATE TABLE t1 (a INT PRIMARY KEY, b INT); CREATE TABLE t2 (c INT PRIMARY KEY, d INT); @@ -1278,7 +1284,7 @@ test.t2 analyze status Engine-independent statistics collected test.t2 analyze status OK explain SELECT * FROM t1 JOIN t2 ON t1.v = t2.v WHERE t2.v IS NULL ORDER BY 1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL ix2 NULL NULL NULL 2 Using where; Using temporary; Using filesort +1 SIMPLE t2 ref ix2 ix2 5 const 2 Using index condition; Using temporary; Using filesort 1 SIMPLE t1 ref ix1 ix1 5 test.t2.v 1 FLUSH STATUS; SELECT * FROM t1 JOIN t2 ON t1.v = t2.v WHERE t2.v IS NULL ORDER BY 1; @@ -1286,14 +1292,14 @@ pk v pk v SHOW STATUS LIKE 'Handler_read_%'; Variable_name Value Handler_read_first 0 -Handler_read_key 0 +Handler_read_key 1 Handler_read_last 0 Handler_read_next 0 Handler_read_prev 0 Handler_read_retry 0 Handler_read_rnd 0 Handler_read_rnd_deleted 0 -Handler_read_rnd_next 4 +Handler_read_rnd_next 1 DROP TABLE t1, t2; End of 5.1 tests # @@ -1329,9 +1335,9 @@ FROM t4 JOIN (t1 JOIN t3 ON t3.ref_t1=t1.c1 JOIN t2 ON t2.ref_t1=t1.c1) ON t4.ref_t1=t1.c1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t4 ALL NULL NULL NULL NULL 4 -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) -1 SIMPLE t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE t4 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t4.ref_t1 1 +1 SIMPLE t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (incremental, BNL join) EXPLAIN SELECT * @@ -1340,9 +1346,9 @@ FROM t4 STRAIGHT_JOIN ON t4.ref_t1=t1.c1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t4 ALL NULL NULL NULL NULL 4 Using where -1 SIMPLE t2 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t4.ref_t1 1 -1 SIMPLE t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t2 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (incremental, BNL join) drop table t1,t2,t3,t4; End of 5.2 tests # @@ -1479,8 +1485,8 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE DU system dog_id NULL NULL NULL 1 1 SIMPLE D system PRIMARY NULL NULL NULL 1 1 SIMPLE DSAR system NULL NULL NULL NULL 1 -1 SIMPLE DT ALL t_id NULL NULL NULL 2 Using where -1 SIMPLE DSA ref PRIMARY PRIMARY 8 const,test.DT.t_id,func 1 Using index +1 SIMPLE DSA ref PRIMARY PRIMARY 4 const 3 Using where; Using index +1 SIMPLE DT ref t_id t_id 2 test.DSA.t_id 2 Using where SELECT * FROM t5 DU, t1 D, t4 DT, t2 DSA, t3 DSAR WHERE DU.dog_id=D.dog_id AND D.dog_id=DT.dog_id AND D.birthday=DT.birthday AND DT.t_id=DSA.t_id AND DT.birthday=DSA.birthday AND DSA.dog_id=DSAR.dog_id; diff --git a/mysql-test/main/join.test b/mysql-test/main/join.test index a3756af023a..dfe92ff9561 100644 --- a/mysql-test/main/join.test +++ b/mysql-test/main/join.test @@ -685,7 +685,7 @@ drop table t1, t2, t3; # BUG#14940 {Wrong query plan is chosen because of odd results of # prev_record_reads() function } -create table t1 (a int); +create table t1 (a int) engine=myisam; insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); create table t2 (a int, b int, primary key(a)); @@ -697,11 +697,13 @@ select 'The cost of accessing t1 (dont care if it changes' '^'; select 'vv: Following query must use ALL(t1), eq_ref(A), eq_ref(B): vv' Z; -set @@optimizer_cache_hit_ratio=0; +select @@myisam.optimizer_disk_read_ratio; +set global myisam.optimizer_disk_read_ratio=0; explain select * from t1, t2 A, t2 B where A.a = t1.a and B.a=A.b; show status like 'Last_query_cost'; select '^^: The above should be ~= 40 + cost(select * from t1). Value less than 40 is an error' Z; -set @@optimizer_cache_hit_ratio=default; +set global myisam.optimizer_disk_read_ratio=default; +select @@myisam.optimizer_disk_read_ratio; drop table t1, t2; # diff --git a/mysql-test/main/join_cache.result b/mysql-test/main/join_cache.result index 2c5323a7795..0f7ad1d23f7 100644 --- a/mysql-test/main/join_cache.result +++ b/mysql-test/main/join_cache.result @@ -894,7 +894,7 @@ LENGTH(Language) < LENGTH(City.Name) - 2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where 1 SIMPLE Country hash_ALL PRIMARY #hash#PRIMARY 3 world.City.Country 239 Using where; Using join buffer (flat, BNLH join) -1 SIMPLE CountryLanguage hash_range PRIMARY,Percentage #hash#PRIMARY:Percentage 3:4 world.City.Country 185 Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join) +1 SIMPLE CountryLanguage hash_ALL|filter PRIMARY,Percentage #hash#PRIMARY|Percentage 3|4 world.City.Country 984 (19%) Using where; Using join buffer (flat, BNLH join); Using rowid filter # Part 2, join_cache_level=3, Query 4 SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -1102,7 +1102,7 @@ LENGTH(Language) < LENGTH(City.Name) - 2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where 1 SIMPLE Country hash_ALL PRIMARY #hash#PRIMARY 3 world.City.Country 239 Using where; Using join buffer (flat, BNLH join) -1 SIMPLE CountryLanguage hash_range PRIMARY,Percentage #hash#PRIMARY:Percentage 3:4 world.City.Country 185 Using where; Rowid-ordered scan; Using join buffer (incremental, BNLH join) +1 SIMPLE CountryLanguage hash_ALL|filter PRIMARY,Percentage #hash#PRIMARY|Percentage 3|4 world.City.Country 984 (19%) Using where; Using join buffer (incremental, BNLH join); Using rowid filter # Part 2, join_cache_level=4, Query 4 SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -2162,7 +2162,7 @@ LENGTH(Language) < LENGTH(City.Name) - 2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where 1 SIMPLE Country hash_ALL PRIMARY #hash#PRIMARY 3 world.City.Country 239 Using where; Using join buffer (flat, BNLH join) -1 SIMPLE CountryLanguage hash_range PRIMARY,Percentage #hash#PRIMARY:Percentage 3:4 world.City.Country 185 Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join) +1 SIMPLE CountryLanguage hash_ALL|filter PRIMARY,Percentage #hash#PRIMARY|Percentage 3|4 world.City.Country 984 (19%) Using where; Using join buffer (flat, BNLH join); Using rowid filter SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -2266,7 +2266,7 @@ LENGTH(Language) < LENGTH(City.Name) - 2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where 1 SIMPLE Country hash_ALL PRIMARY #hash#PRIMARY 3 world.City.Country 239 Using where; Using join buffer (flat, BNLH join) -1 SIMPLE CountryLanguage hash_range PRIMARY,Percentage #hash#PRIMARY:Percentage 3:4 world.City.Country 185 Using where; Rowid-ordered scan; Using join buffer (incremental, BNLH join) +1 SIMPLE CountryLanguage hash_ALL|filter PRIMARY,Percentage #hash#PRIMARY|Percentage 3|4 world.City.Country 984 (19%) Using where; Using join buffer (incremental, BNLH join); Using rowid filter SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -3133,7 +3133,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t8 eq_ref PRIMARY PRIMARY 4 test.t7.artistid 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE t3 ref t3_metaid,t3_formatid,t3_metaidformatid t3_metaidformatid 4 test.t9.metaid 1 Using index condition; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE t4 eq_ref PRIMARY,t4_formatclassid,t4_formats_idx PRIMARY 4 test.t3.formatid 1 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan -1 SIMPLE t1 ALL t1_affiliateid,t1_metaid NULL NULL NULL 2 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE t1 ref t1_affiliateid,t1_metaid t1_affiliateid 4 const 2 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan SELECT t1.uniquekey, t1.xml AS affiliateXml, t8.name AS artistName, t8.artistid, t11.name AS genreName, t11.genreid, t11.priority AS genrePriority, @@ -3249,7 +3249,7 @@ Warning 1292 Truncated incorrect join_buffer_size value: '32' set join_cache_level=8; EXPLAIN SELECT * FROM t1,t2 WHERE t1.a=t2.a AND t1.b >= 30; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL idx NULL NULL NULL 7 Using where +1 SIMPLE t1 range idx idx 5 NULL 3 Using index condition; Using where; Rowid-ordered scan 1 SIMPLE t2 ref idx idx 5 test.t1.a 2 Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan SELECT * FROM t1,t2 WHERE t1.a=t2.a AND t1.b >= 30; a b a b @@ -4398,9 +4398,9 @@ SELECT t2.v FROM t1, t2, t3 WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 GROUP BY t2.v ORDER BY t1.pk,t2.v; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using index; Using temporary; Using filesort +1 SIMPLE t1 ALL idx2 NULL NULL NULL 44 Using where; Using temporary; Using filesort +1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using where; Using index; Using join buffer (flat, BNL join) 1 SIMPLE t3 eq_ref PRIMARY,idx2 PRIMARY 4 test.t2.i 1 Using where -1 SIMPLE t1 ref idx2 idx2 3 test.t3.v 5 Using where SELECT t2.v FROM t1, t2, t3 WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 GROUP BY t2.v ORDER BY t1.pk,t2.v; @@ -4415,9 +4415,9 @@ SELECT t2.v FROM t1, t2, t3 WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 GROUP BY t2.v ORDER BY t1.pk,t2.v; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using index; Using temporary; Using filesort +1 SIMPLE t1 ALL idx2 NULL NULL NULL 44 Using where; Using temporary; Using filesort +1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using where; Using index; Using join buffer (flat, BNL join) 1 SIMPLE t3 eq_ref PRIMARY,idx2 PRIMARY 4 test.t2.i 1 Using where -1 SIMPLE t1 ref idx2 idx2 3 test.t3.v 5 Using where SELECT t2.v FROM t1, t2, t3 WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 GROUP BY t2.v ORDER BY t1.pk,t2.v; @@ -4433,9 +4433,9 @@ SELECT t2.v FROM t1, t2, t3 WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 GROUP BY t2.v ORDER BY t1.pk,t2.v; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using index; Using temporary; Using filesort -1 SIMPLE t3 eq_ref PRIMARY,idx2 PRIMARY 4 test.t2.i 1 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan -1 SIMPLE t1 ref idx2 idx2 3 test.t3.v 5 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan +1 SIMPLE t1 ALL idx2 NULL NULL NULL 44 Using where; Using temporary; Using filesort +1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using where; Using index; Using join buffer (flat, BNL join) +1 SIMPLE t3 eq_ref PRIMARY,idx2 PRIMARY 4 test.t2.i 1 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan SELECT t2.v FROM t1, t2, t3 WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 GROUP BY t2.v ORDER BY t1.pk,t2.v; @@ -4450,9 +4450,9 @@ SELECT t2.v FROM t1, t2, t3 WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 GROUP BY t2.v ORDER BY t1.pk,t2.v; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using index; Using temporary; Using filesort -1 SIMPLE t3 eq_ref PRIMARY,idx2 PRIMARY 4 test.t2.i 1 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan -1 SIMPLE t1 ref idx2 idx2 3 test.t3.v 5 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan +1 SIMPLE t1 ALL idx2 NULL NULL NULL 44 Using where; Using temporary; Using filesort +1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using where; Using index; Using join buffer (flat, BNL join) +1 SIMPLE t3 eq_ref PRIMARY,idx2 PRIMARY 4 test.t2.i 1 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan SELECT t2.v FROM t1, t2, t3 WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 GROUP BY t2.v ORDER BY t1.pk,t2.v; @@ -4468,9 +4468,9 @@ SELECT t2.v FROM t1, t2, t3 WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 GROUP BY t2.v ORDER BY t1.pk,t2.v; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using index; Using temporary; Using filesort -1 SIMPLE t3 hash_ALL PRIMARY,idx2 #hash#PRIMARY 4 test.t2.i 20 Using where; Using join buffer (flat, BNLH join) -1 SIMPLE t1 hash_ALL idx2 #hash#idx2 3 test.t3.v 44 Using where; Using join buffer (incremental, BNLH join) +1 SIMPLE t1 ALL idx2 NULL NULL NULL 44 Using where; Using temporary; Using filesort +1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using where; Using index; Using join buffer (flat, BNL join) +1 SIMPLE t3 hash_ALL PRIMARY,idx2 #hash#PRIMARY 4 test.t2.i 20 Using where; Using join buffer (incremental, BNLH join) SELECT t2.v FROM t1, t2, t3 WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 GROUP BY t2.v ORDER BY t1.pk,t2.v; @@ -4485,9 +4485,9 @@ SELECT t2.v FROM t1, t2, t3 WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 GROUP BY t2.v ORDER BY t1.pk,t2.v; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using index; Using temporary; Using filesort -1 SIMPLE t3 hash_ALL PRIMARY,idx2 #hash#PRIMARY 4 test.t2.i 20 Using where; Using join buffer (flat, BNLH join) -1 SIMPLE t1 hash_ALL idx2 #hash#idx2 3 test.t3.v 44 Using where; Using join buffer (incremental, BNLH join) +1 SIMPLE t1 ALL idx2 NULL NULL NULL 44 Using where; Using temporary; Using filesort +1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using where; Using index; Using join buffer (flat, BNL join) +1 SIMPLE t3 hash_ALL PRIMARY,idx2 #hash#PRIMARY 4 test.t2.i 20 Using where; Using join buffer (incremental, BNLH join) SELECT t2.v FROM t1, t2, t3 WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 GROUP BY t2.v ORDER BY t1.pk,t2.v; @@ -5120,7 +5120,7 @@ EXPLAIN SELECT * FROM t1,t2 WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 2 Using where +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using where; Rowid-ordered scan 1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using where; Rowid-ordered scan; Using join buffer (flat, BNL join) SELECT * FROM t1,t2 WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6); @@ -5130,7 +5130,7 @@ EXPLAIN SELECT * FROM t1,t2 WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 2 Using where +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Rowid-ordered scan 1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using join buffer (flat, BNL join) SELECT * FROM t1,t2 WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6); @@ -6035,12 +6035,12 @@ f1 f2 EXPLAIN EXTENDED SELECT * FROM temp WHERE (f1,f2) IN (SELECT t1.i1, t1.v1 FROM (t2 JOIN t1 ON (t1.v1 = t2.v1))); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY ALL distinct_key NULL NULL NULL 1 100.00 -1 PRIMARY temp hash_ALL NULL #hash#$hj 9 test.t1.i1,test.t1.v1 7 100.00 Using where; Using join buffer (flat, BNLH join) +1 PRIMARY temp ALL NULL NULL NULL NULL 7 100.00 +1 PRIMARY eq_ref distinct_key distinct_key 8 func,func 1 100.00 2 MATERIALIZED t1 ALL NULL NULL NULL NULL 1 100.00 Using where 2 MATERIALIZED t2 hash_index v1 #hash#v1:v1 4:9 test.t1.v1 10 33.33 Using index; Using join buffer (flat, BNLH join) Warnings: -Note 1003 select `test`.`temp`.`f1` AS `f1`,`test`.`temp`.`f2` AS `f2` from `test`.`temp` semi join (`test`.`t2` join `test`.`t1`) where `test`.`temp`.`f1` = `test`.`t1`.`i1` and `test`.`t2`.`v1` = `test`.`t1`.`v1` and `test`.`temp`.`f2` = `test`.`t1`.`v1` +Note 1003 select `test`.`temp`.`f1` AS `f1`,`test`.`temp`.`f2` AS `f2` from `test`.`temp` semi join (`test`.`t2` join `test`.`t1`) where `test`.`t2`.`v1` = `test`.`t1`.`v1` DROP TABLE t1,t2,temp; set join_cache_level=@save_join_cache_level; # @@ -6210,8 +6210,8 @@ a b c explain select t1.a, t1.b, t1.c from t1,t2 where t2.a = t1.a and t2.b = t1.b and t2.c=t1.c; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index PRIMARY PRIMARY 12 NULL 2 Using index -1 SIMPLE t1 hash_ALL NULL #hash#$hj 15 test.t2.a,test.t2.b,test.t2.c 2 Using where; Using join buffer (flat, BNLH join) +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where +1 SIMPLE t2 hash_index PRIMARY #hash#PRIMARY:PRIMARY 12:12 test.t1.c,test.t1.a,test.t1.b 2 Using index; Using join buffer (flat, BNLH join) drop table t1,t2; set join_cache_level=@save_join_cache_level; # @@ -6258,7 +6258,7 @@ EXPLAIN { "table": { "table_name": "a", - "access_type": "index", + "access_type": "range", "possible_keys": ["PRIMARY"], "key": "PRIMARY", "key_length": "4", @@ -6279,7 +6279,7 @@ EXPLAIN "key_length": "10", "used_key_parts": ["kp1", "kp2"], "rows": 836, - "filtered": 76, + "filtered": 9.090909004, "index_condition": "b.kp2 <= 10", "attached_condition": "b.kp2 <= 10 and b.col1 + 1 < 33333" }, diff --git a/mysql-test/main/join_nested.result b/mysql-test/main/join_nested.result index 1f8ffccf16b..96f4372ee14 100644 --- a/mysql-test/main/join_nested.result +++ b/mysql-test/main/join_nested.result @@ -1062,7 +1062,7 @@ t0.b=t1.b AND (t8.b=t9.b OR t8.c IS NULL) AND (t9.a=1); id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t0 ALL idx_a NULL NULL NULL 3 66.67 Using where +1 SIMPLE t0 ref idx_a idx_a 5 const 2 100.00 Using where 1 SIMPLE t1 ref idx_b idx_b 5 test.t0.b 2 100.00 1 SIMPLE t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t5 ALL idx_b NULL NULL NULL 7 100.00 Using where @@ -1284,8 +1284,8 @@ NULL 2 2 DELETE FROM t3; EXPLAIN SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 const c NULL NULL NULL 1 Impossible ON condition -1 SIMPLE t2 const b NULL NULL NULL 1 Impossible ON condition +1 SIMPLE t3 const c NULL NULL NULL 0 Impossible ON condition +1 SIMPLE t2 const b NULL NULL NULL 0 Impossible ON condition 1 SIMPLE t1 index NULL a 5 NULL 21 Using index SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c; a b c diff --git a/mysql-test/main/join_nested_jcl6.result b/mysql-test/main/join_nested_jcl6.result index c5386983ceb..a62bba19f16 100644 --- a/mysql-test/main/join_nested_jcl6.result +++ b/mysql-test/main/join_nested_jcl6.result @@ -652,7 +652,6 @@ t0.b=t1.b AND id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t0 ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t1 hash_ALL NULL #hash#$hj 5 test.t0.b 3 100.00 Using where; Using join buffer (flat, BNLH join) -1 SIMPLE t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t3 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t4 hash_ALL NULL #hash#$hj 5 test.t2.b 2 100.00 Using where; Using join buffer (incremental, BNLH join) @@ -660,8 +659,9 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t7 hash_ALL NULL #hash#$hj 5 test.t5.b 2 100.00 Using where; Using join buffer (incremental, BNLH join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t8 hash_ALL NULL #hash#$hj 5 test.t5.b 2 100.00 Using where; Using join buffer (incremental, BNLH join) +1 SIMPLE t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join) Warnings: -Note 1003 select `test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t5`.`a` AS `a`,`test`.`t5`.`b` AS `b`,`test`.`t6`.`a` AS `a`,`test`.`t6`.`b` AS `b`,`test`.`t7`.`a` AS `a`,`test`.`t7`.`b` AS `b`,`test`.`t8`.`a` AS `a`,`test`.`t8`.`b` AS `b`,`test`.`t9`.`a` AS `a`,`test`.`t9`.`b` AS `b` from `test`.`t0` join `test`.`t1` left join (`test`.`t2` left join (`test`.`t3` join `test`.`t4`) on(`test`.`t3`.`a` = 1 and `test`.`t4`.`b` = `test`.`t2`.`b` and `test`.`t2`.`b` is not null) join `test`.`t5` left join (`test`.`t6` join `test`.`t7` left join `test`.`t8` on(`test`.`t8`.`b` = `test`.`t5`.`b` and `test`.`t6`.`b` < 10 and `test`.`t5`.`b` is not null)) on(`test`.`t7`.`b` = `test`.`t5`.`b` and `test`.`t6`.`b` >= 2 and `test`.`t5`.`b` is not null)) on((`test`.`t3`.`b` = 2 or `test`.`t3`.`c` is null) and (`test`.`t6`.`b` = 2 or `test`.`t6`.`c` is null) and (`test`.`t5`.`b` = `test`.`t0`.`b` or `test`.`t3`.`c` is null or `test`.`t6`.`c` is null or `test`.`t8`.`c` is null) and `test`.`t1`.`a` <> 2) join `test`.`t9` where `test`.`t0`.`a` = 1 and `test`.`t1`.`b` = `test`.`t0`.`b` and `test`.`t9`.`a` = 1 and (`test`.`t2`.`a` >= 4 or `test`.`t2`.`c` is null) and (`test`.`t3`.`a` < 5 or `test`.`t3`.`c` is null) and (`test`.`t4`.`b` = `test`.`t3`.`b` or `test`.`t3`.`c` is null or `test`.`t4`.`c` is null) and (`test`.`t5`.`a` >= 2 or `test`.`t5`.`c` is null) and (`test`.`t6`.`a` >= 4 or `test`.`t6`.`c` is null) and (`test`.`t7`.`a` <= 2 or `test`.`t7`.`c` is null) and (`test`.`t8`.`a` < 1 or `test`.`t8`.`c` is null) and (`test`.`t8`.`b` = `test`.`t9`.`b` or `test`.`t8`.`c` is null) +Note 1003 select `test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t5`.`a` AS `a`,`test`.`t5`.`b` AS `b`,`test`.`t6`.`a` AS `a`,`test`.`t6`.`b` AS `b`,`test`.`t7`.`a` AS `a`,`test`.`t7`.`b` AS `b`,`test`.`t8`.`a` AS `a`,`test`.`t8`.`b` AS `b`,`test`.`t9`.`a` AS `a`,`test`.`t9`.`b` AS `b` from `test`.`t0` join `test`.`t1` left join (`test`.`t2` left join (`test`.`t3` join `test`.`t4`) on(`test`.`t3`.`a` = 1 and `test`.`t4`.`b` = `test`.`t2`.`b` and `test`.`t2`.`b` is not null) join `test`.`t5` left join (`test`.`t6` join `test`.`t7` left join `test`.`t8` on(`test`.`t8`.`b` = `test`.`t5`.`b` and `test`.`t6`.`b` < 10 and `test`.`t5`.`b` is not null)) on(`test`.`t7`.`b` = `test`.`t5`.`b` and `test`.`t6`.`b` >= 2 and `test`.`t5`.`b` is not null)) on((`test`.`t3`.`b` = 2 or `test`.`t3`.`c` is null) and (`test`.`t6`.`b` = 2 or `test`.`t6`.`c` is null) and (`test`.`t5`.`b` = `test`.`t0`.`b` or `test`.`t3`.`c` is null or `test`.`t6`.`c` is null or `test`.`t8`.`c` is null) and `test`.`t1`.`a` <> 2) join `test`.`t9` where `test`.`t0`.`a` = 1 and `test`.`t1`.`b` = `test`.`t0`.`b` and `test`.`t9`.`a` = 1 and (`test`.`t2`.`a` >= 4 or `test`.`t2`.`c` is null) and (`test`.`t3`.`a` < 5 or `test`.`t3`.`c` is null) and (`test`.`t4`.`b` = `test`.`t3`.`b` or `test`.`t3`.`c` is null or `test`.`t4`.`c` is null) and (`test`.`t5`.`a` >= 2 or `test`.`t5`.`c` is null) and (`test`.`t6`.`a` >= 4 or `test`.`t6`.`c` is null) and (`test`.`t7`.`a` <= 2 or `test`.`t7`.`c` is null) and (`test`.`t8`.`a` < 1 or `test`.`t8`.`c` is null) and (`test`.`t9`.`b` = `test`.`t8`.`b` or `test`.`t8`.`c` is null) SELECT t9.a,t9.b FROM t9; a b @@ -920,7 +920,6 @@ t0.b=t1.b AND id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t0 ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t1 hash_ALL NULL #hash#$hj 5 test.t0.b 3 100.00 Using where; Using join buffer (flat, BNLH join) -1 SIMPLE t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t5 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t7 hash_ALL NULL #hash#$hj 5 test.t5.b 2 100.00 Using where; Using join buffer (incremental, BNLH join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join) @@ -928,8 +927,9 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 8 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t3 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t4 hash_ALL NULL #hash#$hj 5 test.t2.b 2 100.00 Using where; Using join buffer (incremental, BNLH join) +1 SIMPLE t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join) Warnings: -Note 1003 select `test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t5`.`a` AS `a`,`test`.`t5`.`b` AS `b`,`test`.`t6`.`a` AS `a`,`test`.`t6`.`b` AS `b`,`test`.`t7`.`a` AS `a`,`test`.`t7`.`b` AS `b`,`test`.`t8`.`a` AS `a`,`test`.`t8`.`b` AS `b`,`test`.`t9`.`a` AS `a`,`test`.`t9`.`b` AS `b` from `test`.`t0` join `test`.`t1` left join (`test`.`t2` left join (`test`.`t3` join `test`.`t4`) on(`test`.`t3`.`a` = 1 and `test`.`t4`.`b` = `test`.`t2`.`b` and `test`.`t2`.`a` > 0 and `test`.`t2`.`b` is not null) join `test`.`t5` left join (`test`.`t6` join `test`.`t7` left join `test`.`t8` on(`test`.`t8`.`b` = `test`.`t5`.`b` and `test`.`t6`.`b` < 10 and `test`.`t5`.`b` is not null)) on(`test`.`t7`.`b` = `test`.`t5`.`b` and `test`.`t6`.`b` >= 2 and `test`.`t5`.`b` is not null)) on((`test`.`t3`.`b` = 2 or `test`.`t3`.`c` is null) and (`test`.`t6`.`b` = 2 or `test`.`t6`.`c` is null) and (`test`.`t5`.`b` = `test`.`t0`.`b` or `test`.`t3`.`c` is null or `test`.`t6`.`c` is null or `test`.`t8`.`c` is null) and `test`.`t1`.`a` <> 2) join `test`.`t9` where `test`.`t0`.`a` = 1 and `test`.`t1`.`b` = `test`.`t0`.`b` and `test`.`t9`.`a` = 1 and (`test`.`t2`.`a` >= 4 or `test`.`t2`.`c` is null) and (`test`.`t3`.`a` < 5 or `test`.`t3`.`c` is null) and (`test`.`t4`.`b` = `test`.`t3`.`b` or `test`.`t3`.`c` is null or `test`.`t4`.`c` is null) and (`test`.`t5`.`a` >= 2 or `test`.`t5`.`c` is null) and (`test`.`t6`.`a` >= 4 or `test`.`t6`.`c` is null) and (`test`.`t7`.`a` <= 2 or `test`.`t7`.`c` is null) and (`test`.`t8`.`a` < 1 or `test`.`t8`.`c` is null) and (`test`.`t8`.`b` = `test`.`t9`.`b` or `test`.`t8`.`c` is null) +Note 1003 select `test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t5`.`a` AS `a`,`test`.`t5`.`b` AS `b`,`test`.`t6`.`a` AS `a`,`test`.`t6`.`b` AS `b`,`test`.`t7`.`a` AS `a`,`test`.`t7`.`b` AS `b`,`test`.`t8`.`a` AS `a`,`test`.`t8`.`b` AS `b`,`test`.`t9`.`a` AS `a`,`test`.`t9`.`b` AS `b` from `test`.`t0` join `test`.`t1` left join (`test`.`t2` left join (`test`.`t3` join `test`.`t4`) on(`test`.`t3`.`a` = 1 and `test`.`t4`.`b` = `test`.`t2`.`b` and `test`.`t2`.`a` > 0 and `test`.`t2`.`b` is not null) join `test`.`t5` left join (`test`.`t6` join `test`.`t7` left join `test`.`t8` on(`test`.`t8`.`b` = `test`.`t5`.`b` and `test`.`t6`.`b` < 10 and `test`.`t5`.`b` is not null)) on(`test`.`t7`.`b` = `test`.`t5`.`b` and `test`.`t6`.`b` >= 2 and `test`.`t5`.`b` is not null)) on((`test`.`t3`.`b` = 2 or `test`.`t3`.`c` is null) and (`test`.`t6`.`b` = 2 or `test`.`t6`.`c` is null) and (`test`.`t5`.`b` = `test`.`t0`.`b` or `test`.`t3`.`c` is null or `test`.`t6`.`c` is null or `test`.`t8`.`c` is null) and `test`.`t1`.`a` <> 2) join `test`.`t9` where `test`.`t0`.`a` = 1 and `test`.`t1`.`b` = `test`.`t0`.`b` and `test`.`t9`.`a` = 1 and (`test`.`t2`.`a` >= 4 or `test`.`t2`.`c` is null) and (`test`.`t3`.`a` < 5 or `test`.`t3`.`c` is null) and (`test`.`t4`.`b` = `test`.`t3`.`b` or `test`.`t3`.`c` is null or `test`.`t4`.`c` is null) and (`test`.`t5`.`a` >= 2 or `test`.`t5`.`c` is null) and (`test`.`t6`.`a` >= 4 or `test`.`t6`.`c` is null) and (`test`.`t7`.`a` <= 2 or `test`.`t7`.`c` is null) and (`test`.`t8`.`a` < 1 or `test`.`t8`.`c` is null) and (`test`.`t9`.`b` = `test`.`t8`.`b` or `test`.`t8`.`c` is null) INSERT INTO t4 VALUES (-3,12,0), (-4,13,0), (-1,11,0), (-3,11,0), (-5,15,0); INSERT INTO t5 VALUES (-3,11,0), (-2,12,0), (-3,13,0), (-4,12,0); CREATE INDEX idx_b ON t4(b); @@ -1071,7 +1071,7 @@ t0.b=t1.b AND (t8.b=t9.b OR t8.c IS NULL) AND (t9.a=1); id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t0 ALL idx_a NULL NULL NULL 3 66.67 Using where +1 SIMPLE t0 ref idx_a idx_a 5 const 2 100.00 Using where 1 SIMPLE t1 ref idx_b idx_b 5 test.t0.b 2 100.00 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t5 ALL idx_b NULL NULL NULL 7 100.00 Using where; Using join buffer (incremental, BNL join) @@ -1293,8 +1293,8 @@ NULL 2 2 DELETE FROM t3; EXPLAIN SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 const c NULL NULL NULL 1 Impossible ON condition -1 SIMPLE t2 const b NULL NULL NULL 1 Impossible ON condition +1 SIMPLE t3 const c NULL NULL NULL 0 Impossible ON condition +1 SIMPLE t2 const b NULL NULL NULL 0 Impossible ON condition 1 SIMPLE t1 index NULL a 5 NULL 21 Using index SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c; a b c @@ -2086,7 +2086,7 @@ ON t6.b >= 2 AND t5.b=t7.b AND id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t5 ALL NULL NULL NULL NULL 3 1 SIMPLE t7 ref|filter PRIMARY,b_i b_i|PRIMARY 5|4 test.t5.b 2 (29%) Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter -1 SIMPLE t6 ALL PRIMARY,b_i NULL NULL NULL 7 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE t6 range|filter PRIMARY,b_i PRIMARY|b_i 4|5 NULL 3 (86%) Using where; Rowid-ordered scan; Using join buffer (incremental, BNL join); Using rowid filter 1 SIMPLE t8 ref b_i b_i 5 test.t5.b 2 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b FROM t5 @@ -2120,9 +2120,9 @@ FROM t5 LEFT JOIN ON (t5.b=t8.b); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t5 ALL NULL NULL NULL NULL 2 -1 SIMPLE t6 ALL NULL NULL NULL NULL 1 Using join buffer (flat, BNL join) +1 SIMPLE t6 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t7 const PRIMARY PRIMARY 4 const 1 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan -1 SIMPLE t8 ALL b_i NULL NULL NULL 1 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE t8 ref b_i b_i 5 test.t5.b 2 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b FROM t5 LEFT JOIN (t6 LEFT JOIN t7 ON t7.a=1, t8) @@ -2137,9 +2137,9 @@ FROM t5 LEFT JOIN ON (t5.b=t8.b); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t5 ALL NULL NULL NULL NULL 2 -1 SIMPLE t6 ALL NULL NULL NULL NULL 1 Using join buffer (flat, BNL join) +1 SIMPLE t6 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t7 ref b_i b_i 5 const 1 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan -1 SIMPLE t8 ALL b_i NULL NULL NULL 1 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE t8 ref b_i b_i 5 test.t5.b 2 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b FROM t5 LEFT JOIN (t6 LEFT JOIN t7 ON t7.b=2, t8) @@ -2154,9 +2154,9 @@ FROM t5 LEFT JOIN ON (t5.b=t8.b); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t5 ALL NULL NULL NULL NULL 2 -1 SIMPLE t8 ALL b_i NULL NULL NULL 1 Using where; Using join buffer (flat, BNL join) -1 SIMPLE t6 ALL NULL NULL NULL NULL 1 Using join buffer (incremental, BNL join) +1 SIMPLE t6 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t7 const PRIMARY PRIMARY 4 const 1 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan +1 SIMPLE t8 ref b_i b_i 5 test.t5.b 2 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b FROM t5 LEFT JOIN (t8, t6 LEFT JOIN t7 ON t7.a=1) diff --git a/mysql-test/main/join_outer.result b/mysql-test/main/join_outer.result index eb5bf0e1700..6ed5114ea5b 100644 --- a/mysql-test/main/join_outer.result +++ b/mysql-test/main/join_outer.result @@ -1430,7 +1430,7 @@ WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL GROUP BY t2.f1, t2.f2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system PRIMARY NULL NULL NULL 1 -1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index; Using filesort +1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index SELECT * FROM t1 LEFT JOIN t2 ON t2.f1 = t1.f1 WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL GROUP BY t2.f1, t2.f2; @@ -1852,7 +1852,7 @@ WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL GROUP BY t2.f1, t2.f2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system PRIMARY NULL NULL NULL 1 -1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index; Using filesort +1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index SELECT * FROM t1 LEFT JOIN t2 ON t2.f1 = t1.f1 WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL GROUP BY t2.f1, t2.f2; @@ -2260,7 +2260,7 @@ create table t2 (a int, b int, c int, key(b), key(c)); insert into t2 select @a:=A.a + 10*B.a+100*C.a, IF(@a<900, NULL, @a), -IF(@a<450, NULL, @a) +IF(@a<400, NULL, @a) from t1 A, t1 B, t1 C; delete from t1 where a=0; # Check that there are different #rows of NULLs for b and c, both !=10: @@ -2269,7 +2269,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ref b b 5 const 780 Using index condition explain select * from t2 force index (c) where c is null; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ref c c 5 const 312 Using index condition +1 SIMPLE t2 ref c c 5 const 282 Using index condition explain select * from t1 left join t2 on t2.b is null; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 9 @@ -2277,7 +2277,7 @@ id select_type table type possible_keys key key_len ref rows Extra explain select * from t1 left join t2 on t2.c is null; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 9 -1 SIMPLE t2 ref c c 5 const 312 Using where +1 SIMPLE t2 ALL c NULL NULL NULL 1000 Using where drop table t1,t2; # # MDEV-10006: optimizer doesn't convert outer join to inner on views with WHERE clause diff --git a/mysql-test/main/join_outer.test b/mysql-test/main/join_outer.test index ac4207a720a..8e4c343f247 100644 --- a/mysql-test/main/join_outer.test +++ b/mysql-test/main/join_outer.test @@ -1813,7 +1813,7 @@ create table t2 (a int, b int, c int, key(b), key(c)); insert into t2 select @a:=A.a + 10*B.a+100*C.a, IF(@a<900, NULL, @a), - IF(@a<450, NULL, @a) + IF(@a<400, NULL, @a) from t1 A, t1 B, t1 C; delete from t1 where a=0; diff --git a/mysql-test/main/join_outer_innodb.result b/mysql-test/main/join_outer_innodb.result index 5373dbc0bbc..dc3a8bdb1f6 100644 --- a/mysql-test/main/join_outer_innodb.result +++ b/mysql-test/main/join_outer_innodb.result @@ -435,46 +435,48 @@ left join t16 on t15.o1 = t16.p1 where t1.a10 = 1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL a4,a6,a5,a7 NULL NULL NULL 3 Using where -1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.a1 1 Using index -1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.b2 1 Using where; Using index +1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.a1 1 +1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.b2 1 Using where 1 SIMPLE t10 eq_ref PRIMARY PRIMARY 1 test.t1.a6 1 -1 SIMPLE t8 eq_ref PRIMARY PRIMARY 1 test.t1.a4 1 Using index -1 SIMPLE t4 eq_ref PRIMARY PRIMARY 4 test.t1.a2 1 Using index +1 SIMPLE t8 eq_ref PRIMARY PRIMARY 1 test.t1.a4 1 +1 SIMPLE t4 eq_ref PRIMARY PRIMARY 4 test.t1.a2 1 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.d1 1 Using where -1 SIMPLE t6 eq_ref PRIMARY PRIMARY 4 test.t1.a3 1 Using where; Using index +1 SIMPLE t6 eq_ref PRIMARY PRIMARY 4 test.t1.a3 1 Using where +1 SIMPLE e2 eq_ref PRIMARY PRIMARY 4 test.t6.f1 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 1 test.t1.a7 1 1 SIMPLE t11 eq_ref PRIMARY PRIMARY 4 test.t1.a5 1 1 SIMPLE t12 eq_ref PRIMARY PRIMARY 4 test.t11.k3 1 Using where 1 SIMPLE l2 eq_ref PRIMARY PRIMARY 4 test.t11.k4 1 Using where 1 SIMPLE t9 ref PRIMARY PRIMARY 1 test.t1.a4 1 1 SIMPLE t13 ref PRIMARY,m3 m3 8 const,test.t1.a1 1 Using index -1 SIMPLE l4 eq_ref PRIMARY PRIMARY 4 test.t13.m2 1 Using where; Using index +1 SIMPLE l4 eq_ref PRIMARY PRIMARY 4 test.t13.m2 1 Using where 1 SIMPLE m2 ref PRIMARY,m3 m3 8 const,test.t1.a1 1 Using index 1 SIMPLE l3 eq_ref PRIMARY PRIMARY 4 test.m2.m2 1 Using where 1 SIMPLE t14 eq_ref PRIMARY PRIMARY 2 test.t1.a8 1 Using where -1 SIMPLE t15 eq_ref PRIMARY PRIMARY 2 test.t1.a9 1 Using where; Using index +1 SIMPLE t15 eq_ref PRIMARY PRIMARY 2 test.t1.a9 1 Using where 1 SIMPLE t16 ref PRIMARY PRIMARY 2 test.t15.o1 1 Using where explain select * from v1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL a4,a6,a5,a7 NULL NULL NULL 3 Using where -1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.a1 1 Using index -1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.b2 1 Using where; Using index +1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.a1 1 +1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.b2 1 Using where 1 SIMPLE t10 eq_ref PRIMARY PRIMARY 1 test.t1.a6 1 -1 SIMPLE t8 eq_ref PRIMARY PRIMARY 1 test.t1.a4 1 Using index -1 SIMPLE t4 eq_ref PRIMARY PRIMARY 4 test.t1.a2 1 Using index +1 SIMPLE t8 eq_ref PRIMARY PRIMARY 1 test.t1.a4 1 +1 SIMPLE t4 eq_ref PRIMARY PRIMARY 4 test.t1.a2 1 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.d1 1 Using where -1 SIMPLE t6 eq_ref PRIMARY PRIMARY 4 test.t1.a3 1 Using where; Using index +1 SIMPLE t6 eq_ref PRIMARY PRIMARY 4 test.t1.a3 1 Using where +1 SIMPLE e2 eq_ref PRIMARY PRIMARY 4 test.t6.f1 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 1 test.t1.a7 1 1 SIMPLE t11 eq_ref PRIMARY PRIMARY 4 test.t1.a5 1 1 SIMPLE t12 eq_ref PRIMARY PRIMARY 4 test.t11.k3 1 Using where 1 SIMPLE l2 eq_ref PRIMARY PRIMARY 4 test.t11.k4 1 Using where 1 SIMPLE t9 ref PRIMARY PRIMARY 1 test.t1.a4 1 1 SIMPLE t13 ref PRIMARY,m3 m3 8 const,test.t1.a1 1 Using index -1 SIMPLE l4 eq_ref PRIMARY PRIMARY 4 test.t13.m2 1 Using where; Using index +1 SIMPLE l4 eq_ref PRIMARY PRIMARY 4 test.t13.m2 1 Using where 1 SIMPLE m2 ref PRIMARY,m3 m3 8 const,test.t1.a1 1 Using index 1 SIMPLE l3 eq_ref PRIMARY PRIMARY 4 test.m2.m2 1 Using where 1 SIMPLE t14 eq_ref PRIMARY PRIMARY 2 test.t1.a8 1 Using where -1 SIMPLE t15 eq_ref PRIMARY PRIMARY 2 test.t1.a9 1 Using where; Using index +1 SIMPLE t15 eq_ref PRIMARY PRIMARY 2 test.t1.a9 1 Using where 1 SIMPLE t16 ref PRIMARY PRIMARY 2 test.t15.o1 1 Using where drop view v1; drop table t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16; diff --git a/mysql-test/main/join_outer_jcl6.result b/mysql-test/main/join_outer_jcl6.result index 5c88511b020..eeb22c2c5ac 100644 --- a/mysql-test/main/join_outer_jcl6.result +++ b/mysql-test/main/join_outer_jcl6.result @@ -1437,7 +1437,7 @@ WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL GROUP BY t2.f1, t2.f2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system PRIMARY NULL NULL NULL 1 -1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index; Using filesort +1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index SELECT * FROM t1 LEFT JOIN t2 ON t2.f1 = t1.f1 WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL GROUP BY t2.f1, t2.f2; @@ -1859,7 +1859,7 @@ WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL GROUP BY t2.f1, t2.f2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system PRIMARY NULL NULL NULL 1 -1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index; Using filesort +1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index SELECT * FROM t1 LEFT JOIN t2 ON t2.f1 = t1.f1 WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL GROUP BY t2.f1, t2.f2; @@ -2267,7 +2267,7 @@ create table t2 (a int, b int, c int, key(b), key(c)); insert into t2 select @a:=A.a + 10*B.a+100*C.a, IF(@a<900, NULL, @a), -IF(@a<450, NULL, @a) +IF(@a<400, NULL, @a) from t1 A, t1 B, t1 C; delete from t1 where a=0; # Check that there are different #rows of NULLs for b and c, both !=10: @@ -2276,7 +2276,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ref b b 5 const 780 Using index condition explain select * from t2 force index (c) where c is null; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ref c c 5 const 312 Using index condition +1 SIMPLE t2 ref c c 5 const 282 Using index condition explain select * from t1 left join t2 on t2.b is null; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 9 @@ -2284,7 +2284,7 @@ id select_type table type possible_keys key key_len ref rows Extra explain select * from t1 left join t2 on t2.c is null; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 9 -1 SIMPLE t2 ref c c 5 const 312 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan +1 SIMPLE t2 ALL c NULL NULL NULL 1000 Using where; Using join buffer (flat, BNL join) drop table t1,t2; # # MDEV-10006: optimizer doesn't convert outer join to inner on views with WHERE clause @@ -2783,8 +2783,8 @@ id select_type table type possible_keys key key_len ref rows Extra explain select * from t1 left join (t3 join t2) on t1.a=t3.b and t3.a<5; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 -1 SIMPLE t3 hash_range a #hash#$hj:a 5:5 test.t1.a 5 Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join) -1 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using join buffer (incremental, BNL join) +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t3 hash_range a #hash#$hj:a 5:5 test.t1.a 5 Using where; Rowid-ordered scan; Using join buffer (incremental, BNLH join) # # .. part 2: make sure condition selectivity can use the condition too. # diff --git a/mysql-test/main/key.result b/mysql-test/main/key.result index 42d57a35531..e6bb46af2b1 100644 --- a/mysql-test/main/key.result +++ b/mysql-test/main/key.result @@ -631,19 +631,19 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort SHOW STATUS LIKE 'Last_query_cost'; Variable_name Value -Last_query_cost 0.014749 +Last_query_cost 0.014784 EXPLAIN SELECT a, SUM( b ) FROM t1 USE INDEX( a ) GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort SHOW STATUS LIKE 'Last_query_cost'; Variable_name Value -Last_query_cost 0.014749 +Last_query_cost 0.014784 EXPLAIN SELECT a, SUM( b ) FROM t1 FORCE INDEX( a ) GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL a 5 NULL 6 SHOW STATUS LIKE 'Last_query_cost'; Variable_name Value -Last_query_cost 0.014749 +Last_query_cost 0.014784 DROP TABLE t1; # # MDEV-21480: Unique key using ref access though eq_ref access can be used diff --git a/mysql-test/main/key_cache.result b/mysql-test/main/key_cache.result index 3edbac8c9ae..4ec0d6ab7d7 100644 --- a/mysql-test/main/key_cache.result +++ b/mysql-test/main/key_cache.result @@ -434,7 +434,7 @@ p i a 3 1 yyyy 4 3 zzzz update t1 set p=3 where p=1; -update t2 set i=2 where i=1; +set statement optimizer_scan_setup_cost=0 for update t2 set i=2 where i=1; select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused'; VARIABLE_NAME VARIABLE_VALUE KEY_BLOCKS_NOT_FLUSHED 0 @@ -482,7 +482,7 @@ p i a 3 1 yyyy 4 3 zzzz update t1 set p=3 where p=1; -update t2 set i=2 where i=1; +set statement optimizer_scan_setup_cost=0 for update t2 set i=2 where i=1; select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused'; VARIABLE_NAME VARIABLE_VALUE KEY_BLOCKS_NOT_FLUSHED 0 @@ -527,7 +527,7 @@ p i a 3 1 yyyy 4 3 zzzz update t1 set p=3 where p=1; -update t2 set i=2 where i=1; +set statement optimizer_scan_setup_cost=0 for update t2 set i=2 where i=1; select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused'; VARIABLE_NAME VARIABLE_VALUE KEY_BLOCKS_NOT_FLUSHED 0 @@ -583,7 +583,7 @@ p i a 3 1 yyyy 4 3 zzzz update t1 set p=3 where p=1; -update t2 set i=2 where i=1; +set statement optimizer_scan_setup_cost=0 for update t2 set i=2 where i=1; select * from information_schema.key_caches where segment_number is null; KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES default 2 NULL 32768 1024 4 # 0 21 0 26 6 @@ -627,10 +627,14 @@ select * from information_schema.key_caches where segment_number is null; KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES default 2 NULL 32768 1024 # # 0 6749 # 3684 103 small NULL NULL 1048576 1024 # # 0 0 # 0 0 +analyze table t2; +Table Op Msg_type Msg_text +test.t2 analyze status Engine-independent statistics collected +test.t2 analyze status OK flush tables; flush status; update t1 set a='zzzz' where a='qqqq'; -update t2 set i=1 where i=2; +set statement optimizer_scan_setup_cost=0 for update t2 set i=1 where i=2; select * from information_schema.key_caches where segment_number is null; KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES default 2 NULL 32768 1024 # # 0 3076 18 1552 18 @@ -699,7 +703,7 @@ update t2 set p=p+3000, i=2 where a='qqqq'; select * from information_schema.key_caches where key_cache_name like "key%" and segment_number is null; KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES -keycache1 7 NULL 262143 2048 25 # 0 2114 25 1071 19 +keycache1 7 NULL 262143 2048 25 # 0 2082 25 1071 19 set global keycache2.key_buffer_size=1024*1024; cache index t2 in keycache2; Table Op Msg_type Msg_text @@ -712,7 +716,7 @@ keycache2 NULL NULL 1048576 1024 6 # 0 6 6 3 3 select * from information_schema.key_caches where key_cache_name like "key%" and segment_number is null; KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES -keycache1 7 NULL 262143 2048 25 # 0 2114 25 1071 19 +keycache1 7 NULL 262143 2048 25 # 0 2082 25 1071 19 keycache2 NULL NULL 1048576 1024 6 # 0 6 6 3 3 cache index t2 in keycache1; Table Op Msg_type Msg_text @@ -753,7 +757,7 @@ select * from information_schema.key_caches where segment_number is null; KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES default 2 NULL 32768 1024 # # 0 3172 24 1552 18 small NULL NULL 1048576 1024 # # 0 0 0 0 0 -keycache1 7 NULL 262143 2048 # # 0 3277 43 1594 30 +keycache1 7 NULL 262143 2048 # # 0 3229 43 1594 30 keycache2 NULL NULL 1048576 1024 # # 0 6 6 3 3 set global keycache1.key_cache_block_size=2*1024; insert into t2 values (7000, 3, 'yyyy'); diff --git a/mysql-test/main/key_cache.test b/mysql-test/main/key_cache.test index 9bd57f017f0..baca5c07fec 100644 --- a/mysql-test/main/key_cache.test +++ b/mysql-test/main/key_cache.test @@ -299,7 +299,7 @@ insert into t2 values (1, 1, 'qqqq'), (2, 1, 'pppp'), select * from t1; select * from t2; update t1 set p=3 where p=1; -update t2 set i=2 where i=1; +set statement optimizer_scan_setup_cost=0 for update t2 set i=2 where i=1; select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused'; select variable_value into @key_blocks_unused from information_schema.session_status where variable_name = 'Key_blocks_unused'; @@ -331,8 +331,7 @@ insert into t2 values (1, 1, 'qqqq'), (2, 1, 'pppp'), select * from t1; select * from t2; update t1 set p=3 where p=1; -update t2 set i=2 where i=1; - +set statement optimizer_scan_setup_cost=0 for update t2 set i=2 where i=1; select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused'; select variable_value < @key_blocks_unused from information_schema.session_status where variable_name = 'Key_blocks_unused'; @@ -357,7 +356,7 @@ insert into t2 values (1, 1, 'qqqq'), (2, 1, 'pppp'), select * from t1; select * from t2; update t1 set p=3 where p=1; -update t2 set i=2 where i=1; +set statement optimizer_scan_setup_cost=0 for update t2 set i=2 where i=1; select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused'; select variable_value = @key_blocks_unused from information_schema.session_status where variable_name = 'Key_blocks_unused'; @@ -389,7 +388,7 @@ insert into t2 values (1, 1, 'qqqq'), (2, 1, 'pppp'), select * from t1; select * from t2; update t1 set p=3 where p=1; -update t2 set i=2 where i=1; +set statement optimizer_scan_setup_cost=0 for update t2 set i=2 where i=1; --replace_column 7 # select * from information_schema.key_caches where segment_number is null; @@ -422,9 +421,10 @@ select * from t2 where p between 1010 and 1020 ; --replace_column 6 # 7 # 10 # select * from information_schema.key_caches where segment_number is null; +analyze table t2; flush tables; flush status; update t1 set a='zzzz' where a='qqqq'; -update t2 set i=1 where i=2; +set statement optimizer_scan_setup_cost=0 for update t2 set i=1 where i=2; --replace_column 6 # 7 # select * from information_schema.key_caches where segment_number is null; diff --git a/mysql-test/main/limit_rows_examined.result b/mysql-test/main/limit_rows_examined.result index e87dd25cac9..9d3d5bbf0ab 100644 --- a/mysql-test/main/limit_rows_examined.result +++ b/mysql-test/main/limit_rows_examined.result @@ -211,51 +211,48 @@ explain select * from t1 where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 11); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 4 -1 PRIMARY eq_ref distinct_key distinct_key 2 func 1 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) select * from t1 where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 11); c1 bb -Warnings: -Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (11). The query result may be incomplete +cc +dd explain select * from t1 where c1 IN (select * from t2 where c2 > ' ') LIMIT ROWS EXAMINED 11; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 4 -1 PRIMARY eq_ref distinct_key distinct_key 2 func 1 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) select * from t1 where c1 IN (select * from t2 where c2 > ' ') LIMIT ROWS EXAMINED 11; c1 bb -Warnings: -Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (11). The query result may be incomplete +cc +dd explain select * from t1 where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0) LIMIT ROWS EXAMINED 11; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 4 -1 PRIMARY eq_ref distinct_key distinct_key 2 func 1 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) select * from t1 where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0) LIMIT ROWS EXAMINED 11; c1 bb -Warnings: -Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (11). The query result may be incomplete +cc +dd explain select * from t1i where c1 IN (select * from t2i where c2 > ' ') LIMIT ROWS EXAMINED 6; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1i index PRIMARY PRIMARY 2 NULL 4 Using where; Using index +1 PRIMARY t1i range PRIMARY PRIMARY 2 NULL 4 Using where; Using index 1 PRIMARY t2i eq_ref PRIMARY PRIMARY 2 test.t1i.c1 1 Using index select * from t1i where c1 IN (select * from t2i where c2 > ' ') @@ -395,7 +392,7 @@ select * from t1i where c1 IN (select * from t2i where c2 > ' ') LIMIT ROWS EXAMINED 17; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1i index NULL PRIMARY 2 NULL 4 Using where; Using index -2 MATERIALIZED t2i index PRIMARY PRIMARY 2 NULL 4 Using where; Using index +2 MATERIALIZED t2i range PRIMARY PRIMARY 2 NULL 4 Using where; Using index select * from t1i where c1 IN (select * from t2i where c2 > ' ') LIMIT ROWS EXAMINED 17; c1 @@ -416,24 +413,22 @@ c1 bb cc dd -select * from v1 LIMIT ROWS EXAMINED 17; +select * from v1 LIMIT ROWS EXAMINED 10; +c1 +bb +cc +dd +select * from v1 LIMIT ROWS EXAMINED 8; c1 bb cc dd Warnings: -Warning 1931 Query execution was interrupted. The query examined at least 18 rows, which exceeds LIMIT ROWS EXAMINED (17). The query result may be incomplete -select * from v1 LIMIT ROWS EXAMINED 16; +Warning 1931 Query execution was interrupted. The query examined at least 9 rows, which exceeds LIMIT ROWS EXAMINED (8). The query result may be incomplete +select * from v1 LIMIT ROWS EXAMINED 3; c1 -bb -cc Warnings: -Warning 1931 Query execution was interrupted. The query examined at least 17 rows, which exceeds LIMIT ROWS EXAMINED (16). The query result may be incomplete -select * from v1 LIMIT ROWS EXAMINED 11; -c1 -bb -Warnings: -Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (11). The query result may be incomplete +Warning 1931 Query execution was interrupted. The query examined at least 4 rows, which exceeds LIMIT ROWS EXAMINED (3). The query result may be incomplete drop view v1; explain select * @@ -441,17 +436,16 @@ from (select * from t1 where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)) as tmp LIMIT ROWS EXAMINED 11; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 4 -1 PRIMARY eq_ref distinct_key distinct_key 2 func 1 -3 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) select * from (select * from t1 where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)) as tmp LIMIT ROWS EXAMINED 11; c1 bb -Warnings: -Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (11). The query result may be incomplete +cc +dd ========================================================================= Aggregation ========================================================================= diff --git a/mysql-test/main/limit_rows_examined.test b/mysql-test/main/limit_rows_examined.test index 2315580410f..512058e1eb6 100644 --- a/mysql-test/main/limit_rows_examined.test +++ b/mysql-test/main/limit_rows_examined.test @@ -277,9 +277,9 @@ create view v1 as select * from t1 where c1 IN (select * from t2 where c2 > ' '); select * from v1; -select * from v1 LIMIT ROWS EXAMINED 17; -select * from v1 LIMIT ROWS EXAMINED 16; -select * from v1 LIMIT ROWS EXAMINED 11; +select * from v1 LIMIT ROWS EXAMINED 10; +select * from v1 LIMIT ROWS EXAMINED 8; +select * from v1 LIMIT ROWS EXAMINED 3; drop view v1; diff --git a/mysql-test/main/mrr_derived_crash_4610.result b/mysql-test/main/mrr_derived_crash_4610.result index 3e38a0d4218..d7800e8a2a9 100644 --- a/mysql-test/main/mrr_derived_crash_4610.result +++ b/mysql-test/main/mrr_derived_crash_4610.result @@ -7,7 +7,7 @@ explain select 1 from (select f2, f3, val, count(id) from t4 join t2 left join t3 on 0) top join t1 on f1 = f3 where f3 = 'aaaa' order by val; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 const PRIMARY PRIMARY 12 const 1 Using index +1 PRIMARY t1 const PRIMARY PRIMARY 12 const 1 1 PRIMARY ref key0 key0 13 const 0 Using where; Using filesort 2 DERIVED t4 ALL NULL NULL NULL NULL 1 2 DERIVED t2 ALL NULL NULL NULL NULL 1 Using join buffer (flat, BNL join) diff --git a/mysql-test/main/myisam.result b/mysql-test/main/myisam.result index aae3ea173b7..864939bbda8 100644 --- a/mysql-test/main/myisam.result +++ b/mysql-test/main/myisam.result @@ -648,6 +648,9 @@ insert into t1 values (1,''), (2,''); explain select count(*) from t1 where a is null; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref idx idx 4 const 2 Using where +set statement optimizer_scan_setup_cost= 0 for explain select count(*) from t1 where a is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL idx NULL NULL NULL 4 Using where drop table t1; create table t1 (c1 int, c2 varchar(4) not null default '', key(c2(3))) default charset=utf8; diff --git a/mysql-test/main/myisam.test b/mysql-test/main/myisam.test index 32b74027b14..53c5f9843cc 100644 --- a/mysql-test/main/myisam.test +++ b/mysql-test/main/myisam.test @@ -595,6 +595,7 @@ explain select count(*) from t1 where a is null; select count(*) from t1 where a is null; insert into t1 values (1,''), (2,''); explain select count(*) from t1 where a is null; +set statement optimizer_scan_setup_cost= 0 for explain select count(*) from t1 where a is null; drop table t1; # diff --git a/mysql-test/main/myisam_explain_non_select_all.result b/mysql-test/main/myisam_explain_non_select_all.result index 98bb644fd5f..0b81b1d85b9 100644 --- a/mysql-test/main/myisam_explain_non_select_all.result +++ b/mysql-test/main/myisam_explain_non_select_all.result @@ -256,7 +256,7 @@ FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED SELECT * FROM t1 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 Using where; FirstMatch +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 33.33 Using where; FirstMatch 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 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` < 3 @@ -332,55 +332,58 @@ CREATE TABLE t1 (a INT); INSERT INTO t1 VALUES (1), (2), (3); CREATE TABLE t2 (b INT); INSERT INTO t2 VALUES (1), (2), (3), (1000); +CREATE TABLE t3 like t2; +insert into t3 select * from t2; +insert into t3 select seq from seq_1001_to_2000; # -# query: UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3) -# select: SELECT * FROM t1, t2 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3) +# query: UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t3 WHERE t3.b < 3) +# select: SELECT * FROM t1, t2 WHERE a IN (SELECT b FROM t3 WHERE t3.b < 3) # Warnings: Warning 1287 ' INTO FROM...' instead -EXPLAIN UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3); +EXPLAIN UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t3 WHERE t3.b < 3); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY t2 ALL NULL NULL NULL NULL 4 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where +2 MATERIALIZED t3 ALL NULL NULL NULL NULL 1004 Using where FLUSH STATUS; FLUSH TABLES; -EXPLAIN EXTENDED UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3); +EXPLAIN EXTENDED UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t3 WHERE t3.b < 3); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 100.00 1 PRIMARY t2 ALL NULL NULL NULL NULL 4 100.00 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 100.00 Using where +2 MATERIALIZED t3 ALL NULL NULL NULL NULL 1004 100.00 Using where # Status of EXPLAIN EXTENDED query Variable_name Value -Handler_read_key 4 +Handler_read_key 6 FLUSH STATUS; FLUSH TABLES; -EXPLAIN EXTENDED SELECT * FROM t1, t2 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3); +EXPLAIN EXTENDED SELECT * FROM t1, t2 WHERE a IN (SELECT b FROM t3 WHERE t3.b < 3); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 100.00 1 PRIMARY t2 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (flat, BNL join) -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 100.00 Using where +2 MATERIALIZED t3 ALL NULL NULL NULL NULL 1004 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` semi join (`test`.`t2`) join `test`.`t2` where `test`.`t2`.`b` < 3 +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` semi join (`test`.`t3`) join `test`.`t2` where `test`.`t3`.`b` < 3 # Status of EXPLAIN EXTENDED "equivalent" SELECT query execution Variable_name Value -Handler_read_key 4 +Handler_read_key 6 Warnings: Warning 1287 ' INTO FROM...' instead # Status of "equivalent" SELECT query execution: Variable_name Value -Handler_read_key 7 -Handler_read_rnd_next 14 +Handler_read_key 9 +Handler_read_rnd_next 1014 # Status of testing query execution: Variable_name Value -Handler_read_key 7 -Handler_read_rnd_next 19 +Handler_read_key 9 +Handler_read_rnd_next 1019 Handler_update 2 -DROP TABLE t1, t2; +DROP TABLE t1, t2, t3; #8 CREATE TABLE t1 (a INT); INSERT INTO t1 VALUES (1), (2), (3); @@ -790,12 +793,12 @@ Warnings: Warning 1287 ' INTO FROM...' instead EXPLAIN DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 6 Using where; Using filesort +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 Using where FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 6 100.00 Using where; Using filesort +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 3 @@ -818,11 +821,8 @@ Handler_read_next 3 # Status of testing query execution: Variable_name Value Handler_delete 3 -Handler_read_key 3 -Handler_read_rnd 3 -Handler_read_rnd_next 7 -Sort_rows 3 -Sort_scan 1 +Handler_read_key 4 +Handler_read_next 3 DROP TABLE t1; #17 @@ -1003,10 +1003,9 @@ FLUSH TABLES; EXPLAIN EXTENDED SELECT * FROM t1 WHERE a IN (SELECT a FROM t2); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 100.00 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 100.00 +1 PRIMARY t2 ALL NULL NULL NULL NULL 4 100.00 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 1 +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`a` = `test`.`t1`.`a` # Status of EXPLAIN EXTENDED "equivalent" SELECT query execution Variable_name Value Handler_read_key 4 @@ -1014,7 +1013,7 @@ Warnings: Warning 1287 ' INTO FROM...' instead # Status of "equivalent" SELECT query execution: Variable_name Value -Handler_read_key 7 +Handler_read_key 4 Handler_read_rnd_next 9 # Status of testing query execution: Variable_name Value @@ -2661,13 +2660,13 @@ Warning 1287 ' INTO ;' is deprecated and will be removed in a future release. Please use 'SELECT