diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 7a6a72af264..0d5628070eb 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -2200,6 +2200,8 @@ class Item_func_in final : public Item_func_opt_neg { /// Set to true when values in const array are populated bool m_populated{false}; + bool need_populate() { return m_need_populate; } + private: /// Set to true if all values in IN-list are const bool m_values_are_const{true}; diff --git a/sql/range_optimizer/range_analysis.cc b/sql/range_optimizer/range_analysis.cc index 624cd072268..79253ed6bad 100644 --- a/sql/range_optimizer/range_analysis.cc +++ b/sql/range_optimizer/range_analysis.cc @@ -174,6 +174,10 @@ static SEL_TREE *get_func_mm_tree_from_in_predicate( Item_func_in *op, bool is_negated) { if (param->has_errors()) return nullptr; + if (thd->lex->is_ps_prepare() && op->need_populate()) { + return nullptr; + } + // Populate array as we need to examine its values here if (op->m_const_array != nullptr && !op->m_populated) { op->populate_bisection(thd); diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 1a1d13fe7ab..5698aa27554 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -4708,6 +4708,10 @@ struct LEX : public Query_tables_list { THD *thd, Query_block *current_query_block, Item *where_clause, Item *having_clause, enum_parsing_context ctx); + inline bool is_ps_prepare() { + return (context_analysis_only & CONTEXT_ANALYSIS_ONLY_PREPARE); + } + inline bool is_ps_or_view_context_analysis() { return (context_analysis_only & (CONTEXT_ANALYSIS_ONLY_PREPARE | CONTEXT_ANALYSIS_ONLY_VIEW));