not_null_range_scan Optimization
Description
CREATE TABLE items (
price DECIMAL(8,2),
weight DECIMAL(8,2),
...
INDEX(weight)
);-- Find items that cost more than 1000 $currency_units per kg:
SET optimizer_switch='not_null_range_scan=ON';
EXPLAIN
SELECT * FROM items WHERE items.price > items.weight / 1000;weight IS NOT NULL+------+-------------+-------+-------+---------------+--------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+-------+---------------+--------+---------+------+------+-------------+
| 1 | SIMPLE | items | range | NULL | weight | 5 | NULL | 1 | Using where |
+------+-------------+-------+-------+---------------+--------+---------+------+------+-------------+Controlling the Optimization
Optimizer Trace
See Also
Last updated
Was this helpful?

