-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[WIP] Improve performance of querying system.jdbc.tables
for Hive, Iceberg, and Delta
#24110
base: master
Are you sure you want to change the base?
Changes from 1 commit
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 |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
import io.trino.metastore.PrincipalPrivileges; | ||
import io.trino.metastore.StorageFormat; | ||
import io.trino.metastore.Table; | ||
import io.trino.metastore.TableInfo; | ||
import io.trino.plugin.base.classloader.ClassLoaderSafeSystemTable; | ||
import io.trino.plugin.base.filter.UtcConstraintExtractor; | ||
import io.trino.plugin.base.projection.ApplyProjectionUtil; | ||
|
@@ -113,6 +114,7 @@ | |
import io.trino.spi.connector.ConstraintApplicationResult; | ||
import io.trino.spi.connector.ProjectionApplicationResult; | ||
import io.trino.spi.connector.RelationCommentMetadata; | ||
import io.trino.spi.connector.RelationType; | ||
import io.trino.spi.connector.RetryMode; | ||
import io.trino.spi.connector.RowChangeParadigm; | ||
import io.trino.spi.connector.SaveMode; | ||
|
@@ -173,7 +175,10 @@ | |
import java.util.OptionalInt; | ||
import java.util.OptionalLong; | ||
import java.util.Set; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.function.Function; | ||
|
@@ -204,6 +209,7 @@ | |
import static io.trino.plugin.base.projection.ApplyProjectionUtil.ProjectedColumnRepresentation; | ||
import static io.trino.plugin.base.projection.ApplyProjectionUtil.extractSupportedProjectedColumns; | ||
import static io.trino.plugin.base.projection.ApplyProjectionUtil.replaceWithNewVariables; | ||
import static io.trino.plugin.base.util.ExecutorUtil.processWithAdditionalThreads; | ||
import static io.trino.plugin.deltalake.DataFileInfo.DataFileType.DATA; | ||
import static io.trino.plugin.deltalake.DeltaLakeAnalyzeProperties.AnalyzeMode.FULL_REFRESH; | ||
import static io.trino.plugin.deltalake.DeltaLakeAnalyzeProperties.AnalyzeMode.INCREMENTAL; | ||
|
@@ -447,6 +453,7 @@ public class DeltaLakeMetadata | |
private final Map<SchemaTableName, TableUpdateInfo> tableUpdateInfos = new ConcurrentHashMap<>(); | ||
private final Map<SchemaTableName, Long> latestTableVersions = new ConcurrentHashMap<>(); | ||
private final Map<QueriedTable, TableSnapshot> queriedSnapshots = new ConcurrentHashMap<>(); | ||
private final Executor metadataFetchingExecutor; | ||
|
||
private record QueriedTable(SchemaTableName schemaTableName, long version) | ||
{ | ||
|
@@ -477,7 +484,8 @@ public DeltaLakeMetadata( | |
CachingExtendedStatisticsAccess statisticsAccess, | ||
DeltaLakeTableMetadataScheduler metadataScheduler, | ||
boolean useUniqueTableLocation, | ||
boolean allowManagedTableRename) | ||
boolean allowManagedTableRename, | ||
Executor metadataFetchingExecutor) | ||
{ | ||
this.metastore = requireNonNull(metastore, "metastore is null"); | ||
this.transactionLogAccess = requireNonNull(transactionLogAccess, "transactionLogAccess is null"); | ||
|
@@ -501,6 +509,7 @@ public DeltaLakeMetadata( | |
this.metadataScheduler = requireNonNull(metadataScheduler, "metadataScheduler is null"); | ||
this.useUniqueTableLocation = useUniqueTableLocation; | ||
this.allowManagedTableRename = allowManagedTableRename; | ||
this.metadataFetchingExecutor = requireNonNull(metadataFetchingExecutor, "metadataFetchingExecutor is null"); | ||
} | ||
|
||
public TableSnapshot getSnapshot(ConnectorSession session, SchemaTableName table, String tableLocation, Optional<Long> atVersion) | ||
|
@@ -798,12 +807,40 @@ private List<ColumnMetadata> getTableColumnMetadata(MetadataEntry metadataEntry, | |
@Override | ||
public List<SchemaTableName> listTables(ConnectorSession session, Optional<String> schemaName) | ||
{ | ||
return schemaName.map(Collections::singletonList) | ||
return streamTables(session, schemaName) | ||
.map(TableInfo::tableName) | ||
.collect(toImmutableList()); | ||
} | ||
|
||
@Override | ||
public Map<SchemaTableName, RelationType> getRelationTypes(ConnectorSession session, Optional<String> schemaName) | ||
{ | ||
return streamTables(session, schemaName) | ||
.collect(toImmutableMap(TableInfo::tableName, this::resolveRelationType, (ignore, second) -> second)); | ||
} | ||
|
||
private Stream<TableInfo> streamTables(ConnectorSession session, Optional<String> optionalSchemaName) | ||
{ | ||
List<Callable<List<TableInfo>>> tasks = optionalSchemaName.map(Collections::singletonList) | ||
.orElseGet(() -> listSchemaNames(session)) | ||
.stream() | ||
.flatMap(schema -> metastore.getAllTables(schema).stream() | ||
.map(table -> new SchemaTableName(schema, table))) | ||
.map(schemaName -> (Callable<List<TableInfo>>) () -> metastore.getAllTables(schemaName)) | ||
.collect(toImmutableList()); | ||
try { | ||
return processWithAdditionalThreads(tasks, metadataFetchingExecutor).stream() | ||
.flatMap(Collection::stream); | ||
} | ||
catch (ExecutionException e) { | ||
throw new RuntimeException(e.getCause()); | ||
} | ||
} | ||
|
||
private RelationType resolveRelationType(TableInfo tableInfo) | ||
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. @piotrrzysko I would drop the question from the commit message.
I guess the question here is, is 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 it is ok for me to have the |
||
{ | ||
if (tableInfo.extendedRelationType() == TableInfo.ExtendedRelationType.TRINO_VIEW) { | ||
return RelationType.VIEW; | ||
} | ||
return RelationType.TABLE; | ||
} | ||
|
||
@Override | ||
|
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.
8 seems pretty low. Did you test bigger number of threads?