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

GROUP_CONCAT with ORDER BY inside takes a lot of memory while it's executed

Details

    • 10.1.14, 10.1.18, 10.1.19

    Description

      A query like

      SELECT GROUP_CONCAT( seq, seq, seq, seq, seq, seq, seq, seq ORDER BY 2,1,3,4,6,5,8,7 ) AS cfield1 FROM seq_1_to_50000000

      easily uses up to 4-5 Gb memory while it's running.

      <montywi> everything has limits
      <montywi> even for filesort; For bigger things it should always hit disk, never memory
      ...
      <montywi> the problem is that when doing a sort, we create a sorted tree in memory
      <montywi> however there is no memory check for this
      <montywi> so this can be any size
      <montywi> Normally it would make sense to limit this to group_concat_max_length, but I fear that would break things, as we sort records there, which can have a notable overhead
      <montywi> So I have limit it to max_heap_table_size

      Attachments

        Issue Links

          Activity

            elenst Elena Stepanova created issue -
            elenst Elena Stepanova made changes -
            Field Original Value New Value
            Priority Major [ 3 ] Minor [ 4 ]
            serg Sergei Golubchik made changes -
            Assignee Elena Stepanova [ elenst ] Oleksandr Byelkin [ sanja ]
            serg Sergei Golubchik made changes -
            Priority Minor [ 4 ] Major [ 3 ]
            serg Sergei Golubchik added a comment - - edited

            There are two possible approaches:

            1. introduce some some limit for a max tree size. when the tree grows that large, a special "cleanup" procedure is executed, that keeps first group_concat_max_len bytes of values (or first group_concat_max_len values, if that's much simpler) and removes all larger values. then continue inserting into the tree
            2. use priority queue, not a tree. never grows large and doesn't need cleanups. but higher up-front memory cost if group_concat_max_len limit is rarely reached
            serg Sergei Golubchik added a comment - - edited There are two possible approaches: introduce some some limit for a max tree size. when the tree grows that large, a special "cleanup" procedure is executed, that keeps first group_concat_max_len bytes of values (or first group_concat_max_len values, if that's much simpler) and removes all larger values. then continue inserting into the tree use priority queue, not a tree. never grows large and doesn't need cleanups. but higher up-front memory cost if group_concat_max_len limit is rarely reached
            ratzpo Rasmus Johansson (Inactive) made changes -
            Sprint 10.1.14 [ 51 ]
            ratzpo Rasmus Johansson (Inactive) made changes -
            Rank Ranked lower
            sanja Oleksandr Byelkin made changes -
            Status Open [ 1 ] In Progress [ 3 ]

            revision-id: eb9fab76fb4322a7821e6502e6303ed381624429 (mariadb-10.1.13-18-geb9fab7)
            parent(s): 732adec0a4c75d99389230feeb0deca0ad668de7
            committer: Oleksandr Byelkin
            timestamp: 2016-05-04 19:15:31 +0200
            message:

            MDEV-9531: GROUP_CONCAT with ORDER BY inside takes a lot of memory while it's executed

            Limitation added to Red-Black tree.

            —

            sanja Oleksandr Byelkin added a comment - revision-id: eb9fab76fb4322a7821e6502e6303ed381624429 (mariadb-10.1.13-18-geb9fab7) parent(s): 732adec0a4c75d99389230feeb0deca0ad668de7 committer: Oleksandr Byelkin timestamp: 2016-05-04 19:15:31 +0200 message: MDEV-9531 : GROUP_CONCAT with ORDER BY inside takes a lot of memory while it's executed Limitation added to Red-Black tree. —
            sanja Oleksandr Byelkin made changes -
            Assignee Oleksandr Byelkin [ sanja ] Sergei Golubchik [ serg ]
            Status In Progress [ 3 ] In Review [ 10002 ]
            serg Sergei Golubchik made changes -
            Assignee Sergei Golubchik [ serg ] Oleksandr Byelkin [ sanja ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            sanja Oleksandr Byelkin made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]
            sanja Oleksandr Byelkin made changes -
            Status In Progress [ 3 ] Stalled [ 10000 ]

            I remove variable and made automatic minimum print output calculation:

            revision-id: 13b5098fcaa888173472d255e29aff22bcc5baae (mariadb-10.1.13-18-g13b5098)
            parent(s): 732adec0a4c75d99389230feeb0deca0ad668de7
            committer: Oleksandr Byelkin
            timestamp: 2016-06-28 10:59:59 +0200
            message:

            MDEV-9531: GROUP_CONCAT with ORDER BY inside takes a lot of memory while it's executed

            Limitation added to Red-Black tree.

            —

            sanja Oleksandr Byelkin added a comment - I remove variable and made automatic minimum print output calculation: revision-id: 13b5098fcaa888173472d255e29aff22bcc5baae (mariadb-10.1.13-18-g13b5098) parent(s): 732adec0a4c75d99389230feeb0deca0ad668de7 committer: Oleksandr Byelkin timestamp: 2016-06-28 10:59:59 +0200 message: MDEV-9531 : GROUP_CONCAT with ORDER BY inside takes a lot of memory while it's executed Limitation added to Red-Black tree. —
            sanja Oleksandr Byelkin made changes -
            Assignee Oleksandr Byelkin [ sanja ] Sergei Golubchik [ serg ]
            Status Stalled [ 10000 ] In Review [ 10002 ]
            serg Sergei Golubchik made changes -
            Assignee Sergei Golubchik [ serg ] Oleksandr Byelkin [ sanja ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            serg Sergei Golubchik made changes -
            Assignee Oleksandr Byelkin [ sanja ] Sergei Golubchik [ serg ]
            serg Sergei Golubchik made changes -
            Status Stalled [ 10000 ] In Review [ 10002 ]
            serg Sergei Golubchik made changes -
            Sprint 10.1.14 [ 51 ] 10.1.14, 10.1.18 [ 51, 98 ]
            serg Sergei Golubchik made changes -
            Assignee Sergei Golubchik [ serg ] Oleksandr Byelkin [ sanja ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            sanja Oleksandr Byelkin made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]

            revision-id: f5a5ac49b5ff7b04aa816d33ca44d9fe88a94498 (mariadb-10.1.17-23-gf5a5ac4)
            parent(s): d30809a3cde823ad696304a941afe5a562bfa3ed
            committer: Oleksandr Byelkin
            timestamp: 2016-09-26 16:21:18 +0200
            message:

            MDEV-9531: GROUP_CONCAT with ORDER BY inside takes a lot of memory while it's executed

            Limitation added to Red-Black tree.

            —

            sanja Oleksandr Byelkin added a comment - revision-id: f5a5ac49b5ff7b04aa816d33ca44d9fe88a94498 (mariadb-10.1.17-23-gf5a5ac4) parent(s): d30809a3cde823ad696304a941afe5a562bfa3ed committer: Oleksandr Byelkin timestamp: 2016-09-26 16:21:18 +0200 message: MDEV-9531 : GROUP_CONCAT with ORDER BY inside takes a lot of memory while it's executed Limitation added to Red-Black tree. —
            sanja Oleksandr Byelkin made changes -
            Assignee Oleksandr Byelkin [ sanja ] Sergei Golubchik [ serg ]
            serg Sergei Golubchik made changes -
            Assignee Sergei Golubchik [ serg ] Oleksandr Byelkin [ sanja ]
            ratzpo Rasmus Johansson (Inactive) made changes -
            Sprint 10.1.14, 10.1.18 [ 51, 98 ] 10.1.14, 10.1.18, 10.1.19 [ 51, 98, 109 ]
            ratzpo Rasmus Johansson (Inactive) made changes -
            Rank Ranked higher
            serg Sergei Golubchik made changes -
            Assignee Oleksandr Byelkin [ sanja ] Sergei Golubchik [ serg ]
            serg Sergei Golubchik made changes -
            Status In Progress [ 3 ] Stalled [ 10000 ]
            serg Sergei Golubchik made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]
            serg Sergei Golubchik made changes -
            Status In Progress [ 3 ] Stalled [ 10000 ]

            please, review commit 73b12b0cebc in bb-10.1-serg

            serg Sergei Golubchik added a comment - please, review commit 73b12b0cebc in bb-10.1-serg
            serg Sergei Golubchik made changes -
            Assignee Sergei Golubchik [ serg ] Oleksandr Byelkin [ sanja ]
            Status Stalled [ 10000 ] In Review [ 10002 ]

            OK to push.

            sanja Oleksandr Byelkin added a comment - OK to push.
            sanja Oleksandr Byelkin made changes -
            Assignee Oleksandr Byelkin [ sanja ] Sergei Golubchik [ serg ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            serg Sergei Golubchik made changes -
            Component/s OTHER [ 10125 ]
            Fix Version/s 10.1.39 [ 23305 ]
            Fix Version/s 10.2.24 [ 23308 ]
            Fix Version/s 10.3.15 [ 23309 ]
            Fix Version/s 10.4.5 [ 23311 ]
            Fix Version/s 10.1 [ 16100 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 73902 ] MariaDB v4 [ 150087 ]
            elenst Elena Stepanova made changes -

            People

              serg Sergei Golubchik
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              3 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.