Starting from MariaDB 10.3, the optimizer converts certain big IN predicates into IN subqueries.
That is, an IN predicate in the form
column [NOT] IN (const1, const2, .... )
is converted into an equivalent IN-subquery:
column [NOT] IN (select ... from temporary_table)
which opens new opportunities for the query optimizer.
The conversion happens if the following conditions are met:
0 to disable the optimization. If column is a key-prefix, MariaDB optimizer will process the condition
column [NOT] IN (const1, const2, .... )
by trying to construct a range access. If the list is large, the analysis may take a lot of memory and CPU time. The problem gets worse when column is a part of a multi-column index and the query has conditions on other parts of the index.
Conversion of IN predicates into a subqueries bypass the range analysis, which means the query optimization phase will use less CPU and memory.
Possible disadvantages of the conversion are are:
IN (...) are less precise.
© 2023 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.
https://mariadb.com/kb/en/conversion-of-big-in-predicates-into-subqueries/