-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Oracle turns off auto commit to drop temporary table #17756
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -302,6 +302,8 @@ protected void dropTable(ConnectorSession session, RemoteTableName remoteTableNa | |
| String dropTableSql = "DROP TABLE " + quotedTable; | ||
| try (Connection connection = connectionFactory.openConnection(session)) { | ||
| if (temporaryTable) { | ||
| // Turn off auto-commit so the lock is held until after the DROP | ||
| connection.setAutoCommit(false); | ||
| // By default, when dropping a table, oracle does not wait for the table lock. | ||
| // If another transaction is using the table at the same time, DROP TABLE will throw. | ||
| // The solution is to first lock the table, waiting for other active transactions to complete. | ||
|
|
@@ -315,6 +317,9 @@ protected void dropTable(ConnectorSession session, RemoteTableName remoteTableNa | |
| dropTableSql += " PURGE"; | ||
| } | ||
| execute(session, connection, dropTableSql); | ||
| // Commit the transaction (for temporaryTables), or a no-op for regular tables. | ||
| // This is better than connection.commit() because you're not supposed to commit() if autoCommit is true. | ||
| connection.setAutoCommit(true); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the last operation on connection - why switch back?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is answered by my most recent response in the other thread |
||
| } | ||
| catch (SQLException e) { | ||
| throw new TrinoException(JDBC_ERROR, e); | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the motivation behind the change? Should we commit explicitly then? Or was switching auto-commit back to true just before connection is closed for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment below - or just call
commit()- will be more readable I thinkThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The motivation is that, because autoCommit is true when we get the Connection, the lock is immediately released because that
LOCK TABLEstatement is auto-committed, so the Connection has to re-acquire the lock for theDROP TABLE, so we have the same situation as we did before. Turning off auto commit holds onto that lock until after the drop table. Oracle's docs say DDL always auto-commits, but I reset autoCommit to true after the drop just in case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, weird - when i typed out my reply, i only had your first comment in this thread visible to me.
I think i want to keep it as

setAutoCommit(true)as it properly handles both cases: