Deleting records with selection on `_id` is broken
See original GitHub issueCrateDB version
4.7.0 / 5.0.1 / 5.10
CrateDB setup information
single / multi-node
Steps to Reproduce
cr> CREATE TABLE del_test (val int);
CREATE OK, 1 row affected (0.415 sec)
cr> INSERT INTO del_test VALUES (1),(1),(2);
INSERT OK, 3 rows affected (0.032 sec)
cr> SELECT arbitrary(_id)
FROM del_test
WHERE val = 1
GROUP BY val
HAVING count(*) > 1;
+----------------------+
| arbitrary(_id) |
+----------------------+
| 6wCcQoQBNMIiChzeUweD |
+----------------------+
SELECT 1 row in set (0.019 sec)
-- here is the problem:
cr> DELETE FROM del_test WHERE _id IN (SELECT arbitrary(_id)
FROM del_test
WHERE val = 1
GROUP BY val
HAVING count(*) > 1);
DELETE OK, 0 rows affected (0.022 sec)
cr> DELETE FROM del_test WHERE _id IN (SELECT '6wCcQoQBNMIiChzeUweD');
DELETE OK, 0 rows affected (0.029 sec)
-- that works
cr> DELETE FROM del_test WHERE _id IN ('6wCcQoQBNMIiChzeUweD');
DELETE OK, 1 row affected (0.031 sec)
Expected Result
DELETE OK, 1 row affected (0.031 sec)
Actual Result
DELETE OK, 0 rows affected (0.029 sec)
edit:
EXPLAIN
SELECT *
FROM del_test
WHERE _id IN (SELECT _id FROM del_test)
-- SELECT OK, 0 records returned (0.033 seconds)
MultiPhase
└ Collect[doc.del_test | [val] | (_id = ANY((SELECT _id FROM (doc.del_test))))]
└ OrderBy[_id ASC]
└ Collect[doc.del_test | [_id] | true]
------------
EXPLAIN
SELECT *
FROM del_test
WHERE _id::CHAR(20) IN (SELECT _id FROM del_test)
-- SELECT OK, 3 records returned (0.041 seconds)
MultiPhase
└ Collect[doc.del_test | [val] | (_cast(cast(_id AS character), 'text') = ANY((SELECT _id FROM (doc.del_test))))]
└ OrderBy[_id ASC]
└ Collect[doc.del_test | [_id] | true]
------------
EXPLAIN
SELECT *
FROM del_test
WHERE _id IN ('58puQ4QBQmJ97UbuHnXp','jxcRQ4QB4KuX8tRunOAg')
Get[doc.del_test | val | DocKeys{'58puQ4QBQmJ97UbuHnXp'; 'jxcRQ4QB4KuX8tRunOAg'} | (_id = ANY(['58puQ4QBQmJ97UbuHnXp', 'jxcRQ4QB4KuX8tRunOAg']))]
Seems like the bug first occurred with CrateDB 4.7 (4.6.8 tested to be working)
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Delete query with select query is not working as expected
DELETE FROM B_786 WHERE EXISTS (SELECT * FROM I_786);. But it is deleting all the data from B_786 table. Here the where condition...
Read more >CTE SQL Deletes; Considerations when Deleting Data with ...
Since we want to removed the ordered data that show a duplicate id (in this case, 2), we'll create a query with the...
Read more >I get the error message "Could not delete from the specified ...
To fix this problem, set the query's Unique Records property to Yes. Open the delete query in Design view.
Read more >Delete class not working - apex - Salesforce Stack Exchange
SELECT Id FROM Account_List_vod__c WHERE Name = 'HO_RADY\'S CHILDREN\'S UCSD' ... deleteAccounts}" rerender="pmsg, pbAccounts" value="Delete ...
Read more >Mass Delete Records tool fails without error message
While working in the tool, users may report that the deletion page refreshes as expected but selected records continue to appear in the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
FYI: That’s not a problem of the
DELETE
but a problem with_id
IN/ANY
and subquery.Just logging that on a separate conversation it has been confirmed that on versions of CrateDB < 5.0.0 the CHAR data type is not available, but the issue can still be worked around using VARCHAR instead.