SET optimizer_switch = ’condition_fanout_filter=off’; 

Or, for a given query, using an optimizer hint: 

SELECT /*+ SET_VAR(optimizer_switch = ’condition_fanout_filter=off’) */ ... 

## 8.2.1.14 Constant-Folding Optimization 

Comparisons between constants and column values in which the constant value is out of range or of the wrong type with respect to the column type are now handled once during query optimization rather row-by- row than during execution. The comparisons that can be treated in this manner are > , >= , < , <= , <> / != , = , and <=> . 

Consider the table created by the following statement: 

CREATE TABLE t (c TINYINT UNSIGNED NOT NULL); 

The WHERE  condition in the query SELECT * FROM t WHERE c < 256  contains the integral constant 256 which is out of range for a TINYINT UNSIGNED  column. Previously, this was handled by treating both operands as the larger type, but now, since any allowed value for c  is less than the constant, the WHERE  expression can instead be folded as WHERE 1 , so that the query is rewritten as SELECT * FROM t WHERE 1 . 

This makes it possible for the optimizer to remove the WHERE  expression altogether. If the column c  were nullable (that is, defined only as TINYINT UNSIGNED ) the query would be rewritten like this: 

SELECT * FROM t WHERE ti IS NOT NULL 

Folding is performed for constants compared to supported MySQL column types as follows: 

• Integer column type.  Integer types are compared with constants of the following types as described here: 

• Integer value.  If the constant is out of range for the column type, the comparison is folded to 1  or IS NOT NULL , as already shown. 

If the constant is a range boundary, the comparison is folded to = . For example (using the same table as already defined): 

mysql> EXPLAIN SELECT * FROM t WHERE c >= 255; *************************** 1. row *************************** id: 1 select_type: SIMPLE table: t partitions: NULL type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 5 filtered: 20.00 Extra: Using where 1 row in set, 1 warning (0.00 sec) mysql> SHOW WARNINGS; *************************** 1. row *************************** Level: Note Code: 1003 Message: /* select#1 */ select ‘test‘.‘t‘.‘ti‘ AS ‘ti‘ from ‘test‘.‘t‘ where (‘test‘.‘t‘.‘ti‘ = 255) 

