summaryrefslogtreecommitdiff
path: root/mysql-test/main
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2021-11-01 12:34:24 +0200
committerSergei Petrunia <sergey@mariadb.com>2023-02-02 21:43:30 +0300
commitb6215b9b20b55911ca06c4cee1fa6ebdd4e8e1eb (patch)
treeaf42c25a59fa80f5bc88c70c485b7ff1b3b141dc /mysql-test/main
parent034aedadf25a9981d8dd94f6042666b68fa7d2a4 (diff)
downloadmariadb-git-b6215b9b20b55911ca06c4cee1fa6ebdd4e8e1eb.tar.gz
Update row and key fetch cost models to take into account data copy costs
Before this patch, when calculating the cost of fetching and using a row/key from the engine, we took into account the cost of finding a row or key from the engine, but did not consistently take into account index only accessed, clustered key or covered keys for all access paths. The cost of the WHERE clause (TIME_FOR_COMPARE) was not consistently considered in best_access_path(). TIME_FOR_COMPARE was used in calculation in other places, like greedy_search(), but was in some cases (like scans) done an a different number of rows than was accessed. The cost calculation of row and index scans didn't take into account the number of rows that where accessed, only the number of accepted rows. When using a filter, the cost of index_only_reads and cost of accessing and disregarding 'filtered rows' where not taken into account, which made filters cost less than there actually where. To remedy the above, the following key & row fetch related costs has been added: - The cost of fetching and using a row is now split into different costs: - key + Row fetch cost (as before) but multiplied with the variable 'optimizer_cache_cost' (default to 0.5). This allows the user to tell the optimizer the likehood of finding the key and row in the engine cache. - ROW_COPY_COST, The cost copying a row from the engine to the sql layer or creating a row from the join_cache to the record buffer. Mostly affects table scan costs. - ROW_LOOKUP_COST, the cost of fetching a row by rowid. - KEY_COPY_COST the cost of finding the next key and copying it from the engine to the SQL layer. This is used when we calculate the cost index only reads. It makes index scans more expensive than before if they cover a lot of rows. (main.index_merge_myisam) - KEY_LOOKUP_COST, the cost of finding the first key in a range. This replaces the old define IDX_LOOKUP_COST, but with a higher cost. - KEY_NEXT_FIND_COST, the cost of finding the next key (and rowid). when doing a index scan and comparing the rowid to the filter. Before this cost was assumed to be 0. All of the above constants/variables are now tuned to be somewhat in proportion of executing complexity to each other. There is tuning need for these in the future, but that can wait until the above are made user variables as that will make tuning much easier. To make the usage of the above easy, there are new (not virtual) cost calclation functions in handler: - ha_read_time(), like read_time(), but take optimizer_cache_cost into account. - ha_read_and_copy_time(), like ha_read_time() but take into account ROW_COPY_TIME - ha_read_and_compare_time(), like ha_read_and_copy_time() but take TIME_FOR_COMPARE into account. - ha_rnd_pos_time(). Read row with row id, taking ROW_COPY_COST into account. This is used with filesort where we don't need to execute the WHERE clause again. - ha_keyread_time(), like keyread_time() but take optimizer_cache_cost into account. - ha_keyread_and_copy_time(), like ha_keyread_time(), but add KEY_COPY_COST. - ha_key_scan_time(), like key_scan_time() but take optimizer_cache_cost nto account. - ha_key_scan_and_compare_time(), like ha_key_scan_time(), but add KEY_COPY_COST & TIME_FOR_COMPARE. I also added some setup costs for doing different types of scans and creating temporary tables (on disk and in memory). This encourages the optimizer to not use these for simple 'a few row' lookups if there are adequate key lookup strategies. - TABLE_SCAN_SETUP_COST, cost of starting a table scan. - INDEX_SCAN_SETUP_COST, cost of starting an index scan. - HEAP_TEMPTABLE_CREATE_COST, cost of creating in memory temporary table. - DISK_TEMPTABLE_CREATE_COST, cost of creating an on disk temporary table. When calculating cost of fetching ranges, we had a cost of IDX_LOOKUP_COST (0.125) for doing a key div for a new range. This is now replaced with 'io_cost * KEY_LOOKUP_COST (1.0) * optimizer_cache_cost', which matches the cost we use for 'ref' and other key lookups. The effect is that the cost is now a bit higher when we have many ranges for a key. Allmost all calculation with TIME_FOR_COMPARE is now done in best_access_path(). 'JOIN::read_time' now includes the full cost for finding the rows in the table. In the result files, many of the changes are now again close to what they where before the "Update cost for hash and cached joins" commit, as that commit didn't fix the filter cost (too complex to do everything in one commit). The above changes showed a lot of a lot of inconsistencies in optimizer cost calculation. The main objective with the other changes was to do calculation as similar (and accurate) as possible and to make different plans more comparable. Detailed list of changes: - Calculate index_only_cost consistently and correctly for all scan and ref accesses. The row fetch_cost and index_only_cost now takes into account clustered keys, covered keys and index only accesses. - cost_for_index_read now returns both full cost and index_only_cost - Fixed cost calculation of get_sweep_read_cost() to match other similar costs. This is bases on the assumption that data is more often stored on SSD than a hard disk. - Replaced constant 2.0 with new define TABLE_SCAN_SETUP_COST. - Some scan cost estimates did not take into account TIME_FOR_COMPARE. Now all scan costs takes this into account. (main.show_explain) - Added session variable optimizer_cache_hit_ratio (default 50%). By adjusting this on can reduce or increase the cost of index or direct record lookups. The effect of the default is that key lookups is now a bit cheaper than before. See usage of 'optimizer_cache_cost' in handler.h. - JOIN_TAB::scan_time() did not take into account index only scans, which produced a wrong cost when index scan was used. Changed JOIN_TAB:::scan_time() to take into consideration clustered and covered keys. The values are now cached and we only have to call this function once. Other calls are changed to use the cached values. Function renamed to JOIN_TAB::estimate_scan_time(). - Fixed that most index cost calculations are done the same way and more close to 'range' calculations. The cost is now lower than before for small data sets and higher for large data sets as we take into account how many keys are read (main.opt_trace_selectivity, main.limit_rows_examined). - Ensured that index_scan_cost() == range(scan_of_all_rows_in_table_using_one_range) + MULTI_RANGE_READ_INFO_CONST. One effect of this is that if there is choice of doing a full index scan and a range-index scan over almost the whole table then index scan will be preferred (no range-read setup cost). (innodb.innodb, main.show_explain, main.range) - Fixed the EQ_REF and REF takes into account clustered and covered keys. This changes some plans to use covered or clustered indexes as these are much cheaper. (main.subselect_mat_cost, main.state_tables_innodb, main.limit_rows_examined) - Rowid filter setup cost and filter compare cost now takes into account fetching and checking the rowid (KEY_NEXT_FIND_COST). (main.partition_pruning heap.heap_btree main.log_state) - Added KEY_NEXT_FIND_COST to Range_rowid_filter_cost_info::lookup_cost to account of the time to find and check the next key value against the container - Introduced ha_keyread_time(rows) that takes into account finding the next row and copying the key value to 'record' (KEY_COPY_COST). - Introduced ha_key_scan_time() for calculating an index scan over all rows. - Added IDX_LOOKUP_COST to keyread_time() as a startup cost. - Added index_only_fetch_cost() as a convenience function to OPT_RANGE. - keyread_time() cost is slightly reduced to prefer shorter keys. (main.index_merge_myisam) - All of the above caused some index_merge combinations to be rejected because of cost (main.index_intersect). In some cases 'ref' where replaced with index_merge because of the low cost calculation of get_sweep_read_cost(). - Some index usage moved from PRIMARY to a covering index. (main.subselect_innodb) - Changed cost calculation of filter to take KEY_LOOKUP_COST and TIME_FOR_COMPARE into account. See sql_select.cc::apply_filter(). filter parameters and costs are now written to optimizer_trace. - Don't use matchings_records_in_range() to try to estimate the number of filtered rows for ranges. The reason is that we want to ensure that 'range' is calculated similar to 'ref'. There is also more work needed to calculate the selectivity when using ranges and ranges and filtering. This causes filtering column in EXPLAIN EXTENDED to be 100.00 for some cases where range cannot use filtering. (main.rowid_filter) - Introduced ha_scan_time() that takes into account the CPU cost of finding the next row and copying the row from the engine to 'record'. This causes costs of table scan to slightly increase and some test to changed their plan from ALL to RANGE or ALL to ref. (innodb.innodb_mysql, main.select_pkeycache) In a few cases where scan time of very small tables have lower cost than a ref or range, things changed from ref/range to ALL. (main.myisam, main.func_group, main.limit_rows_examined, main.subselect2) - Introduced ha_scan_and_compare_time() which is like ha_scan_time() but also adds the cost of the where clause (TIME_FOR_COMPARE). - Added small cost for creating temporary table for materialization. This causes some very small tables to use scan instead of materialization. - Added checking of the WHERE clause (TIME_FOR_COMPARE) of the accepted rows to ROR costs in get_best_ror_intersect() - Removed '- 0.001' from 'join->best_read' and optimize_straight_join() to ensure that the 'Last_query_cost' status variable contains the same value as the one that was calculated by the optimizer. - Take avg_io_cost() into account in handler::keyread_time() and handler::read_time(). This should have no effect as it's 1.0 by default, except for heap that overrides these functions. - Some 'ref_or_null' accesses changed to 'range' because of cost adjustments (main.order_by) - Added scan type "scan_with_join_cache" for optimizer_trace. This is just to show in the trace what kind of scan was used. - When using 'scan_with_join_cache' take into account number of preceding tables (as have to restore all fields for all previous table combination when checking the where clause) The new cost added is: (row_combinations * ROW_COPY_COST * number_of_cached_tables). This increases the cost of join buffering in proportion of the number of tables in the join buffer. One effect is that full scans are now done earlier as the cost is then smaller. (main.join_outer_innodb, main.greedy_optimizer) - Removed the usage of 'worst_seeks' in cost_for_index_read as it caused wrong plans to be created; It prefered JT_EQ_REF even if it would be much more expensive than a full table scan. A related issue was that worst_seeks only applied to full lookup, not to clustered or index only lookups, which is not consistent. This caused some plans to use index scan instead of eq_ref (main.union) - Changed federated block size from 4096 to 1500, which is the typical size of an IO packet. - Added costs for reading rows to Federated. Needed as there is no caching of rows in the federated engine. - Added ha_innobase::rnd_pos_time() cost function. - A lot of extra things added to optimizer trace - More costs, especially for materialization and index_merge. - Make lables more uniform - Fixed a lot of minor bugs - Added 'trace_started()' around a lot of trace blocks. - When calculating ORDER BY with LIMIT cost for using an index the cost did not take into account the number of row retrivals that has to be done or the cost of comparing the rows with the WHERE clause. The cost calculated would be just a fraction of the real cost. Now we calculate the cost as we do for ranges and 'ref'. - 'Using index for group-by' is used a bit more than before as now take into account the WHERE clause cost when comparing with 'ref' and prefer the method with fewer row combinations. (main.group_min_max). Bugs fixed: - Fixed that we don't calculate TIME_FOR_COMPARE twice for some plans, like in optimize_straight_join() and greedy_search() - Fixed bug in save_explain_data where we could test for the wrong index when displaying 'Using index'. This caused some old plans to show 'Using index'. (main.subselect_innodb, main.subselect2) - Fixed bug in get_best_ror_intersect() where 'min_cost' was not updated, and the cost we compared with was not the one that was used. - Fixed very wrong cost calculation for priority queues in check_if_pq_applicable(). (main.order_by now correctly uses priority queue) - When calculating cost of EQ_REF or REF, we added the cost of comparing the WHERE clause with the found rows, not all row combinations. This made ref and eq_ref to be regarded way to cheap compared to other access methods. - FORCE INDEX cost calculation didn't take into account clustered or covered indexes. - JT_EQ_REF cost was estimated as avg_io_cost(), which is half the cost of a JT_REF key. This may be true for InnoDB primary key, but not for other unique keys or other engines. Now we use handler function to calculate the cost, which allows us to handle consistently clustered, covered keys and not covered keys. - ha_start_keyread() didn't call extra_opt() if keyread was already enabled but still changed the 'keyread' variable (which is wrong). Fixed by not doing anything if keyread is already enabled. - multi_range_read_info_cost() didn't take into account io_cost when calculating the cost of ranges. - fix_semijoin_strategies_for_picked_join_order() used the wrong record_count when calling best_access_path() for SJ_OPT_FIRST_MATCH and SJ_OPT_LOOSE_SCAN. - Hash joins didn't provide correct best_cost to the upper level, which means that the cost for hash_joins more expensive than calculated in best_access_path (a difference of 10x * TIME_OF_COMPARE). This is fixed in the new code thanks to that we now include TIME_OF_COMPARE cost in 'read_time'. Other things: - Added some 'if (thd->trace_started())' to speed up code - Removed not used function Cost_estimate::is_zero() - Simplified testing of HA_POS_ERROR in get_best_ror_intersect(). (No cost changes) - Moved ha_start_keyread() from join_read_const_table() to join_read_const() to enable keyread for all types of JT_CONST tables. - Made a few very short functions inline in handler.h Notes: - In main.rowid_filter the join order of order and lineitem is swapped. This is because the cost of doing a range fetch of lineitem(98 rows) is almost as big as the whole join of order,lineitem. The filtering will also ensure that we only have to do very small key fetches of the rows in lineitem. - main.index_merge_myisam had a few changes where we are now using less keys for index_merge. This is because index scans are now more expensive than before. - handler->optimizer_cache_cost is updated in ha_external_lock(). This ensures that it is up to date per statements. Not an optimal solution (for locked tables), but should be ok for now. - 'DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a' does not take cost of filesort into consideration when table scan is chosen. (main.myisam_explain_non_select_all) - perfschema.table_aggregate_global_* has changed because an update on a table with 1 row will now use table scan instead of key lookup. TODO in upcomming commits: - Fix selectivity calculation for ranges with and without filtering and when there is a ref access but scan is chosen. For this we have to store the lowest known value for 'accepted_records' in the OPT_RANGE structure. - Change that records_read does not include filtered rows. - test_if_cheaper_ordering() needs to be updated to properly calculate costs. This will fix tests like main.order_by_innodb, main.single_delete_update - Extend get_range_limit_read_cost() to take into considering cost_for_index_read() if there where no quick keys. This will reduce the computed cost for ORDER BY with LIMIT in some cases. (main.innodb_ext_key) - Fix that we take into account selectivity when counting the number of rows we have to read when considering using a index table scan to resolve ORDER BY. - Add new calculation for rnd_pos_time() where we take into account the benefit of reading multiple rows from the same page.
Diffstat (limited to 'mysql-test/main')
-rw-r--r--mysql-test/main/costs.result91
-rw-r--r--mysql-test/main/costs.test75
-rw-r--r--mysql-test/main/cte_nonrecursive.result8
-rw-r--r--mysql-test/main/cte_recursive.result6
-rw-r--r--mysql-test/main/ctype_binary.result1
-rw-r--r--mysql-test/main/ctype_cp1251.result1
-rw-r--r--mysql-test/main/ctype_latin1.result1
-rw-r--r--mysql-test/main/ctype_ucs.result5
-rw-r--r--mysql-test/main/ctype_utf8.result1
-rw-r--r--mysql-test/main/derived.result2
-rw-r--r--mysql-test/main/derived_cond_pushdown.result28
-rw-r--r--mysql-test/main/derived_cond_pushdown.test2
-rw-r--r--mysql-test/main/derived_opt.result2
-rw-r--r--mysql-test/main/derived_split_innodb.result8
-rw-r--r--mysql-test/main/derived_view.result14
-rw-r--r--mysql-test/main/derived_view.test2
-rw-r--r--mysql-test/main/desc_index_range.result4
-rw-r--r--mysql-test/main/distinct.result2
-rw-r--r--mysql-test/main/explain.result25
-rw-r--r--mysql-test/main/explain.test3
-rw-r--r--mysql-test/main/explain_innodb.result2
-rw-r--r--mysql-test/main/explain_json.result36
-rw-r--r--mysql-test/main/explain_json.test4
-rw-r--r--mysql-test/main/func_group.result9
-rw-r--r--mysql-test/main/func_in.result16
-rw-r--r--mysql-test/main/greedy_optimizer.result109
-rw-r--r--mysql-test/main/greedy_optimizer.test22
-rw-r--r--mysql-test/main/group_by.result4
-rw-r--r--mysql-test/main/group_min_max.result26
-rw-r--r--mysql-test/main/index_intersect.result19
-rw-r--r--mysql-test/main/index_intersect.test1
-rw-r--r--mysql-test/main/index_intersect_innodb.result23
-rw-r--r--mysql-test/main/index_merge_myisam.result8
-rw-r--r--mysql-test/main/innodb_ext_key,off.rdiff35
-rw-r--r--mysql-test/main/innodb_ext_key.result12
-rw-r--r--mysql-test/main/join.result24
-rw-r--r--mysql-test/main/join.test10
-rw-r--r--mysql-test/main/join_cache.result92
-rw-r--r--mysql-test/main/join_cache.test65
-rw-r--r--mysql-test/main/join_nested.result24
-rw-r--r--mysql-test/main/join_nested.test1
-rw-r--r--mysql-test/main/join_nested_jcl6.result36
-rw-r--r--mysql-test/main/join_outer.result6
-rw-r--r--mysql-test/main/join_outer.test2
-rw-r--r--mysql-test/main/join_outer_innodb.result4
-rw-r--r--mysql-test/main/join_outer_jcl6.result6
-rw-r--r--mysql-test/main/key.result13
-rw-r--r--mysql-test/main/key.test3
-rw-r--r--mysql-test/main/key_cache.result32
-rw-r--r--mysql-test/main/limit_rows_examined.result4
-rw-r--r--mysql-test/main/long_unique.result18
-rw-r--r--mysql-test/main/long_unique.test1
-rw-r--r--mysql-test/main/multi_update.result4
-rw-r--r--mysql-test/main/myisam.result7
-rw-r--r--mysql-test/main/myisam.test5
-rw-r--r--mysql-test/main/myisam_explain_non_select_all.result52
-rw-r--r--mysql-test/main/myisam_icp.result8
-rw-r--r--mysql-test/main/myisam_icp.test2
-rw-r--r--mysql-test/main/mysqld--help.result6
-rw-r--r--mysql-test/main/negation_elimination.result6
-rw-r--r--mysql-test/main/null_key.result8
-rw-r--r--mysql-test/main/null_key.test7
-rw-r--r--mysql-test/main/opt_trace.result2990
-rw-r--r--mysql-test/main/opt_trace_index_merge.result146
-rw-r--r--mysql-test/main/opt_trace_index_merge_innodb.result33
-rw-r--r--mysql-test/main/opt_trace_security.result40
-rw-r--r--mysql-test/main/opt_trace_selectivity.result67
-rw-r--r--mysql-test/main/opt_trace_selectivity.test2
-rw-r--r--mysql-test/main/opt_trace_ucs2.result2
-rw-r--r--mysql-test/main/opt_tvc.result43
-rw-r--r--mysql-test/main/opt_tvc.test2
-rw-r--r--mysql-test/main/order_by.result30
-rw-r--r--mysql-test/main/order_by.test10
-rw-r--r--mysql-test/main/order_by_innodb.result26
-rw-r--r--mysql-test/main/order_by_innodb.test8
-rw-r--r--mysql-test/main/order_by_sortkey.result11
-rw-r--r--mysql-test/main/order_by_sortkey.test5
-rw-r--r--mysql-test/main/partition_pruning.result28
-rw-r--r--mysql-test/main/partition_pruning.test6
-rw-r--r--mysql-test/main/partition_range.result4
-rw-r--r--mysql-test/main/ps_1general.result2
-rw-r--r--mysql-test/main/ps_1general.test4
-rw-r--r--mysql-test/main/range.result185
-rw-r--r--mysql-test/main/range.test15
-rw-r--r--mysql-test/main/range_innodb.result7
-rw-r--r--mysql-test/main/range_innodb.test4
-rw-r--r--mysql-test/main/range_mrr_icp.result87
-rw-r--r--mysql-test/main/range_notembedded.result10
-rw-r--r--mysql-test/main/range_notembedded.test1
-rw-r--r--mysql-test/main/range_vs_index_merge.result4
-rw-r--r--mysql-test/main/range_vs_index_merge.test2
-rw-r--r--mysql-test/main/range_vs_index_merge_innodb.result6
-rw-r--r--mysql-test/main/rowid_filter.result500
-rw-r--r--mysql-test/main/rowid_filter.test7
-rw-r--r--mysql-test/main/rowid_filter_innodb.result326
-rw-r--r--mysql-test/main/select.result22
-rw-r--r--mysql-test/main/select.test8
-rw-r--r--mysql-test/main/select_jcl6.result34
-rw-r--r--mysql-test/main/select_pkeycache.result22
-rw-r--r--mysql-test/main/select_safe.result4
-rw-r--r--mysql-test/main/selectivity.result6
-rw-r--r--mysql-test/main/selectivity_innodb.result59
-rw-r--r--mysql-test/main/selectivity_no_engine.result4
-rw-r--r--mysql-test/main/show_explain.result4
-rw-r--r--mysql-test/main/show_explain_json.result6
-rw-r--r--mysql-test/main/single_delete_update.result26
-rw-r--r--mysql-test/main/single_delete_update.test2
-rw-r--r--mysql-test/main/stat_tables.result13
-rw-r--r--mysql-test/main/stat_tables.test2
-rw-r--r--mysql-test/main/stat_tables_innodb.result15
-rw-r--r--mysql-test/main/status.result10
-rw-r--r--mysql-test/main/subselect.result58
-rw-r--r--mysql-test/main/subselect.test8
-rw-r--r--mysql-test/main/subselect2.result10
-rw-r--r--mysql-test/main/subselect3.result10
-rw-r--r--mysql-test/main/subselect3_jcl6.result6
-rw-r--r--mysql-test/main/subselect4.result23
-rw-r--r--mysql-test/main/subselect_exists2in.result10
-rw-r--r--mysql-test/main/subselect_exists2in_costmat.result4
-rw-r--r--mysql-test/main/subselect_exists2in_costmat.test1
-rw-r--r--mysql-test/main/subselect_extra.result4
-rw-r--r--mysql-test/main/subselect_innodb.result9
-rw-r--r--mysql-test/main/subselect_mat.result52
-rw-r--r--mysql-test/main/subselect_mat.test3
-rw-r--r--mysql-test/main/subselect_mat_cost.result14
-rw-r--r--mysql-test/main/subselect_mat_cost.test6
-rw-r--r--mysql-test/main/subselect_mat_cost_bugs.result6
-rw-r--r--mysql-test/main/subselect_no_exists_to_in.result58
-rw-r--r--mysql-test/main/subselect_no_mat.result56
-rw-r--r--mysql-test/main/subselect_no_opts.result32
-rw-r--r--mysql-test/main/subselect_no_scache.result58
-rw-r--r--mysql-test/main/subselect_no_semijoin.result32
-rw-r--r--mysql-test/main/subselect_sj.result118
-rw-r--r--mysql-test/main/subselect_sj.test14
-rw-r--r--mysql-test/main/subselect_sj2.result41
-rw-r--r--mysql-test/main/subselect_sj2.test2
-rw-r--r--mysql-test/main/subselect_sj2_jcl6.result40
-rw-r--r--mysql-test/main/subselect_sj2_jcl6.test2
-rw-r--r--mysql-test/main/subselect_sj2_mat.result60
-rw-r--r--mysql-test/main/subselect_sj_jcl6.result94
-rw-r--r--mysql-test/main/subselect_sj_mat.result78
-rw-r--r--mysql-test/main/subselect_sj_nonmerged.result12
-rw-r--r--mysql-test/main/table_elim.result11
-rw-r--r--mysql-test/main/table_value_constr.result6
-rw-r--r--mysql-test/main/table_value_constr.test1
-rw-r--r--mysql-test/main/tmp_table_count-7586.result2
-rw-r--r--mysql-test/main/tmp_table_count-7586.test2
-rw-r--r--mysql-test/main/type_blob.result2
-rw-r--r--mysql-test/main/type_datetime.result6
-rw-r--r--mysql-test/main/user_var.result4
-rw-r--r--mysql-test/main/view.test2
-rw-r--r--mysql-test/main/xtradb_mrr.result6
-rw-r--r--mysql-test/main/xtradb_mrr.test3
153 files changed, 4274 insertions, 2595 deletions
diff --git a/mysql-test/main/costs.result b/mysql-test/main/costs.result
new file mode 100644
index 00000000000..879d586790b
--- /dev/null
+++ b/mysql-test/main/costs.result
@@ -0,0 +1,91 @@
+create table t1 (a int primary key, b int, c int, d int, e int, key ba (b,a), key bda (b,d,a), key cba (c,b,a), key cb (c,b), key d (d)) engine=aria;
+insert into t1 select seq,seq,seq,seq,seq from seq_1_to_10;
+insert into t1 values(20,2,2,2,2),(21,3,4,5,6);
+#
+# Get different scan costs
+#
+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
+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
+#
+# Range scans should be used if we don't examine all rows in the table
+#
+explain select count(a) from t1;
+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
+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
+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
+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
+#
+# 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
+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
+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
+# 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
+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
+#
+# 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
+#
+# 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
+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
+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
+#
+# 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
+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
+drop table t1;
diff --git a/mysql-test/main/costs.test b/mysql-test/main/costs.test
new file mode 100644
index 00000000000..6dcc41b57a3
--- /dev/null
+++ b/mysql-test/main/costs.test
@@ -0,0 +1,75 @@
+#
+# Test of cost calcuations. This test is using the Aria engine as the cost
+# calculations are stable for it.
+#
+--source include/have_sequence.inc
+
+create table t1 (a int primary key, b int, c int, d int, e int, key ba (b,a), key bda (b,d,a), key cba (c,b,a), key cb (c,b), key d (d)) engine=aria;
+insert into t1 select seq,seq,seq,seq,seq from seq_1_to_10;
+insert into t1 values(20,2,2,2,2),(21,3,4,5,6);
+
+--echo #
+--echo # Get different scan costs
+--echo #
+
+explain select sum(e) as "table_scan" from t1;
+--source include/last_query_cost.inc
+explain select sum(a) as "index scan" from t1;
+--source include/last_query_cost.inc
+
+--echo #
+--echo # Range scans should be used if we don't examine all rows in the table
+--echo #
+explain select count(a) from t1;
+--source include/last_query_cost.inc
+explain select count(*) from t1 where a > 0;
+--source include/last_query_cost.inc
+explain select count(*) from t1 where a > 1;
+--source include/last_query_cost.inc
+explain select count(*) from t1 where a > 2;
+--source include/last_query_cost.inc
+
+--echo #
+--echo # Shorter indexes are prefered over longer indexs
+--echo #
+explain select sum(a+b) from t1;
+--source include/last_query_cost.inc
+explain select count(*) from t1 where b between 5 and 10;
+--source include/last_query_cost.inc
+explain select sum(b+c) from t1 where b between 5 and 6 and c between 5 and 6;
+--source include/last_query_cost.inc
+
+--echo # Cost of 'd' should be slightly smaller as key 'ba' is longer than 'd'
+explain select count(*) from t1 where b > 6;
+--source include/last_query_cost.inc
+explain select count(*) from t1 where d > 6;
+--source include/last_query_cost.inc
+
+
+--echo #
+--echo # Check covering index usage
+--echo #
+explain select a,b,c from t1 where a=b;
+--source include/last_query_cost.inc
+
+--echo #
+--echo # Prefer ref keys over ranges
+--echo #
+
+explain select count(*) from t1 where b=2;
+--source include/last_query_cost.inc
+explain select count(*) from t1 where b=2 and c=2;
+--source include/last_query_cost.inc
+explain select count(*) from t1 where b=3 and c between 3 and 4;
+--source include/last_query_cost.inc
+
+--echo #
+--echo # Prefer eq keys over ref keys
+--echo #
+
+explain select a,b,e from t1 where a=10 or a=11;
+--source include/last_query_cost.inc
+explain select a,b,e from t1 where d=10 or d=11;
+--source include/last_query_cost.inc
+
+drop table t1;
diff --git a/mysql-test/main/cte_nonrecursive.result b/mysql-test/main/cte_nonrecursive.result
index f7871d4f929..7ad246941ae 100644
--- a/mysql-test/main/cte_nonrecursive.result
+++ b/mysql-test/main/cte_nonrecursive.result
@@ -418,8 +418,8 @@ t2.c in (with t as (select * from t1 where t1.a<5)
select t2.c from t2,t where t2.c=t.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 4
-1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1
3 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where
3 MATERIALIZED t1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join)
explain
@@ -430,8 +430,8 @@ from t2,(select * from t1 where t1.a<5) as t
where t2.c=t.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 4
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where
2 MATERIALIZED t1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join)
# two different definitions of t: one in the with clause of the main query,
@@ -461,8 +461,8 @@ t.c in (with t as (select * from t1 where t1.a<5)
select t2.c from t2,t where t2.c=t.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where
-1 PRIMARY <subquery4> eq_ref distinct_key distinct_key 4 func 1
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY <subquery4> eq_ref distinct_key distinct_key 4 func 1
4 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where
4 MATERIALIZED t1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join)
explain
@@ -472,8 +472,8 @@ t.c in (select t2.c from t2, (select * from t1 where t1.a<5) as t
where t2.c=t.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where
-1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1
3 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where
3 MATERIALIZED t1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join)
# another with table tt is defined in the with clause of a subquery
diff --git a/mysql-test/main/cte_recursive.result b/mysql-test/main/cte_recursive.result
index a754b923ecf..a7b73b80845 100644
--- a/mysql-test/main/cte_recursive.result
+++ b/mysql-test/main/cte_recursive.result
@@ -4565,9 +4565,9 @@ id select_type table type possible_keys key key_len ref rows Extra
4 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 2
5 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 2
NULL UNION RESULT <union3,4,5> ALL NULL NULL NULL NULL NULL
-2 DERIVED h ALL NULL NULL NULL NULL 12
-2 DERIVED <derived3> ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
-2 DERIVED w ALL NULL NULL NULL NULL 12 Using where; Using join buffer (incremental, BNL join)
+2 DERIVED h ALL NULL NULL NULL NULL 12 Using where
+2 DERIVED <derived3> ref key0 key0 5 test.h.id 2
+2 DERIVED w ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
prepare stmt from "with recursive
ancestor_couples(h_id, h_name, h_dob, h_father, h_mother,
w_id, w_name, w_dob, w_father, w_mother)
diff --git a/mysql-test/main/ctype_binary.result b/mysql-test/main/ctype_binary.result
index 24fc961e17d..1dd5f93ad17 100644
--- a/mysql-test/main/ctype_binary.result
+++ b/mysql-test/main/ctype_binary.result
@@ -2763,6 +2763,7 @@ id INT(11) DEFAULT NULL,
date_column DATE DEFAULT NULL,
KEY(date_column));
INSERT INTO t1 VALUES (1,'2010-09-01'),(2,'2010-10-01');
+INSERT INTO t1 VALUES (3,'2012-09-01'),(4,'2012-10-01'),(5,'2012-10-01');
EXPLAIN SELECT * FROM t1 WHERE date_column BETWEEN '2010-09-01' AND '2010-10-01';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range date_column date_column 4 NULL 2 Using index condition
diff --git a/mysql-test/main/ctype_cp1251.result b/mysql-test/main/ctype_cp1251.result
index a341d9ce471..475058dc2bb 100644
--- a/mysql-test/main/ctype_cp1251.result
+++ b/mysql-test/main/ctype_cp1251.result
@@ -3175,6 +3175,7 @@ id INT(11) DEFAULT NULL,
date_column DATE DEFAULT NULL,
KEY(date_column));
INSERT INTO t1 VALUES (1,'2010-09-01'),(2,'2010-10-01');
+INSERT INTO t1 VALUES (3,'2012-09-01'),(4,'2012-10-01'),(5,'2012-10-01');
EXPLAIN SELECT * FROM t1 WHERE date_column BETWEEN '2010-09-01' AND '2010-10-01';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range date_column date_column 4 NULL 2 Using index condition
diff --git a/mysql-test/main/ctype_latin1.result b/mysql-test/main/ctype_latin1.result
index 5be12e91b68..4088530fc0f 100644
--- a/mysql-test/main/ctype_latin1.result
+++ b/mysql-test/main/ctype_latin1.result
@@ -3484,6 +3484,7 @@ id INT(11) DEFAULT NULL,
date_column DATE DEFAULT NULL,
KEY(date_column));
INSERT INTO t1 VALUES (1,'2010-09-01'),(2,'2010-10-01');
+INSERT INTO t1 VALUES (3,'2012-09-01'),(4,'2012-10-01'),(5,'2012-10-01');
EXPLAIN SELECT * FROM t1 WHERE date_column BETWEEN '2010-09-01' AND '2010-10-01';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range date_column date_column 4 NULL 2 Using index condition
diff --git a/mysql-test/main/ctype_ucs.result b/mysql-test/main/ctype_ucs.result
index ce0d695797b..ce8e1c2e83b 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 range a a 23 NULL 31 Using where; Using index
+1 SIMPLE t1 index 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 range a a 23 NULL 31 Using where; Using index
+1 SIMPLE t1 index a a 23 NULL 31 Using where; Using index
SELECT hex(concat('d',_ucs2 0x017E,'%'));
hex(concat('d',_ucs2 0x017E,'%'))
0064017E0025
@@ -4368,6 +4368,7 @@ id INT(11) DEFAULT NULL,
date_column DATE DEFAULT NULL,
KEY(date_column));
INSERT INTO t1 VALUES (1,'2010-09-01'),(2,'2010-10-01');
+INSERT INTO t1 VALUES (3,'2012-09-01'),(4,'2012-10-01'),(5,'2012-10-01');
EXPLAIN SELECT * FROM t1 WHERE date_column BETWEEN '2010-09-01' AND '2010-10-01';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range date_column date_column 4 NULL 2 Using index condition
diff --git a/mysql-test/main/ctype_utf8.result b/mysql-test/main/ctype_utf8.result
index 5986ea3ac81..6d50a6cee2e 100644
--- a/mysql-test/main/ctype_utf8.result
+++ b/mysql-test/main/ctype_utf8.result
@@ -5235,6 +5235,7 @@ id INT(11) DEFAULT NULL,
date_column DATE DEFAULT NULL,
KEY(date_column));
INSERT INTO t1 VALUES (1,'2010-09-01'),(2,'2010-10-01');
+INSERT INTO t1 VALUES (3,'2012-09-01'),(4,'2012-10-01'),(5,'2012-10-01');
EXPLAIN SELECT * FROM t1 WHERE date_column BETWEEN '2010-09-01' AND '2010-10-01';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range date_column date_column 4 NULL 2 Using index condition
diff --git a/mysql-test/main/derived.result b/mysql-test/main/derived.result
index 268b111cd77..6f6fccf35d9 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 <derived2> ALL NULL NULL NULL NULL 2
-1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 THEMAX.E2 1 Using where
+1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
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;
diff --git a/mysql-test/main/derived_cond_pushdown.result b/mysql-test/main/derived_cond_pushdown.result
index a17580d9943..9be0a96ef77 100644
--- a/mysql-test/main/derived_cond_pushdown.result
+++ b/mysql-test/main/derived_cond_pushdown.result
@@ -19188,7 +19188,7 @@ DROP TABLE t1;
CREATE TABLE t1 (pk1 INT PRIMARY KEY, f INT) ENGINE=Aria;
INSERT INTO t1 VALUES (1,0),(2,0);
CREATE TABLE t2 (pk2 INT PRIMARY KEY) ENGINE=Aria;
-INSERT INTO t2 VALUES (1),(2),(3);
+INSERT INTO t2 VALUES (1),(2),(3),(11),(12),(13);
CREATE VIEW v2 AS SELECT pk2, COUNT(*) AS cnt FROM t2 GROUP BY pk2;
SELECT * FROM t1 INNER JOIN v2 ON pk1 = pk2 WHERE f <> 5;
pk1 f pk2 cnt
@@ -19506,8 +19506,8 @@ 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 <derived3> ref key0 key0 4 test.t1.id 2 100.00 FirstMatch(t1)
-3 LATERAL DERIVED t1 eq_ref PRIMARY PRIMARY 4 test.t1.id 1 100.00
-3 LATERAL DERIVED t2 ref ro_id ro_id 4 test.t1.id 1 100.00 Using where
+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:
Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`v1`) where `v1`.`id` = `test`.`t1`.`id`
select id, a from t1
@@ -19544,10 +19544,10 @@ 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 <derived3> ref key0 key0 4 test.t1.id 2 100.00 FirstMatch(t1)
-3 LATERAL DERIVED t1 eq_ref PRIMARY PRIMARY 4 test.t1.id 1 100.00
-3 LATERAL DERIVED t2 ref ro_id ro_id 4 test.t1.id 1 100.00 Using where
+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:
-Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`a` AS `a` from `test`.`t1` semi join ((/* select#3 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`a` AS `a` from `test`.`t1` left join `test`.`t2` on(`test`.`t2`.`ro_id` = `test`.`t1`.`id` and `test`.`t2`.`flag` = 1) where `test`.`t1`.`id` = `test`.`t1`.`id` group by `test`.`t1`.`id`) `dt`) where `dt`.`id` = `test`.`t1`.`id`
+Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`a` AS `a` from `test`.`t1` semi join ((/* select#3 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`a` AS `a` from `test`.`t1` left join `test`.`t2` on(`test`.`t2`.`ro_id` = `test`.`t1`.`id` and `test`.`t2`.`flag` = 1) where 1 group by `test`.`t1`.`id`) `dt`) where `dt`.`id` = `test`.`t1`.`id`
drop view v1;
drop table t1,t2;
#
@@ -20061,7 +20061,7 @@ 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 t3 index t1_id t1_id 15 NULL 47 Using where; Using index
1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t3.t1_id 1 Using index
1 PRIMARY <derived2> 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
@@ -20080,11 +20080,11 @@ EXPLAIN
{
"table": {
"table_name": "t3",
- "access_type": "range",
+ "access_type": "index",
"possible_keys": ["t1_id"],
"key": "t1_id",
- "key_length": "5",
- "used_key_parts": ["t1_id"],
+ "key_length": "15",
+ "used_key_parts": ["t1_id", "YEAR", "quarter"],
"rows": 47,
"filtered": 100,
"attached_condition": "t3.t1_id between 200 and 100000 and t3.t1_id is not null",
@@ -20416,8 +20416,8 @@ 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 <derived2> ref key0 key0 17 test.charges.from_ledger_id,test.charges.id 4
-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
+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
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';
@@ -20608,8 +20608,8 @@ 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 <derived2> ref key0 key0 18 test.charges.from_ledger_id,test.charges.id 4
-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
+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
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 39e82210e4c..a09fd1b59e3 100644
--- a/mysql-test/main/derived_cond_pushdown.test
+++ b/mysql-test/main/derived_cond_pushdown.test
@@ -3324,7 +3324,7 @@ CREATE TABLE t1 (pk1 INT PRIMARY KEY, f INT) ENGINE=Aria;
INSERT INTO t1 VALUES (1,0),(2,0);
CREATE TABLE t2 (pk2 INT PRIMARY KEY) ENGINE=Aria;
-INSERT INTO t2 VALUES (1),(2),(3);
+INSERT INTO t2 VALUES (1),(2),(3),(11),(12),(13);
CREATE VIEW v2 AS SELECT pk2, COUNT(*) AS cnt FROM t2 GROUP BY pk2;
diff --git a/mysql-test/main/derived_opt.result b/mysql-test/main/derived_opt.result
index cf0c1cb617f..4033f381458 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 eq_ref PRIMARY PRIMARY 4 test.A.E2 1 Using where
+1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
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 7a680d3a0df..be3de7dbc02 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 <derived2> ref key0 key0 8 test.t1.n1,test.t1.n2 2
-2 LATERAL DERIVED t1 ref c1,n1_c1_n2 n1_c1_n2 4 test.t1.n1 1 Using where; Using index
+2 DERIVED t1 ref c1,n1_c1_n2 c1 1 const 2 Using index condition; Using where; Using temporary; Using filesort
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
@@ -175,8 +175,8 @@ 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 <derived3> ref key0 key0 5 test.t1.a 2
-3 LATERAL DERIVED t1 ref a,a_2 a 5 test.t1.a 1 Using where; Using temporary; Using filesort
-3 LATERAL DERIVED t2 ref c c 5 test.t1.b 1 Using index
+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
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 <derived2> ref key0 key0 9 test.t2.id,test.t1.id 2
-2 DERIVED t3 ref idx1,idx2 idx1 4 const 5 Using where; Using index
+2 LATERAL DERIVED t3 ref idx1,idx2 idx2 4 test.t1.itemid 1 Using index condition; Using where
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 b86cd1c42cc..a64894441c8 100644
--- a/mysql-test/main/derived_view.result
+++ b/mysql-test/main/derived_view.result
@@ -1881,14 +1881,14 @@ WHERE (t2.a ,t1.b) NOT IN (SELECT DISTINCT c,a FROM t3 t);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
-2 DEPENDENT SUBQUERY t unique_subquery PRIMARY,c PRIMARY 4 func 1 Using where
+2 DEPENDENT SUBQUERY t index_subquery PRIMARY,c c 8 func,func 2 Using index; Using where
EXPLAIN
SELECT * FROM t1 , t2
WHERE (t2.a ,t1.b) NOT IN (SELECT DISTINCT c,a FROM (SELECT * FROM t3) t);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
-2 DEPENDENT SUBQUERY t3 unique_subquery PRIMARY,c PRIMARY 4 func 1 Using where
+2 DEPENDENT SUBQUERY t3 index_subquery PRIMARY,c c 8 func,func 2 Using index; Using where
SELECT * FROM t1 , t2
WHERE (t2.a ,t1.b) NOT IN (SELECT DISTINCT c,a FROM (SELECT * FROM t3) t);
b a
@@ -1931,8 +1931,8 @@ WHERE t3.b IN (SELECT v1.b FROM v1, t2
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 <derived3> ref key1 key1 8 const,const 0 Start temporary
-1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where
+1 PRIMARY <derived3> ref key1 key1 8 const,const 0 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
@@ -2439,10 +2439,14 @@ CREATE TABLE t2 (a int, INDEX(a));
INSERT INTO t2 VALUES (1), (2);
INSERT INTO t1 SELECT a FROM (SELECT a FROM test.t1) AS s1 NATURAL JOIN
t2 AS s2;
+INSERT INTO t1 SELECT a FROM (SELECT a FROM test.t1) AS s1 NATURAL JOIN
+t2 AS s2;
SELECT * FROM t1;
a
1
1
+1
+1
DELETE FROM t1;
INSERT INTO t1 VALUES (1);
PREPARE stmt FROM "
@@ -2459,6 +2463,8 @@ SELECT * FROM t1;
a
1
1
+1
+1
drop table t1,t2;
set optimizer_switch=@save968720_optimizer_switch;
#
diff --git a/mysql-test/main/derived_view.test b/mysql-test/main/derived_view.test
index caccc7dafa1..c511b8febc9 100644
--- a/mysql-test/main/derived_view.test
+++ b/mysql-test/main/derived_view.test
@@ -1419,6 +1419,8 @@ INSERT INTO t2 VALUES (1), (2);
INSERT INTO t1 SELECT a FROM (SELECT a FROM test.t1) AS s1 NATURAL JOIN
t2 AS s2;
+INSERT INTO t1 SELECT a FROM (SELECT a FROM test.t1) AS s1 NATURAL JOIN
+t2 AS s2;
SELECT * FROM t1;
DELETE FROM t1;
diff --git a/mysql-test/main/desc_index_range.result b/mysql-test/main/desc_index_range.result
index 6b1f2e31c31..a540efe33d6 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 ref PRIMARY PRIMARY 4 const 1000 Using index
+1 SIMPLE t1 index PRIMARY PRIMARY 8 NULL 1001 Using where; 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'))
@@ -194,7 +194,7 @@ test.t1 analyze status OK
# Must use ROR-intersect:
explain select * from t1 where b = 255 AND a IS NULL;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 index_merge a,b b,a 5,5 NULL 1 Using intersect(b,a); Using where; Using index
+1 SIMPLE t1 ref a,b b 5 const 2 Using where
select * from t1 where b = 255 AND a IS NULL;
pk a b
10000 NULL 255
diff --git a/mysql-test/main/distinct.result b/mysql-test/main/distinct.result
index b422d3b286e..3064e062781 100644
--- a/mysql-test/main/distinct.result
+++ b/mysql-test/main/distinct.result
@@ -175,7 +175,7 @@ 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 t3 ref a a 5 test.t1.b 2 Using index
-1 SIMPLE t2 index a a 4 NULL 5 Using where; Using index; Using join buffer (flat, BNL join)
+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
diff --git a/mysql-test/main/explain.result b/mysql-test/main/explain.result
index 8db5e9f51ac..a5ad9fad4ba 100644
--- a/mysql-test/main/explain.result
+++ b/mysql-test/main/explain.result
@@ -325,7 +325,7 @@ DROP TABLE t1;
# Bug#56814 Explain + subselect + fulltext crashes server
#
CREATE TABLE t1(f1 VARCHAR(6) NOT NULL,
-FULLTEXT KEY(f1),UNIQUE(f1));
+FULLTEXT KEY `fulltext` (f1), UNIQUE `unique` (f1));
INSERT INTO t1 VALUES ('test');
EXPLAIN SELECT 1 FROM t1
WHERE 1 > ALL((SELECT t1.f1 FROM t1 JOIN t1 a ON (MATCH(t1.f1) AGAINST (""))
@@ -333,7 +333,9 @@ 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 fulltext f1_2,f1 f1 0 1 Using where
+2 SUBQUERY t1 index unique,fulltext unique 8 NULL 1 Using where; Using index
+Warnings:
+Warning 1292 Truncated incorrect DECIMAL value: 'test'
PREPARE stmt FROM
'EXPLAIN SELECT 1 FROM t1
WHERE 1 > ALL((SELECT t1.f1 FROM t1 RIGHT OUTER JOIN t1 a
@@ -343,12 +345,16 @@ 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 fulltext f1_2,f1 f1 0 1 Using where
+2 SUBQUERY t1 index unique,fulltext unique 8 NULL 1 Using where; Using index
+Warnings:
+Warning 1292 Truncated incorrect DECIMAL value: 'test'
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 fulltext f1_2,f1 f1 0 1 Using where
+2 SUBQUERY t1 index unique,fulltext unique 8 NULL 1 Using where; Using index
+Warnings:
+Warning 1292 Truncated incorrect DECIMAL value: 'test'
DEALLOCATE PREPARE stmt;
PREPARE stmt FROM
'EXPLAIN SELECT 1 FROM t1
@@ -359,12 +365,15 @@ 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 fulltext f1_2,f1 f1 0 1 Using where
+2 SUBQUERY t1 index unique,fulltext unique 8 NULL 1 Using where; Using index
+Warnings:
+Warning 1292 Truncated incorrect DECIMAL value: 'test'
+INSERT into t1 values('test1'),('test2'),('test3'),('test4'),('test5');
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 fulltext f1_2,f1 f1 0 1 Using where
+1 PRIMARY t1 index NULL unique 8 NULL 6 Using index
+2 SUBQUERY t1 fulltext unique,fulltext fulltext 0 1 Using where
+2 SUBQUERY a index NULL unique 8 NULL 6 Using index
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
End of 5.1 tests.
diff --git a/mysql-test/main/explain.test b/mysql-test/main/explain.test
index 36595ba727c..0e4a3b8c2c0 100644
--- a/mysql-test/main/explain.test
+++ b/mysql-test/main/explain.test
@@ -254,7 +254,7 @@ DROP TABLE t1;
--echo #
CREATE TABLE t1(f1 VARCHAR(6) NOT NULL,
-FULLTEXT KEY(f1),UNIQUE(f1));
+FULLTEXT KEY `fulltext` (f1), UNIQUE `unique` (f1));
INSERT INTO t1 VALUES ('test');
EXPLAIN SELECT 1 FROM t1
@@ -279,6 +279,7 @@ PREPARE stmt FROM
WHERE t1.f1 GROUP BY t1.f1))';
EXECUTE stmt;
+INSERT into t1 values('test1'),('test2'),('test3'),('test4'),('test5');
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
diff --git a/mysql-test/main/explain_innodb.result b/mysql-test/main/explain_innodb.result
index 0bdd5a44985..fe51e45e35d 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 range NULL id 53 NULL 1 Using index for group-by
+2 DERIVED t1 index NULL id 53 NULL 1 Using index
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 3c3c0688ab8..fde96bc1a14 100644
--- a/mysql-test/main/explain_json.result
+++ b/mysql-test/main/explain_json.result
@@ -729,6 +729,19 @@ EXPLAIN
}
},
{
+ "block-nl-join": {
+ "table": {
+ "table_name": "t2",
+ "access_type": "ALL",
+ "rows": 10,
+ "filtered": 100
+ },
+ "buffer_type": "flat",
+ "buffer_size": "119",
+ "join_type": "BNL"
+ }
+ },
+ {
"table": {
"table_name": "<subquery2>",
"access_type": "eq_ref",
@@ -756,19 +769,6 @@ EXPLAIN
}
}
}
- },
- {
- "block-nl-join": {
- "table": {
- "table_name": "t2",
- "access_type": "ALL",
- "rows": 10,
- "filtered": 100
- },
- "buffer_type": "flat",
- "buffer_size": "1Kb",
- "join_type": "BNL"
- }
}
]
}
@@ -930,9 +930,9 @@ drop table t0;
# MDEV-7265: "Full scan on NULL key", the join case
#
CREATE TABLE t1 (a INT, KEY(a));
-INSERT INTO t1 VALUES (1),(2);
+INSERT INTO t1 VALUES (1),(2),(5),(6),(7);
CREATE TABLE t2 (b INT);
-INSERT INTO t2 VALUES (3),(4);
+INSERT INTO t2 VALUES (3),(4),(9),(10),(11);
EXPLAIN FORMAT=JSON SELECT * FROM t1 AS outer_t1 WHERE a <> ALL ( SELECT a FROM t1, t2 WHERE b <> outer_t1.a );
EXPLAIN
{
@@ -946,7 +946,7 @@ EXPLAIN
"key": "a",
"key_length": "5",
"used_key_parts": ["a"],
- "rows": 2,
+ "rows": 5,
"filtered": 100,
"attached_condition": "!<in_optimizer>(outer_t1.a,<exists>(subquery#2))",
"using_index": true
@@ -969,7 +969,7 @@ EXPLAIN
"key_length": "5",
"used_key_parts": ["a"],
"ref": ["func"],
- "rows": 2,
+ "rows": 3,
"filtered": 100,
"attached_condition": "trigcond(<cache>(outer_t1.a) = t1.a or t1.a is null)",
"using_index": true
@@ -981,7 +981,7 @@ EXPLAIN
"table": {
"table_name": "t2",
"access_type": "ALL",
- "rows": 2,
+ "rows": 5,
"filtered": 100
},
"buffer_type": "flat",
diff --git a/mysql-test/main/explain_json.test b/mysql-test/main/explain_json.test
index 17e2da4754c..baf1aa988a2 100644
--- a/mysql-test/main/explain_json.test
+++ b/mysql-test/main/explain_json.test
@@ -163,10 +163,10 @@ drop table t0;
--echo #
CREATE TABLE t1 (a INT, KEY(a));
-INSERT INTO t1 VALUES (1),(2);
+INSERT INTO t1 VALUES (1),(2),(5),(6),(7);
CREATE TABLE t2 (b INT);
-INSERT INTO t2 VALUES (3),(4);
+INSERT INTO t2 VALUES (3),(4),(9),(10),(11);
EXPLAIN FORMAT=JSON SELECT * FROM t1 AS outer_t1 WHERE a <> ALL ( SELECT a FROM t1, t2 WHERE b <> outer_t1.a );
diff --git a/mysql-test/main/func_group.result b/mysql-test/main/func_group.result
index 8f9c27eeb86..5d9b1df58ba 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 range PRIMARY PRIMARY 3 NULL 14 Using where; Using index
+1 SIMPLE t1 index PRIMARY PRIMARY 3 NULL 15 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 range k2 k2 4 NULL 6 Using where; Using index
+1 SIMPLE t2 index k2 k2 4 NULL 7 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 ref a a 5 const 3
+1 SIMPLE t2 ALL a NULL NULL NULL 6 Using where
SELECT MIN(b), MIN(c) FROM t2 WHERE a = 1;
MIN(b) MIN(c)
3 2
@@ -1856,9 +1856,8 @@ 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 <subquery2> eq_ref distinct_key distinct_key 8 func,func 1 100.00
+1 PRIMARY t2 ALL NULL NULL NULL NULL 5 100.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)
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where
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
SELECT MAX(a) FROM t1 WHERE (1,2) IN (SELECT a,b FROM t2 WHERE b<5) and a<10;
diff --git a/mysql-test/main/func_in.result b/mysql-test/main/func_in.result
index 175e23ec65f..13eb9501599 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 range t1f1_idx t1f1_idx 2 NULL 2 Using where; Using index
+1 SIMPLE t1 index t1f1_idx t1f1_idx 2 NULL 3 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 range PRIMARY PRIMARY 4 NULL 2 Using where; Using index
+1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 3 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 range PRIMARY PRIMARY 16 NULL 2 Using where; Using index
+1 SIMPLE t2 index PRIMARY PRIMARY 16 NULL 3 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 range PRIMARY PRIMARY 4 NULL 3 Using where; Using index
+1 SIMPLE t3 index 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 range PRIMARY PRIMARY 4 NULL 2 Using where; Using index; Using join buffer (incremental, BNL join)
+1 SIMPLE t3 index PRIMARY PRIMARY 4 NULL 4 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 range PRIMARY PRIMARY 4 NULL 2 Using index condition
+1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where
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 range PRIMARY PRIMARY 4 NULL 3 Using index condition
+1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where
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 range PRIMARY PRIMARY 4 NULL 2 Using index condition
+1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where
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 7e1220d3904..f424b5036a0 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 3350.237037
+Last_query_cost 2696.338350
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,7 +139,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 3350.237037
+Last_query_cost 2696.338350
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
@@ -151,7 +151,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 1276.787037
+Last_query_cost 1559.791393
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
@@ -163,7 +163,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 1276.787037
+Last_query_cost 1559.791393
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
@@ -175,7 +175,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 1276.787037
+Last_query_cost 1563.335143
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
@@ -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 1276.787037
+Last_query_cost 1563.335143
set optimizer_prune_level=0;
select @@optimizer_prune_level;
@@optimizer_prune_level
@@ -202,24 +202,24 @@ id select_type table type possible_keys key key_len ref rows Extra
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 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 t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost';
Variable_name Value
-Last_query_cost 2705.237037
+Last_query_cost 2693.038350
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 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 t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost';
Variable_name Value
-Last_query_cost 2705.237037
+Last_query_cost 2693.038350
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
@@ -231,7 +231,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 701.018727
+Last_query_cost 751.472751
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
@@ -243,7 +243,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 701.018727
+Last_query_cost 751.472751
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
@@ -255,7 +255,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 701.018727
+Last_query_cost 760.922751
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
@@ -267,7 +267,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 701.018727
+Last_query_cost 760.922751
set optimizer_search_depth=1;
select @@optimizer_search_depth;
@@optimizer_search_depth
@@ -283,7 +283,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 3350.237037
+Last_query_cost 2696.338350
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
@@ -295,7 +295,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 3350.237037
+Last_query_cost 2696.338350
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
@@ -307,7 +307,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 1678.037037
+Last_query_cost 2068.798851
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
@@ -319,7 +319,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 1678.037037
+Last_query_cost 2068.798851
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 1678.037037
+Last_query_cost 2073.523851
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,7 +343,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 1678.037037
+Last_query_cost 2073.523851
set optimizer_search_depth=62;
select @@optimizer_search_depth;
@@optimizer_search_depth
@@ -354,24 +354,24 @@ id select_type table type possible_keys key key_len ref rows Extra
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 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 t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost';
Variable_name Value
-Last_query_cost 2705.237037
+Last_query_cost 2693.038350
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 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 t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost';
Variable_name Value
-Last_query_cost 2705.237037
+Last_query_cost 2693.038350
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
@@ -383,7 +383,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 701.018727
+Last_query_cost 751.472751
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
@@ -395,7 +395,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 701.018727
+Last_query_cost 751.472751
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
@@ -407,7 +407,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 701.018727
+Last_query_cost 760.922751
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
@@ -419,7 +419,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 701.018727
+Last_query_cost 760.922751
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 3350.237037
+Last_query_cost 2696.338350
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,7 +451,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 3350.237037
+Last_query_cost 2696.338350
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
@@ -463,7 +463,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 1276.787037
+Last_query_cost 1559.791393
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
@@ -475,7 +475,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 1276.787037
+Last_query_cost 1559.791393
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
@@ -487,7 +487,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 1276.787037
+Last_query_cost 1563.335143
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
@@ -499,7 +499,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 1276.787037
+Last_query_cost 1563.335143
set optimizer_search_depth=1;
select @@optimizer_search_depth;
@@optimizer_search_depth
@@ -515,7 +515,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 3350.237037
+Last_query_cost 2696.338350
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
@@ -527,7 +527,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 3350.237037
+Last_query_cost 2696.338350
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
@@ -539,7 +539,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 1678.037037
+Last_query_cost 2068.798851
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
@@ -551,7 +551,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 1678.037037
+Last_query_cost 2068.798851
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 1678.037037
+Last_query_cost 2073.523851
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 1678.037037
+Last_query_cost 2073.523851
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 3350.237037
+Last_query_cost 2696.338350
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,7 +603,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 3350.237037
+Last_query_cost 2696.338350
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
@@ -615,7 +615,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 1276.787037
+Last_query_cost 1559.791393
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
@@ -627,7 +627,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 1276.787037
+Last_query_cost 1559.791393
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
@@ -639,7 +639,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 1276.787037
+Last_query_cost 1563.335143
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
@@ -651,7 +651,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 1276.787037
+Last_query_cost 1563.335143
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);
@@ -802,6 +802,9 @@ WHERE t100.K=t10.I
AND t10000.K=t10.I;
COUNT(*)
9
+#####
+# Expect all variants of EQ joining t100 & t10000 with T10
+# to have same cost # handler_reads:
flush status;
EXPLAIN SELECT COUNT(*) FROM t10,t100,t10000
WHERE t100.K=t10.I
@@ -909,6 +912,12 @@ AND t10000.K=t10.K;
COUNT(*)
9
### NOTE: Handler_reads: 31, expected: 30 ###
+#####
+## EQ_REF Should be executed before table scan(ALL)
+## - Independent of #records in table being EQ_REF-joined
+#####
+#####
+# Expect: Join EQ_REF(t100) before ALL(t10000)
flush status;
EXPLAIN SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t100,t10000
WHERE t100.K=t10.I
@@ -948,6 +957,8 @@ WHERE t100.K=t10.I
AND t10000.I=t10.I;
COUNT(*)
9000
+#####
+# Expect: Join EQ_REF(t10000) before ALL(t100) (star-join)
flush status;
EXPLAIN SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t10000,t100
WHERE t100.I=t10.I
@@ -2902,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 57916
+Optimizer_join_prefixes_check_calls 60210
SET OPTIMIZER_SEARCH_DEPTH = DEFAULT;
#
# Bug found when testing greedy optimizer tests
@@ -2917,8 +2928,8 @@ explain SELECT * FROM t1 AS alias1
WHERE alias1.col_varchar_key IN (SELECT COUNT(*) FROM t1 AS SQ3_alias2 JOIN t1 AS SQ3_alias3 ON (SQ3_alias3.col_varchar_key = SQ3_alias2.col_varchar_key AND SQ3_alias3.pk = SQ3_alias2.pk));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY alias1 index NULL col_varchar_key 20 NULL 2 Using where; Using index
-2 DEPENDENT SUBQUERY SQ3_alias2 index PRIMARY,col_varchar_key col_varchar_key 20 NULL 2 Using index
-2 DEPENDENT SUBQUERY SQ3_alias3 eq_ref PRIMARY,col_varchar_key PRIMARY 4 test.SQ3_alias2.pk 1 Using where
+2 DEPENDENT SUBQUERY SQ3_alias2 index PRIMARY,col_varchar_key col_varchar_key 20 NULL 2 Using where; Using index
+2 DEPENDENT SUBQUERY SQ3_alias3 ref PRIMARY,col_varchar_key col_varchar_key 11 test.SQ3_alias2.col_varchar_key 1 Using where; Using index
drop table t1;
#
# This triggered an assert failure while testing
diff --git a/mysql-test/main/greedy_optimizer.test b/mysql-test/main/greedy_optimizer.test
index 2a830c70677..f2731087cd8 100644
--- a/mysql-test/main/greedy_optimizer.test
+++ b/mysql-test/main/greedy_optimizer.test
@@ -441,9 +441,9 @@ WHERE t100.K=t10.I
AND t10000.K=t10.I;
--source include/check_qep.inc
-#####
-# Expect all variants of EQ joining t100 & t10000 with T10
-# to have same cost # handler_reads:
+--echo #####
+--echo # Expect all variants of EQ joining t100 & t10000 with T10
+--echo # to have same cost # handler_reads:
let $query=
SELECT COUNT(*) FROM t10,t100,t10000
WHERE t100.K=t10.I
@@ -493,12 +493,12 @@ WHERE t100.K=t10.I
--source include/check_qep.inc
-#####
-## EQ_REF Should be executed before table scan(ALL)
-## - Independent of #records in table being EQ_REF-joined
-#####
-#####
-# Expect: Join EQ_REF(t100) before ALL(t10000)
+--echo #####
+--echo ## EQ_REF Should be executed before table scan(ALL)
+--echo ## - Independent of #records in table being EQ_REF-joined
+--echo #####
+--echo #####
+--echo # Expect: Join EQ_REF(t100) before ALL(t10000)
let $query=
SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t100,t10000
WHERE t100.K=t10.I
@@ -517,8 +517,8 @@ WHERE t100.K=t10.I
AND t10000.I=t10.I;
--source include/check_qep.inc
-#####
-# Expect: Join EQ_REF(t10000) before ALL(t100) (star-join)
+--echo #####
+--echo # Expect: Join EQ_REF(t10000) before ALL(t100) (star-join)
let $query=
SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t10000,t100
WHERE t100.I=t10.I
diff --git a/mysql-test/main/group_by.result b/mysql-test/main/group_by.result
index 443c399275f..f60f9ca106c 100644
--- a/mysql-test/main/group_by.result
+++ b/mysql-test/main/group_by.result
@@ -2457,7 +2457,7 @@ test.t1 analyze status OK
EXPLAIN SELECT SQL_BUFFER_RESULT MIN(a), b FROM t1 WHERE t1.b = 'a' GROUP BY b;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref b b 4 const 6 Using where; Using index; Using temporary
+1 SIMPLE t1 range b b 9 NULL 2 Using where; Using index for group-by; Using temporary
SELECT SQL_BUFFER_RESULT MIN(a), b FROM t1 WHERE t1.b = 'a' GROUP BY b;
MIN(a) b
@@ -2465,7 +2465,7 @@ MIN(a) b
EXPLAIN SELECT MIN(a), b FROM t1 WHERE t1.b = 'a' GROUP BY b;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref b b 4 const 6 Using where; Using index
+1 SIMPLE t1 range b b 9 NULL 2 Using where; Using index for group-by
SELECT MIN(a), b FROM t1 WHERE t1.b = 'a' GROUP BY b;
MIN(a) b
diff --git a/mysql-test/main/group_min_max.result b/mysql-test/main/group_min_max.result
index 74685df683e..c1030cf9271 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 96.30 Using where; Using index
+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
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 96.30 Using where; Using index
+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
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;
@@ -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 6 Using where; Using index
+1 SIMPLE t1 range a,b a 10 NULL 2 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 6 Using where; Using index
+1 SIMPLE t1 range a,b a 10 NULL 2 Using where; Using index for group-by
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
@@ -2460,7 +2460,7 @@ EXPLAIN SELECT (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) x
FROM t1 AS t1_outer;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1_outer index NULL a 10 NULL 15 Using index
-2 SUBQUERY t1 range a a 5 NULL 5 Using where; Using index
+2 SUBQUERY t1 range a a 5 NULL 2 Using where; Using index for group-by
EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE EXISTS
(SELECT max(b) FROM t1 GROUP BY a HAVING a < 2);
id select_type table type possible_keys key key_len ref rows Extra
@@ -2470,31 +2470,31 @@ EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE
(SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12;
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 SUBQUERY t1 range a a 5 NULL 5 Using where; Using index
+2 SUBQUERY t1 range a a 5 NULL 2 Using where; Using index for group-by
EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE
a IN (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2
1 PRIMARY t1_outer ref a a 5 <subquery2>.max(b) 3 Using index
-2 MATERIALIZED t1 range a a 5 NULL 5 Using where; Using index
+2 MATERIALIZED t1 range a a 5 NULL 2 Using where; Using index for group-by
EXPLAIN SELECT 1 FROM t1 AS t1_outer GROUP BY a HAVING
a > (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1_outer range NULL a 5 NULL 6 Using index for group-by
-2 SUBQUERY t1 range a a 5 NULL 5 Using where; Using index
+2 SUBQUERY t1 range a a 5 NULL 2 Using where; Using index for group-by
EXPLAIN SELECT 1 FROM t1 AS t1_outer1 JOIN t1 AS t1_outer2
ON t1_outer1.a = (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2)
AND t1_outer1.b = t1_outer2.b;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1_outer1 ref a a 5 const 1 Using where; Using index
1 PRIMARY t1_outer2 index NULL a 10 NULL 15 Using where; Using index; Using join buffer (flat, BNL join)
-2 SUBQUERY t1 range a a 5 NULL 5 Using where; Using index
+2 SUBQUERY t1 range a a 5 NULL 2 Using where; Using index for group-by
EXPLAIN SELECT (SELECT (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) x
FROM t1 AS t1_outer) x2 FROM t1 AS t1_outer2;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1_outer2 index NULL a 10 NULL 15 Using index
2 SUBQUERY t1_outer index NULL a 10 NULL 15 Using index
-3 SUBQUERY t1 range a a 5 NULL 5 Using where; Using index
+3 SUBQUERY t1 range a a 5 NULL 2 Using where; Using index for group-by
CREATE TABLE t3 LIKE t1;
FLUSH STATUS;
INSERT INTO t3 SELECT a,MAX(b) FROM t1 GROUP BY a;
@@ -3794,7 +3794,7 @@ CREATE INDEX break_it ON t1 (a, b);
EXPLAIN
SELECT distinct a, b FROM t1 where a = '3' ORDER BY b;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref break_it break_it 5 const 6 Using where; Using index; Using filesort
+1 SIMPLE t1 range break_it break_it 10 NULL 2 Using where; Using index for group-by; Using filesort
SELECT distinct a, b FROM t1 where a = '3' ORDER BY b;
a b
3 1
@@ -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 range a a 13 NULL 2 Using where; Using index
+1 SIMPLE t1 index 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 range a a 13 NULL 2 Using where; Using index
+1 SIMPLE t1 index a a 13 NULL 2 Using where; Using index
drop table t1;
#
# MDEV-15433: Optimizer does not use group by optimization with distinct
diff --git a/mysql-test/main/index_intersect.result b/mysql-test/main/index_intersect.result
index 3ec98216479..79cd7a32c1a 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 range Population,Name Name 35 NULL # Using index condition; Using where
+1 SIMPLE City index_merge Population,Name Name,Population 35,4 NULL # Using sort_intersect(Name,Population); Using where
EXPLAIN
SELECT * FROM City
WHERE Name LIKE 'M%' AND Population > 7000000;
@@ -355,9 +355,6 @@ COUNT(*)
SELECT COUNT(*) FROM City WHERE Country LIKE 'C%';
COUNT(*)
551
-SELECT COUNT(*) FROM City WHERE Country LIKE 'B%';
-COUNT(*)
-339
SELECT COUNT(*) FROM City WHERE Country LIKE 'J%';
COUNT(*)
256
@@ -370,7 +367,7 @@ EXPLAIN
SELECT * FROM City
WHERE Name BETWEEN 'G' AND 'K' AND Population > 1000000 AND Country LIKE 'J%';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE City index_merge Population,Country,Name Population,Country,Name 4,3,35 NULL # Using sort_intersect(Population,Country,Name); Using where
+1 SIMPLE City index_merge Population,Country,Name Population,Country 4,3 NULL # Using sort_intersect(Population,Country); Using where
EXPLAIN
SELECT * FROM City
WHERE Name BETWEEN 'G' AND 'K' AND Population > 500000 AND Country LIKE 'C%';
@@ -476,7 +473,7 @@ EXPLAIN
SELECT * FROM City
WHERE ID BETWEEN 2001 AND 2500 AND Population > 300000 AND Country LIKE 'H%';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE City index_merge PRIMARY,Population,Country Country,PRIMARY 3,4 NULL # Using sort_intersect(Country,PRIMARY); Using where
+1 SIMPLE City range PRIMARY,Population,Country Country 3 NULL # Using index condition; Using where
EXPLAIN
SELECT * FROM City
WHERE ID BETWEEN 3701 AND 4000 AND Population > 1000000
@@ -488,7 +485,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 range PRIMARY,Population,Country Population 4 NULL # Using index condition; Using where
+1 SIMPLE City index_merge PRIMARY,Population,Country Population,Country 4,3 NULL # Using sort_intersect(Population,Country); Using where
SELECT * FROM City USE INDEX ()
WHERE ID BETWEEN 501 AND 1000 AND Population > 700000 AND Country LIKE 'C%';
ID Name Country Population
@@ -715,18 +712,18 @@ 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 range Population,Country,Name Name 35 NULL # Using index condition; Using where
+1 SIMPLE City index_merge Population,Country,Name Name,Country 35,3 NULL # Using sort_intersect(Name,Country); 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 range PRIMARY,Population,Country Population 4 NULL # Using index condition; Using where
+1 SIMPLE City index_merge PRIMARY,Population,Country Population,PRIMARY 4,4 NULL # Using sort_intersect(Population,PRIMARY); 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 range PRIMARY,Population,Country Population 4 NULL # Using index condition; Using where
+1 SIMPLE City index_merge PRIMARY,Population,Country Population,Country 4,3 NULL # Using sort_intersect(Population,Country); Using where
SELECT * FROM City WHERE
Name LIKE 'C%' AND Population > 1000000;
ID Name Country Population
@@ -966,7 +963,7 @@ EXPLAIN
SELECT * FROM t1
WHERE (f1 < 535 OR f1 > 985) AND ( f4='r' OR f4 LIKE 'a%' ) ;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range PRIMARY,f4 f4 35 NULL # Using index condition; Using where
+1 SIMPLE t1 index_merge PRIMARY,f4 f4,PRIMARY 35,4 NULL # Using sort_intersect(f4,PRIMARY); Using where
SELECT * FROM t1
WHERE (f1 < 535 OR f1 > 985) AND ( f4='r' OR f4 LIKE 'a%' ) ;
f1 f4 f5
diff --git a/mysql-test/main/index_intersect.test b/mysql-test/main/index_intersect.test
index 26937fd5eef..d6208f67a92 100644
--- a/mysql-test/main/index_intersect.test
+++ b/mysql-test/main/index_intersect.test
@@ -120,7 +120,6 @@ SELECT COUNT(*) FROM City WHERE Name BETWEEN 'G' AND 'K';
SELECT COUNT(*) FROM City WHERE Population > 1000000;
SELECT COUNT(*) FROM City WHERE Population > 500000;
SELECT COUNT(*) FROM City WHERE Country LIKE 'C%';
-SELECT COUNT(*) FROM City WHERE Country LIKE 'B%';
SELECT COUNT(*) FROM City WHERE Country LIKE 'J%';
diff --git a/mysql-test/main/index_intersect_innodb.result b/mysql-test/main/index_intersect_innodb.result
index 44407dbcd30..5ee4f88fddd 100644
--- a/mysql-test/main/index_intersect_innodb.result
+++ b/mysql-test/main/index_intersect_innodb.result
@@ -81,12 +81,12 @@ 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 range Population,Name Name 35 NULL # Using index condition; Using where
+1 SIMPLE City index_merge Population,Name Name,Population 35,4 NULL # Using sort_intersect(Name,Population); Using where
EXPLAIN
SELECT * FROM City
WHERE Name LIKE 'M%' AND Population > 7000000;
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
SELECT * FROM City USE INDEX ()
WHERE Name LIKE 'C%' AND Population > 1000000;
ID Name Country Population
@@ -341,8 +341,8 @@ ID Name Country Population
SELECT * FROM City
WHERE Name LIKE 'M%' AND Population > 7000000;
ID Name Country Population
-1024 Mumbai (Bombay) IND 10500000
3580 Moscow RUS 8389200
+1024 Mumbai (Bombay) IND 10500000
SELECT COUNT(*) FROM City WHERE Name BETWEEN 'M' AND 'N';
COUNT(*)
301
@@ -361,9 +361,6 @@ COUNT(*)
SELECT COUNT(*) FROM City WHERE Country LIKE 'C%';
COUNT(*)
551
-SELECT COUNT(*) FROM City WHERE Country LIKE 'B%';
-COUNT(*)
-339
SELECT COUNT(*) FROM City WHERE Country LIKE 'J%';
COUNT(*)
256
@@ -371,17 +368,17 @@ EXPLAIN
SELECT * FROM City
WHERE Name BETWEEN 'M' AND 'N' AND Population > 1000000 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 Population,Name,Country 4,35,3 NULL # Using sort_intersect(Population,Name,Country); Using where
+1 SIMPLE City index_merge Population,Country,Name Population,Name 4,35 NULL # Using sort_intersect(Population,Name); Using where
EXPLAIN
SELECT * FROM City
WHERE Name BETWEEN 'G' AND 'K' AND Population > 1000000 AND Country LIKE 'J%';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE City index_merge Population,Country,Name Population,Country,Name 4,3,35 NULL # Using sort_intersect(Population,Country,Name); Using where
+1 SIMPLE City index_merge Population,Country,Name Population,Country 4,3 NULL # Using sort_intersect(Population,Country); Using where
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 range Population,Name,Country Name # NULL # Using index condition; Using where
+1 SIMPLE City index_merge Population,Name,Country Name,Population,Country # NULL # Using sort_intersect(Name,Population,Country); Using where
SELECT * FROM City USE INDEX ()
WHERE Name BETWEEN 'M' AND 'N' AND Population > 1000000 AND Country LIKE 'C%';
ID Name Country Population
@@ -482,13 +479,13 @@ EXPLAIN
SELECT * FROM City
WHERE ID BETWEEN 2001 AND 2500 AND Population > 300000 AND Country LIKE 'H%';
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 Country 7 NULL # Using index condition; Using where
EXPLAIN
SELECT * FROM City
WHERE ID BETWEEN 3701 AND 4000 AND Population > 1000000
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
EXPLAIN
SELECT * FROM City
WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000
@@ -721,7 +718,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 range Population,Country,Name Name 35 NULL # Using index condition; Using where
+1 SIMPLE City index_merge Population,Country,Name Name,Population,Country 35,4,3 NULL # Using sort_intersect(Name,Population,Country); Using where
EXPLAIN
SELECT * FROM City
WHERE ID BETWEEN 1 AND 500 AND Population > 700000 AND Country LIKE 'C%';
@@ -732,7 +729,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 range PRIMARY,Population,Country PRIMARY 4 NULL # Using where
+1 SIMPLE City index_merge PRIMARY,Population,Country PRIMARY,Population,Country 4,4,7 NULL # Using sort_intersect(PRIMARY,Population,Country); Using where
SELECT * FROM City WHERE
Name LIKE 'C%' AND Population > 1000000;
ID Name Country Population
diff --git a/mysql-test/main/index_merge_myisam.result b/mysql-test/main/index_merge_myisam.result
index 1ecc1ded83a..7d10500d34d 100644
--- a/mysql-test/main/index_merge_myisam.result
+++ b/mysql-test/main/index_merge_myisam.result
@@ -683,7 +683,7 @@ key1 key2 key3 key4 filler1
-1 -1 100 100 key4-key3
explain select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 index_merge key1,key2,key3 key1,key2,key3 5,5,5 NULL 2 Using intersect(key1,key2,key3); Using where; Using index
+1 SIMPLE t1 index_merge key1,key2,key3 key1,key2 5,5 NULL 77 Using intersect(key1,key2); Using where
select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100;
key1 key2 key3
100 100 100
@@ -768,7 +768,7 @@ 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_swt1a_2b 8 const,const 3879 Using where
+1 SIMPLE t1 ref stb_swt1a_2b,stb_swt1b,st_b stb_swt1b 8 const,const 3885 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
@@ -910,7 +910,7 @@ INSERT INTO t1 (key1, key2, filler)
SELECT seq/4, seq/8, 'filler-data' FROM seq_30_to_0;
explain select pk from t1 where key1 = 1 and key2 = 1;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref key1,key2 key1 5 const 4 Using where
+1 SIMPLE t1 index_merge key1,key2 key1,key2 5,4 NULL 1 Using intersect(key1,key2); Using where
select pk from t1 where key2 = 1 and key1 = 1;
pk
26
@@ -1487,7 +1487,7 @@ 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 system PRIMARY NULL NULL NULL 1
-2 SUBQUERY t2 ref f2,f3 f3 2 const 2 Using index condition; Using where
+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;
create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
diff --git a/mysql-test/main/innodb_ext_key,off.rdiff b/mysql-test/main/innodb_ext_key,off.rdiff
index b334d006737..274d1cc47e4 100644
--- a/mysql-test/main/innodb_ext_key,off.rdiff
+++ b/mysql-test/main/innodb_ext_key,off.rdiff
@@ -1,17 +1,20 @@
---- innodb_ext_key.result
-+++ innodb_ext_key,off.result
+--- main/innodb_ext_key.result
++++ main/innodb_ext_key,off.reject
@@ -9,7 +9,7 @@
explain
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 ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 const 6 Using where; 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
flush status;
select count(*) from lineitem where l_orderkey=130 and l_shipdate='1992-07-01';
count(*)
-@@ -19,7 +19,7 @@
+@@ -17,9 +17,9 @@
+ show status like 'handler_read%';
+ Variable_name Value
Handler_read_first 0
- Handler_read_key 1
+-Handler_read_key 1
++Handler_read_key 2
Handler_read_last 0
-Handler_read_next 1
+Handler_read_next 6
@@ -95,13 +98,16 @@
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 ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 const 6 Using where; 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
flush status;
select max(l_linenumber) from lineitem
where l_shipdate='1992-07-01' and l_orderkey=130;
-@@ -145,7 +145,7 @@
+@@ -143,9 +143,9 @@
+ show status like 'handler_read%';
+ Variable_name Value
Handler_read_first 0
- Handler_read_key 1
+-Handler_read_key 1
++Handler_read_key 2
Handler_read_last 0
-Handler_read_next 0
+Handler_read_next 6
@@ -249,7 +255,7 @@
drop table t1,t2,t3;
#
# Bug mdev-4340: performance regression with extended_keys=on
-@@ -714,13 +714,13 @@
+@@ -725,13 +725,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
@@ -265,7 +271,7 @@
drop table t0,t1,t2;
#
# MDEV-11196: Error:Run-Time Check Failure #2 - Stack around the variable 'key_buff'
-@@ -768,11 +768,12 @@
+@@ -766,13 +766,14 @@
{
"table": {
"table_name": "t1",
@@ -279,9 +285,12 @@
+ "used_key_parts": ["f2"],
+ "ref": ["const"],
"rows": 1,
- "filtered": 100,
+- "filtered": 50,
++ "filtered": 100,
"index_condition": "t1.pk1 <= 5 and t1.pk2 <= 5 and t1.f2 = 'abc'",
-@@ -805,8 +806,8 @@
+ "attached_condition": "t1.f1 <= '3'"
+ }
+@@ -799,8 +800,8 @@
"access_type": "range",
"possible_keys": ["k1"],
"key": "k1",
@@ -290,5 +299,5 @@
+ "key_length": "3007",
+ "used_key_parts": ["pk1", "f2"],
"rows": 1,
- "filtered": 100,
+ "filtered": 50,
"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 18a3d147bf3..62b143726b2 100644
--- a/mysql-test/main/innodb_ext_key.result
+++ b/mysql-test/main/innodb_ext_key.result
@@ -386,8 +386,8 @@ WHERE c = a AND 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; Start temporary
-1 PRIMARY t2 index NULL PRIMARY 4 NULL 11 Using index; End temporary; Using join buffer (flat, BNL join)
+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);
a
@@ -638,14 +638,14 @@ 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 index b PRIMARY 8 NULL 2 Using where
+1 SIMPLE t1 range b b 9 NULL 3 Using where; Using filesort
select a from t1 where b is null order by a desc limit 2;
a
3
2
explain select a from t2 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 t2 range b b 9 NULL 3 Using where; Using filesort
+1 SIMPLE t2 index b PRIMARY 8 NULL 2 Using where
select a from t2 where b is null order by a desc limit 2;
a
3
@@ -774,7 +774,7 @@ EXPLAIN
"key_length": "3070",
"used_key_parts": ["f2", "pk1"],
"rows": 1,
- "filtered": 100,
+ "filtered": 50,
"index_condition": "t1.pk1 <= 5 and t1.pk2 <= 5 and t1.f2 = 'abc'",
"attached_condition": "t1.f1 <= '3'"
}
@@ -808,7 +808,7 @@ EXPLAIN
"key_length": "3011",
"used_key_parts": ["pk1", "f2", "pk2"],
"rows": 1,
- "filtered": 100,
+ "filtered": 50,
"index_condition": "t1.f2 <= 5 and t1.pk2 <= 5 and t1.pk1 = 'abc'",
"attached_condition": "t1.f1 <= '3'"
}
diff --git a/mysql-test/main/join.result b/mysql-test/main/join.result
index 8f75105c30d..b56f35f475e 100644
--- a/mysql-test/main/join.result
+++ b/mysql-test/main/join.result
@@ -880,7 +880,7 @@ 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 ALL a,b NULL NULL NULL 1000 Using where
+1 SIMPLE t2 range a,b a 5 NULL 198 Using index condition; Using where
1 SIMPLE t3 ref b b 5 test.t2.b 1
drop table t1, t2, t3;
create table t1 (a int);
@@ -892,13 +892,14 @@ 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 6.016090
+Last_query_cost 3.508545
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;
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
@@ -906,10 +907,11 @@ 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 34.016090
-select '^^: The above should be ~= 20 + cost(select * from t1). Value less than 20 is an error' Z;
+Last_query_cost 48.527829
+select '^^: The above should be ~= 40 + cost(select * from t1). Value less than 40 is an error' Z;
Z
-^^: The above should be ~= 20 + cost(select * from t1). Value less than 20 is an error
+^^: The above should be ~= 40 + cost(select * from t1). Value less than 40 is an error
+set @@optimizer_cache_hit_ratio=default;
drop table t1, t2;
CREATE TABLE t1 (a INT PRIMARY KEY, b INT);
CREATE TABLE t2 (c INT PRIMARY KEY, d INT);
@@ -1274,20 +1276,24 @@ test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
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 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;
pk v pk v
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 0
-Handler_read_key 14
+Handler_read_key 0
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 1
+Handler_read_rnd_next 4
DROP TABLE t1, t2;
End of 5.1 tests
#
@@ -1473,8 +1479,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 DSA ref PRIMARY PRIMARY 4 const 3 Using where; Using index
-1 SIMPLE DT ALL t_id NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
+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
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 88f30540589..a3756af023a 100644
--- a/mysql-test/main/join.test
+++ b/mysql-test/main/join.test
@@ -697,12 +697,11 @@ 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;
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 ~= 20 + cost(select * from t1). Value less than 20 is an error' Z;
-
-
-
+select '^^: The above should be ~= 40 + cost(select * from t1). Value less than 40 is an error' Z;
+set @@optimizer_cache_hit_ratio=default;
drop table t1, t2;
#
@@ -957,6 +956,9 @@ INSERT INTO t1 VALUES (3,'b'),(4,NULL),(5,'c'),(6,'cc'),(7,'d'),
(8,'dd'),(9,'e'),(10,'ee');
INSERT INTO t2 VALUES (2,NULL);
ANALYZE TABLE t1,t2;
+# This will ensure that status tables are read now and not part of the later
+# Handler_read% counts
+explain SELECT * FROM t1 JOIN t2 ON t1.v = t2.v WHERE t2.v IS NULL ORDER BY 1;
FLUSH STATUS;
SELECT * FROM t1 JOIN t2 ON t1.v = t2.v WHERE t2.v IS NULL ORDER BY 1;
SHOW STATUS LIKE 'Handler_read_%';
diff --git a/mysql-test/main/join_cache.result b/mysql-test/main/join_cache.result
index 3c9d1f020b9..fe40178a8da 100644
--- a/mysql-test/main/join_cache.result
+++ b/mysql-test/main/join_cache.result
@@ -53,6 +53,7 @@ set join_cache_level=1;
show variables like 'join_cache_level';
Variable_name Value
join_cache_level 1
+# Query 1
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
@@ -60,6 +61,7 @@ Country.Name LIKE 'L%' AND City.Population > 100000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where; Using join buffer (flat, BNL join)
+# Query 2
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
@@ -79,6 +81,7 @@ Tripoli Lebanon
Tripoli Libyan Arab Jamahiriya
Vientiane Laos
Vilnius Lithuania
+# Query 3
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -91,6 +94,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE CountryLanguage ALL NULL NULL NULL NULL 984 Using where; Using join buffer (flat, BNL join)
1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where; Using join buffer (flat, BNL join)
+# Query 4
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
@@ -131,6 +135,7 @@ set join_cache_level=2;
show variables like 'join_cache_level';
Variable_name Value
join_cache_level 2
+# join_cache_level 2, Query 1
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
@@ -138,6 +143,7 @@ Country.Name LIKE 'L%' AND City.Population > 100000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where; Using join buffer (flat, BNL join)
+# join_cache_level 2, Query 2
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
@@ -157,6 +163,7 @@ Tripoli Lebanon
Tripoli Libyan Arab Jamahiriya
Vientiane Laos
Vilnius Lithuania
+# join_cache_level 2, Query 3
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -169,6 +176,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE CountryLanguage ALL NULL NULL NULL NULL 984 Using where; Using join buffer (flat, BNL join)
1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where; Using join buffer (incremental, BNL join)
+# join_cache_level 2, Query 4
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
@@ -209,6 +217,7 @@ set join_cache_level=3;
show variables like 'join_cache_level';
Variable_name Value
join_cache_level 3
+# join_cache_level 3, Query 1
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
@@ -216,6 +225,7 @@ Country.Name LIKE 'L%' AND City.Population > 100000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE City hash_ALL NULL #hash#$hj 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join)
+# join_cache_level 3, Query 2
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
@@ -235,6 +245,7 @@ Tripoli Lebanon
Tripoli Libyan Arab Jamahiriya
Vientiane Laos
Vilnius Lithuania
+# join_cache_level 3, Query 3
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -247,6 +258,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE CountryLanguage hash_ALL NULL #hash#$hj 3 world.Country.Code 984 Using where; Using join buffer (flat, BNLH join)
1 SIMPLE City hash_ALL NULL #hash#$hj 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join)
+# join_cache_level 3, Query 4
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
@@ -287,6 +299,7 @@ set join_cache_level=4;
show variables like 'join_cache_level';
Variable_name Value
join_cache_level 4
+# join_cache_level 4, Query 1
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
@@ -294,6 +307,7 @@ Country.Name LIKE 'L%' AND City.Population > 100000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE City hash_ALL NULL #hash#$hj 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join)
+# join_cache_level 4, Query 2
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
@@ -313,6 +327,7 @@ Tripoli Lebanon
Tripoli Libyan Arab Jamahiriya
Vientiane Laos
Vilnius Lithuania
+# join_cache_level 4, Query 3
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -325,6 +340,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE CountryLanguage hash_ALL NULL #hash#$hj 3 world.Country.Code 984 Using where; Using join buffer (flat, BNLH join)
1 SIMPLE City hash_ALL NULL #hash#$hj 3 world.Country.Code 4079 Using where; Using join buffer (incremental, BNLH join)
+# join_cache_level 4, Query 4
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
@@ -361,6 +377,7 @@ Ludwigshafen am Rhein Germany German
Lungtan Taiwan Min
L´Hospitalet de Llobregat Spain Spanish
Lázaro Cárdenas Mexico Spanish
+# join_cache_level 4, Query 5
SELECT Country.Name, Country.Population, City.Name, City.Population
FROM Country LEFT JOIN City
ON City.Country=Country.Code AND City.Population > 5000000
@@ -379,6 +396,7 @@ Canada 31147000 NULL NULL
Cuba 11201000 NULL NULL
Côte d?Ivoire 14786000 NULL NULL
Czech Republic 10278100 NULL NULL
+# join_cache_level 4, Query 6
SELECT Country.Name, Country.Population, City.Name, City.Population
FROM Country LEFT JOIN City
ON City.Country=Country.Code AND
@@ -404,6 +422,7 @@ Czech Republic 10278100 NULL NULL
CREATE INDEX City_Population ON City(Population);
CREATE INDEX City_Name ON City(Name);
ANALYZE TABLE City;
+# After Analyze, Query 1
EXPLAIN
SELECT Country.Name, Country.Population, City.Name, City.Population
FROM Country LEFT JOIN City
@@ -412,6 +431,7 @@ WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE City hash_range City_Population #hash#$hj:City_Population 3:4 world.Country.Code 24 Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join)
+# After Analyze, Query 2
SELECT Country.Name, Country.Population, City.Name, City.Population
FROM Country LEFT JOIN City
ON City.Country=Country.Code AND City.Population > 5000000
@@ -430,6 +450,7 @@ Canada 31147000 NULL NULL
Cuba 11201000 NULL NULL
Côte d?Ivoire 14786000 NULL NULL
Czech Republic 10278100 NULL NULL
+# After Analyze, Query 3
EXPLAIN
SELECT Country.Name, Country.Population, City.Name, City.Population
FROM Country LEFT JOIN City
@@ -439,6 +460,7 @@ WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE City hash_index_merge City_Population,City_Name #hash#$hj:City_Population,City_Name 3:4,35 world.Country.Code 96 Using sort_union(City_Population,City_Name); Using where; Using join buffer (flat, BNLH join)
+# After Analyze, Query 4
SELECT Country.Name, Country.Population, City.Name, City.Population
FROM Country LEFT JOIN City
ON City.Country=Country.Code AND
@@ -471,6 +493,7 @@ join_buffer_size 256
show variables like 'join_cache_level';
Variable_name Value
join_cache_level 1
+# join_cache_level 1, Join_buffer_size, Query 1
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
@@ -478,6 +501,7 @@ Country.Name LIKE 'L%' AND City.Population > 100000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where; Using join buffer (flat, BNL join)
+# join_cache_level 1, Join_buffer_size, Query 2
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
@@ -497,6 +521,7 @@ Tripoli Lebanon
Tripoli Libyan Arab Jamahiriya
Vientiane Laos
Vilnius Lithuania
+# join_cache_level 1, Join_buffer_size, Query 3
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -509,6 +534,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE CountryLanguage ALL NULL NULL NULL NULL 984 Using where; Using join buffer (flat, BNL join)
1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where; Using join buffer (flat, BNL join)
+# join_cache_level 1, Join_buffer_size, Query 4
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
@@ -549,6 +575,7 @@ set join_cache_level=2;
show variables like 'join_cache_level';
Variable_name Value
join_cache_level 2
+# join_cache_level 2, Join_buffer_size, Query 1
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
@@ -556,6 +583,7 @@ Country.Name LIKE 'L%' AND City.Population > 100000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where; Using join buffer (flat, BNL join)
+# join_cache_level 2, Join_buffer_size, Query 2
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
@@ -575,6 +603,7 @@ Tripoli Lebanon
Tripoli Libyan Arab Jamahiriya
Vientiane Laos
Vilnius Lithuania
+# join_cache_level 2, Join_buffer_size, Query 3
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -587,6 +616,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE CountryLanguage ALL NULL NULL NULL NULL 984 Using where; Using join buffer (flat, BNL join)
1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where; Using join buffer (incremental, BNL join)
+# join_cache_level 2, Join_buffer_size, Query 4
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
@@ -627,6 +657,7 @@ set join_cache_level=3;
show variables like 'join_cache_level';
Variable_name Value
join_cache_level 3
+# join_cache_level 3, Join_buffer_size, Query 1
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
@@ -634,6 +665,7 @@ Country.Name LIKE 'L%' AND City.Population > 100000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE City hash_ALL NULL #hash#$hj 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join)
+# join_cache_level 3, Join_buffer_size, Query 2
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
@@ -653,6 +685,7 @@ Tripoli Lebanon
Tripoli Libyan Arab Jamahiriya
Vientiane Laos
Vilnius Lithuania
+# join_cache_level 3, Join_buffer_size, Query 3
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -665,6 +698,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE CountryLanguage hash_ALL NULL #hash#$hj 3 world.Country.Code 984 Using where; Using join buffer (flat, BNLH join)
1 SIMPLE City hash_ALL NULL #hash#$hj 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join)
+# join_cache_level 3, Join_buffer_size, Query 4
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
@@ -705,6 +739,7 @@ set join_cache_level=4;
show variables like 'join_cache_level';
Variable_name Value
join_cache_level 4
+# join_cache_level 4, Join_buffer_size, Query 1
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
@@ -712,6 +747,7 @@ Country.Name LIKE 'L%' AND City.Population > 100000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE City hash_ALL NULL #hash#$hj 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join)
+# join_cache_level 4, Join_buffer_size, Query 2
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
@@ -731,6 +767,7 @@ Tripoli Lebanon
Tripoli Libyan Arab Jamahiriya
Vientiane Laos
Vilnius Lithuania
+# join_cache_level 4, Join_buffer_size, Query 3
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -743,6 +780,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE CountryLanguage hash_ALL NULL #hash#$hj 3 world.Country.Code 984 Using where; Using join buffer (flat, BNLH join)
1 SIMPLE City hash_ALL NULL #hash#$hj 3 world.Country.Code 4079 Using where; Using join buffer (incremental, BNLH join)
+# join_cache_level 4, Join_buffer_size, Query 4
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
@@ -816,6 +854,7 @@ set join_cache_level=3;
show variables like 'join_cache_level';
Variable_name Value
join_cache_level 3
+# Part 2, join_cache_level=3, Query 1
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
@@ -823,6 +862,7 @@ Country.Name LIKE 'L%' AND City.Population > 100000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country range PRIMARY,Name Name 52 NULL 10 Using index condition; Rowid-ordered scan
1 SIMPLE City hash_ALL Population,Country #hash#Country 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join)
+# Part 2, join_cache_level=3, Query 2
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
@@ -842,6 +882,7 @@ Tripoli Lebanon
Tripoli Libyan Arab Jamahiriya
Vientiane Laos
Vilnius Lithuania
+# Part 2, join_cache_level=3, Query 3
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -853,7 +894,8 @@ 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_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
+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)
+# Part 2, join_cache_level=3, Query 4
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
@@ -890,6 +932,7 @@ Ludwigshafen am Rhein Germany German
Lungtan Taiwan Min
L´Hospitalet de Llobregat Spain Spanish
Lázaro Cárdenas Mexico Spanish
+# Part 2, join_cache_level=3, Query 5
EXPLAIN
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
@@ -897,6 +940,7 @@ City.Population > 100000;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY Country range PRIMARY,Name Name 52 NULL 10 Using index condition; Rowid-ordered scan
1 PRIMARY City hash_ALL Population,Country #hash#Country 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join)
+# Part 2, join_cache_level=3, Query 6
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
City.Population > 100000;
@@ -916,6 +960,7 @@ Kaunas
Klaipeda
?iauliai
Panevezys
+# Part 2, join_cache_level=3, Query 7
EXPLAIN
SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
FROM Country LEFT JOIN CountryLanguage ON
@@ -925,6 +970,7 @@ Country.Population > 10000000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE CountryLanguage hash_ALL PRIMARY #hash#PRIMARY 33 world.Country.Code,const 984 Using where; Using join buffer (flat, BNLH join)
+# Part 2, join_cache_level=3, Query 8
SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
FROM Country LEFT JOIN CountryLanguage ON
(CountryLanguage.Country=Country.Code AND Language='English')
@@ -1016,6 +1062,7 @@ set join_cache_level=4;
show variables like 'join_cache_level';
Variable_name Value
join_cache_level 4
+# Part 2, join_cache_level=4, Query 1
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
@@ -1023,6 +1070,7 @@ Country.Name LIKE 'L%' AND City.Population > 100000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country range PRIMARY,Name Name 52 NULL 10 Using index condition; Rowid-ordered scan
1 SIMPLE City hash_ALL Population,Country #hash#Country 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join)
+# Part 2, join_cache_level=4, Query 2
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
@@ -1042,6 +1090,7 @@ Tripoli Lebanon
Tripoli Libyan Arab Jamahiriya
Vientiane Laos
Vilnius Lithuania
+# Part 2, join_cache_level=4, Query 3
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -1053,7 +1102,8 @@ 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_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
+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)
+# Part 2, join_cache_level=4, Query 4
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
@@ -1090,6 +1140,7 @@ Ludwigshafen am Rhein Germany German
Lungtan Taiwan Min
L´Hospitalet de Llobregat Spain Spanish
Lázaro Cárdenas Mexico Spanish
+# Part 2, join_cache_level=4, Query 5
EXPLAIN
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
@@ -1097,6 +1148,7 @@ City.Population > 100000;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY Country range PRIMARY,Name Name 52 NULL 10 Using index condition; Rowid-ordered scan
1 PRIMARY City hash_ALL Population,Country #hash#Country 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join)
+# Part 2, join_cache_level=4, Query 6
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
City.Population > 100000;
@@ -1116,6 +1168,7 @@ Kaunas
Klaipeda
?iauliai
Panevezys
+# Part 2, join_cache_level=4, Query 7
EXPLAIN
SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
FROM Country LEFT JOIN CountryLanguage ON
@@ -1125,6 +1178,7 @@ Country.Population > 10000000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE CountryLanguage hash_ALL PRIMARY #hash#PRIMARY 33 world.Country.Code,const 984 Using where; Using join buffer (flat, BNLH join)
+# Part 2, join_cache_level=4, Query 8
SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
FROM Country LEFT JOIN CountryLanguage ON
(CountryLanguage.Country=Country.Code AND Language='English')
@@ -1209,6 +1263,7 @@ Belarus NULL
Venezuela NULL
Russian Federation NULL
Vietnam NULL
+# Part 2, join_cache_level=4, Query 9
EXPLAIN
SELECT Country.Name, Country.Population, City.Name, City.Population
FROM Country LEFT JOIN City
@@ -1217,6 +1272,7 @@ WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country range Name Name 52 NULL # Using index condition; Using where; Rowid-ordered scan
1 SIMPLE City hash_range Population,Country #hash#Country:Population 3:4 world.Country.Code # Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join)
+# Part 2, join_cache_level=4, Query 10
SELECT Country.Name, Country.Population, City.Name, City.Population
FROM Country LEFT JOIN City
ON City.Country=Country.Code AND City.Population > 5000000
@@ -1236,6 +1292,7 @@ Cuba 11201000 NULL NULL
Côte d?Ivoire 14786000 NULL NULL
Czech Republic 10278100 NULL NULL
CREATE INDEX City_Name ON City(Name);
+# Part 2, join_cache_level=4, City_Name, Query 1
EXPLAIN
SELECT Country.Name, Country.Population, City.Name, City.Population
FROM Country LEFT JOIN City
@@ -1245,6 +1302,7 @@ WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country range Name Name 52 NULL 17 Using index condition; Using where; Rowid-ordered scan
1 SIMPLE City hash_index_merge Population,Country,City_Name #hash#Country:Population,City_Name 3:4,35 world.Country.Code 96 Using sort_union(Population,City_Name); Using where; Using join buffer (flat, BNLH join)
+# Part 2, join_cache_level=4, City_Name, Query 2
SELECT Country.Name, Country.Population, City.Name, City.Population
FROM Country LEFT JOIN City
ON City.Country=Country.Code AND
@@ -2104,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_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
+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)
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
@@ -2208,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_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
+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)
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
@@ -3075,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 ref t1_affiliateid,t1_metaid t1_affiliateid 4 const 2 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)
SELECT t1.uniquekey, t1.xml AS affiliateXml,
t8.name AS artistName, t8.artistid,
t11.name AS genreName, t11.genreid, t11.priority AS genrePriority,
@@ -3191,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 range idx idx 5 NULL 3 Using index condition; Using where; Rowid-ordered scan
+1 SIMPLE t1 ALL idx NULL NULL NULL 7 Using where
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
@@ -3371,8 +3429,8 @@ set join_cache_level=6;
set join_buffer_size=1024;
EXPLAIN SELECT AVG(c) FROM t1,t2 WHERE t1.a=t2.b;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ALL NULL NULL NULL NULL 2050 Using where
-1 SIMPLE t2 ref idx idx 5 test.t1.a 640 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
+1 SIMPLE t2 ALL idx NULL NULL NULL 1280 Using where
+1 SIMPLE t1 hash_ALL NULL #hash#$hj 5 test.t2.b 2050 Using where; Using join buffer (flat, BNLH join)
SELECT AVG(c) FROM t1,t2 WHERE t1.a=t2.b;
AVG(c)
5.0000
@@ -4969,8 +5027,8 @@ FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.a2 = t3.a3) ON t2.b2 = t1.a1)
LEFT JOIN t4 ON t4.a4 <> 0) LEFT JOIN t5 ON t5.a5 = t2.a2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2
-1 SIMPLE t2 ALL PRIMARY NULL NULL NULL 1 Using where
-1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.a2 1 Using index
+1 SIMPLE t3 index PRIMARY PRIMARY 4 NULL 1 Using where; Using index
+1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t3.a3 1 Using where
1 SIMPLE t4 ALL NULL NULL NULL NULL 1 Using where
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t2.a2 1 Using where
SELECT t4.a4, t5.b5
@@ -5054,13 +5112,15 @@ CREATE TABLE t2 (
f3 int(11), f2 varchar(1024), f4 varchar(10), PRIMARY KEY (f3)
);
INSERT INTO t2 VALUES (6,'RPOYT','y'),(10,'JINQE','m');
+INSERT INTO t2 VALUES (100,'Q','q'),(101,'Q','q'),(102,'Q','q'),(103,'Q','q');
+INSERT INTO t2 VALUES (104,'Q','q'),(105,'Q','q'),(106,'Q','q'),(107,'Q','q');
SET SESSION join_cache_level = 1;
SET SESSION optimizer_switch = 'index_condition_pushdown=off';
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 range PRIMARY PRIMARY 4 NULL 2 Using where; Rowid-ordered scan
+1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 2 Using where
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);
@@ -5070,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 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Rowid-ordered scan
+1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 2 Using where
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);
@@ -5523,7 +5583,7 @@ and t2.uid=t1.fid;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 ref uid uid 5 const 4 Using where; Start temporary
1 PRIMARY t4 eq_ref PRIMARY PRIMARY 4 test.t3.fid 1 Using index
-1 PRIMARY t1 ALL uid NULL NULL NULL 11 Using where; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t1 ref uid uid 5 test.t3.fid 2 Using where; End temporary; Using join buffer (flat, BKAH join); Rowid-ordered scan
1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.fid 1 Using join buffer (flat, BKAH join); Rowid-ordered scan
select name from t2, t1
where t1.uid in (select t4.uid from t4, t3 where t3.uid=1 and t4.uid=t3.fid)
@@ -6150,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 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)
+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)
drop table t1,t2;
set join_cache_level=@save_join_cache_level;
#
@@ -6198,7 +6258,7 @@ EXPLAIN
{
"table": {
"table_name": "a",
- "access_type": "range",
+ "access_type": "index",
"possible_keys": ["PRIMARY"],
"key": "PRIMARY",
"key_length": "4",
diff --git a/mysql-test/main/join_cache.test b/mysql-test/main/join_cache.test
index 125ae84c309..c4401997b1d 100644
--- a/mysql-test/main/join_cache.test
+++ b/mysql-test/main/join_cache.test
@@ -6,6 +6,7 @@
DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11;
DROP DATABASE IF EXISTS world;
--enable_warnings
+--source include/have_innodb.inc
set @org_optimizer_switch=@@optimizer_switch;
set @save_join_cache_level=@@join_cache_level;
@@ -53,16 +54,19 @@ set join_cache_level=1;
show variables like 'join_cache_level';
+--echo # Query 1
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
+--echo # Query 2
--sorted_result
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
+--echo # Query 3
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -72,6 +76,7 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
CountryLanguage.Percentage > 50 AND
LENGTH(Language) < LENGTH(City.Name) - 2;
+--echo # Query 4
--sorted_result
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -84,16 +89,19 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
set join_cache_level=2;
show variables like 'join_cache_level';
+--echo # join_cache_level 2, Query 1
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
+--echo # join_cache_level 2, Query 2
--sorted_result
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
+--echo # join_cache_level 2, Query 3
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -103,6 +111,7 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
CountryLanguage.Percentage > 50 AND
LENGTH(Language) < LENGTH(City.Name) - 2;
+--echo # join_cache_level 2, Query 4
--sorted_result
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -115,16 +124,19 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
set join_cache_level=3;
show variables like 'join_cache_level';
+--echo # join_cache_level 3, Query 1
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
+--echo # join_cache_level 3, Query 2
--sorted_result
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
+--echo # join_cache_level 3, Query 3
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -134,7 +146,7 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
CountryLanguage.Percentage > 50 AND
LENGTH(Language) < LENGTH(City.Name) - 2;
-
+--echo # join_cache_level 3, Query 4
--sorted_result
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -148,16 +160,19 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
set join_cache_level=4;
show variables like 'join_cache_level';
+--echo # join_cache_level 4, Query 1
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
+--echo # join_cache_level 4, Query 2
--sorted_result
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
+--echo # join_cache_level 4, Query 3
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -167,6 +182,7 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
CountryLanguage.Percentage > 50 AND
LENGTH(Language) < LENGTH(City.Name) - 2;
+--echo # join_cache_level 4, Query 4
--sorted_result
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -177,11 +193,13 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
LENGTH(Language) < LENGTH(City.Name) - 2;
+--echo # join_cache_level 4, Query 5
SELECT Country.Name, Country.Population, City.Name, City.Population
FROM Country LEFT JOIN City
ON City.Country=Country.Code AND City.Population > 5000000
WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
+--echo # join_cache_level 4, Query 6
SELECT Country.Name, Country.Population, City.Name, City.Population
FROM Country LEFT JOIN City
ON City.Country=Country.Code AND
@@ -195,17 +213,20 @@ CREATE INDEX City_Name ON City(Name);
ANALYZE TABLE City;
--enable_result_log
+--echo # After Analyze, Query 1
EXPLAIN
SELECT Country.Name, Country.Population, City.Name, City.Population
FROM Country LEFT JOIN City
ON City.Country=Country.Code AND City.Population > 5000000
WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
+--echo # After Analyze, Query 2
SELECT Country.Name, Country.Population, City.Name, City.Population
FROM Country LEFT JOIN City
ON City.Country=Country.Code AND City.Population > 5000000
WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
+--echo # After Analyze, Query 3
EXPLAIN
SELECT Country.Name, Country.Population, City.Name, City.Population
FROM Country LEFT JOIN City
@@ -213,6 +234,7 @@ SELECT Country.Name, Country.Population, City.Name, City.Population
(City.Population > 5000000 OR City.Name LIKE 'Za%')
WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
+--echo # After Analyze, Query 4
SELECT Country.Name, Country.Population, City.Name, City.Population
FROM Country LEFT JOIN City
ON City.Country=Country.Code AND
@@ -229,16 +251,19 @@ show variables like 'join_buffer_size';
show variables like 'join_cache_level';
+--echo # join_cache_level 1, Join_buffer_size, Query 1
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
+--echo # join_cache_level 1, Join_buffer_size, Query 2
--sorted_result
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
+--echo # join_cache_level 1, Join_buffer_size, Query 3
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -248,6 +273,7 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
CountryLanguage.Percentage > 50 AND
LENGTH(Language) < LENGTH(City.Name) - 2;
+--echo # join_cache_level 1, Join_buffer_size, Query 4
--sorted_result
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -260,16 +286,19 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
set join_cache_level=2;
show variables like 'join_cache_level';
+--echo # join_cache_level 2, Join_buffer_size, Query 1
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
+--echo # join_cache_level 2, Join_buffer_size, Query 2
--sorted_result
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
+--echo # join_cache_level 2, Join_buffer_size, Query 3
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -279,6 +308,7 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
CountryLanguage.Percentage > 50 AND
LENGTH(Language) < LENGTH(City.Name) - 2;
+--echo # join_cache_level 2, Join_buffer_size, Query 4
--sorted_result
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -291,16 +321,19 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
set join_cache_level=3;
show variables like 'join_cache_level';
+--echo # join_cache_level 3, Join_buffer_size, Query 1
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
+--echo # join_cache_level 3, Join_buffer_size, Query 2
--sorted_result
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
+--echo # join_cache_level 3, Join_buffer_size, Query 3
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -310,6 +343,7 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
CountryLanguage.Percentage > 50 AND
LENGTH(Language) < LENGTH(City.Name) - 2;
+--echo # join_cache_level 3, Join_buffer_size, Query 4
--sorted_result
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -322,16 +356,19 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
set join_cache_level=4;
show variables like 'join_cache_level';
+--echo # join_cache_level 4, Join_buffer_size, Query 1
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
+--echo # join_cache_level 4, Join_buffer_size, Query 2
--sorted_result
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
+--echo # join_cache_level 4, Join_buffer_size, Query 3
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -341,6 +378,7 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
CountryLanguage.Percentage > 50 AND
LENGTH(Language) < LENGTH(City.Name) - 2;
+--echo # join_cache_level 4, Join_buffer_size, Query 4
--sorted_result
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -374,16 +412,19 @@ show variables like 'join_buffer_size';
set join_cache_level=3;
show variables like 'join_cache_level';
+--echo # Part 2, join_cache_level=3, Query 1
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
+--echo # Part 2, join_cache_level=3, Query 2
--sorted_result
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
+--echo # Part 2, join_cache_level=3, Query 3
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -393,6 +434,7 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
CountryLanguage.Percentage > 50 AND
LENGTH(Language) < LENGTH(City.Name) - 2;
+--echo # Part 2, join_cache_level=3, Query 4
--sorted_result
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -402,15 +444,18 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
CountryLanguage.Percentage > 50 AND
LENGTH(Language) < LENGTH(City.Name) - 2;
+--echo # Part 2, join_cache_level=3, Query 5
EXPLAIN
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
City.Population > 100000;
+--echo # Part 2, join_cache_level=3, Query 6
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
City.Population > 100000;
+--echo # Part 2, join_cache_level=3, Query 7
#enable after fix MDEV-27871
--disable_view_protocol
@@ -421,6 +466,7 @@ SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.P
WHERE
Country.Population > 10000000;
+--echo # Part 2, join_cache_level=3, Query 8
SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
FROM Country LEFT JOIN CountryLanguage ON
(CountryLanguage.Country=Country.Code AND Language='English')
@@ -433,16 +479,19 @@ show variables like 'join_buffer_size';
set join_cache_level=4;
show variables like 'join_cache_level';
+--echo # Part 2, join_cache_level=4, Query 1
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
+--echo # Part 2, join_cache_level=4, Query 2
--sorted_result
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
+--echo # Part 2, join_cache_level=4, Query 3
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -452,6 +501,7 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
CountryLanguage.Percentage > 50 AND
LENGTH(Language) < LENGTH(City.Name) - 2;
+--echo # Part 2, join_cache_level=4, Query 4
--sorted_result
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
@@ -461,15 +511,18 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
CountryLanguage.Percentage > 50 AND
LENGTH(Language) < LENGTH(City.Name) - 2;
+--echo # Part 2, join_cache_level=4, Query 5
EXPLAIN
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
City.Population > 100000;
+--echo # Part 2, join_cache_level=4, Query 6
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
City.Population > 100000;
+--echo # Part 2, join_cache_level=4, Query 7
#enable after fix MDEV-27871
--disable_view_protocol
@@ -480,6 +533,7 @@ SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.P
WHERE
Country.Population > 10000000;
+--echo # Part 2, join_cache_level=4, Query 8
SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
FROM Country LEFT JOIN CountryLanguage ON
(CountryLanguage.Country=Country.Code AND Language='English')
@@ -487,7 +541,7 @@ SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.P
Country.Population > 10000000;
--enable_view_protocol
-
+--echo # Part 2, join_cache_level=4, Query 9
--replace_column 9 #
EXPLAIN
SELECT Country.Name, Country.Population, City.Name, City.Population
@@ -495,6 +549,7 @@ SELECT Country.Name, Country.Population, City.Name, City.Population
ON City.Country=Country.Code AND City.Population > 5000000
WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
+--echo # Part 2, join_cache_level=4, Query 10
SELECT Country.Name, Country.Population, City.Name, City.Population
FROM Country LEFT JOIN City
ON City.Country=Country.Code AND City.Population > 5000000
@@ -502,6 +557,7 @@ SELECT Country.Name, Country.Population, City.Name, City.Population
CREATE INDEX City_Name ON City(Name);
+--echo # Part 2, join_cache_level=4, City_Name, Query 1
EXPLAIN
SELECT Country.Name, Country.Population, City.Name, City.Population
FROM Country LEFT JOIN City
@@ -509,6 +565,7 @@ SELECT Country.Name, Country.Population, City.Name, City.Population
(City.Population > 5000000 OR City.Name LIKE 'Za%')
WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
+--echo # Part 2, join_cache_level=4, City_Name, Query 2
SELECT Country.Name, Country.Population, City.Name, City.Population
FROM Country LEFT JOIN City
ON City.Country=Country.Code AND
@@ -3206,6 +3263,8 @@ CREATE TABLE t2 (
f3 int(11), f2 varchar(1024), f4 varchar(10), PRIMARY KEY (f3)
);
INSERT INTO t2 VALUES (6,'RPOYT','y'),(10,'JINQE','m');
+INSERT INTO t2 VALUES (100,'Q','q'),(101,'Q','q'),(102,'Q','q'),(103,'Q','q');
+INSERT INTO t2 VALUES (104,'Q','q'),(105,'Q','q'),(106,'Q','q'),(107,'Q','q');
SET SESSION join_cache_level = 1;
@@ -3808,8 +3867,6 @@ drop table t0,t1,t2;
--echo # of LEFT JOIN operations when using join buffer
--echo #
---source include/have_innodb.inc
-
CREATE TABLE t1 (
id int(11) NOT NULL AUTO_INCREMENT,
col1 varchar(255) NOT NULL DEFAULT '',
diff --git a/mysql-test/main/join_nested.result b/mysql-test/main/join_nested.result
index 741c3e4038e..1f8ffccf16b 100644
--- a/mysql-test/main/join_nested.result
+++ b/mysql-test/main/join_nested.result
@@ -695,21 +695,21 @@ t0.b=t1.b AND
(t9.a=1);
a b a b a b a b a b a b a b a b a b a b
1 2 2 2 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 1 1
-1 2 3 2 4 2 1 2 3 2 3 1 6 2 1 1 NULL NULL 1 1
-1 2 3 2 4 2 1 2 3 2 3 3 NULL NULL NULL NULL NULL NULL 1 1
-1 2 3 2 4 2 1 2 4 2 3 1 6 2 1 1 NULL NULL 1 1
-1 2 3 2 4 2 1 2 4 2 3 3 NULL NULL NULL NULL NULL NULL 1 1
-1 2 3 2 5 3 NULL NULL NULL NULL 3 1 6 2 1 1 NULL NULL 1 1
-1 2 3 2 5 3 NULL NULL NULL NULL 3 3 NULL NULL NULL NULL NULL NULL 1 1
1 2 2 2 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 1 2
-1 2 3 2 4 2 1 2 3 2 3 1 6 2 1 1 NULL NULL 1 2
1 2 3 2 4 2 1 2 3 2 2 2 6 2 2 2 0 2 1 2
+1 2 3 2 4 2 1 2 3 2 3 1 6 2 1 1 NULL NULL 1 1
+1 2 3 2 4 2 1 2 3 2 3 1 6 2 1 1 NULL NULL 1 2
+1 2 3 2 4 2 1 2 3 2 3 3 NULL NULL NULL NULL NULL NULL 1 1
1 2 3 2 4 2 1 2 3 2 3 3 NULL NULL NULL NULL NULL NULL 1 2
-1 2 3 2 4 2 1 2 4 2 3 1 6 2 1 1 NULL NULL 1 2
1 2 3 2 4 2 1 2 4 2 2 2 6 2 2 2 0 2 1 2
+1 2 3 2 4 2 1 2 4 2 3 1 6 2 1 1 NULL NULL 1 1
+1 2 3 2 4 2 1 2 4 2 3 1 6 2 1 1 NULL NULL 1 2
+1 2 3 2 4 2 1 2 4 2 3 3 NULL NULL NULL NULL NULL NULL 1 1
1 2 3 2 4 2 1 2 4 2 3 3 NULL NULL NULL NULL NULL NULL 1 2
-1 2 3 2 5 3 NULL NULL NULL NULL 3 1 6 2 1 1 NULL NULL 1 2
1 2 3 2 5 3 NULL NULL NULL NULL 2 2 6 2 2 2 0 2 1 2
+1 2 3 2 5 3 NULL NULL NULL NULL 3 1 6 2 1 1 NULL NULL 1 1
+1 2 3 2 5 3 NULL NULL NULL NULL 3 1 6 2 1 1 NULL NULL 1 2
+1 2 3 2 5 3 NULL NULL NULL NULL 3 3 NULL NULL NULL NULL NULL NULL 1 1
1 2 3 2 5 3 NULL NULL NULL NULL 3 3 NULL NULL NULL NULL NULL NULL 1 2
SELECT t1.a,t1.b
FROM t1;
@@ -1062,9 +1062,9 @@ 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 ref idx_a idx_a 5 const 2 100.00
+1 SIMPLE t0 ALL idx_a NULL NULL NULL 3 66.67 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 t1 ALL idx_b NULL NULL NULL 7 75.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t5 ALL idx_b NULL NULL NULL 7 100.00 Using where
1 SIMPLE t7 ALL NULL NULL NULL NULL 2 100.00 Using where
1 SIMPLE t6 ALL NULL NULL NULL NULL 3 100.00 Using where
@@ -1743,10 +1743,10 @@ LEFT JOIN
ON t4.carrier = t1.carrier;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index package_id package_id 5 NULL 45 Using where; Using index
+1 SIMPLE t3 ref package_id package_id 5 test.t2.package_id 1 Using index
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.package_id 1
1 SIMPLE t4 eq_ref PRIMARY,id PRIMARY 2 test.t1.carrier 1 Using where
1 SIMPLE t5 ref carrier_id carrier_id 5 test.t4.id 22 Using index
-1 SIMPLE t3 ref package_id package_id 5 test.t2.package_id 1 Using index
SELECT COUNT(*)
FROM ((t2 JOIN t1 ON t2.package_id = t1.id)
JOIN t3 ON t3.package_id = t1.id)
diff --git a/mysql-test/main/join_nested.test b/mysql-test/main/join_nested.test
index ed1fe4c9f7e..ee89c91e734 100644
--- a/mysql-test/main/join_nested.test
+++ b/mysql-test/main/join_nested.test
@@ -364,6 +364,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
SELECT t9.a,t9.b
FROM t9;
+--sorted_result
SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b,t9.a,t9.b
FROM t0,t1
diff --git a/mysql-test/main/join_nested_jcl6.result b/mysql-test/main/join_nested_jcl6.result
index 57bd6298b3b..c5386983ceb 100644
--- a/mysql-test/main/join_nested_jcl6.result
+++ b/mysql-test/main/join_nested_jcl6.result
@@ -652,6 +652,7 @@ 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)
@@ -659,9 +660,8 @@ 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`.`t9`.`b` = `test`.`t8`.`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`.`t8`.`b` = `test`.`t9`.`b` or `test`.`t8`.`c` is null)
SELECT t9.a,t9.b
FROM t9;
a b
@@ -703,23 +703,23 @@ t0.b=t1.b AND
(t8.b=t9.b OR t8.c IS NULL) AND
(t9.a=1);
a b a b a b a b a b a b a b a b a b a b
-1 2 3 2 4 2 1 2 3 2 3 1 6 2 1 1 NULL NULL 1 1
-1 2 3 2 4 2 1 2 4 2 3 1 6 2 1 1 NULL NULL 1 1
+1 2 2 2 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 1 1
+1 2 2 2 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 1 2
1 2 3 2 4 2 1 2 3 2 2 2 6 2 2 2 0 2 1 2
-1 2 3 2 4 2 1 2 4 2 2 2 6 2 2 2 0 2 1 2
+1 2 3 2 4 2 1 2 3 2 3 1 6 2 1 1 NULL NULL 1 1
1 2 3 2 4 2 1 2 3 2 3 1 6 2 1 1 NULL NULL 1 2
-1 2 3 2 4 2 1 2 4 2 3 1 6 2 1 1 NULL NULL 1 2
1 2 3 2 4 2 1 2 3 2 3 3 NULL NULL NULL NULL NULL NULL 1 1
-1 2 3 2 4 2 1 2 4 2 3 3 NULL NULL NULL NULL NULL NULL 1 1
1 2 3 2 4 2 1 2 3 2 3 3 NULL NULL NULL NULL NULL NULL 1 2
+1 2 3 2 4 2 1 2 4 2 2 2 6 2 2 2 0 2 1 2
+1 2 3 2 4 2 1 2 4 2 3 1 6 2 1 1 NULL NULL 1 1
+1 2 3 2 4 2 1 2 4 2 3 1 6 2 1 1 NULL NULL 1 2
+1 2 3 2 4 2 1 2 4 2 3 3 NULL NULL NULL NULL NULL NULL 1 1
1 2 3 2 4 2 1 2 4 2 3 3 NULL NULL NULL NULL NULL NULL 1 2
-1 2 3 2 5 3 NULL NULL NULL NULL 3 1 6 2 1 1 NULL NULL 1 1
1 2 3 2 5 3 NULL NULL NULL NULL 2 2 6 2 2 2 0 2 1 2
+1 2 3 2 5 3 NULL NULL NULL NULL 3 1 6 2 1 1 NULL NULL 1 1
1 2 3 2 5 3 NULL NULL NULL NULL 3 1 6 2 1 1 NULL NULL 1 2
1 2 3 2 5 3 NULL NULL NULL NULL 3 3 NULL NULL NULL NULL NULL NULL 1 1
1 2 3 2 5 3 NULL NULL NULL NULL 3 3 NULL NULL NULL NULL NULL NULL 1 2
-1 2 2 2 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 1 1
-1 2 2 2 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 1 2
SELECT t1.a,t1.b
FROM t1;
a b
@@ -920,6 +920,7 @@ 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)
@@ -927,9 +928,8 @@ 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`.`t9`.`b` = `test`.`t8`.`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`.`t8`.`b` = `test`.`t9`.`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,9 +1071,9 @@ 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 ref idx_a idx_a 5 const 2 100.00
-1 SIMPLE t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
-1 SIMPLE t1 ALL idx_b NULL NULL NULL 7 75.00 Using where; Using join buffer (incremental, BNL join)
+1 SIMPLE t0 ALL idx_a NULL NULL NULL 3 66.67 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)
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)
@@ -1752,10 +1752,10 @@ LEFT JOIN
ON t4.carrier = t1.carrier;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index package_id package_id 5 NULL 45 Using where; Using index
+1 SIMPLE t3 ref package_id package_id 5 test.t2.package_id 1 Using index
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.package_id 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
1 SIMPLE t4 eq_ref PRIMARY,id PRIMARY 2 test.t1.carrier 1 Using where
1 SIMPLE t5 ref carrier_id carrier_id 5 test.t4.id 22 Using index
-1 SIMPLE t3 ref package_id package_id 5 test.t2.package_id 1 Using index
SELECT COUNT(*)
FROM ((t2 JOIN t1 ON t2.package_id = t1.id)
JOIN t3 ON t3.package_id = t1.id)
@@ -2085,8 +2085,8 @@ ON t6.b >= 2 AND t5.b=t7.b AND
(t8.a > 0 OR t8.c IS NULL) AND t6.a>0 AND t7.a>0;
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 range PRIMARY,b_i PRIMARY 4 NULL 2 Using where; Rowid-ordered scan; Using join buffer (flat, 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 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 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
diff --git a/mysql-test/main/join_outer.result b/mysql-test/main/join_outer.result
index d6ab8c7dc9c..eb5bf0e1700 100644
--- a/mysql-test/main/join_outer.result
+++ b/mysql-test/main/join_outer.result
@@ -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<500, NULL, @a)
+IF(@a<450, 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 393 Using index condition
+1 SIMPLE t2 ref c c 5 const 312 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 ALL c NULL NULL NULL 1000 Using where
+1 SIMPLE t2 ref c c 5 const 312 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 5e1e83e4049..ac4207a720a 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<500, NULL, @a)
+ IF(@a<450, 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 809a980576d..5373dbc0bbc 100644
--- a/mysql-test/main/join_outer_innodb.result
+++ b/mysql-test/main/join_outer_innodb.result
@@ -437,6 +437,7 @@ 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 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 t5 eq_ref PRIMARY PRIMARY 4 test.t4.d1 1 Using where
@@ -453,12 +454,12 @@ id select_type table type possible_keys key key_len ref rows Extra
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 t16 ref PRIMARY PRIMARY 2 test.t15.o1 1 Using where
-1 SIMPLE t10 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
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 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 t5 eq_ref PRIMARY PRIMARY 4 test.t4.d1 1 Using where
@@ -475,7 +476,6 @@ id select_type table type possible_keys key key_len ref rows Extra
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 t16 ref PRIMARY PRIMARY 2 test.t15.o1 1 Using where
-1 SIMPLE t10 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
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 7f2f6ae96d4..5c88511b020 100644
--- a/mysql-test/main/join_outer_jcl6.result
+++ b/mysql-test/main/join_outer_jcl6.result
@@ -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<500, NULL, @a)
+IF(@a<450, 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 393 Using index condition
+1 SIMPLE t2 ref c c 5 const 312 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 ALL c NULL NULL NULL 1000 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t2 ref c c 5 const 312 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
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/key.result b/mysql-test/main/key.result
index 091e8e44b82..653e41f8e28 100644
--- a/mysql-test/main/key.result
+++ b/mysql-test/main/key.result
@@ -231,11 +231,14 @@ numeropost
1
EXPLAIN SELECT numeropost FROM t1 WHERE numreponse='1';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 const numreponse numreponse 4 const 1 Using index
+1 SIMPLE t1 const numreponse numreponse 4 const 1
FLUSH TABLES;
SELECT numeropost FROM t1 WHERE numreponse='1';
numeropost
1
+EXPLAIN SELECT numreponse+0 FROM t1 WHERE numreponse='1';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 const numreponse numreponse 4 const 1 Using index
drop table t1;
create table t1 (c varchar(30) character set utf8, t text character set utf8, unique (c(2)), unique (t(3))) engine=myisam;
show create table t1;
@@ -610,7 +613,7 @@ EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE
(SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12;
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 SUBQUERY t1 range a a 5 NULL 5 Using where; Using index
+2 SUBQUERY t1 range a a 5 NULL 2 Using where; Using index for group-by
SELECT 1 as RES FROM t1 AS t1_outer WHERE
(SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12;
RES
@@ -628,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 10.412184
+Last_query_cost 8.506592
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 10.412184
+Last_query_cost 8.506592
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 15.399000
+Last_query_cost 11.003515
DROP TABLE t1;
#
# MDEV-21480: Unique key using ref access though eq_ref access can be used
diff --git a/mysql-test/main/key.test b/mysql-test/main/key.test
index 29e08b8834a..c891194f1ad 100644
--- a/mysql-test/main/key.test
+++ b/mysql-test/main/key.test
@@ -227,9 +227,12 @@ drop table t1;
CREATE TABLE t1 (numeropost mediumint(8) unsigned NOT NULL default '0', numreponse int(10) unsigned NOT NULL auto_increment, PRIMARY KEY (numeropost,numreponse), UNIQUE KEY numreponse (numreponse));
INSERT INTO t1 (numeropost,numreponse) VALUES ('1','1'),('1','2'),('2','3'),('2','4');
SELECT numeropost FROM t1 WHERE numreponse='1';
+# No 'Using index'
EXPLAIN SELECT numeropost FROM t1 WHERE numreponse='1';
FLUSH TABLES;
SELECT numeropost FROM t1 WHERE numreponse='1';
+# This one will have 'Using index'
+EXPLAIN SELECT numreponse+0 FROM t1 WHERE numreponse='1';
drop table t1;
#
diff --git a/mysql-test/main/key_cache.result b/mysql-test/main/key_cache.result
index 4a5df2da65d..3edbac8c9ae 100644
--- a/mysql-test/main/key_cache.result
+++ b/mysql-test/main/key_cache.result
@@ -440,25 +440,25 @@ VARIABLE_NAME VARIABLE_VALUE
KEY_BLOCKS_NOT_FLUSHED 0
KEY_BLOCKS_USED 4
KEY_BLOCKS_WARM 0
-KEY_READ_REQUESTS 22
+KEY_READ_REQUESTS 21
KEY_READS 0
KEY_WRITE_REQUESTS 26
KEY_WRITES 6
select variable_value into @key_blocks_unused from information_schema.session_status where variable_name = 'Key_blocks_unused';
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 NULL NULL 2097152 1024 4 # 0 22 0 26 6
+default NULL NULL 2097152 1024 4 # 0 21 0 26 6
small NULL NULL 1048576 1024 1 # 0 1 0 2 1
delete from t2 where a='zzzz';
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 NULL NULL 2097152 1024 4 # 0 29 0 32 9
+default NULL NULL 2097152 1024 4 # 0 28 0 32 9
small NULL NULL 1048576 1024 1 # 0 1 0 2 1
delete from t1;
delete from t2;
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 NULL NULL 2097152 1024 4 # 0 29 0 32 9
+default NULL NULL 2097152 1024 4 # 0 28 0 32 9
small NULL NULL 1048576 1024 1 # 0 1 0 2 1
set global key_cache_segments=2;
select @@key_cache_segments;
@@ -488,7 +488,7 @@ VARIABLE_NAME VARIABLE_VALUE
KEY_BLOCKS_NOT_FLUSHED 0
KEY_BLOCKS_USED 4
KEY_BLOCKS_WARM 0
-KEY_READ_REQUESTS 22
+KEY_READ_REQUESTS 21
KEY_READS 0
KEY_WRITE_REQUESTS 26
KEY_WRITES 6
@@ -497,13 +497,13 @@ variable_value < @key_blocks_unused
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 2097152 1024 4 # 0 22 0 26 6
+default 2 NULL 2097152 1024 4 # 0 21 0 26 6
small NULL NULL 1048576 1024 1 # 0 1 0 2 1
delete from t1;
delete from t2;
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 2097152 1024 4 # 0 22 0 26 6
+default 2 NULL 2097152 1024 4 # 0 21 0 26 6
small NULL NULL 1048576 1024 1 # 0 1 0 2 1
set global key_cache_segments=1;
select @@key_cache_segments;
@@ -533,7 +533,7 @@ VARIABLE_NAME VARIABLE_VALUE
KEY_BLOCKS_NOT_FLUSHED 0
KEY_BLOCKS_USED 4
KEY_BLOCKS_WARM 0
-KEY_READ_REQUESTS 22
+KEY_READ_REQUESTS 21
KEY_READS 0
KEY_WRITE_REQUESTS 26
KEY_WRITES 6
@@ -542,13 +542,13 @@ variable_value = @key_blocks_unused
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 1 NULL 2097152 1024 4 # 0 22 0 26 6
+default 1 NULL 2097152 1024 4 # 0 21 0 26 6
small NULL NULL 1048576 1024 1 # 0 1 0 2 1
delete from t1;
delete from t2;
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 1 NULL 2097152 1024 4 # 0 22 0 26 6
+default 1 NULL 2097152 1024 4 # 0 21 0 26 6
small NULL NULL 1048576 1024 1 # 0 1 0 2 1
flush tables;
flush status;
@@ -586,7 +586,7 @@ update t1 set p=3 where p=1;
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 22 0 26 6
+default 2 NULL 32768 1024 4 # 0 21 0 26 6
small NULL NULL 1048576 1024 1 # 0 0 0 0 0
insert into t1(a) select a from t1;
insert into t1(a) select a from t1;
@@ -606,7 +606,7 @@ insert into t2(i,a) select i,a from t2;
insert into t2(i,a) select i,a from t2;
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 6733 # 3684 103
+default 2 NULL 32768 1024 # # 0 6732 # 3684 103
small NULL NULL 1048576 1024 # # 0 0 # 0 0
select * from t1 where p between 1010 and 1020 ;
p a
@@ -625,7 +625,7 @@ p i a
1020 3 zzzz
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 6750 # 3684 103
+default 2 NULL 32768 1024 # # 0 6749 # 3684 103
small NULL NULL 1048576 1024 # # 0 0 # 0 0
flush tables;
flush status;
@@ -699,7 +699,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 2082 25 1071 19
+keycache1 7 NULL 262143 2048 25 # 0 2114 25 1071 19
set global keycache2.key_buffer_size=1024*1024;
cache index t2 in keycache2;
Table Op Msg_type Msg_text
@@ -712,7 +712,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 2082 25 1071 19
+keycache1 7 NULL 262143 2048 25 # 0 2114 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 +753,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 3229 43 1594 30
+keycache1 7 NULL 262143 2048 # # 0 3277 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/limit_rows_examined.result b/mysql-test/main/limit_rows_examined.result
index f0a22b8f3f2..e87dd25cac9 100644
--- a/mysql-test/main/limit_rows_examined.result
+++ b/mysql-test/main/limit_rows_examined.result
@@ -255,7 +255,7 @@ 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 range PRIMARY PRIMARY 2 NULL 4 Using where; Using index
+1 PRIMARY t1i index 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 +395,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 range PRIMARY PRIMARY 2 NULL 4 Using where; Using index
+2 MATERIALIZED t2i index 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
diff --git a/mysql-test/main/long_unique.result b/mysql-test/main/long_unique.result
index 7f8110a283e..664c9e82ec6 100644
--- a/mysql-test/main/long_unique.result
+++ b/mysql-test/main/long_unique.result
@@ -1195,20 +1195,20 @@ ERROR 42S22: Unknown column 'DB_ROW_HASH_1' in 'IN/ALL/ANY subquery'
select DB_ROW_HASH_1, DB_ROW_HASH_2 from t1,t2 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t2);
DB_ROW_HASH_1 DB_ROW_HASH_2
11 1
-22 2
-33 3
-44 4
11 1
-22 2
-33 3
-44 4
11 1
-22 2
-33 3
-44 4
11 1
22 2
+22 2
+22 2
+22 2
+33 3
+33 3
33 3
+33 3
+44 4
+44 4
+44 4
44 4
select * from t2 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t1);
DB_ROW_HASH_1 DB_ROW_HASH_2
diff --git a/mysql-test/main/long_unique.test b/mysql-test/main/long_unique.test
index fa49b6a5ad4..3203675a7ad 100644
--- a/mysql-test/main/long_unique.test
+++ b/mysql-test/main/long_unique.test
@@ -389,6 +389,7 @@ select DB_ROW_HASH_1, DB_ROW_HASH_2 from t1;
select DB_ROW_HASH_1, DB_ROW_HASH_2 from t1,t2;
--error ER_BAD_FIELD_ERROR
select * from t1 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t2);
+--sorted_result
select DB_ROW_HASH_1, DB_ROW_HASH_2 from t1,t2 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t2);
select * from t2 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t1);
--error ER_BAD_FIELD_ERROR
diff --git a/mysql-test/main/multi_update.result b/mysql-test/main/multi_update.result
index 1af632a19c8..674dc79fe12 100644
--- a/mysql-test/main/multi_update.result
+++ b/mysql-test/main/multi_update.result
@@ -1092,8 +1092,8 @@ a b c a b c
set optimizer_switch='firstmatch=off';
explain update t1, t2 set t2.c=1 where t1.a=t2.a and t1.b in (select b from t3 where t3.c< t2.c) order by t2.c, t1.c limit 10;
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 ALL NULL NULL NULL NULL 10 Using temporary; Using filesort
-1 PRIMARY t1 ALL a NULL NULL NULL 10 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 10 Using where; Using temporary; Using filesort
+1 PRIMARY t1 ref a a 5 test.t2.a 1
1 PRIMARY t3 ALL NULL NULL NULL NULL 10 Using where; Start temporary; End temporary
update t1, t2 set t2.c=1 where t1.a=t2.a and t1.b in (select b from t3 where t3.c<=t2.c) order by t2.c, t1.c limit 5;
select * from t2;
diff --git a/mysql-test/main/myisam.result b/mysql-test/main/myisam.result
index 0b0099d7b84..cb163bb29ff 100644
--- a/mysql-test/main/myisam.result
+++ b/mysql-test/main/myisam.result
@@ -640,10 +640,14 @@ create table t1 ( a tinytext, b char(1), index idx (a(1),b) );
insert into t1 values (null,''), (null,'');
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
+1 SIMPLE t1 ALL idx NULL NULL NULL 2 Using where
select count(*) from t1 where a is null;
count(*)
2
+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
drop table t1;
create table t1 (c1 int, c2 varchar(4) not null default '',
key(c2(3))) default charset=utf8;
@@ -2532,6 +2536,7 @@ DROP TABLE t1, t2, t3;
#
# BUG#51307 - widespread corruption with partitions and insert...select
#
+call mtr.add_suppression("Enabling keys got errno 12 on test.t1, retrying");
CREATE TABLE t1(a CHAR(255), KEY(a));
SELECT * FROM t1, t1 AS a1;
a a
diff --git a/mysql-test/main/myisam.test b/mysql-test/main/myisam.test
index ec49e71bc2d..32b74027b14 100644
--- a/mysql-test/main/myisam.test
+++ b/mysql-test/main/myisam.test
@@ -593,6 +593,8 @@ create table t1 ( a tinytext, b char(1), index idx (a(1),b) );
insert into t1 values (null,''), (null,'');
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;
drop table t1;
#
@@ -1676,6 +1678,9 @@ DROP TABLE t1, t2, t3;
--echo #
--echo # BUG#51307 - widespread corruption with partitions and insert...select
--echo #
+
+call mtr.add_suppression("Enabling keys got errno 12 on test.t1, retrying");
+
CREATE TABLE t1(a CHAR(255), KEY(a));
SELECT * FROM t1, t1 AS a1;
SET myisam_sort_buffer_size=4;
diff --git a/mysql-test/main/myisam_explain_non_select_all.result b/mysql-test/main/myisam_explain_non_select_all.result
index 83e18f3906f..9b98dc77eb7 100644
--- a/mysql-test/main/myisam_explain_non_select_all.result
+++ b/mysql-test/main/myisam_explain_non_select_all.result
@@ -256,9 +256,8 @@ 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 t1 ALL NULL NULL NULL NULL 3 100.00
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 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
# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
@@ -268,8 +267,8 @@ Warnings:
Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead
# Status of "equivalent" SELECT query execution:
Variable_name Value
-Handler_read_key 5
-Handler_read_rnd_next 8
+Handler_read_key 4
+Handler_read_rnd_next 5
# Status of testing query execution:
Variable_name Value
Handler_read_key 4
@@ -342,16 +341,16 @@ Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be
EXPLAIN UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.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 <subquery2> eq_ref distinct_key distinct_key 4 func 1
1 PRIMARY t2 ALL NULL NULL NULL NULL 3
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 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);
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 <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 Using where
# Status of EXPLAIN EXTENDED query
Variable_name Value
@@ -361,8 +360,8 @@ FLUSH TABLES;
EXPLAIN EXTENDED SELECT * FROM t1, t2 WHERE a IN (SELECT b FROM t2 WHERE t2.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 <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 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
@@ -373,12 +372,12 @@ Warnings:
Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead
# Status of "equivalent" SELECT query execution:
Variable_name Value
-Handler_read_key 7
+Handler_read_key 13
Handler_read_rnd_next 12
# Status of testing query execution:
Variable_name Value
-Handler_read_key 7
-Handler_read_rnd_next 16
+Handler_read_key 9
+Handler_read_rnd_next 20
Handler_update 2
DROP TABLE t1, t2;
@@ -791,12 +790,12 @@ Warnings:
Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> 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 range PRIMARY PRIMARY 4 NULL 3 Using where
+1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 6 Using where; Using filesort
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 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where
+1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 6 100.00 Using where; Using filesort
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 3
@@ -819,8 +818,11 @@ Handler_read_next 3
# Status of testing query execution:
Variable_name Value
Handler_delete 3
-Handler_read_key 4
-Handler_read_next 3
+Handler_read_key 3
+Handler_read_rnd 3
+Handler_read_rnd_next 7
+Sort_rows 3
+Sort_scan 1
DROP TABLE t1;
#17
@@ -1494,12 +1496,12 @@ Warnings:
Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead
EXPLAIN DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ALL NULL NULL NULL NULL 26 Using where; Using filesort
+1 SIMPLE t2 index NULL a 15 NULL 5 Using where
FLUSH STATUS;
FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -1523,11 +1525,9 @@ Handler_read_next 26
# Status of testing query execution:
Variable_name Value
Handler_delete 1
+Handler_read_first 1
Handler_read_key 8
-Handler_read_rnd 1
-Handler_read_rnd_next 27
-Sort_rows 1
-Sort_scan 1
+Handler_read_next 26
DROP TABLE t1, t2;
#32
@@ -2009,12 +2009,12 @@ Warnings:
Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead
EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ALL NULL NULL NULL NULL 26 Using where; Using filesort
+1 SIMPLE t2 index NULL a 15 NULL 5 Using where; Using buffer
FLUSH STATUS;
FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort
+1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where; Using buffer
# Status of EXPLAIN EXTENDED query
Variable_name Value
Handler_read_key 8
@@ -2037,13 +2037,11 @@ Handler_read_key 8
Handler_read_next 26
# Status of testing query execution:
Variable_name Value
+Handler_read_first 1
Handler_read_key 8
+Handler_read_next 26
Handler_read_rnd 1
-Handler_read_rnd_next 27
Handler_update 1
-Sort_priority_queue_sorts 1
-Sort_rows 1
-Sort_scan 1
DROP TABLE t1, t2;
#42
diff --git a/mysql-test/main/myisam_icp.result b/mysql-test/main/myisam_icp.result
index 2bd9ac9ba95..5dfa61effef 100644
--- a/mysql-test/main/myisam_icp.result
+++ b/mysql-test/main/myisam_icp.result
@@ -407,7 +407,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|filter PRIMARY,k1 PRIMARY|k1 4|5 NULL 3 (50%) Using index condition; Using where; Rowid-ordered scan; Using filesort; Using rowid filter
+1 SIMPLE t1 range PRIMARY,k1 PRIMARY 4 NULL 3 Using index condition; Using where; Rowid-ordered scan; Using filesort
DROP TABLE t1;
#
#
@@ -429,8 +429,8 @@ 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);
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 t2 index NULL PRIMARY 4 NULL # Using index
2 DEPENDENT SUBQUERY it eq_ref PRIMARY PRIMARY 4 func # Using index condition
-2 DEPENDENT SUBQUERY t2 index NULL PRIMARY 4 NULL # Using index; 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
@@ -506,7 +506,7 @@ WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR
(t1.pk > 1 AND t2.pk BETWEEN 6 AND 6);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 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)
+1 SIMPLE t2 ALL PRIMARY NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1
WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR
(t1.pk > 1 AND t2.pk BETWEEN 6 AND 6);
@@ -922,7 +922,7 @@ DROP TABLE t1;
# Bug#870046: ICP for a GROUP BY query
#
CREATE TABLE t1 (a int, b varchar(1), c varchar(1), INDEX idx(b));
-INSERT INTO t1 VALUES (2,'x','x'), (5,'x','y');
+INSERT INTO t1 VALUES (2,'x','x'), (5,'x','y'), (6,'a','b'), (7,'a','b');
SET SESSION optimizer_switch='index_condition_pushdown=off';
EXPLAIN
SELECT a, MIN(c) FROM t1 WHERE b = 'x' AND c > 'x' GROUP BY a;
diff --git a/mysql-test/main/myisam_icp.test b/mysql-test/main/myisam_icp.test
index a115d0f7caa..7b4ff23b50e 100644
--- a/mysql-test/main/myisam_icp.test
+++ b/mysql-test/main/myisam_icp.test
@@ -215,7 +215,7 @@ DROP TABLE t1;
--echo #
CREATE TABLE t1 (a int, b varchar(1), c varchar(1), INDEX idx(b));
-INSERT INTO t1 VALUES (2,'x','x'), (5,'x','y');
+INSERT INTO t1 VALUES (2,'x','x'), (5,'x','y'), (6,'a','b'), (7,'a','b');
SET SESSION optimizer_switch='index_condition_pushdown=off';
EXPLAIN
diff --git a/mysql-test/main/mysqld--help.result b/mysql-test/main/mysqld--help.result
index 857e11d57ef..f5e1340feda 100644
--- a/mysql-test/main/mysqld--help.result
+++ b/mysql-test/main/mysqld--help.result
@@ -720,6 +720,11 @@ The following specify which files/extra groups are read (specified before remain
max_connections*5 or max_connections + table_cache*2
(whichever is larger) number of file descriptors
(Automatically configured unless set explicitly)
+ --optimizer-cache-hit-ratio=#
+ Expected hit rate of the row and index cache in storage
+ engines. The value should be an integer between 0 and 99,
+ where 0 means cache is empty and 99 means that value is
+ almost always in the cache
--optimizer-extra-pruning-depth=#
If the optimizer needs to enumerate join prefix of this
size or larger, then it will try agressively prune away
@@ -1698,6 +1703,7 @@ old-alter-table DEFAULT
old-mode UTF8_IS_UTF8MB3
old-passwords FALSE
old-style-user-limits FALSE
+optimizer-cache-hit-ratio 50
optimizer-extra-pruning-depth 8
optimizer-max-sel-arg-weight 32000
optimizer-prune-level 2
diff --git a/mysql-test/main/negation_elimination.result b/mysql-test/main/negation_elimination.result
index 7b9a76d86b2..0ad23e547b0 100644
--- a/mysql-test/main/negation_elimination.result
+++ b/mysql-test/main/negation_elimination.result
@@ -4,7 +4,7 @@ insert into t1 values (NULL), (0), (1), (2), (3), (4), (5), (6), (7), (8), (9),
(10), (11), (12), (13), (14), (15), (16), (17), (18), (19);
explain select * from t1 where not(not(a));
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range a a 5 NULL 20 Using where; Using index
+1 SIMPLE t1 index a a 5 NULL 21 Using where; Using index
select * from t1 where not(not(a));
a
1
@@ -55,7 +55,7 @@ a
10
explain select * from t1 where not(a = 10);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range a a 5 NULL 19 Using where; Using index
+1 SIMPLE t1 index a a 5 NULL 21 Using where; Using index
select * from t1 where not(a = 10);
a
0
@@ -500,7 +500,7 @@ NULL NULL
3 1
explain extended select a, not(not(a)), not(a <= 2 and not(a)), not(a not like "1"), not (a not in (1,2)), not(a != 2) from t1 where not(not(a)) having not(not(a));
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 range a a 5 NULL 4 100.00 Using where; Using index
+1 SIMPLE t1 index a a 5 NULL 5 80.00 Using where; Using index
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`a` <> 0 AS `not(not(a))`,`test`.`t1`.`a` > 2 or `test`.`t1`.`a` <> 0 AS `not(a <= 2 and not(a))`,`test`.`t1`.`a` like '1' AS `not(a not like "1")`,`test`.`t1`.`a` in (1,2) AS `not (a not in (1,2))`,`test`.`t1`.`a` = 2 AS `not(a != 2)` from `test`.`t1` where `test`.`t1`.`a` <> 0 having `test`.`t1`.`a` <> 0
drop table t1;
diff --git a/mysql-test/main/null_key.result b/mysql-test/main/null_key.result
index d59a1cd0a2e..572d7302b74 100644
--- a/mysql-test/main/null_key.result
+++ b/mysql-test/main/null_key.result
@@ -160,12 +160,12 @@ a b
7 NULL
explain select * from t1 where (a = 7 or a is null) and (b=7 or b is null);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range a,b a 10 NULL 4 Using where; Using index
+1 SIMPLE t1 ref_or_null a,b a 5 const 5 Using where; Using index
select * from t1 where (a = 7 or a is null) and (b=7 or b is null);
a b
-NULL 7
7 NULL
7 7
+NULL 7
explain select * from t1 where (a = 7 or a is null) and (a = 7 or a is null);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref_or_null a a 5 const 5 Using where; Using index
@@ -258,10 +258,11 @@ PRIMARY KEY (id)
) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL);
INSERT INTO t1 VALUES (11,5),(12,6),(13,7),(14,8),(15,9);
+INSERT INTO t1 VALUES (1000,1000),(1010,1010);
INSERT INTO t2 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL);
explain select id from t1 where uniq_id is null;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ALL idx1 NULL NULL NULL 15 Using where
+1 SIMPLE t1 ref idx1 idx1 5 const 6 Using index condition
explain select id from t1 where uniq_id =1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const idx1 idx1 5 const 1
@@ -285,6 +286,7 @@ id
110
DELETE FROM t1 WHERE uniq_id IS NULL;
DELETE FROM t2 WHERE uniq_id IS NULL;
+DELETE FROM t1 WHERE id >= 1000;
SELECT * FROM t1 ORDER BY uniq_id, id;
id uniq_id
3 1
diff --git a/mysql-test/main/null_key.test b/mysql-test/main/null_key.test
index 7eabd6d5dc3..65a93022a2e 100644
--- a/mysql-test/main/null_key.test
+++ b/mysql-test/main/null_key.test
@@ -104,6 +104,7 @@ CREATE TABLE t2 (
INSERT INTO t1 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL);
INSERT INTO t1 VALUES (11,5),(12,6),(13,7),(14,8),(15,9);
+INSERT INTO t1 VALUES (1000,1000),(1010,1010);
INSERT INTO t2 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL);
#
# Check IS NULL optimization
@@ -122,6 +123,12 @@ select id from t2 where uniq_id is null;
#
DELETE FROM t1 WHERE uniq_id IS NULL;
DELETE FROM t2 WHERE uniq_id IS NULL;
+
+#
+# Delete extra records that were used to force null optimization
+#
+DELETE FROM t1 WHERE id >= 1000;
+
#
# Select what is left -- notice the difference
#
diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result
index 331021b1948..1b0dec475eb 100644
--- a/mysql-test/main/opt_trace.result
+++ b/mysql-test/main/opt_trace.result
@@ -118,7 +118,8 @@ select * from v1 {
"table": "t1",
"table_scan": {
"rows": 2,
- "cost": 2.004394531
+ "read_cost": 1.002197266,
+ "read_and_compare_cost": 1.502197266
}
}
]
@@ -131,18 +132,24 @@ select * from v1 {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 1,
- "cost": 2.404394531,
+ "rows": 2,
+ "rows_after_scan": 1,
+ "rows_after_filter": 1,
+ "cost": 1.502197266,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 1,
- "cost": 2.404394531,
+ "cost": 1.502197266,
"uses_join_buffering": false
}
}
@@ -153,13 +160,14 @@ select * from v1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 1,
- "cost_for_plan": 2.604394531
+ "cost_for_plan": 1.502197266
}
]
},
{
"best_join_order": ["t1"],
- "cost": 2.603394531
+ "rows": 1,
+ "cost": 1.502197266
},
{
"substitute_best_equal": {
@@ -277,7 +285,8 @@ select * from (select * from t1 where t1.a=1)q {
"table": "t1",
"table_scan": {
"rows": 2,
- "cost": 2.004394531
+ "read_cost": 1.002197266,
+ "read_and_compare_cost": 1.502197266
}
}
]
@@ -290,18 +299,24 @@ select * from (select * from t1 where t1.a=1)q {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 1,
- "cost": 2.404394531,
+ "rows": 2,
+ "rows_after_scan": 1,
+ "rows_after_filter": 1,
+ "cost": 1.502197266,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 1,
- "cost": 2.404394531,
+ "cost": 1.502197266,
"uses_join_buffering": false
}
}
@@ -312,13 +327,14 @@ select * from (select * from t1 where t1.a=1)q {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 1,
- "cost_for_plan": 2.604394531
+ "cost_for_plan": 1.502197266
}
]
},
{
"best_join_order": ["t1"],
- "cost": 2.603394531
+ "rows": 1,
+ "cost": 1.502197266
},
{
"substitute_best_equal": {
@@ -441,7 +457,8 @@ select * from v2 {
"table": "t1",
"table_scan": {
"rows": 2,
- "cost": 2.004394531
+ "read_cost": 1.002197266,
+ "read_and_compare_cost": 1.502197266
}
}
]
@@ -454,11 +471,17 @@ select * from v2 {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 1,
- "cost": 2.404394531,
+ "rows": 2,
+ "rows_after_scan": 1,
+ "rows_after_filter": 1,
+ "cost": 1.502197266,
+ "index_only": false,
"chosen": true,
"use_tmp_table": true
}
@@ -466,7 +489,7 @@ select * from v2 {
"chosen_access_method": {
"type": "scan",
"records": 1,
- "cost": 2.404394531,
+ "cost": 1.502197266,
"uses_join_buffering": false
}
}
@@ -477,14 +500,15 @@ select * from v2 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 1,
- "cost_for_plan": 2.604394531,
+ "cost_for_plan": 1.502197266,
"cost_for_sorting": 1
}
]
},
{
"best_join_order": ["t1"],
- "cost": 3.603394531
+ "rows": 1,
+ "cost": 2.502197266
},
{
"substitute_best_equal": {
@@ -522,7 +546,8 @@ select * from v2 {
"table": "<derived2>",
"table_scan": {
"rows": 2,
- "cost": 2
+ "read_cost": 2,
+ "read_and_compare_cost": 2.5
}
}
]
@@ -535,18 +560,24 @@ select * from v2 {
{
"best_access_path": {
"table": "<derived2>",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 2,
- "cost": 2.4,
+ "rows": 2,
+ "rows_after_scan": 2,
+ "rows_after_filter": 2,
+ "cost": 2.5,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 2,
- "cost": 2.4,
+ "cost": 2.5,
"uses_join_buffering": false
}
}
@@ -557,13 +588,14 @@ select * from v2 {
"plan_prefix": [],
"table": "<derived2>",
"rows_for_plan": 2,
- "cost_for_plan": 2.8
+ "cost_for_plan": 2.5
}
]
},
{
"best_join_order": ["<derived2>"],
- "cost": 2.799
+ "rows": 2,
+ "cost": 2.5
},
{
"attaching_conditions_to_tables": {
@@ -667,7 +699,8 @@ explain select * from v2 {
"table": "t2",
"table_scan": {
"rows": 10,
- "cost": 2.021972656
+ "read_cost": 1.010986328,
+ "read_and_compare_cost": 3.510986328
}
}
]
@@ -680,18 +713,24 @@ explain select * from v2 {
{
"best_access_path": {
"table": "t2",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 10,
- "cost": 4.021972656,
+ "rows": 10,
+ "rows_after_scan": 10,
+ "rows_after_filter": 10,
+ "cost": 3.510986328,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 10,
- "cost": 4.021972656,
+ "cost": 3.510986328,
"uses_join_buffering": false
}
}
@@ -702,13 +741,14 @@ explain select * from v2 {
"plan_prefix": [],
"table": "t2",
"rows_for_plan": 10,
- "cost_for_plan": 6.021972656
+ "cost_for_plan": 3.510986328
}
]
},
{
"best_join_order": ["t2"],
- "cost": 6.020972656
+ "rows": 10,
+ "cost": 3.510986328
},
{
"attaching_conditions_to_tables": {
@@ -791,7 +831,8 @@ explain select * from v1 {
"table": "t1",
"table_scan": {
"rows": 10,
- "cost": 2.021972656
+ "read_cost": 1.010986328,
+ "read_and_compare_cost": 3.510986328
}
}
]
@@ -804,11 +845,17 @@ explain select * from v1 {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 10,
- "cost": 4.021972656,
+ "rows": 10,
+ "rows_after_scan": 10,
+ "rows_after_filter": 10,
+ "cost": 3.510986328,
+ "index_only": false,
"chosen": true,
"use_tmp_table": true
}
@@ -816,7 +863,7 @@ explain select * from v1 {
"chosen_access_method": {
"type": "scan",
"records": 10,
- "cost": 4.021972656,
+ "cost": 3.510986328,
"uses_join_buffering": false
}
}
@@ -827,14 +874,15 @@ explain select * from v1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 10,
- "cost_for_plan": 6.021972656,
+ "cost_for_plan": 3.510986328,
"cost_for_sorting": 10
}
]
},
{
"best_join_order": ["t1"],
- "cost": 16.02097266
+ "rows": 10,
+ "cost": 13.51098633
},
{
"attaching_conditions_to_tables": {
@@ -866,7 +914,8 @@ explain select * from v1 {
"table": "<derived2>",
"table_scan": {
"rows": 10,
- "cost": 10
+ "read_cost": 10,
+ "read_and_compare_cost": 12.5
}
}
]
@@ -879,18 +928,24 @@ explain select * from v1 {
{
"best_access_path": {
"table": "<derived2>",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 10,
- "cost": 12,
+ "rows": 10,
+ "rows_after_scan": 10,
+ "rows_after_filter": 10,
+ "cost": 12.5,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 10,
- "cost": 12,
+ "cost": 12.5,
"uses_join_buffering": false
}
}
@@ -901,13 +956,14 @@ explain select * from v1 {
"plan_prefix": [],
"table": "<derived2>",
"rows_for_plan": 10,
- "cost_for_plan": 14
+ "cost_for_plan": 12.5
}
]
},
{
"best_join_order": ["<derived2>"],
- "cost": 13.999
+ "rows": 10,
+ "cost": 12.5
},
{
"attaching_conditions_to_tables": {
@@ -1039,14 +1095,16 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
"table": "t1",
"table_scan": {
"rows": 100,
- "cost": 2.317382812
+ "read_cost": 1.158691406,
+ "read_and_compare_cost": 26.15869141
}
},
{
"table": "t2",
"table_scan": {
"rows": 100,
- "cost": 2.317382812
+ "read_cost": 1.158691406,
+ "read_and_compare_cost": 26.15869141
}
}
]
@@ -1059,18 +1117,24 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 100,
- "cost": 22.31738281,
+ "rows": 100,
+ "rows_after_scan": 100,
+ "rows_after_filter": 100,
+ "cost": 26.15869141,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 100,
- "cost": 22.31738281,
+ "cost": 26.15869141,
"uses_join_buffering": false
}
}
@@ -1078,18 +1142,24 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
{
"best_access_path": {
"table": "t2",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 100,
- "cost": 22.31738281,
+ "rows": 100,
+ "rows_after_scan": 100,
+ "rows_after_filter": 100,
+ "cost": 26.15869141,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 100,
- "cost": 22.31738281,
+ "cost": 26.15869141,
"uses_join_buffering": false
}
}
@@ -1100,7 +1170,7 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 100,
- "cost_for_plan": 42.31738281,
+ "cost_for_plan": 26.15869141,
"rest_of_plan": [
{
"plan_prefix": ["t1"],
@@ -1108,6 +1178,9 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
{
"best_access_path": {
"table": "t2",
+ "plan_details": {
+ "record_count": 100
+ },
"considered_access_paths": [
{
"access_type": "ref",
@@ -1115,23 +1188,23 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
"used_range_estimates": false,
"reason": "not available",
"rows": 1,
- "cond_check_cost": 2.200585794,
- "startup_cost": 0,
- "rows_after_filter": 1,
- "cost": 220.0585794,
+ "cost": 125.0585794,
"chosen": true
},
{
- "access_type": "scan",
- "resulting_rows": 75,
- "cost": 1522.317383,
+ "access_type": "scan_with_join_cache",
+ "rows": 100,
+ "rows_after_scan": 75,
+ "rows_after_filter": 75,
+ "cost": 1901.158691,
+ "index_only": false,
"chosen": false
}
],
"chosen_access_method": {
"type": "ref",
"records": 1,
- "cost": 220.0585794,
+ "cost": 125.0585794,
"uses_join_buffering": false
}
}
@@ -1142,7 +1215,7 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
"plan_prefix": ["t1"],
"table": "t2",
"rows_for_plan": 100,
- "cost_for_plan": 282.3759623
+ "cost_for_plan": 151.2172709
}
]
},
@@ -1150,7 +1223,7 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
"plan_prefix": [],
"table": "t2",
"rows_for_plan": 100,
- "cost_for_plan": 42.31738281,
+ "cost_for_plan": 26.15869141,
"rest_of_plan": [
{
"plan_prefix": ["t2"],
@@ -1158,6 +1231,9 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 100
+ },
"considered_access_paths": [
{
"access_type": "ref",
@@ -1165,23 +1241,23 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
"used_range_estimates": false,
"reason": "not available",
"rows": 1,
- "cond_check_cost": 2.200585794,
- "startup_cost": 0,
- "rows_after_filter": 1,
- "cost": 220.0585794,
+ "cost": 125.0585794,
"chosen": true
},
{
- "access_type": "scan",
- "resulting_rows": 75,
- "cost": 1522.317383,
+ "access_type": "scan_with_join_cache",
+ "rows": 100,
+ "rows_after_scan": 75,
+ "rows_after_filter": 75,
+ "cost": 1901.158691,
+ "index_only": false,
"chosen": false
}
],
"chosen_access_method": {
"type": "ref",
"records": 1,
- "cost": 220.0585794,
+ "cost": 125.0585794,
"uses_join_buffering": false
}
}
@@ -1192,10 +1268,10 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
"plan_prefix": ["t2"],
"table": "t1",
"rows_for_plan": 100,
- "cost_for_plan": 282.3759623,
+ "cost_for_plan": 151.2172709,
"pruned_by_cost": true,
- "current_cost": 282.3759623,
- "best_cost": 282.3759623
+ "current_cost": 151.2172709,
+ "best_cost": 151.2173709
}
]
}
@@ -1203,7 +1279,8 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
},
{
"best_join_order": ["t1", "t2"],
- "cost": 282.3749623
+ "rows": 100,
+ "cost": 151.2172709
},
{
"substitute_best_equal": {
@@ -1284,7 +1361,7 @@ EXPLAIN SELECT DISTINCT a FROM t1 {
"range_analysis": {
"table_scan": {
"rows": 65536,
- "cost": 13255.2
+ "cost": 16457
},
"potential_range_indexes": [
{
@@ -1300,9 +1377,8 @@ EXPLAIN SELECT DISTINCT a FROM t1 {
],
"best_covering_index_scan": {
"index": "a",
- "cost": 13377.39141,
- "chosen": false,
- "cause": "cost"
+ "cost": 14898.29141,
+ "chosen": true
},
"group_index_range": {
"distinct_query": true,
@@ -1357,10 +1433,15 @@ EXPLAIN SELECT DISTINCT a FROM t1 {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "index_merge",
- "resulting_rows": 5,
+ "rows": 5,
+ "rows_after_scan": 5,
+ "rows_after_filter": 5,
"cost": 6.5,
"chosen": true
}
@@ -1379,13 +1460,14 @@ EXPLAIN SELECT DISTINCT a FROM t1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 5,
- "cost_for_plan": 7.5
+ "cost_for_plan": 6.5
}
]
},
{
"best_join_order": ["t1"],
- "cost": 7.499
+ "rows": 5,
+ "cost": 6.5
},
{
"attaching_conditions_to_tables": {
@@ -1480,7 +1562,7 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a {
"range_analysis": {
"table_scan": {
"rows": 7,
- "cost": 5.429052734
+ "cost": 2.764526367
},
"potential_range_indexes": [
{
@@ -1491,7 +1573,7 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a {
],
"best_covering_index_scan": {
"index": "a",
- "cost": 2.409226263,
+ "cost": 2.084226263,
"chosen": true
},
"setup_range_conditions": [],
@@ -1555,11 +1637,17 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 1,
- "cost": 3.429052734,
+ "rows": 7,
+ "rows_after_scan": 1,
+ "rows_after_filter": 1,
+ "cost": 2.084226263,
+ "index_only": true,
"chosen": true,
"use_tmp_table": true
}
@@ -1567,7 +1655,7 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a {
"chosen_access_method": {
"type": "scan",
"records": 1,
- "cost": 3.429052734,
+ "cost": 2.084226263,
"uses_join_buffering": false
}
}
@@ -1578,14 +1666,15 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 1,
- "cost_for_plan": 3.629052734,
+ "cost_for_plan": 2.084226263,
"cost_for_sorting": 1
}
]
},
{
"best_join_order": ["t1"],
- "cost": 4.628052734
+ "rows": 1,
+ "cost": 3.084226263
},
{
"substitute_best_equal": {
@@ -1608,7 +1697,7 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a {
"reconsidering_access_paths_for_index_ordering": {
"clause": "GROUP BY",
"fanout": 1,
- "read_time": 3.430052734,
+ "read_time": 2.084226263,
"table": "t1",
"rows_estimation": 7,
"possible_keys": [
@@ -1617,8 +1706,8 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a {
"can_resolve_order": true,
"direction": 1,
"updated_limit": 7,
- "index_scan_time": 7,
- "records": 7,
+ "index_scan_cost": 2.084226263,
+ "rows": 7,
"chosen": true
}
]
@@ -1707,7 +1796,7 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id {
"range_analysis": {
"table_scan": {
"rows": 16,
- "cost": 7.23125
+ "cost": 5.015625
},
"potential_range_indexes": [
{
@@ -1718,7 +1807,7 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id {
],
"best_covering_index_scan": {
"index": "id",
- "cost": 4.21171589,
+ "cost": 4.11171589,
"chosen": true
},
"setup_range_conditions": [],
@@ -1782,10 +1871,15 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "index_merge",
- "resulting_rows": 9,
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
"cost": 3.25,
"chosen": true,
"use_tmp_table": true
@@ -1805,14 +1899,15 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 9,
- "cost_for_plan": 5.05,
+ "cost_for_plan": 3.25,
"cost_for_sorting": 9
}
]
},
{
"best_join_order": ["t1"],
- "cost": 14.049
+ "rows": 9,
+ "cost": 12.25
},
{
"substitute_best_equal": {
@@ -1903,7 +1998,7 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id {
"range_analysis": {
"table_scan": {
"rows": 16,
- "cost": 7.23125
+ "cost": 5.015625
},
"potential_range_indexes": [
{
@@ -1914,7 +2009,7 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id {
],
"best_covering_index_scan": {
"index": "id",
- "cost": 4.21171589,
+ "cost": 4.11171589,
"chosen": true
},
"setup_range_conditions": [],
@@ -1978,10 +2073,15 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "index_merge",
- "resulting_rows": 9,
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
"cost": 3.25,
"chosen": true,
"use_tmp_table": true
@@ -2001,14 +2101,15 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 9,
- "cost_for_plan": 5.05,
+ "cost_for_plan": 3.25,
"cost_for_sorting": 9
}
]
},
{
"best_join_order": ["t1"],
- "cost": 14.049
+ "rows": 9,
+ "cost": 12.25
},
{
"substitute_best_equal": {
@@ -2148,7 +2249,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"range_analysis": {
"table_scan": {
"rows": 1000,
- "cost": 232.5644531
+ "cost": 265.2822266
},
"potential_range_indexes": [
{
@@ -2177,7 +2278,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"using_mrr": false,
"index_only": false,
"rows": 180,
- "cost": 216.2943776,
+ "cost": 135.6693776,
"chosen": true
},
{
@@ -2187,7 +2288,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"using_mrr": false,
"index_only": false,
"rows": 21,
- "cost": 25.36242739,
+ "cost": 16.28742739,
"chosen": true
}
],
@@ -2208,7 +2309,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"ranges": ["(1,2) <= (a,b) <= (1,2)"]
},
"rows_for_plan": 21,
- "cost_for_plan": 25.36242739,
+ "cost_for_plan": 16.28742739,
"chosen": true
}
}
@@ -2218,12 +2319,12 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"rowid_filters": [
{
"key": "a_b",
- "build_cost": 0.886777098,
+ "build_cost": 1.127362357,
"rows": 21
},
{
"key": "a_c",
- "build_cost": 10.52169992,
+ "build_cost": 6.264109827,
"rows": 180
}
]
@@ -2259,16 +2360,16 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "ref",
"index": "a_c",
"used_range_estimates": true,
"rows": 180,
- "cond_check_cost": 216.2743776,
- "startup_cost": 0,
- "rows_after_filter": 180,
- "cost": 216.2743776,
+ "cost": 135.6493776,
"chosen": true
},
{
@@ -2276,10 +2377,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"index": "a_b",
"used_range_estimates": true,
"rows": 21,
- "cond_check_cost": 25.34242739,
- "startup_cost": 0,
- "rows_after_filter": 21,
- "cost": 25.34242739,
+ "cost": 16.26742739,
"chosen": true
},
{
@@ -2291,7 +2389,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"chosen_access_method": {
"type": "ref",
"records": 21,
- "cost": 25.34242739,
+ "cost": 16.26742739,
"uses_join_buffering": false
}
}
@@ -2302,13 +2400,14 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 21,
- "cost_for_plan": 29.54242739
+ "cost_for_plan": 16.26742739
}
]
},
{
"best_join_order": ["t1"],
- "cost": 29.54142739
+ "rows": 21,
+ "cost": 16.26742739
},
{
"substitute_best_equal": {
@@ -2331,7 +2430,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"reconsidering_access_paths_for_index_ordering": {
"clause": "ORDER BY",
"fanout": 1,
- "read_time": 25.34342739,
+ "read_time": 16.26742739,
"table": "t1",
"rows_estimation": 21,
"possible_keys": [
@@ -2340,7 +2439,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"can_resolve_order": true,
"direction": 1,
"updated_limit": 47,
- "index_scan_time": 47,
+ "index_scan_cost": 35.77753234,
"usable": false,
"cause": "cost"
},
@@ -2349,9 +2448,9 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"can_resolve_order": true,
"direction": 1,
"updated_limit": 47,
- "range_scan_time": 4.331020747,
- "index_scan_time": 4.331020747,
- "records": 180,
+ "index_scan_cost": 35.78900415,
+ "range_scan_cost": 6.375520747,
+ "rows": 180,
"chosen": true
},
{
@@ -2396,7 +2495,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"using_mrr": false,
"index_only": false,
"rows": 180,
- "cost": 216.2943776,
+ "cost": 135.6693776,
"chosen": true
}
],
@@ -2417,7 +2516,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
"ranges": ["(1) <= (a) <= (1)"]
},
"rows_for_plan": 180,
- "cost_for_plan": 216.2943776,
+ "cost_for_plan": 135.6693776,
"chosen": true
}
}
@@ -2524,7 +2623,8 @@ select t1.a from t1 left join t2 on t1.a=t2.a {
"table": "t1",
"table_scan": {
"rows": 4,
- "cost": 2.006835938
+ "read_cost": 1.003417969,
+ "read_and_compare_cost": 2.003417969
}
},
{
@@ -2543,18 +2643,24 @@ select t1.a from t1 left join t2 on t1.a=t2.a {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 4,
- "cost": 2.806835937,
+ "rows": 4,
+ "rows_after_scan": 4,
+ "rows_after_filter": 4,
+ "cost": 2.003417969,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 4,
- "cost": 2.806835937,
+ "cost": 2.003417969,
"uses_join_buffering": false
}
}
@@ -2565,13 +2671,14 @@ select t1.a from t1 left join t2 on t1.a=t2.a {
"plan_prefix": ["t2"],
"table": "t1",
"rows_for_plan": 4,
- "cost_for_plan": 3.606835937
+ "cost_for_plan": 2.003417969
}
]
},
{
"best_join_order": ["t2", "t1"],
- "cost": 3.605835937
+ "rows": 4,
+ "cost": 2.003417969
},
{
"substitute_best_equal": {
@@ -2671,14 +2778,16 @@ explain select * from t1 left join t2 on t2.a=t1.a {
"table": "t1",
"table_scan": {
"rows": 4,
- "cost": 2.006835938
+ "read_cost": 1.003417969,
+ "read_and_compare_cost": 2.003417969
}
},
{
"table": "t2",
"table_scan": {
"rows": 2,
- "cost": 2.004394531
+ "read_cost": 1.002197266,
+ "read_and_compare_cost": 1.502197266
}
}
]
@@ -2691,18 +2800,24 @@ explain select * from t1 left join t2 on t2.a=t1.a {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 4,
- "cost": 2.806835937,
+ "rows": 4,
+ "rows_after_scan": 4,
+ "rows_after_filter": 4,
+ "cost": 2.003417969,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 4,
- "cost": 2.806835937,
+ "cost": 2.003417969,
"uses_join_buffering": false
}
}
@@ -2713,7 +2828,7 @@ explain select * from t1 left join t2 on t2.a=t1.a {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 4,
- "cost_for_plan": 3.606835937,
+ "cost_for_plan": 2.003417969,
"rest_of_plan": [
{
"plan_prefix": ["t1"],
@@ -2721,28 +2836,31 @@ explain select * from t1 left join t2 on t2.a=t1.a {
{
"best_access_path": {
"table": "t2",
+ "plan_details": {
+ "record_count": 4
+ },
"considered_access_paths": [
{
"access_type": "eq_ref",
"index": "PRIMARY",
"rows": 1,
- "cond_check_cost": 1.2,
- "startup_cost": 0,
- "rows_after_filter": 1,
- "cost": 4.8,
+ "cost": 5.002147913,
"chosen": true
},
{
"access_type": "scan",
- "resulting_rows": 1.5,
- "cost": 10.81757812,
+ "rows": 2,
+ "rows_after_scan": 1.5,
+ "rows_after_filter": 1.5,
+ "cost": 6.008789062,
+ "index_only": false,
"chosen": false
}
],
"chosen_access_method": {
"type": "eq_ref",
"records": 1,
- "cost": 4.8,
+ "cost": 5.002147913,
"uses_join_buffering": false
}
}
@@ -2753,7 +2871,7 @@ explain select * from t1 left join t2 on t2.a=t1.a {
"plan_prefix": ["t1"],
"table": "t2",
"rows_for_plan": 4,
- "cost_for_plan": 9.206835937
+ "cost_for_plan": 7.005565882
}
]
}
@@ -2761,7 +2879,8 @@ explain select * from t1 left join t2 on t2.a=t1.a {
},
{
"best_join_order": ["t1", "t2"],
- "cost": 9.205835937
+ "rows": 4,
+ "cost": 7.005565882
},
{
"substitute_best_equal": {
@@ -2898,7 +3017,8 @@ explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and
"table": "t1",
"table_scan": {
"rows": 4,
- "cost": 2.006835938
+ "read_cost": 1.003417969,
+ "read_and_compare_cost": 2.003417969
}
},
{
@@ -2923,18 +3043,24 @@ explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 4,
- "cost": 2.806835937,
+ "rows": 4,
+ "rows_after_scan": 4,
+ "rows_after_filter": 4,
+ "cost": 2.003417969,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 4,
- "cost": 2.806835937,
+ "cost": 2.003417969,
"uses_join_buffering": false
}
}
@@ -2945,13 +3071,14 @@ explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and
"plan_prefix": ["t3", "t2"],
"table": "t1",
"rows_for_plan": 4,
- "cost_for_plan": 3.606835937
+ "cost_for_plan": 2.003417969
}
]
},
{
"best_join_order": ["t3", "t2", "t1"],
- "cost": 3.605835937
+ "rows": 4,
+ "cost": 2.003417969
},
{
"substitute_best_equal": {
@@ -3111,14 +3238,16 @@ explain extended select * from t1 where a in (select pk from t10) {
"table": "t1",
"table_scan": {
"rows": 3,
- "cost": 2.006591797
+ "read_cost": 1.003295898,
+ "read_and_compare_cost": 1.753295898
}
},
{
"table": "t10",
"table_scan": {
"rows": 10,
- "cost": 2.021972656
+ "read_cost": 1.010986328,
+ "read_and_compare_cost": 3.510986328
}
}
]
@@ -3139,18 +3268,24 @@ explain extended select * from t1 where a in (select pk from t10) {
{
"best_access_path": {
"table": "t10",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 10,
- "cost": 4.021972656,
+ "rows": 10,
+ "rows_after_scan": 10,
+ "rows_after_filter": 10,
+ "cost": 3.510986328,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 10,
- "cost": 4.021972656,
+ "cost": 3.510986328,
"uses_join_buffering": false
}
}
@@ -3161,7 +3296,7 @@ explain extended select * from t1 where a in (select pk from t10) {
"plan_prefix": [],
"table": "t10",
"rows_for_plan": 10,
- "cost_for_plan": 6.021972656
+ "cost_for_plan": 3.510986328
}
]
}
@@ -3176,18 +3311,24 @@ explain extended select * from t1 where a in (select pk from t10) {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 3,
- "cost": 2.606591797,
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 1.753295898,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 2.606591797,
+ "cost": 1.753295898,
"uses_join_buffering": false
}
}
@@ -3195,18 +3336,24 @@ explain extended select * from t1 where a in (select pk from t10) {
{
"best_access_path": {
"table": "t10",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 10,
- "cost": 4.021972656,
+ "rows": 10,
+ "rows_after_scan": 10,
+ "rows_after_filter": 10,
+ "cost": 3.510986328,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 10,
- "cost": 4.021972656,
+ "cost": 3.510986328,
"uses_join_buffering": false
}
}
@@ -3217,7 +3364,7 @@ explain extended select * from t1 where a in (select pk from t10) {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 3,
- "cost_for_plan": 3.206591797,
+ "cost_for_plan": 1.753295898,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -3226,18 +3373,24 @@ explain extended select * from t1 where a in (select pk from t10) {
{
"best_access_path": {
"table": "t10",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 10,
- "cost": 10.02197266,
+ "access_type": "scan_with_join_cache",
+ "rows": 10,
+ "rows_after_scan": 10,
+ "rows_after_filter": 10,
+ "cost": 11.01098633,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 10,
- "cost": 10.02197266,
+ "cost": 11.01098633,
"uses_join_buffering": true
}
}
@@ -3248,22 +3401,25 @@ explain extended select * from t1 where a in (select pk from t10) {
"plan_prefix": ["t1"],
"table": "t10",
"rows_for_plan": 30,
- "cost_for_plan": 19.22856445,
+ "cost_for_plan": 12.76428223,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
"records": 3,
- "read_time": 19.22856445
+ "cost": 12.76428223
},
{
"strategy": "SJ-Materialization",
"records": 3,
- "cost": 7.878564453
+ "cost": 6.914282227
},
{
"strategy": "DuplicateWeedout",
"records": 3,
- "read_time": 35.72856445
+ "dups_cost": 12.76428223,
+ "write_cost": 2.5,
+ "full_lookup_cost": 15,
+ "total_cost": 30.26428223
},
{
"chosen_strategy": "SJ-Materialization"
@@ -3276,7 +3432,7 @@ explain extended select * from t1 where a in (select pk from t10) {
"plan_prefix": [],
"table": "t10",
"rows_for_plan": 10,
- "cost_for_plan": 6.021972656,
+ "cost_for_plan": 3.510986328,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -3296,7 +3452,8 @@ explain extended select * from t1 where a in (select pk from t10) {
},
{
"best_join_order": ["t1", "<subquery2>"],
- "cost": 7.877564453
+ "rows": 3,
+ "cost": 6.914282227
},
{
"substitute_best_equal": {
@@ -3465,7 +3622,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"range_analysis": {
"table_scan": {
"rows": 10,
- "cost": 6.031738281
+ "cost": 3.515869141
},
"potential_range_indexes": [
{
@@ -3486,7 +3643,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
],
"best_covering_index_scan": {
"index": "pk_a_b",
- "cost": 3.010739566,
+ "cost": 2.760739566,
"chosen": true
},
"setup_range_conditions": [],
@@ -3499,7 +3656,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.345585794,
+ "cost": 1.270585794,
"chosen": true
},
{
@@ -3509,7 +3666,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.345829876,
+ "cost": 1.270829876,
"chosen": false,
"cause": "cost"
},
@@ -3520,7 +3677,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"using_mrr": false,
"index_only": true,
"rows": 1,
- "cost": 0.346073957,
+ "cost": 0.746073957,
"chosen": true
}
],
@@ -3528,10 +3685,10 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"intersecting_indexes": [
{
"index": "pk",
- "index_scan_cost": 1.000585794,
- "cumulated_index_scan_cost": 1.000585794,
- "disk_sweep_cost": 0.90078125,
- "cumulative_total_cost": 1.901367044,
+ "index_scan_cost": 0.525585794,
+ "cumulated_index_scan_cost": 0.525585794,
+ "disk_sweep_cost": 0.75,
+ "cumulative_total_cost": 1.275585794,
"usable": true,
"matching_rows_now": 1,
"intersect_covering_with_this_index": false,
@@ -3569,7 +3726,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"ranges": ["(2,5,1) <= (pk,a,b) <= (2,5,1)"]
},
"rows_for_plan": 1,
- "cost_for_plan": 0.346073957,
+ "cost_for_plan": 0.746073957,
"chosen": true
}
}
@@ -3579,17 +3736,17 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"rowid_filters": [
{
"key": "pk",
- "build_cost": 0.130585794,
+ "build_cost": 0.526585794,
"rows": 1
},
{
"key": "pk_a",
- "build_cost": 0.130829876,
+ "build_cost": 0.526829876,
"rows": 1
},
{
"key": "pk_a_b",
- "build_cost": 0.131073957,
+ "build_cost": 0.527073957,
"rows": 1
}
]
@@ -3625,16 +3782,16 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "ref",
"index": "pk",
"used_range_estimates": true,
"rows": 1,
- "cond_check_cost": 1.325585794,
- "startup_cost": 0,
- "rows_after_filter": 1,
- "cost": 1.325585794,
+ "cost": 1.250585794,
"chosen": true
},
{
@@ -3642,10 +3799,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"index": "pk_a",
"used_range_estimates": true,
"rows": 1,
- "cond_check_cost": 1.325829876,
- "startup_cost": 0,
- "rows_after_filter": 1,
- "cost": 1.325829876,
+ "cost": 1.250829876,
"chosen": false,
"cause": "cost"
},
@@ -3654,10 +3808,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"index": "pk_a_b",
"used_range_estimates": true,
"rows": 1,
- "cond_check_cost": 0.326073957,
- "startup_cost": 0,
- "rows_after_filter": 1,
- "cost": 0.326073957,
+ "cost": 0.726073957,
"chosen": true
},
{
@@ -3669,7 +3820,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"chosen_access_method": {
"type": "ref",
"records": 1,
- "cost": 0.326073957,
+ "cost": 0.726073957,
"uses_join_buffering": false
}
}
@@ -3680,13 +3831,14 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 1,
- "cost_for_plan": 0.526073957
+ "cost_for_plan": 0.726073957
}
]
},
{
"best_join_order": ["t1"],
- "cost": 0.525073957
+ "rows": 1,
+ "cost": 0.726073957
},
{
"substitute_best_equal": {
@@ -3782,7 +3934,8 @@ select f1(a) from t1 {
"table": "t1",
"table_scan": {
"rows": 4,
- "cost": 2.006835938
+ "read_cost": 1.003417969,
+ "read_and_compare_cost": 2.003417969
}
}
]
@@ -3795,18 +3948,24 @@ select f1(a) from t1 {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 4,
- "cost": 2.806835937,
+ "rows": 4,
+ "rows_after_scan": 4,
+ "rows_after_filter": 4,
+ "cost": 2.003417969,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 4,
- "cost": 2.806835937,
+ "cost": 2.003417969,
"uses_join_buffering": false
}
}
@@ -3817,13 +3976,14 @@ select f1(a) from t1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 4,
- "cost_for_plan": 3.606835937
+ "cost_for_plan": 2.003417969
}
]
},
{
"best_join_order": ["t1"],
- "cost": 3.605835937
+ "rows": 4,
+ "cost": 2.003417969
},
{
"attaching_conditions_to_tables": {
@@ -3887,7 +4047,8 @@ select f2(a) from t1 {
"table": "t1",
"table_scan": {
"rows": 4,
- "cost": 2.006835938
+ "read_cost": 1.003417969,
+ "read_and_compare_cost": 2.003417969
}
}
]
@@ -3900,18 +4061,24 @@ select f2(a) from t1 {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 4,
- "cost": 2.806835937,
+ "rows": 4,
+ "rows_after_scan": 4,
+ "rows_after_filter": 4,
+ "cost": 2.003417969,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 4,
- "cost": 2.806835937,
+ "cost": 2.003417969,
"uses_join_buffering": false
}
}
@@ -3922,13 +4089,14 @@ select f2(a) from t1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 4,
- "cost_for_plan": 3.606835937
+ "cost_for_plan": 2.003417969
}
]
},
{
"best_join_order": ["t1"],
- "cost": 3.605835937
+ "rows": 4,
+ "cost": 2.003417969
},
{
"attaching_conditions_to_tables": {
@@ -3969,7 +4137,7 @@ a
2
select length(trace) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
length(trace)
-2393
+2719
set optimizer_trace_max_mem_size=100;
select * from t1;
a
@@ -3983,7 +4151,7 @@ select * from t1 {
"join_preparation": {
"select_id": 1,
"steps": [
- 2293 0
+ 2619 0
set optimizer_trace_max_mem_size=0;
select * from t1;
a
@@ -3991,7 +4159,7 @@ a
2
select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
-select * from t1 2393 0
+select * from t1 2719 0
drop table t1;
set optimizer_trace='enabled=off';
set @@optimizer_trace_max_mem_size= @save_optimizer_trace_max_mem_size;
@@ -4016,7 +4184,7 @@ explain delete from t0 where t0.a<3 {
"range_analysis": {
"table_scan": {
"rows": 10,
- "cost": 6.021972656
+ "cost": 3.510986328
},
"potential_range_indexes": [
{
@@ -4035,7 +4203,7 @@ explain delete from t0 where t0.a<3 {
"using_mrr": false,
"index_only": false,
"rows": 3,
- "cost": 3.746757383,
+ "cost": 2.771757383,
"chosen": true
}
],
@@ -4053,7 +4221,7 @@ explain delete from t0 where t0.a<3 {
"ranges": ["(NULL) < (a) < (3)"]
},
"rows_for_plan": 3,
- "cost_for_plan": 3.746757383,
+ "cost_for_plan": 2.771757383,
"chosen": true
}
}
@@ -4156,7 +4324,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"range_analysis": {
"table_scan": {
"rows": 10,
- "cost": 6.021972656
+ "cost": 3.510986328
},
"potential_range_indexes": [
{
@@ -4167,7 +4335,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
],
"best_covering_index_scan": {
"index": "a",
- "cost": 3.005857945,
+ "cost": 2.755857945,
"chosen": true
},
"setup_range_conditions": [],
@@ -4180,7 +4348,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"using_mrr": false,
"index_only": true,
"rows": 3,
- "cost": 0.746757383,
+ "cost": 1.196757383,
"chosen": true
}
],
@@ -4201,7 +4369,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"ranges": ["(NULL) < (a) < (3)"]
},
"rows_for_plan": 3,
- "cost_for_plan": 0.746757383,
+ "cost_for_plan": 1.196757383,
"chosen": true
}
}
@@ -4221,7 +4389,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"range_analysis": {
"table_scan": {
"rows": 10,
- "cost": 6.021972656
+ "cost": 3.510986328
},
"potential_range_indexes": [
{
@@ -4232,7 +4400,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
],
"best_covering_index_scan": {
"index": "a",
- "cost": 3.005857945,
+ "cost": 2.755857945,
"chosen": true
},
"setup_range_conditions": [],
@@ -4245,7 +4413,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"using_mrr": false,
"index_only": true,
"rows": 3,
- "cost": 0.746757383,
+ "cost": 1.196757383,
"chosen": true
}
],
@@ -4266,7 +4434,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"ranges": ["(NULL) < (a) < (3)"]
},
"rows_for_plan": 3,
- "cost_for_plan": 0.746757383,
+ "cost_for_plan": 1.196757383,
"chosen": true
}
}
@@ -4291,18 +4459,23 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
{
"best_access_path": {
"table": "t0",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "range",
- "resulting_rows": 3,
- "cost": 0.746757383,
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 1.196757383,
"chosen": true
}
],
"chosen_access_method": {
"type": "range",
"records": 3,
- "cost": 0.746757383,
+ "cost": 1.196757383,
"uses_join_buffering": false
}
}
@@ -4310,18 +4483,23 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "range",
- "resulting_rows": 3,
- "cost": 0.746757383,
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 1.196757383,
"chosen": true
}
],
"chosen_access_method": {
"type": "range",
"records": 3,
- "cost": 0.746757383,
+ "cost": 1.196757383,
"uses_join_buffering": false
}
}
@@ -4332,7 +4510,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"plan_prefix": [],
"table": "t0",
"rows_for_plan": 3,
- "cost_for_plan": 1.346757383,
+ "cost_for_plan": 1.196757383,
"rest_of_plan": [
{
"plan_prefix": ["t0"],
@@ -4340,6 +4518,9 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
"access_type": "ref",
@@ -4347,10 +4528,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"used_range_estimates": false,
"reason": "not better than ref estimates",
"rows": 1,
- "cond_check_cost": 1.200585794,
- "startup_cost": 0,
- "rows_after_filter": 1,
- "cost": 3.601757383,
+ "cost": 2.176757383,
"chosen": true
},
{
@@ -4362,7 +4540,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"chosen_access_method": {
"type": "ref",
"records": 1,
- "cost": 3.601757383,
+ "cost": 2.176757383,
"uses_join_buffering": false
}
}
@@ -4373,7 +4551,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"plan_prefix": ["t0"],
"table": "t1",
"rows_for_plan": 3,
- "cost_for_plan": 5.548514767
+ "cost_for_plan": 3.373514767
}
]
},
@@ -4381,7 +4559,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 3,
- "cost_for_plan": 1.346757383,
+ "cost_for_plan": 1.196757383,
"rest_of_plan": [
{
"plan_prefix": ["t1"],
@@ -4389,6 +4567,9 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
{
"best_access_path": {
"table": "t0",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
"access_type": "ref",
@@ -4397,10 +4578,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"used_range_estimates": false,
"reason": "not better than ref estimates",
"rows": 2,
- "cond_check_cost": 1.401171589,
- "startup_cost": 0,
- "rows_after_filter": 2,
- "cost": 4.203514767,
+ "cost": 2.853514767,
"chosen": true
},
{
@@ -4412,7 +4590,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"chosen_access_method": {
"type": "ref",
"records": 2,
- "cost": 4.203514767,
+ "cost": 2.853514767,
"uses_join_buffering": false
}
}
@@ -4423,10 +4601,10 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
"plan_prefix": ["t1"],
"table": "t0",
"rows_for_plan": 6,
- "cost_for_plan": 6.75027215,
+ "cost_for_plan": 4.05027215,
"pruned_by_cost": true,
- "current_cost": 6.75027215,
- "best_cost": 5.548514767
+ "current_cost": 4.05027215,
+ "best_cost": 3.373614767
}
]
}
@@ -4434,7 +4612,8 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
},
{
"best_join_order": ["t0", "t1"],
- "cost": 5.547514767
+ "rows": 3,
+ "cost": 3.373514767
},
{
"substitute_best_equal": {
@@ -4543,7 +4722,8 @@ explain select * from (select rand() from t1)q {
"table": "t1",
"table_scan": {
"rows": 3,
- "cost": 2.005126953
+ "read_cost": 1.002563477,
+ "read_and_compare_cost": 1.752563477
}
}
]
@@ -4556,18 +4736,24 @@ explain select * from (select rand() from t1)q {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 3,
- "cost": 2.605126953,
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 1.752563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 2.605126953,
+ "cost": 1.752563477,
"uses_join_buffering": false
}
}
@@ -4578,13 +4764,14 @@ explain select * from (select rand() from t1)q {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 3,
- "cost_for_plan": 3.205126953
+ "cost_for_plan": 1.752563477
}
]
},
{
"best_join_order": ["t1"],
- "cost": 3.204126953
+ "rows": 3,
+ "cost": 1.752563477
},
{
"attaching_conditions_to_tables": {
@@ -4616,7 +4803,8 @@ explain select * from (select rand() from t1)q {
"table": "<derived2>",
"table_scan": {
"rows": 3,
- "cost": 3
+ "read_cost": 3,
+ "read_and_compare_cost": 3.75
}
}
]
@@ -4629,18 +4817,24 @@ explain select * from (select rand() from t1)q {
{
"best_access_path": {
"table": "<derived2>",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 3,
- "cost": 3.6,
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 3.75,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 3.6,
+ "cost": 3.75,
"uses_join_buffering": false
}
}
@@ -4651,13 +4845,14 @@ explain select * from (select rand() from t1)q {
"plan_prefix": [],
"table": "<derived2>",
"rows_for_plan": 3,
- "cost_for_plan": 4.2
+ "cost_for_plan": 3.75
}
]
},
{
"best_join_order": ["<derived2>"],
- "cost": 4.199
+ "rows": 3,
+ "cost": 3.75
},
{
"attaching_conditions_to_tables": {
@@ -4809,21 +5004,24 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"table": "t1",
"table_scan": {
"rows": 3,
- "cost": 2.005126953
+ "read_cost": 1.002563477,
+ "read_and_compare_cost": 1.752563477
}
},
{
"table": "t_inner_1",
"table_scan": {
"rows": 3,
- "cost": 2.005126953
+ "read_cost": 1.002563477,
+ "read_and_compare_cost": 1.752563477
}
},
{
"table": "t_inner_2",
"table_scan": {
"rows": 3,
- "cost": 2.005126953
+ "read_cost": 1.002563477,
+ "read_and_compare_cost": 1.752563477
}
}
]
@@ -4844,18 +5042,24 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
{
"best_access_path": {
"table": "t_inner_1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 3,
- "cost": 2.605126953,
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 1.752563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 2.605126953,
+ "cost": 1.752563477,
"uses_join_buffering": false
}
}
@@ -4863,18 +5067,24 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 3,
- "cost": 2.605126953,
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 1.752563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 2.605126953,
+ "cost": 1.752563477,
"uses_join_buffering": false
}
}
@@ -4885,7 +5095,7 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"plan_prefix": [],
"table": "t_inner_1",
"rows_for_plan": 3,
- "cost_for_plan": 3.205126953,
+ "cost_for_plan": 1.752563477,
"rest_of_plan": [
{
"plan_prefix": ["t_inner_1"],
@@ -4893,18 +5103,24 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 4.405126953,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 4.002563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 4.405126953,
+ "cost": 4.002563477,
"uses_join_buffering": true
}
}
@@ -4915,7 +5131,7 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"plan_prefix": ["t_inner_1"],
"table": "t_inner_2",
"rows_for_plan": 9,
- "cost_for_plan": 9.410253906
+ "cost_for_plan": 5.755126953
}
]
},
@@ -4923,7 +5139,7 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"plan_prefix": [],
"table": "t_inner_2",
"rows_for_plan": 3,
- "cost_for_plan": 3.205126953,
+ "cost_for_plan": 1.752563477,
"pruned_by_heuristic": true
}
]
@@ -4939,18 +5155,24 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 3,
- "cost": 2.605126953,
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 1.752563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 2.605126953,
+ "cost": 1.752563477,
"uses_join_buffering": false
}
}
@@ -4958,18 +5180,24 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
{
"best_access_path": {
"table": "t_inner_1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 3,
- "cost": 2.605126953,
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 1.752563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 2.605126953,
+ "cost": 1.752563477,
"uses_join_buffering": false
}
}
@@ -4977,18 +5205,24 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 3,
- "cost": 2.605126953,
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 1.752563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 2.605126953,
+ "cost": 1.752563477,
"uses_join_buffering": false
}
}
@@ -4999,7 +5233,7 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 3,
- "cost_for_plan": 3.205126953,
+ "cost_for_plan": 1.752563477,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -5008,18 +5242,24 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
{
"best_access_path": {
"table": "t_inner_1",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 4.405126953,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 4.002563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 4.405126953,
+ "cost": 4.002563477,
"uses_join_buffering": true
}
}
@@ -5027,18 +5267,24 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 4.405126953,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 4.002563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 4.405126953,
+ "cost": 4.002563477,
"uses_join_buffering": true
}
}
@@ -5049,7 +5295,7 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"plan_prefix": ["t1"],
"table": "t_inner_1",
"rows_for_plan": 9,
- "cost_for_plan": 9.410253906,
+ "cost_for_plan": 5.755126953,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -5058,18 +5304,24 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 9
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 8.005126953,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 9.852563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 8.005126953,
+ "cost": 9.852563477,
"uses_join_buffering": true
}
}
@@ -5080,22 +5332,25 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"plan_prefix": ["t1", "t_inner_1"],
"table": "t_inner_2",
"rows_for_plan": 27,
- "cost_for_plan": 22.81538086,
+ "cost_for_plan": 15.60769043,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
"records": 3,
- "read_time": 48.86665039
+ "cost": 22.7833252
},
{
"strategy": "SJ-Materialization",
"records": 3,
- "cost": 10.81538086
+ "cost": 9.10769043
},
{
"strategy": "DuplicateWeedout",
"records": 3,
- "read_time": 27.31538086
+ "dups_cost": 15.60769043,
+ "write_cost": 1.45,
+ "full_lookup_cost": 4.05,
+ "total_cost": 21.10769043
},
{
"chosen_strategy": "SJ-Materialization"
@@ -5108,7 +5363,7 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"plan_prefix": ["t1"],
"table": "t_inner_2",
"rows_for_plan": 9,
- "cost_for_plan": 9.410253906,
+ "cost_for_plan": 5.755126953,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -5118,7 +5373,7 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"plan_prefix": [],
"table": "t_inner_1",
"rows_for_plan": 3,
- "cost_for_plan": 3.205126953,
+ "cost_for_plan": 1.752563477,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -5126,7 +5381,7 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"plan_prefix": [],
"table": "t_inner_2",
"rows_for_plan": 3,
- "cost_for_plan": 3.205126953,
+ "cost_for_plan": 1.752563477,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -5149,7 +5404,8 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
},
{
"best_join_order": ["t1", "<subquery2>"],
- "cost": 10.81438086
+ "rows": 3,
+ "cost": 9.10769043
},
{
"substitute_best_equal": {
@@ -5201,11 +5457,11 @@ explain select * from t1 t_outer_1,t2 t_outer_2 where t_outer_1.a in (select t_
t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t_outer_1 ALL NULL NULL NULL NULL 3
-1 PRIMARY t_inner_1 ALL NULL NULL NULL NULL 3 Using where; Start temporary; Using join buffer (flat, BNL join)
-1 PRIMARY t_inner_2 ALL NULL NULL NULL NULL 9 End temporary; Using join buffer (incremental, BNL join)
-1 PRIMARY t_inner_4 ALL NULL NULL NULL NULL 3 Start temporary; Using join buffer (incremental, BNL join)
+1 PRIMARY t_inner_1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t_inner_2 ALL NULL NULL NULL NULL 9 FirstMatch(t_outer_1); Using join buffer (incremental, BNL join)
1 PRIMARY t_outer_2 ALL NULL NULL NULL NULL 9 Using join buffer (incremental, BNL join)
-1 PRIMARY t_inner_3 ALL NULL NULL NULL NULL 9 Using where; End temporary; Using join buffer (incremental, BNL join)
+1 PRIMARY t_inner_4 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join)
+1 PRIMARY t_inner_3 ALL NULL NULL NULL NULL 9 Using where; FirstMatch(t_outer_2); Using join buffer (incremental, BNL join)
select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
explain select * from t1 t_outer_1,t2 t_outer_2 where t_outer_1.a in (select t_inner_1.a from t2 t_inner_2, t1 t_inner_1) and
@@ -5364,42 +5620,48 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"table": "t_outer_1",
"table_scan": {
"rows": 3,
- "cost": 2.005126953
+ "read_cost": 1.002563477,
+ "read_and_compare_cost": 1.752563477
}
},
{
"table": "t_outer_2",
"table_scan": {
"rows": 9,
- "cost": 2.015380859
+ "read_cost": 1.00769043,
+ "read_and_compare_cost": 3.25769043
}
},
{
"table": "t_inner_2",
"table_scan": {
"rows": 9,
- "cost": 2.015380859
+ "read_cost": 1.00769043,
+ "read_and_compare_cost": 3.25769043
}
},
{
"table": "t_inner_1",
"table_scan": {
"rows": 3,
- "cost": 2.005126953
+ "read_cost": 1.002563477,
+ "read_and_compare_cost": 1.752563477
}
},
{
"table": "t_inner_3",
"table_scan": {
"rows": 9,
- "cost": 2.015380859
+ "read_cost": 1.00769043,
+ "read_and_compare_cost": 3.25769043
}
},
{
"table": "t_inner_4",
"table_scan": {
"rows": 3,
- "cost": 2.005126953
+ "read_cost": 1.002563477,
+ "read_and_compare_cost": 1.752563477
}
}
]
@@ -5427,18 +5689,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_outer_1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 3,
- "cost": 2.605126953,
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 1.752563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 2.605126953,
+ "cost": 1.752563477,
"uses_join_buffering": false
}
}
@@ -5446,18 +5714,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 3,
- "cost": 2.605126953,
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 1.752563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 2.605126953,
+ "cost": 1.752563477,
"uses_join_buffering": false
}
}
@@ -5465,18 +5739,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 9,
- "cost": 3.815380859,
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 3.25769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 3.815380859,
+ "cost": 3.25769043,
"uses_join_buffering": false
}
}
@@ -5484,18 +5764,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_outer_2",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 9,
- "cost": 3.815380859,
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 3.25769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 3.815380859,
+ "cost": 3.25769043,
"uses_join_buffering": false
}
}
@@ -5503,18 +5789,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_4",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 3,
- "cost": 2.605126953,
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 1.752563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 2.605126953,
+ "cost": 1.752563477,
"uses_join_buffering": false
}
}
@@ -5522,18 +5814,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 9,
- "cost": 3.815380859,
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 3.25769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 3.815380859,
+ "cost": 3.25769043,
"uses_join_buffering": false
}
}
@@ -5544,7 +5842,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_outer_1",
"rows_for_plan": 3,
- "cost_for_plan": 3.205126953,
+ "cost_for_plan": 1.752563477,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -5553,18 +5851,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_1",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 4.405126953,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 4.002563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 4.405126953,
+ "cost": 4.002563477,
"uses_join_buffering": true
}
}
@@ -5572,18 +5876,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 9.215380859,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 10.00769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 9.215380859,
+ "cost": 10.00769043,
"uses_join_buffering": true
}
}
@@ -5591,18 +5901,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_outer_2",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 9.215380859,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 10.00769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 9.215380859,
+ "cost": 10.00769043,
"uses_join_buffering": true
}
}
@@ -5610,18 +5926,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_4",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 4.405126953,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 4.002563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 4.405126953,
+ "cost": 4.002563477,
"uses_join_buffering": true
}
}
@@ -5629,18 +5951,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 9.215380859,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 10.00769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 9.215380859,
+ "cost": 10.00769043,
"uses_join_buffering": true
}
}
@@ -5651,7 +5979,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1"],
"table": "t_outer_2",
"rows_for_plan": 27,
- "cost_for_plan": 17.82050781,
+ "cost_for_plan": 11.76025391,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -5660,18 +5988,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 52.41538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 76.15769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 52.41538086,
+ "cost": 76.15769043,
"uses_join_buffering": true
}
}
@@ -5679,18 +6013,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_1",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 18.80512695,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 26.05256348,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 18.80512695,
+ "cost": 26.05256348,
"uses_join_buffering": true
}
}
@@ -5698,18 +6038,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_4",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 18.80512695,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 26.05256348,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 18.80512695,
+ "cost": 26.05256348,
"uses_join_buffering": true
}
}
@@ -5717,18 +6063,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 52.41538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 76.15769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 52.41538086,
+ "cost": 76.15769043,
"uses_join_buffering": true
}
}
@@ -5739,7 +6091,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2"],
"table": "t_inner_1",
"rows_for_plan": 81,
- "cost_for_plan": 52.82563477,
+ "cost_for_plan": 37.81281738,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -5748,18 +6100,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 81
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 149.6153809,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 258.4076904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 149.6153809,
+ "cost": 258.4076904,
"uses_join_buffering": true
}
}
@@ -5767,18 +6125,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_4",
+ "plan_details": {
+ "record_count": 81
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 51.20512695,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 86.80256348,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 51.20512695,
+ "cost": 86.80256348,
"uses_join_buffering": true
}
}
@@ -5786,18 +6150,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 81
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 149.6153809,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 258.4076904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 149.6153809,
+ "cost": 258.4076904,
"uses_join_buffering": true
}
}
@@ -5808,20 +6178,23 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2", "t_inner_1"],
"table": "t_inner_2",
"rows_for_plan": 729,
- "cost_for_plan": 348.2410156,
+ "cost_for_plan": 296.2205078,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
"records": 27,
- "read_time": 721.2047852
+ "cost": 322.9523926
},
{
"strategy": "DuplicateWeedout",
"records": 27,
- "read_time": 461.6410156
+ "dups_cost": 296.2205078,
+ "write_cost": 5.05,
+ "full_lookup_cost": 109.35,
+ "total_cost": 410.6205078
},
{
- "chosen_strategy": "DuplicateWeedout"
+ "chosen_strategy": "FirstMatch"
}
],
"rest_of_plan": [
@@ -5836,18 +6209,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_4",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 18.80512695,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 34.15256348,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 18.80512695,
+ "cost": 34.15256348,
"uses_join_buffering": true
}
}
@@ -5855,18 +6234,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 52.41538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 100.4576904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 52.41538086,
+ "cost": 100.4576904,
"uses_join_buffering": true
}
}
@@ -5882,7 +6267,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_4",
"rows_for_plan": 81,
- "cost_for_plan": 496.6461426,
+ "cost_for_plan": 357.1049561,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -5897,18 +6282,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 81
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 149.6153809,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 331.3076904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 149.6153809,
+ "cost": 331.3076904,
"uses_join_buffering": true
}
}
@@ -5925,20 +6316,23 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 729,
- "cost_for_plan": 792.0615234,
+ "cost_for_plan": 688.4126465,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
"records": 27,
- "read_time": 1165.025293
+ "cost": 634.1445312
},
{
"strategy": "DuplicateWeedout",
"records": 27,
- "read_time": 905.4615234
+ "dups_cost": 688.4126465,
+ "write_cost": 5.05,
+ "full_lookup_cost": 109.35,
+ "total_cost": 802.8126465
},
{
- "chosen_strategy": "DuplicateWeedout"
+ "chosen_strategy": "FirstMatch"
}
]
}
@@ -5953,7 +6347,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 243,
- "cost_for_plan": 562.6563965,
+ "cost_for_plan": 423.410083,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -5963,7 +6357,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2", "t_inner_1"],
"table": "t_inner_4",
"rows_for_plan": 243,
- "cost_for_plan": 152.6307617,
+ "cost_for_plan": 124.6153809,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -5977,18 +6371,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 243
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 441.2153809,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 878.0576904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 441.2153809,
+ "cost": 878.0576904,
"uses_join_buffering": true
}
}
@@ -5996,18 +6396,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 243
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 441.2153809,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 878.0576904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 441.2153809,
+ "cost": 878.0576904,
"uses_join_buffering": true
}
}
@@ -6023,11 +6429,11 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_2",
"rows_for_plan": 2187,
- "cost_for_plan": 1031.246143,
+ "cost_for_plan": 1002.673071,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 1031.246143,
- "best_cost": 905.4615234
+ "current_cost": 1002.673071,
+ "best_cost": 634.1446312
},
{
"plan_prefix": [
@@ -6038,11 +6444,11 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 2187,
- "cost_for_plan": 1031.246143,
+ "cost_for_plan": 1002.673071,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 1031.246143,
- "best_cost": 905.4615234
+ "current_cost": 1002.673071,
+ "best_cost": 634.1446312
}
]
},
@@ -6050,7 +6456,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2", "t_inner_1"],
"table": "t_inner_3",
"rows_for_plan": 729,
- "cost_for_plan": 348.2410156,
+ "cost_for_plan": 296.2205078,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": "min_read_time"
}
@@ -6060,7 +6466,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2"],
"table": "t_inner_2",
"rows_for_plan": 243,
- "cost_for_plan": 118.8358887,
+ "cost_for_plan": 87.91794434,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -6068,7 +6474,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2"],
"table": "t_inner_4",
"rows_for_plan": 81,
- "cost_for_plan": 52.82563477,
+ "cost_for_plan": 37.81281738,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -6076,7 +6482,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2"],
"table": "t_inner_3",
"rows_for_plan": 243,
- "cost_for_plan": 118.8358887,
+ "cost_for_plan": 87.91794434,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -6086,7 +6492,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1"],
"table": "t_inner_1",
"rows_for_plan": 9,
- "cost_for_plan": 9.410253906,
+ "cost_for_plan": 5.755126953,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -6095,18 +6501,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 9
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 20.01538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 27.55769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 20.01538086,
+ "cost": 27.55769043,
"uses_join_buffering": true
}
}
@@ -6114,18 +6526,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_outer_2",
+ "plan_details": {
+ "record_count": 9
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 20.01538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 27.55769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 20.01538086,
+ "cost": 27.55769043,
"uses_join_buffering": true
}
}
@@ -6133,18 +6551,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_4",
+ "plan_details": {
+ "record_count": 9
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 8.005126953,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 9.852563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 8.005126953,
+ "cost": 9.852563477,
"uses_join_buffering": true
}
}
@@ -6152,18 +6576,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 9
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 20.01538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 27.55769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 20.01538086,
+ "cost": 27.55769043,
"uses_join_buffering": true
}
}
@@ -6174,7 +6604,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1"],
"table": "t_outer_2",
"rows_for_plan": 81,
- "cost_for_plan": 45.62563477,
+ "cost_for_plan": 33.31281738,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -6183,18 +6613,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 81
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 149.6153809,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 258.4076904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 149.6153809,
+ "cost": 258.4076904,
"uses_join_buffering": true
}
}
@@ -6202,18 +6638,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_4",
+ "plan_details": {
+ "record_count": 81
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 51.20512695,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 86.80256348,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 51.20512695,
+ "cost": 86.80256348,
"uses_join_buffering": true
}
}
@@ -6221,18 +6663,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 81
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 149.6153809,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 258.4076904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 149.6153809,
+ "cost": 258.4076904,
"uses_join_buffering": true
}
}
@@ -6243,12 +6691,15 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"],
"table": "t_inner_2",
"rows_for_plan": 729,
- "cost_for_plan": 341.0410156,
+ "cost_for_plan": 291.7205078,
"semijoin_strategy_choice": [
{
"strategy": "DuplicateWeedout",
"records": 27,
- "read_time": 454.4410156
+ "dups_cost": 291.7205078,
+ "write_cost": 5.05,
+ "full_lookup_cost": 109.35,
+ "total_cost": 406.1205078
},
{
"chosen_strategy": "DuplicateWeedout"
@@ -6266,18 +6717,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_4",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 18.80512695,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 34.15256348,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 18.80512695,
+ "cost": 34.15256348,
"uses_join_buffering": true
}
}
@@ -6285,18 +6742,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 52.41538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 100.4576904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 52.41538086,
+ "cost": 100.4576904,
"uses_join_buffering": true
}
}
@@ -6312,7 +6775,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_4",
"rows_for_plan": 81,
- "cost_for_plan": 489.4461426,
+ "cost_for_plan": 440.2730713,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -6327,18 +6790,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 81
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 149.6153809,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 331.3076904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 149.6153809,
+ "cost": 331.3076904,
"uses_join_buffering": true
}
}
@@ -6355,22 +6824,28 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 729,
- "cost_for_plan": 784.8615234,
+ "cost_for_plan": 771.5807617,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
"records": 27,
- "read_time": 1157.825293
+ "cost": 717.3126465
},
{
"strategy": "DuplicateWeedout",
"records": 27,
- "read_time": 898.2615234
+ "dups_cost": 771.5807617,
+ "write_cost": 5.05,
+ "full_lookup_cost": 109.35,
+ "total_cost": 885.9807617
},
{
- "chosen_strategy": "DuplicateWeedout"
+ "chosen_strategy": "FirstMatch"
}
- ]
+ ],
+ "pruned_by_cost": true,
+ "current_cost": 717.3126465,
+ "best_cost": 634.1446312
}
]
},
@@ -6383,7 +6858,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 243,
- "cost_for_plan": 555.4563965,
+ "cost_for_plan": 506.5781982,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -6393,7 +6868,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"],
"table": "t_inner_4",
"rows_for_plan": 243,
- "cost_for_plan": 145.4307617,
+ "cost_for_plan": 120.1153809,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -6407,18 +6882,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 243
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 441.2153809,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 878.0576904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 441.2153809,
+ "cost": 878.0576904,
"uses_join_buffering": true
}
}
@@ -6426,18 +6907,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 243
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 441.2153809,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 878.0576904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 441.2153809,
+ "cost": 878.0576904,
"uses_join_buffering": true
}
}
@@ -6453,11 +6940,11 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_2",
"rows_for_plan": 2187,
- "cost_for_plan": 1024.046143,
+ "cost_for_plan": 998.1730713,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 1024.046143,
- "best_cost": 898.2615234
+ "current_cost": 998.1730713,
+ "best_cost": 634.1446312
},
{
"plan_prefix": [
@@ -6468,11 +6955,11 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 2187,
- "cost_for_plan": 1024.046143,
+ "cost_for_plan": 998.1730713,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 1024.046143,
- "best_cost": 898.2615234
+ "current_cost": 998.1730713,
+ "best_cost": 634.1446312
}
]
},
@@ -6480,7 +6967,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"],
"table": "t_inner_3",
"rows_for_plan": 729,
- "cost_for_plan": 341.0410156,
+ "cost_for_plan": 291.7205078,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": "min_read_time"
}
@@ -6490,20 +6977,23 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1"],
"table": "t_inner_2",
"rows_for_plan": 81,
- "cost_for_plan": 45.62563477,
+ "cost_for_plan": 33.31281738,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
"records": 3,
- "read_time": 81.35893555
+ "cost": 36.32946777
},
{
"strategy": "DuplicateWeedout",
"records": 3,
- "read_time": 58.22563477
+ "dups_cost": 33.31281738,
+ "write_cost": 1.45,
+ "full_lookup_cost": 12.15,
+ "total_cost": 46.91281738
},
{
- "chosen_strategy": "DuplicateWeedout"
+ "chosen_strategy": "FirstMatch"
}
],
"rest_of_plan": [
@@ -6513,18 +7003,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_outer_2",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 9.215380859,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 12.70769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 9.215380859,
+ "cost": 12.70769043,
"uses_join_buffering": true
}
}
@@ -6532,18 +7028,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_4",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 4.405126953,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 4.902563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 4.405126953,
+ "cost": 4.902563477,
"uses_join_buffering": true
}
}
@@ -6551,18 +7053,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 9.215380859,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 12.70769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 9.215380859,
+ "cost": 12.70769043,
"uses_join_buffering": true
}
}
@@ -6573,7 +7081,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"],
"table": "t_outer_2",
"rows_for_plan": 27,
- "cost_for_plan": 72.84101562,
+ "cost_for_plan": 49.0371582,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -6587,18 +7095,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_4",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 18.80512695,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 34.15256348,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 18.80512695,
+ "cost": 34.15256348,
"uses_join_buffering": true
}
}
@@ -6606,18 +7120,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 52.41538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 100.4576904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 52.41538086,
+ "cost": 100.4576904,
"uses_join_buffering": true
}
}
@@ -6633,7 +7153,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_4",
"rows_for_plan": 81,
- "cost_for_plan": 107.8461426,
+ "cost_for_plan": 83.18972168,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -6648,18 +7168,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 81
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 149.6153809,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 331.3076904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 149.6153809,
+ "cost": 331.3076904,
"uses_join_buffering": true
}
}
@@ -6676,20 +7202,23 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 729,
- "cost_for_plan": 403.2615234,
+ "cost_for_plan": 414.4974121,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
"records": 27,
- "read_time": 776.225293
+ "cost": 360.2292969
},
{
"strategy": "DuplicateWeedout",
"records": 27,
- "read_time": 516.6615234
+ "dups_cost": 414.4974121,
+ "write_cost": 5.05,
+ "full_lookup_cost": 109.35,
+ "total_cost": 528.8974121
},
{
- "chosen_strategy": "DuplicateWeedout"
+ "chosen_strategy": "FirstMatch"
}
]
}
@@ -6704,7 +7233,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 243,
- "cost_for_plan": 173.8563965,
+ "cost_for_plan": 149.4948486,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -6714,7 +7243,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"],
"table": "t_inner_4",
"rows_for_plan": 9,
- "cost_for_plan": 64.43076172,
+ "cost_for_plan": 41.23203125,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -6728,18 +7257,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_outer_2",
+ "plan_details": {
+ "record_count": 9
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 20.01538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 35.65769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 20.01538086,
+ "cost": 35.65769043,
"uses_join_buffering": true
}
}
@@ -6747,18 +7282,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 9
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 20.01538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 35.65769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 20.01538086,
+ "cost": 35.65769043,
"uses_join_buffering": true
}
}
@@ -6774,7 +7315,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_outer_2",
"rows_for_plan": 81,
- "cost_for_plan": 100.6461426,
+ "cost_for_plan": 76.88972168,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -6789,18 +7330,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 81
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 149.6153809,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 331.3076904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 149.6153809,
+ "cost": 331.3076904,
"uses_join_buffering": true
}
}
@@ -6817,17 +7364,23 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 729,
- "cost_for_plan": 396.0615234,
+ "cost_for_plan": 408.1974121,
"semijoin_strategy_choice": [
{
"strategy": "DuplicateWeedout",
"records": 27,
- "read_time": 509.4615234
+ "dups_cost": 408.1974121,
+ "write_cost": 5.05,
+ "full_lookup_cost": 109.35,
+ "total_cost": 522.5974121
},
{
"chosen_strategy": "DuplicateWeedout"
}
- ]
+ ],
+ "pruned_by_cost": true,
+ "current_cost": 522.5974121,
+ "best_cost": 360.2293969
}
]
},
@@ -6840,7 +7393,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 81,
- "cost_for_plan": 100.6461426,
+ "cost_for_plan": 76.88972168,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -6850,7 +7403,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"],
"table": "t_inner_3",
"rows_for_plan": 27,
- "cost_for_plan": 72.84101562,
+ "cost_for_plan": 49.0371582,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -6860,7 +7413,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1"],
"table": "t_inner_4",
"rows_for_plan": 27,
- "cost_for_plan": 22.81538086,
+ "cost_for_plan": 15.60769043,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -6869,18 +7422,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_outer_2",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 52.41538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 88.30769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 52.41538086,
+ "cost": 88.30769043,
"uses_join_buffering": true
}
}
@@ -6888,18 +7447,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 52.41538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 88.30769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 52.41538086,
+ "cost": 88.30769043,
"uses_join_buffering": true
}
}
@@ -6907,18 +7472,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 52.41538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 88.30769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 52.41538086,
+ "cost": 88.30769043,
"uses_join_buffering": true
}
}
@@ -6929,7 +7500,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"],
"table": "t_outer_2",
"rows_for_plan": 243,
- "cost_for_plan": 123.8307617,
+ "cost_for_plan": 103.9153809,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -6943,18 +7514,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 243
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 441.2153809,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 878.0576904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 441.2153809,
+ "cost": 878.0576904,
"uses_join_buffering": true
}
}
@@ -6962,18 +7539,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 243
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 441.2153809,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 878.0576904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 441.2153809,
+ "cost": 878.0576904,
"uses_join_buffering": true
}
}
@@ -6989,11 +7572,11 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_2",
"rows_for_plan": 2187,
- "cost_for_plan": 1002.446143,
+ "cost_for_plan": 981.9730713,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 1002.446143,
- "best_cost": 509.4615234
+ "current_cost": 981.9730713,
+ "best_cost": 360.2293969
},
{
"plan_prefix": [
@@ -7004,11 +7587,11 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 2187,
- "cost_for_plan": 1002.446143,
+ "cost_for_plan": 981.9730713,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 1002.446143,
- "best_cost": 509.4615234
+ "current_cost": 981.9730713,
+ "best_cost": 360.2293969
}
]
},
@@ -7016,7 +7599,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"],
"table": "t_inner_2",
"rows_for_plan": 243,
- "cost_for_plan": 123.8307617,
+ "cost_for_plan": 103.9153809,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -7024,7 +7607,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"],
"table": "t_inner_3",
"rows_for_plan": 243,
- "cost_for_plan": 123.8307617,
+ "cost_for_plan": 103.9153809,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -7034,7 +7617,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1"],
"table": "t_inner_3",
"rows_for_plan": 81,
- "cost_for_plan": 45.62563477,
+ "cost_for_plan": 33.31281738,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -7044,7 +7627,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1"],
"table": "t_inner_2",
"rows_for_plan": 27,
- "cost_for_plan": 17.82050781,
+ "cost_for_plan": 11.76025391,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -7052,7 +7635,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1"],
"table": "t_inner_4",
"rows_for_plan": 9,
- "cost_for_plan": 9.410253906,
+ "cost_for_plan": 5.755126953,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -7060,7 +7643,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1"],
"table": "t_inner_3",
"rows_for_plan": 27,
- "cost_for_plan": 17.82050781,
+ "cost_for_plan": 11.76025391,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -7070,7 +7653,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_outer_2",
"rows_for_plan": 9,
- "cost_for_plan": 5.615380859,
+ "cost_for_plan": 3.25769043,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -7078,7 +7661,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_1",
"rows_for_plan": 3,
- "cost_for_plan": 3.205126953,
+ "cost_for_plan": 1.752563477,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -7086,7 +7669,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_2",
"rows_for_plan": 9,
- "cost_for_plan": 5.615380859,
+ "cost_for_plan": 3.25769043,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -7094,7 +7677,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_4",
"rows_for_plan": 3,
- "cost_for_plan": 3.205126953,
+ "cost_for_plan": 1.752563477,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -7102,7 +7685,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_3",
"rows_for_plan": 9,
- "cost_for_plan": 5.615380859,
+ "cost_for_plan": 3.25769043,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -7111,10 +7694,118 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"fix_semijoin_strategies_for_picked_join_order": [
{
- "semi_join_strategy": "DuplicateWeedout"
+ "semi_join_strategy": "FirstMatch",
+ "join_order": [
+ {
+ "table": "t_inner_4",
+ "best_access_path": {
+ "table": "t_inner_4",
+ "plan_details": {
+ "record_count": 27
+ },
+ "considered_access_paths": [
+ {
+ "access_type": "scan",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 47.31921387,
+ "index_only": false,
+ "chosen": true
+ }
+ ],
+ "chosen_access_method": {
+ "type": "scan",
+ "records": 3,
+ "cost": 47.31921387,
+ "uses_join_buffering": false
+ }
+ }
+ },
+ {
+ "table": "t_inner_3",
+ "best_access_path": {
+ "table": "t_inner_3",
+ "plan_details": {
+ "record_count": 81
+ },
+ "considered_access_paths": [
+ {
+ "access_type": "scan",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 263.8729248,
+ "index_only": false,
+ "chosen": true
+ }
+ ],
+ "chosen_access_method": {
+ "type": "scan",
+ "records": 9,
+ "cost": 263.8729248,
+ "uses_join_buffering": false
+ }
+ }
+ }
+ ]
},
{
- "semi_join_strategy": "DuplicateWeedout"
+ "semi_join_strategy": "FirstMatch",
+ "join_order": [
+ {
+ "table": "t_inner_1",
+ "best_access_path": {
+ "table": "t_inner_1",
+ "plan_details": {
+ "record_count": 3
+ },
+ "considered_access_paths": [
+ {
+ "access_type": "scan",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 5.25769043,
+ "index_only": false,
+ "chosen": true
+ }
+ ],
+ "chosen_access_method": {
+ "type": "scan",
+ "records": 3,
+ "cost": 5.25769043,
+ "uses_join_buffering": false
+ }
+ }
+ },
+ {
+ "table": "t_inner_2",
+ "best_access_path": {
+ "table": "t_inner_2",
+ "plan_details": {
+ "record_count": 9
+ },
+ "considered_access_paths": [
+ {
+ "access_type": "scan",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 29.31921387,
+ "index_only": false,
+ "chosen": true
+ }
+ ],
+ "chosen_access_method": {
+ "type": "scan",
+ "records": 9,
+ "cost": 29.31921387,
+ "uses_join_buffering": false
+ }
+ }
+ }
+ ]
}
]
},
@@ -7123,11 +7814,12 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"t_outer_1",
"t_inner_1",
"t_inner_2",
- "t_inner_4",
"t_outer_2",
+ "t_inner_4",
"t_inner_3"
],
- "cost": 509.4605234
+ "rows": 27,
+ "cost": 360.2292969
},
{
"substitute_best_equal": {
@@ -7152,11 +7844,11 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"attached": null
},
{
- "table": "t_inner_4",
+ "table": "t_outer_2",
"attached": null
},
{
- "table": "t_outer_2",
+ "table": "t_inner_4",
"attached": null
},
{
@@ -7347,42 +8039,48 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"table": "t_outer_1",
"table_scan": {
"rows": 3,
- "cost": 2.005126953
+ "read_cost": 1.002563477,
+ "read_and_compare_cost": 1.752563477
}
},
{
"table": "t_outer_2",
"table_scan": {
"rows": 9,
- "cost": 2.015380859
+ "read_cost": 1.00769043,
+ "read_and_compare_cost": 3.25769043
}
},
{
"table": "t_inner_2",
"table_scan": {
"rows": 9,
- "cost": 2.015380859
+ "read_cost": 1.00769043,
+ "read_and_compare_cost": 3.25769043
}
},
{
"table": "t_inner_1",
"table_scan": {
"rows": 3,
- "cost": 2.005126953
+ "read_cost": 1.002563477,
+ "read_and_compare_cost": 1.752563477
}
},
{
"table": "t_inner_3",
"table_scan": {
"rows": 9,
- "cost": 2.015380859
+ "read_cost": 1.00769043,
+ "read_and_compare_cost": 3.25769043
}
},
{
"table": "t_inner_4",
"table_scan": {
"rows": 3,
- "cost": 2.005126953
+ "read_cost": 1.002563477,
+ "read_and_compare_cost": 1.752563477
}
}
]
@@ -7408,18 +8106,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 3,
- "cost": 2.605126953,
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 1.752563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 2.605126953,
+ "cost": 1.752563477,
"uses_join_buffering": false
}
}
@@ -7427,18 +8131,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 9,
- "cost": 3.815380859,
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 3.25769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 3.815380859,
+ "cost": 3.25769043,
"uses_join_buffering": false
}
}
@@ -7449,7 +8159,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_1",
"rows_for_plan": 3,
- "cost_for_plan": 3.205126953,
+ "cost_for_plan": 1.752563477,
"rest_of_plan": [
{
"plan_prefix": ["t_inner_1"],
@@ -7457,18 +8167,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 9.215380859,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 10.00769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 9.215380859,
+ "cost": 10.00769043,
"uses_join_buffering": true
}
}
@@ -7479,7 +8195,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_inner_1"],
"table": "t_inner_2",
"rows_for_plan": 27,
- "cost_for_plan": 17.82050781
+ "cost_for_plan": 11.76025391
}
]
},
@@ -7487,7 +8203,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_2",
"rows_for_plan": 9,
- "cost_for_plan": 5.615380859,
+ "cost_for_plan": 3.25769043,
"pruned_by_heuristic": true
}
]
@@ -7500,18 +8216,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_4",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 3,
- "cost": 2.605126953,
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 1.752563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 2.605126953,
+ "cost": 1.752563477,
"uses_join_buffering": false
}
}
@@ -7519,18 +8241,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 9,
- "cost": 3.815380859,
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 3.25769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 3.815380859,
+ "cost": 3.25769043,
"uses_join_buffering": false
}
}
@@ -7541,7 +8269,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_4",
"rows_for_plan": 3,
- "cost_for_plan": 3.205126953,
+ "cost_for_plan": 1.752563477,
"rest_of_plan": [
{
"plan_prefix": ["t_inner_4"],
@@ -7549,18 +8277,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 9.215380859,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 10.00769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 9.215380859,
+ "cost": 10.00769043,
"uses_join_buffering": true
}
}
@@ -7571,7 +8305,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_inner_4"],
"table": "t_inner_3",
"rows_for_plan": 27,
- "cost_for_plan": 17.82050781
+ "cost_for_plan": 11.76025391
}
]
},
@@ -7579,7 +8313,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_3",
"rows_for_plan": 9,
- "cost_for_plan": 5.615380859,
+ "cost_for_plan": 3.25769043,
"pruned_by_heuristic": true
}
]
@@ -7595,18 +8329,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_outer_1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 3,
- "cost": 2.605126953,
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 1.752563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 2.605126953,
+ "cost": 1.752563477,
"uses_join_buffering": false
}
}
@@ -7614,18 +8354,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 3,
- "cost": 2.605126953,
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 1.752563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 2.605126953,
+ "cost": 1.752563477,
"uses_join_buffering": false
}
}
@@ -7633,18 +8379,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 9,
- "cost": 3.815380859,
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 3.25769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 3.815380859,
+ "cost": 3.25769043,
"uses_join_buffering": false
}
}
@@ -7652,18 +8404,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_outer_2",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 9,
- "cost": 3.815380859,
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 3.25769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 3.815380859,
+ "cost": 3.25769043,
"uses_join_buffering": false
}
}
@@ -7671,18 +8429,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_4",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 3,
- "cost": 2.605126953,
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 1.752563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 2.605126953,
+ "cost": 1.752563477,
"uses_join_buffering": false
}
}
@@ -7690,18 +8454,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 9,
- "cost": 3.815380859,
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 3.25769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 3.815380859,
+ "cost": 3.25769043,
"uses_join_buffering": false
}
}
@@ -7712,7 +8482,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_outer_1",
"rows_for_plan": 3,
- "cost_for_plan": 3.205126953,
+ "cost_for_plan": 1.752563477,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -7721,18 +8491,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_1",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 4.405126953,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 4.002563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 4.405126953,
+ "cost": 4.002563477,
"uses_join_buffering": true
}
}
@@ -7740,18 +8516,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 9.215380859,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 10.00769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 9.215380859,
+ "cost": 10.00769043,
"uses_join_buffering": true
}
}
@@ -7759,18 +8541,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_outer_2",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 9.215380859,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 10.00769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 9.215380859,
+ "cost": 10.00769043,
"uses_join_buffering": true
}
}
@@ -7778,18 +8566,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_4",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 4.405126953,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 4.002563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 4.405126953,
+ "cost": 4.002563477,
"uses_join_buffering": true
}
}
@@ -7797,18 +8591,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 9.215380859,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 10.00769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 9.215380859,
+ "cost": 10.00769043,
"uses_join_buffering": true
}
}
@@ -7819,7 +8619,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1"],
"table": "t_outer_2",
"rows_for_plan": 27,
- "cost_for_plan": 17.82050781,
+ "cost_for_plan": 11.76025391,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -7828,18 +8628,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 52.41538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 76.15769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 52.41538086,
+ "cost": 76.15769043,
"uses_join_buffering": true
}
}
@@ -7847,18 +8653,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_1",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 18.80512695,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 26.05256348,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 18.80512695,
+ "cost": 26.05256348,
"uses_join_buffering": true
}
}
@@ -7866,18 +8678,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_4",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 18.80512695,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 26.05256348,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 18.80512695,
+ "cost": 26.05256348,
"uses_join_buffering": true
}
}
@@ -7885,18 +8703,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 52.41538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 76.15769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 52.41538086,
+ "cost": 76.15769043,
"uses_join_buffering": true
}
}
@@ -7907,7 +8731,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2"],
"table": "t_inner_1",
"rows_for_plan": 81,
- "cost_for_plan": 52.82563477,
+ "cost_for_plan": 37.81281738,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -7916,18 +8740,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 81
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 149.6153809,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 258.4076904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 149.6153809,
+ "cost": 258.4076904,
"uses_join_buffering": true
}
}
@@ -7935,18 +8765,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_4",
+ "plan_details": {
+ "record_count": 81
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 51.20512695,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 86.80256348,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 51.20512695,
+ "cost": 86.80256348,
"uses_join_buffering": true
}
}
@@ -7954,18 +8790,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 81
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 149.6153809,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 258.4076904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 149.6153809,
+ "cost": 258.4076904,
"uses_join_buffering": true
}
}
@@ -7976,22 +8818,25 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2", "t_inner_1"],
"table": "t_inner_2",
"rows_for_plan": 729,
- "cost_for_plan": 348.2410156,
+ "cost_for_plan": 296.2205078,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
"records": 27,
- "read_time": 721.2047852
+ "cost": 322.9523926
},
{
"strategy": "SJ-Materialization",
"records": 27,
- "cost": 32.34101562
+ "cost": 27.22050781
},
{
"strategy": "DuplicateWeedout",
"records": 27,
- "read_time": 461.6410156
+ "dups_cost": 296.2205078,
+ "write_cost": 5.05,
+ "full_lookup_cost": 109.35,
+ "total_cost": 410.6205078
},
{
"chosen_strategy": "SJ-Materialization"
@@ -8009,18 +8854,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_4",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 18.80512695,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 34.15256348,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 18.80512695,
+ "cost": 34.15256348,
"uses_join_buffering": true
}
}
@@ -8028,18 +8879,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 52.41538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 100.4576904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 52.41538086,
+ "cost": 100.4576904,
"uses_join_buffering": true
}
}
@@ -8055,7 +8912,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_4",
"rows_for_plan": 81,
- "cost_for_plan": 67.34614258,
+ "cost_for_plan": 61.37307129,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -8070,18 +8927,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 81
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 149.6153809,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 331.3076904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 149.6153809,
+ "cost": 331.3076904,
"uses_join_buffering": true
}
}
@@ -8098,22 +8961,25 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 729,
- "cost_for_plan": 362.7615234,
+ "cost_for_plan": 392.6807617,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
"records": 27,
- "read_time": 735.725293
+ "cost": 338.4126465
},
{
"strategy": "SJ-Materialization",
"records": 27,
- "cost": 46.86152344
+ "cost": 42.68076172
},
{
"strategy": "DuplicateWeedout",
"records": 27,
- "read_time": 476.1615234
+ "dups_cost": 392.6807617,
+ "write_cost": 5.05,
+ "full_lookup_cost": 109.35,
+ "total_cost": 507.0807617
},
{
"chosen_strategy": "SJ-Materialization"
@@ -8131,11 +8997,11 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 243,
- "cost_for_plan": 133.3563965,
+ "cost_for_plan": 127.6781982,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 133.3563965,
- "best_cost": 46.86152344
+ "current_cost": 127.6781982,
+ "best_cost": 42.68086172
}
]
},
@@ -8143,21 +9009,21 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2", "t_inner_1"],
"table": "t_inner_4",
"rows_for_plan": 243,
- "cost_for_plan": 152.6307617,
+ "cost_for_plan": 124.6153809,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 152.6307617,
- "best_cost": 46.86152344
+ "current_cost": 124.6153809,
+ "best_cost": 42.68086172
},
{
"plan_prefix": ["t_outer_1", "t_outer_2", "t_inner_1"],
"table": "t_inner_3",
"rows_for_plan": 729,
- "cost_for_plan": 348.2410156,
+ "cost_for_plan": 296.2205078,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 348.2410156,
- "best_cost": 46.86152344
+ "current_cost": 296.2205078,
+ "best_cost": 42.68086172
}
]
},
@@ -8165,31 +9031,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_outer_2"],
"table": "t_inner_2",
"rows_for_plan": 243,
- "cost_for_plan": 118.8358887,
+ "cost_for_plan": 87.91794434,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 118.8358887,
- "best_cost": 46.86152344
+ "current_cost": 87.91794434,
+ "best_cost": 42.68086172
},
{
"plan_prefix": ["t_outer_1", "t_outer_2"],
"table": "t_inner_4",
"rows_for_plan": 81,
- "cost_for_plan": 52.82563477,
+ "cost_for_plan": 37.81281738,
"semijoin_strategy_choice": [],
- "pruned_by_cost": true,
- "current_cost": 52.82563477,
- "best_cost": 46.86152344
+ "pruned_by_heuristic": true
},
{
"plan_prefix": ["t_outer_1", "t_outer_2"],
"table": "t_inner_3",
"rows_for_plan": 243,
- "cost_for_plan": 118.8358887,
+ "cost_for_plan": 87.91794434,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 118.8358887,
- "best_cost": 46.86152344
+ "current_cost": 87.91794434,
+ "best_cost": 42.68086172
}
]
},
@@ -8197,7 +9061,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1"],
"table": "t_inner_1",
"rows_for_plan": 9,
- "cost_for_plan": 9.410253906,
+ "cost_for_plan": 5.755126953,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -8206,18 +9070,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 9
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 20.01538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 27.55769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 20.01538086,
+ "cost": 27.55769043,
"uses_join_buffering": true
}
}
@@ -8225,18 +9095,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_outer_2",
+ "plan_details": {
+ "record_count": 9
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 20.01538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 27.55769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 20.01538086,
+ "cost": 27.55769043,
"uses_join_buffering": true
}
}
@@ -8244,18 +9120,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_4",
+ "plan_details": {
+ "record_count": 9
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 8.005126953,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 9.852563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 8.005126953,
+ "cost": 9.852563477,
"uses_join_buffering": true
}
}
@@ -8263,18 +9145,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 9
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 20.01538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 27.55769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 20.01538086,
+ "cost": 27.55769043,
"uses_join_buffering": true
}
}
@@ -8285,7 +9173,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1"],
"table": "t_outer_2",
"rows_for_plan": 81,
- "cost_for_plan": 45.62563477,
+ "cost_for_plan": 33.31281738,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -8294,18 +9182,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_2",
+ "plan_details": {
+ "record_count": 81
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 149.6153809,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 258.4076904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 149.6153809,
+ "cost": 258.4076904,
"uses_join_buffering": true
}
}
@@ -8313,18 +9207,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_4",
+ "plan_details": {
+ "record_count": 81
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 51.20512695,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 86.80256348,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 51.20512695,
+ "cost": 86.80256348,
"uses_join_buffering": true
}
}
@@ -8332,18 +9232,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 81
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 149.6153809,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 258.4076904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 149.6153809,
+ "cost": 258.4076904,
"uses_join_buffering": true
}
}
@@ -8354,40 +9260,43 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"],
"table": "t_inner_2",
"rows_for_plan": 729,
- "cost_for_plan": 341.0410156,
+ "cost_for_plan": 291.7205078,
"semijoin_strategy_choice": [
{
"strategy": "DuplicateWeedout",
"records": 27,
- "read_time": 454.4410156
+ "dups_cost": 291.7205078,
+ "write_cost": 5.05,
+ "full_lookup_cost": 109.35,
+ "total_cost": 406.1205078
},
{
"chosen_strategy": "DuplicateWeedout"
}
],
"pruned_by_cost": true,
- "current_cost": 454.4410156,
- "best_cost": 46.86152344
+ "current_cost": 406.1205078,
+ "best_cost": 42.68086172
},
{
"plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"],
"table": "t_inner_4",
"rows_for_plan": 243,
- "cost_for_plan": 145.4307617,
+ "cost_for_plan": 120.1153809,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 145.4307617,
- "best_cost": 46.86152344
+ "current_cost": 120.1153809,
+ "best_cost": 42.68086172
},
{
"plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"],
"table": "t_inner_3",
"rows_for_plan": 729,
- "cost_for_plan": 341.0410156,
+ "cost_for_plan": 291.7205078,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 341.0410156,
- "best_cost": 46.86152344
+ "current_cost": 291.7205078,
+ "best_cost": 42.68086172
}
]
},
@@ -8395,22 +9304,25 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1"],
"table": "t_inner_2",
"rows_for_plan": 81,
- "cost_for_plan": 45.62563477,
+ "cost_for_plan": 33.31281738,
"semijoin_strategy_choice": [
{
"strategy": "FirstMatch",
"records": 3,
- "read_time": 81.35893555
+ "cost": 36.32946777
},
{
"strategy": "SJ-Materialization",
"records": 3,
- "cost": 16.52563477
+ "cost": 16.01281738
},
{
"strategy": "DuplicateWeedout",
"records": 3,
- "read_time": 58.22563477
+ "dups_cost": 33.31281738,
+ "write_cost": 1.45,
+ "full_lookup_cost": 12.15,
+ "total_cost": 46.91281738
},
{
"chosen_strategy": "SJ-Materialization"
@@ -8423,18 +9335,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_outer_2",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 9.215380859,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 12.70769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 9.215380859,
+ "cost": 12.70769043,
"uses_join_buffering": true
}
}
@@ -8442,18 +9360,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_4",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 4.405126953,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 4.902563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 4.405126953,
+ "cost": 4.902563477,
"uses_join_buffering": true
}
}
@@ -8461,18 +9385,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 3
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 9.215380859,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 12.70769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 9.215380859,
+ "cost": 12.70769043,
"uses_join_buffering": true
}
}
@@ -8483,7 +9413,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"],
"table": "t_outer_2",
"rows_for_plan": 27,
- "cost_for_plan": 31.14101563,
+ "cost_for_plan": 28.72050781,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -8497,18 +9427,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_4",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 3,
- "cost": 18.80512695,
+ "access_type": "scan_with_join_cache",
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 34.15256348,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 18.80512695,
+ "cost": 34.15256348,
"uses_join_buffering": true
}
}
@@ -8516,18 +9452,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 27
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 52.41538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 100.4576904,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 52.41538086,
+ "cost": 100.4576904,
"uses_join_buffering": true
}
}
@@ -8543,11 +9485,11 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_4",
"rows_for_plan": 81,
- "cost_for_plan": 66.14614258,
+ "cost_for_plan": 62.87307129,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 66.14614258,
- "best_cost": 46.86152344
+ "current_cost": 62.87307129,
+ "best_cost": 42.68086172
},
{
"plan_prefix": [
@@ -8558,11 +9500,11 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 243,
- "cost_for_plan": 132.1563965,
+ "cost_for_plan": 129.1781982,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 132.1563965,
- "best_cost": 46.86152344
+ "current_cost": 129.1781982,
+ "best_cost": 42.68086172
}
]
},
@@ -8570,7 +9512,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"],
"table": "t_inner_4",
"rows_for_plan": 9,
- "cost_for_plan": 22.73076172,
+ "cost_for_plan": 20.91538086,
"semijoin_strategy_choice": [],
"rest_of_plan": [
{
@@ -8584,18 +9526,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_outer_2",
+ "plan_details": {
+ "record_count": 9
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 20.01538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 35.65769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 20.01538086,
+ "cost": 35.65769043,
"uses_join_buffering": true
}
}
@@ -8603,18 +9551,24 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
{
"best_access_path": {
"table": "t_inner_3",
+ "plan_details": {
+ "record_count": 9
+ },
"considered_access_paths": [
{
- "access_type": "scan",
- "resulting_rows": 9,
- "cost": 20.01538086,
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 35.65769043,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 9,
- "cost": 20.01538086,
+ "cost": 35.65769043,
"uses_join_buffering": true
}
}
@@ -8630,11 +9584,11 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_outer_2",
"rows_for_plan": 81,
- "cost_for_plan": 58.94614258,
+ "cost_for_plan": 56.57307129,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 58.94614258,
- "best_cost": 46.86152344
+ "current_cost": 56.57307129,
+ "best_cost": 42.68086172
},
{
"plan_prefix": [
@@ -8645,11 +9599,11 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
],
"table": "t_inner_3",
"rows_for_plan": 81,
- "cost_for_plan": 58.94614258,
+ "cost_for_plan": 56.57307129,
"semijoin_strategy_choice": [],
"pruned_by_cost": true,
- "current_cost": 58.94614258,
- "best_cost": 46.86152344
+ "current_cost": 56.57307129,
+ "best_cost": 42.68086172
}
]
},
@@ -8657,7 +9611,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"],
"table": "t_inner_3",
"rows_for_plan": 27,
- "cost_for_plan": 31.14101563,
+ "cost_for_plan": 28.72050781,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -8667,15 +9621,126 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1", "t_inner_1"],
"table": "t_inner_4",
"rows_for_plan": 27,
- "cost_for_plan": 22.81538086,
+ "cost_for_plan": 15.60769043,
"semijoin_strategy_choice": [],
- "pruned_by_heuristic": true
+ "rest_of_plan": [
+ {
+ "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"],
+ "get_costs_for_tables": [
+ {
+ "best_access_path": {
+ "table": "t_outer_2",
+ "plan_details": {
+ "record_count": 27
+ },
+ "considered_access_paths": [
+ {
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 88.30769043,
+ "index_only": false,
+ "chosen": true
+ }
+ ],
+ "chosen_access_method": {
+ "type": "scan",
+ "records": 9,
+ "cost": 88.30769043,
+ "uses_join_buffering": true
+ }
+ }
+ },
+ {
+ "best_access_path": {
+ "table": "t_inner_2",
+ "plan_details": {
+ "record_count": 27
+ },
+ "considered_access_paths": [
+ {
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 88.30769043,
+ "index_only": false,
+ "chosen": true
+ }
+ ],
+ "chosen_access_method": {
+ "type": "scan",
+ "records": 9,
+ "cost": 88.30769043,
+ "uses_join_buffering": true
+ }
+ }
+ },
+ {
+ "best_access_path": {
+ "table": "t_inner_3",
+ "plan_details": {
+ "record_count": 27
+ },
+ "considered_access_paths": [
+ {
+ "access_type": "scan_with_join_cache",
+ "rows": 9,
+ "rows_after_scan": 9,
+ "rows_after_filter": 9,
+ "cost": 88.30769043,
+ "index_only": false,
+ "chosen": true
+ }
+ ],
+ "chosen_access_method": {
+ "type": "scan",
+ "records": 9,
+ "cost": 88.30769043,
+ "uses_join_buffering": true
+ }
+ }
+ }
+ ]
+ },
+ {
+ "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"],
+ "table": "t_outer_2",
+ "rows_for_plan": 243,
+ "cost_for_plan": 103.9153809,
+ "semijoin_strategy_choice": [],
+ "pruned_by_cost": true,
+ "current_cost": 103.9153809,
+ "best_cost": 42.68086172
+ },
+ {
+ "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"],
+ "table": "t_inner_2",
+ "rows_for_plan": 243,
+ "cost_for_plan": 103.9153809,
+ "semijoin_strategy_choice": [],
+ "pruned_by_cost": true,
+ "current_cost": 103.9153809,
+ "best_cost": 42.68086172
+ },
+ {
+ "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"],
+ "table": "t_inner_3",
+ "rows_for_plan": 243,
+ "cost_for_plan": 103.9153809,
+ "semijoin_strategy_choice": [],
+ "pruned_by_cost": true,
+ "current_cost": 103.9153809,
+ "best_cost": 42.68086172
+ }
+ ]
},
{
"plan_prefix": ["t_outer_1", "t_inner_1"],
"table": "t_inner_3",
"rows_for_plan": 81,
- "cost_for_plan": 45.62563477,
+ "cost_for_plan": 33.31281738,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -8685,7 +9750,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1"],
"table": "t_inner_2",
"rows_for_plan": 27,
- "cost_for_plan": 17.82050781,
+ "cost_for_plan": 11.76025391,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -8693,7 +9758,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1"],
"table": "t_inner_4",
"rows_for_plan": 9,
- "cost_for_plan": 9.410253906,
+ "cost_for_plan": 5.755126953,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -8701,7 +9766,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": ["t_outer_1"],
"table": "t_inner_3",
"rows_for_plan": 27,
- "cost_for_plan": 17.82050781,
+ "cost_for_plan": 11.76025391,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -8711,7 +9776,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_outer_2",
"rows_for_plan": 9,
- "cost_for_plan": 5.615380859,
+ "cost_for_plan": 3.25769043,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -8719,7 +9784,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_1",
"rows_for_plan": 3,
- "cost_for_plan": 3.205126953,
+ "cost_for_plan": 1.752563477,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -8727,7 +9792,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_2",
"rows_for_plan": 9,
- "cost_for_plan": 5.615380859,
+ "cost_for_plan": 3.25769043,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -8735,7 +9800,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_4",
"rows_for_plan": 3,
- "cost_for_plan": 3.205126953,
+ "cost_for_plan": 1.752563477,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
},
@@ -8743,7 +9808,7 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"plan_prefix": [],
"table": "t_inner_3",
"rows_for_plan": 9,
- "cost_for_plan": 5.615380859,
+ "cost_for_plan": 3.25769043,
"semijoin_strategy_choice": [],
"pruned_by_heuristic": true
}
@@ -8782,7 +9847,8 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"<subquery2>",
"<subquery3>"
],
- "cost": 46.86052344
+ "rows": 27,
+ "cost": 42.68076172
},
{
"substitute_best_equal": {
@@ -8886,7 +9952,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": true,
"rows": 1,
- "cost": 0.345829876,
+ "cost": 0.745829876,
"chosen": true
}
],
@@ -8915,7 +9981,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": true,
"rows": 107,
- "cost": 21.63379668,
+ "cost": 24.68379668,
"chosen": true
}
],
@@ -8947,7 +10013,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 1000,
- "cost": 1203.877243,
+ "cost": 756.2522431,
"chosen": true
}
],
@@ -8987,7 +10053,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 4,
- "cost": 4.948710032,
+ "cost": 3.523710032,
"chosen": true
}
],
@@ -9021,7 +10087,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.346171589,
+ "cost": 1.271171589,
"chosen": true
}
],
@@ -9050,7 +10116,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.346171589,
+ "cost": 1.271171589,
"chosen": true
}
],
@@ -9087,7 +10153,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.345927508,
+ "cost": 1.270927508,
"chosen": true
}
],
@@ -9117,7 +10183,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.345878692,
+ "cost": 1.270878692,
"chosen": true
}
],
@@ -9147,7 +10213,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.345927508,
+ "cost": 1.270927508,
"chosen": true
}
],
@@ -9180,7 +10246,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.345878692,
+ "cost": 1.270878692,
"chosen": true
}
],
@@ -9216,7 +10282,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.394255553,
+ "cost": 1.319255553,
"chosen": true
}
],
@@ -9235,7 +10301,7 @@ INSERT INTO t1 VALUES (2, 'ab\n');
set optimizer_trace=1;
EXPLAIN SELECT * FROM t1 WHERE b='ab\n';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref i_b i_b 13 const 2 Using index condition
+1 SIMPLE t1 ALL i_b NULL NULL NULL 2 Using where
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
[
@@ -9250,8 +10316,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 2,
- "cost": 2.546855016,
- "chosen": true
+ "cost": 2.021855016,
+ "chosen": false,
+ "cause": "cost"
}
],
"analyzing_roworder_intersect":
@@ -9305,7 +10372,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 1000,
- "cost": 1203.877243,
+ "cost": 756.2522431,
"chosen": true
}
],
@@ -9363,12 +10430,19 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"best_access_path":
{
"table": "A",
+ "plan_details":
+ {
+ "record_count": 1
+ },
"considered_access_paths":
[
{
"access_type": "scan",
- "resulting_rows": 5,
- "cost": 4.017089844,
+ "rows": 10,
+ "rows_after_scan": 5,
+ "rows_after_filter": 5,
+ "cost": 3.508544922,
+ "index_only": false,
"chosen": true
}
],
@@ -9376,7 +10450,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
{
"type": "scan",
"records": 5,
- "cost": 4.017089844,
+ "cost": 3.508544922,
"uses_join_buffering": false
}
}
@@ -9385,12 +10459,19 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"best_access_path":
{
"table": "B",
+ "plan_details":
+ {
+ "record_count": 1
+ },
"considered_access_paths":
[
{
"access_type": "scan",
- "resulting_rows": 800,
- "cost": 204.1972656,
+ "rows": 1000,
+ "rows_after_scan": 800,
+ "rows_after_filter": 800,
+ "cost": 252.0986328,
+ "index_only": false,
"chosen": true
}
],
@@ -9398,7 +10479,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
{
"type": "scan",
"records": 800,
- "cost": 204.1972656,
+ "cost": 252.0986328,
"uses_join_buffering": false
}
}
@@ -9410,7 +10491,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
[],
"table": "A",
"rows_for_plan": 5,
- "cost_for_plan": 5.017089844,
+ "cost_for_plan": 3.508544922,
"rest_of_plan":
[
{
@@ -9422,12 +10503,19 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"best_access_path":
{
"table": "B",
+ "plan_details":
+ {
+ "record_count": 5
+ },
"considered_access_paths":
[
{
"access_type": "scan",
- "resulting_rows": 800,
- "cost": 1820.986328,
+ "rows": 1000,
+ "rows_after_scan": 800,
+ "rows_after_filter": 800,
+ "cost": 1260.493164,
+ "index_only": false,
"chosen": true
}
],
@@ -9435,7 +10523,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
{
"type": "scan",
"records": 800,
- "cost": 1820.986328,
+ "cost": 1260.493164,
"uses_join_buffering": false
}
}
@@ -9447,7 +10535,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
["A"],
"table": "B",
"rows_for_plan": 4000,
- "cost_for_plan": 2626.003418
+ "cost_for_plan": 1264.001709
}
]
},
@@ -9456,7 +10544,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
[],
"table": "B",
"rows_for_plan": 800,
- "cost_for_plan": 364.1972656,
+ "cost_for_plan": 252.0986328,
"pruned_by_heuristic": true
}
]
@@ -9480,12 +10568,19 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"best_access_path":
{
"table": "A",
+ "plan_details":
+ {
+ "record_count": 1
+ },
"considered_access_paths":
[
{
"access_type": "scan",
- "resulting_rows": 10,
- "cost": 4.017089844,
+ "rows": 10,
+ "rows_after_scan": 10,
+ "rows_after_filter": 10,
+ "cost": 3.508544922,
+ "index_only": false,
"chosen": true
}
],
@@ -9493,7 +10588,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
{
"type": "scan",
"records": 10,
- "cost": 4.017089844,
+ "cost": 3.508544922,
"uses_join_buffering": false
}
}
@@ -9502,12 +10597,19 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"best_access_path":
{
"table": "B",
+ "plan_details":
+ {
+ "record_count": 1
+ },
"considered_access_paths":
[
{
"access_type": "scan",
- "resulting_rows": 800,
- "cost": 204.1972656,
+ "rows": 1000,
+ "rows_after_scan": 800,
+ "rows_after_filter": 800,
+ "cost": 252.0986328,
+ "index_only": false,
"chosen": true
}
],
@@ -9515,7 +10617,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
{
"type": "scan",
"records": 800,
- "cost": 204.1972656,
+ "cost": 252.0986328,
"uses_join_buffering": false
}
}
@@ -9527,7 +10629,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
[],
"table": "A",
"rows_for_plan": 10,
- "cost_for_plan": 6.017089844,
+ "cost_for_plan": 3.508544922,
"rest_of_plan":
[
{
@@ -9539,6 +10641,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"best_access_path":
{
"table": "B",
+ "plan_details":
+ {
+ "record_count": 10
+ },
"considered_access_paths":
[
{
@@ -9547,16 +10653,16 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"used_range_estimates": false,
"reason": "not available",
"rows": 1,
- "cond_check_cost": 2.200585794,
- "startup_cost": 0,
- "rows_after_filter": 1,
- "cost": 22.00585794,
+ "cost": 12.50585794,
"chosen": true
},
{
- "access_type": "scan",
- "resulting_rows": 600,
- "cost": 1404.197266,
+ "access_type": "scan_with_join_cache",
+ "rows": 1000,
+ "rows_after_scan": 600,
+ "rows_after_filter": 600,
+ "cost": 1752.098633,
+ "index_only": false,
"chosen": false
}
],
@@ -9564,7 +10670,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
{
"type": "ref",
"records": 1,
- "cost": 22.00585794,
+ "cost": 12.50585794,
"uses_join_buffering": false
}
}
@@ -9576,7 +10682,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
["A"],
"table": "B",
"rows_for_plan": 10,
- "cost_for_plan": 30.02294779,
+ "cost_for_plan": 16.01440287,
"selectivity": 0.8,
"estimated_join_cardinality": 8
}
@@ -9587,10 +10693,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
[],
"table": "B",
"rows_for_plan": 800,
- "cost_for_plan": 364.1972656,
+ "cost_for_plan": 252.0986328,
"pruned_by_cost": true,
- "current_cost": 364.1972656,
- "best_cost": 30.02294779
+ "current_cost": 252.0986328,
+ "best_cost": 16.01450287
}
]
]
@@ -9619,7 +10725,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.357887479,
+ "cost": 1.282887479,
"chosen": true
}
],
@@ -9644,9 +10750,9 @@ insert into t3 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
explain
select * from t3 where (a,a) in (select t1.a, t2.a from t1, t2 where t1.b=t2.b);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 5
-1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using where
-1 PRIMARY t3 ALL NULL NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t3 ALL NULL NULL NULL NULL 10 Using where
+1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t3.a 1 Using where
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.semijoin_table_pullout')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
JSON_DETAILED(JSON_EXTRACT(trace, '$**.semijoin_table_pullout'))
[
@@ -9679,7 +10785,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.range_scan_alternatives'))
"using_mrr": false,
"index_only": true,
"rows": 1,
- "cost": 0.345829876,
+ "cost": 0.745829876,
"chosen": true
}
]
@@ -9710,12 +10816,19 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"best_access_path":
{
"table": "t1",
+ "plan_details":
+ {
+ "record_count": 1
+ },
"considered_access_paths":
[
{
"access_type": "scan",
- "resulting_rows": 10,
- "cost": 4.021972656,
+ "rows": 10,
+ "rows_after_scan": 10,
+ "rows_after_filter": 10,
+ "cost": 3.510986328,
+ "index_only": false,
"chosen": true
}
],
@@ -9723,7 +10836,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
{
"type": "scan",
"records": 10,
- "cost": 4.021972656,
+ "cost": 3.510986328,
"uses_join_buffering": false
}
}
@@ -9732,12 +10845,19 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"best_access_path":
{
"table": "t2",
+ "plan_details":
+ {
+ "record_count": 1
+ },
"considered_access_paths":
[
{
"access_type": "scan",
- "resulting_rows": 100,
- "cost": 22.21972656,
+ "rows": 100,
+ "rows_after_scan": 100,
+ "rows_after_filter": 100,
+ "cost": 26.10986328,
+ "index_only": false,
"chosen": true,
"use_tmp_table": true
}
@@ -9746,7 +10866,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
{
"type": "scan",
"records": 100,
- "cost": 22.21972656,
+ "cost": 26.10986328,
"uses_join_buffering": false
}
}
@@ -9758,7 +10878,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
[],
"table": "t1",
"rows_for_plan": 10,
- "cost_for_plan": 6.021972656,
+ "cost_for_plan": 3.510986328,
"rest_of_plan":
[
{
@@ -9770,6 +10890,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"best_access_path":
{
"table": "t2",
+ "plan_details":
+ {
+ "record_count": 10
+ },
"considered_access_paths":
[
{
@@ -9778,16 +10902,16 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"used_range_estimates": false,
"reason": "not available",
"rows": 1,
- "cond_check_cost": 2.200585794,
- "startup_cost": 0,
- "rows_after_filter": 1,
- "cost": 22.00585794,
+ "cost": 12.50585794,
"chosen": true
},
{
- "access_type": "scan",
- "resulting_rows": 75,
- "cost": 172.2197266,
+ "access_type": "scan_with_join_cache",
+ "rows": 100,
+ "rows_after_scan": 75,
+ "rows_after_filter": 75,
+ "cost": 213.6098633,
+ "index_only": false,
"chosen": false
}
],
@@ -9795,7 +10919,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
{
"type": "ref",
"records": 1,
- "cost": 22.00585794,
+ "cost": 12.50585794,
"uses_join_buffering": false
}
}
@@ -9807,7 +10931,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
["t1"],
"table": "t2",
"rows_for_plan": 10,
- "cost_for_plan": 30.0278306,
+ "cost_for_plan": 16.01684427,
"cost_for_sorting": 10
}
]
@@ -9817,10 +10941,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
[],
"table": "t2",
"rows_for_plan": 100,
- "cost_for_plan": 42.21972656,
+ "cost_for_plan": 26.10986328,
"pruned_by_cost": true,
- "current_cost": 42.21972656,
- "best_cost": 40.0278306
+ "current_cost": 26.10986328,
+ "best_cost": 26.01694427
}
]
]
@@ -9918,7 +11042,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.range_scan_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 0,
- "cost": 0.145,
+ "cost": 0.52,
"chosen": true
}
]
@@ -10020,7 +11144,8 @@ select count(*) from seq_1_to_10000000 {
"table": "seq_1_to_10000000",
"table_scan": {
"rows": 10000000,
- "cost": 10000000
+ "read_cost": 5000000,
+ "read_and_compare_cost": 7250000
}
}
]
@@ -10033,18 +11158,24 @@ select count(*) from seq_1_to_10000000 {
{
"best_access_path": {
"table": "seq_1_to_10000000",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 10000000,
- "cost": 12000000,
+ "rows": 10000000,
+ "rows_after_scan": 10000000,
+ "rows_after_filter": 10000000,
+ "cost": 7250000,
+ "index_only": true,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 10000000,
- "cost": 12000000,
+ "cost": 7250000,
"uses_join_buffering": false
}
}
@@ -10055,13 +11186,14 @@ select count(*) from seq_1_to_10000000 {
"plan_prefix": [],
"table": "seq_1_to_10000000",
"rows_for_plan": 10000000,
- "cost_for_plan": 14000000
+ "cost_for_plan": 7250000
}
]
},
{
"best_join_order": ["seq_1_to_10000000"],
- "cost": 14000000
+ "rows": 10000000,
+ "cost": 7250000
},
{
"attaching_conditions_to_tables": {
@@ -10124,9 +11256,8 @@ set @tmp=@@in_predicate_conversion_threshold;
set in_predicate_conversion_threshold=3;
explain select * from t0 where a in (1,2,3,4,5,6);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t0 ALL NULL NULL NULL NULL 10
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 6
+1 PRIMARY t0 ALL NULL NULL NULL NULL 10 Using where
+1 PRIMARY <derived3> ref key0 key0 4 test.t0.a 2 FirstMatch(t0)
3 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used
select json_detailed(json_extract(trace, '$**.in_to_subquery_conversion'))
from information_schema.optimizer_trace;
@@ -10210,9 +11341,9 @@ create table t3 (a int, b int, c int);
insert into t3 values (0,0,0),(1,1,1),(2,2,2),(3,3,3),(4,4,4);
explain select * from t2,t1,t3 where t2.b= t1.b and t1.a=t3.a;
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 index PRIMARY PRIMARY 12 NULL 5 Using where; Using index; Using join buffer (flat, BNL join)
-1 SIMPLE t3 ALL NULL NULL NULL NULL 5 Using where; Using join buffer (incremental, BNL join)
+1 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using where
+1 SIMPLE t3 ALL NULL NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t1 ref PRIMARY PRIMARY 8 test.t3.a,test.t2.b 1 Using index
set @trace=(select trace from information_schema.optimizer_trace);
set @path= (select json_search(@trace, 'one', 'no predicate for first keypart'));
set @sub_path= substr(@path, 2, locate('.best_access_path', @path)-2);
@@ -10410,6 +11541,10 @@ json_detailed(json_extract(trace, '$**.choose_best_splitting'))
"best_access_path":
{
"table": "t2",
+ "plan_details":
+ {
+ "record_count": 1
+ },
"considered_access_paths":
[
{
@@ -10418,10 +11553,7 @@ json_detailed(json_extract(trace, '$**.choose_best_splitting'))
"used_range_estimates": false,
"reason": "not available",
"rows": 1.8367,
- "cond_check_cost": 2.367925794,
- "startup_cost": 0,
- "rows_after_filter": 1.8367,
- "cost": 2.367925794,
+ "cost": 1.417925794,
"chosen": true
},
{
@@ -10434,7 +11566,7 @@ json_detailed(json_extract(trace, '$**.choose_best_splitting'))
{
"type": "ref",
"records": 1.8367,
- "cost": 2.367925794,
+ "cost": 1.417925794,
"uses_join_buffering": false
}
}
@@ -10446,7 +11578,7 @@ json_detailed(json_extract(trace, '$**.choose_best_splitting'))
[],
"table": "t2",
"rows_for_plan": 1.8367,
- "cost_for_plan": 2.735265794,
+ "cost_for_plan": 1.417925794,
"cost_for_sorting": 1.8367
}
]
@@ -10457,8 +11589,8 @@ json_detailed(json_extract(trace, '$**.choose_best_splitting'))
"table": "t2",
"key": "idx_a",
"record_count": 4,
- "cost": 2.856285919,
- "unsplit_cost": 43.72361682
+ "cost": 3.651150919,
+ "unsplit_cost": 46.6794762
}
}
]
@@ -10470,8 +11602,8 @@ information_schema.optimizer_trace;
json_detailed(json_extract(trace, '$**.lateral_derived'))
[
{
- "startup_cost": 11.42514368,
- "splitting_cost": 2.856285919,
+ "startup_cost": 14.60460368,
+ "splitting_cost": 3.651150919,
"records": 1
}
]
diff --git a/mysql-test/main/opt_trace_index_merge.result b/mysql-test/main/opt_trace_index_merge.result
index 5944bfc8c3f..5407af41fd5 100644
--- a/mysql-test/main/opt_trace_index_merge.result
+++ b/mysql-test/main/opt_trace_index_merge.result
@@ -73,7 +73,7 @@ explain select * from t1 where a=1 or b=1 {
"range_analysis": {
"table_scan": {
"rows": 1000,
- "cost": 231.5878906
+ "cost": 264.7939453
},
"potential_range_indexes": [
{
@@ -111,12 +111,12 @@ explain select * from t1 where a=1 or b=1 {
"using_mrr": false,
"index_only": true,
"rows": 1,
- "cost": 0.345585794,
+ "cost": 0.745585794,
"chosen": true
}
],
"index_to_merge": "a",
- "cumulated_cost": 0.345585794
+ "cumulated_cost": 0.745585794
},
{
"range_scan_alternatives": [
@@ -127,15 +127,15 @@ explain select * from t1 where a=1 or b=1 {
"using_mrr": false,
"index_only": true,
"rows": 1,
- "cost": 0.345585794,
+ "cost": 0.745585794,
"chosen": true
}
],
"index_to_merge": "b",
- "cumulated_cost": 0.691171589
+ "cumulated_cost": 1.491171589
}
],
- "cost_of_reading_ranges": 0.691171589,
+ "cost_of_reading_ranges": 1.491171589,
"use_roworder_union": true,
"cause": "always cheaper than non roworder retrieval",
"analyzing_roworder_scans": [
@@ -158,7 +158,7 @@ explain select * from t1 where a=1 or b=1 {
}
}
],
- "index_roworder_union_cost": 2.484903732,
+ "index_roworder_union_cost": 2.595171589,
"members": 2,
"chosen": true
}
@@ -187,7 +187,7 @@ explain select * from t1 where a=1 or b=1 {
]
},
"rows_for_plan": 2,
- "cost_for_plan": 2.484903732,
+ "cost_for_plan": 2.595171589,
"chosen": true
}
}
@@ -211,18 +211,23 @@ explain select * from t1 where a=1 or b=1 {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "index_merge",
- "resulting_rows": 2,
- "cost": 2.484903732,
+ "rows": 2,
+ "rows_after_scan": 2,
+ "rows_after_filter": 2,
+ "cost": 2.595171589,
"chosen": true
}
],
"chosen_access_method": {
"type": "index_merge",
"records": 2,
- "cost": 2.484903732,
+ "cost": 2.595171589,
"uses_join_buffering": false
}
}
@@ -233,13 +238,14 @@ explain select * from t1 where a=1 or b=1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 2,
- "cost_for_plan": 2.884903732
+ "cost_for_plan": 2.595171589
}
]
},
{
"best_join_order": ["t1"],
- "cost": 2.883903732
+ "rows": 2,
+ "cost": 2.595171589
},
{
"substitute_best_equal": {
@@ -320,7 +326,7 @@ set optimizer_trace='enabled=on';
# 3-way ROR-intersection
explain select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 index_merge key1,key2,key3 key1,key2,key3 5,5,5 NULL 2 Using intersect(key1,key2,key3); Using where; Using index
+1 SIMPLE t1 index_merge key1,key2,key3 key1,key2 5,5 NULL 77 Using intersect(key1,key2); Using where
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
[
@@ -335,7 +341,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 2243,
- "cost": 2700.058937,
+ "cost": 1695.083937,
"chosen": true
},
{
@@ -346,7 +352,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 2243,
- "cost": 2700.058937,
+ "cost": 1695.083937,
"chosen": false,
"cause": "cost"
},
@@ -358,7 +364,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 2243,
- "cost": 2700.058937,
+ "cost": 1695.083937,
"chosen": false,
"cause": "cost"
}
@@ -369,10 +375,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
[
{
"index": "key1",
- "index_scan_cost": 10.31393703,
- "cumulated_index_scan_cost": 10.31393703,
- "disk_sweep_cost": 1923.144061,
- "cumulative_total_cost": 1933.457998,
+ "index_scan_cost": 61.88893703,
+ "cumulated_index_scan_cost": 61.88893703,
+ "disk_sweep_cost": 1682.25,
+ "cumulative_total_cost": 1744.138937,
"usable": true,
"matching_rows_now": 2243,
"intersect_covering_with_this_index": false,
@@ -380,10 +386,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
},
{
"index": "key2",
- "index_scan_cost": 10.31393703,
- "cumulated_index_scan_cost": 20.62787405,
- "disk_sweep_cost": 84.51771758,
- "cumulative_total_cost": 105.1455916,
+ "index_scan_cost": 61.88893703,
+ "cumulated_index_scan_cost": 123.7778741,
+ "disk_sweep_cost": 57.75,
+ "cumulative_total_cost": 181.5278741,
"usable": true,
"matching_rows_now": 77.6360508,
"intersect_covering_with_this_index": false,
@@ -391,14 +397,15 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
},
{
"index": "key3",
- "index_scan_cost": 10.31393703,
- "cumulated_index_scan_cost": 30.94181108,
+ "index_scan_cost": 61.88893703,
+ "cumulated_index_scan_cost": 185.6668111,
"disk_sweep_cost": 0,
- "cumulative_total_cost": 30.94181108,
+ "cumulative_total_cost": 185.6668111,
"usable": true,
"matching_rows_now": 2.687185191,
"intersect_covering_with_this_index": true,
- "chosen": true
+ "chosen": false,
+ "cause": "does not reduce cost"
}
],
"clustered_pk":
@@ -406,9 +413,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"clustered_pk_added_to_intersect": false,
"cause": "no clustered pk index"
},
- "rows": 2,
- "cost": 30.94181108,
- "covering": true,
+ "rows": 77,
+ "cost": 197.0550842,
+ "covering": false,
"chosen": true
},
"analyzing_index_merge_union":
@@ -422,9 +429,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary'))
"range_access_plan":
{
"type": "index_roworder_intersect",
- "rows": 2,
- "cost": 30.94181108,
- "covering": true,
+ "rows": 77,
+ "cost": 197.0550842,
+ "covering": false,
"clustered_pk_scan": false,
"intersect_of":
[
@@ -441,18 +448,11 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary'))
"rows": 2243,
"ranges":
["(100) <= (key2) <= (100)"]
- },
- {
- "type": "range_scan",
- "index": "key3",
- "rows": 2243,
- "ranges":
- ["(100) <= (key3) <= (100)"]
}
]
},
- "rows_for_plan": 2,
- "cost_for_plan": 30.94181108,
+ "rows_for_plan": 77,
+ "cost_for_plan": 197.0550842,
"chosen": true
}
]
@@ -486,7 +486,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": true,
"rows": 2243,
- "cost": 457.058937,
+ "cost": 517.508937,
"chosen": true
},
{
@@ -497,13 +497,13 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": true,
"rows": 2243,
- "cost": 457.058937,
+ "cost": 517.508937,
"chosen": false,
"cause": "cost"
}
],
"index_to_merge": "key1",
- "cumulated_cost": 457.058937
+ "cumulated_cost": 517.508937
},
{
"range_scan_alternatives":
@@ -516,7 +516,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": true,
"rows": 2243,
- "cost": 457.058937,
+ "cost": 517.508937,
"chosen": true
},
{
@@ -527,16 +527,16 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": true,
"rows": 2243,
- "cost": 457.058937,
+ "cost": 517.508937,
"chosen": false,
"cause": "cost"
}
],
"index_to_merge": "key3",
- "cumulated_cost": 914.1178741
+ "cumulated_cost": 1035.017874
}
],
- "cost_of_reading_ranges": 914.1178741,
+ "cost_of_reading_ranges": 1035.017874,
"use_roworder_union": true,
"cause": "always cheaper than non roworder retrieval",
"analyzing_roworder_scans":
@@ -553,10 +553,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
[
{
"index": "key1",
- "index_scan_cost": 10.31393703,
- "cumulated_index_scan_cost": 10.31393703,
- "disk_sweep_cost": 1923.144061,
- "cumulative_total_cost": 1933.457998,
+ "index_scan_cost": 61.88893703,
+ "cumulated_index_scan_cost": 61.88893703,
+ "disk_sweep_cost": 1682.25,
+ "cumulative_total_cost": 1744.138937,
"usable": true,
"matching_rows_now": 2243,
"intersect_covering_with_this_index": false,
@@ -564,10 +564,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
},
{
"index": "key2",
- "index_scan_cost": 10.31393703,
- "cumulated_index_scan_cost": 20.62787405,
- "disk_sweep_cost": 84.51771758,
- "cumulative_total_cost": 105.1455916,
+ "index_scan_cost": 61.88893703,
+ "cumulated_index_scan_cost": 123.7778741,
+ "disk_sweep_cost": 57.75,
+ "cumulative_total_cost": 181.5278741,
"usable": true,
"matching_rows_now": 77.6360508,
"intersect_covering_with_this_index": false,
@@ -580,7 +580,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"cause": "no clustered pk index"
},
"rows": 77,
- "cost": 105.1455916,
+ "cost": 197.0550842,
"covering": false,
"chosen": true
}
@@ -597,10 +597,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
[
{
"index": "key3",
- "index_scan_cost": 10.31393703,
- "cumulated_index_scan_cost": 10.31393703,
- "disk_sweep_cost": 1923.144061,
- "cumulative_total_cost": 1933.457998,
+ "index_scan_cost": 61.88893703,
+ "cumulated_index_scan_cost": 61.88893703,
+ "disk_sweep_cost": 1682.25,
+ "cumulative_total_cost": 1744.138937,
"usable": true,
"matching_rows_now": 2243,
"intersect_covering_with_this_index": false,
@@ -608,10 +608,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
},
{
"index": "key4",
- "index_scan_cost": 10.31393703,
- "cumulated_index_scan_cost": 20.62787405,
- "disk_sweep_cost": 84.51771758,
- "cumulative_total_cost": 105.1455916,
+ "index_scan_cost": 61.88893703,
+ "cumulated_index_scan_cost": 123.7778741,
+ "disk_sweep_cost": 57.75,
+ "cumulative_total_cost": 181.5278741,
"usable": true,
"matching_rows_now": 77.6360508,
"intersect_covering_with_this_index": false,
@@ -624,13 +624,13 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"cause": "no clustered pk index"
},
"rows": 77,
- "cost": 105.1455916,
+ "cost": 197.0550842,
"covering": false,
"chosen": true
}
}
],
- "index_roworder_union_cost": 194.9771115,
+ "index_roworder_union_cost": 332.5637481,
"members": 2,
"chosen": true
}
@@ -649,7 +649,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary'))
{
"type": "index_roworder_intersect",
"rows": 77,
- "cost": 105.1455916,
+ "cost": 197.0550842,
"covering": false,
"clustered_pk_scan": false,
"intersect_of":
@@ -673,7 +673,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary'))
{
"type": "index_roworder_intersect",
"rows": 77,
- "cost": 105.1455916,
+ "cost": 197.0550842,
"covering": false,
"clustered_pk_scan": false,
"intersect_of":
@@ -697,7 +697,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary'))
]
},
"rows_for_plan": 154,
- "cost_for_plan": 194.9771115,
+ "cost_for_plan": 332.5637481,
"chosen": true
}
]
diff --git a/mysql-test/main/opt_trace_index_merge_innodb.result b/mysql-test/main/opt_trace_index_merge_innodb.result
index 495ade7cd32..b7390cff757 100644
--- a/mysql-test/main/opt_trace_index_merge_innodb.result
+++ b/mysql-test/main/opt_trace_index_merge_innodb.result
@@ -89,7 +89,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"range_analysis": {
"table_scan": {
"rows": 1000,
- "cost": 206
+ "cost": 253
},
"potential_range_indexes": [
{
@@ -118,7 +118,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"using_mrr": false,
"index_only": false,
"rows": 1000,
- "cost": 204.27,
+ "cost": 252.02,
"chosen": true
},
{
@@ -128,7 +128,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"using_mrr": false,
"index_only": false,
"rows": 1,
- "cost": 1.345146475,
+ "cost": 1.270146475,
"chosen": true
}
],
@@ -136,10 +136,10 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"intersecting_indexes": [
{
"index": "key1",
- "index_scan_cost": 1.000146475,
- "cumulated_index_scan_cost": 1.000146475,
- "disk_sweep_cost": 1.004153686,
- "cumulative_total_cost": 2.004300162,
+ "index_scan_cost": 0.525146475,
+ "cumulated_index_scan_cost": 0.525146475,
+ "disk_sweep_cost": 0.752076843,
+ "cumulative_total_cost": 1.277223319,
"usable": true,
"matching_rows_now": 1,
"intersect_covering_with_this_index": false,
@@ -167,7 +167,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"ranges": ["(1) <= (key1) <= (1)"]
},
"rows_for_plan": 1,
- "cost_for_plan": 1.345146475,
+ "cost_for_plan": 1.270146475,
"chosen": true
}
}
@@ -177,7 +177,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"rowid_filters": [
{
"key": "key1",
- "build_cost": 0.130146475,
+ "build_cost": 0.526146475,
"rows": 1
}
]
@@ -206,16 +206,16 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "ref",
"index": "key1",
"used_range_estimates": true,
"rows": 1,
- "cond_check_cost": 1.325146475,
- "startup_cost": 0,
- "rows_after_filter": 1,
- "cost": 1.325146475,
+ "cost": 1.250146475,
"chosen": true
},
{
@@ -227,7 +227,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"chosen_access_method": {
"type": "ref",
"records": 1,
- "cost": 1.325146475,
+ "cost": 1.250146475,
"uses_join_buffering": false
}
}
@@ -238,13 +238,14 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 1,
- "cost_for_plan": 1.525146475
+ "cost_for_plan": 1.250146475
}
]
},
{
"best_join_order": ["t1"],
- "cost": 1.524146475
+ "rows": 1,
+ "cost": 1.250146475
},
{
"substitute_best_equal": {
diff --git a/mysql-test/main/opt_trace_security.result b/mysql-test/main/opt_trace_security.result
index ed828cda438..414ff2e4a0b 100644
--- a/mysql-test/main/opt_trace_security.result
+++ b/mysql-test/main/opt_trace_security.result
@@ -80,7 +80,8 @@ select * from db1.t1 {
"table": "t1",
"table_scan": {
"rows": 3,
- "cost": 2.005126953
+ "read_cost": 1.002563477,
+ "read_and_compare_cost": 1.752563477
}
}
]
@@ -93,18 +94,24 @@ select * from db1.t1 {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 3,
- "cost": 2.605126953,
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 1.752563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 2.605126953,
+ "cost": 1.752563477,
"uses_join_buffering": false
}
}
@@ -115,13 +122,14 @@ select * from db1.t1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 3,
- "cost_for_plan": 3.205126953
+ "cost_for_plan": 1.752563477
}
]
},
{
"best_join_order": ["t1"],
- "cost": 3.204126953
+ "rows": 3,
+ "cost": 1.752563477
},
{
"attaching_conditions_to_tables": {
@@ -210,7 +218,8 @@ select * from db1.v1 {
"table": "t1",
"table_scan": {
"rows": 3,
- "cost": 2.005126953
+ "read_cost": 1.002563477,
+ "read_and_compare_cost": 1.752563477
}
}
]
@@ -223,18 +232,24 @@ select * from db1.v1 {
{
"best_access_path": {
"table": "t1",
+ "plan_details": {
+ "record_count": 1
+ },
"considered_access_paths": [
{
"access_type": "scan",
- "resulting_rows": 3,
- "cost": 2.605126953,
+ "rows": 3,
+ "rows_after_scan": 3,
+ "rows_after_filter": 3,
+ "cost": 1.752563477,
+ "index_only": false,
"chosen": true
}
],
"chosen_access_method": {
"type": "scan",
"records": 3,
- "cost": 2.605126953,
+ "cost": 1.752563477,
"uses_join_buffering": false
}
}
@@ -245,13 +260,14 @@ select * from db1.v1 {
"plan_prefix": [],
"table": "t1",
"rows_for_plan": 3,
- "cost_for_plan": 3.205126953
+ "cost_for_plan": 1.752563477
}
]
},
{
"best_join_order": ["t1"],
- "cost": 3.204126953
+ "rows": 3,
+ "cost": 1.752563477
},
{
"attaching_conditions_to_tables": {
diff --git a/mysql-test/main/opt_trace_selectivity.result b/mysql-test/main/opt_trace_selectivity.result
index 44f4ad9bb90..bed10cd56e1 100644
--- a/mysql-test/main/opt_trace_selectivity.result
+++ b/mysql-test/main/opt_trace_selectivity.result
@@ -42,6 +42,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"best_access_path":
{
"table": "t1",
+ "plan_details":
+ {
+ "record_count": 1
+ },
"considered_access_paths":
[
{
@@ -49,10 +53,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"index": "a",
"used_range_estimates": true,
"rows": 104,
- "cond_check_cost": 124.96562,
- "startup_cost": 0,
- "rows_after_filter": 104,
- "cost": 124.96562,
+ "cost": 78.54062004,
"chosen": true
},
{
@@ -60,10 +61,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"index": "b",
"used_range_estimates": true,
"rows": 340,
- "cond_check_cost": 408.2577963,
- "startup_cost": 0,
- "rows_after_filter": 340,
- "cost": 408.2577963,
+ "cost": 255.6327963,
"chosen": false,
"cause": "cost"
},
@@ -72,17 +70,16 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"index": "c",
"used_range_estimates": true,
"rows": 632,
- "cond_check_cost": 758.7718449,
- "startup_cost": 0,
- "rows_after_filter": 632,
- "cost": 758.7718449,
+ "cost": 475.2468449,
"chosen": false,
"cause": "cost"
},
{
"access_type": "index_merge",
- "resulting_rows": 7,
- "cost": 2.173416331,
+ "rows": 7,
+ "rows_after_scan": 7,
+ "rows_after_filter": 7,
+ "cost": 13.79559815,
"chosen": true
}
],
@@ -90,7 +87,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
{
"type": "index_merge",
"records": 7,
- "cost": 2.173416331,
+ "cost": 13.79559815,
"uses_join_buffering": false
}
}
@@ -102,7 +99,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
[],
"table": "t1",
"rows_for_plan": 7,
- "cost_for_plan": 3.573416331
+ "cost_for_plan": 13.79559815
}
]
]
@@ -139,6 +136,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"best_access_path":
{
"table": "t1",
+ "plan_details":
+ {
+ "record_count": 1
+ },
"considered_access_paths":
[
{
@@ -146,10 +147,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"index": "a",
"used_range_estimates": true,
"rows": 6,
- "cond_check_cost": 7.327343464,
- "startup_cost": 0,
- "rows_after_filter": 6,
- "cost": 7.327343464,
+ "cost": 5.002343464,
"chosen": true
},
{
@@ -157,10 +155,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"index": "b",
"used_range_estimates": true,
"rows": 232,
- "cond_check_cost": 278.6156139,
- "startup_cost": 0,
- "rows_after_filter": 232,
- "cost": 278.6156139,
+ "cost": 174.5906139,
"chosen": false,
"cause": "cost"
},
@@ -169,25 +164,21 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"index": "c",
"used_range_estimates": true,
"rows": 293,
- "cond_check_cost": 351.8394392,
- "startup_cost": 0,
- "rows_after_filter": 293,
- "cost": 351.8394392,
+ "cost": 220.3644392,
"chosen": false,
"cause": "cost"
},
{
- "access_type": "index_merge",
- "resulting_rows": 1,
- "cost": 2.092957403,
- "chosen": true
+ "type": "scan",
+ "chosen": false,
+ "cause": "cost"
}
],
"chosen_access_method":
{
- "type": "index_merge",
- "records": 1,
- "cost": 2.092957403,
+ "type": "ref",
+ "records": 6,
+ "cost": 5.002343464,
"uses_join_buffering": false
}
}
@@ -198,8 +189,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"plan_prefix":
[],
"table": "t1",
- "rows_for_plan": 1,
- "cost_for_plan": 2.292957403
+ "rows_for_plan": 6,
+ "cost_for_plan": 5.002343464,
+ "selectivity": 0.1,
+ "estimated_join_cardinality": 0.6
}
]
]
diff --git a/mysql-test/main/opt_trace_selectivity.test b/mysql-test/main/opt_trace_selectivity.test
index 4d59d4974cd..3ebf4d97ed9 100644
--- a/mysql-test/main/opt_trace_selectivity.test
+++ b/mysql-test/main/opt_trace_selectivity.test
@@ -19,7 +19,9 @@ select count(*) from t1 where c=5 and b=5;
set optimizer_trace="enabled=on";
select count(*) from t1 where a=2 and b=5 and c=10;
+
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_indexes')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
select count(*) from t1 where a=2 and b=5 and c=5;
diff --git a/mysql-test/main/opt_trace_ucs2.result b/mysql-test/main/opt_trace_ucs2.result
index 9e4f25f3150..0b7506d6c5f 100644
--- a/mysql-test/main/opt_trace_ucs2.result
+++ b/mysql-test/main/opt_trace_ucs2.result
@@ -38,7 +38,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false,
"index_only": false,
"rows": 2,
- "cost": 2.547733708,
+ "cost": 2.022733708,
"chosen": true
}
],
diff --git a/mysql-test/main/opt_tvc.result b/mysql-test/main/opt_tvc.result
index 504038954b2..7c4d02fb09d 100644
--- a/mysql-test/main/opt_tvc.result
+++ b/mysql-test/main/opt_tvc.result
@@ -150,8 +150,8 @@ from t2 where b in (3,4)
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 100.00 Using where
-2 MATERIALIZED <derived4> ref key0 key0 4 test.t2.b 2 100.00
+2 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 100.00
+2 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 2 75.00 Using where; Using join buffer (flat, BNL join)
4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (3),(4)) `tvc_0` join `test`.`t2`) where `tvc_0`.`_col_1` = `test`.`t2`.`b`
@@ -168,8 +168,8 @@ from (values (3),(4)) as tvc_0
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 100.00 Using where
-2 MATERIALIZED <derived4> ref key0 key0 4 test.t2.b 2 100.00
+2 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 100.00
+2 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 2 75.00 Using where; Using join buffer (flat, BNL join)
4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (3),(4)) `tvc_0` join `test`.`t2`) where `tvc_0`.`3` = `test`.`t2`.`b`
@@ -382,8 +382,8 @@ as dr_table
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 6 100.00 Using where
-2 MATERIALIZED <derived5> ref key0 key0 4 test.t1.a 2 100.00
+2 MATERIALIZED t1 ALL NULL NULL NULL NULL 6 100.00
+2 MATERIALIZED <derived5> ALL NULL NULL NULL NULL 2 75.00 Using where; Using join buffer (flat, BNL join)
5 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0` join `test`.`t1`) where `test`.`t1`.`a` = 1 and `tvc_0`.`_col_1` = `test`.`t1`.`a`
@@ -407,8 +407,8 @@ as dr_table
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 6 100.00 Using where
-2 MATERIALIZED <derived5> ref key0 key0 4 test.t1.a 2 100.00
+2 MATERIALIZED t1 ALL NULL NULL NULL NULL 6 100.00
+2 MATERIALIZED <derived5> ALL NULL NULL NULL NULL 2 75.00 Using where; Using join buffer (flat, BNL join)
5 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0` join `test`.`t1`) where `test`.`t1`.`a` = 1 and `tvc_0`.`1` = `test`.`t1`.`a`
@@ -444,7 +444,7 @@ where b in (3,5)
group by b
) as dr_table;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY <derived2> ALL NULL NULL NULL NULL 12 100.00
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL 9 100.00
2 DERIVED t1 ALL NULL NULL NULL NULL 6 100.00 Using temporary; Using filesort
2 DERIVED <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00
3 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 2 100.00
@@ -464,7 +464,7 @@ as tvc_0
group by b
) as dr_table;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY <derived2> ALL NULL NULL NULL NULL 12 100.00
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL 9 100.00
2 DERIVED t1 ALL NULL NULL NULL NULL 6 100.00 Using temporary; Using filesort
2 DERIVED <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00
3 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 2 100.00
@@ -526,7 +526,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1,2),(3,4)) `tvc_0`) where 1
set @@in_predicate_conversion_threshold= 2;
-# trasformation works for the one IN predicate and doesn't work for the other
+# transformation works for the one IN predicate and doesn't work for the other
set @@in_predicate_conversion_threshold= 5;
select * from t2
where (a,b) in ((1,2),(8,9)) and
@@ -539,11 +539,10 @@ where (a,b) in ((1,2),(8,9)) and
(a,c) in ((1,3),(8,0),(5,1));
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 6 100.00 Using where
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1 100.00
-2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 3 100.00
+1 PRIMARY <derived3> ref key0 key0 8 test.t2.a,test.t2.c 2 100.00 FirstMatch(t2)
3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
-Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` semi join ((values (1,3),(8,0),(5,1)) `tvc_0`) where (`test`.`t2`.`a`,`test`.`t2`.`b`) in (<cache>((1,2)),<cache>((8,9)))
+Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` semi join ((values (1,3),(8,0),(5,1)) `tvc_0`) where `tvc_0`.`_col_1` = `test`.`t2`.`a` and `tvc_0`.`_col_2` = `test`.`t2`.`c` and (`test`.`t2`.`a`,`test`.`t2`.`b`) in (<cache>((1,2)),<cache>((8,9)))
set @@in_predicate_conversion_threshold= 2;
#
# mdev-14281: conversion of NOT IN predicate into subquery predicate
@@ -568,18 +567,18 @@ explain extended select * from t1
where (a,b) not in ((1,2),(8,9), (5,1));
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where
-2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 3 100.00
+2 DEPENDENT SUBQUERY <derived3> index_subquery key0 key0 8 func,func 2 100.00 Using where; Full scan on NULL key
3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<expr_cache><`test`.`t1`.`a`,`test`.`t1`.`b`>(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),(`test`.`t1`.`a`,`test`.`t1`.`b`) in ( <materialize> (/* select#2 */ select `tvc_0`.`_col_1`,`tvc_0`.`_col_2` from (values (1,2),(8,9),(5,1)) `tvc_0` ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`_col_1` and `test`.`t1`.`b` = `<subquery2>`.`_col_2`))))
+Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<expr_cache><`test`.`t1`.`a`,`test`.`t1`.`b`>(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in (temporary) on key0 where trigcond(<cache>(`test`.`t1`.`a`) = `tvc_0`.`_col_1`) and trigcond(<cache>(`test`.`t1`.`b`) = `tvc_0`.`_col_2`)))))
explain extended select * from t1
where (a,b) not in (select * from (values (1,2),(8,9), (5,1)) as tvc_0);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where
-2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 3 100.00
+2 DEPENDENT SUBQUERY <derived3> index_subquery key0 key0 8 func,func 2 100.00 Using where; Full scan on NULL key
3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<expr_cache><`test`.`t1`.`a`,`test`.`t1`.`b`>(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),(`test`.`t1`.`a`,`test`.`t1`.`b`) in ( <materialize> (/* select#2 */ select `tvc_0`.`1`,`tvc_0`.`2` from (values (1,2),(8,9),(5,1)) `tvc_0` ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`1` and `test`.`t1`.`b` = `<subquery2>`.`2`))))
+Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<expr_cache><`test`.`t1`.`a`,`test`.`t1`.`b`>(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in (temporary) on key0 where trigcond(<cache>(`test`.`t1`.`a`) = `tvc_0`.`1`) and trigcond(<cache>(`test`.`t1`.`b`) = `tvc_0`.`2`)))))
select * from t1
where b < 7 and (a,b) not in ((1,2),(8,9), (5,1));
a b
@@ -590,10 +589,10 @@ explain extended select * from t1
where b < 7 and (a,b) not in ((1,2),(8,9), (5,1));
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where
-2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 3 100.00
+2 DEPENDENT SUBQUERY <derived3> index_subquery key0 key0 8 func,func 2 100.00 Using where; Full scan on NULL key
3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`b` < 7 and !<expr_cache><`test`.`t1`.`a`,`test`.`t1`.`b`>(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),(`test`.`t1`.`a`,`test`.`t1`.`b`) in ( <materialize> (/* select#2 */ select `tvc_0`.`_col_1`,`tvc_0`.`_col_2` from (values (1,2),(8,9),(5,1)) `tvc_0` ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`_col_1` and `test`.`t1`.`b` = `<subquery2>`.`_col_2`))))
+Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`b` < 7 and !<expr_cache><`test`.`t1`.`a`,`test`.`t1`.`b`>(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in (temporary) on key0 where trigcond(<cache>(`test`.`t1`.`a`) = `tvc_0`.`_col_1`) and trigcond(<cache>(`test`.`t1`.`b`) = `tvc_0`.`_col_2`)))))
select * from t2
where (a,c) not in ((1,2),(8,9), (5,1));
a b c
@@ -606,10 +605,10 @@ explain extended select * from t2
where (a,c) not in ((1,2),(8,9), (5,1));
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 6 100.00 Using where
-2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 3 100.00
+2 DEPENDENT SUBQUERY <derived3> index_subquery key0 key0 8 func,func 2 100.00 Using where; Full scan on NULL key
3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
-Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where !<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`c`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`c`),(`test`.`t2`.`a`,`test`.`t2`.`c`) in ( <materialize> (/* select#2 */ select `tvc_0`.`_col_1`,`tvc_0`.`_col_2` from (values (1,2),(8,9),(5,1)) `tvc_0` ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on distinct_key where `test`.`t2`.`a` = `<subquery2>`.`_col_1` and `test`.`t2`.`c` = `<subquery2>`.`_col_2`))))
+Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where !<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`c`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`c`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in (temporary) on key0 where trigcond(<cache>(`test`.`t2`.`a`) = `tvc_0`.`_col_1`) and trigcond(<cache>(`test`.`t2`.`c`) = `tvc_0`.`_col_2`)))))
drop table t1, t2, t3;
set @@in_predicate_conversion_threshold= default;
#
diff --git a/mysql-test/main/opt_tvc.test b/mysql-test/main/opt_tvc.test
index f8469f22aa1..ebb34758f87 100644
--- a/mysql-test/main/opt_tvc.test
+++ b/mysql-test/main/opt_tvc.test
@@ -276,7 +276,7 @@ eval $query;
eval explain extended $query;
set @@in_predicate_conversion_threshold= 2;
---echo # trasformation works for the one IN predicate and doesn't work for the other
+--echo # transformation works for the one IN predicate and doesn't work for the other
set @@in_predicate_conversion_threshold= 5;
diff --git a/mysql-test/main/order_by.result b/mysql-test/main/order_by.result
index c1016393828..af379cf4aae 100644
--- a/mysql-test/main/order_by.result
+++ b/mysql-test/main/order_by.result
@@ -1192,7 +1192,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index k2 k3 5 NULL 111 Using where
EXPLAIN SELECT id,c3 FROM t2 WHERE c2=11 ORDER BY c3 LIMIT 4000;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 index k2 k3 5 NULL 22318 Using where
+1 SIMPLE t2 ref k2 k2 5 const 7341 Using where; Using filesort
EXPLAIN SELECT id,c3 FROM t2 WHERE c2 BETWEEN 10 AND 12 ORDER BY c3 LIMIT 20;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index k2 k3 5 NULL 73 Using where
@@ -1221,6 +1221,10 @@ id c3
176 14
186 14
196 14
+ALTER TABLE t2 DROP INDEX k3, ADD INDEX k3 (c3,c2);
+EXPLAIN SELECT c3 FROM t2 WHERE c2=11 ORDER BY c3 LIMIT 4000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 index k2 k3 10 NULL 22318 Using where; Using index
DROP TABLE t1,t2;
CREATE TABLE t1 (
a INT,
@@ -1551,11 +1555,17 @@ INSERT INTO t1 VALUES (1, 10), (2, NULL);
EXPLAIN
SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref_or_null a_c,a a_c 10 const,const 2 Using where; Using index; Using filesort
+1 SIMPLE t1 range a_c,a a_c 10 NULL 2 Using where; Using index
# Must return 1 row
SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
col
1
+# With more rows "range" changes to "ref_or_null"
+INSERT INTO t1 select seq,seq from seq_1_to_10;
+EXPLAIN
+SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ref_or_null a_c,a a_c 10 const,const 2 Using where; Using index; Using filesort
# Must use ref-or-null on the a_c index
EXPLAIN
SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c DESC;
@@ -3412,10 +3422,9 @@ ANALYZE
"r_loops": 1,
"r_total_time_ms": "REPLACED",
"r_limit": 5,
- "r_used_priority_queue": false,
- "r_output_rows": 100,
- "r_buffer_size": "REPLACED",
- "r_sort_mode": "sort_key,packed_addon_fields",
+ "r_used_priority_queue": true,
+ "r_output_rows": 6,
+ "r_sort_mode": "sort_key,rowid",
"table": {
"table_name": "t1",
"access_type": "ALL",
@@ -3453,7 +3462,7 @@ CREATE TABLE t2 SELECT * FROM t1;
EXPLAIN SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.b ORDER BY t1.b LIMIT 1) AS c FROM t2;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2
-2 DEPENDENT SUBQUERY t1 index PRIMARY b 5 NULL 1 Using where
+2 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 test.t2.b 1 Using where
SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.b ORDER BY t1.b LIMIT 1) AS c FROM t2;
c
1
@@ -3501,11 +3510,10 @@ WHERE books.library_id = 8663 AND
books.scheduled_for_removal=0 )
ORDER BY wings.id;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2 100.00 Using filesort
-1 PRIMARY wings eq_ref PRIMARY PRIMARY 4 test.books.wings_id 1 100.00
-2 MATERIALIZED books ref library_idx library_idx 4 const 2 100.00 Using where
+1 PRIMARY wings ALL PRIMARY NULL NULL NULL 2 100.00 Using temporary; Using filesort
+1 PRIMARY books ALL library_idx NULL NULL NULL 2 100.00 Using where; FirstMatch(wings); Using join buffer (flat, BNL join)
Warnings:
-Note 1003 select `test`.`wings`.`id` AS `wing_id`,`test`.`wings`.`department_id` AS `department_id` from `test`.`wings` semi join (`test`.`books`) where `test`.`books`.`library_id` = 8663 and `test`.`books`.`scheduled_for_removal` = 0 and `test`.`wings`.`id` = `test`.`books`.`wings_id` order by `test`.`wings`.`id`
+Note 1003 select `test`.`wings`.`id` AS `wing_id`,`test`.`wings`.`department_id` AS `department_id` from `test`.`wings` semi join (`test`.`books`) where `test`.`books`.`library_id` = 8663 and `test`.`books`.`scheduled_for_removal` = 0 and `test`.`books`.`wings_id` = `test`.`wings`.`id` order by `test`.`wings`.`id`
set optimizer_switch= @save_optimizer_switch;
DROP TABLE books, wings;
#
diff --git a/mysql-test/main/order_by.test b/mysql-test/main/order_by.test
index 1cd9efa2710..baa173ea753 100644
--- a/mysql-test/main/order_by.test
+++ b/mysql-test/main/order_by.test
@@ -9,6 +9,7 @@
--source include/no_view_protocol.inc
call mtr.add_suppression("Sort aborted.*");
+--source include/have_sequence.inc
call mtr.add_suppression("Out of sort memory; increase server sort buffer size");
--source include/have_sequence.inc
@@ -803,6 +804,10 @@ EXPLAIN SELECT id,c3 FROM t2 WHERE c2 BETWEEN 20 AND 30 ORDER BY c3 LIMIT 4000;
SELECT id,c3 FROM t2 WHERE c2=11 ORDER BY c3 LIMIT 20;
+# Show that order by optimization takes into account index only scans
+ALTER TABLE t2 DROP INDEX k3, ADD INDEX k3 (c3,c2);
+EXPLAIN SELECT c3 FROM t2 WHERE c2=11 ORDER BY c3 LIMIT 4000;
+
DROP TABLE t1,t2;
#
@@ -912,6 +917,11 @@ SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
--echo # Must return 1 row
SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
+--echo # With more rows "range" changes to "ref_or_null"
+INSERT INTO t1 select seq,seq from seq_1_to_10;
+EXPLAIN
+SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
+
# part 2 of the problem : DESC test cases
--echo # Must use ref-or-null on the a_c index
--replace_column 1 x 2 x 3 x 6 x 7 x 8 x 9 x 10 x
diff --git a/mysql-test/main/order_by_innodb.result b/mysql-test/main/order_by_innodb.result
index 741084c8a6c..7462b8e6688 100644
--- a/mysql-test/main/order_by_innodb.result
+++ b/mysql-test/main/order_by_innodb.result
@@ -53,17 +53,29 @@ KEY a_c (a,c),
KEY a_b (a,b)
) ENGINE=InnoDB;
insert into t1 select A.a , B.a, C.a from t0 A, t0 B, t0 C;
+select count(*) from t1;
+count(*)
+1000
+select count(*) from t1 where a=1;
+count(*)
+200
+select count(*) from t1 where a=1 and c=2;
+count(*)
+20
# should use ref access
explain select a,b,c from t1 where a=1 and c=2 order by b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref a_c,a_b a_c 10 const,const 20 Using where; Using filesort
-# both should use range access
-explain select a,b,c from t1 where a=1 and c=2 order by b limit 1000;
+# all should use range access
+explain select a,b,c from t1 where a=1 and c=2 order by b limit 10;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ref a_c,a_b a_c 10 const,const 20 Using where; Using filesort
+explain select a,b,c from t1 where a=1 and c=2 order by b limit 300;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range a_c,a_b a_b 5 NULL 200 Using where
-explain select a,b,c from t1 where a=1 and c=2 order by b limit 2000;
+1 SIMPLE t1 ref a_c,a_b a_c 10 const,const 20 Using where; Using filesort
+explain select a,b,c from t1 where a=1 and c=2 order by b limit 1000;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range a_c,a_b a_b 5 NULL 200 Using where
+1 SIMPLE t1 ref a_c,a_b a_c 10 const,const 20 Using where; Using filesort
drop table t1,t0;
# Start of 10.2 tests
#
@@ -245,8 +257,8 @@ dd.d1, dd.d2, dd.id limit 1
);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL PRIMARY 4 NULL # Using index
-1 PRIMARY t2 eq_ref PRIMARY,id2 PRIMARY 4 func # Using where
-2 DEPENDENT SUBQUERY dd range id2,for_latest_sort for_latest_sort 6 NULL # Using where
+1 PRIMARY t2 eq_ref PRIMARY,id2 id2 8 test.t1.id,func # Using where; Using index
+2 DEPENDENT SUBQUERY dd ref id2,for_latest_sort id2 4 test.t1.id # Using where; Using filesort
drop table t1,t2,t3;
# End of 10.2 tests
#
diff --git a/mysql-test/main/order_by_innodb.test b/mysql-test/main/order_by_innodb.test
index bdaef56672f..acce96c7603 100644
--- a/mysql-test/main/order_by_innodb.test
+++ b/mysql-test/main/order_by_innodb.test
@@ -66,13 +66,17 @@ KEY a_c (a,c),
KEY a_b (a,b)
) ENGINE=InnoDB;
insert into t1 select A.a , B.a, C.a from t0 A, t0 B, t0 C;
+select count(*) from t1;
+select count(*) from t1 where a=1;
+select count(*) from t1 where a=1 and c=2;
--echo # should use ref access
explain select a,b,c from t1 where a=1 and c=2 order by b;
---echo # both should use range access
+--echo # all should use range access
+explain select a,b,c from t1 where a=1 and c=2 order by b limit 10;
+explain select a,b,c from t1 where a=1 and c=2 order by b limit 300;
explain select a,b,c from t1 where a=1 and c=2 order by b limit 1000;
-explain select a,b,c from t1 where a=1 and c=2 order by b limit 2000;
drop table t1,t0;
--echo # Start of 10.2 tests
diff --git a/mysql-test/main/order_by_sortkey.result b/mysql-test/main/order_by_sortkey.result
index c1d9609eb47..853823f5f61 100644
--- a/mysql-test/main/order_by_sortkey.result
+++ b/mysql-test/main/order_by_sortkey.result
@@ -40,6 +40,9 @@ INSERT INTO tmp SELECT f1,f2 FROM t1;
INSERT INTO t1(f1,f2) SELECT * FROM tmp;
INSERT INTO tmp SELECT f1,f2 FROM t1;
INSERT INTO t1(f1,f2) SELECT * FROM tmp;
+select count(*) from t1;
+count(*)
+87700
set sort_buffer_size= 32768;
FLUSH STATUS;
SHOW SESSION STATUS LIKE 'Sort%';
@@ -49,6 +52,9 @@ Sort_priority_queue_sorts 0
Sort_range 0
Sort_rows 0
Sort_scan 0
+explain SELECT * FROM t1 ORDER BY f2 LIMIT 100;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 87700 Using filesort
SELECT * FROM t1 ORDER BY f2 LIMIT 100;
f0 f1 f2
1 0 0
@@ -158,4 +164,9 @@ Sort_priority_queue_sorts 1
Sort_range 0
Sort_rows 100
Sort_scan 1
+SHOW STATUS LIKE 'Handler_read_rnd%';
+Variable_name Value
+Handler_read_rnd 100
+Handler_read_rnd_deleted 0
+Handler_read_rnd_next 87701
DROP TABLE t1, tmp;
diff --git a/mysql-test/main/order_by_sortkey.test b/mysql-test/main/order_by_sortkey.test
index 43de028496e..d3f8ba396d8 100644
--- a/mysql-test/main/order_by_sortkey.test
+++ b/mysql-test/main/order_by_sortkey.test
@@ -50,6 +50,7 @@ INSERT INTO tmp SELECT f1,f2 FROM t1;
INSERT INTO t1(f1,f2) SELECT * FROM tmp;
INSERT INTO tmp SELECT f1,f2 FROM t1;
INSERT INTO t1(f1,f2) SELECT * FROM tmp;
+select count(*) from t1;
# Test when only sortkeys fits to memory
set sort_buffer_size= 32768;
@@ -57,8 +58,12 @@ set sort_buffer_size= 32768;
FLUSH STATUS;
SHOW SESSION STATUS LIKE 'Sort%';
+explain SELECT * FROM t1 ORDER BY f2 LIMIT 100;
SELECT * FROM t1 ORDER BY f2 LIMIT 100;
+# Check that Sort_priority_queue_sorts is used
SHOW SESSION STATUS LIKE 'Sort%';
+# Check that we did scan the whole table and did LIMIT lookups
+SHOW STATUS LIKE 'Handler_read_rnd%';
DROP TABLE t1, tmp;
diff --git a/mysql-test/main/partition_pruning.result b/mysql-test/main/partition_pruning.result
index 519bf590b9b..dcc25892276 100644
--- a/mysql-test/main/partition_pruning.result
+++ b/mysql-test/main/partition_pruning.result
@@ -15,13 +15,13 @@ PARTITION max VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (-1),(0),(1),(2),(3),(4),(5),(6),(7),(8);
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1;
id select_type table partitions type possible_keys key key_len ref rows Extra
-# # # # # # # # # 3 #
+# # # # range # # # # 3 #
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 7;
id select_type table partitions type possible_keys key key_len ref rows Extra
-# # # # # # # # # 8 #
+# # # # range # # # # 8 #
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1;
id select_type table partitions type possible_keys key key_len ref rows Extra
-# # # # # # # # # 3 #
+# # # # range # # # # 3 #
DROP TABLE t1;
#
# Bug#49742: Partition Pruning not working correctly for RANGE
@@ -2888,12 +2888,12 @@ id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t2 p0,p1,p2,p3,p4 ALL b NULL NULL NULL 910 Using where
explain extended select * from t2 where b in (2,4,6);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t2 ALL b NULL NULL NULL 910 25.38 Using where
+1 SIMPLE t2 range b b 5 NULL 231 100.00 Using where
Warnings:
Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where `test`.`t2`.`b` in (2,4,6)
explain partitions select * from t2 where b in (2,4,6);
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 p0,p1,p2,p3,p4 ALL b NULL NULL NULL 910 Using where
+1 SIMPLE t2 p0,p1,p2,p3,p4 range b b 5 NULL 231 Using where
explain extended select * from t2 where b in (7,8,9);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL b NULL NULL NULL 910 36.81 Using where
@@ -2912,12 +2912,12 @@ id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t2 p0,p1,p2,p3,p4 ALL b NULL NULL NULL 910 Using where
explain extended select * from t2 where b > 5 and b < 8;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t2 ALL b NULL NULL NULL 910 22.20 Using where
+1 SIMPLE t2 range b b 5 NULL 202 100.00 Using where
Warnings:
Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where `test`.`t2`.`b` > 5 and `test`.`t2`.`b` < 8
explain partitions select * from t2 where b > 5 and b < 8;
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 p0,p1,p2,p3,p4 ALL b NULL NULL NULL 910 Using where
+1 SIMPLE t2 p0,p1,p2,p3,p4 range b b 5 NULL 202 Using where
explain extended select * from t2 where b > 5 and b < 7;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 range b b 5 NULL 77 100.00 Using where
@@ -2946,10 +2946,10 @@ flush status;
update t2 set a = 111 where b in (5,6);
show status like 'Handler_read_rnd_next';
Variable_name Value
-Handler_read_rnd_next 915
+Handler_read_rnd_next 0
show status like 'Handler_read_key';
Variable_name Value
-Handler_read_key 0
+Handler_read_key 10
flush status;
update t2 set a = 222 where b = 7;
show status like 'Handler_read_rnd_next';
@@ -3378,7 +3378,7 @@ id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p1 const PRIMARY PRIMARY 8 const,const 1
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE c1 = 1 AND c2 >= 1;
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 p1,p2 range PRIMARY PRIMARY 8 NULL 3 Using where
+1 SIMPLE t1 p1,p2 ref PRIMARY PRIMARY 4 const 1 Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE c1 = 1 AND c2 > 1;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p1,p2 range PRIMARY PRIMARY 8 NULL 2 Using where
@@ -3387,7 +3387,7 @@ id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p1 range PRIMARY PRIMARY 8 NULL 2 Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE c1 = 1 AND c2 <= 3;
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 p1,p2 range PRIMARY PRIMARY 8 NULL 3 Using where
+1 SIMPLE t1 p1,p2 ref PRIMARY PRIMARY 4 const 1 Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE c1 = 2 AND c2 <= 3;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p1,p2 range PRIMARY PRIMARY 8 NULL 2 Using where
@@ -3405,7 +3405,7 @@ id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p1,p2 range PRIMARY PRIMARY 8 NULL 2 Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE c1 = 2 AND c2 <= 4;
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 p1,p2 range PRIMARY PRIMARY 8 NULL 3 Using where
+1 SIMPLE t1 p1,p2 ref PRIMARY PRIMARY 4 const 1 Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE c1 = 2 AND c2 = 4;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p2 const PRIMARY PRIMARY 8 const,const 1
@@ -3465,8 +3465,8 @@ select * from t1
where company_id = 1000
and dept_id in (select dept_id from t2 where COMPANY_ID = 1000);
id select_type table partitions type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 p_1000 ref PRIMARY PRIMARY 8 const 3 Using index
-1 PRIMARY t1 p_1000 ALL PRIMARY NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t1 p_1000 ALL PRIMARY NULL NULL NULL 6 Using where
+1 PRIMARY t2 p_1000 eq_ref PRIMARY PRIMARY 16 const,test.t1.dept_id 1 Using index
drop table t1,t2;
#
# MDEV-9505: Valgrind failure in SEL_ARG::store_min,find_used_partitions,...
diff --git a/mysql-test/main/partition_pruning.test b/mysql-test/main/partition_pruning.test
index d59f52be313..78924d27550 100644
--- a/mysql-test/main/partition_pruning.test
+++ b/mysql-test/main/partition_pruning.test
@@ -25,11 +25,11 @@ PARTITION max VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (-1),(0),(1),(2),(3),(4),(5),(6),(7),(8);
---replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 11 #
+--replace_column 1 # 2 # 3 # 4 # 6 # 7 # 8 # 9 # 11 #
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1;
---replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 11 #
+--replace_column 1 # 2 # 3 # 4 # 6 # 7 # 8 # 9 # 11 #
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 7;
---replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 11 #
+--replace_column 1 # 2 # 3 # 4 # 6 # 7 # 8 # 9 # 11 #
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1;
DROP TABLE t1;
diff --git a/mysql-test/main/partition_range.result b/mysql-test/main/partition_range.result
index cc2e7831405..3c1ff311bf5 100644
--- a/mysql-test/main/partition_range.result
+++ b/mysql-test/main/partition_range.result
@@ -9,11 +9,11 @@ COUNT(*)
3
EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10000, 1000000, 3000) GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range a a 5 NULL 4 Using where; Using index
+1 SIMPLE t1 range a a 5 NULL 3 Using where; Using index for group-by
alter table t1 partition by hash(a) partitions 1;
EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10000, 1000000, 3000) GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range a a 5 NULL 4 Using where; Using index
+1 SIMPLE t1 range a a 5 NULL 3 Using where; Using index for group-by
alter table t1 remove partitioning;
insert into t1 (a,b) select seq,seq from seq_4001_to_4100;
insert into t1 (a,b) select seq,seq from seq_10001_to_10100;
diff --git a/mysql-test/main/ps_1general.result b/mysql-test/main/ps_1general.result
index ca2447b6b26..b71057248b6 100644
--- a/mysql-test/main/ps_1general.result
+++ b/mysql-test/main/ps_1general.result
@@ -451,7 +451,7 @@ def Extra 253 255 14 N 1 39 8
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using filesort
SET @arg00=1 ;
-prepare stmt1 from ' explain select a from t1 where a > ? order by b ';
+prepare stmt1 from ' explain select a from t1 force index (primary) where a > ? order by b ';
execute stmt1 using @arg00;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def id 8 3 1 Y 32928 0 63
diff --git a/mysql-test/main/ps_1general.test b/mysql-test/main/ps_1general.test
index 20f2ad019f4..c98fc4a5619 100644
--- a/mysql-test/main/ps_1general.test
+++ b/mysql-test/main/ps_1general.test
@@ -437,8 +437,10 @@ prepare stmt3 from ' unlock tables ' ;
## Load/Unload table contents
--let $datafile = $MYSQLTEST_VARDIR/tmp/data.txt
+--disable_warnings
--error 0,1
--remove_file $datafile
+--enable_warnings
--replace_result $MYSQLTEST_VARDIR <MYSQLTEST_VARDIR>
eval prepare stmt1 from ' load data infile ''$datafile''
@@ -497,7 +499,7 @@ prepare stmt1 from ' explain select a from t1 order by b ';
execute stmt1;
--disable_metadata
SET @arg00=1 ;
-prepare stmt1 from ' explain select a from t1 where a > ? order by b ';
+prepare stmt1 from ' explain select a from t1 force index (primary) where a > ? order by b ';
--enable_metadata
--replace_result 4096 4_OR_8_K 8192 4_OR_8_K
execute stmt1 using @arg00;
diff --git a/mysql-test/main/range.result b/mysql-test/main/range.result
index 36e6e2b2aec..a2ecc66c570 100644
--- a/mysql-test/main/range.result
+++ b/mysql-test/main/range.result
@@ -252,7 +252,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref x x 5 const 1 Using index
explain select count(*) from t1 where x in (1,2,3,4);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range x x 5 NULL 4 Using where; Using index
+1 SIMPLE t1 index x x 5 NULL 9 Using where; Using index
drop table t1;
CREATE TABLE t1 (key1 int(11) NOT NULL default '0', KEY i1 (key1));
INSERT INTO t1 VALUES (0),(0),(0),(0),(0),(1),(1);
@@ -261,12 +261,12 @@ INSERT INTO t2 VALUES (0),(0),(1),(1),(2),(2);
explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref j1 j1 4 const 1 Using index
-1 SIMPLE t1 range i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join)
+1 SIMPLE t1 index i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join)
explain select * from t1 force index(i1), t2 force index(j1) where
(t1.key1 <t2.keya + 1) and t2.keya=3;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref j1 j1 4 const 1 Using index
-1 SIMPLE t1 range i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join)
+1 SIMPLE t1 index i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join)
DROP TABLE t1,t2;
CREATE TABLE t1 (
a int(11) default NULL,
@@ -281,7 +281,7 @@ INSERT INTO t1 VALUES
(33,5),(33,5),(33,5),(33,5),(34,5),(35,5);
EXPLAIN SELECT * FROM t1 WHERE a IN(1,2) AND b=5;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range|filter a,b a|b 5|5 NULL 2 (41%) Using index condition; Using where; Using rowid filter
+1 SIMPLE t1 ref|filter a,b b|a 5|5 const 15 (5%) Using where; Using rowid filter
SELECT * FROM t1 WHERE a IN(1,2) AND b=5;
a b
DROP TABLE t1;
@@ -676,7 +676,7 @@ create table t1(a char(2), key(a(1)));
insert into t1 values ('x'), ('xx');
explain select a from t1 where a > 'x';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range a a 2 NULL 2 Using where
+1 SIMPLE t1 ALL a NULL NULL NULL 2 Using where
select a from t1 where a > 'x';
a
xx
@@ -1138,7 +1138,7 @@ INSERT INTO t1 VALUES
('A2','2005-12-01 08:00:00',1000);
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref PRIMARY PRIMARY 20 const 3 Using index condition
+1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 4 Using where
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
item started price
Warnings:
@@ -1236,14 +1236,13 @@ insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 (a int, b int, filler char(100));
insert into t2 select A.a + 10 * (B.a + 10 * C.a), 10, 'filler' from t1 A,
t1 B, t1 C where A.a < 5;
-insert into t2 select 1000, b, 'filler' from t2;
+insert into t2 select 1000, b, 'filler' from t2 limit 250;
alter table t2 add index (a,b);
-select 'In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)' Z;
-Z
-In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)
+# In following EXPLAIN the access method should be ref, #rows~=250
+# (and not 2) when we are not using rowid-ordered scans
explain select * from t2 where a=1000 and b<11;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ref a a 5 const 503 Using index condition
+1 SIMPLE t2 range a a 10 NULL 253 Using index condition
drop table t1, t2;
CREATE TABLE t1( a INT, b INT, KEY( a, b ) );
CREATE TABLE t2( a INT, b INT, KEY( a, b ) );
@@ -2542,7 +2541,7 @@ insert into t2 values
explain select * from t1,t2
where a = d and (a,e) in ((3,3),(7,7),(2,2));
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 range|filter idx1,idx2 idx1|idx2 5|5 NULL 3 (60%) Using index condition; Using where; Using rowid filter
+1 SIMPLE t2 range idx1,idx2 idx1 5 NULL 3 Using index condition; Using where
1 SIMPLE t1 ref idx idx 5 test.t2.d 8
explain format=json select * from t1,t2
where a = d and (a,e) in ((3,3),(7,7),(2,2));
@@ -2559,16 +2558,8 @@ EXPLAIN
"key": "idx1",
"key_length": "5",
"used_key_parts": ["d"],
- "rowid_filter": {
- "range": {
- "key": "idx2",
- "used_key_parts": ["e"]
- },
- "rows": 12,
- "selectivity_pct": 60
- },
"rows": 3,
- "filtered": 60,
+ "filtered": 100,
"index_condition": "t2.d is not null",
"attached_condition": "(t2.d,t2.e) in (<cache>((3,3)),<cache>((7,7)),<cache>((2,2)))"
}
@@ -2628,8 +2619,8 @@ insert into t2 values
explain select * from t1,t2
where a = d and (a,e) in ((3,3),(7,7),(8,8)) and length(f) = 1;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 range|filter idx1,idx2 idx1|idx2 5|5 NULL 8 (14%) Using index condition; Using where; Using rowid filter
-1 SIMPLE t1 ref idx idx 5 test.t2.d 8
+1 SIMPLE t1 range idx idx 5 NULL 6 Using index condition
+1 SIMPLE t2 ref|filter idx1,idx2 idx1|idx2 5|5 test.t1.a 12 (14%) Using where; Using rowid filter
explain format=json select * from t1,t2
where a = d and (a,e) in ((3,3),(7,7),(8,8)) and length(f) = 1;
EXPLAIN
@@ -2639,12 +2630,26 @@ EXPLAIN
"nested_loop": [
{
"table": {
- "table_name": "t2",
+ "table_name": "t1",
"access_type": "range",
+ "possible_keys": ["idx"],
+ "key": "idx",
+ "key_length": "5",
+ "used_key_parts": ["a"],
+ "rows": 6,
+ "filtered": 100,
+ "index_condition": "t1.a is not null"
+ }
+ },
+ {
+ "table": {
+ "table_name": "t2",
+ "access_type": "ref",
"possible_keys": ["idx1", "idx2"],
"key": "idx1",
"key_length": "5",
"used_key_parts": ["d"],
+ "ref": ["test.t1.a"],
"rowid_filter": {
"range": {
"key": "idx2",
@@ -2653,23 +2658,9 @@ EXPLAIN
"rows": 15,
"selectivity_pct": 14.42307692
},
- "rows": 8,
+ "rows": 12,
"filtered": 14.42307663,
- "index_condition": "t2.d is not null",
- "attached_condition": "(t2.d,t2.e) in (<cache>((3,3)),<cache>((7,7)),<cache>((8,8))) and octet_length(t2.f) = 1"
- }
- },
- {
- "table": {
- "table_name": "t1",
- "access_type": "ref",
- "possible_keys": ["idx"],
- "key": "idx",
- "key_length": "5",
- "used_key_parts": ["a"],
- "ref": ["test.t2.d"],
- "rows": 8,
- "filtered": 100
+ "attached_condition": "(t1.a,t2.e) in (<cache>((3,3)),<cache>((7,7)),<cache>((8,8))) and octet_length(t2.f) = 1"
}
}
]
@@ -2678,37 +2669,37 @@ EXPLAIN
select * from t1,t2
where a = d and (a,e) in ((3,3),(7,7),(8,8)) and length(f) = 1;
a b c d e f
-3 2 uuuw 3 3 i
3 2 uuua 3 3 i
-3 3 zzzz 3 3 i
-3 3 zyxw 3 3 i
-3 3 zzza 3 3 i
-3 3 zyxa 3 3 i
-3 2 uuuw 3 3 i
3 2 uuua 3 3 i
-3 3 zzzz 3 3 i
+3 2 uuuw 3 3 i
+3 2 uuuw 3 3 i
+3 3 zyxa 3 3 i
+3 3 zyxa 3 3 i
+3 3 zyxw 3 3 i
3 3 zyxw 3 3 i
3 3 zzza 3 3 i
-3 3 zyxa 3 3 i
-7 7 xxxyy 7 7 h
+3 3 zzza 3 3 i
+3 3 zzzz 3 3 i
+3 3 zzzz 3 3 i
7 7 xxxya 7 7 h
-7 8 xxxxx 7 7 h
+7 7 xxxyy 7 7 h
7 8 xxxxa 7 7 h
+7 8 xxxxx 7 7 h
prepare stmt from "select * from t1,t2
where a = d and (a,e) in ((3,3),(7,7),(8,8)) and length(f) = 1";
execute stmt;
a b c d e f
3 2 uuuw 3 3 i
-3 2 uuua 3 3 i
-3 3 zzzz 3 3 i
-3 3 zyxw 3 3 i
-3 3 zzza 3 3 i
-3 3 zyxa 3 3 i
3 2 uuuw 3 3 i
3 2 uuua 3 3 i
+3 2 uuua 3 3 i
+3 3 zzzz 3 3 i
3 3 zzzz 3 3 i
3 3 zyxw 3 3 i
+3 3 zyxw 3 3 i
3 3 zzza 3 3 i
+3 3 zzza 3 3 i
+3 3 zyxa 3 3 i
3 3 zyxa 3 3 i
7 7 xxxyy 7 7 h
7 7 xxxya 7 7 h
@@ -2717,17 +2708,17 @@ a b c d e f
execute stmt;
a b c d e f
3 2 uuuw 3 3 i
-3 2 uuua 3 3 i
-3 3 zzzz 3 3 i
-3 3 zyxw 3 3 i
-3 3 zzza 3 3 i
-3 3 zyxa 3 3 i
3 2 uuuw 3 3 i
3 2 uuua 3 3 i
+3 2 uuua 3 3 i
+3 3 zzzz 3 3 i
3 3 zzzz 3 3 i
3 3 zyxw 3 3 i
+3 3 zyxw 3 3 i
+3 3 zzza 3 3 i
3 3 zzza 3 3 i
3 3 zyxa 3 3 i
+3 3 zyxa 3 3 i
7 7 xxxyy 7 7 h
7 7 xxxya 7 7 h
7 8 xxxxx 7 7 h
@@ -2739,8 +2730,8 @@ insert into t1 select * from t1;
explain select * from t1,t2
where a = d and (a,e) in ((4,4),(7,7),(8,8)) and length(f) = 1;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 range|filter idx1,idx2 idx1|idx2 5|5 NULL 7 (7%) Using index condition; Using where; Using rowid filter
-1 SIMPLE t1 ref idx idx 5 test.t2.d 11
+1 SIMPLE t1 range idx idx 5 NULL 15 Using index condition
+1 SIMPLE t2 ref|filter idx1,idx2 idx1|idx2 5|5 test.t1.a 12 (7%) Using where; Using rowid filter
explain format=json select * from t1,t2
where a = d and (a,e) in ((4,4),(7,7),(8,8)) and length(f) = 1;
EXPLAIN
@@ -2750,12 +2741,26 @@ EXPLAIN
"nested_loop": [
{
"table": {
- "table_name": "t2",
+ "table_name": "t1",
"access_type": "range",
+ "possible_keys": ["idx"],
+ "key": "idx",
+ "key_length": "5",
+ "used_key_parts": ["a"],
+ "rows": 15,
+ "filtered": 100,
+ "index_condition": "t1.a is not null"
+ }
+ },
+ {
+ "table": {
+ "table_name": "t2",
+ "access_type": "ref",
"possible_keys": ["idx1", "idx2"],
"key": "idx1",
"key_length": "5",
"used_key_parts": ["d"],
+ "ref": ["test.t1.a"],
"rowid_filter": {
"range": {
"key": "idx2",
@@ -2764,23 +2769,9 @@ EXPLAIN
"rows": 7,
"selectivity_pct": 6.730769231
},
- "rows": 7,
- "filtered": 14.28571415,
- "index_condition": "t2.d is not null",
- "attached_condition": "(t2.d,t2.e) in (<cache>((4,4)),<cache>((7,7)),<cache>((8,8))) and octet_length(t2.f) = 1"
- }
- },
- {
- "table": {
- "table_name": "t1",
- "access_type": "ref",
- "possible_keys": ["idx"],
- "key": "idx",
- "key_length": "5",
- "used_key_parts": ["a"],
- "ref": ["test.t2.d"],
- "rows": 11,
- "filtered": 100
+ "rows": 12,
+ "filtered": 6.730769157,
+ "attached_condition": "(t1.a,t2.e) in (<cache>((4,4)),<cache>((7,7)),<cache>((8,8))) and octet_length(t2.f) = 1"
}
}
]
@@ -2789,14 +2780,14 @@ EXPLAIN
select * from t1,t2
where a = d and (a,e) in ((4,4),(7,7),(8,8)) and length(f) = 1;
a b c d e f
-7 7 xxxyy 7 7 h
7 7 xxxya 7 7 h
-7 7 xxxyy 7 7 h
7 7 xxxya 7 7 h
-7 8 xxxxx 7 7 h
+7 7 xxxyy 7 7 h
+7 7 xxxyy 7 7 h
7 8 xxxxa 7 7 h
-7 8 xxxxx 7 7 h
7 8 xxxxa 7 7 h
+7 8 xxxxx 7 7 h
+7 8 xxxxx 7 7 h
alter table t2 drop index idx1, drop index idx2, add index idx3(d,e);
# join order: (t2,t1) with ref access of t1
# range access to t2 by 2-component keys for index idx3
@@ -2900,22 +2891,22 @@ EXPLAIN
select * from t1,t2
where a = d and (a,e) in ((4,d+1),(7,d+1),(8,d+1)) and length(f) = 1;
a b c d e f
-4 3 zyx 4 5 a
4 3 zya 4 5 a
-4 3 zyx 4 5 a
4 3 zya 4 5 a
-4 5 ww 4 5 a
+4 3 zyx 4 5 a
+4 3 zyx 4 5 a
4 5 wa 4 5 a
-4 5 ww 4 5 a
4 5 wa 4 5 a
-7 7 xxxyy 7 8 b
+4 5 ww 4 5 a
+4 5 ww 4 5 a
7 7 xxxya 7 8 b
-7 7 xxxyy 7 8 b
7 7 xxxya 7 8 b
-7 8 xxxxx 7 8 b
+7 7 xxxyy 7 8 b
+7 7 xxxyy 7 8 b
7 8 xxxxa 7 8 b
-7 8 xxxxx 7 8 b
7 8 xxxxa 7 8 b
+7 8 xxxxx 7 8 b
+7 8 xxxxx 7 8 b
# join order: (t1,t2) with ref access of t2
# no range access
explain select * from t1,t2
@@ -2960,14 +2951,14 @@ EXPLAIN
select * from t1,t2
where a = d and (a,e) in ((e,d+1),(7,7),(8,8)) and length(f) = 1;
a b c d e f
-7 8 xxxxx 7 7 h
-7 7 xxxyy 7 7 h
-7 8 xxxxa 7 7 h
7 7 xxxya 7 7 h
-7 8 xxxxx 7 7 h
+7 7 xxxya 7 7 h
+7 7 xxxyy 7 7 h
7 7 xxxyy 7 7 h
7 8 xxxxa 7 7 h
-7 7 xxxya 7 7 h
+7 8 xxxxa 7 7 h
+7 8 xxxxx 7 7 h
+7 8 xxxxx 7 7 h
# join order: (t1,t2) with ref access of t2
# range access to t1 by 1-component keys for index idx
explain select * from t1,t2
diff --git a/mysql-test/main/range.test b/mysql-test/main/range.test
index c42670c1ed1..a8c56fcc35c 100644
--- a/mysql-test/main/range.test
+++ b/mysql-test/main/range.test
@@ -1025,7 +1025,7 @@ create table t2 (a int, b int, filler char(100));
insert into t2 select A.a + 10 * (B.a + 10 * C.a), 10, 'filler' from t1 A,
t1 B, t1 C where A.a < 5;
-insert into t2 select 1000, b, 'filler' from t2;
+insert into t2 select 1000, b, 'filler' from t2 limit 250;
alter table t2 add index (a,b);
# t2 values
# ( 1 , 10, 'filler')
@@ -1033,13 +1033,14 @@ alter table t2 add index (a,b);
# ( 3 , 10, 'filler')
# (... , 10, 'filler')
# ...
-# (1000, 10, 'filler') - 500 times
+# (1000, 10, 'filler') - 250 times
-# 500 rows, 1 row
+# 250 rows, 1 row
-select 'In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)' Z;
-explain select * from t2 where a=1000 and b<11;
+--echo # In following EXPLAIN the access method should be ref, #rows~=250
+--echo # (and not 2) when we are not using rowid-ordered scans
+explain select * from t2 where a=1000 and b<11;
drop table t1, t2;
#
@@ -1980,6 +1981,7 @@ select * from t1,t2
where a = d and (a,e) in ((3,3),(7,7),(8,8)) and length(f) = 1;
eval explain $q5;
eval explain format=json $q5;
+--sorted_result
eval $q5;
eval prepare stmt from "$q5";
execute stmt;
@@ -1995,6 +1997,7 @@ select * from t1,t2
where a = d and (a,e) in ((4,4),(7,7),(8,8)) and length(f) = 1;
eval explain $q6;
eval explain format=json $q6;
+--sorted_result
eval $q6;
alter table t2 drop index idx1, drop index idx2, add index idx3(d,e);
@@ -2015,6 +2018,7 @@ select * from t1,t2
where a = d and (a,e) in ((4,d+1),(7,d+1),(8,d+1)) and length(f) = 1;
eval explain $q8;
eval explain format=json $q8;
+--sorted_result
eval $q8;
--echo # join order: (t1,t2) with ref access of t2
@@ -2024,6 +2028,7 @@ select * from t1,t2
where a = d and (a,e) in ((e,d+1),(7,7),(8,8)) and length(f) = 1;
eval explain $q9;
eval explain format=json $q9;
+--sorted_result
eval $q9;
--echo # join order: (t1,t2) with ref access of t2
diff --git a/mysql-test/main/range_innodb.result b/mysql-test/main/range_innodb.result
index eddfbfd0d62..011ae411b21 100644
--- a/mysql-test/main/range_innodb.result
+++ b/mysql-test/main/range_innodb.result
@@ -53,9 +53,9 @@ set optimizer_switch='extended_keys=on';
explain
select pk, a, b from t1,t2,t3 where b >= d and pk < c and b = '0';
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 ref PRIMARY,idx1,idx2 idx1 5 const 3 Using index condition
-1 SIMPLE t3 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t2 ALL NULL NULL NULL NULL #
+1 SIMPLE t1 ALL PRIMARY,idx1,idx2 NULL NULL NULL # Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t3 ALL NULL NULL NULL NULL # Using where; Using join buffer (incremental, BNL join)
select pk, a, b from t1,t2,t3 where b >= d and pk < c and b = '0';
pk a b
1 6 0
@@ -83,6 +83,7 @@ drop table t1,t2;
# MDEV-14440: Server crash in in handler::ha_external_lock or Assertion `inited==RND'
# failed in handler::ha_rnd_end upon SELECT from partitioned table
#
+call mtr.add_suppression("Got error .* when reading table");
set @optimizer_switch_save= @@optimizer_switch;
set optimizer_switch='index_merge_sort_intersection=off';
create table t0(a int);
diff --git a/mysql-test/main/range_innodb.test b/mysql-test/main/range_innodb.test
index 276b9cea08f..35511279910 100644
--- a/mysql-test/main/range_innodb.test
+++ b/mysql-test/main/range_innodb.test
@@ -58,6 +58,8 @@ insert into t3 values (3),(-1),(4);
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='extended_keys=on';
+# InnoDB sometimes returns 4 other times 5 records for t1
+--replace_column 9 #
explain
select pk, a, b from t1,t2,t3 where b >= d and pk < c and b = '0';
select pk, a, b from t1,t2,t3 where b >= d and pk < c and b = '0';
@@ -89,6 +91,8 @@ drop table t1,t2;
--echo # failed in handler::ha_rnd_end upon SELECT from partitioned table
--echo #
+call mtr.add_suppression("Got error .* when reading table");
+
set @optimizer_switch_save= @@optimizer_switch;
set optimizer_switch='index_merge_sort_intersection=off';
create table t0(a int);
diff --git a/mysql-test/main/range_mrr_icp.result b/mysql-test/main/range_mrr_icp.result
index d2d06ab7b42..a3c8bb7b8c2 100644
--- a/mysql-test/main/range_mrr_icp.result
+++ b/mysql-test/main/range_mrr_icp.result
@@ -255,7 +255,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref x x 5 const 1 Using index
explain select count(*) from t1 where x in (1,2,3,4);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range x x 5 NULL 4 Using where; Using index
+1 SIMPLE t1 index x x 5 NULL 9 Using where; Using index
drop table t1;
CREATE TABLE t1 (key1 int(11) NOT NULL default '0', KEY i1 (key1));
INSERT INTO t1 VALUES (0),(0),(0),(0),(0),(1),(1);
@@ -264,12 +264,12 @@ INSERT INTO t2 VALUES (0),(0),(1),(1),(2),(2);
explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref j1 j1 4 const 1 Using index
-1 SIMPLE t1 range i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join)
+1 SIMPLE t1 index i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join)
explain select * from t1 force index(i1), t2 force index(j1) where
(t1.key1 <t2.keya + 1) and t2.keya=3;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref j1 j1 4 const 1 Using index
-1 SIMPLE t1 range i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join)
+1 SIMPLE t1 index i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join)
DROP TABLE t1,t2;
CREATE TABLE t1 (
a int(11) default NULL,
@@ -679,7 +679,7 @@ create table t1(a char(2), key(a(1)));
insert into t1 values ('x'), ('xx');
explain select a from t1 where a > 'x';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range a a 2 NULL 2 Using where
+1 SIMPLE t1 ALL a NULL NULL NULL 2 Using where
select a from t1 where a > 'x';
a
xx
@@ -1141,7 +1141,7 @@ INSERT INTO t1 VALUES
('A2','2005-12-01 08:00:00',1000);
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref PRIMARY PRIMARY 20 const 3 Using index condition
+1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 4 Using where
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
item started price
Warnings:
@@ -1239,14 +1239,13 @@ insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 (a int, b int, filler char(100));
insert into t2 select A.a + 10 * (B.a + 10 * C.a), 10, 'filler' from t1 A,
t1 B, t1 C where A.a < 5;
-insert into t2 select 1000, b, 'filler' from t2;
+insert into t2 select 1000, b, 'filler' from t2 limit 250;
alter table t2 add index (a,b);
-select 'In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)' Z;
-Z
-In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)
+# In following EXPLAIN the access method should be ref, #rows~=250
+# (and not 2) when we are not using rowid-ordered scans
explain select * from t2 where a=1000 and b<11;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ref a a 5 const 503 Using index condition
+1 SIMPLE t2 range a a 10 NULL 253 Using index condition; Rowid-ordered scan
drop table t1, t2;
CREATE TABLE t1( a INT, b INT, KEY( a, b ) );
CREATE TABLE t2( a INT, b INT, KEY( a, b ) );
@@ -2566,7 +2565,7 @@ EXPLAIN
"key_length": "5",
"used_key_parts": ["d"],
"rows": 3,
- "filtered": 60,
+ "filtered": 100,
"index_condition": "t2.d is not null",
"attached_condition": "(t2.d,t2.e) in (<cache>((3,3)),<cache>((7,7)),<cache>((2,2)))",
"mrr_type": "Rowid-ordered scan"
@@ -2645,7 +2644,7 @@ EXPLAIN
"key_length": "5",
"used_key_parts": ["d"],
"rows": 8,
- "filtered": 14.42307663,
+ "filtered": 100,
"index_condition": "t2.d is not null",
"attached_condition": "(t2.d,t2.e) in (<cache>((3,3)),<cache>((7,7)),<cache>((8,8))) and octet_length(t2.f) = 1",
"mrr_type": "Rowid-ordered scan"
@@ -2670,22 +2669,22 @@ EXPLAIN
select * from t1,t2
where a = d and (a,e) in ((3,3),(7,7),(8,8)) and length(f) = 1;
a b c d e f
-3 2 uuuw 3 3 i
3 2 uuua 3 3 i
-3 3 zzzz 3 3 i
+3 2 uuua 3 3 i
+3 2 uuuw 3 3 i
+3 2 uuuw 3 3 i
+3 3 zyxa 3 3 i
+3 3 zyxa 3 3 i
+3 3 zyxw 3 3 i
3 3 zyxw 3 3 i
3 3 zzza 3 3 i
-3 3 zyxa 3 3 i
-7 7 xxxyy 7 7 h
+3 3 zzza 3 3 i
+3 3 zzzz 3 3 i
+3 3 zzzz 3 3 i
7 7 xxxya 7 7 h
-7 8 xxxxx 7 7 h
+7 7 xxxyy 7 7 h
7 8 xxxxa 7 7 h
-3 2 uuuw 3 3 i
-3 2 uuua 3 3 i
-3 3 zzzz 3 3 i
-3 3 zyxw 3 3 i
-3 3 zzza 3 3 i
-3 3 zyxa 3 3 i
+7 8 xxxxx 7 7 h
prepare stmt from "select * from t1,t2
where a = d and (a,e) in ((3,3),(7,7),(8,8)) and length(f) = 1";
execute stmt;
@@ -2749,7 +2748,7 @@ EXPLAIN
"key_length": "5",
"used_key_parts": ["d"],
"rows": 7,
- "filtered": 14.28571415,
+ "filtered": 100,
"index_condition": "t2.d is not null",
"attached_condition": "(t2.d,t2.e) in (<cache>((4,4)),<cache>((7,7)),<cache>((8,8))) and octet_length(t2.f) = 1",
"mrr_type": "Rowid-ordered scan"
@@ -2774,14 +2773,14 @@ EXPLAIN
select * from t1,t2
where a = d and (a,e) in ((4,4),(7,7),(8,8)) and length(f) = 1;
a b c d e f
-7 7 xxxyy 7 7 h
7 7 xxxya 7 7 h
-7 7 xxxyy 7 7 h
7 7 xxxya 7 7 h
-7 8 xxxxx 7 7 h
+7 7 xxxyy 7 7 h
+7 7 xxxyy 7 7 h
7 8 xxxxa 7 7 h
-7 8 xxxxx 7 7 h
7 8 xxxxa 7 7 h
+7 8 xxxxx 7 7 h
+7 8 xxxxx 7 7 h
alter table t2 drop index idx1, drop index idx2, add index idx3(d,e);
# join order: (t2,t1) with ref access of t1
# range access to t2 by 2-component keys for index idx3
@@ -2887,22 +2886,22 @@ EXPLAIN
select * from t1,t2
where a = d and (a,e) in ((4,d+1),(7,d+1),(8,d+1)) and length(f) = 1;
a b c d e f
-4 5 ww 4 5 a
-7 8 xxxxx 7 8 b
+4 3 zya 4 5 a
+4 3 zya 4 5 a
+4 3 zyx 4 5 a
4 3 zyx 4 5 a
-7 7 xxxyy 7 8 b
4 5 wa 4 5 a
-7 8 xxxxa 7 8 b
-4 3 zya 4 5 a
-7 7 xxxya 7 8 b
+4 5 wa 4 5 a
4 5 ww 4 5 a
-7 8 xxxxx 7 8 b
-4 3 zyx 4 5 a
+4 5 ww 4 5 a
+7 7 xxxya 7 8 b
+7 7 xxxya 7 8 b
+7 7 xxxyy 7 8 b
7 7 xxxyy 7 8 b
-4 5 wa 4 5 a
7 8 xxxxa 7 8 b
-4 3 zya 4 5 a
-7 7 xxxya 7 8 b
+7 8 xxxxa 7 8 b
+7 8 xxxxx 7 8 b
+7 8 xxxxx 7 8 b
# join order: (t1,t2) with ref access of t2
# no range access
explain select * from t1,t2
@@ -2947,14 +2946,14 @@ EXPLAIN
select * from t1,t2
where a = d and (a,e) in ((e,d+1),(7,7),(8,8)) and length(f) = 1;
a b c d e f
-7 8 xxxxx 7 7 h
-7 7 xxxyy 7 7 h
-7 8 xxxxa 7 7 h
7 7 xxxya 7 7 h
-7 8 xxxxx 7 7 h
+7 7 xxxya 7 7 h
+7 7 xxxyy 7 7 h
7 7 xxxyy 7 7 h
7 8 xxxxa 7 7 h
-7 7 xxxya 7 7 h
+7 8 xxxxa 7 7 h
+7 8 xxxxx 7 7 h
+7 8 xxxxx 7 7 h
# join order: (t1,t2) with ref access of t2
# range access to t1 by 1-component keys for index idx
explain select * from t1,t2
diff --git a/mysql-test/main/range_notembedded.result b/mysql-test/main/range_notembedded.result
index e1bcc7463d5..b3d2dfbb43b 100644
--- a/mysql-test/main/range_notembedded.result
+++ b/mysql-test/main/range_notembedded.result
@@ -13,7 +13,7 @@ set @tmp_21958=@@optimizer_trace;
set optimizer_trace=1;
explain select * from t2 where key1 in (1,2,3) and pk not in (1,2,3);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 range PRIMARY,key1 key1 5 NULL 3 Using index condition
+1 SIMPLE t2 ALL PRIMARY,key1 NULL NULL NULL 5 Using where
# This should show only ranges in form "(1) <= (key1) <= (1)"
# ranges over "pk" should not be constructed.
select json_detailed(JSON_EXTRACT(trace, '$**.ranges'))
@@ -24,11 +24,6 @@ json_detailed(JSON_EXTRACT(trace, '$**.ranges'))
"(1) <= (key1) <= (1)",
"(2) <= (key1) <= (2)",
"(3) <= (key1) <= (3)"
- ],
- [
- "(1) <= (key1) <= (1)",
- "(2) <= (key1) <= (2)",
- "(3) <= (key1) <= (3)"
]
]
set optimizer_trace=@tmp_21958;
@@ -225,9 +220,10 @@ user_id int(10) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (notification_type_id,item_id,item_parent_id,user_id)
);
insert into t1 values (1,1,1,1), (2,2,2,2), (3,3,3,3);
+insert into t1 select seq,seq,seq,seq from seq_10_to_30;
# Run crashing query
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range PRIMARY PRIMARY 2 NULL 3 Using where
+1 SIMPLE t1 range PRIMARY PRIMARY 2 NULL 5 Using where
drop table t1;
#
# MDEV-25069: Assertion `root->weight >= ...' failed in SEL_ARG::tree_delete #2
diff --git a/mysql-test/main/range_notembedded.test b/mysql-test/main/range_notembedded.test
index 00d16a5d564..5778cdbd82c 100644
--- a/mysql-test/main/range_notembedded.test
+++ b/mysql-test/main/range_notembedded.test
@@ -122,6 +122,7 @@ CREATE TABLE t1 (
PRIMARY KEY (notification_type_id,item_id,item_parent_id,user_id)
);
insert into t1 values (1,1,1,1), (2,2,2,2), (3,3,3,3);
+insert into t1 select seq,seq,seq,seq from seq_10_to_30;
let $consts=`select group_concat(concat("'",seq,"'")) from seq_1_to_4642`;
diff --git a/mysql-test/main/range_vs_index_merge.result b/mysql-test/main/range_vs_index_merge.result
index 1729b95a105..3babbc989b3 100644
--- a/mysql-test/main/range_vs_index_merge.result
+++ b/mysql-test/main/range_vs_index_merge.result
@@ -333,7 +333,7 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN
SELECT * FROM City WHERE (ID < 600) OR (ID BETWEEN 900 AND 1500);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE City ALL PRIMARY NULL NULL NULL 4079 Using where
+1 SIMPLE City range PRIMARY PRIMARY 4 NULL 1200 Using index condition
EXPLAIN
SELECT * FROM City WHERE Country > 'A' AND Country < 'ARG';
id select_type table type possible_keys key key_len ref rows Extra
@@ -1077,7 +1077,7 @@ EXPLAIN SELECT Name, Country, Population FROM City WHERE
(Name='Samara' AND Country='RUS') OR
(Name='Seattle' AND Country='USA');
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE City index_merge Country,CountryPopulation,CountryName,CityName CountryName,CityName 38,35 NULL 28 Using sort_union(CountryName,CityName); Using where
+1 SIMPLE City range Country,CountryPopulation,CountryName,CityName CountryName 38 NULL 28 Using index condition
SELECT Name, Country, Population FROM City WHERE
(Name='Manila' AND Country='PHL') OR
(Name='Addis Abeba' AND Country='ETH') OR
diff --git a/mysql-test/main/range_vs_index_merge.test b/mysql-test/main/range_vs_index_merge.test
index 38b643c0b13..6517beab0be 100644
--- a/mysql-test/main/range_vs_index_merge.test
+++ b/mysql-test/main/range_vs_index_merge.test
@@ -659,7 +659,7 @@ let $cond =
(Name='Lugansk' AND Country='UKR') OR
(Name='Caracas' AND Country='VEN') OR
(Name='Samara' AND Country='RUS') OR
-(Name='Seattle' AND Country='USA');
+(Name='Seattle' AND Country='USA');
eval
EXPLAIN SELECT Name, Country, Population FROM City WHERE
diff --git a/mysql-test/main/range_vs_index_merge_innodb.result b/mysql-test/main/range_vs_index_merge_innodb.result
index 79a670aedb2..de345f66161 100644
--- a/mysql-test/main/range_vs_index_merge_innodb.result
+++ b/mysql-test/main/range_vs_index_merge_innodb.result
@@ -365,7 +365,7 @@ WHERE ((ID < 800) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
OR ((ID BETWEEN 900 AND 1500) AND
(Name LIKE 'Pa%' OR (Population > 103000 AND Population < 105000)));
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,Country,PRIMARY 39,3,4 NULL 683 Using sort_union(Name,Country,PRIMARY); Using where
+1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,Country,Population 39,3,4 NULL 212 Using sort_union(Name,Country,Population); Using where
EXPLAIN
SELECT * FROM City
WHERE ((ID < 200) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG')))
@@ -620,7 +620,7 @@ WHERE ((Population > 101000 AND Population < 102000) AND
((ID BETWEEN 3400 AND 3800) AND
(Country < 'AGO' OR Name LIKE 'Pa%'));
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE City index_merge PRIMARY,Population,Country,Name Population,PRIMARY 4,4 NULL 440 Using sort_union(Population,PRIMARY); Using where
+1 SIMPLE City index_merge PRIMARY,Population,Country,Name Country,Name,Population 3,39,4 NULL 115 Using sort_union(Country,Name,Population); Using where
EXPLAIN
SELECT * FROM City
WHERE ((Population > 101000 AND Population < 110000) AND
@@ -1804,7 +1804,7 @@ SELECT * FROM t1
WHERE t1.a>300 AND t1.c!=0 AND t1.b>=350 AND t1.b<=400 AND
(t1.c=0 OR t1.a=500);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range PRIMARY,idx idx 5 NULL 2 Using where; Using index
+1 SIMPLE t1 range PRIMARY,idx PRIMARY 4 NULL 1 Using where
SELECT * FROM t1
WHERE t1.a>300 AND t1.c!=0 AND t1.b>=350 AND t1.b<=400 AND
(t1.c=0 OR t1.a=500);
diff --git a/mysql-test/main/rowid_filter.result b/mysql-test/main/rowid_filter.result
index 3f27ef6540f..9a2251c91a6 100644
--- a/mysql-test/main/rowid_filter.result
+++ b/mysql-test/main/rowid_filter.result
@@ -242,7 +242,7 @@ EXPLAIN
"key_length": "4",
"used_key_parts": ["l_shipDATE"],
"rows": 509,
- "filtered": 11.69025803,
+ "filtered": 100,
"index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
"attached_condition": "lineitem.l_quantity > 45"
}
@@ -254,7 +254,7 @@ set statement optimizer_switch='rowid_filter=off' for ANALYZE SELECT l_orderkey,
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
l_quantity > 45;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE lineitem range i_l_shipdate,i_l_quantity i_l_shipdate 4 NULL 509 510.00 11.69 11.76 Using index condition; Using where
+1 SIMPLE lineitem range i_l_shipdate,i_l_quantity i_l_shipdate 4 NULL 509 510.00 100.00 11.76 Using index condition; Using where
set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT l_orderkey, l_linenumber, l_shipdate, l_quantity FROM lineitem
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
l_quantity > 45;
@@ -281,7 +281,7 @@ ANALYZE
"r_rows": 510,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 11.69025803,
+ "filtered": 100,
"r_filtered": 11.76470588,
"index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
"attached_condition": "lineitem.l_quantity > 45"
@@ -359,8 +359,8 @@ FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND
o_totalprice between 200000 and 230000;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 NULL 98 Using index condition
-1 SIMPLE orders eq_ref|filter PRIMARY,i_o_totalprice PRIMARY|i_o_totalprice 4|9 dbt3_s001.lineitem.l_orderkey 1 (5%) Using where; Using rowid filter
+1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 69 Using index condition
+1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (2%) Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND
@@ -372,42 +372,42 @@ EXPLAIN
"nested_loop": [
{
"table": {
- "table_name": "lineitem",
+ "table_name": "orders",
"access_type": "range",
+ "possible_keys": ["PRIMARY", "i_o_totalprice"],
+ "key": "i_o_totalprice",
+ "key_length": "9",
+ "used_key_parts": ["o_totalprice"],
+ "rows": 69,
+ "filtered": 100,
+ "index_condition": "orders.o_totalprice between 200000 and 230000"
+ }
+ },
+ {
+ "table": {
+ "table_name": "lineitem",
+ "access_type": "ref",
"possible_keys": [
"PRIMARY",
"i_l_shipdate",
"i_l_orderkey",
"i_l_orderkey_quantity"
],
- "key": "i_l_shipdate",
- "key_length": "4",
- "used_key_parts": ["l_shipDATE"],
- "rows": 98,
- "filtered": 100,
- "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'"
- }
- },
- {
- "table": {
- "table_name": "orders",
- "access_type": "eq_ref",
- "possible_keys": ["PRIMARY", "i_o_totalprice"],
- "key": "PRIMARY",
+ "key": "i_l_orderkey",
"key_length": "4",
- "used_key_parts": ["o_orderkey"],
- "ref": ["dbt3_s001.lineitem.l_orderkey"],
+ "used_key_parts": ["l_orderkey"],
+ "ref": ["dbt3_s001.orders.o_orderkey"],
"rowid_filter": {
"range": {
- "key": "i_o_totalprice",
- "used_key_parts": ["o_totalprice"]
+ "key": "i_l_shipdate",
+ "used_key_parts": ["l_shipDATE"]
},
- "rows": 69,
- "selectivity_pct": 4.6
+ "rows": 98,
+ "selectivity_pct": 1.631973356
},
- "rows": 1,
- "filtered": 4.599999905,
- "attached_condition": "orders.o_totalprice between 200000 and 230000"
+ "rows": 4,
+ "filtered": 1.631973386,
+ "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'"
}
}
]
@@ -418,8 +418,8 @@ FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND
o_totalprice between 200000 and 230000;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 NULL 98 98.00 100.00 100.00 Using index condition
-1 SIMPLE orders eq_ref|filter PRIMARY,i_o_totalprice PRIMARY|i_o_totalprice 4|9 dbt3_s001.lineitem.l_orderkey 1 (5%) 0.11 (10%) 4.60 100.00 Using where; Using rowid filter
+1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 69 71.00 100.00 100.00 Using index condition
+1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (2%) 0.15 (2%) 1.63 100.00 Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND
@@ -436,57 +436,57 @@ ANALYZE
"nested_loop": [
{
"table": {
- "table_name": "lineitem",
+ "table_name": "orders",
"access_type": "range",
- "possible_keys": [
- "PRIMARY",
- "i_l_shipdate",
- "i_l_orderkey",
- "i_l_orderkey_quantity"
- ],
- "key": "i_l_shipdate",
- "key_length": "4",
- "used_key_parts": ["l_shipDATE"],
+ "possible_keys": ["PRIMARY", "i_o_totalprice"],
+ "key": "i_o_totalprice",
+ "key_length": "9",
+ "used_key_parts": ["o_totalprice"],
"r_loops": 1,
- "rows": 98,
- "r_rows": 98,
+ "rows": 69,
+ "r_rows": 71,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"filtered": 100,
"r_filtered": 100,
- "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'"
+ "index_condition": "orders.o_totalprice between 200000 and 230000"
}
},
{
"table": {
- "table_name": "orders",
- "access_type": "eq_ref",
- "possible_keys": ["PRIMARY", "i_o_totalprice"],
- "key": "PRIMARY",
+ "table_name": "lineitem",
+ "access_type": "ref",
+ "possible_keys": [
+ "PRIMARY",
+ "i_l_shipdate",
+ "i_l_orderkey",
+ "i_l_orderkey_quantity"
+ ],
+ "key": "i_l_orderkey",
"key_length": "4",
- "used_key_parts": ["o_orderkey"],
- "ref": ["dbt3_s001.lineitem.l_orderkey"],
+ "used_key_parts": ["l_orderkey"],
+ "ref": ["dbt3_s001.orders.o_orderkey"],
"rowid_filter": {
"range": {
- "key": "i_o_totalprice",
- "used_key_parts": ["o_totalprice"]
+ "key": "i_l_shipdate",
+ "used_key_parts": ["l_shipDATE"]
},
- "rows": 69,
- "selectivity_pct": 4.6,
- "r_rows": 71,
- "r_lookups": 96,
- "r_selectivity_pct": 10.41666667,
+ "rows": 98,
+ "selectivity_pct": 1.631973356,
+ "r_rows": 98,
+ "r_lookups": 476,
+ "r_selectivity_pct": 2.31092437,
"r_buffer_size": "REPLACED",
"r_filling_time_ms": "REPLACED"
},
- "r_loops": 98,
- "rows": 1,
- "r_rows": 0.112244898,
+ "r_loops": 71,
+ "rows": 4,
+ "r_rows": 0.154929577,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 4.599999905,
+ "filtered": 1.631973386,
"r_filtered": 100,
- "attached_condition": "orders.o_totalprice between 200000 and 230000"
+ "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'"
}
}
]
@@ -647,8 +647,8 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
l_quantity > 45 AND
o_totalprice between 180000 and 230000;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE lineitem range|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate|i_l_quantity 4|9 NULL 509 (12%) Using index condition; Using where; Using rowid filter
-1 SIMPLE orders eq_ref|filter PRIMARY,i_o_totalprice PRIMARY|i_o_totalprice 4|9 dbt3_s001.lineitem.l_orderkey 1 (9%) Using where; Using rowid filter
+1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 139 Using index condition
+1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (8%) Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
@@ -661,8 +661,21 @@ EXPLAIN
"nested_loop": [
{
"table": {
- "table_name": "lineitem",
+ "table_name": "orders",
"access_type": "range",
+ "possible_keys": ["PRIMARY", "i_o_totalprice"],
+ "key": "i_o_totalprice",
+ "key_length": "9",
+ "used_key_parts": ["o_totalprice"],
+ "rows": 139,
+ "filtered": 100,
+ "index_condition": "orders.o_totalprice between 180000 and 230000"
+ }
+ },
+ {
+ "table": {
+ "table_name": "lineitem",
+ "access_type": "ref",
"possible_keys": [
"PRIMARY",
"i_l_shipdate",
@@ -670,43 +683,21 @@ EXPLAIN
"i_l_orderkey_quantity",
"i_l_quantity"
],
- "key": "i_l_shipdate",
- "key_length": "4",
- "used_key_parts": ["l_shipDATE"],
- "rowid_filter": {
- "range": {
- "key": "i_l_quantity",
- "used_key_parts": ["l_quantity"]
- },
- "rows": 702,
- "selectivity_pct": 11.69025812
- },
- "rows": 509,
- "filtered": 11.69025803,
- "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
- "attached_condition": "lineitem.l_quantity > 45"
- }
- },
- {
- "table": {
- "table_name": "orders",
- "access_type": "eq_ref",
- "possible_keys": ["PRIMARY", "i_o_totalprice"],
- "key": "PRIMARY",
+ "key": "i_l_orderkey",
"key_length": "4",
- "used_key_parts": ["o_orderkey"],
- "ref": ["dbt3_s001.lineitem.l_orderkey"],
+ "used_key_parts": ["l_orderkey"],
+ "ref": ["dbt3_s001.orders.o_orderkey"],
"rowid_filter": {
"range": {
- "key": "i_o_totalprice",
- "used_key_parts": ["o_totalprice"]
+ "key": "i_l_shipdate",
+ "used_key_parts": ["l_shipDATE"]
},
- "rows": 139,
- "selectivity_pct": 9.266666667
+ "rows": 509,
+ "selectivity_pct": 8.476269775
},
- "rows": 1,
- "filtered": 9.266666412,
- "attached_condition": "orders.o_totalprice between 180000 and 230000"
+ "rows": 4,
+ "filtered": 0.990897834,
+ "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 45"
}
}
]
@@ -718,8 +709,8 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
l_quantity > 45 AND
o_totalprice between 180000 and 230000;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE lineitem range|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate|i_l_quantity 4|9 NULL 509 (12%) 60.00 (11%) 11.69 100.00 Using index condition; Using where; Using rowid filter
-1 SIMPLE orders eq_ref|filter PRIMARY,i_o_totalprice PRIMARY|i_o_totalprice 4|9 dbt3_s001.lineitem.l_orderkey 1 (9%) 0.27 (25%) 9.27 100.00 Using where; Using rowid filter
+1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 139 144.00 100.00 100.00 Using index condition
+1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (8%) 0.54 (8%) 0.99 20.51 Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
@@ -737,72 +728,58 @@ ANALYZE
"nested_loop": [
{
"table": {
- "table_name": "lineitem",
+ "table_name": "orders",
"access_type": "range",
- "possible_keys": [
- "PRIMARY",
- "i_l_shipdate",
- "i_l_orderkey",
- "i_l_orderkey_quantity",
- "i_l_quantity"
- ],
- "key": "i_l_shipdate",
- "key_length": "4",
- "used_key_parts": ["l_shipDATE"],
- "rowid_filter": {
- "range": {
- "key": "i_l_quantity",
- "used_key_parts": ["l_quantity"]
- },
- "rows": 702,
- "selectivity_pct": 11.69025812,
- "r_rows": 605,
- "r_lookups": 510,
- "r_selectivity_pct": 11.76470588,
- "r_buffer_size": "REPLACED",
- "r_filling_time_ms": "REPLACED"
- },
+ "possible_keys": ["PRIMARY", "i_o_totalprice"],
+ "key": "i_o_totalprice",
+ "key_length": "9",
+ "used_key_parts": ["o_totalprice"],
"r_loops": 1,
- "rows": 509,
- "r_rows": 60,
+ "rows": 139,
+ "r_rows": 144,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 11.69025803,
+ "filtered": 100,
"r_filtered": 100,
- "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
- "attached_condition": "lineitem.l_quantity > 45"
+ "index_condition": "orders.o_totalprice between 180000 and 230000"
}
},
{
"table": {
- "table_name": "orders",
- "access_type": "eq_ref",
- "possible_keys": ["PRIMARY", "i_o_totalprice"],
- "key": "PRIMARY",
+ "table_name": "lineitem",
+ "access_type": "ref",
+ "possible_keys": [
+ "PRIMARY",
+ "i_l_shipdate",
+ "i_l_orderkey",
+ "i_l_orderkey_quantity",
+ "i_l_quantity"
+ ],
+ "key": "i_l_orderkey",
"key_length": "4",
- "used_key_parts": ["o_orderkey"],
- "ref": ["dbt3_s001.lineitem.l_orderkey"],
+ "used_key_parts": ["l_orderkey"],
+ "ref": ["dbt3_s001.orders.o_orderkey"],
"rowid_filter": {
"range": {
- "key": "i_o_totalprice",
- "used_key_parts": ["o_totalprice"]
+ "key": "i_l_shipdate",
+ "used_key_parts": ["l_shipDATE"]
},
- "rows": 139,
- "selectivity_pct": 9.266666667,
- "r_rows": 144,
- "r_lookups": 59,
- "r_selectivity_pct": 25.42372881,
+ "rows": 509,
+ "selectivity_pct": 8.476269775,
+ "r_rows": 510,
+ "r_lookups": 954,
+ "r_selectivity_pct": 8.176100629,
"r_buffer_size": "REPLACED",
"r_filling_time_ms": "REPLACED"
},
- "r_loops": 60,
- "rows": 1,
- "r_rows": 0.266666667,
+ "r_loops": 144,
+ "rows": 4,
+ "r_rows": 0.541666667,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 9.266666412,
- "r_filtered": 100,
- "attached_condition": "orders.o_totalprice between 180000 and 230000"
+ "filtered": 0.990897834,
+ "r_filtered": 20.51282051,
+ "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 45"
}
}
]
@@ -836,8 +813,8 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
l_quantity > 45 AND
o_totalprice between 180000 and 230000;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate 4 NULL 509 Using index condition; Using where
-1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 Using where
+1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 139 Using index condition
+1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 Using where
set statement optimizer_switch='rowid_filter=off' for EXPLAIN FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
@@ -850,8 +827,21 @@ EXPLAIN
"nested_loop": [
{
"table": {
- "table_name": "lineitem",
+ "table_name": "orders",
"access_type": "range",
+ "possible_keys": ["PRIMARY", "i_o_totalprice"],
+ "key": "i_o_totalprice",
+ "key_length": "9",
+ "used_key_parts": ["o_totalprice"],
+ "rows": 139,
+ "filtered": 100,
+ "index_condition": "orders.o_totalprice between 180000 and 230000"
+ }
+ },
+ {
+ "table": {
+ "table_name": "lineitem",
+ "access_type": "ref",
"possible_keys": [
"PRIMARY",
"i_l_shipdate",
@@ -859,27 +849,13 @@ EXPLAIN
"i_l_orderkey_quantity",
"i_l_quantity"
],
- "key": "i_l_shipdate",
- "key_length": "4",
- "used_key_parts": ["l_shipDATE"],
- "rows": 509,
- "filtered": 11.69025803,
- "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
- "attached_condition": "lineitem.l_quantity > 45"
- }
- },
- {
- "table": {
- "table_name": "orders",
- "access_type": "eq_ref",
- "possible_keys": ["PRIMARY", "i_o_totalprice"],
- "key": "PRIMARY",
+ "key": "i_l_orderkey",
"key_length": "4",
- "used_key_parts": ["o_orderkey"],
- "ref": ["dbt3_s001.lineitem.l_orderkey"],
- "rows": 1,
- "filtered": 9.266666412,
- "attached_condition": "orders.o_totalprice between 180000 and 230000"
+ "used_key_parts": ["l_orderkey"],
+ "ref": ["dbt3_s001.orders.o_orderkey"],
+ "rows": 4,
+ "filtered": 0.990897834,
+ "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 45"
}
}
]
@@ -891,8 +867,8 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
l_quantity > 45 AND
o_totalprice between 180000 and 230000;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate 4 NULL 509 510.00 11.69 11.76 Using index condition; Using where
-1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 1.00 9.27 26.67 Using where
+1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 139 144.00 100.00 100.00 Using index condition
+1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 6.62 0.99 1.68 Using where
set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
@@ -910,46 +886,45 @@ ANALYZE
"nested_loop": [
{
"table": {
- "table_name": "lineitem",
+ "table_name": "orders",
"access_type": "range",
- "possible_keys": [
- "PRIMARY",
- "i_l_shipdate",
- "i_l_orderkey",
- "i_l_orderkey_quantity",
- "i_l_quantity"
- ],
- "key": "i_l_shipdate",
- "key_length": "4",
- "used_key_parts": ["l_shipDATE"],
+ "possible_keys": ["PRIMARY", "i_o_totalprice"],
+ "key": "i_o_totalprice",
+ "key_length": "9",
+ "used_key_parts": ["o_totalprice"],
"r_loops": 1,
- "rows": 509,
- "r_rows": 510,
+ "rows": 139,
+ "r_rows": 144,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 11.69025803,
- "r_filtered": 11.76470588,
- "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
- "attached_condition": "lineitem.l_quantity > 45"
+ "filtered": 100,
+ "r_filtered": 100,
+ "index_condition": "orders.o_totalprice between 180000 and 230000"
}
},
{
"table": {
- "table_name": "orders",
- "access_type": "eq_ref",
- "possible_keys": ["PRIMARY", "i_o_totalprice"],
- "key": "PRIMARY",
+ "table_name": "lineitem",
+ "access_type": "ref",
+ "possible_keys": [
+ "PRIMARY",
+ "i_l_shipdate",
+ "i_l_orderkey",
+ "i_l_orderkey_quantity",
+ "i_l_quantity"
+ ],
+ "key": "i_l_orderkey",
"key_length": "4",
- "used_key_parts": ["o_orderkey"],
- "ref": ["dbt3_s001.lineitem.l_orderkey"],
- "r_loops": 60,
- "rows": 1,
- "r_rows": 1,
+ "used_key_parts": ["l_orderkey"],
+ "ref": ["dbt3_s001.orders.o_orderkey"],
+ "r_loops": 144,
+ "rows": 4,
+ "r_rows": 6.625,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 9.266666412,
- "r_filtered": 26.66666667,
- "attached_condition": "orders.o_totalprice between 180000 and 230000"
+ "filtered": 0.990897834,
+ "r_filtered": 1.677148847,
+ "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 45"
}
}
]
@@ -977,13 +952,21 @@ o_orderkey l_linenumber l_shipdate l_quantity o_totalprice
5829 5 1997-01-31 49 183734.56
5895 2 1997-04-27 47 201419.83
5895 3 1997-03-15 49 201419.83
+set statement optimizer_switch='rowid_filter=on' for EXPLAIN SELECT STRAIGHT_JOIN o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice
+FROM lineitem JOIN orders ON o_orderkey=l_orderkey
+WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
+l_quantity > 45 AND
+o_totalprice between 180000 and 230000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE lineitem range|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate|i_l_quantity 4|9 NULL 509 (12%) Using index condition; Using where; Using rowid filter
+1 SIMPLE orders eq_ref|filter PRIMARY,i_o_totalprice PRIMARY|i_o_totalprice 4|9 dbt3_s001.lineitem.l_orderkey 1 (9%) Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for EXPLAIN SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
o_totalprice between 200000 and 230000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 69 Using index condition
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 Using where
+1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (8%) Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
@@ -1020,6 +1003,14 @@ EXPLAIN
"key_length": "4",
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
+ "rowid_filter": {
+ "range": {
+ "key": "i_l_shipdate",
+ "used_key_parts": ["l_shipDATE"]
+ },
+ "rows": 509,
+ "selectivity_pct": 8.476269775
+ },
"rows": 4,
"filtered": 8.476269722,
"attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'"
@@ -1034,7 +1025,7 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
o_totalprice between 200000 and 230000;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 69 71.00 100.00 100.00 Using index condition
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 6.70 8.48 7.77 Using where
+1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (8%) 0.52 (7%) 8.48 100.00 Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
@@ -1081,13 +1072,26 @@ ANALYZE
"key_length": "4",
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
+ "rowid_filter": {
+ "range": {
+ "key": "i_l_shipdate",
+ "used_key_parts": ["l_shipDATE"]
+ },
+ "rows": 509,
+ "selectivity_pct": 8.476269775,
+ "r_rows": 510,
+ "r_lookups": 476,
+ "r_selectivity_pct": 7.773109244,
+ "r_buffer_size": "REPLACED",
+ "r_filling_time_ms": "REPLACED"
+ },
"r_loops": 71,
"rows": 4,
- "r_rows": 6.704225352,
+ "r_rows": 0.521126761,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"filtered": 8.476269722,
- "r_filtered": 7.773109244,
+ "r_filtered": 100,
"attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'"
}
}
@@ -1337,7 +1341,7 @@ EXPLAIN
"key_length": "4",
"used_key_parts": ["l_receiptDATE"],
"rows": 18,
- "filtered": 5.555555344,
+ "filtered": 100,
"index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'",
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-10-10'"
}
@@ -1366,7 +1370,7 @@ l_shipdate BETWEEN '1996-10-01' AND '1996-10-10' AND
l_receiptdate BETWEEN '1996-10-05' AND '1996-10-10' AND
o_totalprice BETWEEN 200000 AND 250000;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_receiptdate 4 NULL 18 18.00 5.56 38.89 Using index condition; Using where
+1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_receiptdate 4 NULL 18 18.00 100.00 38.89 Using index condition; Using where
1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 1.00 7.47 14.29 Using where
set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT l_shipdate, l_receiptdate, o_totalprice
FROM orders, lineitem
@@ -1403,7 +1407,7 @@ ANALYZE
"r_rows": 18,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 5.555555344,
+ "filtered": 100,
"r_filtered": 38.88888889,
"index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'",
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-10-10'"
@@ -1474,7 +1478,7 @@ EXPLAIN
"key_length": "4",
"used_key_parts": ["l_receiptDATE"],
"rows": 18,
- "filtered": 5.555555344,
+ "filtered": 100,
"index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'",
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-10-10'"
}
@@ -1503,7 +1507,7 @@ l_shipdate BETWEEN '1996-10-01' AND '1996-10-10' AND
l_receiptdate BETWEEN '1996-10-05' AND '1996-10-10' AND
o_totalprice BETWEEN 200000 AND 250000;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_receiptdate 4 NULL 18 18.00 5.56 38.89 Using index condition; Using where
+1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_receiptdate 4 NULL 18 18.00 100.00 38.89 Using index condition; Using where
1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 1.00 7.47 14.29 Using where
set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT l_shipdate, l_receiptdate, o_totalprice
FROM orders, lineitem
@@ -1540,7 +1544,7 @@ ANALYZE
"r_rows": 18,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 5.555555344,
+ "filtered": 100,
"r_filtered": 38.88888889,
"index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'",
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-10-10'"
@@ -1591,7 +1595,7 @@ o_totalprice BETWEEN 200000 AND 220000 AND
l_shipdate BETWEEN '1996-10-01' AND '1996-12-01';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 Using index condition; Using where
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 Using where
+1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate
FROM orders, lineitem
WHERE o_orderkey=l_orderkey AND
@@ -1612,7 +1616,7 @@ EXPLAIN
"key_length": "9",
"used_key_parts": ["o_totaldiscount"],
"rows": 39,
- "filtered": 3.200000048,
+ "filtered": 100,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
"attached_condition": "orders.o_totalprice between 200000 and 220000"
}
@@ -1631,6 +1635,14 @@ EXPLAIN
"key_length": "4",
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
+ "rowid_filter": {
+ "range": {
+ "key": "i_l_shipdate",
+ "used_key_parts": ["l_shipDATE"]
+ },
+ "rows": 183,
+ "selectivity_pct": 3.04746045
+ },
"rows": 4,
"filtered": 3.047460556,
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'"
@@ -1646,8 +1658,8 @@ o_totaldiscount BETWEEN 18000 AND 20000 AND
o_totalprice BETWEEN 200000 AND 220000 AND
l_shipdate BETWEEN '1996-10-01' AND '1996-12-01';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 41.00 3.20 2.44 Using index condition; Using where
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 6.00 3.05 66.67 Using where
+1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 41.00 100.00 2.44 Using index condition; Using where
+1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) 4.00 (66%) 3.05 100.00 Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate
FROM orders, lineitem
WHERE o_orderkey=l_orderkey AND
@@ -1677,7 +1689,7 @@ ANALYZE
"r_rows": 41,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 3.200000048,
+ "filtered": 100,
"r_filtered": 2.43902439,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
"attached_condition": "orders.o_totalprice between 200000 and 220000"
@@ -1697,13 +1709,26 @@ ANALYZE
"key_length": "4",
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
+ "rowid_filter": {
+ "range": {
+ "key": "i_l_shipdate",
+ "used_key_parts": ["l_shipDATE"]
+ },
+ "rows": 183,
+ "selectivity_pct": 3.04746045,
+ "r_rows": 183,
+ "r_lookups": 6,
+ "r_selectivity_pct": 66.66666667,
+ "r_buffer_size": "REPLACED",
+ "r_filling_time_ms": "REPLACED"
+ },
"r_loops": 1,
"rows": 4,
- "r_rows": 6,
+ "r_rows": 4,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"filtered": 3.047460556,
- "r_filtered": 66.66666667,
+ "r_filtered": 100,
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'"
}
}
@@ -1750,7 +1775,7 @@ EXPLAIN
"key_length": "9",
"used_key_parts": ["o_totaldiscount"],
"rows": 39,
- "filtered": 3.200000048,
+ "filtered": 100,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
"attached_condition": "orders.o_totalprice between 200000 and 220000"
}
@@ -1784,7 +1809,7 @@ o_totaldiscount BETWEEN 18000 AND 20000 AND
o_totalprice BETWEEN 200000 AND 220000 AND
l_shipdate BETWEEN '1996-10-01' AND '1996-12-01';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 41.00 3.20 2.44 Using index condition; Using where
+1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 41.00 100.00 2.44 Using index condition; Using where
1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 6.00 3.05 66.67 Using where
set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate
FROM orders, lineitem
@@ -1815,7 +1840,7 @@ ANALYZE
"r_rows": 41,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 3.200000048,
+ "filtered": 100,
"r_filtered": 2.43902439,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
"attached_condition": "orders.o_totalprice between 200000 and 220000"
@@ -1870,7 +1895,7 @@ o_totalprice BETWEEN 200000 AND 220000 AND
l_shipdate BETWEEN '1996-10-01' AND '1996-12-01';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 Using index condition; Using where
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 Using where
+1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate
FROM v1, lineitem
WHERE o_orderkey=l_orderkey AND
@@ -1915,6 +1940,14 @@ EXPLAIN
"key_length": "4",
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
+ "rowid_filter": {
+ "range": {
+ "key": "i_l_shipdate",
+ "used_key_parts": ["l_shipDATE"]
+ },
+ "rows": 183,
+ "selectivity_pct": 3.04746045
+ },
"rows": 4,
"filtered": "REPLACED",
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'"
@@ -1931,7 +1964,7 @@ o_totalprice BETWEEN 200000 AND 220000 AND
l_shipdate BETWEEN '1996-10-01' AND '1996-12-01';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 41.00 # 2.44 Using index condition; Using where
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 6.00 # 66.67 Using where
+1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) 4.00 (66%) # 100.00 Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate
FROM v1, lineitem
WHERE o_orderkey=l_orderkey AND
@@ -1986,13 +2019,26 @@ ANALYZE
"key_length": "4",
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
+ "rowid_filter": {
+ "range": {
+ "key": "i_l_shipdate",
+ "used_key_parts": ["l_shipDATE"]
+ },
+ "rows": 183,
+ "selectivity_pct": 3.04746045,
+ "r_rows": 183,
+ "r_lookups": 6,
+ "r_selectivity_pct": 66.66666667,
+ "r_buffer_size": "REPLACED",
+ "r_filling_time_ms": "REPLACED"
+ },
"r_loops": 1,
"rows": 4,
- "r_rows": 6,
+ "r_rows": 4,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"filtered": "REPLACED",
- "r_filtered": 66.66666667,
+ "r_filtered": 100,
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'"
}
}
@@ -2778,7 +2824,7 @@ ANALYZE
"r_rows": 44,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 8.630000114,
+ "filtered": 100,
"r_filtered": 0,
"index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'",
"attached_condition": "t1.fl2 = 0"
@@ -2831,7 +2877,7 @@ ANALYZE
"r_rows": 0,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 8.529999733,
+ "filtered": 100,
"r_filtered": 100,
"index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'",
"attached_condition": "t1.fl2 = 0"
diff --git a/mysql-test/main/rowid_filter.test b/mysql-test/main/rowid_filter.test
index a2543e197ca..79a158562aa 100644
--- a/mysql-test/main/rowid_filter.test
+++ b/mysql-test/main/rowid_filter.test
@@ -115,6 +115,13 @@ eval $without_filter ANALYZE FORMAT=JSON $q3;
--sorted_result
eval $without_filter $q3;
+# Check different optimization
+eval $with_filter EXPLAIN SELECT STRAIGHT_JOIN o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice
+ FROM lineitem JOIN orders ON o_orderkey=l_orderkey
+ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
+ l_quantity > 45 AND
+ o_totalprice between 180000 and 230000;
+
let $q4=
SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
diff --git a/mysql-test/main/rowid_filter_innodb.result b/mysql-test/main/rowid_filter_innodb.result
index 7f42e3a4143..b4b5fc8e679 100644
--- a/mysql-test/main/rowid_filter_innodb.result
+++ b/mysql-test/main/rowid_filter_innodb.result
@@ -245,7 +245,7 @@ EXPLAIN
"key_length": "4",
"used_key_parts": ["l_shipDATE"],
"rows": 510,
- "filtered": 10.07493782,
+ "filtered": 100,
"index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
"attached_condition": "lineitem.l_quantity > 45"
}
@@ -257,7 +257,7 @@ set statement optimizer_switch='rowid_filter=off' for ANALYZE SELECT l_orderkey,
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
l_quantity > 45;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE lineitem range i_l_shipdate,i_l_quantity i_l_shipdate 4 NULL 510 510.00 10.07 11.76 Using index condition; Using where
+1 SIMPLE lineitem range i_l_shipdate,i_l_quantity i_l_shipdate 4 NULL 510 510.00 100.00 11.76 Using index condition; Using where
set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT l_orderkey, l_linenumber, l_shipdate, l_quantity FROM lineitem
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
l_quantity > 45;
@@ -284,7 +284,7 @@ ANALYZE
"r_rows": 510,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 10.07493782,
+ "filtered": 100,
"r_filtered": 11.76470588,
"index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
"attached_condition": "lineitem.l_quantity > 45"
@@ -633,8 +633,8 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
l_quantity > 45 AND
o_totalprice between 180000 and 230000;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE lineitem range|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate|i_l_quantity 4|9 NULL 510 (10%) Using index condition; Using where; Using rowid filter
-1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 Using where
+1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 144 Using where; Using index
+1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (8%) Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
@@ -647,8 +647,22 @@ EXPLAIN
"nested_loop": [
{
"table": {
- "table_name": "lineitem",
+ "table_name": "orders",
"access_type": "range",
+ "possible_keys": ["PRIMARY", "i_o_totalprice"],
+ "key": "i_o_totalprice",
+ "key_length": "9",
+ "used_key_parts": ["o_totalprice"],
+ "rows": 144,
+ "filtered": 100,
+ "attached_condition": "orders.o_totalprice between 180000 and 230000",
+ "using_index": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "lineitem",
+ "access_type": "ref",
"possible_keys": [
"PRIMARY",
"i_l_shipdate",
@@ -656,35 +670,21 @@ EXPLAIN
"i_l_orderkey_quantity",
"i_l_quantity"
],
- "key": "i_l_shipdate",
+ "key": "i_l_orderkey",
"key_length": "4",
- "used_key_parts": ["l_shipDATE"],
+ "used_key_parts": ["l_orderkey"],
+ "ref": ["dbt3_s001.orders.o_orderkey"],
"rowid_filter": {
"range": {
- "key": "i_l_quantity",
- "used_key_parts": ["l_quantity"]
+ "key": "i_l_shipdate",
+ "used_key_parts": ["l_shipDATE"]
},
- "rows": 605,
- "selectivity_pct": 10.07493755
+ "rows": 510,
+ "selectivity_pct": 8.492922565
},
- "rows": 510,
- "filtered": 10.07493782,
- "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
- "attached_condition": "lineitem.l_quantity > 45"
- }
- },
- {
- "table": {
- "table_name": "orders",
- "access_type": "eq_ref",
- "possible_keys": ["PRIMARY", "i_o_totalprice"],
- "key": "PRIMARY",
- "key_length": "4",
- "used_key_parts": ["o_orderkey"],
- "ref": ["dbt3_s001.lineitem.l_orderkey"],
- "rows": 1,
- "filtered": 9.600000381,
- "attached_condition": "orders.o_totalprice between 180000 and 230000"
+ "rows": 4,
+ "filtered": 0.855656624,
+ "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 45"
}
}
]
@@ -696,8 +696,8 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
l_quantity > 45 AND
o_totalprice between 180000 and 230000;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE lineitem range|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate|i_l_quantity 4|9 NULL 510 (10%) 60.00 (11%) 10.07 100.00 Using index condition; Using where; Using rowid filter
-1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 1.00 9.60 26.67 Using where
+1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 144 144.00 100.00 100.00 Using where; Using index
+1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (8%) 0.54 (8%) 0.86 20.51 Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
@@ -715,8 +715,27 @@ ANALYZE
"nested_loop": [
{
"table": {
- "table_name": "lineitem",
+ "table_name": "orders",
"access_type": "range",
+ "possible_keys": ["PRIMARY", "i_o_totalprice"],
+ "key": "i_o_totalprice",
+ "key_length": "9",
+ "used_key_parts": ["o_totalprice"],
+ "r_loops": 1,
+ "rows": 144,
+ "r_rows": 144,
+ "r_table_time_ms": "REPLACED",
+ "r_other_time_ms": "REPLACED",
+ "filtered": 100,
+ "r_filtered": 100,
+ "attached_condition": "orders.o_totalprice between 180000 and 230000",
+ "using_index": true
+ }
+ },
+ {
+ "table": {
+ "table_name": "lineitem",
+ "access_type": "ref",
"possible_keys": [
"PRIMARY",
"i_l_shipdate",
@@ -724,50 +743,31 @@ ANALYZE
"i_l_orderkey_quantity",
"i_l_quantity"
],
- "key": "i_l_shipdate",
+ "key": "i_l_orderkey",
"key_length": "4",
- "used_key_parts": ["l_shipDATE"],
+ "used_key_parts": ["l_orderkey"],
+ "ref": ["dbt3_s001.orders.o_orderkey"],
"rowid_filter": {
"range": {
- "key": "i_l_quantity",
- "used_key_parts": ["l_quantity"]
+ "key": "i_l_shipdate",
+ "used_key_parts": ["l_shipDATE"]
},
- "rows": 605,
- "selectivity_pct": 10.07493755,
- "r_rows": 605,
- "r_lookups": 510,
- "r_selectivity_pct": 11.76470588,
+ "rows": 510,
+ "selectivity_pct": 8.492922565,
+ "r_rows": 510,
+ "r_lookups": 954,
+ "r_selectivity_pct": 8.176100629,
"r_buffer_size": "REPLACED",
"r_filling_time_ms": "REPLACED"
},
- "r_loops": 1,
- "rows": 510,
- "r_rows": 60,
- "r_table_time_ms": "REPLACED",
- "r_other_time_ms": "REPLACED",
- "filtered": 10.07493782,
- "r_filtered": 100,
- "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'",
- "attached_condition": "lineitem.l_quantity > 45"
- }
- },
- {
- "table": {
- "table_name": "orders",
- "access_type": "eq_ref",
- "possible_keys": ["PRIMARY", "i_o_totalprice"],
- "key": "PRIMARY",
- "key_length": "4",
- "used_key_parts": ["o_orderkey"],
- "ref": ["dbt3_s001.lineitem.l_orderkey"],
- "r_loops": 60,
- "rows": 1,
- "r_rows": 1,
+ "r_loops": 144,
+ "rows": 4,
+ "r_rows": 0.541666667,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 9.600000381,
- "r_filtered": 26.66666667,
- "attached_condition": "orders.o_totalprice between 180000 and 230000"
+ "filtered": 0.855656624,
+ "r_filtered": 20.51282051,
+ "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 45"
}
}
]
@@ -942,6 +942,14 @@ o_orderkey l_linenumber l_shipdate l_quantity o_totalprice
5829 5 1997-01-31 49 183734.56
5895 2 1997-04-27 47 201419.83
5895 3 1997-03-15 49 201419.83
+set statement optimizer_switch='rowid_filter=on' for EXPLAIN SELECT STRAIGHT_JOIN o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice
+FROM lineitem JOIN orders ON o_orderkey=l_orderkey
+WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
+l_quantity > 45 AND
+o_totalprice between 180000 and 230000;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE lineitem range|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate|i_l_quantity 4|9 NULL 510 (10%) Using index condition; Using where; Using rowid filter
+1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 Using where
set statement optimizer_switch='rowid_filter=on' for EXPLAIN SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice
FROM orders JOIN lineitem ON o_orderkey=l_orderkey
WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND
@@ -1306,7 +1314,7 @@ EXPLAIN
"key_length": "4",
"used_key_parts": ["l_receiptDATE"],
"rows": 18,
- "filtered": 5.555555344,
+ "filtered": 100,
"index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'",
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-10-10'"
}
@@ -1335,7 +1343,7 @@ l_shipdate BETWEEN '1996-10-01' AND '1996-10-10' AND
l_receiptdate BETWEEN '1996-10-05' AND '1996-10-10' AND
o_totalprice BETWEEN 200000 AND 250000;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_receiptdate 4 NULL 18 18.00 5.56 38.89 Using index condition; Using where
+1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_receiptdate 4 NULL 18 18.00 100.00 38.89 Using index condition; Using where
1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 1.00 5.67 14.29 Using where
set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT l_shipdate, l_receiptdate, o_totalprice
FROM orders, lineitem
@@ -1372,7 +1380,7 @@ ANALYZE
"r_rows": 18,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 5.555555344,
+ "filtered": 100,
"r_filtered": 38.88888889,
"index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'",
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-10-10'"
@@ -1443,7 +1451,7 @@ EXPLAIN
"key_length": "4",
"used_key_parts": ["l_receiptDATE"],
"rows": 18,
- "filtered": 5.555555344,
+ "filtered": 100,
"index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'",
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-10-10'"
}
@@ -1472,7 +1480,7 @@ l_shipdate BETWEEN '1996-10-01' AND '1996-10-10' AND
l_receiptdate BETWEEN '1996-10-05' AND '1996-10-10' AND
o_totalprice BETWEEN 200000 AND 250000;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_receiptdate 4 NULL 18 18.00 5.56 38.89 Using index condition; Using where
+1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_receiptdate 4 NULL 18 18.00 100.00 38.89 Using index condition; Using where
1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 1.00 5.67 14.29 Using where
set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT l_shipdate, l_receiptdate, o_totalprice
FROM orders, lineitem
@@ -1509,7 +1517,7 @@ ANALYZE
"r_rows": 18,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 5.555555344,
+ "filtered": 100,
"r_filtered": 38.88888889,
"index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'",
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-10-10'"
@@ -1560,7 +1568,7 @@ o_totalprice BETWEEN 200000 AND 220000 AND
l_shipdate BETWEEN '1996-10-01' AND '1996-12-01';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 41 Using index condition; Using where
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
+1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate
FROM orders, lineitem
WHERE o_orderkey=l_orderkey AND
@@ -1581,7 +1589,7 @@ EXPLAIN
"key_length": "9",
"used_key_parts": ["o_totaldiscount"],
"rows": 41,
- "filtered": 3.333333254,
+ "filtered": 100,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
"attached_condition": "orders.o_totalprice between 200000 and 220000"
}
@@ -1596,10 +1604,18 @@ EXPLAIN
"i_l_orderkey",
"i_l_orderkey_quantity"
],
- "key": "PRIMARY",
+ "key": "i_l_orderkey",
"key_length": "4",
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
+ "rowid_filter": {
+ "range": {
+ "key": "i_l_shipdate",
+ "used_key_parts": ["l_shipDATE"]
+ },
+ "rows": 183,
+ "selectivity_pct": 3.04746045
+ },
"rows": 4,
"filtered": 3.047460556,
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'"
@@ -1615,8 +1631,8 @@ o_totaldiscount BETWEEN 18000 AND 20000 AND
o_totalprice BETWEEN 200000 AND 220000 AND
l_shipdate BETWEEN '1996-10-01' AND '1996-12-01';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 41 41.00 3.33 2.44 Using index condition; Using where
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 6.00 3.05 66.67 Using where
+1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 41 41.00 100.00 2.44 Using index condition; Using where
+1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) 4.00 (66%) 3.05 100.00 Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate
FROM orders, lineitem
WHERE o_orderkey=l_orderkey AND
@@ -1646,7 +1662,7 @@ ANALYZE
"r_rows": 41,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 3.333333254,
+ "filtered": 100,
"r_filtered": 2.43902439,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
"attached_condition": "orders.o_totalprice between 200000 and 220000"
@@ -1662,17 +1678,30 @@ ANALYZE
"i_l_orderkey",
"i_l_orderkey_quantity"
],
- "key": "PRIMARY",
+ "key": "i_l_orderkey",
"key_length": "4",
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
+ "rowid_filter": {
+ "range": {
+ "key": "i_l_shipdate",
+ "used_key_parts": ["l_shipDATE"]
+ },
+ "rows": 183,
+ "selectivity_pct": 3.04746045,
+ "r_rows": 183,
+ "r_lookups": 6,
+ "r_selectivity_pct": 66.66666667,
+ "r_buffer_size": "REPLACED",
+ "r_filling_time_ms": "REPLACED"
+ },
"r_loops": 1,
"rows": 4,
- "r_rows": 6,
+ "r_rows": 4,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"filtered": 3.047460556,
- "r_filtered": 66.66666667,
+ "r_filtered": 100,
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'"
}
}
@@ -1719,7 +1748,7 @@ EXPLAIN
"key_length": "9",
"used_key_parts": ["o_totaldiscount"],
"rows": 41,
- "filtered": 3.333333254,
+ "filtered": 100,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
"attached_condition": "orders.o_totalprice between 200000 and 220000"
}
@@ -1753,7 +1782,7 @@ o_totaldiscount BETWEEN 18000 AND 20000 AND
o_totalprice BETWEEN 200000 AND 220000 AND
l_shipdate BETWEEN '1996-10-01' AND '1996-12-01';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 41 41.00 3.33 2.44 Using index condition; Using where
+1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 41 41.00 100.00 2.44 Using index condition; Using where
1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 6.00 3.05 66.67 Using where
set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate
FROM orders, lineitem
@@ -1784,7 +1813,7 @@ ANALYZE
"r_rows": 41,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 3.333333254,
+ "filtered": 100,
"r_filtered": 2.43902439,
"index_condition": "orders.o_totaldiscount between 18000 and 20000",
"attached_condition": "orders.o_totalprice between 200000 and 220000"
@@ -1839,7 +1868,7 @@ o_totalprice BETWEEN 200000 AND 220000 AND
l_shipdate BETWEEN '1996-10-01' AND '1996-12-01';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 41 Using index condition; Using where
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where
+1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate
FROM v1, lineitem
WHERE o_orderkey=l_orderkey AND
@@ -1880,10 +1909,18 @@ EXPLAIN
"i_l_orderkey",
"i_l_orderkey_quantity"
],
- "key": "PRIMARY",
+ "key": "i_l_orderkey",
"key_length": "4",
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
+ "rowid_filter": {
+ "range": {
+ "key": "i_l_shipdate",
+ "used_key_parts": ["l_shipDATE"]
+ },
+ "rows": 183,
+ "selectivity_pct": 3.04746045
+ },
"rows": 4,
"filtered": "REPLACED",
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'"
@@ -1900,7 +1937,7 @@ o_totalprice BETWEEN 200000 AND 220000 AND
l_shipdate BETWEEN '1996-10-01' AND '1996-12-01';
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 41 41.00 # 2.44 Using index condition; Using where
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 6.00 # 66.67 Using where
+1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) 4.00 (66%) # 100.00 Using where; Using rowid filter
set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate
FROM v1, lineitem
WHERE o_orderkey=l_orderkey AND
@@ -1951,17 +1988,30 @@ ANALYZE
"i_l_orderkey",
"i_l_orderkey_quantity"
],
- "key": "PRIMARY",
+ "key": "i_l_orderkey",
"key_length": "4",
"used_key_parts": ["l_orderkey"],
"ref": ["dbt3_s001.orders.o_orderkey"],
+ "rowid_filter": {
+ "range": {
+ "key": "i_l_shipdate",
+ "used_key_parts": ["l_shipDATE"]
+ },
+ "rows": 183,
+ "selectivity_pct": 3.04746045,
+ "r_rows": 183,
+ "r_lookups": 6,
+ "r_selectivity_pct": 66.66666667,
+ "r_buffer_size": "REPLACED",
+ "r_filling_time_ms": "REPLACED"
+ },
"r_loops": 1,
"rows": 4,
- "r_rows": 6,
+ "r_rows": 4,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
"filtered": "REPLACED",
- "r_filtered": 66.66666667,
+ "r_filtered": 100,
"attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'"
}
}
@@ -2747,7 +2797,7 @@ ANALYZE
"r_rows": 44,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 8.630000114,
+ "filtered": 100,
"r_filtered": 0,
"index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'",
"attached_condition": "t1.fl2 = 0"
@@ -2800,7 +2850,7 @@ ANALYZE
"r_rows": 0,
"r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED",
- "filtered": 8.529999733,
+ "filtered": 100,
"r_filtered": 100,
"index_condition": "t1.nm like '3400%' or t1.nm like '3402%' or t1.nm like '3403%' or t1.nm like '3404%' or t1.nm like '3405%' or t1.nm like '3406%' or t1.nm like '3407%' or t1.nm like '3409%' or t1.nm like '3411%' or t1.nm like '3412%' or t1.nm like '3413%' or t1.nm like '3414%' or t1.nm like '3415%' or t1.nm like '3416%' or t1.nm like '3417%' or t1.nm like '3418%' or t1.nm like '3419%' or t1.nm like '3421%' or t1.nm like '3422%' or t1.nm like '3423%' or t1.nm like '3424%' or t1.nm like '3425%' or t1.nm like '3426%' or t1.nm like '3427%' or t1.nm like '3428%' or t1.nm like '3429%' or t1.nm like '3430%' or t1.nm like '3431%' or t1.nm like '3432%' or t1.nm like '3433%' or t1.nm like '3434%' or t1.nm like '3435%' or t1.nm like '3436%' or t1.nm like '3437%' or t1.nm like '3439%' or t1.nm like '3440%' or t1.nm like '3441%' or t1.nm like '3442%' or t1.nm like '3443%' or t1.nm like '3444%' or t1.nm like '3445%' or t1.nm like '3446%' or t1.nm like '3447%' or t1.nm like '3448%'",
"attached_condition": "t1.fl2 = 0"
@@ -2854,8 +2904,8 @@ union
( select * from t1
where (f1 is null and f2 is null) and (f2 between 'a' and 'z' or f1 in ('a')));
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ref|filter f1,f2 f1|f1 13|13 const 1 (2%) Using index condition; Using where; Using rowid filter
-2 UNION t1 ref|filter f1,f2 f1|f1 13|13 const 1 (2%) Using index condition; Using where; Using rowid filter
+1 PRIMARY t1 index_merge f1,f2 f1,f2 13,33 NULL 1 Using intersect(f1,f2); Using where
+2 UNION t1 index_merge f1,f2 f1,f2 13,33 NULL 1 Using intersect(f1,f2); Using where
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL
explain format=json ( select * from t1
where (f1 is null and f2 is null) and (f2 between 'a' and 'z' or f1 in ('a')))
@@ -2876,24 +2926,28 @@ EXPLAIN
{
"table": {
"table_name": "t1",
- "access_type": "ref",
+ "access_type": "index_merge",
"possible_keys": ["f1", "f2"],
- "key": "f1",
- "key_length": "13",
- "used_key_parts": ["f1"],
- "ref": ["const"],
- "rowid_filter": {
- "range": {
- "key": "f1",
- "used_key_parts": ["f1"]
- },
- "rows": 1,
- "selectivity_pct": 1.587301587
+ "key_length": "13,33",
+ "index_merge": {
+ "intersect": [
+ {
+ "range": {
+ "key": "f1",
+ "used_key_parts": ["f1"]
+ }
+ },
+ {
+ "range": {
+ "key": "f2",
+ "used_key_parts": ["f2"]
+ }
+ }
+ ]
},
"rows": 1,
- "filtered": 1.587301612,
- "index_condition": "t1.f1 is null",
- "attached_condition": "t1.f2 is null and (t1.f2 between 'a' and 'z' or t1.f1 = 'a')"
+ "filtered": 100,
+ "attached_condition": "t1.f1 is null and t1.f2 is null and (t1.f2 between 'a' and 'z' or t1.f1 = 'a')"
}
}
]
@@ -2907,24 +2961,28 @@ EXPLAIN
{
"table": {
"table_name": "t1",
- "access_type": "ref",
+ "access_type": "index_merge",
"possible_keys": ["f1", "f2"],
- "key": "f1",
- "key_length": "13",
- "used_key_parts": ["f1"],
- "ref": ["const"],
- "rowid_filter": {
- "range": {
- "key": "f1",
- "used_key_parts": ["f1"]
- },
- "rows": 1,
- "selectivity_pct": 1.587301587
+ "key_length": "13,33",
+ "index_merge": {
+ "intersect": [
+ {
+ "range": {
+ "key": "f1",
+ "used_key_parts": ["f1"]
+ }
+ },
+ {
+ "range": {
+ "key": "f2",
+ "used_key_parts": ["f2"]
+ }
+ }
+ ]
},
"rows": 1,
- "filtered": 1.587301612,
- "index_condition": "t1.f1 is null",
- "attached_condition": "t1.f2 is null and (t1.f2 between 'a' and 'z' or t1.f1 = 'a')"
+ "filtered": 100,
+ "attached_condition": "t1.f1 is null and t1.f2 is null and (t1.f2 between 'a' and 'z' or t1.f1 = 'a')"
}
}
]
@@ -2988,7 +3046,7 @@ count(*)
5
explain extended select count(*) from t1 where a between 21 and 30 and b=2;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 ref b,a b 5 const 24 9.60 Using where
+1 SIMPLE t1 ref|filter b,a b|a 5|5 const 24 (10%) 9.60 Using where; Using rowid filter
Warnings:
Note 1003 select count(0) AS `count(*)` from `test`.`t1` where `test`.`t1`.`b` = 2 and `test`.`t1`.`a` between 21 and 30
select * from t1 where a between 21 and 30 and b=2;
@@ -3441,16 +3499,16 @@ WHERE 1 = 1 AND domain = 'www.mailhost.i-dev.fr' AND
timestamp >= DATE_ADD('2017-01-30 08:24:51', INTERVAL -1 MONTH)
ORDER BY timestamp DESC;
id domain registrant_name registrant_organization registrant_street1 registrant_street2 registrant_street3 registrant_street4 registrant_street5 registrant_city registrant_postal_code registrant_country registrant_email registrant_telephone administrative_name administrative_organization administrative_street1 administrative_street2 administrative_street3 administrative_street4 administrative_street5 administrative_city administrative_postal_code administrative_country administrative_email administrative_telephone technical_name technical_organization technical_street1 technical_street2 technical_street3 technical_street4 technical_street5 technical_city technical_postal_code technical_country technical_email technical_telephone json timestamp
-80551 www.mailhost.i-dev.fr NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 2017-01-30 10:00:56
-80579 www.mailhost.i-dev.fr NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 2017-01-30 10:00:56
-80594 www.mailhost.i-dev.fr NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 2017-01-30 10:00:56
80609 www.mailhost.i-dev.fr NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 2017-01-30 10:00:56
+80594 www.mailhost.i-dev.fr NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 2017-01-30 10:00:56
+80579 www.mailhost.i-dev.fr NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 2017-01-30 10:00:56
+80551 www.mailhost.i-dev.fr NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 2017-01-30 10:00:56
EXPLAIN EXTENDED SELECT * FROM t1
WHERE 1 = 1 AND domain = 'www.mailhost.i-dev.fr' AND
timestamp >= DATE_ADD('2017-01-30 08:24:51', INTERVAL -1 MONTH)
ORDER BY timestamp DESC;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 ALL ixEventWhoisDomainDomain,ixEventWhoisDomainTimestamp NULL NULL NULL 60 22.22 Using where; Using filesort
+1 SIMPLE t1 range|filter ixEventWhoisDomainDomain,ixEventWhoisDomainTimestamp ixEventWhoisDomainTimestamp|ixEventWhoisDomainDomain 4|98 NULL 20 (67%) 66.67 Using where; Using rowid filter
Warnings:
Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`domain` AS `domain`,`test`.`t1`.`registrant_name` AS `registrant_name`,`test`.`t1`.`registrant_organization` AS `registrant_organization`,`test`.`t1`.`registrant_street1` AS `registrant_street1`,`test`.`t1`.`registrant_street2` AS `registrant_street2`,`test`.`t1`.`registrant_street3` AS `registrant_street3`,`test`.`t1`.`registrant_street4` AS `registrant_street4`,`test`.`t1`.`registrant_street5` AS `registrant_street5`,`test`.`t1`.`registrant_city` AS `registrant_city`,`test`.`t1`.`registrant_postal_code` AS `registrant_postal_code`,`test`.`t1`.`registrant_country` AS `registrant_country`,`test`.`t1`.`registrant_email` AS `registrant_email`,`test`.`t1`.`registrant_telephone` AS `registrant_telephone`,`test`.`t1`.`administrative_name` AS `administrative_name`,`test`.`t1`.`administrative_organization` AS `administrative_organization`,`test`.`t1`.`administrative_street1` AS `administrative_street1`,`test`.`t1`.`administrative_street2` AS `administrative_street2`,`test`.`t1`.`administrative_street3` AS `administrative_street3`,`test`.`t1`.`administrative_street4` AS `administrative_street4`,`test`.`t1`.`administrative_street5` AS `administrative_street5`,`test`.`t1`.`administrative_city` AS `administrative_city`,`test`.`t1`.`administrative_postal_code` AS `administrative_postal_code`,`test`.`t1`.`administrative_country` AS `administrative_country`,`test`.`t1`.`administrative_email` AS `administrative_email`,`test`.`t1`.`administrative_telephone` AS `administrative_telephone`,`test`.`t1`.`technical_name` AS `technical_name`,`test`.`t1`.`technical_organization` AS `technical_organization`,`test`.`t1`.`technical_street1` AS `technical_street1`,`test`.`t1`.`technical_street2` AS `technical_street2`,`test`.`t1`.`technical_street3` AS `technical_street3`,`test`.`t1`.`technical_street4` AS `technical_street4`,`test`.`t1`.`technical_street5` AS `technical_street5`,`test`.`t1`.`technical_city` AS `technical_city`,`test`.`t1`.`technical_postal_code` AS `technical_postal_code`,`test`.`t1`.`technical_country` AS `technical_country`,`test`.`t1`.`technical_email` AS `technical_email`,`test`.`t1`.`technical_telephone` AS `technical_telephone`,`test`.`t1`.`json` AS `json`,`test`.`t1`.`timestamp` AS `timestamp` from `test`.`t1` where `test`.`t1`.`domain` = 'www.mailhost.i-dev.fr' and `test`.`t1`.`timestamp` >= <cache>('2017-01-30 08:24:51' + interval -1 month) order by `test`.`t1`.`timestamp` desc
SET optimizer_switch=@save_optimizer_switch;
@@ -3497,7 +3555,7 @@ SELECT * FROM t1
WHERE (a BETWEEN 9 AND 10 OR a IS NULL) AND (b BETWEEN 9 AND 10 OR b = 9)
ORDER BY pk LIMIT 1;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 index a,b PRIMARY 4 NULL 75 54.55 Using where
+1 SIMPLE t1 index a,b PRIMARY 4 NULL 75 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a` between 9 and 10 or `test`.`t1`.`a` is null) and (`test`.`t1`.`b` between 9 and 10 or `test`.`t1`.`b` = 9) order by `test`.`t1`.`pk` limit 1
ANALYZE
@@ -3505,7 +3563,7 @@ SELECT * FROM t1
WHERE (a BETWEEN 9 AND 10 OR a IS NULL) AND (b BETWEEN 9 AND 10 OR b = 9)
ORDER BY pk LIMIT 1;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE t1 index a,b PRIMARY 4 NULL 3008 3008.00 1.36 0.00 Using where
+1 SIMPLE t1 index a,b PRIMARY 4 NULL 3008 3008.00 6.38 0.00 Using where
DROP TABLE t1;
SET global innodb_stats_persistent= @stats.save;
#
@@ -4082,7 +4140,7 @@ WHERE t1.c1 NOT IN (SELECT t2.c1 FROM t2, t1 AS a1
WHERE t2.i1 = t1.pk AND t2.i1 BETWEEN 3 AND 5);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 60 100.00 Using where
-2 DEPENDENT SUBQUERY t2 ref c1,i1 i1 5 test.t1.pk 20 100.00 Using index condition; Using where
+2 DEPENDENT SUBQUERY t2 ref|filter c1,i1 c1|i1 3|5 func 38 (25%) 25.00 Using where; Full scan on NULL key; Using rowid filter
2 DEPENDENT SUBQUERY a1 ALL NULL NULL NULL NULL 60 100.00 Using join buffer (flat, BNL join)
Warnings:
Note 1276 Field or reference 'test.t1.pk' of SELECT #2 was resolved in SELECT #1
diff --git a/mysql-test/main/select.result b/mysql-test/main/select.result
index 2b545fe5e94..675601df08c 100644
--- a/mysql-test/main/select.result
+++ b/mysql-test/main/select.result
@@ -3540,7 +3540,7 @@ WHERE t1.id=2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 const idx1 NULL NULL NULL 1
-1 SIMPLE t3 ref idx1 idx1 5 const 4
+1 SIMPLE t3 ALL idx1 NULL NULL NULL 9 Using where
SELECT * FROM t1 LEFT JOIN t2 ON t2.b=t1.a INNER JOIN t3 ON t3.d=t1.id
WHERE t1.id=2;
id a b c d e
@@ -3597,7 +3597,7 @@ CREATE TABLE t1(id int PRIMARY KEY, b int, e int);
CREATE TABLE t2(i int, a int, INDEX si(i), INDEX ai(a));
CREATE TABLE t3(a int PRIMARY KEY, c char(4), INDEX ci(c));
INSERT INTO t1 VALUES
-(1,10,19), (2,20,22), (4,41,42), (9,93,95), (7, 77,79),
+(1,10,19), (2,20,22), (4,41,42), (9,39,95), (7, 77,79),
(6,63,67), (5,55,58), (3,38,39), (8,81,89);
INSERT INTO t2 VALUES
(21,210), (41,410), (82,820), (83,830), (84,840),
@@ -3625,6 +3625,14 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 range si,ai si 5 NULL 4 Using index condition; Using where
1 SIMPLE t3 eq_ref|filter PRIMARY,ci PRIMARY|ci 4|5 test.t2.a 1 (30%) Using where; Using rowid filter
+EXPLAIN
+SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3
+WHERE t1.id = 9 AND t2.i BETWEEN t1.b AND t1.e AND
+t3.a=t2.a AND t3.c IN ('bb','ee');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
+1 SIMPLE t2 range si si 5 NULL 13 Using index condition; Using where
+1 SIMPLE t3 eq_ref|filter PRIMARY,ci PRIMARY|ci 4|5 test.t2.a 1 (30%) Using where; Using rowid filter
EXPLAIN
SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3
WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND
@@ -3717,7 +3725,7 @@ COUNT(*)
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where
+1 SIMPLE t1 index_merge idx1,idx2 idx2,idx1 4,10 NULL 1 Using intersect(idx2,idx1); Using where; Using index
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null=3 IS NULL ;
id select_type table type possible_keys key key_len ref rows Extra
@@ -3731,7 +3739,7 @@ CREATE UNIQUE INDEX idx1 ON t1(ID1_with_null,ID2_with_null);
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where
+1 SIMPLE t1 index_merge idx1,idx2 idx2,idx1 4,10 NULL 1 Using intersect(idx2,idx1); Using where; Using index
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null IS NULL ;
id select_type table type possible_keys key key_len ref rows Extra
@@ -3744,7 +3752,7 @@ EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND
(ID2_with_null=1 OR ID2_with_null=2);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where
+1 SIMPLE t1 ref|filter idx1,idx2 idx1|idx2 5|4 const 2 (1%) Using index condition; Using where; Using rowid filter
DROP TABLE t1;
CREATE TABLE t1 (a INT, ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, KEY ts(ts));
INSERT INTO t1 VALUES (30,"2006-01-03 23:00:00"), (31,"2006-01-03 23:00:00");
@@ -3765,7 +3773,7 @@ AND t1.ts BETWEEN t2.dt1 AND t2.dt2
AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31";
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 const PRIMARY PRIMARY 4 const 1
-1 SIMPLE t1 range ts ts 4 NULL 2 Using index condition; Using where
+1 SIMPLE t1 ALL ts NULL NULL NULL 2 Using where
SELECT * FROM t1 LEFT JOIN t2 ON (t1.a=t2.a) WHERE t1.a=30
AND t1.ts BETWEEN t2.dt1 AND t2.dt2
AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31";
@@ -4031,7 +4039,7 @@ EXPLAIN SELECT COUNT(*) FROM t1 f1 INNER JOIN t1 f2
ON ( f1.b=f2.b AND f1.a<f2.a )
WHERE 1 AND f1.b NOT IN (100,2232,3343,51111);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE f1 range inx inx 5 NULL 7 Using where; Using index
+1 SIMPLE f1 index inx inx 10 NULL 7 Using where; Using index
1 SIMPLE f2 ref inx inx 5 test.f1.b 1 Using where; Using index
DROP TABLE t1;
CREATE TABLE t1 (c1 INT, c2 INT);
diff --git a/mysql-test/main/select.test b/mysql-test/main/select.test
index 823aa0d54c9..2974987a683 100644
--- a/mysql-test/main/select.test
+++ b/mysql-test/main/select.test
@@ -1532,7 +1532,6 @@ INSERT INTO t4 (companynr, companyname) VALUES (68,'company 10');
INSERT INTO t4 (companynr, companyname) VALUES (50,'company 11');
INSERT INTO t4 (companynr, companyname) VALUES (00,'Unknown');
--enable_query_log
-
#
# Test of stright join to force a full join.
#
@@ -3140,7 +3139,7 @@ CREATE TABLE t2(i int, a int, INDEX si(i), INDEX ai(a));
CREATE TABLE t3(a int PRIMARY KEY, c char(4), INDEX ci(c));
INSERT INTO t1 VALUES
- (1,10,19), (2,20,22), (4,41,42), (9,93,95), (7, 77,79),
+ (1,10,19), (2,20,22), (4,41,42), (9,39,95), (7, 77,79),
(6,63,67), (5,55,58), (3,38,39), (8,81,89);
INSERT INTO t2 VALUES
(21,210), (41,410), (82,820), (83,830), (84,840),
@@ -3162,6 +3161,11 @@ SELECT t3.a FROM t1,t2,t3
WHERE t1.id = 8 AND t2.i BETWEEN t1.b AND t1.e AND
t3.a=t2.a AND t3.c IN ('bb','ee') ;
+EXPLAIN
+SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3
+ WHERE t1.id = 9 AND t2.i BETWEEN t1.b AND t1.e AND
+ t3.a=t2.a AND t3.c IN ('bb','ee');
+
EXPLAIN
SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3
WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND
diff --git a/mysql-test/main/select_jcl6.result b/mysql-test/main/select_jcl6.result
index 7541fdf9e56..19970c90c7f 100644
--- a/mysql-test/main/select_jcl6.result
+++ b/mysql-test/main/select_jcl6.result
@@ -1391,16 +1391,16 @@ id select_type table type possible_keys key key_len ref rows Extra
delete from t2 where fld1=999999;
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
-1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
+1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where
+1 SIMPLE t2 hash_ALL NULL #hash#$hj 1 test.t4.companynr 1199 Using where; Using join buffer (flat, BNLH join)
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or 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
-1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
+1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where
+1 SIMPLE t2 hash_ALL NULL #hash#$hj 1 test.t4.companynr 1199 Using where; Using join buffer (flat, BNLH join)
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 and t4.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
-1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
+1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where
+1 SIMPLE t2 hash_ALL NULL #hash#$hj 1 test.t4.companynr 1199 Using where; Using join buffer (flat, BNLH join)
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
@@ -3551,7 +3551,7 @@ WHERE t1.id=2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 const idx1 NULL NULL NULL 1
-1 SIMPLE t3 ref idx1 idx1 5 const 4
+1 SIMPLE t3 ALL idx1 NULL NULL NULL 9 Using where
SELECT * FROM t1 LEFT JOIN t2 ON t2.b=t1.a INNER JOIN t3 ON t3.d=t1.id
WHERE t1.id=2;
id a b c d e
@@ -3608,7 +3608,7 @@ CREATE TABLE t1(id int PRIMARY KEY, b int, e int);
CREATE TABLE t2(i int, a int, INDEX si(i), INDEX ai(a));
CREATE TABLE t3(a int PRIMARY KEY, c char(4), INDEX ci(c));
INSERT INTO t1 VALUES
-(1,10,19), (2,20,22), (4,41,42), (9,93,95), (7, 77,79),
+(1,10,19), (2,20,22), (4,41,42), (9,39,95), (7, 77,79),
(6,63,67), (5,55,58), (3,38,39), (8,81,89);
INSERT INTO t2 VALUES
(21,210), (41,410), (82,820), (83,830), (84,840),
@@ -3636,6 +3636,14 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 range si,ai si 5 NULL 4 Using index condition; Using where; Rowid-ordered scan
1 SIMPLE t3 eq_ref|filter PRIMARY,ci PRIMARY|ci 4|5 test.t2.a 1 (30%) Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter
+EXPLAIN
+SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3
+WHERE t1.id = 9 AND t2.i BETWEEN t1.b AND t1.e AND
+t3.a=t2.a AND t3.c IN ('bb','ee');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
+1 SIMPLE t3 range PRIMARY,ci ci 5 NULL 6 Using index condition; Rowid-ordered scan
+1 SIMPLE t2 hash_range si #hash#$hj:si 5:5 test.t3.a 13 Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join)
EXPLAIN
SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3
WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND
@@ -3728,7 +3736,7 @@ COUNT(*)
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where
+1 SIMPLE t1 index_merge idx1,idx2 idx2,idx1 4,10 NULL 1 Using intersect(idx2,idx1); Using where; Using index
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null=3 IS NULL ;
id select_type table type possible_keys key key_len ref rows Extra
@@ -3742,7 +3750,7 @@ CREATE UNIQUE INDEX idx1 ON t1(ID1_with_null,ID2_with_null);
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where
+1 SIMPLE t1 index_merge idx1,idx2 idx2,idx1 4,10 NULL 1 Using intersect(idx2,idx1); Using where; Using index
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null IS NULL ;
id select_type table type possible_keys key key_len ref rows Extra
@@ -3755,7 +3763,7 @@ EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND
(ID2_with_null=1 OR ID2_with_null=2);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where
+1 SIMPLE t1 ref|filter idx1,idx2 idx1|idx2 5|4 const 2 (1%) Using index condition; Using where; Using rowid filter
DROP TABLE t1;
CREATE TABLE t1 (a INT, ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, KEY ts(ts));
INSERT INTO t1 VALUES (30,"2006-01-03 23:00:00"), (31,"2006-01-03 23:00:00");
@@ -3776,7 +3784,7 @@ AND t1.ts BETWEEN t2.dt1 AND t2.dt2
AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31";
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 const PRIMARY PRIMARY 4 const 1
-1 SIMPLE t1 range ts ts 4 NULL 2 Using index condition; Using where; Rowid-ordered scan
+1 SIMPLE t1 ALL ts NULL NULL NULL 2 Using where
SELECT * FROM t1 LEFT JOIN t2 ON (t1.a=t2.a) WHERE t1.a=30
AND t1.ts BETWEEN t2.dt1 AND t2.dt2
AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31";
@@ -4042,7 +4050,7 @@ EXPLAIN SELECT COUNT(*) FROM t1 f1 INNER JOIN t1 f2
ON ( f1.b=f2.b AND f1.a<f2.a )
WHERE 1 AND f1.b NOT IN (100,2232,3343,51111);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE f1 range inx inx 5 NULL 7 Using where; Using index
+1 SIMPLE f1 index inx inx 10 NULL 7 Using where; Using index
1 SIMPLE f2 ref inx inx 5 test.f1.b 1 Using where; Using index
DROP TABLE t1;
CREATE TABLE t1 (c1 INT, c2 INT);
diff --git a/mysql-test/main/select_pkeycache.result b/mysql-test/main/select_pkeycache.result
index 2b545fe5e94..675601df08c 100644
--- a/mysql-test/main/select_pkeycache.result
+++ b/mysql-test/main/select_pkeycache.result
@@ -3540,7 +3540,7 @@ WHERE t1.id=2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 const idx1 NULL NULL NULL 1
-1 SIMPLE t3 ref idx1 idx1 5 const 4
+1 SIMPLE t3 ALL idx1 NULL NULL NULL 9 Using where
SELECT * FROM t1 LEFT JOIN t2 ON t2.b=t1.a INNER JOIN t3 ON t3.d=t1.id
WHERE t1.id=2;
id a b c d e
@@ -3597,7 +3597,7 @@ CREATE TABLE t1(id int PRIMARY KEY, b int, e int);
CREATE TABLE t2(i int, a int, INDEX si(i), INDEX ai(a));
CREATE TABLE t3(a int PRIMARY KEY, c char(4), INDEX ci(c));
INSERT INTO t1 VALUES
-(1,10,19), (2,20,22), (4,41,42), (9,93,95), (7, 77,79),
+(1,10,19), (2,20,22), (4,41,42), (9,39,95), (7, 77,79),
(6,63,67), (5,55,58), (3,38,39), (8,81,89);
INSERT INTO t2 VALUES
(21,210), (41,410), (82,820), (83,830), (84,840),
@@ -3625,6 +3625,14 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 range si,ai si 5 NULL 4 Using index condition; Using where
1 SIMPLE t3 eq_ref|filter PRIMARY,ci PRIMARY|ci 4|5 test.t2.a 1 (30%) Using where; Using rowid filter
+EXPLAIN
+SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3
+WHERE t1.id = 9 AND t2.i BETWEEN t1.b AND t1.e AND
+t3.a=t2.a AND t3.c IN ('bb','ee');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
+1 SIMPLE t2 range si si 5 NULL 13 Using index condition; Using where
+1 SIMPLE t3 eq_ref|filter PRIMARY,ci PRIMARY|ci 4|5 test.t2.a 1 (30%) Using where; Using rowid filter
EXPLAIN
SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3
WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND
@@ -3717,7 +3725,7 @@ COUNT(*)
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where
+1 SIMPLE t1 index_merge idx1,idx2 idx2,idx1 4,10 NULL 1 Using intersect(idx2,idx1); Using where; Using index
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null=3 IS NULL ;
id select_type table type possible_keys key key_len ref rows Extra
@@ -3731,7 +3739,7 @@ CREATE UNIQUE INDEX idx1 ON t1(ID1_with_null,ID2_with_null);
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where
+1 SIMPLE t1 index_merge idx1,idx2 idx2,idx1 4,10 NULL 1 Using intersect(idx2,idx1); Using where; Using index
EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null IS NULL ;
id select_type table type possible_keys key key_len ref rows Extra
@@ -3744,7 +3752,7 @@ EXPLAIN SELECT * FROM t1
WHERE ID_better=1 AND ID1_with_null IS NULL AND
(ID2_with_null=1 OR ID2_with_null=2);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where
+1 SIMPLE t1 ref|filter idx1,idx2 idx1|idx2 5|4 const 2 (1%) Using index condition; Using where; Using rowid filter
DROP TABLE t1;
CREATE TABLE t1 (a INT, ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, KEY ts(ts));
INSERT INTO t1 VALUES (30,"2006-01-03 23:00:00"), (31,"2006-01-03 23:00:00");
@@ -3765,7 +3773,7 @@ AND t1.ts BETWEEN t2.dt1 AND t2.dt2
AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31";
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 const PRIMARY PRIMARY 4 const 1
-1 SIMPLE t1 range ts ts 4 NULL 2 Using index condition; Using where
+1 SIMPLE t1 ALL ts NULL NULL NULL 2 Using where
SELECT * FROM t1 LEFT JOIN t2 ON (t1.a=t2.a) WHERE t1.a=30
AND t1.ts BETWEEN t2.dt1 AND t2.dt2
AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31";
@@ -4031,7 +4039,7 @@ EXPLAIN SELECT COUNT(*) FROM t1 f1 INNER JOIN t1 f2
ON ( f1.b=f2.b AND f1.a<f2.a )
WHERE 1 AND f1.b NOT IN (100,2232,3343,51111);
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE f1 range inx inx 5 NULL 7 Using where; Using index
+1 SIMPLE f1 index inx inx 10 NULL 7 Using where; Using index
1 SIMPLE f2 ref inx inx 5 test.f1.b 1 Using where; Using index
DROP TABLE t1;
CREATE TABLE t1 (c1 INT, c2 INT);
diff --git a/mysql-test/main/select_safe.result b/mysql-test/main/select_safe.result
index 649e2dc484e..90ed1a4e785 100644
--- a/mysql-test/main/select_safe.result
+++ b/mysql-test/main/select_safe.result
@@ -74,8 +74,8 @@ id select_type table type possible_keys key key_len ref rows Extra
set MAX_SEEKS_FOR_KEY=1;
explain select STRAIGHT_JOIN * from t1,t1 as t2 where t1.b=t2.b;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ALL b NULL NULL NULL 11
-1 SIMPLE t2 ALL b NULL NULL NULL 11 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t1 ALL b NULL NULL NULL 11 Using where
+1 SIMPLE t2 ref b b 21 test.t1.b 5
SET MAX_SEEKS_FOR_KEY=DEFAULT;
drop table t1;
create table t1 (a int);
diff --git a/mysql-test/main/selectivity.result b/mysql-test/main/selectivity.result
index 71fce3475bc..060588c1a2c 100644
--- a/mysql-test/main/selectivity.result
+++ b/mysql-test/main/selectivity.result
@@ -541,8 +541,8 @@ limit 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort
1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00
-1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 4.17 Using where; Start temporary; Using join buffer (flat, BNL join)
-1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1 100.00 Using where; End temporary
+1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 4.17 Using where
+1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1 100.00 Using where; FirstMatch(supplier)
4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 15.14 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2
@@ -1790,7 +1790,7 @@ set optimizer_use_condition_selectivity=2;
explain extended select t1.b,t2.a,t3.a,t3.b from t1,t2,t3
where t1.c = t2.a AND t1.d = t3.a and t1.a = 50 and t1.b <= 100;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 range a a 10 NULL 9 9.00 Using index condition; Using where
+1 SIMPLE t1 range a a 10 NULL 9 100.00 Using index condition; Using where
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.c 1 100.00 Using index
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.d 1 100.00
Warnings:
diff --git a/mysql-test/main/selectivity_innodb.result b/mysql-test/main/selectivity_innodb.result
index ab79d15c9a1..f8c14a14dbf 100644
--- a/mysql-test/main/selectivity_innodb.result
+++ b/mysql-test/main/selectivity_innodb.result
@@ -82,10 +82,10 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where
1 PRIMARY supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.partsupp.ps_suppkey 1 100.00 Using where
1 PRIMARY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where
-2 DEPENDENT SUBQUERY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where
2 DEPENDENT SUBQUERY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00
2 DEPENDENT SUBQUERY supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.partsupp.ps_suppkey 1 100.00 Using where
2 DEPENDENT SUBQUERY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where
+2 DEPENDENT SUBQUERY region eq_ref PRIMARY PRIMARY 4 dbt3_s001.nation.n_regionkey 1 20.00 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.part.p_partkey' of SELECT #2 was resolved in SELECT #1
Note 1003 /* select#1 */ select `dbt3_s001`.`supplier`.`s_acctbal` AS `s_acctbal`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`nation`.`n_name` AS `n_name`,`dbt3_s001`.`part`.`p_partkey` AS `p_partkey`,`dbt3_s001`.`part`.`p_mfgr` AS `p_mfgr`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`dbt3_s001`.`supplier`.`s_comment` AS `s_comment` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and (`dbt3_s001`.`part`.`p_size` = 9 or `dbt3_s001`.`part`.`p_size` = 19999) and `dbt3_s001`.`part`.`p_type` like '%TIN' and `dbt3_s001`.`partsupp`.`ps_supplycost` = <expr_cache><`dbt3_s001`.`part`.`p_partkey`>((/* select#2 */ select min(`dbt3_s001`.`partsupp`.`ps_supplycost`) from `dbt3_s001`.`partsupp` join `dbt3_s001`.`supplier` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and `dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`)) order by `dbt3_s001`.`supplier`.`s_acctbal` desc,`dbt3_s001`.`nation`.`n_name`,`dbt3_s001`.`supplier`.`s_name`,`dbt3_s001`.`part`.`p_partkey`
@@ -123,13 +123,13 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where
1 PRIMARY supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.partsupp.ps_suppkey 1 100.00 Using where
1 PRIMARY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where
-2 DEPENDENT SUBQUERY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where
2 DEPENDENT SUBQUERY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00
2 DEPENDENT SUBQUERY supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.partsupp.ps_suppkey 1 100.00 Using where
2 DEPENDENT SUBQUERY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where
+2 DEPENDENT SUBQUERY region eq_ref PRIMARY PRIMARY 4 dbt3_s001.nation.n_regionkey 1 20.00 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.part.p_partkey' of SELECT #2 was resolved in SELECT #1
-Note 1003 /* select#1 */ select `dbt3_s001`.`supplier`.`s_acctbal` AS `s_acctbal`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`nation`.`n_name` AS `n_name`,`dbt3_s001`.`part`.`p_partkey` AS `p_partkey`,`dbt3_s001`.`part`.`p_mfgr` AS `p_mfgr`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`dbt3_s001`.`supplier`.`s_comment` AS `s_comment` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`part`.`p_size` = 9 and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and `dbt3_s001`.`part`.`p_type` like '%TIN' and `dbt3_s001`.`partsupp`.`ps_supplycost` = <expr_cache><`dbt3_s001`.`part`.`p_partkey`>((/* select#2 */ select min(`dbt3_s001`.`partsupp`.`ps_supplycost`) from `dbt3_s001`.`partsupp` join `dbt3_s001`.`supplier` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and `dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`)) order by `dbt3_s001`.`supplier`.`s_acctbal` desc,`dbt3_s001`.`nation`.`n_name`,`dbt3_s001`.`supplier`.`s_name`,`dbt3_s001`.`part`.`p_partkey`
+Note 1003 /* select#1 */ select `dbt3_s001`.`supplier`.`s_acctbal` AS `s_acctbal`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`nation`.`n_name` AS `n_name`,`dbt3_s001`.`part`.`p_partkey` AS `p_partkey`,`dbt3_s001`.`part`.`p_mfgr` AS `p_mfgr`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`dbt3_s001`.`supplier`.`s_comment` AS `s_comment` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`part`.`p_size` = 9 and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and `dbt3_s001`.`part`.`p_type` like '%TIN' and `dbt3_s001`.`partsupp`.`ps_supplycost` = <expr_cache><`dbt3_s001`.`part`.`p_partkey`>((/* select#2 */ select min(`dbt3_s001`.`partsupp`.`ps_supplycost`) from `dbt3_s001`.`partsupp` join `dbt3_s001`.`supplier` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`region`.`r_regionkey` = `dbt3_s001`.`nation`.`n_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and `dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`)) order by `dbt3_s001`.`supplier`.`s_acctbal` desc,`dbt3_s001`.`nation`.`n_name`,`dbt3_s001`.`supplier`.`s_name`,`dbt3_s001`.`part`.`p_partkey`
=== Q15 ===
create view revenue0 (supplier_no, total_revenue) as
select l_suppkey, sum(l_extendedprice * (1 - l_discount))
@@ -171,7 +171,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY supplier index PRIMARY PRIMARY 4 NULL 10 100.00
1 PRIMARY <derived3> ref key0 key0 5 dbt3_s001.supplier.s_suppkey 10 100.00 Using where
3 DERIVED lineitem range i_l_shipdate,i_l_suppkey i_l_shipdate 4 NULL 229 100.00 Using where; Using temporary; Using filesort
-2 SUBQUERY <derived4> ALL NULL NULL NULL NULL 228 100.00
+2 SUBQUERY <derived4> ALL NULL NULL NULL NULL 229 100.00
4 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 229 100.00 Using where; Using temporary; Using filesort
Warnings:
Note 1003 /* select#1 */ select `dbt3_s001`.`supplier`.`s_suppkey` AS `s_suppkey`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`revenue0`.`total_revenue` AS `total_revenue` from `dbt3_s001`.`supplier` join `dbt3_s001`.`revenue0` where `revenue0`.`supplier_no` = `dbt3_s001`.`supplier`.`s_suppkey` and `revenue0`.`total_revenue` = (/* select#2 */ select max(`revenue0`.`total_revenue`) from `dbt3_s001`.`revenue0`) order by `dbt3_s001`.`supplier`.`s_suppkey`
@@ -544,16 +544,15 @@ and n_name = 'UNITED STATES'
order by s_name
limit 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort
-1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 4.17 Using where
-2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where
+1 PRIMARY supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 100.00 Using where; Using filesort
+1 PRIMARY nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 4.00 Using where
+1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 70 100.00 Using where
+1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 4.17 Using where; FirstMatch(nation)
4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 14.40 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2
-Note 1003 /* select#1 */ select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where `dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey` and `dbt3_s001`.`nation`.`n_name` = 'UNITED STATES' and `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((/* select#4 */ select 0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`) from `dbt3_s001`.`lineitem` where `dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date)) and `dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>(cast('1993-01-01' as date) + interval '1' year))) and `dbt3_s001`.`part`.`p_name` like 'g%' order by `dbt3_s001`.`supplier`.`s_name` limit 10
+Note 1003 /* select#1 */ select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`nation`.`n_name` = 'UNITED STATES' and `dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`partsupp`.`ps_suppkey` = `dbt3_s001`.`supplier`.`s_suppkey` and `dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((/* select#4 */ select 0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`) from `dbt3_s001`.`lineitem` where `dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date)) and `dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>(cast('1993-01-01' as date) + interval '1' year))) and `dbt3_s001`.`part`.`p_name` like 'g%' order by `dbt3_s001`.`supplier`.`s_name` limit 10
select sql_calc_found_rows
s_name, s_address
from supplier, nation
@@ -600,16 +599,15 @@ and n_name = 'UNITED STATES'
order by s_name
limit 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort
-1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 7.03 Using where
-2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where
+1 PRIMARY supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 100.00 Using where; Using filesort
+1 PRIMARY nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 4.00 Using where
+1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 70 100.00 Using where
+1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 7.03 Using where; FirstMatch(nation)
4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 14.40 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2
-Note 1003 /* select#1 */ select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where `dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey` and `dbt3_s001`.`nation`.`n_name` = 'UNITED STATES' and `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((/* select#4 */ select 0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`) from `dbt3_s001`.`lineitem` where `dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date)) and `dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>(cast('1993-01-01' as date) + interval '1' year))) and `dbt3_s001`.`part`.`p_name` like 'g%' order by `dbt3_s001`.`supplier`.`s_name` limit 10
+Note 1003 /* select#1 */ select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`nation`.`n_name` = 'UNITED STATES' and `dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`partsupp`.`ps_suppkey` = `dbt3_s001`.`supplier`.`s_suppkey` and `dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((/* select#4 */ select 0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`) from `dbt3_s001`.`lineitem` where `dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date)) and `dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>(cast('1993-01-01' as date) + interval '1' year))) and `dbt3_s001`.`part`.`p_name` like 'g%' order by `dbt3_s001`.`supplier`.`s_name` limit 10
select sql_calc_found_rows
s_name, s_address
from supplier, nation
@@ -656,16 +654,15 @@ and n_name = 'UNITED STATES'
order by s_name
limit 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort
-1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 7.81 Using where
-2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where
+1 PRIMARY supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 100.00 Using where; Using filesort
+1 PRIMARY nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 4.00 Using where
+1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 70 100.00 Using where
+1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 7.81 Using where; FirstMatch(nation)
4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 14.40 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2
-Note 1003 /* select#1 */ select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where `dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey` and `dbt3_s001`.`nation`.`n_name` = 'UNITED STATES' and `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((/* select#4 */ select 0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`) from `dbt3_s001`.`lineitem` where `dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date)) and `dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>(cast('1993-01-01' as date) + interval '1' year))) and `dbt3_s001`.`part`.`p_name` like 'g%' order by `dbt3_s001`.`supplier`.`s_name` limit 10
+Note 1003 /* select#1 */ select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`nation`.`n_name` = 'UNITED STATES' and `dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`partsupp`.`ps_suppkey` = `dbt3_s001`.`supplier`.`s_suppkey` and `dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((/* select#4 */ select 0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`) from `dbt3_s001`.`lineitem` where `dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date)) and `dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>(cast('1993-01-01' as date) + interval '1' year))) and `dbt3_s001`.`part`.`p_name` like 'g%' order by `dbt3_s001`.`supplier`.`s_name` limit 10
select sql_calc_found_rows
s_name, s_address
from supplier, nation
@@ -712,16 +709,15 @@ and n_name = 'UNITED STATES'
order by s_name
limit 10;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort
-1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 7.81 Using where
-2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where
+1 PRIMARY supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 100.00 Using where; Using filesort
+1 PRIMARY nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 4.00 Using where
+1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 70 100.00 Using where
+1 PRIMARY part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 7.81 Using where; FirstMatch(nation)
4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 14.40 Using where
Warnings:
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2
Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2
-Note 1003 /* select#1 */ select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where `dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey` and `dbt3_s001`.`nation`.`n_name` = 'UNITED STATES' and `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((/* select#4 */ select 0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`) from `dbt3_s001`.`lineitem` where `dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date)) and `dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>(cast('1993-01-01' as date) + interval '1' year))) and `dbt3_s001`.`part`.`p_name` like 'g%' order by `dbt3_s001`.`supplier`.`s_name` limit 10
+Note 1003 /* select#1 */ select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`nation`.`n_name` = 'UNITED STATES' and `dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`partsupp`.`ps_suppkey` = `dbt3_s001`.`supplier`.`s_suppkey` and `dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((/* select#4 */ select 0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`) from `dbt3_s001`.`lineitem` where `dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date)) and `dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>(cast('1993-01-01' as date) + interval '1' year))) and `dbt3_s001`.`part`.`p_name` like 'g%' order by `dbt3_s001`.`supplier`.`s_name` limit 10
select sql_calc_found_rows
s_name, s_address
from supplier, nation
@@ -808,10 +804,9 @@ explain extended
select * from t1 where a in ( select b from t2 ) AND ( a > 3 );
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 1 100.00 Using where
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00
+1 PRIMARY t2 ALL NULL NULL NULL NULL 2 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 `test`.`t1`.`a` > 3
+Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`b` = `test`.`t1`.`a` and `test`.`t1`.`a` > 3
select * from t1 where a in ( select b from t2 ) AND ( a > 3 );
a
drop table t1,t2;
@@ -1673,7 +1668,7 @@ Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`
# gives selectivity data
explain extended select * from t1 where a in (17,51,5) and b=2;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 ref|filter b,a b|a 5|5 const 24 (3%) 2.90 Using where; Using rowid filter
+1 SIMPLE t1 ref|filter b,a b|a 5|5 const 59 (3%) 2.90 Using where; Using rowid filter
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`b` = 2 and `test`.`t1`.`a` in (17,51,5)
drop table t1;
diff --git a/mysql-test/main/selectivity_no_engine.result b/mysql-test/main/selectivity_no_engine.result
index 3811b12a1be..552a16d8334 100644
--- a/mysql-test/main/selectivity_no_engine.result
+++ b/mysql-test/main/selectivity_no_engine.result
@@ -236,8 +236,8 @@ set optimizer_use_condition_selectivity=2;
explain
select * from t1,t2 where t1.id = t2.t1_id and t2.f2='qux' and t2.f1='baz';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t2 ref f1 f1 325 const,const 2 Using index condition; Using where
-1 SIMPLE t1 eq_ref PRIMARY PRIMARY 122 test.t2.t1_id 1
+1 SIMPLE t2 ALL f1 NULL NULL NULL 4 Using where
+1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
select * from t1,t2 where t1.id = t2.t1_id and t2.f2='qux' and t2.f1='baz';
id dt t1_id f1 f2
foo 2011-04-12 05:18:08 foo baz qux
diff --git a/mysql-test/main/show_explain.result b/mysql-test/main/show_explain.result
index 6bdc773aa4c..aa3be6f1f58 100644
--- a/mysql-test/main/show_explain.result
+++ b/mysql-test/main/show_explain.result
@@ -40,7 +40,7 @@ select count(*) from t1 where a < 100000;
connection default;
show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 range a a 5 NULL 999 Using where; Using index
+1 SIMPLE t1 index a a 5 NULL 1000 Using where; Using index
Warnings:
Note 1003 select count(*) from t1 where a < 100000
connection con1;
@@ -730,8 +730,8 @@ SELECT * FROM t2 WHERE (5, 78) IN (SELECT `a1`, MAX(`a1`) FROM t2 GROUP BY `a1`)
connection default;
show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t2 ALL NULL NULL NULL NULL 20
1 PRIMARY <subquery2> const distinct_key distinct_key 8 const,const 1
-1 PRIMARY t2 ALL NULL NULL NULL NULL 20 Using join buffer (flat, BNL join)
2 MATERIALIZED t2 index NULL a1 4 NULL 20 Using index
Warnings:
Note 1003 SELECT * FROM t2 WHERE (5, 78) IN (SELECT `a1`, MAX(`a1`) FROM t2 GROUP BY `a1`)
diff --git a/mysql-test/main/show_explain_json.result b/mysql-test/main/show_explain_json.result
index a5c441af5b8..daf8a3f5ef4 100644
--- a/mysql-test/main/show_explain_json.result
+++ b/mysql-test/main/show_explain_json.result
@@ -51,13 +51,13 @@ SHOW EXPLAIN
{
"table": {
"table_name": "t1",
- "access_type": "range",
+ "access_type": "index",
"possible_keys": ["a"],
"key": "a",
"key_length": "5",
"used_key_parts": ["a"],
- "rows": 999,
- "filtered": 100,
+ "rows": 1000,
+ "filtered": 99.90000153,
"attached_condition": "t1.a < 100000",
"using_index": true
}
diff --git a/mysql-test/main/single_delete_update.result b/mysql-test/main/single_delete_update.result
index 1f0299ac0fc..6a17895ef8a 100644
--- a/mysql-test/main/single_delete_update.result
+++ b/mysql-test/main/single_delete_update.result
@@ -151,19 +151,19 @@ Variable_name Value
Sort_merge_passes 0
Sort_priority_queue_sorts 0
Sort_range 0
-Sort_rows 1
-Sort_scan 1
+Sort_rows 0
+Sort_scan 0
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
-Handler_read_first 0
+Handler_read_first 1
Handler_read_key 0
Handler_read_last 0
-Handler_read_next 0
+Handler_read_next 16
Handler_read_prev 0
Handler_read_retry 0
-Handler_read_rnd 1
+Handler_read_rnd 0
Handler_read_rnd_deleted 0
-Handler_read_rnd_next 17
+Handler_read_rnd_next 0
## should be 5 (previous LIMIT)
SELECT 1 - COUNT(*) FROM t2 WHERE b = 10;
1 - COUNT(*)
@@ -332,6 +332,7 @@ DROP TABLE t2;
#
CREATE TABLE t2 (i INT, key1 INT, key2 INT, INDEX (key1), INDEX (key2));
INSERT INTO t2 (key1, key2) SELECT i, i FROM t1;
+INSERT INTO t2 (key1, key2) SELECT i+100, i+100 FROM t1;
FLUSH STATUS;
SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
i key1 key2
@@ -754,21 +755,21 @@ UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
SHOW SESSION STATUS LIKE 'Sort%';
Variable_name Value
Sort_merge_passes 0
-Sort_priority_queue_sorts 1
+Sort_priority_queue_sorts 0
Sort_range 0
-Sort_rows 1
-Sort_scan 1
+Sort_rows 0
+Sort_scan 0
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
-Handler_read_first 0
+Handler_read_first 1
Handler_read_key 0
Handler_read_last 0
-Handler_read_next 0
+Handler_read_next 16
Handler_read_prev 0
Handler_read_retry 0
Handler_read_rnd 1
Handler_read_rnd_deleted 0
-Handler_read_rnd_next 17
+Handler_read_rnd_next 0
## should be 5 (previous LIMIT)
SELECT COUNT(*) FROM t2 WHERE b = 10 AND d = 10 ORDER BY a, c;
COUNT(*)
@@ -939,6 +940,7 @@ DROP TABLE t2;
#
CREATE TABLE t2 (i INT, key1 INT, key2 INT, INDEX (key1), INDEX (key2));
INSERT INTO t2 (key1, key2) SELECT i, i FROM t1;
+INSERT INTO t2 (key1, key2) SELECT i+100, i+100 FROM t1;
FLUSH STATUS;
SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
i key1 key2
diff --git a/mysql-test/main/single_delete_update.test b/mysql-test/main/single_delete_update.test
index 4a4ad5e5a8e..05cff5e1413 100644
--- a/mysql-test/main/single_delete_update.test
+++ b/mysql-test/main/single_delete_update.test
@@ -147,6 +147,7 @@ DROP TABLE t2;
CREATE TABLE t2 (i INT, key1 INT, key2 INT, INDEX (key1), INDEX (key2));
INSERT INTO t2 (key1, key2) SELECT i, i FROM t1;
+INSERT INTO t2 (key1, key2) SELECT i+100, i+100 FROM t1;
FLUSH STATUS;
SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
@@ -372,6 +373,7 @@ DROP TABLE t2;
CREATE TABLE t2 (i INT, key1 INT, key2 INT, INDEX (key1), INDEX (key2));
INSERT INTO t2 (key1, key2) SELECT i, i FROM t1;
+INSERT INTO t2 (key1, key2) SELECT i+100, i+100 FROM t1;
FLUSH STATUS;
SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
diff --git a/mysql-test/main/stat_tables.result b/mysql-test/main/stat_tables.result
index a753aaa2e5d..35659bc0076 100644
--- a/mysql-test/main/stat_tables.result
+++ b/mysql-test/main/stat_tables.result
@@ -852,6 +852,7 @@ set histogram_size=0;
#
create table t1 (a int, b int);
insert into t1(a,b) values (1,2),(1,3),(1,4),(1,5),(2,6),(2,7),(3,8),(3,9),(3,9),(4,10);
+insert into t1 select seq,seq from seq_10_to_100;
set use_stat_tables= preferably_for_queries;
#
# with use_stat_tables= PREFERABLY_FOR_QUERIES
@@ -865,7 +866,7 @@ db_name table_name column_name min_value max_value nulls_ratio avg_length avg_fr
analyze
select * from t1 where a = 1 and b=3;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 100.00 10.00 Using where
+1 SIMPLE t1 ALL NULL NULL NULL NULL 101 101.00 100.00 0.99 Using where
#
# with use_stat_tables= PREFERABLY_FOR_QUERIES
# analyze table t1 will collect statistics if we use PERSISTENT
@@ -877,12 +878,12 @@ test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status Table is already up to date
select * from mysql.column_stats;
db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
-test t1 a 1 4 0.0000 4.0000 2.5000 0 NULL NULL
+test t1 a 1 100 0.0000 4.0000 1.0632 0 NULL NULL
# filtered shows that we used the data from stat tables
analyze
select * from t1 where a = 1 and b=3;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 25.00 10.00 Using where
+1 SIMPLE t1 ALL NULL NULL NULL NULL 101 101.00 1.05 0.99 Using where
#
# with use_stat_tables= PREFERABLY
# analyze table t1 will collect statistics
@@ -894,13 +895,13 @@ test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status Table is already up to date
select * from mysql.column_stats;
db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
-test t1 a 1 4 0.0000 4.0000 2.5000 0 NULL NULL
-test t1 b 2 10 0.0000 4.0000 1.1111 0 NULL NULL
+test t1 a 1 100 0.0000 4.0000 1.0632 0 NULL NULL
+test t1 b 2 100 0.0000 4.0000 1.0202 0 NULL NULL
# filtered shows that we used the data from stat tables
analyze
select * from t1 where a=1 and b=3;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 10.00 10.00 Using where
+1 SIMPLE t1 ALL NULL NULL NULL NULL 101 101.00 0.99 0.99 Using where
drop table t1;
set @@global.histogram_size=@save_histogram_size;
# End of 10.4 tests
diff --git a/mysql-test/main/stat_tables.test b/mysql-test/main/stat_tables.test
index 7488ccb6877..fccae8d88c4 100644
--- a/mysql-test/main/stat_tables.test
+++ b/mysql-test/main/stat_tables.test
@@ -4,6 +4,7 @@
--source include/have_stat_tables.inc
--source include/have_partition.inc
+--source include/have_sequence.inc
select @@global.use_stat_tables;
select @@session.use_stat_tables;
@@ -602,6 +603,7 @@ set histogram_size=0;
create table t1 (a int, b int);
insert into t1(a,b) values (1,2),(1,3),(1,4),(1,5),(2,6),(2,7),(3,8),(3,9),(3,9),(4,10);
+insert into t1 select seq,seq from seq_10_to_100;
set use_stat_tables= preferably_for_queries;
--echo #
--echo # with use_stat_tables= PREFERABLY_FOR_QUERIES
diff --git a/mysql-test/main/stat_tables_innodb.result b/mysql-test/main/stat_tables_innodb.result
index 732300e70e1..f874f6a0ff6 100644
--- a/mysql-test/main/stat_tables_innodb.result
+++ b/mysql-test/main/stat_tables_innodb.result
@@ -251,7 +251,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE n2 eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1
1 SIMPLE orders eq_ref PRIMARY,i_o_orderdate,i_o_custkey PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 Using where
1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where
-1 SIMPLE n1 eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1 Using where
+1 SIMPLE n1 eq_ref PRIMARY,i_n_regionkey i_n_regionkey 9 dbt3_s001.region.r_regionkey,dbt3_s001.customer.c_nationkey 1 Using index
select o_year,
sum(case when nation = 'UNITED STATES' then volume else 0 end) /
sum(volume) as mkt_share
@@ -884,6 +884,7 @@ set histogram_size=0;
#
create table t1 (a int, b int);
insert into t1(a,b) values (1,2),(1,3),(1,4),(1,5),(2,6),(2,7),(3,8),(3,9),(3,9),(4,10);
+insert into t1 select seq,seq from seq_10_to_100;
set use_stat_tables= preferably_for_queries;
#
# with use_stat_tables= PREFERABLY_FOR_QUERIES
@@ -897,7 +898,7 @@ db_name table_name column_name min_value max_value nulls_ratio avg_length avg_fr
analyze
select * from t1 where a = 1 and b=3;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 100.00 10.00 Using where
+1 SIMPLE t1 ALL NULL NULL NULL NULL 101 101.00 100.00 0.99 Using where
#
# with use_stat_tables= PREFERABLY_FOR_QUERIES
# analyze table t1 will collect statistics if we use PERSISTENT
@@ -909,12 +910,12 @@ test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
select * from mysql.column_stats;
db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
-test t1 a 1 4 0.0000 4.0000 2.5000 0 NULL NULL
+test t1 a 1 100 0.0000 4.0000 1.0632 0 NULL NULL
# filtered shows that we used the data from stat tables
analyze
select * from t1 where a = 1 and b=3;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 25.00 10.00 Using where
+1 SIMPLE t1 ALL NULL NULL NULL NULL 101 101.00 1.05 0.99 Using where
#
# with use_stat_tables= PREFERABLY
# analyze table t1 will collect statistics
@@ -926,13 +927,13 @@ test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
select * from mysql.column_stats;
db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
-test t1 a 1 4 0.0000 4.0000 2.5000 0 NULL NULL
-test t1 b 2 10 0.0000 4.0000 1.1111 0 NULL NULL
+test t1 a 1 100 0.0000 4.0000 1.0632 0 NULL NULL
+test t1 b 2 100 0.0000 4.0000 1.0202 0 NULL NULL
# filtered shows that we used the data from stat tables
analyze
select * from t1 where a=1 and b=3;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
-1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 10.00 10.00 Using where
+1 SIMPLE t1 ALL NULL NULL NULL NULL 101 101.00 0.99 0.99 Using where
drop table t1;
set @@global.histogram_size=@save_histogram_size;
# End of 10.4 tests
diff --git a/mysql-test/main/status.result b/mysql-test/main/status.result
index 18e792ef02e..de2c9d79dcd 100644
--- a/mysql-test/main/status.result
+++ b/mysql-test/main/status.result
@@ -71,10 +71,10 @@ a
6
show status like 'last_query_cost';
Variable_name Value
-Last_query_cost 22.084449
+Last_query_cost 13.542725
show status like 'last_query_cost';
Variable_name Value
-Last_query_cost 22.084449
+Last_query_cost 13.542725
select 1;
1
1
@@ -134,13 +134,13 @@ a
1
SHOW SESSION STATUS LIKE 'Last_query_cost';
Variable_name Value
-Last_query_cost 2.802418
+Last_query_cost 1.501709
EXPLAIN SELECT a FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2
SHOW SESSION STATUS LIKE 'Last_query_cost';
Variable_name Value
-Last_query_cost 2.802418
+Last_query_cost 1.501709
SELECT a FROM t1 UNION SELECT a FROM t1 ORDER BY a;
a
1
@@ -173,7 +173,7 @@ a a
1 1
SHOW SESSION STATUS LIKE 'Last_query_cost';
Variable_name Value
-Last_query_cost 6.805836
+Last_query_cost 4.003418
DROP TABLE t1;
connect con1,localhost,root,,;
show status like 'com_show_status';
diff --git a/mysql-test/main/subselect.result b/mysql-test/main/subselect.result
index 79c6cd78e92..eb787a1e4c0 100644
--- a/mysql-test/main/subselect.result
+++ b/mysql-test/main/subselect.result
@@ -1449,21 +1449,21 @@ a
4
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index
-1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 100.00 Using where
+1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 100.00 Using where
+1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index
Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t1`.`b` <> 30
select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
a
2
3
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index
-1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 100.00
-1 PRIMARY t3 index PRIMARY PRIMARY 4 NULL 3 75.00 Using where; Using index; Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 100.00 Using where
+1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index
+1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00 Using index
Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where `test`.`t3`.`a` = `test`.`t1`.`b` and `test`.`t1`.`a` = `test`.`t2`.`a`
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where `test`.`t3`.`a` = `test`.`t1`.`b` and `test`.`t2`.`a` = `test`.`t1`.`a`
drop table t1, t2, t3;
create table t1 (a int, b int, index a (a,b));
create table t2 (a int, index a (a));
@@ -1503,7 +1503,7 @@ a
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
-1 PRIMARY t3 range a a 5 NULL 3 100.00 Using where; Using index
+1 PRIMARY t3 index a a 5 NULL 3 100.00 Using where; Using index
1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 100.00 Using index; FirstMatch(t2)
Warnings:
Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where `test`.`t1`.`b` = `test`.`t3`.`a` and `test`.`t1`.`a` = `test`.`t2`.`a`
@@ -1611,21 +1611,21 @@ a3 1
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
+2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
+2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
+2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
@@ -2418,16 +2418,18 @@ a
3
DROP TABLE t1;
create table t1 (a int, b int);
-insert into t1 values (1,2),(3,4);
+insert into t1 values (1,2),(3,4),(5,6),(7,8);
select * from t1 up where exists (select * from t1 where t1.a=up.a);
a b
1 2
3 4
+5 6
+7 8
explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY up ALL NULL NULL NULL NULL 2 100.00
+1 PRIMARY up ALL NULL NULL NULL NULL 4 100.00
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00
+2 MATERIALIZED t1 ALL NULL NULL NULL NULL 4 100.00
Warnings:
Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` semi join (`test`.`t1`) where 1
@@ -3100,7 +3102,7 @@ retailerID statusID changed
drop table t1;
create table t1(a int, primary key (a));
insert into t1 values (10);
-create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b));
+create table t2 (a int primary key, b varchar(32), c int, unique key cb(c, b));
insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989');
insert into t2(a, c, b) values (4,10,'360'), (5,10,'35998'), (6,10,'35999');
analyze table t1;
@@ -3113,7 +3115,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 range b b 40 NULL 3 Using where
+2 SUBQUERY t2 ref cb cb 5 const 1 Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
@@ -3125,7 +3127,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 range b b 40 NULL 3 Using index condition
+2 SUBQUERY t2 ref cb cb 5 const 1 Using index condition; Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
@@ -4438,7 +4440,7 @@ out_a MIN(b)
DROP TABLE t1;
CREATE TABLE t1 (a INT);
CREATE TABLE t2 (a INT);
-INSERT INTO t1 VALUES (1),(2);
+INSERT INTO t1 VALUES (1),(2),(3),(4);
INSERT INTO t2 VALUES (1),(2);
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
2
@@ -4447,7 +4449,7 @@ SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
EXPLAIN EXTENDED
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00
Warnings:
@@ -4457,7 +4459,7 @@ EXPLAIN EXTENDED
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION
(SELECT 1 FROM t2 WHERE t1.a = t2.a));
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 2 100.00 Using where
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
@@ -4541,15 +4543,15 @@ SET @save_join_cache_level=@@join_cache_level;
SET join_cache_level=0;
EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 GROUP BY a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary
Warnings:
Note 1003 /* select#1 */ select 1 AS `1` from <materialize> (/* select#2 */ select min(`test`.`t1`.`a`) from `test`.`t1` group by `test`.`t1`.`a`) join `test`.`t1` where `<subquery2>`.`min(a)` = 1
EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 WHERE a > 3 GROUP BY a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary
Warnings:
Note 1003 /* select#1 */ select 1 AS `1` from <materialize> (/* select#2 */ select min(`test`.`t1`.`a`) from `test`.`t1` where `test`.`t1`.`a` > 3 group by `test`.`t1`.`a`) join `test`.`t1` where `<subquery2>`.`min(a)` = 1
@@ -6080,8 +6082,7 @@ WHERE col_varchar_nokey IN
(SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY ot system NULL NULL NULL NULL 1
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED it1 ref idx_cvk_cik idx_cvk_cik 9 const,const 1 Using where; Using index
+1 PRIMARY it1 ref idx_cvk_cik idx_cvk_cik 9 const,const 1 Using where; Using index; FirstMatch(ot)
SELECT col_int_nokey FROM ot
WHERE col_varchar_nokey IN
(SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL);
@@ -6093,8 +6094,7 @@ WHERE (col_varchar_nokey, 'x') IN
(SELECT col_varchar_key, col_varchar_key2 FROM it2);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY ot system NULL NULL NULL NULL 1
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1
-2 MATERIALIZED it2 ref idx_cvk_cvk2_cik,idx_cvk_cik idx_cvk_cvk2_cik 8 const,const 1 Using where; Using index
+1 PRIMARY it2 ref idx_cvk_cvk2_cik,idx_cvk_cik idx_cvk_cvk2_cik 8 const,const 1 Using where; Using index; FirstMatch(ot)
SELECT col_int_nokey FROM ot
WHERE (col_varchar_nokey, 'x') IN
(SELECT col_varchar_key, col_varchar_key2 FROM it2);
diff --git a/mysql-test/main/subselect.test b/mysql-test/main/subselect.test
index be22169a1d6..90b96d4be9e 100644
--- a/mysql-test/main/subselect.test
+++ b/mysql-test/main/subselect.test
@@ -7,6 +7,7 @@
# as possible.
#
# Initialise
+--source include/have_sequence.inc
--disable_warnings
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12;
drop view if exists v2;
@@ -1024,6 +1025,7 @@ create table t1 (s1 char(5), index s1(s1));
create table t2 (s1 char(5), index s1(s1));
insert into t1 values ('a1'),('a2'),('a3');
insert into t2 values ('a1'),('a2');
+
select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
@@ -1456,7 +1458,7 @@ DROP TABLE t1;
#--view-protocol is disabled because view gives another query plan
--disable_view_protocol
create table t1 (a int, b int);
-insert into t1 values (1,2),(3,4);
+insert into t1 values (1,2),(3,4),(5,6),(7,8);
select * from t1 up where exists (select * from t1 where t1.a=up.a);
explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a);
drop table t1;
@@ -2066,7 +2068,7 @@ drop table t1;
create table t1(a int, primary key (a));
insert into t1 values (10);
-create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b));
+create table t2 (a int primary key, b varchar(32), c int, unique key cb(c, b));
insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989');
insert into t2(a, c, b) values (4,10,'360'), (5,10,'35998'), (6,10,'35999');
analyze table t1;
@@ -3383,7 +3385,7 @@ DROP TABLE t1;
CREATE TABLE t1 (a INT);
CREATE TABLE t2 (a INT);
-INSERT INTO t1 VALUES (1),(2);
+INSERT INTO t1 VALUES (1),(2),(3),(4);
INSERT INTO t2 VALUES (1),(2);
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
diff --git a/mysql-test/main/subselect2.result b/mysql-test/main/subselect2.result
index db6c85900ad..dea2a963caf 100644
--- a/mysql-test/main/subselect2.result
+++ b/mysql-test/main/subselect2.result
@@ -132,7 +132,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3_b eq_ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 test.t3_a.PARENTID 1 Using where
1 PRIMARY t3_c eq_ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 test.t3_b.PARENTID 1 Using where
1 PRIMARY t3_d eq_ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 test.t3_c.PARENTID 1 Using where
-1 PRIMARY t3_e ref|filter PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX FFOLDERID_IDX|CMFLDRPARNT_IDX 34|35 test.t3_d.PARENTID 1 (29%) Using where; Using rowid filter
+1 PRIMARY t3_e eq_ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 test.t3_d.PARENTID 1 Using where
drop table t1, t2, t3, t4;
CREATE TABLE t1 (a int(10) , PRIMARY KEY (a)) Engine=InnoDB;
INSERT INTO t1 VALUES (1),(2);
@@ -163,7 +163,7 @@ SELECT * FROM t2,t3 WHERE (2,9) IN (SELECT DISTINCT a,pk FROM t1) OR a = b;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 index a a 5 NULL 2 Using where; Using index
1 PRIMARY t3 ref b b 5 test.t2.a 2 Using index
-2 SUBQUERY t1 const PRIMARY,a PRIMARY 4 const 1 Using where
+2 SUBQUERY t1 const PRIMARY,a a 9 const,const 1 Using where; Using index
SELECT * FROM t2,t3 WHERE (2,9) IN (SELECT DISTINCT a,pk FROM t1) OR a = b;
pk a b
0 4 4
@@ -172,7 +172,7 @@ SELECT * FROM t2,t3 WHERE (2,9) IN (SELECT DISTINCT a,pk FROM v1) OR a = b;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 index a a 5 NULL 2 Using where; Using index
1 PRIMARY t3 ref b b 5 test.t2.a 2 Using index
-2 SUBQUERY t1 const PRIMARY,a PRIMARY 4 const 1 Using where
+2 SUBQUERY t1 const PRIMARY,a a 9 const,const 1 Using where; Using index
SELECT * FROM t2,t3 WHERE (2,9) IN (SELECT DISTINCT a,pk FROM v1) OR a = b;
pk a b
0 4 4
@@ -287,7 +287,7 @@ ORDER BY mirror_date ASC
) AS calculated_result;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3
-2 DERIVED t1 range date date 6 NULL 3 Using index condition; Using where; Rowid-ordered scan; Using filesort
+2 DERIVED t1 ALL date NULL NULL NULL 3 Using where; Using filesort
SELECT * FROM (
SELECT node_uid, date, mirror_date, @result := 0 AS result
FROM t1
@@ -310,7 +310,7 @@ ORDER BY mirror_date ASC
) AS calculated_result;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3
-2 DERIVED t1 range date date 6 NULL 3 Using index condition; Using where; Using filesort
+2 DERIVED t1 ALL date NULL NULL NULL 3 Using where; Using filesort
SELECT * FROM (
SELECT node_uid, date, mirror_date, @result := 0 AS result
FROM t1
diff --git a/mysql-test/main/subselect3.result b/mysql-test/main/subselect3.result
index 28187e0ffdd..fe6ef646886 100644
--- a/mysql-test/main/subselect3.result
+++ b/mysql-test/main/subselect3.result
@@ -96,10 +96,10 @@ explain extended
select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 4 100.00
-2 DEPENDENT SUBQUERY t1 ALL a NULL NULL NULL 8 100.00 Using where
+2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 3 100.00 Using where; Full scan on NULL key
Warnings:
Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
-Note 1003 /* select#1 */ select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where `test`.`t1`.`oref` = `test`.`t2`.`oref` and trigcond(<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a` or `test`.`t1`.`a` is null) having trigcond(`test`.`t1`.`a` is null)))) AS `Z` from `test`.`t2`
+Note 1003 /* select#1 */ select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a checking NULL where `test`.`t1`.`oref` = `test`.`t2`.`oref` having trigcond(`test`.`t1`.`a` is null))))) AS `Z` from `test`.`t2`
flush status;
select oref, a from t2 where a in (select a from t1 where oref=t2.oref);
oref a
@@ -1339,9 +1339,9 @@ insert into t2 select * from t2;
explain select * from t1 where (a,b,c) in (select X.a, Y.a, Z.a from t2 X, t2 Y, t2 Z where X.b=33);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
-1 PRIMARY X ALL NULL NULL NULL NULL 6 Using where; Start temporary; Using join buffer (flat, BNL join)
-1 PRIMARY Y ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join)
-1 PRIMARY Z ALL NULL NULL NULL NULL 6 Using where; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY X ALL NULL NULL NULL NULL 6 Using where
+1 PRIMARY Y ALL NULL NULL NULL NULL 6 Using where
+1 PRIMARY Z ALL NULL NULL NULL NULL 6 Using where; FirstMatch(t1)
drop table t0,t1,t2;
set @@optimizer_switch=@save_optimizer_switch;
diff --git a/mysql-test/main/subselect3_jcl6.result b/mysql-test/main/subselect3_jcl6.result
index 9df821e07dc..25d76e6ee8c 100644
--- a/mysql-test/main/subselect3_jcl6.result
+++ b/mysql-test/main/subselect3_jcl6.result
@@ -99,10 +99,10 @@ explain extended
select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 4 100.00
-2 DEPENDENT SUBQUERY t1 ALL a NULL NULL NULL 8 100.00 Using where
+2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 3 100.00 Using where; Full scan on NULL key
Warnings:
Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
-Note 1003 /* select#1 */ select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where `test`.`t1`.`oref` = `test`.`t2`.`oref` and trigcond(<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a` or `test`.`t1`.`a` is null) having trigcond(`test`.`t1`.`a` is null)))) AS `Z` from `test`.`t2`
+Note 1003 /* select#1 */ select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a checking NULL where `test`.`t1`.`oref` = `test`.`t2`.`oref` having trigcond(`test`.`t1`.`a` is null))))) AS `Z` from `test`.`t2`
flush status;
select oref, a from t2 where a in (select a from t1 where oref=t2.oref);
oref a
@@ -622,8 +622,8 @@ aa 1 1
bb NULL NULL
select oref, a from t2 where a in (select ie from t1 where oref=t2.oref);
oref a
-aa 1
cc 5
+aa 1
select oref, a from t2 where a not in (select ie from t1 where oref=t2.oref);
oref a
ee NULL
diff --git a/mysql-test/main/subselect4.result b/mysql-test/main/subselect4.result
index 6f29fe34ca5..c277a4ba5c9 100644
--- a/mysql-test/main/subselect4.result
+++ b/mysql-test/main/subselect4.result
@@ -714,8 +714,7 @@ WHERE ( t1.f10 ) IN ( SELECT f11 FROM t2 GROUP BY f11 ));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
-2 SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1
-3 MATERIALIZED t2 ALL NULL NULL NULL NULL 2
+2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
SELECT * FROM t1
WHERE f3 = (
SELECT t1.f3 FROM t1
@@ -729,8 +728,7 @@ WHERE ( f10, f10 ) IN ( SELECT f11, f11 FROM t2 GROUP BY f11 ));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
-2 SUBQUERY <subquery3> eq_ref distinct_key distinct_key 8 func,func 1
-3 MATERIALIZED t2 ALL NULL NULL NULL NULL 2
+2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
SELECT * FROM t1
WHERE f3 = (
SELECT f3 FROM t1
@@ -1371,7 +1369,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where
3 SUBQUERY SQ1_t1 index NULL f4 5 NULL 2 Using index; Using temporary
-3 SUBQUERY SQ1_t3 range f4 f4 5 NULL 2 Using where; Using index; Using join buffer (flat, BNL join)
+3 SUBQUERY SQ1_t3 index f4 f4 5 NULL 2 Using where; Using index; Using join buffer (flat, BNL join)
SELECT * FROM t1 WHERE
(SELECT f2 FROM t2
WHERE f4 <= ALL
@@ -1391,8 +1389,8 @@ INSERT INTO t2 VALUES (1), (2);
EXPLAIN
SELECT i FROM t1 WHERE (1) NOT IN (SELECT i FROM t2);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 system NULL NULL NULL NULL 1
-2 SUBQUERY t2 index_subquery k k 5 const 2 Using index
+1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
+2 SUBQUERY t2 index k k 5 NULL 2 Using where; Using index
DROP TABLE t2;
DROP TABLE t1;
#
@@ -1788,7 +1786,7 @@ SELECT * FROM t1 WHERE ( 6 ) NOT IN ( SELECT t2.f3 FROM t2 JOIN t3 ON t3.f10 = t
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 SUBQUERY t3 system NULL NULL NULL NULL 1
-2 SUBQUERY t2 ref_or_null f10 f10 10 const,const 2 Using where; Using index
+2 SUBQUERY t2 index f10 f10 10 NULL 2 Using where; Using index
SELECT * FROM t1 WHERE ( 6 ) NOT IN ( SELECT t2.f3 FROM t2 JOIN t3 ON t3.f10 = t2.f10);
f4
drop table t1,t2,t3;
@@ -2902,8 +2900,8 @@ WHERE tn.key1 IN ('1','2','3','4','5','6','7','8','9','10')
);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY hist ALL NULL NULL NULL NULL 100 Using where
-2 DEPENDENT SUBQUERY tms range PRIMARY PRIMARY 32 NULL 10 Using where; Using index
-2 DEPENDENT SUBQUERY tn eq_ref PRIMARY PRIMARY 32 test.tms.key1 1 Using where
+2 DEPENDENT SUBQUERY tn range PRIMARY PRIMARY 32 NULL 10 Using index condition; Using where
+2 DEPENDENT SUBQUERY tms eq_ref PRIMARY PRIMARY 32 test.tn.key1 1 Using index
set optimizer_switch=@tmp_os;
drop table t1, t10, t11;
#
@@ -3132,10 +3130,9 @@ where b in (select c from t3
group by (select a from t1 where a = 1) in (select d from t4));
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 100.00
+1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch(t2); Using join buffer (flat, BNL join)
Warnings:
-Note 1003 select `test`.`t2`.`b` AS `b` from `test`.`t2` semi join (`test`.`t3`) where 1
+Note 1003 select `test`.`t2`.`b` AS `b` from `test`.`t2` semi join (`test`.`t3`) where `test`.`t3`.`c` = `test`.`t2`.`b`
select b from t2
where b in (select c from t3
group by (select a from t1 where a = 1) in (select d from t4));
diff --git a/mysql-test/main/subselect_exists2in.result b/mysql-test/main/subselect_exists2in.result
index a473f48e0f6..c01c28fc258 100644
--- a/mysql-test/main/subselect_exists2in.result
+++ b/mysql-test/main/subselect_exists2in.result
@@ -902,9 +902,8 @@ WHERE EXISTS ( SELECT * FROM t1 AS sq2
WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
-3 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 100.00 Using where
-3 DEPENDENT SUBQUERY <subquery4> eq_ref distinct_key distinct_key 4 func 1 100.00
-4 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch
+3 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1276 Field or reference 'sq1.pk' of SELECT #3 was resolved in SELECT #1
Note 1276 Field or reference 'sq1.f1' of SELECT #3 was resolved in SELECT #1
@@ -922,9 +921,8 @@ WHERE EXISTS ( SELECT * FROM t1 AS sq2
WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
-3 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 100.00 Using where
-3 DEPENDENT SUBQUERY <subquery4> eq_ref distinct_key distinct_key 4 func 1 100.00
-4 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00
+3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch
+3 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1276 Field or reference 'sq1.pk' of SELECT #3 was resolved in SELECT #1
Note 1276 Field or reference 'sq1.f1' of SELECT #3 was resolved in SELECT #1
diff --git a/mysql-test/main/subselect_exists2in_costmat.result b/mysql-test/main/subselect_exists2in_costmat.result
index 1c9574aafd3..5630f8f275a 100644
--- a/mysql-test/main/subselect_exists2in_costmat.result
+++ b/mysql-test/main/subselect_exists2in_costmat.result
@@ -64,8 +64,8 @@ Code = Country) OR
Name LIKE 'L%') AND
surfacearea > 1000000;
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY Country ALL Name,SurfaceArea NULL NULL NULL 239 Using where
-2 MATERIALIZED City ALL Population,Country NULL NULL NULL 4079 Using where
+1 PRIMARY Country range Name,SurfaceArea SurfaceArea 4 NULL 71 Using index condition; Using where; Rowid-ordered scan
+2 DEPENDENT SUBQUERY City index_subquery Population,Country Country 3 func 17 Using where
SELECT Name FROM Country
WHERE (EXISTS (select 1 from City where City.Population > 100000 and
Code = Country) OR
diff --git a/mysql-test/main/subselect_exists2in_costmat.test b/mysql-test/main/subselect_exists2in_costmat.test
index 371f0936d1a..dd3890496f5 100644
--- a/mysql-test/main/subselect_exists2in_costmat.test
+++ b/mysql-test/main/subselect_exists2in_costmat.test
@@ -67,6 +67,7 @@ set @@optimizer_switch = 'exists_to_in=on,in_to_exists=on,semijoin=on,materializ
-- echo Q1.1m:
-- echo MATERIALIZATION: there are too many rows in the outer query
-- echo to be looked up in the inner table.
+
EXPLAIN
SELECT Name FROM Country
WHERE (EXISTS (select 1 from City where City.Population > 100000 and
diff --git a/mysql-test/main/subselect_extra.result b/mysql-test/main/subselect_extra.result
index c654fdfca13..057d05e0038 100644
--- a/mysql-test/main/subselect_extra.result
+++ b/mysql-test/main/subselect_extra.result
@@ -451,8 +451,8 @@ WHERE t3.b IN (SELECT v1.b FROM v1, t2
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 <derived3> ref key1 key1 8 const,const 0 Start temporary
-1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where
+1 PRIMARY <derived3> ref key1 key1 8 const,const 0 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
diff --git a/mysql-test/main/subselect_innodb.result b/mysql-test/main/subselect_innodb.result
index 0c44708eb32..c95cf3abb37 100644
--- a/mysql-test/main/subselect_innodb.result
+++ b/mysql-test/main/subselect_innodb.result
@@ -314,7 +314,7 @@ EXPLAIN SELECT 1 FROM t1 WHERE NOT EXISTS
(SELECT 1 FROM t2 WHERE d = (SELECT d FROM t2 WHERE a >= 1) ORDER BY d);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 1 Using where
-2 DEPENDENT SUBQUERY t2 unique_subquery PRIMARY,d PRIMARY 1 func 1 Using where
+2 DEPENDENT SUBQUERY t2 unique_subquery PRIMARY,d d 2 func 1 Using index; Using where
3 DEPENDENT SUBQUERY t2 index NULL d 2 NULL 1 Using index
DROP TABLE t2;
CREATE TABLE t2 (b INT, c INT, UNIQUE KEY (b), UNIQUE KEY (b, c )) ENGINE=INNODB;
@@ -612,11 +612,10 @@ INNER JOIN
ON ( 1 IN ( SELECT f4 FROM t4 ) ) )
ON ( f1 >= f2 );
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
-1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00
-1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t4 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using join buffer (flat, BNL join)
+1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (incremental, BNL join)
1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00 Using join buffer (incremental, BNL join)
-3 MATERIALIZED t4 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t3`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` semi join (`test`.`t4`) join `test`.`t3` where `test`.`t4`.`f4` = 1 and `test`.`t1`.`f1` >= `test`.`t2`.`f2`
DROP TABLE t1,t2,t3,t4;
diff --git a/mysql-test/main/subselect_mat.result b/mysql-test/main/subselect_mat.result
index 2353e18c28e..f2ee080454b 100644
--- a/mysql-test/main/subselect_mat.result
+++ b/mysql-test/main/subselect_mat.result
@@ -105,7 +105,7 @@ explain extended
select * from t1i where a1 in (select b1 from t2i where b1 > '0');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1i index NULL _it1_idx # NULL 3 100.00 Using where;
-2 MATERIALIZED t2i range it2i1,it2i3 it2i1 # NULL 5 100.00 Using where;
+2 MATERIALIZED t2i index it2i1,it2i3 it2i1 # NULL 5 100.00 Using where;
Warnings:
Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`>(<in_optimizer>(`test`.`t1i`.`a1`,`test`.`t1i`.`a1` in ( <materialize> (/* select#2 */ select `test`.`t2i`.`b1` from `test`.`t2i` where `test`.`t2i`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery2>`.`b1`))))
select * from t1i where a1 in (select b1 from t2i where b1 > '0');
@@ -127,7 +127,7 @@ explain extended
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1i index NULL _it1_idx # NULL 3 100.00 Using where;
-2 MATERIALIZED t2i range it2i1,it2i3 it2i3 # NULL 5 100.00 Using where;
+2 MATERIALIZED t2i index it2i1,it2i3 it2i3 # NULL 5 100.00 Using where;
Warnings:
Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery2>`.`b1` and `test`.`t1i`.`a2` = `<subquery2>`.`b2`))))
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0');
@@ -340,7 +340,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1i index NULL # # # 3 100.00 #
3 MATERIALIZED t3i index NULL # # # 4 100.00 #
4 MATERIALIZED t2i index it2i2 # # # 5 100.00 #
-2 MATERIALIZED t2i range it2i1,it2i3 # # # 5 100.00 #
+2 MATERIALIZED t2i index it2i1,it2i3 # # # 5 100.00 #
Warnings:
Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery2>`.`b1` and `test`.`t1i`.`a2` = `<subquery2>`.`b2`)))) and <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#3 */ select `test`.`t3i`.`c1`,`test`.`t3i`.`c2` from `test`.`t3i` where <expr_cache><`test`.`t3i`.`c1`,`test`.`t3i`.`c2`>(<in_optimizer>((`test`.`t3i`.`c1`,`test`.`t3i`.`c2`),(`test`.`t3i`.`c1`,`test`.`t3i`.`c2`) in ( <materialize> (/* select#4 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), <primary_index_lookup>(`test`.`t3i`.`c1` in <temporary table> on distinct_key where `test`.`t3i`.`c1` = `<subquery4>`.`b1` and `test`.`t3i`.`c2` = `<subquery4>`.`b2`)))) ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery3>`.`c1` and `test`.`t1i`.`a2` = `<subquery3>`.`c2`))))
select * from t1i
@@ -423,7 +423,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
7 UNION t1i index NULL # # # 3 100.00 #
9 MATERIALIZED t3i index NULL # # # 4 100.00 #
10 MATERIALIZED t2i index it2i2 # # # 5 100.00 #
-8 MATERIALIZED t2i range it2i1,it2i3 # # # 5 100.00 #
+8 MATERIALIZED t2i index it2i1,it2i3 # # # 5 100.00 #
NULL UNION RESULT <union1,7> ALL NULL # # # NULL NULL #
Warnings:
Note 1003 (/* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#3 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%02' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery3>`.`c2`)))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#4 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%03' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery4>`.`c2`)))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery2>`.`b1` and `test`.`t1`.`a2` = `<subquery2>`.`b2`)))) and <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (/* select#5 */ select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <expr_cache><`test`.`t3`.`c1`,`test`.`t3`.`c2`>(<in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (/* select#6 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where `test`.`t3`.`c1` = `<subquery6>`.`b1` and `test`.`t3`.`c2` = `<subquery6>`.`b2`)))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery5>`.`c1` and `test`.`t1`.`a2` = `<subquery5>`.`c2`))))) union (/* select#7 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#8 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery8>`.`b1` and `test`.`t1i`.`a2` = `<subquery8>`.`b2`)))) and <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#9 */ select `test`.`t3i`.`c1`,`test`.`t3i`.`c2` from `test`.`t3i` where <expr_cache><`test`.`t3i`.`c1`,`test`.`t3i`.`c2`>(<in_optimizer>((`test`.`t3i`.`c1`,`test`.`t3i`.`c2`),(`test`.`t3i`.`c1`,`test`.`t3i`.`c2`) in ( <materialize> (/* select#10 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), <primary_index_lookup>(`test`.`t3i`.`c1` in <temporary table> on distinct_key where `test`.`t3i`.`c1` = `<subquery10>`.`b1` and `test`.`t3i`.`c2` = `<subquery10>`.`b2`)))) ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery9>`.`c1` and `test`.`t1i`.`a2` = `<subquery9>`.`c2`)))))
@@ -1534,8 +1534,7 @@ SET @@optimizer_switch='semijoin=on,materialization=on';
EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan
+1 PRIMARY t2 ALL PRIMARY NULL NULL NULL 2 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
pk
2
@@ -1889,8 +1888,8 @@ WHERE alias4.c = alias3.b
);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
-3 MATERIALIZED alias3 ALL NULL NULL NULL NULL 2 Using where
-3 MATERIALIZED alias4 ref c c 11 test.alias3.b 2 Using where; Using index
+3 MATERIALIZED alias3 ALL NULL NULL NULL NULL 2
+3 MATERIALIZED alias4 index c c 11 NULL 2 Using where; Using index; Using join buffer (flat, BNL join)
DROP TABLE t1,t2;
#
# BUG#928048: Query containing IN subquery with OR in the where clause returns a wrong result
@@ -1953,11 +1952,11 @@ EXPLAIN EXTENDED
SELECT * FROM t1
WHERE a IN (SELECT MAX(c) FROM t2) AND b=7 AND (a IS NULL OR a=b);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00
-1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
+1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00 Using where
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from <materialize> (/* select#2 */ select max(`test`.`t2`.`c`) from `test`.`t2` having `MAX(c)` is null or `MAX(c)` = 7) join `test`.`t1` where `test`.`t1`.`b` = 7 and `test`.`t1`.`a` = `<subquery2>`.`MAX(c)` and (<cache>(/*always not null*/ 1 is null) or `<subquery2>`.`MAX(c)` = 7)
+Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from <materialize> (/* select#2 */ select max(`test`.`t2`.`c`) from `test`.`t2` having `MAX(c)` is null or `MAX(c)` = 7) join `test`.`t1` where `test`.`t1`.`b` = 7 and `<subquery2>`.`MAX(c)` = `test`.`t1`.`a` and (`test`.`t1`.`a` is null or `test`.`t1`.`a` = 7)
SELECT * FROM t1
WHERE a IN (SELECT MAX(c) FROM t2) AND b=7 AND (a IS NULL OR a=b);
a b
@@ -1966,8 +1965,8 @@ EXPLAIN
SELECT * FROM t1
WHERE a IN (SELECT MAX(c) FROM t2 WHERE c < 4) AND b=7 AND (a IS NULL OR a=b);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1
-1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
+1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 Using where
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where
SELECT * FROM t1
WHERE a IN (SELECT MAX(c) FROM t2 WHERE c < 4) AND b=7 AND (a IS NULL OR a=b);
@@ -2241,9 +2240,8 @@ WHERE EXISTS ( SELECT * FROM t1 AS sq2
WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY sq1 ALL NULL NULL NULL NULL 2 Using where
-2 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 Using where
-2 DEPENDENT SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1
-3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where; FirstMatch
+2 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
# this checks the result set above
set optimizer_switch= 'materialization=off,semijoin=off';
SELECT sq1.f2 FROM t1 AS sq1
@@ -2275,10 +2273,9 @@ WHERE EXISTS ( SELECT * FROM t2, t3
WHERE i3 = i2 AND f1 IN ( SELECT f3 FROM t3 ) );
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
-2 DEPENDENT SUBQUERY t2 index i2 i2 5 NULL 3 100.00 Using where; Using index
-2 DEPENDENT SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00
+2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 8 100.00 Using where; FirstMatch
+2 DEPENDENT SUBQUERY t2 index i2 i2 5 NULL 3 100.00 Using where; Using index; Using join buffer (flat, BNL join)
2 DEPENDENT SUBQUERY t3 ref i3 i3 5 test.t2.i2 2 100.00 Using index
-3 MATERIALIZED t3 ALL NULL NULL NULL NULL 8 100.00
Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where <expr_cache><`test`.`t1`.`f1`>(exists(/* select#2 */ select 1 from `test`.`t2` semi join (`test`.`t3`) join `test`.`t3` where `test`.`t3`.`i3` = `test`.`t2`.`i2` and `test`.`t1`.`f1` = `test`.`t3`.`f3` limit 1))
@@ -2314,9 +2311,8 @@ SELECT pk, f1, ( SELECT COUNT(*) FROM t2
WHERE t1.pk IN ( SELECT f2 FROM t2 ) ) AS sq FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00
-2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00
-2 DEPENDENT SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00
-3 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00
+2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; FirstMatch
+2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using join buffer (flat, BNL join)
Warnings:
Note 1276 Field or reference 'test.t1.pk' of SELECT #2 was resolved in SELECT #1
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`f1` AS `f1`,<expr_cache><`test`.`t1`.`pk`>((/* select#2 */ select count(0) from `test`.`t2` semi join (`test`.`t2`) where `test`.`t1`.`pk` = `test`.`t2`.`f2`)) AS `sq` from `test`.`t1`
@@ -2450,8 +2446,7 @@ explain
SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 9
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2);
1
1
@@ -2462,8 +2457,8 @@ alter table t1 add key(id);
explain
SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3
-1 PRIMARY t1 ref id id 4 test.t2.i1 2 Using index
+1 PRIMARY t1 index id id 4 NULL 9 Using index
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where
SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2);
1
@@ -2519,8 +2514,8 @@ INSERT INTO t2 VALUES (11,11),(12,12),(13,13);
CREATE VIEW v1 AS SELECT t2.i1 FROM t2 where t2.i1 = t2.i2;
explain SELECT 1 FROM t1 where t1.id IN (SELECT v1.i1 from v1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3
-1 PRIMARY t1 ref id id 4 test.t2.i1 2 Using index
+1 PRIMARY t1 index id id 4 NULL 9 Using index
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where
SELECT 1 FROM t1 where t1.id IN (SELECT v1.i1 from v1);
1
@@ -2817,6 +2812,7 @@ PRIMARY KEY (pk)
INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo'),(2,'f','ffff','ffff','ffff');
CREATE TABLE t2 LIKE t1;
INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii'),(2,'f','ffff','ffff','ffff');
+insert into t2 select -seq,"","","","" from seq_1_to_10;
SET @@optimizer_switch='default,semijoin=on,materialization=on';
EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
id select_type table type possible_keys key key_len ref rows Extra
diff --git a/mysql-test/main/subselect_mat.test b/mysql-test/main/subselect_mat.test
index cacafb0000f..58548d18caa 100644
--- a/mysql-test/main/subselect_mat.test
+++ b/mysql-test/main/subselect_mat.test
@@ -2,7 +2,7 @@
# Hash semi-join regression tests
# (WL#1110: Subquery optimization: materialization)
#
-
+--source include/have_sequence.inc
# force the use of materialization
set @subselect_mat_test_optimizer_switch_value='materialization=on,in_to_exists=off,semijoin=off';
@@ -111,6 +111,7 @@ INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo'),(2,'f','ffff','ffff','ffff');
CREATE TABLE t2 LIKE t1;
INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii'),(2,'f','ffff','ffff','ffff');
+insert into t2 select -seq,"","","","" from seq_1_to_10;
SET @@optimizer_switch='default,semijoin=on,materialization=on';
EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
diff --git a/mysql-test/main/subselect_mat_cost.result b/mysql-test/main/subselect_mat_cost.result
index 66d48b549c4..d46fb616d5e 100644
--- a/mysql-test/main/subselect_mat_cost.result
+++ b/mysql-test/main/subselect_mat_cost.result
@@ -59,15 +59,15 @@ set @@optimizer_switch = 'in_to_exists=on,semijoin=on,materialization=on,partial
Q1.1m:
MATERIALIZATION: there are too many rows in the outer query
to be looked up in the inner table.
-EXPLAIN
+set statement optimizer_cache_hit_ratio=20 for EXPLAIN
SELECT Name FROM Country
WHERE (Code IN (select Country from City where City.Population > 100000) OR
Name LIKE 'L%') AND
surfacearea > 1000000;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY Country ALL Name,SurfaceArea NULL NULL NULL 239 Using where
-2 MATERIALIZED City ALL Population,Country NULL NULL NULL 4079 Using where
-SELECT Name FROM Country
+3 MATERIALIZED City ALL Population,Country NULL NULL NULL 4079 Using where
+set statement optimizer_cache_hit_ratio=20 for SELECT Name FROM Country
WHERE (Code IN (select Country from City where City.Population > 100000) OR
Name LIKE 'L%') AND
surfacearea > 1000000;
@@ -133,9 +133,9 @@ Country.SurfaceArea < 3000 AND Country.SurfaceArea > 10 AND
(select Language from CountryLanguage where Percentage > 50) OR
City.name LIKE '%Island%');
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY Country ALL PRIMARY,SurfaceArea NULL NULL NULL 239 Using where
+1 PRIMARY Country range PRIMARY,SurfaceArea SurfaceArea 4 NULL 47 Using index condition; Rowid-ordered scan
1 PRIMARY City ref Country Country 3 world.Country.Code 17 Using where
-2 MATERIALIZED CountryLanguage ALL Percentage,Language NULL NULL NULL 984 Using where
+2 MATERIALIZED CountryLanguage range Percentage,Language Percentage 4 NULL 197 Using index condition; Rowid-ordered scan
SELECT *
FROM Country, City
WHERE City.Country = Country.Code AND
@@ -158,7 +158,7 @@ Country.SurfaceArea < 3000 AND Country.SurfaceArea > 10 AND
(select Language from CountryLanguage where Percentage > 50) OR
Country.name LIKE '%Island%');
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY Country ALL PRIMARY,SurfaceArea NULL NULL NULL 239 Using where
+1 PRIMARY Country range PRIMARY,SurfaceArea SurfaceArea 4 NULL 47 Using index condition; Using where; Rowid-ordered scan
1 PRIMARY City ref Country Country 3 world.Country.Code 17
2 DEPENDENT SUBQUERY CountryLanguage index_subquery Percentage,Language Language 30 func 2 Using where
SELECT *
@@ -203,7 +203,7 @@ OR
(Country.Code, City.Name) IN
(select Country, Language from CountryLanguage));
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY Country ALL PRIMARY,SurfaceArea NULL NULL NULL 239 Using where
+1 PRIMARY Country range PRIMARY,SurfaceArea SurfaceArea 4 NULL 73 Using index condition; Rowid-ordered scan
1 PRIMARY City ref Country Country 3 world.Country.Code 17 Using where
3 MATERIALIZED CountryLanguage index PRIMARY,Language PRIMARY 33 NULL 984 Using index
2 DEPENDENT SUBQUERY CountryLanguage unique_subquery PRIMARY,Percentage,Language PRIMARY 33 func,func 1 Using where
diff --git a/mysql-test/main/subselect_mat_cost.test b/mysql-test/main/subselect_mat_cost.test
index 8fe38849735..12263e75cfc 100644
--- a/mysql-test/main/subselect_mat_cost.test
+++ b/mysql-test/main/subselect_mat_cost.test
@@ -73,13 +73,13 @@ set @@optimizer_switch = 'in_to_exists=on,semijoin=on,materialization=on,partial
-- echo Q1.1m:
-- echo MATERIALIZATION: there are too many rows in the outer query
-- echo to be looked up in the inner table.
-EXPLAIN
+set statement optimizer_cache_hit_ratio=20 for EXPLAIN
SELECT Name FROM Country
WHERE (Code IN (select Country from City where City.Population > 100000) OR
Name LIKE 'L%') AND
surfacearea > 1000000;
-SELECT Name FROM Country
+set statement optimizer_cache_hit_ratio=20 for SELECT Name FROM Country
WHERE (Code IN (select Country from City where City.Population > 100000) OR
Name LIKE 'L%') AND
surfacearea > 1000000;
@@ -210,7 +210,6 @@ WHERE Code NOT IN (SELECT Country FROM CountryLanguage WHERE Language = 'English
-- echo MATERIALIZATION because the outer query filters less rows than Q5-a,
-- echo so there are more lookups.
-
set statement optimizer_switch='rowid_filter=off' for
EXPLAIN
SELECT Country.Name
@@ -369,6 +368,7 @@ drop index CountryCapital on Country;
# TODO: the cost estimates for subqueries in the HAVING clause need to be changed
# to take into account that the subquery predicate is executed #times ~ to the
# number of groups, not number of rows
+
EXPLAIN
SELECT City.Name, City.Population
FROM City JOIN Country ON City.Country = Country.Code
diff --git a/mysql-test/main/subselect_mat_cost_bugs.result b/mysql-test/main/subselect_mat_cost_bugs.result
index 185a99672e6..14522a24950 100644
--- a/mysql-test/main/subselect_mat_cost_bugs.result
+++ b/mysql-test/main/subselect_mat_cost_bugs.result
@@ -197,7 +197,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 Using where; Using filesort
1 PRIMARY alias1 eq_ref PRIMARY PRIMARY 4 alias2.f3 1 Using index
3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2
-3 DEPENDENT SUBQUERY t1 range PRIMARY PRIMARY 4 NULL 2 Using where; Using index; Using join buffer (flat, BNL join)
+3 DEPENDENT SUBQUERY t1 index PRIMARY PRIMARY 4 NULL 2 Using where; Using index; Using join buffer (flat, BNL join)
2 DERIVED t2 ALL NULL NULL NULL NULL 2
SELECT alias2.f2 AS field1
FROM t1 AS alias1 JOIN ( SELECT * FROM t2 ) AS alias2 ON alias2.f3 = alias1.f1
@@ -363,8 +363,8 @@ WHERE t4.a >= t3.b
AND a = SOME (SELECT b FROM t5));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where
-2 DEPENDENT SUBQUERY t5 index c c 10 NULL 2 Using where; Using index; Start temporary
-2 DEPENDENT SUBQUERY t4 eq_ref PRIMARY PRIMARY 4 test.t5.b 1 Using where; End temporary
+2 DEPENDENT SUBQUERY t4 ALL PRIMARY NULL NULL NULL 2 Using where
+2 DEPENDENT SUBQUERY t5 index c c 10 NULL 2 Using where; Using index; Start temporary; End temporary; Using join buffer (flat, BNL join)
SELECT *
FROM t3
WHERE t3.b > ALL (
diff --git a/mysql-test/main/subselect_no_exists_to_in.result b/mysql-test/main/subselect_no_exists_to_in.result
index 18cc982c565..429696ebeec 100644
--- a/mysql-test/main/subselect_no_exists_to_in.result
+++ b/mysql-test/main/subselect_no_exists_to_in.result
@@ -1453,21 +1453,21 @@ a
4
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index
-1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 100.00 Using where
+1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 100.00 Using where
+1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index
Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t1`.`b` <> 30
select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
a
2
3
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index
-1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 100.00
-1 PRIMARY t3 index PRIMARY PRIMARY 4 NULL 3 75.00 Using where; Using index; Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 100.00 Using where
+1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index
+1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00 Using index
Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where `test`.`t3`.`a` = `test`.`t1`.`b` and `test`.`t1`.`a` = `test`.`t2`.`a`
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where `test`.`t3`.`a` = `test`.`t1`.`b` and `test`.`t2`.`a` = `test`.`t1`.`a`
drop table t1, t2, t3;
create table t1 (a int, b int, index a (a,b));
create table t2 (a int, index a (a));
@@ -1507,7 +1507,7 @@ a
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
-1 PRIMARY t3 range a a 5 NULL 3 100.00 Using where; Using index
+1 PRIMARY t3 index a a 5 NULL 3 100.00 Using where; Using index
1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 100.00 Using index; FirstMatch(t2)
Warnings:
Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where `test`.`t1`.`b` = `test`.`t3`.`a` and `test`.`t1`.`a` = `test`.`t2`.`a`
@@ -1615,21 +1615,21 @@ a3 1
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
+2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
+2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
+2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
@@ -2422,15 +2422,17 @@ a
3
DROP TABLE t1;
create table t1 (a int, b int);
-insert into t1 values (1,2),(3,4);
+insert into t1 values (1,2),(3,4),(5,6),(7,8);
select * from t1 up where exists (select * from t1 where t1.a=up.a);
a b
1 2
3 4
+5 6
+7 8
explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY up ALL NULL NULL NULL NULL 2 100.00 Using where
-2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
+1 PRIMARY up ALL NULL NULL NULL NULL 4 100.00 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 4 100.00 Using where
Warnings:
Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
Note 1003 /* select#1 */ select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where <expr_cache><`test`.`up`.`a`>(exists(/* select#2 */ select 1 from `test`.`t1` where `test`.`t1`.`a` = `test`.`up`.`a` limit 1))
@@ -3103,7 +3105,7 @@ retailerID statusID changed
drop table t1;
create table t1(a int, primary key (a));
insert into t1 values (10);
-create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b));
+create table t2 (a int primary key, b varchar(32), c int, unique key cb(c, b));
insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989');
insert into t2(a, c, b) values (4,10,'360'), (5,10,'35998'), (6,10,'35999');
analyze table t1;
@@ -3116,7 +3118,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 range b b 40 NULL 3 Using where
+2 SUBQUERY t2 ref cb cb 5 const 1 Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
@@ -3128,7 +3130,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 range b b 40 NULL 3 Using index condition
+2 SUBQUERY t2 ref cb cb 5 const 1 Using index condition; Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
@@ -4441,7 +4443,7 @@ out_a MIN(b)
DROP TABLE t1;
CREATE TABLE t1 (a INT);
CREATE TABLE t2 (a INT);
-INSERT INTO t1 VALUES (1),(2);
+INSERT INTO t1 VALUES (1),(2),(3),(4);
INSERT INTO t2 VALUES (1),(2);
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
2
@@ -4450,7 +4452,7 @@ SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
EXPLAIN EXTENDED
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
@@ -4459,7 +4461,7 @@ EXPLAIN EXTENDED
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION
(SELECT 1 FROM t2 WHERE t1.a = t2.a));
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 2 100.00 Using where
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
@@ -4543,15 +4545,15 @@ SET @save_join_cache_level=@@join_cache_level;
SET join_cache_level=0;
EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 GROUP BY a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary
Warnings:
Note 1003 /* select#1 */ select 1 AS `1` from <materialize> (/* select#2 */ select min(`test`.`t1`.`a`) from `test`.`t1` group by `test`.`t1`.`a`) join `test`.`t1` where `<subquery2>`.`min(a)` = 1
EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 WHERE a > 3 GROUP BY a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary
Warnings:
Note 1003 /* select#1 */ select 1 AS `1` from <materialize> (/* select#2 */ select min(`test`.`t1`.`a`) from `test`.`t1` where `test`.`t1`.`a` > 3 group by `test`.`t1`.`a`) join `test`.`t1` where `<subquery2>`.`min(a)` = 1
@@ -6080,8 +6082,7 @@ WHERE col_varchar_nokey IN
(SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY ot system NULL NULL NULL NULL 1
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED it1 ref idx_cvk_cik idx_cvk_cik 9 const,const 1 Using where; Using index
+1 PRIMARY it1 ref idx_cvk_cik idx_cvk_cik 9 const,const 1 Using where; Using index; FirstMatch(ot)
SELECT col_int_nokey FROM ot
WHERE col_varchar_nokey IN
(SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL);
@@ -6093,8 +6094,7 @@ WHERE (col_varchar_nokey, 'x') IN
(SELECT col_varchar_key, col_varchar_key2 FROM it2);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY ot system NULL NULL NULL NULL 1
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1
-2 MATERIALIZED it2 ref idx_cvk_cvk2_cik,idx_cvk_cik idx_cvk_cvk2_cik 8 const,const 1 Using where; Using index
+1 PRIMARY it2 ref idx_cvk_cvk2_cik,idx_cvk_cik idx_cvk_cvk2_cik 8 const,const 1 Using where; Using index; FirstMatch(ot)
SELECT col_int_nokey FROM ot
WHERE (col_varchar_nokey, 'x') IN
(SELECT col_varchar_key, col_varchar_key2 FROM it2);
diff --git a/mysql-test/main/subselect_no_mat.result b/mysql-test/main/subselect_no_mat.result
index 0aa5f00a149..86b8e075f01 100644
--- a/mysql-test/main/subselect_no_mat.result
+++ b/mysql-test/main/subselect_no_mat.result
@@ -1456,21 +1456,21 @@ a
4
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index
-1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 100.00 Using where
+1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 100.00 Using where
+1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index
Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t1`.`b` <> 30
select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
a
2
3
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index
-1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 100.00
-1 PRIMARY t3 index PRIMARY PRIMARY 4 NULL 3 75.00 Using where; Using index; Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 100.00 Using where
+1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index
+1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00 Using index
Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where `test`.`t3`.`a` = `test`.`t1`.`b` and `test`.`t1`.`a` = `test`.`t2`.`a`
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where `test`.`t3`.`a` = `test`.`t1`.`b` and `test`.`t2`.`a` = `test`.`t1`.`a`
drop table t1, t2, t3;
create table t1 (a int, b int, index a (a,b));
create table t2 (a int, index a (a));
@@ -1510,7 +1510,7 @@ a
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
-1 PRIMARY t3 range a a 5 NULL 3 100.00 Using where; Using index
+1 PRIMARY t3 index a a 5 NULL 3 100.00 Using where; Using index
1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 100.00 Using index; FirstMatch(t2)
Warnings:
Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where `test`.`t1`.`b` = `test`.`t3`.`a` and `test`.`t1`.`a` = `test`.`t2`.`a`
@@ -1618,21 +1618,21 @@ a3 1
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
+2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
+2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
+2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
@@ -2425,15 +2425,17 @@ a
3
DROP TABLE t1;
create table t1 (a int, b int);
-insert into t1 values (1,2),(3,4);
+insert into t1 values (1,2),(3,4),(5,6),(7,8);
select * from t1 up where exists (select * from t1 where t1.a=up.a);
a b
1 2
3 4
+5 6
+7 8
explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY up ALL NULL NULL NULL NULL 2 100.00
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch(up); Using join buffer (flat, BNL join)
+1 PRIMARY up ALL NULL NULL NULL NULL 4 100.00
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where; FirstMatch(up); Using join buffer (flat, BNL join)
Warnings:
Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`up`.`a`
@@ -3105,7 +3107,7 @@ retailerID statusID changed
drop table t1;
create table t1(a int, primary key (a));
insert into t1 values (10);
-create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b));
+create table t2 (a int primary key, b varchar(32), c int, unique key cb(c, b));
insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989');
insert into t2(a, c, b) values (4,10,'360'), (5,10,'35998'), (6,10,'35999');
analyze table t1;
@@ -3118,7 +3120,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 range b b 40 NULL 3 Using where
+2 SUBQUERY t2 ref cb cb 5 const 1 Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
@@ -3130,7 +3132,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 range b b 40 NULL 3 Using index condition
+2 SUBQUERY t2 ref cb cb 5 const 1 Using index condition; Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
@@ -4228,8 +4230,8 @@ INSERT INTO t2 VALUES (7), (5), (1), (3);
SELECT id, st FROM t1
WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id);
id st
-3 FL
1 GA
+3 FL
7 FL
SELECT id, st FROM t1
WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id)
@@ -4441,7 +4443,7 @@ out_a MIN(b)
DROP TABLE t1;
CREATE TABLE t1 (a INT);
CREATE TABLE t2 (a INT);
-INSERT INTO t1 VALUES (1),(2);
+INSERT INTO t1 VALUES (1),(2),(3),(4);
INSERT INTO t2 VALUES (1),(2);
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
2
@@ -4450,7 +4452,7 @@ SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
EXPLAIN EXTENDED
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
Warnings:
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
@@ -4459,7 +4461,7 @@ EXPLAIN EXTENDED
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION
(SELECT 1 FROM t2 WHERE t1.a = t2.a));
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 2 100.00 Using where
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
@@ -5687,9 +5689,9 @@ WHERE (ot1.a,ot4.a) IN (SELECT it2.a,it3.a
FROM it2,it3);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY ot1 ALL NULL NULL NULL NULL 2
-1 PRIMARY it2 ALL NULL NULL NULL NULL 4 Using where; Start temporary; Using join buffer (flat, BNL join)
-1 PRIMARY it3 ALL NULL NULL NULL NULL 6 Using join buffer (flat, BNL join)
-1 PRIMARY ot4 ALL NULL NULL NULL NULL 8 Using where; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY ot4 ALL NULL NULL NULL NULL 8 Using join buffer (flat, BNL join)
+1 PRIMARY it2 ALL NULL NULL NULL NULL 4 Using where
+1 PRIMARY it3 ALL NULL NULL NULL NULL 6 Using where; FirstMatch(ot4)
DROP TABLE IF EXISTS ot1, ot4, it2, it3;
#
# Bug#729039: NULL keys used to evaluate subquery
diff --git a/mysql-test/main/subselect_no_opts.result b/mysql-test/main/subselect_no_opts.result
index e11c344cfb4..70bacb29b0a 100644
--- a/mysql-test/main/subselect_no_opts.result
+++ b/mysql-test/main/subselect_no_opts.result
@@ -1614,21 +1614,21 @@ a3 1
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
+2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
+2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
+2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
@@ -2421,15 +2421,17 @@ a
3
DROP TABLE t1;
create table t1 (a int, b int);
-insert into t1 values (1,2),(3,4);
+insert into t1 values (1,2),(3,4),(5,6),(7,8);
select * from t1 up where exists (select * from t1 where t1.a=up.a);
a b
1 2
3 4
+5 6
+7 8
explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY up ALL NULL NULL NULL NULL 2 100.00 Using where
-2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
+1 PRIMARY up ALL NULL NULL NULL NULL 4 100.00 Using where
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 4 100.00 Using where
Warnings:
Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
Note 1003 /* select#1 */ select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where <in_optimizer>(`test`.`up`.`a`,<exists>(/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where <cache>(`test`.`up`.`a`) = `test`.`t1`.`a`))
@@ -3101,7 +3103,7 @@ retailerID statusID changed
drop table t1;
create table t1(a int, primary key (a));
insert into t1 values (10);
-create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b));
+create table t2 (a int primary key, b varchar(32), c int, unique key cb(c, b));
insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989');
insert into t2(a, c, b) values (4,10,'360'), (5,10,'35998'), (6,10,'35999');
analyze table t1;
@@ -3114,7 +3116,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 range b b 40 NULL 3 Using where
+2 SUBQUERY t2 ref cb cb 5 const 1 Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
@@ -3126,7 +3128,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 range b b 40 NULL 3 Using index condition
+2 SUBQUERY t2 ref cb cb 5 const 1 Using index condition; Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
@@ -4437,7 +4439,7 @@ out_a MIN(b)
DROP TABLE t1;
CREATE TABLE t1 (a INT);
CREATE TABLE t2 (a INT);
-INSERT INTO t1 VALUES (1),(2);
+INSERT INTO t1 VALUES (1),(2),(3),(4);
INSERT INTO t2 VALUES (1),(2);
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
2
@@ -4446,7 +4448,7 @@ SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
EXPLAIN EXTENDED
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
@@ -4455,7 +4457,7 @@ EXPLAIN EXTENDED
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION
(SELECT 1 FROM t2 WHERE t1.a = t2.a));
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 2 100.00 Using where
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
diff --git a/mysql-test/main/subselect_no_scache.result b/mysql-test/main/subselect_no_scache.result
index 8208e7a5379..76a04aba9a3 100644
--- a/mysql-test/main/subselect_no_scache.result
+++ b/mysql-test/main/subselect_no_scache.result
@@ -1455,21 +1455,21 @@ a
4
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index
-1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 100.00 Using where
+1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 100.00 Using where
+1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index
Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t1`.`b` <> 30
select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
a
2
3
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index
-1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 100.00
-1 PRIMARY t3 index PRIMARY PRIMARY 4 NULL 3 75.00 Using where; Using index; Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 100.00 Using where
+1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index
+1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00 Using index
Warnings:
-Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where `test`.`t3`.`a` = `test`.`t1`.`b` and `test`.`t1`.`a` = `test`.`t2`.`a`
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where `test`.`t3`.`a` = `test`.`t1`.`b` and `test`.`t2`.`a` = `test`.`t1`.`a`
drop table t1, t2, t3;
create table t1 (a int, b int, index a (a,b));
create table t2 (a int, index a (a));
@@ -1509,7 +1509,7 @@ a
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
-1 PRIMARY t3 range a a 5 NULL 3 100.00 Using where; Using index
+1 PRIMARY t3 index a a 5 NULL 3 100.00 Using where; Using index
1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 100.00 Using index; FirstMatch(t2)
Warnings:
Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where `test`.`t1`.`b` = `test`.`t3`.`a` and `test`.`t1`.`a` = `test`.`t2`.`a`
@@ -1617,21 +1617,21 @@ a3 1
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
+2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
+2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
-2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
+2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
+Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
@@ -2424,16 +2424,18 @@ a
3
DROP TABLE t1;
create table t1 (a int, b int);
-insert into t1 values (1,2),(3,4);
+insert into t1 values (1,2),(3,4),(5,6),(7,8);
select * from t1 up where exists (select * from t1 where t1.a=up.a);
a b
1 2
3 4
+5 6
+7 8
explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY up ALL NULL NULL NULL NULL 2 100.00
+1 PRIMARY up ALL NULL NULL NULL NULL 4 100.00
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00
+2 MATERIALIZED t1 ALL NULL NULL NULL NULL 4 100.00
Warnings:
Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` semi join (`test`.`t1`) where 1
@@ -3106,7 +3108,7 @@ retailerID statusID changed
drop table t1;
create table t1(a int, primary key (a));
insert into t1 values (10);
-create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b));
+create table t2 (a int primary key, b varchar(32), c int, unique key cb(c, b));
insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989');
insert into t2(a, c, b) values (4,10,'360'), (5,10,'35998'), (6,10,'35999');
analyze table t1;
@@ -3119,7 +3121,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 range b b 40 NULL 3 Using where
+2 SUBQUERY t2 ref cb cb 5 const 1 Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
@@ -3131,7 +3133,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 range b b 40 NULL 3 Using index condition
+2 SUBQUERY t2 ref cb cb 5 const 1 Using index condition; Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
@@ -4444,7 +4446,7 @@ out_a MIN(b)
DROP TABLE t1;
CREATE TABLE t1 (a INT);
CREATE TABLE t2 (a INT);
-INSERT INTO t1 VALUES (1),(2);
+INSERT INTO t1 VALUES (1),(2),(3),(4);
INSERT INTO t2 VALUES (1),(2);
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
2
@@ -4453,7 +4455,7 @@ SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
EXPLAIN EXTENDED
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00
Warnings:
@@ -4463,7 +4465,7 @@ EXPLAIN EXTENDED
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION
(SELECT 1 FROM t2 WHERE t1.a = t2.a));
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 2 100.00 Using where
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
@@ -4547,15 +4549,15 @@ SET @save_join_cache_level=@@join_cache_level;
SET join_cache_level=0;
EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 GROUP BY a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary
Warnings:
Note 1003 /* select#1 */ select 1 AS `1` from <materialize> (/* select#2 */ select min(`test`.`t1`.`a`) from `test`.`t1` group by `test`.`t1`.`a`) join `test`.`t1` where `<subquery2>`.`min(a)` = 1
EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 WHERE a > 3 GROUP BY a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary
Warnings:
Note 1003 /* select#1 */ select 1 AS `1` from <materialize> (/* select#2 */ select min(`test`.`t1`.`a`) from `test`.`t1` where `test`.`t1`.`a` > 3 group by `test`.`t1`.`a`) join `test`.`t1` where `<subquery2>`.`min(a)` = 1
@@ -6086,8 +6088,7 @@ WHERE col_varchar_nokey IN
(SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY ot system NULL NULL NULL NULL 1
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED it1 ref idx_cvk_cik idx_cvk_cik 9 const,const 1 Using where; Using index
+1 PRIMARY it1 ref idx_cvk_cik idx_cvk_cik 9 const,const 1 Using where; Using index; FirstMatch(ot)
SELECT col_int_nokey FROM ot
WHERE col_varchar_nokey IN
(SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL);
@@ -6099,8 +6100,7 @@ WHERE (col_varchar_nokey, 'x') IN
(SELECT col_varchar_key, col_varchar_key2 FROM it2);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY ot system NULL NULL NULL NULL 1
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1
-2 MATERIALIZED it2 ref idx_cvk_cvk2_cik,idx_cvk_cik idx_cvk_cvk2_cik 8 const,const 1 Using where; Using index
+1 PRIMARY it2 ref idx_cvk_cvk2_cik,idx_cvk_cik idx_cvk_cvk2_cik 8 const,const 1 Using where; Using index; FirstMatch(ot)
SELECT col_int_nokey FROM ot
WHERE (col_varchar_nokey, 'x') IN
(SELECT col_varchar_key, col_varchar_key2 FROM it2);
diff --git a/mysql-test/main/subselect_no_semijoin.result b/mysql-test/main/subselect_no_semijoin.result
index e14d3d8bb73..edab14728b7 100644
--- a/mysql-test/main/subselect_no_semijoin.result
+++ b/mysql-test/main/subselect_no_semijoin.result
@@ -925,8 +925,8 @@ a t1.a in (select t2.a from t2,t3 where t3.a=t2.a)
explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
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
-2 MATERIALIZED t3 ALL NULL NULL NULL NULL 3 100.00
-2 MATERIALIZED t2 index a a 5 NULL 3 75.00 Using where; Using index; Using join buffer (flat, BNL join)
+2 MATERIALIZED t3 ALL NULL NULL NULL NULL 3 100.00 Using where
+2 MATERIALIZED t2 ref a a 5 test.t3.a 2 100.00 Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where `test`.`t2`.`a` = `test`.`t3`.`a` ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`a`)))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1`
drop table t1,t2,t3;
@@ -1463,8 +1463,8 @@ a
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index NULL PRIMARY 4 NULL 4 100.00 Using where; Using index
-2 MATERIALIZED t1 ALL PRIMARY NULL NULL NULL 4 100.00
-2 MATERIALIZED t3 index PRIMARY PRIMARY 4 NULL 3 75.00 Using where; Using index; Using join buffer (flat, BNL join)
+2 MATERIALIZED t1 ALL PRIMARY NULL NULL NULL 4 100.00 Using where
+2 MATERIALIZED t3 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00 Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t1`.`b` ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on distinct_key where `test`.`t2`.`a` = `<subquery2>`.`a`))))
drop table t1, t2, t3;
@@ -2421,15 +2421,17 @@ a
3
DROP TABLE t1;
create table t1 (a int, b int);
-insert into t1 values (1,2),(3,4);
+insert into t1 values (1,2),(3,4),(5,6),(7,8);
select * from t1 up where exists (select * from t1 where t1.a=up.a);
a b
1 2
3 4
+5 6
+7 8
explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY up ALL NULL NULL NULL NULL 2 100.00 Using where
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00
+1 PRIMARY up ALL NULL NULL NULL NULL 4 100.00 Using where
+2 MATERIALIZED t1 ALL NULL NULL NULL NULL 4 100.00
Warnings:
Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
Note 1003 /* select#1 */ select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where <expr_cache><`test`.`up`.`a`>(<in_optimizer>(`test`.`up`.`a`,`test`.`up`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where 1 ), <primary_index_lookup>(`test`.`up`.`a` in <temporary table> on distinct_key where `test`.`up`.`a` = `<subquery2>`.`a`))))
@@ -3101,7 +3103,7 @@ retailerID statusID changed
drop table t1;
create table t1(a int, primary key (a));
insert into t1 values (10);
-create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b));
+create table t2 (a int primary key, b varchar(32), c int, unique key cb(c, b));
insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989');
insert into t2(a, c, b) values (4,10,'360'), (5,10,'35998'), (6,10,'35999');
analyze table t1;
@@ -3114,7 +3116,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 range b b 40 NULL 3 Using where
+2 SUBQUERY t2 ref cb cb 5 const 1 Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
@@ -3126,7 +3128,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
-2 SUBQUERY t2 range b b 40 NULL 3 Using index condition
+2 SUBQUERY t2 ref cb cb 5 const 1 Using index condition; Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
@@ -4437,7 +4439,7 @@ out_a MIN(b)
DROP TABLE t1;
CREATE TABLE t1 (a INT);
CREATE TABLE t2 (a INT);
-INSERT INTO t1 VALUES (1),(2);
+INSERT INTO t1 VALUES (1),(2),(3),(4);
INSERT INTO t2 VALUES (1),(2);
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
2
@@ -4446,7 +4448,7 @@ SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
EXPLAIN EXTENDED
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00
Warnings:
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
@@ -4455,7 +4457,7 @@ EXPLAIN EXTENDED
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION
(SELECT 1 FROM t2 WHERE t1.a = t2.a));
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 2 100.00 Using where
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
@@ -5731,8 +5733,8 @@ SET join_cache_level=0;
EXPLAIN SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON 1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
-2 MATERIALIZED t2 index NULL PRIMARY 4 NULL 3 Using index
-2 MATERIALIZED it index PRIMARY PRIMARY 4 NULL 3 Using index
+2 DEPENDENT SUBQUERY it eq_ref PRIMARY PRIMARY 4 func 1 Using index
+2 DEPENDENT SUBQUERY t2 index NULL PRIMARY 4 NULL 3 Using index
SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON 1);
pk i
11 0
diff --git a/mysql-test/main/subselect_sj.result b/mysql-test/main/subselect_sj.result
index 8078700bf5b..fa892e4d967 100644
--- a/mysql-test/main/subselect_sj.result
+++ b/mysql-test/main/subselect_sj.result
@@ -205,10 +205,10 @@ a b a b
insert into t1 select (A.a + 10 * B.a),1 from t0 A, t0 B;
explain extended select * from t1 where a in (select pk from t10 where pk<3);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t10 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where; Using index
-1 PRIMARY t1 ALL NULL NULL NULL NULL 103 100.00 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL NULL NULL NULL NULL 103 100.00 Using where
+1 PRIMARY t10 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index
Warnings:
-Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t10` join `test`.`t1` where `test`.`t1`.`a` = `test`.`t10`.`pk` and `test`.`t10`.`pk` < 3
+Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t10` join `test`.`t1` where `test`.`t10`.`pk` = `test`.`t1`.`a` and `test`.`t1`.`a` < 3
drop table t0, t1, t2;
drop table t10, t11, t12;
@@ -344,8 +344,8 @@ WHERE PNUM IN
(SELECT PNUM FROM PROJ));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY STAFF ALL NULL NULL NULL NULL 5
-1 PRIMARY PROJ ALL NULL NULL NULL NULL 6 Start temporary
-1 PRIMARY WORKS ALL NULL NULL NULL NULL 12 Using where; End temporary
+1 PRIMARY PROJ ALL NULL NULL NULL NULL 6
+1 PRIMARY WORKS ALL NULL NULL NULL NULL 12 Using where; FirstMatch(STAFF)
SELECT EMPNUM, EMPNAME
FROM STAFF
WHERE EMPNUM IN
@@ -763,16 +763,16 @@ explain extended
select a from t1
where a in (select c from t2 where d >= some(select e from t3 where b=e));
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t2 ALL NULL NULL NULL NULL 6 100.00 Start temporary
-1 PRIMARY t1 ALL NULL NULL NULL NULL 7 100.00 Using where; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL NULL NULL NULL NULL 7 100.00
+1 PRIMARY t2 ALL NULL NULL NULL NULL 6 100.00 Using where; FirstMatch(t1)
3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
Warnings:
Note 1276 Field or reference 'test.t1.b' of SELECT #3 was resolved in SELECT #1
-Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t1`.`a` = `test`.`t2`.`c` and <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t2`.`d`,<exists>(/* select#3 */ select `test`.`t3`.`e` from `test`.`t3` where `test`.`t1`.`b` = `test`.`t3`.`e` and <cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`))))
+Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`c` = `test`.`t1`.`a` and <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t2`.`d`,<exists>(/* select#3 */ select `test`.`t3`.`e` from `test`.`t3` where `test`.`t1`.`b` = `test`.`t3`.`e` and <cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`))))
show warnings;
Level Code Message
Note 1276 Field or reference 'test.t1.b' of SELECT #3 was resolved in SELECT #1
-Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t1`.`a` = `test`.`t2`.`c` and <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t2`.`d`,<exists>(/* select#3 */ select `test`.`t3`.`e` from `test`.`t3` where `test`.`t1`.`b` = `test`.`t3`.`e` and <cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`))))
+Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`c` = `test`.`t1`.`a` and <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t2`.`d`,<exists>(/* select#3 */ select `test`.`t3`.`e` from `test`.`t3` where `test`.`t1`.`b` = `test`.`t3`.`e` and <cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`))))
select a from t1
where a in (select c from t2 where d >= some(select e from t3 where b=e));
a
@@ -802,6 +802,7 @@ PRIMARY KEY (pk)
INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo','ffff','ffff','ffff','ffff','ffff','ffff',GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))')), (2,'f','ffff','ffff','ffff', 'ffff','ffff','ffff','ffff','ffff','ffff',GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))'));
CREATE TABLE t2 LIKE t1;
INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii','iiii','ffff','ffff','ffff','ffff','ffff',GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))')), (2,'f','ffff','ffff','ffff','ffff','ffff','ffff','ffff','ffff','ffff',GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))'));
+insert into t2 (pk) values (-1),(0);
EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (a, b) IN (SELECT a, b FROM t2 WHERE pk > 0);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
@@ -1249,8 +1250,8 @@ INSERT INTO t2 VALUES (1, 0), (1, 1), (2, 0), (2, 1);
EXPLAIN
SELECT * FROM t1 WHERE (i) IN (SELECT i FROM t2 where j > 0);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 5
-1 PRIMARY t2 index k k 10 NULL 4 Using where; Using index; Start temporary; End temporary
+1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where
+1 PRIMARY t2 ref k k 5 test.t1.i 1 Using where; Using index; Start temporary; End temporary
SELECT * FROM t1 WHERE (i) IN (SELECT i FROM t2 where j > 0);
i
1
@@ -1612,7 +1613,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY A index PRIMARY PRIMARY 4 NULL 3 Using index
1 PRIMARY C eq_ref PRIMARY PRIMARY 4 test.A.t1field 1 Using index
1 PRIMARY D eq_ref PRIMARY PRIMARY 4 test.A.t1field 1 Using index
-1 PRIMARY B index NULL PRIMARY 4 NULL 3 Using index; Start temporary; End temporary
+1 PRIMARY B index NULL PRIMARY 4 NULL 3 Using index; FirstMatch(D)
SELECT * FROM t1 A
WHERE
A.t1field IN (SELECT A.t1field FROM t2 B) AND
@@ -1639,8 +1640,8 @@ select * from t1 A, t1 B
where A.a = B.a and A.a in (select a from t2 C) and B.a in (select a from t2 D);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY A ALL NULL NULL NULL NULL 3
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
1 PRIMARY B ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1
2 MATERIALIZED C ALL NULL NULL NULL NULL 3
3 MATERIALIZED D ALL NULL NULL NULL NULL 3
@@ -1980,7 +1981,7 @@ f1 f3 f4 f2 f4
DROP TABLE t1,t2,t3;
#
# BUG#803457: Wrong result with semijoin + view + outer join in maria-5.3-subqueries-mwl90
-# (Original testcase)
+# (Original, slightly modified testcase)
#
CREATE TABLE t1 (f1 int, f2 int );
INSERT INTO t1 VALUES (2,0),(4,0),(0,NULL);
@@ -1990,24 +1991,23 @@ CREATE TABLE t3 ( f1 int, f3 int );
INSERT INTO t3 VALUES (2,0),(4,0),(0,NULL),(4,0),(8,0);
CREATE TABLE t4 ( f2 int, KEY (f2) );
INSERT INTO t4 VALUES (0),(NULL);
-CREATE VIEW v4 AS SELECT DISTINCT f2 FROM t4 ;
+INSERT INTO t4 VALUES (0),(NULL),(-1),(-2),(-3);
# The following must not have outer joins:
explain extended
-SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4);
+SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4 where f2 = 0 or f2 IS NULL);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 PRIMARY t3 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (flat, BNL join)
-2 MATERIALIZED t4 index f2 f2 5 NULL 2 100.00 Using index
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
+2 MATERIALIZED t4 ref_or_null f2 f2 5 const 4 100.00 Using where; Using index
Warnings:
-Note 1003 select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3`,`test`.`t3`.`f3` AS `f3` from `test`.`t1` semi join (`test`.`t4`) join `test`.`t2` join `test`.`t3` where `test`.`t3`.`f1` = `test`.`t1`.`f1` and `test`.`t1`.`f2` = `test`.`t2`.`f2`
-SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4);
+Note 1003 select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3`,`test`.`t3`.`f3` AS `f3` from `test`.`t1` semi join (`test`.`t4`) join `test`.`t2` join `test`.`t3` where `test`.`t3`.`f1` = `test`.`t1`.`f1` and `test`.`t1`.`f2` = `test`.`t2`.`f2` and (`test`.`t4`.`f2` = 0 or `test`.`t4`.`f2` is null)
+SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4 where f2 = 0 or f2 IS NULL);
f1 f2 f3 f3
2 0 0 0
4 0 0 0
4 0 0 0
-drop view v4;
drop table t1, t2, t3, t4;
#
# BUG#803303: Wrong result with semijoin=on, outer join in maria-5.3-subqueries-mwl90
@@ -2090,9 +2090,9 @@ explain
SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE IFNULL(t2.f3,'foo') IN (SELECT * FROM t4);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
+1 PRIMARY t4 ALL NULL NULL NULL NULL 2 Start temporary
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
-1 PRIMARY t3 ALL NULL NULL NULL NULL 5 Using where
-1 PRIMARY t4 ALL NULL NULL NULL NULL 2 Using where; Start temporary; End temporary
+1 PRIMARY t3 ALL NULL NULL NULL NULL 5 Using where; End temporary
SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3 ) WHERE IFNULL(t2.f3,'foo') IN (SELECT * FROM t4);
f1 f2 f3 f3
2 0 0 0
@@ -2153,8 +2153,8 @@ INSERT INTO t3 VALUES (6,5),(6,2),(8,0),(9,1),(6,5);
explain
SELECT * FROM t1, t2 WHERE (t2.a , t1.b) IN (SELECT a, b FROM t3);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2
-1 PRIMARY t3 ALL b NULL NULL NULL 5 Using where; Start temporary
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
+1 PRIMARY t3 ref b b 5 test.t1.b 2 Start temporary
1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 2 Using where; Using index; End temporary; Using join buffer (flat, BNL join)
SELECT * FROM t1, t2 WHERE (t2.a , t1.b) IN (SELECT a, b FROM t3);
b a
@@ -2178,10 +2178,10 @@ INSERT INTO t5 VALUES (7,0),(9,0);
explain
SELECT * FROM t3 WHERE t3.a IN (SELECT t5.a FROM t2, t4, t5 WHERE t2.c = t5.a AND t2.b = t5.b);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t5 index a a 10 NULL 2 Using where; Using index; Start temporary
+1 PRIMARY t5 index a a 10 NULL 2 Using where; Using index; LooseScan
1 PRIMARY t2 ref b b 5 test.t5.b 2 Using where
-1 PRIMARY t4 ALL NULL NULL NULL NULL 3
-1 PRIMARY t3 ALL NULL NULL NULL NULL 15 Using where; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t4 ALL NULL NULL NULL NULL 3 FirstMatch(t5)
+1 PRIMARY t3 ALL NULL NULL NULL NULL 15 Using where; Using join buffer (flat, BNL join)
SELECT * FROM t3 WHERE t3.a IN (SELECT t5.a FROM t2, t4, t5 WHERE t2.c = t5.a AND t2.b = t5.b);
a
0
@@ -2350,8 +2350,8 @@ SELECT * FROM t1 WHERE (a) IN (SELECT a FROM t2 JOIN t3 ON b = a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 9
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t3 ALL NULL NULL NULL NULL 13
-2 MATERIALIZED t2 index b b 8 NULL 7 Using where; Using index
+2 MATERIALIZED t3 ALL NULL NULL NULL NULL 13 Using where
+2 MATERIALIZED t2 ref b b 4 test.t3.a 1 Using index
SELECT * FROM t1 WHERE (a) IN (SELECT a FROM t2 JOIN t3 ON b = a);
a
19
@@ -2499,10 +2499,9 @@ SELECT * FROM t1, t2
WHERE t1.a = t2.a AND t2.a IN (SELECT b FROM t3 STRAIGHT_JOIN t4);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 system NULL NULL NULL NULL 1
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 1
-1 PRIMARY t1 ref a a 5 const 1 Using index
-1 PRIMARY t2 ref a a 5 func 1 Using index
-2 MATERIALIZED t4 ALL NULL NULL NULL NULL 0
+1 PRIMARY t2 ref a a 5 const 1 Using index
+1 PRIMARY t4 ALL NULL NULL NULL NULL 0 FirstMatch(t2); Using join buffer (flat, BNL join)
+1 PRIMARY t1 ref a a 5 func 1 Using index
SELECT * FROM t1, t2
WHERE t1.a = t2.a AND t2.a IN (SELECT b FROM t3 STRAIGHT_JOIN t4);
a a
@@ -2574,33 +2573,33 @@ SELECT a, b, d FROM t1, t2
WHERE ( b, d ) IN
( SELECT b, d FROM t1, t2 WHERE b = c );
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 ALL NULL NULL NULL NULL 7
-1 PRIMARY t1 index b b 5 NULL 10 Using where; Using index; LooseScan
-1 PRIMARY t2 ref c c 5 test.t1.b 1 Using where; FirstMatch(t1)
+1 PRIMARY t1 index b b 5 NULL 10 Using where; Using index; Start temporary
+1 PRIMARY t2 ref c c 5 test.t1.b 1
1 PRIMARY t1 ref b b 5 test.t1.b 2
+1 PRIMARY t2 ALL NULL NULL NULL NULL 7 Using where; End temporary; Using join buffer (flat, BNL join)
SELECT a, b, d FROM t1, t2
WHERE ( b, d ) IN
( SELECT b, d FROM t1, t2 WHERE b = c );
a b d
-2 1 2
-7 1 2
-8 4 2
1 2 1
-4 2 1
+1 2 1
10 2 1
+10 2 1
+2 1 2
+2 1 2
3 3 3
+3 3 3
+4 2 1
+4 2 1
+5 5 5
6 3 3
-9 3 3
-2 1 2
+6 3 3
+7 1 2
7 1 2
8 4 2
-5 5 5
-3 3 3
-6 3 3
+8 4 2
+9 3 3
9 3 3
-1 2 1
-4 2 1
-10 2 1
DROP TABLE t1, t2;
# Another testcase for the above that still uses LooseScan:
create table t0(a int primary key);
@@ -2768,22 +2767,22 @@ SELECT * FROM t1 AS t1_1, t1 AS t1_2
WHERE (t1_1.a, t1_2.a) IN ( SELECT a, b FROM v1 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1_1 ALL NULL NULL NULL NULL 11 Using where
-1 PRIMARY t1_2 ALL NULL NULL NULL NULL 11
-1 PRIMARY <derived3> ref key0 key0 5 test.t1_1.a 2 Using where; FirstMatch(t1_2)
+1 PRIMARY <derived3> ref key0 key0 5 test.t1_1.a 2 Start temporary
+1 PRIMARY t1_2 ALL NULL NULL NULL NULL 11 Using where; End temporary
3 DERIVED t1 ALL NULL NULL NULL NULL 11
SELECT * FROM t1 AS t1_1, t1 AS t1_2
WHERE (t1_1.a, t1_2.a) IN ( SELECT a, b FROM v1 );
a b a b
-3 1 9 1
-5 8 4 0
-3 9 9 1
2 4 4 0
2 4 6 8
2 6 4 0
2 6 6 8
+3 1 9 1
+3 9 9 1
5 4 4 0
-7 7 7 7
5 4 4 0
+5 8 4 0
+7 7 7 7
DROP VIEW v1;
DROP TABLE t1;
set @@join_cache_level= @tmp_jcl_978479;
@@ -2927,9 +2926,9 @@ alias2.col_int_key = alias1.col_int_key
WHERE alias1.pk = 58 OR alias1.col_varchar_key = 'o'
);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY alias1 index_merge PRIMARY,col_int_key,col_varchar_key PRIMARY,col_varchar_key 4,4 NULL 2 Using sort_union(PRIMARY,col_varchar_key); Using where; Start temporary
-1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
-1 PRIMARY alias2 ALL col_int_key NULL NULL NULL 12 Range checked for each record (index map: 0x2); End temporary
+1 PRIMARY t2 ALL NULL NULL NULL NULL 2
+1 PRIMARY alias1 index_merge PRIMARY,col_int_key,col_varchar_key PRIMARY,col_varchar_key 4,4 NULL 2 Using sort_union(PRIMARY,col_varchar_key); Using where
+1 PRIMARY alias2 ALL col_int_key NULL NULL NULL 12 Range checked for each record (index map: 0x2); FirstMatch(t2)
SELECT *
FROM t2
WHERE (field1) IN (SELECT alias1.col_varchar_nokey AS field1
@@ -3289,8 +3288,7 @@ explain extended
SELECT Id FROM t1 WHERE Id in (SELECT t1_Id FROM t2 WHERE t2.col1 IS NULL);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 100.00
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t2 ref col1 col1 5 const 2 100.00 Using index condition; Using where
+1 PRIMARY t2 ALL col1 NULL NULL NULL 2 100.00 Using where; FirstMatch(t1)
Warnings:
Note 1003 select 1 AS `Id` from (`test`.`t2`) where `test`.`t2`.`t1_Id` = 1 and `test`.`t2`.`col1` is null
DROP TABLE t1, t2;
diff --git a/mysql-test/main/subselect_sj.test b/mysql-test/main/subselect_sj.test
index e4d02ed666c..377f2344819 100644
--- a/mysql-test/main/subselect_sj.test
+++ b/mysql-test/main/subselect_sj.test
@@ -739,6 +739,7 @@ INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo','ffff','ffff','ffff','ffff','f
CREATE TABLE t2 LIKE t1;
INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii','iiii','ffff','ffff','ffff','ffff','ffff',GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))')), (2,'f','ffff','ffff','ffff','ffff','ffff','ffff','ffff','ffff','ffff',GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))'));
+insert into t2 (pk) values (-1),(0);
# Test that materialization is skipped for semijoins where materialized
# table would contain GEOMETRY or different kinds of BLOB/TEXT columns
@@ -1739,7 +1740,7 @@ DROP TABLE t1,t2,t3;
--echo #
--echo # BUG#803457: Wrong result with semijoin + view + outer join in maria-5.3-subqueries-mwl90
---echo # (Original testcase)
+--echo # (Original, slightly modified testcase)
--echo #
CREATE TABLE t1 (f1 int, f2 int );
@@ -1753,15 +1754,13 @@ INSERT INTO t3 VALUES (2,0),(4,0),(0,NULL),(4,0),(8,0);
CREATE TABLE t4 ( f2 int, KEY (f2) );
INSERT INTO t4 VALUES (0),(NULL);
-
-CREATE VIEW v4 AS SELECT DISTINCT f2 FROM t4 ;
+INSERT INTO t4 VALUES (0),(NULL),(-1),(-2),(-3);
--echo # The following must not have outer joins:
explain extended
-SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4);
-SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4);
+SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4 where f2 = 0 or f2 IS NULL);
+SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4 where f2 = 0 or f2 IS NULL);
-drop view v4;
drop table t1, t2, t3, t4;
--echo #
@@ -2249,6 +2248,7 @@ INSERT INTO t1 VALUES
CREATE TABLE t2 ( a INT, b INT, KEY(a)) ENGINE=MyISAM;
INSERT INTO t2 VALUES (3,20),(2,21),(3,22);
+--sorted_result
SELECT *
FROM t1 AS alias1, t1 AS alias2
WHERE ( alias1.c, alias2.c )
@@ -2299,6 +2299,7 @@ explain
SELECT a, b, d FROM t1, t2
WHERE ( b, d ) IN
( SELECT b, d FROM t1, t2 WHERE b = c );
+--sorted_result
SELECT a, b, d FROM t1, t2
WHERE ( b, d ) IN
( SELECT b, d FROM t1, t2 WHERE b = c );
@@ -2449,6 +2450,7 @@ EXPLAIN
SELECT * FROM t1 AS t1_1, t1 AS t1_2
WHERE (t1_1.a, t1_2.a) IN ( SELECT a, b FROM v1 );
+--sorted_result
SELECT * FROM t1 AS t1_1, t1 AS t1_2
WHERE (t1_1.a, t1_2.a) IN ( SELECT a, b FROM v1 );
diff --git a/mysql-test/main/subselect_sj2.result b/mysql-test/main/subselect_sj2.result
index f81540716d1..8bb05873853 100644
--- a/mysql-test/main/subselect_sj2.result
+++ b/mysql-test/main/subselect_sj2.result
@@ -54,9 +54,9 @@ a b
19 14
explain select * from t2 where b in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 ALL b NULL NULL NULL 20
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3
+1 PRIMARY t2 ref b b 5 test.t1.a 2
+2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 Using where
select * from t2 where b in (select a from t1);
a b
1 1
@@ -82,9 +82,9 @@ test.t3 analyze status Engine-independent statistics collected
test.t3 analyze status OK
explain select * from t3 where b in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t3 ALL b NULL NULL NULL 20
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3
+1 PRIMARY t3 ref b b 5 test.t1.a 2
+2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 Using where
select * from t3 where b in (select a from t1);
a b pk1 pk2 pk3
1 1 1 1 1
@@ -307,7 +307,7 @@ from t0 where a in
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t0 ALL NULL NULL NULL NULL 10
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func 1 Using where
-2 MATERIALIZED t1 range a a 5 NULL 10 Using where; Using index
+2 MATERIALIZED t1 index a a 5 NULL 10 Using where; Using index
2 MATERIALIZED t2 ref a a 5 test.t1.a 1 Using index
2 MATERIALIZED t3 ref a a 5 test.t1.a 1 Using index
drop table t0, t1,t2,t3;
@@ -743,9 +743,8 @@ alter table t3 add primary key(id), add key(a);
The following must use loose index scan over t3, key a:
explain select count(a) from t2 where a in ( SELECT a FROM t3);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 index a a 5 NULL 1000 Using index
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t3 index a a 5 NULL 30000 Using index
+1 PRIMARY t2 index a a 5 NULL 1000 Using where; Using index
+1 PRIMARY t3 ref a a 5 test.t2.a 30 Using index; FirstMatch(t2)
select count(a) from t2 where a in ( SELECT a FROM t3);
count(a)
1000
@@ -773,8 +772,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where
1 PRIMARY t2 ALL NULL NULL NULL NULL 1
1 PRIMARY t3 ALL NULL NULL NULL NULL 2 FirstMatch(t2)
-1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1 Using where
-3 MATERIALIZED t2 ALL NULL NULL NULL NULL 1
+1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where; FirstMatch(t3)
select 1 from t2 where
c2 in (select 1 from t3, t2) and
c1 in (select convert(c6,char(1)) from t2);
@@ -843,9 +841,9 @@ SELECT * FROM t3
WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY alias1 const PRIMARY PRIMARY 4 const # Using index
-1 PRIMARY alias2 index f12 f12 7 NULL # Using index; Start temporary
-1 PRIMARY t1 index NULL PRIMARY 4 NULL # Using index
-1 PRIMARY t3 ALL NULL NULL NULL NULL # Using where; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY alias2 index f12 f12 7 NULL # Using index; LooseScan
+1 PRIMARY t1 index NULL PRIMARY 4 NULL # Using index; FirstMatch(alias2)
+1 PRIMARY t3 ALL NULL NULL NULL NULL # Using where; Using join buffer (flat, BNL join)
SELECT * FROM t3
WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24);
f12
@@ -914,9 +912,9 @@ SELECT * FROM t3 LEFT JOIN (v1,t2) ON t3.a = t2.a
WHERE t3.b IN (SELECT b FROM t4);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 1
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 2
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
2 MATERIALIZED t4 ALL NULL NULL NULL NULL 2
3 DERIVED t1 ALL NULL NULL NULL NULL 1
SELECT * FROM t3 LEFT JOIN (v1,t2) ON t3.a = t2.a
@@ -973,10 +971,9 @@ SELECT d FROM t2, t1
WHERE a = d AND ( pk < 2 OR d = 'z' )
);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2
+1 PRIMARY t2 index PRIMARY,d d 9 NULL 17 Using where; Using index; LooseScan
+1 PRIMARY t1 ref a a 5 test.t2.d 1 Using where; Using index; FirstMatch(t2)
1 PRIMARY t1 ref b b 4 test.t2.d 1
-2 MATERIALIZED t2 index_merge PRIMARY,d d,PRIMARY 4,4 NULL 2 Using sort_union(d,PRIMARY); Using where
-2 MATERIALIZED t1 ref a a 5 test.t2.d 1 Using where; Using index
SELECT * FROM t1 WHERE b IN (
SELECT d FROM t2, t1
WHERE a = d AND ( pk < 2 OR d = 'z' )
@@ -1228,9 +1225,9 @@ explain
SELECT * FROM t1, t3 WHERE t3_c IN ( SELECT t1_pk2 FROM t4, t2 WHERE t2_c = t1_pk2 AND t2_i >= t3_i ) AND ( t1_pk1 = 'POL' );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ref PRIMARY PRIMARY 5 const 1 Using where; Using index
-1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Start temporary
-1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
-1 PRIMARY t4 index NULL PRIMARY 59 NULL 2 Using where; Using index; End temporary
+1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
+1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where
+1 PRIMARY t4 index NULL PRIMARY 59 NULL 2 Using where; Using index; FirstMatch(t3)
DROP TABLE t1,t2,t3,t4;
#
# MDEV-6263: Wrong result when using IN subquery with order by
diff --git a/mysql-test/main/subselect_sj2.test b/mysql-test/main/subselect_sj2.test
index 6c936559ce6..4c95c977371 100644
--- a/mysql-test/main/subselect_sj2.test
+++ b/mysql-test/main/subselect_sj2.test
@@ -1312,8 +1312,6 @@ SELECT * FROM t1 WHERE 9 IN ( SELECT b FROM t2 WHERE 1 IN ( SELECT MIN(c) FROM t
DROP TABLE t1,t2,t3;
---source include/have_innodb.inc
-
--disable_warnings
DROP TABLE IF EXISTS t1,t2,t3,t4;
--enable_warnings
diff --git a/mysql-test/main/subselect_sj2_jcl6.result b/mysql-test/main/subselect_sj2_jcl6.result
index 10cfc2e2546..95b02d1a23a 100644
--- a/mysql-test/main/subselect_sj2_jcl6.result
+++ b/mysql-test/main/subselect_sj2_jcl6.result
@@ -66,8 +66,7 @@ a b
explain select * from t2 where b in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL b NULL NULL NULL 20
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3
+1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t2); Using join buffer (flat, BNL join)
select * from t2 where b in (select a from t1);
a b
1 1
@@ -93,9 +92,9 @@ test.t3 analyze status Engine-independent statistics collected
test.t3 analyze status OK
explain select * from t3 where b in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t3 ALL b NULL NULL NULL 20
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3
+1 PRIMARY t3 ref b b 5 test.t1.a 2 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
+2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 Using where
select * from t3 where b in (select a from t1);
a b pk1 pk2 pk3
1 1 1 1 1
@@ -318,7 +317,7 @@ from t0 where a in
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t0 ALL NULL NULL NULL NULL 10
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func 1 Using where
-2 MATERIALIZED t1 range a a 5 NULL 10 Using where; Using index
+2 MATERIALIZED t1 index a a 5 NULL 10 Using where; Using index
2 MATERIALIZED t2 ref a a 5 test.t1.a 1 Using index
2 MATERIALIZED t3 ref a a 5 test.t1.a 1 Using index
drop table t0, t1,t2,t3;
@@ -756,9 +755,8 @@ alter table t3 add primary key(id), add key(a);
The following must use loose index scan over t3, key a:
explain select count(a) from t2 where a in ( SELECT a FROM t3);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 index a a 5 NULL 1000 Using index
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t3 index a a 5 NULL 30000 Using index
+1 PRIMARY t2 index a a 5 NULL 1000 Using where; Using index
+1 PRIMARY t3 ref a a 5 test.t2.a 30 Using index; FirstMatch(t2)
select count(a) from t2 where a in ( SELECT a FROM t3);
count(a)
1000
@@ -786,8 +784,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using join buffer (flat, BNL join)
1 PRIMARY t3 ALL NULL NULL NULL NULL 2 FirstMatch(t2); Using join buffer (incremental, BNL join)
-1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1 Using where
-3 MATERIALIZED t2 ALL NULL NULL NULL NULL 1
+1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where; FirstMatch(t3); Using join buffer (incremental, BNL join)
select 1 from t2 where
c2 in (select 1 from t3, t2) and
c1 in (select convert(c6,char(1)) from t2);
@@ -986,10 +983,9 @@ SELECT d FROM t2, t1
WHERE a = d AND ( pk < 2 OR d = 'z' )
);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2
+1 PRIMARY t2 index PRIMARY,d d 9 NULL 17 Using where; Using index; LooseScan
+1 PRIMARY t1 ref a a 5 test.t2.d 1 Using where; Using index; FirstMatch(t2)
1 PRIMARY t1 ref b b 4 test.t2.d 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
-2 MATERIALIZED t2 index_merge PRIMARY,d d,PRIMARY 4,4 NULL 2 Using sort_union(d,PRIMARY); Using where
-2 MATERIALIZED t1 ref a a 5 test.t2.d 1 Using where; Using index
SELECT * FROM t1 WHERE b IN (
SELECT d FROM t2, t1
WHERE a = d AND ( pk < 2 OR d = 'z' )
@@ -1442,10 +1438,9 @@ SELECT t3.* FROM t1 JOIN t3 ON t3.b = t1.b
WHERE c IN (SELECT t4.b FROM t4 JOIN t2);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 1 Using where
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using join buffer (flat, BNL join)
+1 PRIMARY t4 ALL NULL NULL NULL NULL 2 Using where; FirstMatch(t3); Using join buffer (incremental, BNL join)
1 PRIMARY t1 ref b b 4 test.t3.b 1 Using index
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 1
-2 MATERIALIZED t4 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
SELECT t3.* FROM t1 JOIN t3 ON t3.b = t1.b
WHERE c IN (SELECT t4.b FROM t4 JOIN t2);
b c
@@ -1463,7 +1458,7 @@ INSERT INTO t2 VALUES (8);
CREATE TABLE t3 (pk int PRIMARY KEY, a int);
INSERT INTO t3 VALUES (1, 6), (2, 8);
CREATE TABLE t4 (b int) ENGINE=InnoDB;
-INSERT INTO t4 VALUES (2);
+INSERT INTO t4 VALUES (2),(88),(99);
set @tmp_optimizer_switch=@@optimizer_switch;
SET optimizer_switch = 'semijoin_with_cache=on';
SET join_cache_level = 2;
@@ -1471,10 +1466,10 @@ EXPLAIN
SELECT * FROM t1, t2 WHERE b IN (SELECT a FROM t3, t4 WHERE b = pk);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 1
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
-2 MATERIALIZED t4 ALL NULL NULL NULL NULL 1 Using where
-2 MATERIALIZED t3 eq_ref PRIMARY PRIMARY 4 test.t4.b 1
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
+2 MATERIALIZED t4 ALL NULL NULL NULL NULL 3
+2 MATERIALIZED t3 ALL PRIMARY NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
SELECT * FROM t1, t2 WHERE b IN (SELECT a FROM t3, t4 WHERE b = pk);
pk a b
1 6 8
@@ -1496,8 +1491,7 @@ EXPLAIN
SELECT * FROM t1 WHERE b IN (SELECT a FROM t2 GROUP BY a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 1
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 1
+1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
SELECT * FROM t1 WHERE b IN (SELECT a FROM t2 GROUP BY a);
a b
v v
diff --git a/mysql-test/main/subselect_sj2_jcl6.test b/mysql-test/main/subselect_sj2_jcl6.test
index a0c8a6c0f04..ea3f07b289a 100644
--- a/mysql-test/main/subselect_sj2_jcl6.test
+++ b/mysql-test/main/subselect_sj2_jcl6.test
@@ -66,7 +66,7 @@ INSERT INTO t2 VALUES (8);
CREATE TABLE t3 (pk int PRIMARY KEY, a int);
INSERT INTO t3 VALUES (1, 6), (2, 8);
CREATE TABLE t4 (b int) ENGINE=InnoDB;
-INSERT INTO t4 VALUES (2);
+INSERT INTO t4 VALUES (2),(88),(99);
set @tmp_optimizer_switch=@@optimizer_switch;
diff --git a/mysql-test/main/subselect_sj2_mat.result b/mysql-test/main/subselect_sj2_mat.result
index 4b269619102..5d4543d673f 100644
--- a/mysql-test/main/subselect_sj2_mat.result
+++ b/mysql-test/main/subselect_sj2_mat.result
@@ -56,9 +56,9 @@ a b
19 14
explain select * from t2 where b in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 ALL b NULL NULL NULL 20
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3
+1 PRIMARY t2 ref b b 5 test.t1.a 2
+2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 Using where
select * from t2 where b in (select a from t1);
a b
1 1
@@ -84,9 +84,9 @@ test.t3 analyze status Engine-independent statistics collected
test.t3 analyze status OK
explain select * from t3 where b in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t3 ALL b NULL NULL NULL 20
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3
+1 PRIMARY t3 ref b b 5 test.t1.a 2
+2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 Using where
select * from t3 where b in (select a from t1);
a b pk1 pk2 pk3
1 1 1 1 1
@@ -309,7 +309,7 @@ from t0 where a in
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t0 ALL NULL NULL NULL NULL 10
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func 1 Using where
-2 MATERIALIZED t1 range a a 5 NULL 10 Using where; Using index
+2 MATERIALIZED t1 index a a 5 NULL 10 Using where; Using index
2 MATERIALIZED t2 ref a a 5 test.t1.a 1 Using index
2 MATERIALIZED t3 ref a a 5 test.t1.a 1 Using index
drop table t0, t1,t2,t3;
@@ -745,9 +745,8 @@ alter table t3 add primary key(id), add key(a);
The following must use loose index scan over t3, key a:
explain select count(a) from t2 where a in ( SELECT a FROM t3);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 index a a 5 NULL 1000 Using index
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t3 index a a 5 NULL 30000 Using index
+1 PRIMARY t2 index a a 5 NULL 1000 Using where; Using index
+1 PRIMARY t3 ref a a 5 test.t2.a 30 Using index; FirstMatch(t2)
select count(a) from t2 where a in ( SELECT a FROM t3);
count(a)
1000
@@ -775,8 +774,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where
1 PRIMARY t2 ALL NULL NULL NULL NULL 1
1 PRIMARY t3 ALL NULL NULL NULL NULL 2 FirstMatch(t2)
-1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1 Using where
-3 MATERIALIZED t2 ALL NULL NULL NULL NULL 1
+1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where; FirstMatch(t3)
select 1 from t2 where
c2 in (select 1 from t3, t2) and
c1 in (select convert(c6,char(1)) from t2);
@@ -845,9 +843,9 @@ SELECT * FROM t3
WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY alias1 const PRIMARY PRIMARY 4 const # Using index
-1 PRIMARY alias2 index f12 f12 7 NULL # Using index; Start temporary
-1 PRIMARY t1 index NULL PRIMARY 4 NULL # Using index
-1 PRIMARY t3 ALL NULL NULL NULL NULL # Using where; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY alias2 index f12 f12 7 NULL # Using index; LooseScan
+1 PRIMARY t1 index NULL PRIMARY 4 NULL # Using index; FirstMatch(alias2)
+1 PRIMARY t3 ALL NULL NULL NULL NULL # Using where; Using join buffer (flat, BNL join)
SELECT * FROM t3
WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24);
f12
@@ -916,9 +914,9 @@ SELECT * FROM t3 LEFT JOIN (v1,t2) ON t3.a = t2.a
WHERE t3.b IN (SELECT b FROM t4);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 1
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 2
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
2 MATERIALIZED t4 ALL NULL NULL NULL NULL 2
3 DERIVED t1 ALL NULL NULL NULL NULL 1
SELECT * FROM t3 LEFT JOIN (v1,t2) ON t3.a = t2.a
@@ -975,10 +973,9 @@ SELECT d FROM t2, t1
WHERE a = d AND ( pk < 2 OR d = 'z' )
);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2
+1 PRIMARY t2 index PRIMARY,d d 9 NULL 17 Using where; Using index; LooseScan
+1 PRIMARY t1 ref a a 5 test.t2.d 1 Using where; Using index; FirstMatch(t2)
1 PRIMARY t1 ref b b 4 test.t2.d 1
-2 MATERIALIZED t2 index_merge PRIMARY,d d,PRIMARY 4,4 NULL 2 Using sort_union(d,PRIMARY); Using where
-2 MATERIALIZED t1 ref a a 5 test.t2.d 1 Using where; Using index
SELECT * FROM t1 WHERE b IN (
SELECT d FROM t2, t1
WHERE a = d AND ( pk < 2 OR d = 'z' )
@@ -1230,9 +1227,9 @@ explain
SELECT * FROM t1, t3 WHERE t3_c IN ( SELECT t1_pk2 FROM t4, t2 WHERE t2_c = t1_pk2 AND t2_i >= t3_i ) AND ( t1_pk1 = 'POL' );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ref PRIMARY PRIMARY 5 const 1 Using where; Using index
-1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Start temporary
-1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
-1 PRIMARY t4 index NULL PRIMARY 59 NULL 2 Using where; Using index; End temporary
+1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
+1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where
+1 PRIMARY t4 index NULL PRIMARY 59 NULL 2 Using where; Using index; FirstMatch(t3)
DROP TABLE t1,t2,t3,t4;
#
# MDEV-6263: Wrong result when using IN subquery with order by
@@ -1529,8 +1526,7 @@ t3.sack_id = 33479 AND t3.kit_id = 6;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 ref PRIMARY PRIMARY 5 const,const 5 Using index
1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t3.cat_id 1 Using index
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 Using where
-2 MATERIALIZED t2 index cat_id cat_id 4 NULL 19 Using index
+1 PRIMARY t2 ref cat_id cat_id 4 test.t3.cat_id 2 Using where; Using index; FirstMatch(t1)
SELECT count(*) FROM t1, t3
WHERE t1.cat_id = t3.cat_id AND
t3.cat_id IN (SELECT cat_id FROM t2) AND
@@ -1741,7 +1737,7 @@ WHERE f1 IN ( SELECT f2 FROM t2 WHERE f2 > 'bar' )
HAVING f1 != 'foo'
ORDER BY f1;
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 range f1 f1 11 NULL 2 Using where; Using index
+1 PRIMARY t1 index f1 f1 11 NULL 2 Using where; Using index
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 11 func 1
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where
DROP TABLE t1,t2;
@@ -1945,20 +1941,20 @@ AND t3.id_product IN (SELECT id_product FROM t2 t2_3 WHERE t2_3.id_t2 = 18 OR t2
AND t3.id_product IN (SELECT id_product FROM t2 t2_4 WHERE t2_4.id_t2 = 34 OR t2_4.id_t2 = 23)
AND t3.id_product IN (SELECT id_product FROM t2 t2_5 WHERE t2_5.id_t2 = 29 OR t2_5.id_t2 = 28 OR t2_5.id_t2 = 26);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t3 index PRIMARY PRIMARY 4 NULL 18 Using index
+1 PRIMARY t1 index NULL PRIMARY 8 NULL 73 Using index
+1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t1.id_product 1 Using index
+1 PRIMARY t4 eq_ref PRIMARY PRIMARY 8 test.t1.id_product,const 1 Using where; Using index
1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1 Using where
-1 PRIMARY <subquery5> eq_ref distinct_key distinct_key 4 func 1 Using where
1 PRIMARY <subquery4> eq_ref distinct_key distinct_key 4 func 1 Using where
-1 PRIMARY t4 eq_ref PRIMARY PRIMARY 8 test.t3.id_product,const 1 Using where; Using index
+1 PRIMARY <subquery5> eq_ref distinct_key distinct_key 4 func 1 Using where
+1 PRIMARY <subquery6> eq_ref distinct_key distinct_key 4 func 1 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 Using where
1 PRIMARY t5 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
-1 PRIMARY <subquery6> eq_ref distinct_key distinct_key 4 func 1 Using where
-1 PRIMARY t1 index NULL PRIMARY 8 NULL 73 Using where; Using index; Using join buffer (flat, BNL join)
3 MATERIALIZED t2_2 ref id_t2,id_product id_t2 5 const 12
-5 MATERIALIZED t2_4 range id_t2,id_product id_t2 5 NULL 18 Using index condition; Using where
4 MATERIALIZED t2_3 range id_t2,id_product id_t2 5 NULL 33 Using index condition; Using where
-2 MATERIALIZED t2_1 ALL id_t2,id_product NULL NULL NULL 223 Using where
+5 MATERIALIZED t2_4 range id_t2,id_product id_t2 5 NULL 18 Using index condition; Using where
6 MATERIALIZED t2_5 range id_t2,id_product id_t2 5 NULL 31 Using index condition; Using where
+2 MATERIALIZED t2_1 ref id_t2,id_product id_t2 5 const 51
set optimizer_switch='rowid_filter=default';
drop table t1,t2,t3,t4,t5;
set global innodb_stats_persistent= @innodb_stats_persistent_save;
diff --git a/mysql-test/main/subselect_sj_jcl6.result b/mysql-test/main/subselect_sj_jcl6.result
index a782280da96..b43171d7910 100644
--- a/mysql-test/main/subselect_sj_jcl6.result
+++ b/mysql-test/main/subselect_sj_jcl6.result
@@ -216,10 +216,10 @@ a b a b
insert into t1 select (A.a + 10 * B.a),1 from t0 A, t0 B;
explain extended select * from t1 where a in (select pk from t10 where pk<3);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t10 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where; Using index
-1 PRIMARY t1 ALL NULL NULL NULL NULL 103 100.00 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL NULL NULL NULL NULL 103 100.00 Using where
+1 PRIMARY t10 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index
Warnings:
-Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t10` join `test`.`t1` where `test`.`t1`.`a` = `test`.`t10`.`pk` and `test`.`t10`.`pk` < 3
+Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t10` join `test`.`t1` where `test`.`t10`.`pk` = `test`.`t1`.`a` and `test`.`t1`.`a` < 3
drop table t0, t1, t2;
drop table t10, t11, t12;
@@ -355,8 +355,8 @@ WHERE PNUM IN
(SELECT PNUM FROM PROJ));
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY STAFF ALL NULL NULL NULL NULL 5
-1 PRIMARY PROJ ALL NULL NULL NULL NULL 6 Start temporary; Using join buffer (flat, BNL join)
-1 PRIMARY WORKS ALL NULL NULL NULL NULL 12 Using where; End temporary; Using join buffer (incremental, BNL join)
+1 PRIMARY PROJ ALL NULL NULL NULL NULL 6 Using join buffer (flat, BNL join)
+1 PRIMARY WORKS ALL NULL NULL NULL NULL 12 Using where; FirstMatch(STAFF); Using join buffer (incremental, BNL join)
SELECT EMPNUM, EMPNAME
FROM STAFF
WHERE EMPNUM IN
@@ -813,6 +813,7 @@ PRIMARY KEY (pk)
INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo','ffff','ffff','ffff','ffff','ffff','ffff',GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))')), (2,'f','ffff','ffff','ffff', 'ffff','ffff','ffff','ffff','ffff','ffff',GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))'));
CREATE TABLE t2 LIKE t1;
INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii','iiii','ffff','ffff','ffff','ffff','ffff',GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))')), (2,'f','ffff','ffff','ffff','ffff','ffff','ffff','ffff','ffff','ffff',GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))'));
+insert into t2 (pk) values (-1),(0);
EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (a, b) IN (SELECT a, b FROM t2 WHERE pk > 0);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
@@ -1260,8 +1261,8 @@ INSERT INTO t2 VALUES (1, 0), (1, 1), (2, 0), (2, 1);
EXPLAIN
SELECT * FROM t1 WHERE (i) IN (SELECT i FROM t2 where j > 0);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 5
-1 PRIMARY t2 index k k 10 NULL 4 Using where; Using index; Start temporary; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where
+1 PRIMARY t2 ref k k 5 test.t1.i 1 Using where; Using index; Start temporary; End temporary
SELECT * FROM t1 WHERE (i) IN (SELECT i FROM t2 where j > 0);
i
1
@@ -1650,8 +1651,8 @@ select * from t1 A, t1 B
where A.a = B.a and A.a in (select a from t2 C) and B.a in (select a from t2 D);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY A ALL NULL NULL NULL NULL 3
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
1 PRIMARY B ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1
2 MATERIALIZED C ALL NULL NULL NULL NULL 3
3 MATERIALIZED D ALL NULL NULL NULL NULL 3
@@ -1991,7 +1992,7 @@ f1 f3 f4 f2 f4
DROP TABLE t1,t2,t3;
#
# BUG#803457: Wrong result with semijoin + view + outer join in maria-5.3-subqueries-mwl90
-# (Original testcase)
+# (Original, slightly modified testcase)
#
CREATE TABLE t1 (f1 int, f2 int );
INSERT INTO t1 VALUES (2,0),(4,0),(0,NULL);
@@ -2001,24 +2002,23 @@ CREATE TABLE t3 ( f1 int, f3 int );
INSERT INTO t3 VALUES (2,0),(4,0),(0,NULL),(4,0),(8,0);
CREATE TABLE t4 ( f2 int, KEY (f2) );
INSERT INTO t4 VALUES (0),(NULL);
-CREATE VIEW v4 AS SELECT DISTINCT f2 FROM t4 ;
+INSERT INTO t4 VALUES (0),(NULL),(-1),(-2),(-3);
# The following must not have outer joins:
explain extended
-SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4);
+SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4 where f2 = 0 or f2 IS NULL);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 PRIMARY t3 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (incremental, BNL join)
-2 MATERIALIZED t4 index f2 f2 5 NULL 2 100.00 Using index
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
+2 MATERIALIZED t4 ref_or_null f2 f2 5 const 4 100.00 Using where; Using index
Warnings:
-Note 1003 select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3`,`test`.`t3`.`f3` AS `f3` from `test`.`t1` semi join (`test`.`t4`) join `test`.`t2` join `test`.`t3` where `test`.`t3`.`f1` = `test`.`t1`.`f1` and `test`.`t1`.`f2` = `test`.`t2`.`f2`
-SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4);
+Note 1003 select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3`,`test`.`t3`.`f3` AS `f3` from `test`.`t1` semi join (`test`.`t4`) join `test`.`t2` join `test`.`t3` where `test`.`t3`.`f1` = `test`.`t1`.`f1` and `test`.`t1`.`f2` = `test`.`t2`.`f2` and (`test`.`t4`.`f2` = 0 or `test`.`t4`.`f2` is null)
+SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4 where f2 = 0 or f2 IS NULL);
f1 f2 f3 f3
2 0 0 0
4 0 0 0
4 0 0 0
-drop view v4;
drop table t1, t2, t3, t4;
#
# BUG#803303: Wrong result with semijoin=on, outer join in maria-5.3-subqueries-mwl90
@@ -2101,9 +2101,9 @@ explain
SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE IFNULL(t2.f3,'foo') IN (SELECT * FROM t4);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
-1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
-1 PRIMARY t3 ALL NULL NULL NULL NULL 5 Using where; Using join buffer (incremental, BNL join)
-1 PRIMARY t4 ALL NULL NULL NULL NULL 2 Using where; Start temporary; End temporary; Using join buffer (incremental, BNL join)
+1 PRIMARY t4 ALL NULL NULL NULL NULL 2 Start temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (incremental, BNL join)
+1 PRIMARY t3 ALL NULL NULL NULL NULL 5 Using where; End temporary; Using join buffer (incremental, BNL join)
SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3 ) WHERE IFNULL(t2.f3,'foo') IN (SELECT * FROM t4);
f1 f2 f3 f3
2 0 0 0
@@ -2164,8 +2164,8 @@ INSERT INTO t3 VALUES (6,5),(6,2),(8,0),(9,1),(6,5);
explain
SELECT * FROM t1, t2 WHERE (t2.a , t1.b) IN (SELECT a, b FROM t3);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 ALL NULL NULL NULL NULL 2
-1 PRIMARY t3 ALL b NULL NULL NULL 5 Using where; Start temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
+1 PRIMARY t3 ref b b 5 test.t1.b 2 Start temporary; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 2 Using where; Using index; End temporary; Using join buffer (incremental, BNL join)
SELECT * FROM t1, t2 WHERE (t2.a , t1.b) IN (SELECT a, b FROM t3);
b a
@@ -2189,10 +2189,10 @@ INSERT INTO t5 VALUES (7,0),(9,0);
explain
SELECT * FROM t3 WHERE t3.a IN (SELECT t5.a FROM t2, t4, t5 WHERE t2.c = t5.a AND t2.b = t5.b);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t5 index a a 10 NULL 2 Using where; Using index; Start temporary
-1 PRIMARY t2 ref b b 5 test.t5.b 2 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
-1 PRIMARY t4 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join)
-1 PRIMARY t3 ALL NULL NULL NULL NULL 15 Using where; End temporary; Using join buffer (incremental, BNL join)
+1 PRIMARY t5 index a a 10 NULL 2 Using where; Using index; LooseScan
+1 PRIMARY t2 ref b b 5 test.t5.b 2 Using where
+1 PRIMARY t4 ALL NULL NULL NULL NULL 3 FirstMatch(t5)
+1 PRIMARY t3 ALL NULL NULL NULL NULL 15 Using where; Using join buffer (flat, BNL join)
SELECT * FROM t3 WHERE t3.a IN (SELECT t5.a FROM t2, t4, t5 WHERE t2.c = t5.a AND t2.b = t5.b);
a
0
@@ -2361,8 +2361,8 @@ SELECT * FROM t1 WHERE (a) IN (SELECT a FROM t2 JOIN t3 ON b = a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 9
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t3 ALL NULL NULL NULL NULL 13
-2 MATERIALIZED t2 index b b 8 NULL 7 Using where; Using index; Using join buffer (flat, BNL join)
+2 MATERIALIZED t3 ALL NULL NULL NULL NULL 13 Using where
+2 MATERIALIZED t2 ref b b 4 test.t3.a 1 Using index
SELECT * FROM t1 WHERE (a) IN (SELECT a FROM t2 JOIN t3 ON b = a);
a
19
@@ -2510,10 +2510,9 @@ SELECT * FROM t1, t2
WHERE t1.a = t2.a AND t2.a IN (SELECT b FROM t3 STRAIGHT_JOIN t4);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 system NULL NULL NULL NULL 1
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 1
-1 PRIMARY t1 ref a a 5 const 1 Using index
-1 PRIMARY t2 ref a a 5 func 1 Using index
-2 MATERIALIZED t4 ALL NULL NULL NULL NULL 0
+1 PRIMARY t2 ref a a 5 const 1 Using index
+1 PRIMARY t4 ALL NULL NULL NULL NULL 0 FirstMatch(t2); Using join buffer (flat, BNL join)
+1 PRIMARY t1 ref a a 5 func 1 Using index
SELECT * FROM t1, t2
WHERE t1.a = t2.a AND t2.a IN (SELECT b FROM t3 STRAIGHT_JOIN t4);
a a
@@ -2585,16 +2584,18 @@ SELECT a, b, d FROM t1, t2
WHERE ( b, d ) IN
( SELECT b, d FROM t1, t2 WHERE b = c );
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t2 ALL NULL NULL NULL NULL 7
-1 PRIMARY t1 index b b 5 NULL 10 Using where; Using index; LooseScan
-1 PRIMARY t2 ref c c 5 test.t1.b 1 Using where; FirstMatch(t1)
-1 PRIMARY t1 ref b b 5 test.t1.b 2 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
+1 PRIMARY t1 index b b 5 NULL 10 Using where; Using index; Start temporary
+1 PRIMARY t2 ref c c 5 test.t1.b 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
+1 PRIMARY t1 ref b b 5 test.t1.b 2 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
+1 PRIMARY t2 ALL NULL NULL NULL NULL 7 Using where; End temporary; Using join buffer (incremental, BNL join)
SELECT a, b, d FROM t1, t2
WHERE ( b, d ) IN
( SELECT b, d FROM t1, t2 WHERE b = c );
a b d
1 2 1
1 2 1
+10 2 1
+10 2 1
2 1 2
2 1 2
3 3 3
@@ -2610,8 +2611,6 @@ a b d
8 4 2
9 3 3
9 3 3
-10 2 1
-10 2 1
DROP TABLE t1, t2;
# Another testcase for the above that still uses LooseScan:
create table t0(a int primary key);
@@ -2779,22 +2778,22 @@ SELECT * FROM t1 AS t1_1, t1 AS t1_2
WHERE (t1_1.a, t1_2.a) IN ( SELECT a, b FROM v1 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1_1 ALL NULL NULL NULL NULL 11 Using where
-1 PRIMARY t1_2 ALL NULL NULL NULL NULL 11
-1 PRIMARY <derived3> ref key0 key0 5 test.t1_1.a 2 Using where; FirstMatch(t1_2)
+1 PRIMARY <derived3> ref key0 key0 5 test.t1_1.a 2 Start temporary
+1 PRIMARY t1_2 ALL NULL NULL NULL NULL 11 Using where; End temporary
3 DERIVED t1 ALL NULL NULL NULL NULL 11
SELECT * FROM t1 AS t1_1, t1 AS t1_2
WHERE (t1_1.a, t1_2.a) IN ( SELECT a, b FROM v1 );
a b a b
-3 1 9 1
-5 8 4 0
-3 9 9 1
2 4 4 0
2 4 6 8
2 6 4 0
2 6 6 8
+3 1 9 1
+3 9 9 1
5 4 4 0
-7 7 7 7
5 4 4 0
+5 8 4 0
+7 7 7 7
DROP VIEW v1;
DROP TABLE t1;
set @@join_cache_level= @tmp_jcl_978479;
@@ -2938,9 +2937,9 @@ alias2.col_int_key = alias1.col_int_key
WHERE alias1.pk = 58 OR alias1.col_varchar_key = 'o'
);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY alias1 index_merge PRIMARY,col_int_key,col_varchar_key PRIMARY,col_varchar_key 4,4 NULL 2 Using sort_union(PRIMARY,col_varchar_key); Using where; Start temporary
-1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
-1 PRIMARY alias2 ALL col_int_key NULL NULL NULL 12 Range checked for each record (index map: 0x2); End temporary
+1 PRIMARY t2 ALL NULL NULL NULL NULL 2
+1 PRIMARY alias1 index_merge PRIMARY,col_int_key,col_varchar_key PRIMARY,col_varchar_key 4,4 NULL 2 Using sort_union(PRIMARY,col_varchar_key); Using where
+1 PRIMARY alias2 ALL col_int_key NULL NULL NULL 12 Range checked for each record (index map: 0x2); FirstMatch(t2)
SELECT *
FROM t2
WHERE (field1) IN (SELECT alias1.col_varchar_nokey AS field1
@@ -3300,8 +3299,7 @@ explain extended
SELECT Id FROM t1 WHERE Id in (SELECT t1_Id FROM t2 WHERE t2.col1 IS NULL);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 100.00
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
-2 MATERIALIZED t2 ref col1 col1 5 const 2 100.00 Using index condition; Using where
+1 PRIMARY t2 ALL col1 NULL NULL NULL 2 100.00 Using where; FirstMatch(t1)
Warnings:
Note 1003 select 1 AS `Id` from (`test`.`t2`) where `test`.`t2`.`t1_Id` = 1 and `test`.`t2`.`col1` is null
DROP TABLE t1, t2;
diff --git a/mysql-test/main/subselect_sj_mat.result b/mysql-test/main/subselect_sj_mat.result
index 4c88d3a78f1..ea6d8003be5 100644
--- a/mysql-test/main/subselect_sj_mat.result
+++ b/mysql-test/main/subselect_sj_mat.result
@@ -107,9 +107,9 @@ a1 a2
explain extended
select * from t1i where a1 in (select b1 from t2i where b1 > '0');
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1i range _it1_idx _it1_idx # NULL 3 100.00 Using where;
+1 PRIMARY t1i index _it1_idx _it1_idx # NULL 3 100.00
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key # func 1 100.00
-2 MATERIALIZED t2i range it2i1,it2i3 it2i1 # NULL 5 100.00 Using where;
+2 MATERIALIZED t2i index it2i1,it2i3 it2i1 # NULL 5 100.00 Using where;
Warnings:
Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) where `test`.`t2i`.`b1` > '0'
select * from t1i where a1 in (select b1 from t2i where b1 > '0');
@@ -131,9 +131,9 @@ a1 a2
explain extended
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0');
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1i range _it1_idx _it1_idx # NULL 3 100.00 Using where;
+1 PRIMARY t1i index _it1_idx _it1_idx # NULL 3 100.00
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key # func,func 1 100.00
-2 MATERIALIZED t2i range it2i1,it2i2,it2i3 it2i3 # NULL 5 100.00 Using where;
+2 MATERIALIZED t2i index it2i1,it2i2,it2i3 it2i3 # NULL 5 100.00 Using where;
Warnings:
Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) where `test`.`t2i`.`b1` > '0'
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0');
@@ -278,10 +278,11 @@ a1 a2
explain extended
select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t2i index it2i1,it2i2,it2i3 it2i3 18 NULL 5 50.00 Using where; Using index; LooseScan
-1 PRIMARY t1i ref it1i1,it1i2,it1i3 it1i3 18 test.t2i.b1,test.t2i.b2 1 100.00 Using index
+1 PRIMARY t1i index it1i1,it1i2,it1i3 it1i3 18 NULL 3 100.00 Using index
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 16 func,func 1 100.00
+2 MATERIALIZED t2i index it2i1,it2i2,it2i3 it2i3 18 NULL 5 100.00 Using index
Warnings:
-Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) where `test`.`t1i`.`a1` = `test`.`t2i`.`b1` and `test`.`t1i`.`a2` = `test`.`t2i`.`b2`
+Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) where 1
select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2);
a1 a2
1 - 01 2 - 01
@@ -352,14 +353,12 @@ where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
(a1, a2) in (select c1, c2 from t3i
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY t1i range it1i1,it1i2,it1i3 # # # 3 100.00 #
-1 PRIMARY <subquery2> eq_ref distinct_key # # # 1 100.00 #
-1 PRIMARY <subquery3> eq_ref distinct_key # # # 1 100.00 #
-2 MATERIALIZED t2i range it2i1,it2i2,it2i3 # # # 5 100.00 #
-3 MATERIALIZED t3i range it3i1,it3i2,it3i3 # # # 4 100.00 #
-3 MATERIALIZED t2i ref it2i1,it2i2,it2i3 # # # 1 100.00 #
+1 PRIMARY t2i index it2i1,it2i2,it2i3 # # # 5 50.00 #
+1 PRIMARY t1i ref it1i1,it1i2,it1i3 # # # 1 100.00 #
+1 PRIMARY t3i ref it3i1,it3i2,it3i3 # # # 1 100.00 #
+1 PRIMARY t2i ref it2i1,it2i2,it2i3 # # # 1 100.00 #
Warnings:
-Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) semi join (`test`.`t2i` join `test`.`t3i`) where `test`.`t2i`.`b1` = `test`.`t3i`.`c1` and `test`.`t2i`.`b2` = `test`.`t3i`.`c2` and `test`.`t2i`.`b1` > '0' and `test`.`t3i`.`c2` > '0'
+Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) semi join (`test`.`t2i` join `test`.`t3i`) where `test`.`t1i`.`a1` = `test`.`t2i`.`b1` and `test`.`t3i`.`c1` = `test`.`t2i`.`b1` and `test`.`t2i`.`b1` = `test`.`t2i`.`b1` and `test`.`t1i`.`a2` = `test`.`t2i`.`b2` and `test`.`t3i`.`c2` = `test`.`t2i`.`b2` and `test`.`t2i`.`b2` = `test`.`t2i`.`b2` and `test`.`t2i`.`b1` > '0' and `test`.`t2i`.`b2` > '0'
select * from t1i
where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
(a1, a2) in (select c1, c2 from t3i
@@ -442,15 +441,13 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
5 MATERIALIZED t2i ref it2i1,it2i2,it2i3 # # # 1 100.00 #
4 MATERIALIZED t3 ALL NULL # # # 4 100.00 #
3 MATERIALIZED t3 ALL NULL # # # 4 100.00 #
-7 UNION t1i range it1i1,it1i2,it1i3 # # # 3 100.00 #
-7 UNION <subquery8> eq_ref distinct_key # # # 1 100.00 #
-7 UNION <subquery9> eq_ref distinct_key # # # 1 100.00 #
-8 MATERIALIZED t2i range it2i1,it2i2,it2i3 # # # 5 100.00 #
-9 MATERIALIZED t3i range it3i1,it3i2,it3i3 # # # 4 100.00 #
-9 MATERIALIZED t2i ref it2i1,it2i2,it2i3 # # # 1 100.00 #
+7 UNION t2i index it2i1,it2i2,it2i3 # # # 5 50.00 #
+7 UNION t1i ref it1i1,it1i2,it1i3 # # # 1 100.00 #
+7 UNION t3i ref it3i1,it3i2,it3i3 # # # 1 100.00 #
+7 UNION t2i ref it2i1,it2i2,it2i3 # # # 1 100.00 #
NULL UNION RESULT <union1,7> ALL NULL # # # NULL NULL #
Warnings:
-Note 1003 (/* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3`) where `test`.`t2i`.`b1` = `test`.`t3`.`c1` and `test`.`t2i`.`b2` = `test`.`t3`.`c2` and (<expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#3 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%02' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery3>`.`c2`)))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#4 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%03' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery4>`.`c2`))))) and `test`.`t3`.`c2` > '0') union (/* select#7 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) semi join (`test`.`t2i` join `test`.`t3i`) where `test`.`t2i`.`b1` = `test`.`t3i`.`c1` and `test`.`t2i`.`b2` = `test`.`t3i`.`c2` and `test`.`t2i`.`b1` > '0' and `test`.`t3i`.`c2` > '0')
+Note 1003 (/* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3`) where `test`.`t2i`.`b1` = `test`.`t3`.`c1` and `test`.`t2i`.`b2` = `test`.`t3`.`c2` and (<expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#3 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%02' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery3>`.`c2`)))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#4 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%03' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery4>`.`c2`))))) and `test`.`t3`.`c2` > '0') union (/* select#7 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) semi join (`test`.`t2i` join `test`.`t3i`) where `test`.`t1i`.`a1` = `test`.`t2i`.`b1` and `test`.`t3i`.`c1` = `test`.`t2i`.`b1` and `test`.`t2i`.`b1` = `test`.`t2i`.`b1` and `test`.`t1i`.`a2` = `test`.`t2i`.`b2` and `test`.`t3i`.`c2` = `test`.`t2i`.`b2` and `test`.`t2i`.`b2` = `test`.`t2i`.`b2` and `test`.`t2i`.`b1` > '0' and `test`.`t2i`.`b2` > '0')
(select * from t1
where (a1, a2) in (select b1, b2 from t2
where b2 in (select c2 from t3 where c2 LIKE '%02') or
@@ -1573,8 +1570,7 @@ SET @@optimizer_switch='semijoin=on,materialization=on';
EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan
+1 PRIMARY t2 ALL PRIMARY NULL NULL NULL 2 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
pk
2
@@ -1993,11 +1989,11 @@ EXPLAIN EXTENDED
SELECT * FROM t1
WHERE a IN (SELECT MAX(c) FROM t2) AND b=7 AND (a IS NULL OR a=b);
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00
-1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
+1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00 Using where
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00
Warnings:
-Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from <materialize> (/* select#2 */ select max(`test`.`t2`.`c`) from `test`.`t2` having `MAX(c)` is null or `MAX(c)` = 7) join `test`.`t1` where `test`.`t1`.`b` = 7 and `test`.`t1`.`a` = `<subquery2>`.`MAX(c)` and (<cache>(/*always not null*/ 1 is null) or `<subquery2>`.`MAX(c)` = 7)
+Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from <materialize> (/* select#2 */ select max(`test`.`t2`.`c`) from `test`.`t2` having `MAX(c)` is null or `MAX(c)` = 7) join `test`.`t1` where `test`.`t1`.`b` = 7 and `<subquery2>`.`MAX(c)` = `test`.`t1`.`a` and (`test`.`t1`.`a` is null or `test`.`t1`.`a` = 7)
SELECT * FROM t1
WHERE a IN (SELECT MAX(c) FROM t2) AND b=7 AND (a IS NULL OR a=b);
a b
@@ -2006,8 +2002,8 @@ EXPLAIN
SELECT * FROM t1
WHERE a IN (SELECT MAX(c) FROM t2 WHERE c < 4) AND b=7 AND (a IS NULL OR a=b);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1
-1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
+1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 Using where
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where
SELECT * FROM t1
WHERE a IN (SELECT MAX(c) FROM t2 WHERE c < 4) AND b=7 AND (a IS NULL OR a=b);
@@ -2283,9 +2279,8 @@ WHERE EXISTS ( SELECT * FROM t1 AS sq2
WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY sq1 ALL NULL NULL NULL NULL 2 Using where
-2 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 Using where
-2 DEPENDENT SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1
-3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2
+2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where; FirstMatch
+2 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
# this checks the result set above
set optimizer_switch= 'materialization=off,semijoin=off';
SELECT sq1.f2 FROM t1 AS sq1
@@ -2317,10 +2312,9 @@ WHERE EXISTS ( SELECT * FROM t2, t3
WHERE i3 = i2 AND f1 IN ( SELECT f3 FROM t3 ) );
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
-2 DEPENDENT SUBQUERY t2 index i2 i2 5 NULL 3 100.00 Using where; Using index
-2 DEPENDENT SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00
+2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 8 100.00 Using where; FirstMatch
+2 DEPENDENT SUBQUERY t2 index i2 i2 5 NULL 3 100.00 Using where; Using index; Using join buffer (flat, BNL join)
2 DEPENDENT SUBQUERY t3 ref i3 i3 5 test.t2.i2 2 100.00 Using index
-3 MATERIALIZED t3 ALL NULL NULL NULL NULL 8 100.00
Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where <expr_cache><`test`.`t1`.`f1`>(exists(/* select#2 */ select 1 from `test`.`t2` semi join (`test`.`t3`) join `test`.`t3` where `test`.`t3`.`i3` = `test`.`t2`.`i2` and `test`.`t1`.`f1` = `test`.`t3`.`f3` limit 1))
@@ -2356,9 +2350,8 @@ SELECT pk, f1, ( SELECT COUNT(*) FROM t2
WHERE t1.pk IN ( SELECT f2 FROM t2 ) ) AS sq FROM t1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00
-2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00
-2 DEPENDENT SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00
-3 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00
+2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; FirstMatch
+2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using join buffer (flat, BNL join)
Warnings:
Note 1276 Field or reference 'test.t1.pk' of SELECT #2 was resolved in SELECT #1
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`f1` AS `f1`,<expr_cache><`test`.`t1`.`pk`>((/* select#2 */ select count(0) from `test`.`t2` semi join (`test`.`t2`) where `test`.`t1`.`pk` = `test`.`t2`.`f2`)) AS `sq` from `test`.`t1`
@@ -2492,8 +2485,7 @@ explain
SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 9
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
-2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2);
1
1
@@ -2504,8 +2496,8 @@ alter table t1 add key(id);
explain
SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3
-1 PRIMARY t1 ref id id 4 test.t2.i1 2 Using index
+1 PRIMARY t1 index id id 4 NULL 9 Using index
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where
SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2);
1
@@ -2561,8 +2553,8 @@ INSERT INTO t2 VALUES (11,11),(12,12),(13,13);
CREATE VIEW v1 AS SELECT t2.i1 FROM t2 where t2.i1 = t2.i2;
explain SELECT 1 FROM t1 where t1.id IN (SELECT v1.i1 from v1);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3
-1 PRIMARY t1 ref id id 4 test.t2.i1 2 Using index
+1 PRIMARY t1 index id id 4 NULL 9 Using index
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where
SELECT 1 FROM t1 where t1.id IN (SELECT v1.i1 from v1);
1
diff --git a/mysql-test/main/subselect_sj_nonmerged.result b/mysql-test/main/subselect_sj_nonmerged.result
index a3e6c493930..99ce641da8e 100644
--- a/mysql-test/main/subselect_sj_nonmerged.result
+++ b/mysql-test/main/subselect_sj_nonmerged.result
@@ -47,8 +47,8 @@ id select_type table type possible_keys key key_len ref rows Extra
# Compare to this which really will have 50 record combinations:
explain select * from t3 where a in (select max(t2.a) from t1, t2 group by t2.b, t1.b);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t3 index PRIMARY PRIMARY 8 NULL 100 Using index
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 test.t3.a 1 Using where
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 50
+1 PRIMARY t3 eq_ref PRIMARY PRIMARY 8 <subquery2>.max(t2.a) 1 Using where; Using index
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 Using temporary
2 MATERIALIZED t1 ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join)
SET @save_optimizer_switch=@@optimizer_switch;
@@ -57,8 +57,8 @@ SET optimizer_switch='outer_join_with_cache=off';
explain select * from t3
where a in (select max(t2.a) from t1 left join t2 on t1.a=t2.a group by t2.b, t1.b);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t3 index PRIMARY PRIMARY 8 NULL 100 Using index
-1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 test.t3.a 1 Using where
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 50
+1 PRIMARY t3 eq_ref PRIMARY PRIMARY 8 <subquery2>.max(t2.a) 1 Using where; Using index
2 MATERIALIZED t1 ALL NULL NULL NULL NULL 10 Using temporary
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 Using where
SET optimizer_switch=@save_optimizer_switch;
@@ -67,8 +67,8 @@ insert into t4 select A.a + 10*B.a, A.a + 10*B.a, 'filler' from t0 A, t0 B;
explain select * from t0, t4 where
t4.b=t0.a and t4.a in (select max(t2.a) from t1, t2 group by t2.b);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 5
-1 PRIMARY t0 ALL NULL NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY t0 ALL NULL NULL NULL NULL 10 Using where
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 5 Using join buffer (flat, BNL join)
1 PRIMARY t4 eq_ref a a 10 <subquery2>.max(t2.a),test.t0.a 1
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 Using temporary
2 MATERIALIZED t1 ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join)
diff --git a/mysql-test/main/table_elim.result b/mysql-test/main/table_elim.result
index 4b9956a4e48..b17cbfeeb07 100644
--- a/mysql-test/main/table_elim.result
+++ b/mysql-test/main/table_elim.result
@@ -337,7 +337,7 @@ id select_type table type possible_keys key key_len ref rows Extra
explain select t1.a from t1 left join t2 on t2.pk between 0.5 and 1.5;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4
-1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using where; Using index
+1 SIMPLE t2 index PRIMARY PRIMARY 4 NULL 2 Using where; Using index
explain select t1.a from t1 left join t2 on t2.pk between 10 and 10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4
@@ -408,7 +408,7 @@ select t1.*
from t1 left join t2 on t2.pk=3 or t2.pk= 4;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4
-1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using where; Using index
+1 SIMPLE t2 index PRIMARY PRIMARY 4 NULL 2 Using where; Using index
explain
select t1.*
from t1 left join t2 on t2.pk=3 or t2.pk= 3;
@@ -419,7 +419,7 @@ select t1.*
from t1 left join t2 on (t2.pk=3 and t2.b=3) or (t2.pk= 4 and t2.b=3);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4
-1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using where
+1 SIMPLE t2 ALL PRIMARY NULL NULL NULL 2 Using where
drop table t1, t2;
#
# LPBUG#523593: Running RQG optimizer_no_subquery crashes MariaDB
@@ -562,10 +562,7 @@ LEFT JOIN t1 ON t4.f1 = t1.f1
JOIN t5 ON t4.f3 ON t3.f1 = t5.f5 ON t2.f4 = t3.f4
WHERE t3.f2 ;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t3 ALL NULL NULL NULL NULL 2 Using where
-1 SIMPLE t2 ref f4 f4 1003 test.t3.f4 2 Using where
-1 SIMPLE t5 ref f5 f5 5 test.t3.f1 2 Using where; Using index
-1 SIMPLE t4 ALL NULL NULL NULL NULL 3 Using where
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
# ^^ The above must not produce a QEP of t3,t5,t2,t4
# as that violates the "no interleaving of outer join nests" rule.
DROP TABLE t1,t2,t3,t4,t5;
diff --git a/mysql-test/main/table_value_constr.result b/mysql-test/main/table_value_constr.result
index e6d973d53ee..75333b65f71 100644
--- a/mysql-test/main/table_value_constr.result
+++ b/mysql-test/main/table_value_constr.result
@@ -567,12 +567,12 @@ where t1.a=t2.a and st<3
select * from t2;
a b st
1 1 1
-1 2 2
1 1 2
-1 2 3
-1 2 3
1 1 3
1 1 3
+1 2 2
+1 2 3
+1 2 3
# recursive CTE that uses VALUES structure(s) : computation of factorial (first 10 elements)
with recursive fact(n,f) as
(
diff --git a/mysql-test/main/table_value_constr.test b/mysql-test/main/table_value_constr.test
index 331cfb8b7db..8fa443c3b77 100644
--- a/mysql-test/main/table_value_constr.test
+++ b/mysql-test/main/table_value_constr.test
@@ -422,6 +422,7 @@ select * from t2;
--echo # recursive CTE that uses VALUES structure(s) : that uses UNION ALL
+--sorted_result
with recursive t2(a,b,st) as
(
values(1,1,1)
diff --git a/mysql-test/main/tmp_table_count-7586.result b/mysql-test/main/tmp_table_count-7586.result
index 637e7385685..ebb2333113f 100644
--- a/mysql-test/main/tmp_table_count-7586.result
+++ b/mysql-test/main/tmp_table_count-7586.result
@@ -52,6 +52,7 @@ Created_tmp_disk_tables 0
Created_tmp_files 0
Created_tmp_tables 2
drop table t3;
+set @@optimizer_switch="firstmatch=off";
EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
@@ -69,6 +70,7 @@ Variable_name Value
Created_tmp_disk_tables 0
Created_tmp_files 0
Created_tmp_tables 1
+set @@optimizer_switch=default;
drop table t1,t2,t3;
truncate table performance_schema.events_statements_history_long;
flush status;
diff --git a/mysql-test/main/tmp_table_count-7586.test b/mysql-test/main/tmp_table_count-7586.test
index 0629e27f164..8fe9e3d2eff 100644
--- a/mysql-test/main/tmp_table_count-7586.test
+++ b/mysql-test/main/tmp_table_count-7586.test
@@ -47,6 +47,7 @@ select sum(created_tmp_tables) from performance_schema.events_statements_history
show status like '%Created_tmp%';
drop table t3;
+set @@optimizer_switch="firstmatch=off";
EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a);
truncate table performance_schema.events_statements_history_long;
flush status;
@@ -54,6 +55,7 @@ CREATE TABLE t3 SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a);
--echo # Performance schema should be the same as "Created_tmp_tables" variable below
select sum(created_tmp_tables) from performance_schema.events_statements_history_long;
show status like '%Created_tmp%';
+set @@optimizer_switch=default;
drop table t1,t2,t3;
diff --git a/mysql-test/main/type_blob.result b/mysql-test/main/type_blob.result
index 851d0bd72d4..abde3db7fac 100644
--- a/mysql-test/main/type_blob.result
+++ b/mysql-test/main/type_blob.result
@@ -625,7 +625,7 @@ id txt
3 NULL
explain select * from t1 where txt='Chevy' or txt is NULL;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref_or_null txt_index txt_index 23 const 3 Using where
+1 SIMPLE t1 ALL txt_index NULL NULL NULL 6 Using where
explain select * from t1 FORCE INDEX (`txt_index`) where txt='Chevy' or txt is NULL;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref_or_null txt_index txt_index 23 const 3 Using where
diff --git a/mysql-test/main/type_datetime.result b/mysql-test/main/type_datetime.result
index 3e864d0ffa9..c4568e80ae6 100644
--- a/mysql-test/main/type_datetime.result
+++ b/mysql-test/main/type_datetime.result
@@ -105,7 +105,7 @@ date numfacture expedition
0000-00-00 00:00:00 1212 0001-00-00 00:00:00
EXPLAIN SELECT * FROM t1 WHERE expedition='0001-00-00 00:00:00';
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref expedition expedition 5 const 2
+1 SIMPLE t1 ALL expedition NULL NULL NULL 2 Using where
drop table t1;
create table t1 (a datetime not null, b datetime not null);
insert into t1 values (now(), now());
@@ -545,7 +545,7 @@ select * from t1
where id in (select id from t1 as x1 where (t1.cur_date is null));
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
-1 PRIMARY x1 ALL NULL NULL NULL NULL 2 100.00 Using where; Start temporary; End temporary
+1 PRIMARY x1 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch(t1)
Warnings:
Note 1276 Field or reference 'test.t1.cur_date' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`cur_date` AS `cur_date` from `test`.`t1` semi join (`test`.`t1` `x1`) where `test`.`x1`.`id` = `test`.`t1`.`id` and `test`.`t1`.`cur_date` = 0
@@ -557,7 +557,7 @@ select * from t2
where id in (select id from t2 as x1 where (t2.cur_date is null));
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
-1 PRIMARY x1 ALL NULL NULL NULL NULL 2 100.00 Using where; Start temporary; End temporary
+1 PRIMARY x1 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch(t2)
Warnings:
Note 1276 Field or reference 'test.t2.cur_date' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`t2`.`id` AS `id`,`test`.`t2`.`cur_date` AS `cur_date` from `test`.`t2` semi join (`test`.`t2` `x1`) where `test`.`x1`.`id` = `test`.`t2`.`id` and `test`.`t2`.`cur_date` = 0
diff --git a/mysql-test/main/user_var.result b/mysql-test/main/user_var.result
index a5837996c19..ae0621a3b57 100644
--- a/mysql-test/main/user_var.result
+++ b/mysql-test/main/user_var.result
@@ -22,7 +22,7 @@ i @vv1:=if(sv1.i,1,0) @vv2:=if(sv2.i,1,0) @vv3:=if(sv3.i,1,0) @vv1+@vv2+@vv3
2 1 0 0 1
explain select * from t1 where i=@vv1;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref i i 4 const 2
+1 SIMPLE t1 ALL i NULL NULL NULL 3 Using where
select @vv1,i,v from t1 where i=@vv1;
@vv1 i v
1 1 1
@@ -35,7 +35,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL i 4 NULL 3 Using where; Using index
explain select * from t1 where i=@vv1;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t1 ref i i 4 const 2
+1 SIMPLE t1 ALL i NULL NULL NULL 3 Using where
drop table t1,t2;
set @a=0,@b=0;
select @a:=10, @b:=1, @a > @b, @a < @b;
diff --git a/mysql-test/main/view.test b/mysql-test/main/view.test
index c6cc9a69f93..5b1a48f0f8a 100644
--- a/mysql-test/main/view.test
+++ b/mysql-test/main/view.test
@@ -1880,7 +1880,9 @@ CREATE VIEW v1 AS SELECT id, f FROM t1 WHERE id <= 2;
INSERT INTO t1 VALUES (2, 'foo2');
INSERT INTO t1 VALUES (1, 'foo1');
+--sorted_result
SELECT * FROM v1;
+--sorted_result
SELECT * FROM v1;
DROP VIEW v1;
diff --git a/mysql-test/main/xtradb_mrr.result b/mysql-test/main/xtradb_mrr.result
index b4c91d9aff4..7d84f605e14 100644
--- a/mysql-test/main/xtradb_mrr.result
+++ b/mysql-test/main/xtradb_mrr.result
@@ -431,6 +431,12 @@ INSERT INTO `t1` VALUES (97,7,0,'z','z');
INSERT INTO `t1` VALUES (98,1,1,'j','j');
INSERT INTO `t1` VALUES (99,7,8,'c','c');
INSERT INTO `t1` VALUES (100,2,5,'f','f');
+EXPLAIN SELECT table1 .`col_varchar_key`
+FROM t1 table1 STRAIGHT_JOIN ( t1 table3 JOIN t1 table4 ON table4 .`pk` = table3 .`col_int_nokey` ) ON table4 .`col_varchar_nokey` ;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE table1 index NULL col_varchar_key 9 NULL # Using index
+1 SIMPLE table3 ALL NULL NULL NULL NULL # Using where; Using join buffer (flat, BNL join)
+1 SIMPLE table4 eq_ref PRIMARY PRIMARY 4 test.table3.col_int_nokey # Using where
SELECT table1 .`col_varchar_key`
FROM t1 table1 STRAIGHT_JOIN ( t1 table3 JOIN t1 table4 ON table4 .`pk` = table3 .`col_int_nokey` ) ON table4 .`col_varchar_nokey` ;
col_varchar_key
diff --git a/mysql-test/main/xtradb_mrr.test b/mysql-test/main/xtradb_mrr.test
index 9de9b192b06..f5cecc54a3f 100644
--- a/mysql-test/main/xtradb_mrr.test
+++ b/mysql-test/main/xtradb_mrr.test
@@ -151,6 +151,9 @@ INSERT INTO `t1` VALUES (97,7,0,'z','z');
INSERT INTO `t1` VALUES (98,1,1,'j','j');
INSERT INTO `t1` VALUES (99,7,8,'c','c');
INSERT INTO `t1` VALUES (100,2,5,'f','f');
+--replace_column 9 #
+EXPLAIN SELECT table1 .`col_varchar_key`
+FROM t1 table1 STRAIGHT_JOIN ( t1 table3 JOIN t1 table4 ON table4 .`pk` = table3 .`col_int_nokey` ) ON table4 .`col_varchar_nokey` ;
SELECT table1 .`col_varchar_key`
FROM t1 table1 STRAIGHT_JOIN ( t1 table3 JOIN t1 table4 ON table4 .`pk` = table3 .`col_int_nokey` ) ON table4 .`col_varchar_nokey` ;
DROP TABLE t1;