diff options
author | Sergei Petrunia <sergey@mariadb.com> | 2022-12-08 21:24:31 +0300 |
---|---|---|
committer | Sergei Petrunia <sergey@mariadb.com> | 2022-12-08 21:24:31 +0300 |
commit | cb69a8123e140aa3d2b94513a471161d693059da (patch) | |
tree | 988bbc65918450a0cdaad6cb16ef51c986350c5b /sql/sql_select.cc | |
parent | 9eba044b9710bbdd8195e887cfdd4d62233942ca (diff) | |
download | mariadb-git-bb-10.11-tmp.tar.gz |
MDEV-21095: Make Optimizer Trace support Index Condition Pushdownbb-10.11-tmp
Fixes over previous patches: do tracing of attached conditions
close to where we generate them.
Fix the tracing code to print the right conditions.
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r-- | sql/sql_select.cc | 91 |
1 files changed, 30 insertions, 61 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 58964f06e6b..c27bd5987bd 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -323,8 +323,6 @@ static void fix_items_after_optimize(THD *thd, SELECT_LEX *select_lex); static void optimize_rownum(THD *thd, SELECT_LEX_UNIT *unit, Item *cond); static bool process_direct_rownum_comparison(THD *thd, SELECT_LEX_UNIT *unit, Item *cond); -void trace_attached_conditions(THD *thd, JOIN *join); -void trace_join_readinfo(THD *thd, JOIN *join); #ifndef DBUG_OFF @@ -3105,8 +3103,6 @@ int JOIN::optimize_stage2() if (make_join_readinfo(this, select_opts_for_readinfo, no_jbuf_after)) DBUG_RETURN(1); - trace_join_readinfo(thd, this); - /* Perform FULLTEXT search before all regular searches */ if (!(select_options & SELECT_DESCRIBE)) if (init_ftfuncs(thd, select_lex, MY_TEST(order))) @@ -5074,8 +5070,6 @@ mysql_select(THD *thd, TABLE_LIST *tables, List<Item> &fields, COND *conds, goto err; // 1 } - trace_attached_conditions(thd, join); - if (thd->lex->describe & DESCRIBE_EXTENDED) { join->conds_history= join->conds; @@ -12305,6 +12299,10 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) DBUG_ENTER("make_join_select"); if (select) { + Json_writer_object trace_wrapper(thd); + Json_writer_object trace_conditions(thd, "attaching_conditions_to_tables"); + Json_writer_array trace_attached_comp(thd, + "attached_conditions_computation"); add_not_null_conds(join); table_map used_tables; /* @@ -12377,6 +12375,9 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) { add_cond_and_fix(thd, &outer_ref_cond, join->outer_ref_cond); join->outer_ref_cond= outer_ref_cond; + + Json_writer_object trace(thd); + trace.add("outer_ref_cond", outer_ref_cond); } } else @@ -12392,6 +12393,9 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) add_cond_and_fix(thd, &pseudo_bits_cond, join->pseudo_bits_cond); join->pseudo_bits_cond= pseudo_bits_cond; + + Json_writer_object trace(thd); + trace.add("pseudo_bits_cond", pseudo_bits_cond); } } } @@ -12957,6 +12961,23 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) if (!tab->bush_children) i++; } + + if (unlikely(thd->trace_started())) + { + trace_attached_comp.end(); + Json_writer_array trace_attached_summary(thd, + "attached_conditions_summary"); + for (tab= first_depth_first_tab(join); tab; + tab= next_depth_first_tab(join, tab)) + { + if (!tab->table) + continue; + Item *const cond = tab->select_cond; + Json_writer_object trace_one_table(thd); + trace_one_table.add_table_name(tab); + trace_one_table.add("attached_condition", cond); + } + } } DBUG_RETURN(0); } @@ -14026,6 +14047,9 @@ make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after) uint i; DBUG_ENTER("make_join_readinfo"); + Json_writer_object trace_wrapper(join->thd); + Json_writer_array trace_arr(join->thd, "make_join_readinfo"); + bool statistics= MY_TEST(!(join->select_options & SELECT_DESCRIBE)); bool sorted= 1; @@ -31100,61 +31124,6 @@ bool JOIN::transform_all_conds_and_on_exprs_in_join_list( return false; } - -void trace_attached_conditions(THD *thd, JOIN *join) -{ - if (!unlikely(thd->trace_started())) - return; - - Json_writer_object trace_wrapper(thd); - Json_writer_object trace_conditions(thd, "attaching_conditions_to_tables"); - Json_writer_array trace_attached_comp(thd, - "attached_conditions_computation"); - JOIN_TAB *tab; - - trace_attached_comp.end(); - Json_writer_array trace_attached_summary(thd, - "attached_conditions_summary"); - - for (tab= first_depth_first_tab(join); - tab; - tab= next_depth_first_tab(join, tab)) - { - if (!tab->table) - continue; - - Item *const remaining_cond = tab->select_cond; - Item *const idx_cond = tab->table->file->pushed_idx_cond; - Json_writer_object trace_one_table(thd); - - trace_one_table.add_table_name(tab); - trace_one_table.add("attached_condition", remaining_cond); - if (idx_cond) - trace_one_table.add("index_condition", idx_cond); - } -} - - -void trace_join_readinfo(THD *thd, JOIN *join) -{ - if (!unlikely(thd->trace_started())) - return; - - Json_writer_object trace_wrapper(thd); - Json_writer_array trace_conditions(thd, "make_join_readinfo"); - JOIN_TAB *tab; - - for (tab= first_linear_tab(join, WITH_BUSH_ROOTS, WITHOUT_CONST_TABLES); - tab; - tab= next_linear_tab(join, tab, WITH_BUSH_ROOTS)) - { - Json_writer_object trace_one_table(thd); - trace_one_table.add_table_name(tab); - trace_one_table.add("index_condition", tab->select_cond); - } -} - - /** @} (end of group Query_Optimizer) */ |