-
Notifications
You must be signed in to change notification settings - Fork 23
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
Discussion: Allow DDL statements in transactions? #31
Comments
I second the idea to disallow running DDLs "inside" transaction first of all. |
As I see, Go implementation executes a DDL at once, meaning for one DDL it uses one separate request:
When a DDL statement is executed, we're not sending it to the backend. Instead we insert it into internal list, pumping up all the DDLs. When a non-DDL statement is executed or the I can't say I like very much how it all looks in code, and in some cases it requires to call Python code where it all implemented: So, finalizing it all from user's position: it creates a feeling that DDLs are executed with transactions. I'm okay with raising an error in case DDL is executed while transaction is in progress, but probably for users it'll be easier not to think about DDLs are executed outiside of transactions, and just work like they are a part of transactions. |
DDL Transactions
I feel that that behavior is also slightly confusing, for two reasons:
CREATE TABLE Singers (SingerId INT64, Name STRING(MAX)) PRIMARY KEY (SingerId);
CREATE TABLE Albums (AlbumId INT64, Title STRING(MAX)) PRIMARY KEY (Id); -- Note the mistyped Id column name
-- This will fail with an error that points to the CREATE TABLE Albums statement.
INSERT INTO Singers (id, Name) VALUES (1, 'Test'); DDL BatchesBatching DDL statements together is certainly something that you sometimes want, especially as it makes creating a large set of new tables or indexes a lot faster than executing them one by one. This is however different from DDL transactions as a transaction is something that a user would expect to be atomic. The generic Connection API specification therefore included the ability to define DDL batches using custom SQL statements. So if you want to execute a set of DDL statements as one batch, you would then execute the following set of statements: START BATCH DDL;
CREATE TABLE Singers (SingerId INT64, Name STRING(MAX)) PRIMARY KEY (SingerId);
CREATE TABLE Albums (AlbumId INT64, Title STRING(MAX)) PRIMARY KEY (AlbumId);
RUN BATCH; A DDL batch is not intended to be atomic. This feature would then be implemented as part of #16 |
It's true. As I said, it creates feeling that you're executing those DDLs in a transaction with other statements.
Sounds good. If so, pumping up DDLs into an array will be redundant anyway (as I mentioned, I don't actually like how it looks in the code, so this custom statements idea sounds very good to me). With this in mind, I'm okay to raise an exception in case DDL is executed while in transaction 👍 |
@olavloite Sorry for the late reply. I agree with (1) and (2) and should raise an exception in case DDL is executed in a transaction. |
DDL statements cannot be executed as part of a transaction on Cloud Spanner. Although it would be technically possible to execute a DDL statement while a transaction is active, it could cause confusion whether the statement is part of the transaction or not. The driver therefore should return an error if an application tries to execute a DDL statement during an active transaction. Fixes #31
DDL statements cannot be executed as part of a transaction on Cloud Spanner. Although it would be technically possible to execute a DDL statement while a transaction is active, it could cause confusion whether the statement is part of the transaction or not. The driver therefore should return an error if an application tries to execute a DDL statement during an active transaction. Fixes #31
The initial (and current) implementation of the go-sql-spanner driver allows DDL statements to be executed using a transaction. That is however slightly confusing, as:
My personal opinion is that we should disallow both the above as the statement is not part of the transaction. Accepting the statement and executing it outside of the transaction will probably cause more confusion than if we were to return an error in such a case.
Note that a user can always execute a DDL statement when a transaction is active, but they will need to do so directly on the database instead of using a transaction.
What are your thoughts on this?
The text was updated successfully, but these errors were encountered: