Notes when an index cannot be used
MariaDB starting with 10.6.16
This is a new note added in 10.6.16
Warning about incompatible index comparison
A frequent mistake database developers do is to compare an indexed column with another column that is not compatible with the indexed column. For example comparing string columns with number columns or using incompatible character sets or collations.
Because of this we have introduced notes (low severity warnings) when an indexed column cannot use the index to lookup rows.
The warnings are of type different types:
If one compares an indexed columnc with a value of a different type one will get a warning like the following:
Note 1105 Cannot use key `PRIMARY` part[0] for lookup: `test`.`t1`.`id` of type `char` = "1" of type `bigint`
If one compares indexed character columns with a value of a a not compatible collation one will get a warning like the following:
Note 1105 Cannot use key `s2` part[0] for lookup: `test`.`t1`.`s2` of collation `latin1_swedish_ci` = "'a' collate latin1_german1_ci" of collation `latin1_german1_ci`
Note that in MariadB 10.6 -> 11.3 we will use the error 1105 (Unknown error) as we cannot add an new error code in a GA version. In 11.4 we will change this to be an unique error code.
Enabling the note
By default, the warning is only shown when on executes EXPLAIN on a query. If one wants to enable it for all queries, one can do with the option/server variable:
In config file: --note-verbosity=all As a server variable: @@note_verbosity="all";
note_verbosity
is a set variable that describes with note categories one want to get notes for.
It can have one or many of the following options:
Option | Description |
---|---|
basic | All old notes. |
unusable_keys | Give warnings for unusable keys for SELECT, DELETE and UPDATE. |
explain | Give warnings about unusable keys for EXPLAIN. |
One can also set note_verbosity
to the value of all
to set all options.
Enabling warnings and notes for the slow query log
One can get the note about incompatible keys also in the slow query log by adding the option warnings
in the log_slow_verbosity
option/variable. It will automatically be enabled if one uses log_slow_verbosity=all
.
In config file: --log-slow-verbosity=warnings As a server variable: @@log_slow_verbosity="all";