Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-21958

Query having many NOT-IN clauses running forever and causing available free memory to use completely

Details

    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

          Activity

            Pushed the "conservative" fix.

            psergei Sergei Petrunia added a comment - Pushed the "conservative" fix.

            ccalender "conservative" means this fix:
            https://jira.mariadb.org/browse/MDEV-21958?focusedCommentId=171309&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-171309
            It implements the "(Very basic) Make NOT-IN non-sargable" suggestion. It solves the issue when the column col in the "col NOT IN (...)" is the primary (or the unique secondary) key. This was the case in the customer's complaint.

            psergei Sergei Petrunia added a comment - ccalender "conservative" means this fix: https://jira.mariadb.org/browse/MDEV-21958?focusedCommentId=171309&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-171309 It implements the "(Very basic) Make NOT-IN non-sargable" suggestion. It solves the issue when the column col in the "col NOT IN (...)" is the primary (or the unique secondary) key. This was the case in the customer's complaint.

            A question from yesterday's optimizer call: Will the fix for MDEV-9750 help with this?
            The answer is: "not much", unless one sets optimizer_max_sel_arg_weight really low.

            The problem in this MDEV is N^2 memory usage. Let's look the example data from here:

            https://jira.mariadb.org/browse/MDEV-21958?focusedCommentId=170462&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-170462

            n_ranges	SEL_ARGS	SEL_ARGs per range
            11	11	1.00
            21	43	2.05
            51	199	3.90
            101	659	6.52
            201	2329	11.59
            401	8669	21.62
            601	19009	31.63
            801	33349	41.63
            1001	51689	51.64
            2001	203389	101.64
            4001	806789	201.65
            

            here n_ranges=4000 , SEL_ARGs=800K.

            The default max_sel_arg_weight is 32K. Before we construct an OR-list of 32K elements (and hit the limit),we may allocate up to

            32K ^ 2 = 1024 * KK = 1024M= 1G
            

            SEL_ARG objects. Each is ~100 bytes, so we'll use up to ~100G memory.

            psergei Sergei Petrunia added a comment - A question from yesterday's optimizer call: Will the fix for MDEV-9750 help with this? The answer is: "not much", unless one sets optimizer_max_sel_arg_weight really low . The problem in this MDEV is N^2 memory usage. Let's look the example data from here: https://jira.mariadb.org/browse/MDEV-21958?focusedCommentId=170462&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-170462 n_ranges SEL_ARGS SEL_ARGs per range 11 11 1.00 21 43 2.05 51 199 3.90 101 659 6.52 201 2329 11.59 401 8669 21.62 601 19009 31.63 801 33349 41.63 1001 51689 51.64 2001 203389 101.64 4001 806789 201.65 here n_ranges=4000 , SEL_ARGs=800K. The default max_sel_arg_weight is 32K. Before we construct an OR-list of 32K elements (and hit the limit),we may allocate up to 32K ^ 2 = 1024 * KK = 1024M= 1G SEL_ARG objects. Each is ~100 bytes, so we'll use up to ~100G memory.

            Ok, the "conservative" fix that was pushed now has its own MDEV: MDEV-24711

            psergei Sergei Petrunia added a comment - Ok, the "conservative" fix that was pushed now has its own MDEV: MDEV-24711

            Closing this one.
            Followup task: MDEV-26856.

            psergei Sergei Petrunia added a comment - Closing this one. Followup task: MDEV-26856 .

            People

              psergei Sergei Petrunia
              suresh.ramagiri@mariadb.com suresh ramagiri
              Votes:
              1 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.