diff options
author | Alexander Barkov <bar@mnogosearch.org> | 2014-11-18 16:33:29 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mnogosearch.org> | 2014-11-18 16:33:29 +0400 |
commit | e52b1637e0d59d3a4368fe2ce3a41c47d4041c2a (patch) | |
tree | cb9dcc3b2aec21fc88ec42106be0c3330de214f0 /sql | |
parent | 807934d08345c69ae31e0a0a1fcf7c92431d6204 (diff) | |
download | mariadb-git-e52b1637e0d59d3a4368fe2ce3a41c47d4041c2a.tar.gz |
MDEV-6950 Bad results with joins comparing DATE/DATETIME and INT/DECIMAL/DOUBLE/ENUM/VARCHAR columns
MDEV-6971 Bad results with joins comparing TIME and DOUBLE/DECIMAL columns
Disallow using indexes on non-temporal columns to optimize
ref access, range access and table elimination when the counterpart's
cmp_type is TIME_RESULT, e.g.:
SELECT * FROM t1 WHERE indexed_int_column=time_expression;
Only index on a temporal column can be used to optimize temporal comparison
operations.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/opt_range.cc | 2 | ||||
-rw-r--r-- | sql/opt_table_elimination.cc | 2 | ||||
-rw-r--r-- | sql/sql_select.cc | 4 |
3 files changed, 8 insertions, 0 deletions
diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 6871a6bd0af..7854a4b0081 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -8252,6 +8252,8 @@ get_mm_leaf(RANGE_OPT_PARAM *param, COND *conf_func, Field *field, !(conf_func->compare_collation()->state & MY_CS_BINSORT && (type == Item_func::EQUAL_FUNC || type == Item_func::EQ_FUNC))) goto end; + if (value->cmp_type() == TIME_RESULT && field->cmp_type() != TIME_RESULT) + goto end; if (key_part->image_type == Field::itMBR) { diff --git a/sql/opt_table_elimination.cc b/sql/opt_table_elimination.cc index 2ef565517b5..9c10790f9c0 100644 --- a/sql/opt_table_elimination.cc +++ b/sql/opt_table_elimination.cc @@ -1486,6 +1486,8 @@ void check_equality(Dep_analysis_context *ctx, Dep_module_expr **eq_mod, left->real_item()->type() == Item::FIELD_ITEM) { Field *field= ((Item_field*)left->real_item())->field; + if (right->cmp_type() == TIME_RESULT && field->cmp_type() != TIME_RESULT) + return; if (field->result_type() == STRING_RESULT) { if (right->result_type() != STRING_RESULT) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index ef69f8c11c8..ce17adf44d4 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4440,6 +4440,10 @@ add_key_field(JOIN *join, if (!eq_func) // eq_func is NEVER true when num_values > 1 return; + if ((*value)->cmp_type() == TIME_RESULT && + field->cmp_type() != TIME_RESULT) + return; + /* We can't use indexes when comparing a string index to a number or two strings if the effective collation |