Skip to content

Commit 1024391

Browse files
committed
Oracle purges dropped temp tables
1 parent 0f3ff0a commit 1024391

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/BaseJdbcClient.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ public void finishInsertTable(ConnectorSession session, JdbcOutputTableHandle ha
890890

891891
// We conditionally create more than the one table, so keep a list of the tables that need to be dropped.
892892
Closer closer = Closer.create();
893-
closer.register(() -> dropTable(session, temporaryTable));
893+
closer.register(() -> dropTable(session, temporaryTable, true));
894894

895895
try (Connection connection = getConnection(session, handle)) {
896896
verify(connection.getAutoCommit());
@@ -906,7 +906,7 @@ public void finishInsertTable(ConnectorSession session, JdbcOutputTableHandle ha
906906

907907
if (handle.getPageSinkIdColumnName().isPresent()) {
908908
RemoteTableName pageSinkTable = constructPageSinkIdsTable(session, connection, handle, pageSinkIds);
909-
closer.register(() -> dropTable(session, pageSinkTable));
909+
closer.register(() -> dropTable(session, pageSinkTable, true));
910910

911911
insertSql += format(" WHERE EXISTS (SELECT 1 FROM %s page_sink_table WHERE page_sink_table.%s = temp_table.%s)",
912912
quoted(pageSinkTable),
@@ -1034,10 +1034,10 @@ public void setColumnType(ConnectorSession session, JdbcTableHandle handle, Jdbc
10341034
public void dropTable(ConnectorSession session, JdbcTableHandle handle)
10351035
{
10361036
verify(handle.getAuthorization().isEmpty(), "Unexpected authorization is required for table: %s".formatted(handle));
1037-
dropTable(session, handle.asPlainTable().getRemoteTableName());
1037+
dropTable(session, handle.asPlainTable().getRemoteTableName(), false);
10381038
}
10391039

1040-
protected void dropTable(ConnectorSession session, RemoteTableName remoteTableName)
1040+
protected void dropTable(ConnectorSession session, RemoteTableName remoteTableName, boolean temporaryTable)
10411041
{
10421042
String sql = "DROP TABLE " + quoted(remoteTableName);
10431043
execute(session, sql);
@@ -1047,10 +1047,12 @@ protected void dropTable(ConnectorSession session, RemoteTableName remoteTableNa
10471047
public void rollbackCreateTable(ConnectorSession session, JdbcOutputTableHandle handle)
10481048
{
10491049
if (handle.getTemporaryTableName().isPresent()) {
1050-
dropTable(session, new JdbcTableHandle(
1051-
new SchemaTableName(handle.getSchemaName(), handle.getTemporaryTableName().get()),
1052-
new RemoteTableName(Optional.ofNullable(handle.getCatalogName()), Optional.ofNullable(handle.getSchemaName()), handle.getTemporaryTableName().get()),
1053-
Optional.empty()));
1050+
dropTable(session,
1051+
new RemoteTableName(
1052+
Optional.ofNullable(handle.getCatalogName()),
1053+
Optional.ofNullable(handle.getSchemaName()),
1054+
handle.getTemporaryTableName().get()),
1055+
true);
10541056
}
10551057
}
10561058

plugin/trino-oracle/src/main/java/io/trino/plugin/oracle/OracleClient.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,20 @@ public void dropSchema(ConnectorSession session, String schemaName)
296296
throw new TrinoException(NOT_SUPPORTED, "This connector does not support dropping schemas");
297297
}
298298

299+
@Override
300+
protected void dropTable(ConnectorSession session, RemoteTableName remoteTableName, boolean temporaryTable)
301+
{
302+
String sql = "DROP TABLE " + quoted(remoteTableName);
303+
// Oracle puts dropped tables into a recycling bin, which keeps them accessible for a period of time.
304+
// PURGE will bypass the bin and completely delete the table immediately.
305+
// We should only PURGE the table if it is a temporary table that trino created,
306+
// as purging all dropped tables may be unexpected behavior for our clients.
307+
if (temporaryTable) {
308+
sql += " PURGE";
309+
}
310+
execute(session, sql);
311+
}
312+
299313
@Override
300314
public void renameSchema(ConnectorSession session, String schemaName, String newSchemaName)
301315
{

0 commit comments

Comments
 (0)