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

Unnecessary 'cascade' memory allocation for every updated row when there is no FOREIGN KEY

Details

    Description

      MySQL 5.7.2 introduced heap memory allocations for every updated row:

      	if (node->cascade_heap) {
      		mem_heap_empty(node->cascade_heap);
      	} else {
      		node->cascade_heap = mem_heap_create(128);
      	}
       
      	mem_heap_allocator<upd_node_t*> mem_heap_ator(node->cascade_heap);
       
      	cascade_upd_nodes = new
      		(mem_heap_ator.allocate(sizeof(upd_cascade_t)))
      		upd_cascade_t(deque_mem_heap_t(mem_heap_ator));
       
      	new_upd_nodes = new
      		(mem_heap_ator.allocate(sizeof(upd_cascade_t)))
      		upd_cascade_t(deque_mem_heap_t(mem_heap_ator));
       
      	processed_cascades = new
      		(mem_heap_ator.allocate(sizeof(upd_cascade_t)))
      		upd_cascade_t(deque_mem_heap_t(mem_heap_ator));
      

      If the mem_heap_create(128) was replaced with a larger parameter, then these allocations could reuse the same memory heap for every updated row. It would still be unnecessary to allocate the memory when there are no FOREIGN KEY ON (UPDATE|DELETE) (SET NULL|CASCADE) constraints, but we would avoid the multiple calls to mem_heap_create_block_func() on every updated row.

      Attachments

        Issue Links

          Activity

            marko Marko Mäkelä created issue -
            marko Marko Mäkelä made changes -
            Field Original Value New Value
            Fix Version/s 10.3 [ 22126 ]
            marko Marko Mäkelä made changes -
            Affects Version/s 10.3.0 [ 22127 ]
            marko Marko Mäkelä made changes -
            Status Open [ 1 ] Confirmed [ 10101 ]

            As noted in MDEV-14958, MySQL 5.7.21 removes this code and reverts back to call stack recursion. To compensate for the increased stack memory usage, it limits the maximum depth of FOREIGN KEY constraints from 255 to 15.
            Bug #26191879 FOREIGN KEY CASCADES USE EXCESSIVE MEMORY

            marko Marko Mäkelä added a comment - As noted in MDEV-14958 , MySQL 5.7.21 removes this code and reverts back to call stack recursion. To compensate for the increased stack memory usage, it limits the maximum depth of FOREIGN KEY constraints from 255 to 15. Bug #26191879 FOREIGN KEY CASCADES USE EXCESSIVE MEMORY
            marko Marko Mäkelä made changes -
            marko Marko Mäkelä made changes -
            Status Confirmed [ 10101 ] In Progress [ 3 ]
            marko Marko Mäkelä made changes -

            The MySQL 5.7.21 fix also appears to fix MDEV-15199. Thus, we do not seem to have any other choice than to merge the fix from MySQL.
            But, we can try to reduce the stack memory usage for each iteration.

            marko Marko Mäkelä added a comment - The MySQL 5.7.21 fix also appears to fix MDEV-15199 . Thus, we do not seem to have any other choice than to merge the fix from MySQL. But, we can try to reduce the stack memory usage for each iteration.
            marko Marko Mäkelä made changes -
            marko Marko Mäkelä made changes -
            Fix Version/s 10.3.5 [ 22905 ]
            Fix Version/s 10.2.13 [ 22910 ]
            Fix Version/s 10.2 [ 14601 ]
            Fix Version/s 10.3 [ 22126 ]
            Resolution Fixed [ 1 ]
            Status In Progress [ 3 ] Closed [ 6 ]
            marko Marko Mäkelä made changes -
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 83352 ] MariaDB v4 [ 153081 ]
            mariadb-jira-automation Jira Automation (IT) made changes -
            Zendesk Related Tickets 187744

            People

              marko Marko Mäkelä
              marko Marko Mäkelä
              Votes:
              0 Vote for this issue
              Watchers:
              2 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.