-
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: Can't replace a table with a view in a transaction (SQL docs) #22868
Comments
similar to #12123 |
@vivekmenezes what do you think about allowing the CREATE to proceed but using some internally defined table name that is guaranteed to be unique. Then perform the rename of the new table to is final name when the txn commits, during the schema change? |
This would also solve #12123. |
This is discussed in https://github.com/cockroachdb/cockroach/blob/master/pkg/sql/sqlbase/structured.proto The particular problem with your proposal is that it fails when the CREATE statement is followed by an INSERT statement in the same transaction. |
Within the same transaction the correct name would be known to the TableCollection (uncommittedTables). The INSERT would see the correct name from there. I think it would work? |
Yeah, it's a lot more complex though because we have to choose what gets done with transaction with timestamp T and what gets done with transaction with timestamp S. There are two transactions at work here. And once that choice is made it requires some documentation work so users know what to expect. Unfortunately this is not looking like it can be done "transactionally" as in it support serializability |
…add index on node_id The goal of this change is to improve the storagenode_storage_tallies table by removing the unneeded id column that is not being used but only taking up space, and also to add an index on a different column that needs it. Removing and adding a column seems simple, but ended up being more complicated because of some cockroachdb limitations. The cockroachdb limitation when trying to remove a column from a table and create a new primary key are: 1. only allows primary key creation at table creation time (docs: https://www.cockroachlabs.com/docs/stable/primary-key.html) 2. table drop or rename is performed async and cannot be done in a transaction (issue: cockroachdb/cockroach#12123, cockroachdb/cockroach#22868) To address these differences between cockroachdb and Postgres, this PR performs different migrations for the two database. The Postgres migration is straight forward and what you would expect, but the cockroach migration has two main changes: 1. To change a primary key, use the recommended process from the cockroachdb docs to create a new table with the new primary key you want and then migrate the data. 2. In order to do 1, we needed to do the new table renaming in a separate transaction from the data migration. Ref: SM-65 Change-Id: Idc9aee3ab57aa4d5570e3d2980afea853cd966bf
…add index on node_id The goal of this change is to improve the storagenode_storage_tallies table by removing the unneeded id column that is not being used but only taking up space, and also to add an index on a different column that needs it. Removing and adding a column seems simple, but ended up being more complicated because of some cockroachdb limitations. The cockroachdb limitation when trying to remove a column from a table and create a new primary key are: 1. only allows primary key creation at table creation time (docs: https://www.cockroachlabs.com/docs/stable/primary-key.html) 2. table drop or rename is performed async and cannot be done in a transaction (issue: cockroachdb/cockroach#12123, cockroachdb/cockroach#22868) To address these differences between cockroachdb and Postgres, this PR performs different migrations for the two database. The Postgres migration is straight forward and what you would expect, but the cockroach migration has two main changes: 1. To change a primary key, use the recommended process from the cockroachdb docs to create a new table with the new primary key you want and then migrate the data. 2. In order to do 1, we needed to do the new table renaming in a separate transaction from the data migration. Ref: SM-65 Change-Id: Idc9aee3ab57aa4d5570e3d2980afea853cd966bf
This is solved. 🎉 |
I followed the docs at this document and tried running this SQL queries:
https://www.cockroachlabs.com/docs/stable/views.html#simplify-supporting-legacy-code
I expected that the query would run, but it complained that the relation still exists:
Outside of a transaction these statements work.
Full SQL to reproduce:
Version:
Jira issue: CRDB-5837
The text was updated successfully, but these errors were encountered: