Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
10.2.21, 10.4.12
-
CentOS/RHEL 7
Description
One of the customer reported that running a huge query (25KB) having a NOT-IN clause with many values running forever, causing the server to use available free memory and invoking the oom-killer to kill the mysqld process. Same behavior when tried to get the `EXPLAIN PLAN`.
Initially, checking the existing bugs, found following two:
MDEV-9764 - MariaDB does not limit memory used for range optimization
MDEV-9750 - extended_keys=on causing the memory exhaustion on queries having multiple IN/NOT IN using INNODB
As per those two bugs, we have told customer to turn off the "extended_keys" and check, but it's not helping out.
Further, locally on the MariaDB Server versions 10.2.21, 10.3.14 and 10.4.12(ES), I can reproduce the same behavior on an empty table. Here as well, neither setting "extended_keys=off" helped nor the "max_session_mem_used" system variable worked to avoid the exhaustion of available free memory.
Repro steps, I will share it separately.
Maybe, we need to understand how can we handle this case?
Thank You.
Attachments
Issue Links
- causes
-
MDEV-24444 ASAN use-after-poison in Item_func_in::get_func_mm_tree with NOT IN query
-
- Closed
-
- includes
-
MDEV-24711 Make "unique_key NOT IN (...)" conditions non-sargable
-
- Closed
-
- relates to
-
MDEV-26856 Queries with many NOT IN clauses or ORs use a lot of memory
-
- Open
-
-
MDEV-9750 Quick memory exhaustion with 'extended_keys=on' on queries having multiple 'IN'/'NOT IN' using InnoDB
-
- Closed
-
-
MDEV-23634 Select query hanged the server and leads to OOM in MariaDB 10.4.14
-
- Closed
-
- mentioned in
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
So, let's consider what the optimizer does for
...
The first line
produces N+1 ranges:
(-inf; c11) U (c11, c12) U (c12, ...) ... U (..., c1N) U (c1N; +inf)
Let's assume it's N ranges to simplify computations.
The same goes for every line.
Now, let's try to computing the AND, assuming all constants unequal.
AND-ing two interval lists with X and Y intervals in the worst case produces X+Y-1 intervals.
This means we will finally produce an interval list with
N + N + N + ... (M times) = N*M
intervals.
This is already bad enough, because it's 790 *900=711000 intervals.
Another possible is intermediate results. They are allocated on MEM_ROOT. If the space is not reused (and I think it is not), this means range optimizer will consume the memory for N *M/2 * M intervals