-
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
CREATE TABLE and INSERT fail in same Transaction #14548
Comments
Hi @timchunght, thanks for reporting! In case you're curious, there are a few existing issues tracking oddities with schema changes and transactions:
As far as I know this specific bug hasn't yet been discovered, but I'll defer triaging to the schema change experts. +cc @vivekmenezes The workaround, as you've discovered, is to execute the |
Creating a table was not historically a schema change in the same sense as other schema changes operations and some effort was made to allow subsequent inserts to the new table within the same transaction to work. Did we regress accidentally here, or was this intentional? |
At least when there are relations between tables (fks, views), CREATE does need to be a schema change (with the committed intermediate state + waitForOneVersion dance). |
#14368 gets rid of this kind of surprise by explicitly making this an error. It's in review. @petermattis this used to work the way you describe but now is executed like a schema change. It's strictly not necessary, and we can consider adding back the lost behavior post 1.0 |
@benesch Thanks and I have looked at them before filling this issue. It appears that, as you acknowledged, transaction might have slight unexpected behaviours. Nonetheless, we were able to do a 'fix' by just splitting them into two subsequent transactions. However, we also sacrificed on the transaction guarantee (though not a big deal for this case, it could potentially be useful given a lot of existing PG tools implement transactions that combine CREATE TABLE with immediate INSERT) I had to fork the library and change that specific part... |
@timchunght thanks for pointing that out. We'll keep this issue open so that it gets fixed. |
Is this fixed now that you've merged #14368? |
Still hangs forever for me on the latest master. (Gist: https://gist.github.com/benesch/cce1a20c0981bc0d45c3a47165c47834) |
confirmed that this hang still exists. Working on a fix.
…On Tue, Apr 4, 2017 at 11:45 AM Nikhil Benesch ***@***.***> wrote:
Still hangs forever for me on the latest master. (Gist:
https://gist.github.com/benesch/cce1a20c0981bc0d45c3a47165c47834)
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#14548 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALOpBPr5myE0wBiDBF6rjmZz8wtg0z8nks5rsmWKgaJpZM4Mw9t2>
.
|
This bug only happens when the INSERT statement used in the transaction uses placeholder variables. A workaround is to not use placeholder variables when running an INSERT following a CREATE TABLE in the same transaction. I'm going to fix this but the workaround might work for you in the interim. |
This is a bug in sql PREPARE. It uses a different transaction when reading the table descriptor to type check the placeholder variables. For the case where a table descriptor is created in the same transaction it needs to use the transaction that created the table while type checking the PREPARE placeholder variables. |
Similar to the issue we saw in #14473, I believe the root cause of this is that Prepare statements do not run within a parent transaction if one exists: executor.go#L449 |
I believe there is a bug in the transaction. So when I CREATE TABLE and INSERT into the same table in the same transaction, cockroach just hangs indefinitely. This bug was discovered when using the goose migration tool with Cockroach. All the code only uses the
lib/pq
and the defaultdatabase/sql
and same issue persists even in isolation with the code moved into an individual script.Everything works perfectly in postgres. However, if I were to move the CREATE TABLE outside of the transaction, everything works. Please advise.
The text was updated successfully, but these errors were encountered: