Bug #113570 | composite index with the indexed expression "is not null" not being used | ||
---|---|---|---|
Submitted: | 5 Jan 2024 23:35 | Modified: | 8 Jan 2024 11:26 |
Reporter: | Felix Livni | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | 8.0.33 | OS: | Ubuntu |
Assigned to: | CPU Architecture: | Any | |
Tags: | composite-index, INDEX, indexed-expression |
[5 Jan 2024 23:35]
Felix Livni
[7 Jan 2024 20:01]
Knut Anders Hatlen
I believe this is a documented limitation. https://dev.mysql.com/doc/refman/8.0/en/create-index.html#create-index-functional-key-part... says: > Functional indexes are implemented as hidden virtual generated columns, which has these implications: > (...) > Functional key parts inherit all restrictions that apply to generated columns. https://dev.mysql.com/doc/refman/8.0/en/generated-column-index-optimizations.html says: > MySQL supports indexes on generated columns >(...) > The optimization applies to these operators: =, <, <=, >, >=, BETWEEN, and IN(). The "column2 is not null" predicate in the query does not use any of those operators, so the optimization does not apply. A workaround is to add "= true" to the predicate to transform it to one where the optimization does apply: mysql> explain analyze select * from appointments where user_id = 7 and recurrence_rule is not null = true \G *************************** 1. row *************************** EXPLAIN: -> Index lookup on appointments using idx1 ((recurrence_rule is not null)=true, user_id=7) (cost=0.35 rows=1) (actual time=0.0563..0.0563 rows=0 loops=1) 1 row in set (0.00 sec)
[8 Jan 2024 11:26]
MySQL Verification Team
Hi Mr. Livni, Thank you for your bug report. We managed to repeat the behaviour that you reported. However, we have to agree with our colleague that this behaviour is intended and fully documented here: https://dev.mysql.com/doc/refman/8.0/en/create-index.html#create-index-functional-key-part... https://dev.mysql.com/doc/refman/8.0/en/generated-column-index-optimizations.html Not a bug.