SELECT t.Node,t.ParentNode,t.EmployeeID,p.Depth + 1 as Depth, CONCAT(p.Lineage, t.ParentNode, '/')
FROM tree t JOIN prev p ON t.ParentNode = p.Node
)
SELECT * FROM prev;
WITH RECURSIVE prev AS (
SELECT * FROM tree WHERE ParentNode ISNULL
UNION
SELECT t.Node,t.ParentNode,t.EmployeeID,p.Depth + 1 as Depth, CONCAT(p.Lineage, t.ParentNode, '/')
FROM prev p JOIN tree t ON t.ParentNode = p.Node
)
UPDATE tree t, prev p SET t.Depth=p.Depth, t.Lineage=p.Lineage WHERE t.Node=p.Node;
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax touse near 'UPDATE tree t, prev p SET t.Depth=p.Depth, t.Lineage=p.Lineage WHERE t.Node=p.No'at line 7
valerii no, it is not. psergei and igor, can you estimate how much work is still needed to get this task done? I will change the status to stalled for now and will remove the fixVersion until we have a better idea about the task/open effort. It does not make sense to just add 11.2 as fixVersion for now, as this does not seem to be realistic
Ralf Gebhardt
added a comment - valerii no, it is not. psergei and igor , can you estimate how much work is still needed to get this task done? I will change the status to stalled for now and will remove the fixVersion until we have a better idea about the task/open effort. It does not make sense to just add 11.2 as fixVersion for now, as this does not seem to be realistic
For people this bang their head on the wall in 2024 with this long time issue not resolved, like me, I finally found a solution that is not perfect but works, use a temporary table to save CTE result then update the main table. In the example above :
CREATE TEMPORARY TABLE tmp_table
WITH RECURSIVE prev AS (
SELECT * FROM tree WHERE ParentNode IS NULL
UNION
SELECT t.Node,t.ParentNode,t.EmployeeID,p.Depth + 1 as Depth, CONCAT(p.Lineage, t.ParentNode, '/')
FROM prev p JOIN tree t ON t.ParentNode = p.Node
)
SELECT * FROM prev;
UPDATE tree t, tmp_table p SET t.Depth=p.Depth, t.Lineage=p.Lineage WHERE t.Node=p.Node;
PierreCar
added a comment - For people this bang their head on the wall in 2024 with this long time issue not resolved, like me, I finally found a solution that is not perfect but works, use a temporary table to save CTE result then update the main table. In the example above :
CREATE TEMPORARY TABLE tmp_table
WITH RECURSIVE prev AS (
SELECT * FROM tree WHERE ParentNode IS NULL
UNION
SELECT t.Node,t.ParentNode,t.EmployeeID,p.Depth + 1 as Depth, CONCAT(p.Lineage, t.ParentNode, '/')
FROM prev p JOIN tree t ON t.ParentNode = p.Node
)
SELECT * FROM prev;
UPDATE tree t, tmp_table p SET t.Depth=p.Depth, t.Lineage=p.Lineage WHERE t.Node=p.Node;
Note: the most common use case is when the UPDATE modifies a base table, not the CTE. This is what the examples in this MDEV do.
It is also possible to think of UPDATE changing the CTE, which translates into changes to the table used in the CTE. Similar to updatable VIEWs.
Example (also at https://dbfiddle.uk/Q1p7ImR2)
createtable t1 (pk intprimarykey, a int);
insertinto t1 values (1,1),(2,2),(3,3),(4,4);
with T as (select pk, a from t1 where pk <3 ) update T set a=a*1000;
select * from t1;
pk a
1 1000
2 2000
3 3
4 4
SQL Server supports this, PostgreSQL doesn't. I haven't checked what the SQL Standard says about this.
I think update-through-CTE should be outside of scope of this MDEV.
Sergei Petrunia
added a comment - - edited Note: the most common use case is when the UPDATE modifies a base table, not the CTE. This is what the examples in this MDEV do.
It is also possible to think of UPDATE changing the CTE, which translates into changes to the table used in the CTE. Similar to updatable VIEWs.
Example (also at https://dbfiddle.uk/Q1p7ImR2 )
create table t1 (pk int primary key , a int );
insert into t1 values (1,1),(2,2),(3,3),(4,4);
with T as ( select pk, a from t1 where pk <3 ) update T set a=a*1000;
select * from t1;
pk a
1 1000
2 2000
3 3
4 4
SQL Server supports this, PostgreSQL doesn't. I haven't checked what the SQL Standard says about this.
I think update-through-CTE should be outside of scope of this MDEV.
A preliminary patch for this task that implemented UPDATE command with updatable CTEs was pushed into 10.5-mdev-18511 in October 2020. The patch contains a lot of test cases demonstrating how the feature worked for 10.5.
Actually it was the patch for MDEV-23552. Unfortunately the code cannot be applied directly to the current 10.4+ because the upper level architecture for UPDATE/DELETE has been changed by MDEV-28883. However CTE related code was incorporated into 10.5 when the CTE implementation was redesigned. One of the reason why MDEV-28883 was initiated was the fact that I experienced serious difficulties with implementation of MDEV-23552. Even more difficulties were expected with implementation of a similar task for DELETE commands. serg, I've looked at at the support case 201775 and I don't understand what the ticket has to do with MDEV-18511.
I also don't understand why MDEV-21012 is considered as a sub-task of this task.
Igor Babaev (Inactive)
added a comment - - edited A preliminary patch for this task that implemented UPDATE command with updatable CTEs was pushed into 10.5-mdev-18511 in October 2020. The patch contains a lot of test cases demonstrating how the feature worked for 10.5.
Actually it was the patch for MDEV-23552 . Unfortunately the code cannot be applied directly to the current 10.4+ because the upper level architecture for UPDATE/DELETE has been changed by MDEV-28883 . However CTE related code was incorporated into 10.5 when the CTE implementation was redesigned. One of the reason why MDEV-28883 was initiated was the fact that I experienced serious difficulties with implementation of MDEV-23552 . Even more difficulties were expected with implementation of a similar task for DELETE commands.
serg , I've looked at at the support case 201775 and I don't understand what the ticket has to do with MDEV-18511 .
I also don't understand why MDEV-21012 is considered as a sub-task of this task.
MYSQL 8.0 does not allow update updatable CTE/derived tables.
MYSQL 8.0 merges mergeable derived tables used in multi-update/multi-delete. MariaDB always materializes such derived tables.
Igor Babaev (Inactive)
added a comment - - edited MYSQL 8.0 does not allow update updatable CTE/derived tables.
MYSQL 8.0 merges mergeable derived tables used in multi-update/multi-delete. MariaDB always materializes such derived tables.
People
Sergei Petrunia
Daniel Black
Votes:
11Vote for this issue
Watchers:
23Start watching this issue
Dates
Created:
Updated:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":891.3000001907349,"ttfb":233.69999980926514,"pageVisibility":"visible","entityId":72459,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"c385c457-afe7-45a4-a177-fa5eba6791dc","navigationType":0,"readyForUser":991.3999996185303,"redirectCount":0,"resourceLoadedEnd":1040.1999998092651,"resourceLoadedStart":239,"resourceTiming":[{"duration":116.80000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":239,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":239,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":355.80000019073486,"responseStart":0,"secureConnectionStart":0},{"duration":116.89999961853027,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":239.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":239.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":356.0999994277954,"responseStart":0,"secureConnectionStart":0},{"duration":130,"initiatorType":"script","name":"https://jira.mariadb.org/s/e9b27a47da5fb0f74a35acd57e9847fb-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":239.5,"connectEnd":239.5,"connectStart":239.5,"domainLookupEnd":239.5,"domainLookupStart":239.5,"fetchStart":239.5,"redirectEnd":0,"redirectStart":0,"requestStart":239.5,"responseEnd":369.5,"responseStart":369.5,"secureConnectionStart":239.5},{"duration":189.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/c32eb0da7ad9831253f8397e6cc26afd-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":239.5999994277954,"connectEnd":239.5999994277954,"connectStart":239.5999994277954,"domainLookupEnd":239.5999994277954,"domainLookupStart":239.5999994277954,"fetchStart":239.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":239.5999994277954,"responseEnd":429.3999996185303,"responseStart":429.3999996185303,"secureConnectionStart":239.5999994277954},{"duration":193.5999994277954,"initiatorType":"script","name":"https://jira.mariadb.org/s/bc0bcb146314416123c992714ee00ff7-CDN/lu2bv2/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":239.80000019073486,"connectEnd":239.80000019073486,"connectStart":239.80000019073486,"domainLookupEnd":239.80000019073486,"domainLookupStart":239.80000019073486,"fetchStart":239.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":239.80000019073486,"responseEnd":433.3999996185303,"responseStart":433.3999996185303,"secureConnectionStart":239.80000019073486},{"duration":193.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":240,"connectEnd":240,"connectStart":240,"domainLookupEnd":240,"domainLookupStart":240,"fetchStart":240,"redirectEnd":0,"redirectStart":0,"requestStart":240,"responseEnd":433.80000019073486,"responseStart":433.80000019073486,"secureConnectionStart":240},{"duration":194.20000076293945,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":240.0999994277954,"connectEnd":240.0999994277954,"connectStart":240.0999994277954,"domainLookupEnd":240.0999994277954,"domainLookupStart":240.0999994277954,"fetchStart":240.0999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":240.0999994277954,"responseEnd":434.30000019073486,"responseStart":434.30000019073486,"secureConnectionStart":240.0999994277954},{"duration":272.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bv2/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":240.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":240.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":512.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":194.4000005722046,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":240.39999961853027,"connectEnd":240.39999961853027,"connectStart":240.39999961853027,"domainLookupEnd":240.39999961853027,"domainLookupStart":240.39999961853027,"fetchStart":240.39999961853027,"redirectEnd":0,"redirectStart":0,"requestStart":240.39999961853027,"responseEnd":434.80000019073486,"responseStart":434.80000019073486,"secureConnectionStart":240.39999961853027},{"duration":272.30000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bv2/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":240.69999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":240.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":513,"responseStart":0,"secureConnectionStart":0},{"duration":194.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/719848dd97ebe0663199f49a3936487a-CDN/lu2bv2/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":240.80000019073486,"connectEnd":240.80000019073486,"connectStart":240.80000019073486,"domainLookupEnd":240.80000019073486,"domainLookupStart":240.80000019073486,"fetchStart":240.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":240.80000019073486,"responseEnd":435.30000019073486,"responseStart":435.30000019073486,"secureConnectionStart":240.80000019073486},{"duration":581.6999998092651,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":253.30000019073486,"connectEnd":253.30000019073486,"connectStart":253.30000019073486,"domainLookupEnd":253.30000019073486,"domainLookupStart":253.30000019073486,"fetchStart":253.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":253.30000019073486,"responseEnd":835,"responseStart":835,"secureConnectionStart":253.30000019073486},{"duration":578.3000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":257.5,"connectEnd":257.5,"connectStart":257.5,"domainLookupEnd":257.5,"domainLookupStart":257.5,"fetchStart":257.5,"redirectEnd":0,"redirectStart":0,"requestStart":257.5,"responseEnd":835.8000001907349,"responseStart":835.8000001907349,"secureConnectionStart":257.5},{"duration":174.10000038146973,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":524.6999998092651,"connectEnd":524.6999998092651,"connectStart":524.6999998092651,"domainLookupEnd":524.6999998092651,"domainLookupStart":524.6999998092651,"fetchStart":524.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":524.6999998092651,"responseEnd":698.8000001907349,"responseStart":698.8000001907349,"secureConnectionStart":524.6999998092651},{"duration":58,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2bv2/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":787,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":787,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":845,"responseStart":0,"secureConnectionStart":0},{"duration":247.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":788,"connectEnd":788,"connectStart":788,"domainLookupEnd":788,"domainLookupStart":788,"fetchStart":788,"redirectEnd":0,"redirectStart":0,"requestStart":788,"responseEnd":1035.5,"responseStart":1035.5,"secureConnectionStart":788},{"duration":251.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/53a43b6764f587426c7bb9a150184c00-CDN/lu2bv2/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/js/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":788.3999996185303,"connectEnd":788.3999996185303,"connectStart":788.3999996185303,"domainLookupEnd":788.3999996185303,"domainLookupStart":788.3999996185303,"fetchStart":788.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":788.3999996185303,"responseEnd":1040.1999998092651,"responseStart":1040.1999998092651,"secureConnectionStart":788.3999996185303},{"duration":178.10000038146973,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":884.0999994277954,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":884.0999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1062.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":183.19999980926514,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":905.8999996185303,"connectEnd":905.8999996185303,"connectStart":905.8999996185303,"domainLookupEnd":905.8999996185303,"domainLookupStart":905.8999996185303,"fetchStart":905.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":905.8999996185303,"responseEnd":1089.0999994277954,"responseStart":1089.0999994277954,"secureConnectionStart":905.8999996185303}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":41,"responseStart":233,"responseEnd":258,"domLoading":237,"domInteractive":1072,"domContentLoadedEventStart":1072,"domContentLoadedEventEnd":1134,"domComplete":1382,"loadEventStart":1382,"loadEventEnd":1382,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1043.1999998092651},{"name":"bigPipe.sidebar-id.end","time":1044},{"name":"bigPipe.activity-panel-pipe-id.start","time":1044.1999998092651},{"name":"bigPipe.activity-panel-pipe-id.end","time":1046.5999994277954},{"name":"activityTabFullyLoaded","time":1163.5999994277954}],"measures":[],"correlationId":"173314eb788108","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":122,"dbReadsTimeInMs":19,"dbConnsTimeInMs":28,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
valerii no, it is not. psergei and igor, can you estimate how much work is still needed to get this task done? I will change the status to stalled for now and will remove the fixVersion until we have a better idea about the task/open effort. It does not make sense to just add 11.2 as fixVersion for now, as this does not seem to be realistic