Bug #67006 | unnecessary use of ICP for a single predicate | ||
---|---|---|---|
Submitted: | 28 Sep 2012 10:30 | Modified: | 10 Jan 2013 13:58 |
Reporter: | Arnaud Adant | Email Updates: | |
Status: | Duplicate | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S5 (Performance) |
Version: | 5.6 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[28 Sep 2012 10:30]
Arnaud Adant
[8 Oct 2012 12:14]
Olav Sandstå
The reason for ICP being used here is that: 1. The WHERE predicate is part of the table's condition also after optimization. The ICP code will try to push down any conditions that can be evaluated using the index. 2. The reason the WHERE predicate is part of the table's condition is the following code in test_if_ref() (in sql_optimizer.cc): if (right_item->const_item() && !(right_item->is_null())) { /* We can remove binary fields and numerical fields except float, as float comparison isn't 100 % secure We have to keep normal strings to be able to check for end spaces sergefp: the above seems to be too restrictive. Counterexample: create table t100 (v varchar(10), key(v)) default charset=latin1; insert into t100 values ('a'),('a '); explain select * from t100 where v='a'; The EXPLAIN shows 'using Where'. Running the query returns both rows, so it seems there are no problems with endspace in the most frequent case? */ if (field->binary() && field->real_type() != MYSQL_TYPE_STRING && field->real_type() != MYSQL_TYPE_VARCHAR && (field->type() != MYSQL_TYPE_FLOAT || field->decimals() == 0)) { return !right_item->save_in_field_no_warnings(field, true); } } In this case we include the WHERE predicate in the table's condition even if it is handled by the ref access is due to following: a) The field's/table's character is different from the default character set. b) It is a VARCHAR field. As the comment in the above code suggests, this might be too restrictive.
[10 Jan 2013 13:58]
Erlend Dahl
Fixed as a duplicate of bug#66983