-
Notifications
You must be signed in to change notification settings - Fork 1.9k
IGNITE-28629 Support savepoint in SQL #13099
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one or more | ||
| // contributor license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright ownership. | ||
| // The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| // (the "License"); you may not use this file except in compliance with | ||
| // the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| = Transactions | ||
|
|
||
| This page describes SQL transaction commands supported by the Calcite-based SQL engine. | ||
|
|
||
| == SAVEPOINT | ||
|
|
||
| Creates a named savepoint in the current transaction. | ||
|
|
||
| [source,sql] | ||
| ---- | ||
| SAVEPOINT savepointName | ||
| ---- | ||
|
|
||
| === Parameters | ||
|
|
||
| - `savepointName` - the name of the savepoint to create. | ||
|
|
||
| === Description | ||
|
|
||
| `SAVEPOINT` can be used only inside an explicit `PESSIMISTIC` transaction. | ||
|
|
||
| The command records the current transaction state. Later, you can use `ROLLBACK TO SAVEPOINT` to roll back all transaction changes made after the savepoint was created. | ||
|
|
||
| If a savepoint with the same name already exists, `SAVEPOINT` replaces it. The command does not roll back any transaction changes. It removes the previous savepoint with that name and makes the name refer to the current transaction state. | ||
|
|
||
| == ROLLBACK TO SAVEPOINT | ||
|
|
||
| Rolls back transaction changes to a previously created savepoint. | ||
|
|
||
| [source,sql] | ||
| ---- | ||
| ROLLBACK TO SAVEPOINT savepointName | ||
| ---- | ||
|
|
||
| === Parameters | ||
|
|
||
| - `savepointName` - the name of the savepoint to roll back to. | ||
|
|
||
| === Description | ||
|
|
||
| `ROLLBACK TO SAVEPOINT` can be used only inside an explicit `PESSIMISTIC` transaction. | ||
|
|
||
| The command rolls back all transaction changes made after the specified savepoint was created. The transaction remains active and can be committed or rolled back later. | ||
|
|
||
| When a transaction is rolled back to a savepoint, savepoints created after the target savepoint are released. The target savepoint remains available and can be used again. | ||
|
|
||
| If the specified savepoint does not exist, the command fails. | ||
|
|
||
| == Example | ||
|
|
||
| [source,sql] | ||
| ---- | ||
| INSERT INTO Person(id, name) VALUES (1, 'John'); | ||
|
|
||
| SAVEPOINT before_update; | ||
|
|
||
| UPDATE Person SET name = 'Jane' WHERE id = 1; | ||
|
|
||
| ROLLBACK TO SAVEPOINT before_update; | ||
| ---- | ||
|
|
||
| After `ROLLBACK TO SAVEPOINT before_update`, the `UPDATE` statement is rolled back, but the preceding `INSERT` statement remains part of the active transaction. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...org/apache/ignite/internal/processors/query/calcite/sql/IgniteSqlRollbackToSavepoint.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.ignite.internal.processors.query.calcite.sql; | ||
|
|
||
| import java.util.List; | ||
| import org.apache.calcite.sql.SqlDdl; | ||
| import org.apache.calcite.sql.SqlIdentifier; | ||
| import org.apache.calcite.sql.SqlKind; | ||
| import org.apache.calcite.sql.SqlNode; | ||
| import org.apache.calcite.sql.SqlOperator; | ||
| import org.apache.calcite.sql.SqlSpecialOperator; | ||
| import org.apache.calcite.sql.SqlWriter; | ||
| import org.apache.calcite.sql.parser.SqlParserPos; | ||
|
|
||
| /** Parse tree for {@code ROLLBACK TO SAVEPOINT name} statement. */ | ||
| public class IgniteSqlRollbackToSavepoint extends SqlDdl { | ||
| /** */ | ||
| protected static final SqlOperator OPERATOR = | ||
| new SqlSpecialOperator("ROLLBACK TO SAVEPOINT", SqlKind.OTHER_DDL); | ||
|
zstan marked this conversation as resolved.
|
||
|
|
||
| /** Savepoint name. */ | ||
| private final SqlIdentifier name; | ||
|
|
||
| /** | ||
| * @param pos Parser position. | ||
| * @param name Savepoint name. | ||
| */ | ||
| public IgniteSqlRollbackToSavepoint(SqlParserPos pos, SqlIdentifier name) { | ||
| super(OPERATOR, pos); | ||
|
|
||
| this.name = name; | ||
| } | ||
|
|
||
| /** */ | ||
| public SqlIdentifier name() { | ||
| return name; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public List<SqlNode> getOperandList() { | ||
| return List.of(name); | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { | ||
| writer.keyword(getOperator().getName()); | ||
| name.unparse(writer, leftPrec, rightPrec); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.