Skip to content

Conversation

@piotrrzysko
Copy link
Member

@piotrrzysko piotrrzysko commented Nov 12, 2024

Description

For now, we are mainly focused on improving performance for connectors using Glue.

Locally, the execution time of the following query, for 6500 tables and 530 schemas, decreased from 3m 11s to 27s:

SELECT TABLE_CAT, TABLE_SCHEM, TABLE_NAME, TABLE_TYPE, REMARKS,
  TYPE_CAT, TYPE_SCHEM, TYPE_NAME,   SELF_REFERENCING_COL_NAME, REF_GENERATION
FROM system.jdbc.tables
WHERE TABLE_CAT = 'hive' AND TABLE_TYPE IN ('TABLE', 'VIEW')
ORDER BY TABLE_TYPE, TABLE_CAT, TABLE_SCHEM, TABLE_NAME;

Additional context and related issues

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
(x) Release notes are required, with the following suggested text:

## Hive, Iceberg, Delta
* Improve performance of querying system.jdbc.tables for Hive, Iceberg, and Delta. ({issue}`24110`)

@cla-bot cla-bot bot added the cla-signed label Nov 12, 2024
@github-actions github-actions bot added iceberg Iceberg connector delta-lake Delta Lake connector hive Hive connector labels Nov 12, 2024
@piotrrzysko piotrrzysko changed the title [WIP] Improve performance of querying system.jdbc.tables for Hive, Iceberg, and Delta [WIP] Improve performance of querying system.jdbc.tables for Hive, Iceberg, and Delta Nov 12, 2024
@shohamyamin
Copy link
Contributor

Hi there!

I came across this PR and was curious if it might address a similar issue to the one in my PR #23909, which focuses on improving the retrieval of column metadata for Iceberg tables. In my PR, I added parallelization to the streamTableColumns method in IcebergMetadata.java, enhancing performance for users pulling column metadata.

I noticed there haven’t been any changes related to the REST catalog in this PR. Would you consider applying similar improvements to the REST catalog as well? This would allow users working with REST catalog setups to benefit from the enhanced metadata retrieval. Also, could you provide some details about the use cases this PR aims to support?

Thanks!

@piotrrzysko piotrrzysko force-pushed the parallel-jdbc-table branch 2 times, most recently from e8bcc3f to f7f8579 Compare November 13, 2024 05:43
@piotrrzysko
Copy link
Member Author

@shohamyamin

I came across this PR and was curious if it might address a similar issue to the one in my #23909, which focuses on improving the retrieval of column metadata for Iceberg tables.

This PR focuses on improving the performance of table listing. It won't address column retrieval, but it should be relatively straightforward to extend the current changes to include columns as well.

I noticed there haven’t been any changes related to the REST catalog in this PR. Would you consider applying similar improvements to the REST catalog as well?

Currently, I'm mainly focused on improving performance for the Glue catalog, but the same approach can be applied to other catalogs as well.

Also, could you provide some details about the use cases this PR aims to support?

The goal is to improve the performance of queries like the one in the PR's description, which are often issued by DB tools to list tables.

@hashhar hashhar self-requested a review November 14, 2024 14:58
Copy link
Member

@lukasz-stec lukasz-stec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, that will be a great improvement for glue catalogs with many schemas!.
Please provide benchmark results once you have it, both in PR description but also in the commit messages if applicable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@piotrrzysko I would drop the question from the commit message.
The question was:

Is this resolution necessary? Could we instead use the
existing mapping between ExtendedRelationType and RelationType that's
already encapsulated in RelationType?

I guess the question here is, is OTHER_VIEW or OTHER_MATERIALIZED_VIEW possible in delta-lake? TRINO_MATERIALIZED_VIEW is not.
@raunaqmorarka @dain Do you know?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw it is ok for me to have the resolveRelationType here to keep the existing functionality

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would drop the question from the commit message.
The question is

Question: Should we consider setting the default value of
"hive.metadata.parallelism" to 1 when using the "file" metastore?

I would not worry about file metastore. @raunaqmorarka WDYT?

Copy link
Member

@hashhar hashhar Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: seems super easy to do however (in the module set default config), but yes, I don't think it matters unless this change has affected test runtime for tests which use the FileHMS.

@piotrrzysko
Copy link
Member Author

piotrrzysko commented Nov 17, 2024

Benchmark results for the following query (master vs. 8 thread vs. 16 threads):

SELECT * FROM system.jdbc.tables WHERE table_cat = 'hive'

The queried catalog had 234 schemas with a total of 5674 tables.

image

@piotrrzysko piotrrzysko changed the title [WIP] Improve performance of querying system.jdbc.tables for Hive, Iceberg, and Delta Improve performance of querying system.jdbc.tables for Hive, Iceberg, and Delta Nov 17, 2024
@piotrrzysko piotrrzysko marked this pull request as ready for review November 17, 2024 19:48
@github-actions github-actions bot added the docs label Nov 17, 2024
Copy link
Member

@hashhar hashhar Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: seems super easy to do however (in the module set default config), but yes, I don't think it matters unless this change has affected test runtime for tests which use the FileHMS.

@hashhar
Copy link
Member

hashhar commented Nov 20, 2024

/test-with-secrets sha=a443d3f9c7a936a810aac5f5b2b0a0e552f9beaf

@github-actions
Copy link

github-actions bot commented Nov 20, 2024

The CI workflow run with tests that require additional secrets finished as failure: https://github.com/trinodb/trino/actions/runs/11936682245

The parameter for specifying the maximum number of threads fetching
tables ("hive.metadata.parallelism") aligns with the naming convention
used in the BigQuery connector ("bigquery.metadata.parallelism").

Parallelization has been introduced in HiveMetadata rather than in
specific metastore implementations, primarily to avoid reintroducing a
cache storing tables for all schemas, which was removed in
trinodb@cb4d168.
This approach attempts to parallelize table retrieval for all metastore
types, even though not all support concurrent access. Currently, only
the FileHiveMetastore does not support multithreaded access, making
parallelization ineffective.

Benchmark results for the following query:
SELECT * FROM system.jdbc.tables WHERE table_cat = 'hive'
show decrease in execution time from 55s to 15s.
The queried catalog had 234 schemas with a total of 5674 tables.
Before introducing DeltaLakeMetadata::getRelationTypes,
ConnectorMetadata::getRelationTypes was used to retrieve relation types
for Delta Lake. The original implementation classified all tables as
RelationType.TABLE, except those with the extended relational type
TRINO_VIEW, which were classified as RelationType.VIEW. This is why the
resolveRelationType method was added in this commit.

Benchmark results for the following query:
SELECT * FROM system.jdbc.tables WHERE table_cat = 'delta_lake'
show decrease in execution time from 55s to 16s.
The queried catalog had 234 schemas with a total of 5674 tables.
Parallelization has been implemented at the TrinoCatalog level, rather
than in IcebergMetadata, because some catalogs (e.g., Nessie) seem to
support optimized table retrieval across all schemas. Currently,
parallelization has been added for Glue and Hive catalogs, but it can
easily be extended to other catalogs as well.

Benchmark results for the following query:
SELECT * FROM system.jdbc.tables WHERE table_cat = 'iceberg'
show decrease in execution time from 54s to 17s.
The queried catalog had 234 schemas with a total of 5674 tables.
@piotrrzysko
Copy link
Member Author

Rebased and addressed comments.

@hashhar
Copy link
Member

hashhar commented Nov 22, 2024

/test-with-secrets sha=c84ce622d138423d1d8cd51e7e34a2db3447eb33

@github-actions
Copy link

github-actions bot commented Nov 22, 2024

The CI workflow run with tests that require additional secrets finished as failure: https://github.com/trinodb/trino/actions/runs/11973910005

@hashhar
Copy link
Member

hashhar commented Nov 22, 2024

unrelated failure on test with secrets, merging. Thanks a lot @piotrrzysko. 😄 🚀

I've reworded release notes a little bit, please take a look.

@hashhar hashhar merged commit d34e358 into trinodb:master Nov 22, 2024
97 of 98 checks passed
@github-actions github-actions bot added this to the 466 milestone Nov 22, 2024
@mosabua
Copy link
Member

mosabua commented Nov 25, 2024

@hashhar @raunaqmorarka @piotrrzysko - can you explain this more so we can get a release notes entry that is more user facing. What does it actually improve? Is this for federated queries where these connectors need to access jdbc info? Also .. is Hudi connector also affected?

@hashhar
Copy link
Member

hashhar commented Nov 26, 2024

this improves metadata retreival performance when accessing the system.jdbc.tables and any Hive, Iceberg or Delta catalogs are present/metadata is queried.

The proposed RN entry is indeed user-facing - people who were querying system.jdbc.tables will now see faster performance if they are using Hive, Iceberg or Delta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed delta-lake Delta Lake connector docs hive Hive connector iceberg Iceberg connector performance

Development

Successfully merging this pull request may close these issues.

6 participants