Skip to content
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

feat: allow DDL with autocommit=false #3057

Merged
merged 3 commits into from
May 3, 2024

Conversation

olavloite
Copy link
Collaborator

@olavloite olavloite commented Apr 22, 2024

Adds support for running DDL statements when a connection is in autocommit=false mode. By default, DDL statements are only allowed when no transaction is active. That is; no query or DML statement has been executed which activated a read/write transaction.

A new flag is added that can be used to revert the behavior back to the original behavior where DDL is always refused when autocommit=false. The same flag can also be used to make the API behave the same as MySQL and Oracle, where any active transaction is automatically committed whenever a DDL statement is encountered.

Concretely this means that the following is now allowed:

set autocommit=false;
create table Singers (SingerId INT64, Name STRING(MAX)) PRIMARY KEY (SingerId);

The following is by default NOT allowed, unless
ddlInTransactionMode=AUTO_COMMIT_TRANSACTION

set autocommit=false;
select * from singers; -- This starts a transaction
create table Albums (AlbumId INT64) PRIMARY KEY (AlbumId); -- This is not allowed

Adds support for running DDL statements when a connection is in
autocommit=false mode. By default, DDL statements are only allowed
when no transaction is active. That is; no query or DML statement
has been executed which activated a read/write transaction.

A new flag is added that can be used to revert the behavior back
to the original behavior where DDL is always refused when
autocommit=false.

Concretely this means that the following is now allowed:

```
set autocommit=false;
create table Singers (SingerId INT64, Name STRING(MAX)) PRIMARY KEY (SingerId);
```

The following is by default NOT allowed, unless
ddlInTransactionMode=AUTO_COMMIT_TRANSACTION

```
set autocommit=false;
select * from singers; -- This starts a transaction
create table Albums (AlbumId INT64) PRIMARY KEY (AlbumId); -- This is not allowed
```
@olavloite olavloite requested review from a team as code owners April 22, 2024 15:56
@product-auto-label product-auto-label bot added size: xl Pull request size is extra large. api: spanner Issues related to the googleapis/java-spanner API. labels Apr 22, 2024
@olavloite olavloite added the automerge Merge the pull request once unit tests and other checks pass. label May 3, 2024
@gcf-merge-on-green gcf-merge-on-green bot merged commit 22833ac into main May 3, 2024
30 of 34 checks passed
@gcf-merge-on-green gcf-merge-on-green bot deleted the allow-ddl-in-autocommit-off branch May 3, 2024 08:22
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner API. size: xl Pull request size is extra large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants