Open ThorbenLindhauer opened 4 years ago
This comment was imported from JIRA and written by user @ThorbenLindhauer
I wouldn't bet on that the github issue addresses our problem. I could still reproduce the original problem with CockroachDB 20.1.5 (both in Cockpit when executing jobs as well as with an artificial example) and the query plan still seems to be the same. See https://forum.cockroachlabs.com/t/understanding-a-transactionretryerror-with-a-foreign-key/3895 for details.
This comment was imported from JIRA and written by user @ThorbenLindhauer
It's also not necessarily restricted to constraints in the same table.
This comment was imported from JIRA and written by user @ThorbenLindhauer
According to https://forum.cockroachlabs.com/t/understanding-a-transactionretryerror-with-a-foreign-key/3895/6?u=thorben and https://github.com/cockroachdb/cockroach/issues/41701, in 20.1.5 the optimizer still uses the problematic hash join when the table has less than five rows. With 20.2, it is supposed to only do that only when the table has a single row.
This issue was imported from JIRA:
// Given Two process instances in the execution table
// When The same operation is applied on each of the instances so that the row in the execution table is deleted (maybe it can be reproduced with updates as well). Example: Job execution that finishes the process instance.
// Then A concurrency error is reported by CockroachDB that leads to a
CrdbTransactionRetryException
in the process engine// Expected No concurrency error is reported since the data is not related and the transactions are in any case serializable.
Understanding: CockroachDB needs to ensure that the foreign key constraint is not violated after the DELETE. It does that by performing a hash join on the foreign key index with a full scan after the delete was performed (see query plans in linked CRDB forum post).
Potentially related CockroachDB issue: https://github.com/cockroachdb/cockroach/issues/51648 (resolved in CRDB 20.1.5) Forum post: https://forum.cockroachlabs.com/t/understanding-a-transactionretryerror-with-a-foreign-key/3895
Links: