-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: INSERT with self-referencing FK check issues #20041
Labels
A-sql-execution
Relating to SQL execution.
A-sql-fks
A-sql-pgcompat
Semantic compatibility with PostgreSQL
C-bug
Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
Comments
Oh, and to add to this, it does work on postgres. |
knz
added
C-bug
Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
A-sql-pgcompat
Semantic compatibility with PostgreSQL
labels
Apr 27, 2018
This may have been fixed on #23373 . testing. |
nope, not fixed. |
knz
changed the title
sql: Inserts can't see their earlier writes
sql: Insert FK checks can't see their earlier writes
Apr 27, 2018
BramGruneir
changed the title
sql: Insert FK checks can't see their earlier writes
sql: INSERT with self-referencing FK check issues
Nov 27, 2018
Updated this based on #32610 and merging that issue into this. |
Solution is described (and will be implemented by fixing) #33475. |
#33475 is not closed so assuming this can be closed as well. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-sql-execution
Relating to SQL execution.
A-sql-fks
A-sql-pgcompat
Semantic compatibility with PostgreSQL
C-bug
Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
When inserting in a self-referential table, you can't insert multiple values in a single statement if they rely on a value earlier in the statement.
But this works.
This is due to each individual insert statement using a single batch and batches can't read previous writes.
However, if we were to use a single batch per inserted element, it would drastically slow down the inserts overall.
Another, slightly different version of this problem:
This fails because we eagerly check the FKs instead of waiting to the end of the statement. But even if we did wait to check at the end of the statement, then we would not yet have the batch committed and the FK check would still fail.
That being said, it might be possible to elide this FK check if the values match in the mutation path.
The text was updated successfully, but these errors were encountered: