-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Fix TableHandles with ColumnHandles caching #14751
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -412,28 +412,28 @@ public void setTableComment(ConnectorSession session, JdbcTableHandle handle, Op | |||
| public void setColumnComment(ConnectorSession session, JdbcTableHandle handle, JdbcColumnHandle column, Optional<String> comment) | ||||
| { | ||||
| delegate.setColumnComment(session, handle, column, comment); | ||||
| invalidateColumnsCache(handle.asPlainTable().getSchemaTableName()); | ||||
| invalidateTableCaches(handle.asPlainTable().getSchemaTableName()); | ||||
|
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. cmt msg
I'd suggest title like "Invalidate table handle cache when column changed" then drop "handle" in "When column handle is changed," -- it's not the column handle what's changing (column handles are immutable), it's the column itself
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. BTW why having stale I don't think it's used explicitly. If it's used implicitly (via equals), then maybe we have concurrency problem.
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 the only reasonable usage of the value of the comment is in How the situation described above differs from the e.g.
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.
so the invalidation doesn't matter.
Good question. trino/plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/BaseJdbcClient.java Line 256 in 5579e70
But I can imagine some JDBC connector eagerly populating the
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. anyway, I am fine with doing
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.
It matters. Plenty of connectors for |
||||
| } | ||||
|
|
||||
| @Override | ||||
| public void addColumn(ConnectorSession session, JdbcTableHandle handle, ColumnMetadata column) | ||||
| { | ||||
| delegate.addColumn(session, handle, column); | ||||
| invalidateColumnsCache(handle.asPlainTable().getSchemaTableName()); | ||||
| invalidateTableCaches(handle.asPlainTable().getSchemaTableName()); | ||||
findepi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
| } | ||||
|
|
||||
| @Override | ||||
| public void dropColumn(ConnectorSession session, JdbcTableHandle handle, JdbcColumnHandle column) | ||||
| { | ||||
| delegate.dropColumn(session, handle, column); | ||||
| invalidateColumnsCache(handle.asPlainTable().getSchemaTableName()); | ||||
| invalidateTableCaches(handle.asPlainTable().getSchemaTableName()); | ||||
| } | ||||
|
|
||||
| @Override | ||||
| public void renameColumn(ConnectorSession session, JdbcTableHandle handle, JdbcColumnHandle jdbcColumn, String newColumnName) | ||||
| { | ||||
| delegate.renameColumn(session, handle, jdbcColumn, newColumnName); | ||||
| invalidateColumnsCache(handle.asPlainTable().getSchemaTableName()); | ||||
| invalidateTableCaches(handle.asPlainTable().getSchemaTableName()); | ||||
| } | ||||
|
|
||||
| @Override | ||||
|
|
@@ -578,6 +578,12 @@ CacheStats getTableNamesCacheStats() | |||
| return tableNamesCache.stats(); | ||||
| } | ||||
|
|
||||
| @VisibleForTesting | ||||
| CacheStats getTableHandlesByNameCacheStats() | ||||
ssheikin marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
| { | ||||
| return tableHandlesByNameCache.stats(); | ||||
| } | ||||
|
|
||||
| @VisibleForTesting | ||||
| CacheStats getTableHandlesByQueryCacheStats() | ||||
| { | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -264,7 +264,12 @@ public Optional<ProjectionApplicationResult<ConnectorTableHandle>> applyProjecti | |
| return Optional.empty(); | ||
| } | ||
|
|
||
| verify(tableColumnSet.containsAll(newColumnSet), "applyProjection called with columns %s and some are not available in existing query: %s", newColumnSet, tableColumnSet); | ||
| Set<JdbcColumnHandle> tableSyntheticColumnSet = ImmutableSet.<JdbcColumnHandle>builder() | ||
|
||
| .addAll(tableColumnSet) | ||
| .add((JdbcColumnHandle) getDeleteRowIdColumnHandle(session, table)) | ||
|
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. Make getDeleteRowIdColumnHandle return JdbcColumnHandle and remove the cast here. |
||
| .build(); | ||
|
|
||
| verify(tableSyntheticColumnSet.containsAll(newColumnSet), "applyProjection called with columns %s and some are not available in existing query: %s", newColumnSet, tableSyntheticColumnSet); | ||
| } | ||
|
|
||
| return Optional.of(new ProjectionApplicationResult<>( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ | |
| import java.util.Map; | ||
| import java.util.Optional; | ||
|
|
||
| import static com.google.common.base.Verify.verify; | ||
| import static io.trino.plugin.jdbc.StandardColumnMappings.bigintColumnMapping; | ||
| import static io.trino.plugin.jdbc.StandardColumnMappings.bigintWriteFunction; | ||
| import static io.trino.plugin.jdbc.StandardColumnMappings.booleanColumnMapping; | ||
|
|
@@ -109,6 +110,13 @@ public Optional<String> getTableComment(ResultSet resultSet) | |
| return Optional.empty(); | ||
| } | ||
|
|
||
| @Override | ||
| public void setColumnComment(ConnectorSession session, JdbcTableHandle handle, JdbcColumnHandle column, Optional<String> comment) | ||
| { | ||
| // do not throw when invoked, however do not allow to set non-empty comment until the connector supports setting column comments | ||
| verify(comment.isEmpty(), "This connector does not support setting column comments"); | ||
|
Comment on lines
+116
to
+117
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 isn't correct anyway. what about: without a
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.
true.
existing comment does not exist, because
I'd left it as it is, because if I test
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.
it could exist if H2 supports column comments. Trino is not the only gate to the underlying db
Fine. Leave it but please make it clear it's not correct, but just as a reminder.
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. I was thinking about it. I was thinking that setting empty comment is fine, for connectors that do not support it. However I was wrong:
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. Yes, it's controversial. So better trade-off is not to test caching for addComment.
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. As agreed, left it as it is now. |
||
| } | ||
|
|
||
| @Override | ||
| public boolean supportsAggregationPushdown(ConnectorSession session, JdbcTableHandle table, List<AggregateFunction> aggregates, Map<String, ColumnHandle> assignments, List<List<ColumnHandle>> groupingSets) | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.