On Thu, Jan 28, 2021 at 07:42:07PM +0300, Sergey Petrunia wrote:
Hi Varun,
@@ -6819,6 +6820,7 @@ static TRP_RANGE *get_key_scans_params(PARAM *param, SEL_TREE *tree, double found_read_time; uint mrr_flags, buf_size; INDEX_SCAN_INFO *index_scan; + param->is_ror_scan= FALSE; uint keynr= param->real_keynr[idx]; if (key->type == SEL_ARG::MAYBE_KEY || key->maybe_flag)
check_quick_select actually does initialize PARAM::is_ror_scan, except for "degenerate" cases that are handled at the start of the function.
So, I think an easier fix would be to just have check_quick_select to set is_ror_scan for the degenerate cases, too.
I've also removed another redundant initialization, and it seems things work. Please find the patch below:
diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 7785c768fbc..f2c55b2b5a5 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -3065,7 +3065,6 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond) param.mem_root= &alloc; param.old_root= thd->mem_root; param.table= table; - param.is_ror_scan= FALSE; param.remove_false_where_parts= true;
if (create_key_parts_for_pseudo_indexes(¶m, used_fields))
Ok, this one should be removed because it causes a failure like this: ==10660== Conditional jump or move depends on uninitialised value(s) ==10660== at 0xAC760A: sel_arg_range_seq_next(void*, st_key_multi_range*) (opt_range_mrr.cc:316) ==10660== by 0xACCD96: records_in_column_ranges(PARAM*, unsigned int, SEL_ARG*) (opt_range.cc:2864) ==10660== by 0xACD821: calculate_cond_selectivity_for_table(THD*, TABLE*, Item**) (opt_range.cc:3117) ==10660== by 0x742C69: make_join_statistics(JOIN*, List<TABLE_LIST>&, st_dynamic_array*) (sql_select.cc:4510) ==10660== by 0x738887: JOIN::optimize_inner() (sql_select.cc:1587) ==10660== by 0x736D09: JOIN::optimize() (sql_select.cc:1117) ==10660== by 0x74039B: mysql_select(THD*, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) (sql_select.cc:3822) ==10660== by 0x777D5F: mysql_explain_union(THD*, st_select_lex_unit*, select_result*) (sql_select.cc:25334)
@@ -10385,6 +10384,7 @@ ha_rows check_quick_select(PARAM *param, uint idx, bool index_only, uint keynr= param->real_keynr[idx]; DBUG_ENTER("check_quick_select");
+ param->is_ror_scan= FALSE; /* Handle cases when we don't have a valid non-empty list of range */ if (!tree) DBUG_RETURN(HA_POS_ERROR);
BR Sergei -- Sergei Petrunia, Software Developer MariaDB Corporation | Skype: sergefp | Blog: http://petrunia.net