The current MariaDB (as of version 12.0) has some serious limitations to how views and derived tables can be used in UPDATE/DELETE statements.
Let's consider two tables t1, t2 and two views v1,
v2 :
createtable t1 (a int);
createtable t2 (b int);
insertinto t1 values (3), (7), (1), (8), (2);
insertinto t2 values (4), (7), (1), (5), (2);
createview v1 asselect a from t1;
createview v2 asselect * from t1,t2 where t1.a=t2.b;
The following limitations for UPDATE statements can be observed:
1u. The derived table with the same specification as of an updatable view cannot be updated
MariaDB [test]> update v1 set a=10;
Query OK, 5 rows affected (0.027 sec)
Rows matched: 5 Changed: 5 Warnings: 0
MariaDB [test]> select * from t1;
+------+
| a |
+------+
| 10 |
| 10 |
| 10 |
| 10 |
| 10 |
+------+
5 rows in set (0.001 sec)
MariaDB [test]> update (select a from t1) dt set dt.a=20;
ERROR 1288 (HY000): The target table dt of the UPDATE is not updatable
2u. Only one underlying table of a view specified as a join of some tables can be updated
MariaDB [test]> update t1,t2 set t1.a=10, t2.b=20 where t1.a=t2.b;
Query OK, 6 rows affected (0.019 sec)
Rows matched: 6 Changed: 6 Warnings: 0
MariaDB [test]> select * from t1;
+------+
| a |
+------+
| 3 |
| 10 |
| 10 |
| 8 |
| 10 |
+------+
5 rows in set (0.002 sec)
MariaDB [test]> select * from t2;
+------+
| b |
+------+
| 4 |
| 20 |
| 20 |
| 5 |
| 20 |
+------+
5 rows in set (0.002 sec)
MariaDB [test]> update v2 set v2.a=30, v2.b=40;
ERROR 1393 (HY000): Can not modify more than one base table through a join view 'test.v2'
Similar limitations can be observed for DELETE statements:
1d. Delete from the derived table with the same specification as of a updatable view is not allowed:
ariaDB [test]> delete from v1 where a < 5;
Query OK, 3 rows affected (0.017 sec)
MariaDB [test]> select * from t1;
+------+
| a |
+------+
| 7 |
| 8 |
+------+
2 rows in set (0.001 sec)
MariaDB [test]> delete from (select * from t1) dt where dt.a > 7;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(select * from t1) dt where dt.a > 7' at line 1
2d. Rows of one underlying table of a view specified as a join of some tables can be deleted
MariaDB [test]> delete from t1,t2 using t1,t2 where t1.a=t2.b;
Query OK, 6 rows affected (0.027 sec)
MariaDB [test]> select * from t1;
+------+
| a |
+------+
| 3 |
| 8 |
+------+
2 rows in set (0.001 sec)
MariaDB [test]> select * from t2;
+------+
| b |
+------+
| 4 |
| 5 |
+------+
2 rows in set (0.001 sec)
MariaDB [test]> delete from v2 where t1.a=t2.b;
ERROR 1395 (HY000): Can not delete from join view 'test.v2'
Attachments
Issue Links
relates to
MDEV-18511CTE support for UPDATE and DELETE statements
Stalled
MDEV-23552Merge mergeable derived tables used at the top level of UPDATE/DELETE statements
This feature will be implemented in a bundle with MDEV-18511 and MDEV-23552. These 3 mdevs will allow to use views, derived tables and CTEs interchangeably in UPDATE and DELETE statements (as far as privileges are not concerned).
Igor Babaev (Inactive)
added a comment - This feature will be implemented in a bundle with MDEV-18511 and MDEV-23552 . These 3 mdevs will allow to use views, derived tables and CTEs interchangeably in UPDATE and DELETE statements (as far as privileges are not concerned).
People
Unassigned
Igor Babaev (Inactive)
Votes:
1Vote for this issue
Watchers:
3Start 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":865.7000000476837,"ttfb":208.90000009536743,"pageVisibility":"visible","entityId":133324,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"b3763d9f-5450-46d6-b87a-c4bf7272d73f","navigationType":0,"readyForUser":963.7000000476837,"redirectCount":0,"resourceLoadedEnd":598.2000000476837,"resourceLoadedStart":214.60000014305115,"resourceTiming":[{"duration":29,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bsh/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":214.60000014305115,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":214.60000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":243.60000014305115,"responseStart":0,"secureConnectionStart":0},{"duration":30.299999952316284,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bsh/820016/12ta74/eb142f92e4bd16bd1ef8b08c1b9d5d56/_/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":214.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":214.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":245.20000004768372,"responseStart":0,"secureConnectionStart":0},{"duration":224.60000014305115,"initiatorType":"script","name":"https://jira.mariadb.org/s/c54b129276d75dc2a3460e1d78f37913-CDN/lu2bsh/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":215,"connectEnd":215,"connectStart":215,"domainLookupEnd":215,"domainLookupStart":215,"fetchStart":215,"redirectEnd":0,"redirectStart":0,"requestStart":248.10000014305115,"responseEnd":439.60000014305115,"responseStart":266.80000019073486,"secureConnectionStart":215},{"duration":383.2000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/s/f867843cd2fdb209d4d1d4f760f86346-CDN/lu2bsh/820016/12ta74/eb142f92e4bd16bd1ef8b08c1b9d5d56/_/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":215,"connectEnd":215,"connectStart":215,"domainLookupEnd":215,"domainLookupStart":215,"fetchStart":215,"redirectEnd":0,"redirectStart":0,"requestStart":250.5,"responseEnd":598.2000000476837,"responseStart":272.80000019073486,"secureConnectionStart":215},{"duration":65.29999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/ffdb17665775c5b4d6f097f3974ee359-CDN/lu2bsh/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":215.20000004768372,"connectEnd":215.20000004768372,"connectStart":215.20000004768372,"domainLookupEnd":215.20000004768372,"domainLookupStart":215.20000004768372,"fetchStart":215.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":251.10000014305115,"responseEnd":280.5,"responseStart":277.2000000476837,"secureConnectionStart":215.20000004768372},{"duration":69.70000004768372,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":215.20000004768372,"connectEnd":215.20000004768372,"connectStart":215.20000004768372,"domainLookupEnd":215.20000004768372,"domainLookupStart":215.20000004768372,"fetchStart":215.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":252.10000014305115,"responseEnd":284.90000009536743,"responseStart":280.80000019073486,"secureConnectionStart":215.20000004768372},{"duration":34.200000047683716,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bsh/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":215.40000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":215.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":249.60000014305115,"responseStart":0,"secureConnectionStart":0},{"duration":70,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":215.40000009536743,"connectEnd":215.40000009536743,"connectStart":215.40000009536743,"domainLookupEnd":215.40000009536743,"domainLookupStart":215.40000009536743,"fetchStart":215.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":252.5,"responseEnd":285.40000009536743,"responseStart":282,"secureConnectionStart":215.40000009536743},{"duration":97,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":215.5,"connectEnd":215.5,"connectStart":215.5,"domainLookupEnd":215.5,"domainLookupStart":215.5,"fetchStart":215.5,"redirectEnd":0,"redirectStart":0,"requestStart":254.10000014305115,"responseEnd":312.5,"responseStart":308.7000000476837,"secureConnectionStart":215.5},{"duration":34.299999952316284,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bsh/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":215.70000004768372,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":215.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":250,"responseStart":0,"secureConnectionStart":0},{"duration":70.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/81b5d7c27af3ebc078cc4a36383678ba-CDN/lu2bsh/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":215.80000019073486,"connectEnd":215.80000019073486,"connectStart":215.80000019073486,"domainLookupEnd":215.80000019073486,"domainLookupStart":215.80000019073486,"fetchStart":215.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":254.70000004768372,"responseEnd":286.5,"responseStart":283.30000019073486,"secureConnectionStart":215.80000019073486},{"duration":297,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":221.30000019073486,"connectEnd":221.30000019073486,"connectStart":221.30000019073486,"domainLookupEnd":221.30000019073486,"domainLookupStart":221.30000019073486,"fetchStart":221.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":322.5,"responseEnd":518.3000001907349,"responseStart":513.2000000476837,"secureConnectionStart":221.30000019073486},{"duration":297.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":221.40000009536743,"connectEnd":221.40000009536743,"connectStart":221.40000009536743,"domainLookupEnd":221.40000009536743,"domainLookupStart":221.40000009536743,"fetchStart":221.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":325.30000019073486,"responseEnd":518.5,"responseStart":513.9000000953674,"secureConnectionStart":221.40000009536743},{"duration":141.79999995231628,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":585.9000000953674,"connectEnd":585.9000000953674,"connectStart":585.9000000953674,"domainLookupEnd":585.9000000953674,"domainLookupStart":585.9000000953674,"fetchStart":585.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":700.3000001907349,"responseEnd":727.7000000476837,"responseStart":726.5,"secureConnectionStart":585.9000000953674}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":59,"responseStart":209,"responseEnd":216,"domLoading":212,"domInteractive":1047,"domContentLoadedEventStart":1047,"domContentLoadedEventEnd":1093,"domComplete":1796,"loadEventStart":1796,"loadEventEnd":1797,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1027.6000001430511},{"name":"bigPipe.sidebar-id.end","time":1028.5},{"name":"bigPipe.activity-panel-pipe-id.start","time":1028.7000000476837},{"name":"bigPipe.activity-panel-pipe-id.end","time":1029.5},{"name":"activityTabFullyLoaded","time":1109.4000000953674}],"measures":[],"correlationId":"ffec2df17b89c3","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":74,"dbReadsTimeInMs":11,"dbConnsTimeInMs":18,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
This feature will be implemented in a bundle with MDEV-18511 and MDEV-23552. These 3 mdevs will allow to use views, derived tables and CTEs interchangeably in UPDATE and DELETE statements (as far as privileges are not concerned).