Created
October 3, 2022 08:46
-
-
Save spetrunia/0b3b2361f1f777e34d8a8de212ccb3fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc | |
index f121a592d5b..ac447286a56 100644 | |
--- a/sql/opt_subselect.cc | |
+++ b/sql/opt_subselect.cc | |
@@ -3635,12 +3636,12 @@ bool Duplicate_weedout_picker::check_qep(JOIN *join, | |
if (p->table->emb_sj_nest) | |
{ | |
- sj_inner_fanout= COST_MULT(sj_inner_fanout, p->records_read); | |
+ sj_inner_fanout= COST_MULT(sj_inner_fanout, p->records_out); | |
dups_removed_fanout |= p->table->table->map; | |
} | |
else | |
{ | |
- sj_outer_fanout= COST_MULT(sj_outer_fanout, p->records_read); | |
+ sj_outer_fanout= COST_MULT(sj_outer_fanout, p->records_out); | |
temptable_rec_size += p->table->table->file->ref_length; | |
} | |
} | |
@@ -3659,10 +3660,9 @@ bool Duplicate_weedout_picker::check_qep(JOIN *join, | |
sj_outer_fanout, | |
temptable_rec_size, | |
0, 0); | |
- double prefix_record_count= join->positions[first_tab].prefix_record_count; | |
double write_cost= (one_cost.create + | |
- prefix_record_count * sj_outer_fanout * one_cost.write); | |
- double full_lookup_cost= (prefix_record_count * sj_outer_fanout * | |
+ first_weedout_table_rec_count * sj_outer_fanout * one_cost.write); | |
+ double full_lookup_cost= (first_weedout_table_rec_count* sj_outer_fanout * | |
sj_inner_fanout * one_cost.lookup); | |
*read_time= dups_cost + write_cost + full_lookup_cost; | |
@@ -3674,7 +3674,7 @@ bool Duplicate_weedout_picker::check_qep(JOIN *join, | |
Json_writer_object trace(join->thd); | |
trace. | |
add("strategy", "DuplicateWeedout"). | |
- add("prefix_record_count", prefix_record_count). | |
+ add("prefix_record_count", first_weedout_table_rec_count). | |
add("tmp_table_records", sj_outer_fanout). | |
add("sj_inner_fanout", sj_inner_fanout). | |
add("rows", *record_count). | |
diff --git a/sql/opt_subselect.h b/sql/opt_subselect.h | |
index 2eb5ff56b02..f59ce0dbb85 100644 | |
--- a/sql/opt_subselect.h | |
+++ b/sql/opt_subselect.h | |
@@ -300,6 +300,7 @@ class Loose_scan_opt | |
if (best_loose_scan_cost != DBL_MAX) | |
{ | |
pos->records_read= best_loose_scan_records; | |
+ pos->records_init= pos->records_out= pos->records_read; | |
pos->key= best_loose_scan_start_key; | |
pos->cond_selectivity= 1.0; | |
pos->loosescan_picker.loosescan_key= best_loose_scan_key; | |
diff --git a/sql/sql_select.cc b/sql/sql_select.cc | |
index 02976201411..8517861f6c6 100644 | |
--- a/sql/sql_select.cc | |
+++ b/sql/sql_select.cc | |
@@ -18250,6 +18280,14 @@ void optimize_wo_join_buffering(JOIN *join, uint first_tab, uint last_tab, | |
join->cur_sj_inner_tables= save_cur_sj_inner_tables; | |
*reopt_cost= cost; | |
+ if (rec_count < *outer_rec_count) | |
+ { | |
+ /* | |
+ The tables inside the subquery produce smaller fanout than outer tables. | |
+ This can happen in edge cases. | |
+ */ | |
+ *outer_rec_count= rec_count; | |
+ } | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment