From fd20f40166e0dd9db8c61596d8ea3f29ba26a5bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=A8=E8=B6=85?= Date: Mon, 14 Oct 2024 15:42:52 +0800 Subject: [PATCH] bug-110125 When the index field = function constant, and the index field is unsigned number, the result type of the function constant is string result, the execution plan is determined to go through the index filtering, not Impossible WHERE, the result of the function is forced to be converted into unsigned number to do index scanning to match, will be truncate to 0, resulting in the result is wrong --- sql/range_optimizer/range_analysis.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sql/range_optimizer/range_analysis.cc b/sql/range_optimizer/range_analysis.cc index 98b03458fb8a..a8550257a6ac 100644 --- a/sql/range_optimizer/range_analysis.cc +++ b/sql/range_optimizer/range_analysis.cc @@ -1639,6 +1639,26 @@ static SEL_ROOT *get_mm_leaf(THD *thd, RANGE_OPT_PARAM *param, Item *cond_func, goto end; } } + } else if (type == Item_func::EQ_FUNC && value->const_item() && + (field->result_type() == INT_RESULT || + field->result_type() == REAL_RESULT || + field->result_type() == DECIMAL_RESULT) && + field->is_unsigned()) { + if ((value->result_type() == INT_RESULT || + value->result_type() == REAL_RESULT || + value->result_type() == DECIMAL_RESULT) && + !(value)->unsigned_flag) { + impossible_cond_cause = "unsigned_num_cannot_be_negative"; + tree->type = SEL_ROOT::Type::IMPOSSIBLE; + goto end; + } else if (value->result_type() == STRING_RESULT) { + double nr = value->val_real(); + if (nr < 0) { + impossible_cond_cause = "unsigned_num_cannot_be_negative"; + tree->type = SEL_ROOT::Type::IMPOSSIBLE; + goto end; + } + } } switch (type) {