!!! WORK IN PROGRESS !!!
Certain kinds of IN-subqueries canot be flattened into semi-joins. These subqueries can be both correlated or non-correlated. In order to provide consistent performance in all cases, MariaDB provides several alternative strategies for these types of subqueries. Whenever several strategies are possible, the optimizer chooses the optimal one based on cost estimates.
The two primary strategies are materialization (also called outside-in materialization), and in-to-exists tranformation. Materialization is applicable only for non-correlated subqueries, while in-to-exist can be used both for correlated and non-correlated subqueries.
An IN subquery cannot be flattened into a semi-join in the following cases:
- Subquery in a disjunction (OR)
SELECT ... FROM ... WHERE expr IN (SELECT ... ) OR expr
SELECT Name FROM Country WHERE (Code IN (select Country from City where City.Population > 100000) OR Name LIKE 'L%') AND surfacearea > 1000000;
- Negated subquery predicate (NOT IN)
- Subqueries with GROUP BY, HAVING, and aggregate functions
- Subquery in the SELECT or HAVING clause
SELECT ... WHERE expr IN (SELECT ... ) OR ...
- Subquery with a UNION
Materialization for non-correlated IN-subqueries
NULL-aware efficient execution
- Example improvement over MySQL 5.x
- General performance guidelines
In certain cases it may be necessary to override the choice of the optimizer. Typically this is needed for benchmarking or testing purposes, or to mimic the behavior of an older version of the server, or if the optimizer made a poor choice.
All the above strategies can be controlled via the optimizer_switch system variable.
In some very special cases, even if materialization was forced, it may still be impossible to
In addition to this switch, the system variable
rowid_merge_buff_size controls the maximum memory available
to the Rowid-merge algorithm. By default it is: TODO.
Example: To tell the server that all non-semijoin ...