Skip to content

Hive 30249 - #6961

Open
illiabarbashov-sketch wants to merge 2 commits into
apache:masterfrom
illiabarbashov-sketch:HIVE-30249
Open

illiabarbashov-sketch wants to merge 2 commits into
apache:masterfrom
illiabarbashov-sketch:HIVE-30249

Conversation

@illiabarbashov-sketch

@illiabarbashov-sketch illiabarbashov-sketch commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR reduces the HMS calls made while compiling a query. Most of them are lookups of the same metadata repeated within one compilation, which now come from the query-level HMS cache

Why are the changes needed?

Compilation goes back to HMS for the same metadata many times: once per table alias, per getMetaData pass (before CBO, after CBO, per subquery, in the masking rewrite), and per statistics or partition call. With a remote HMS each of these is a network round trip, and that adds directly to compile time.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

  • New unit tests in TestSessionHiveMetaStoreClientQueryCache, built on a mocked metastore client.
  • Qtests: TestMiniLlapLocalCliDriver passes with check_constraint.q, constraints_optimization.q, cte_mat_1.q, default_constraint.q, insert_overwrite.q, materialized_view_rewrite_1.q and sqlmerge_stats.q.
  • TPC-DS plans: all 200 TestTezTPCDS30TBPerfCliDriver tests pass with no .q.out changes, so plans are identical.
  • HMS call counts and compile times which measured on that driver with a temporary call counter.

- Hive.getTableConstraints moved to the combined getAllTableConstraints call, which the query-level HMS cache does not
  cover (it caches the per-type constraint calls); every Table copy made during compilation fetched again
- Impact (local, TPC-DS 30 TB perf driver, 201 statements): 1,866 -> 992 calls (the distinct tables), compile 350.3 ->
  283.8 s (-19 %); one statement spent 2.0 s of 2.0 s Calcite plan generation in 26 calls at ~80 ms
- cluster (TPC-DS 10TB Parquet, 24 x r6id, 198 query-iterations): warm compile 386.8 -> 383.6 s, no wall gain
  against the cluster HMS
- the cache hands out a copy: Hive.getTableConstraints keeps only the RELY constraints in the object it gets
- test: one call per query; the copy (mutation: the cached object itself) keeps the second result whole
Cut the HMS calls made while compiling a query:
- Do not fetch constraints for materialized view scans in the registry; materialized views
  cannot have constraints.
- Share the getTable entry with the write id list lookup: getValidWriteIdList sent a request
  without getColumnStats/engine, so the same table took a second HMS call. The TABLE cache key
  is now a copy of the caller's request.
- Cache getCheckConstraints and getDefaultConstraints, fetched once per MERGE branch and per
  insert destination.
- Cache getPartitionWithAuthInfo for the static partition of an insert target, handing out a
  copy as ql Partition changes the object it gets; a missing partition is not cached.
- Remember tables missing from the metastore (CTE names, optional lookups) within a
  compilation; createTable drops the entry.
- Pass the Table to getPartitionColumnStatistics instead of fetching it again.
- HiveMetaStoreClientWithLocalCache takes the table for its watermark and transactional check
  from the query-level cache instead of two getTable RPCs per statistics/partition call.

TPC-DS 30TB perf driver (201 statements), on top of the getAllTableConstraints cache:
HMS RPCs 5956 -> 3148 (master: 6830), median summed compile time 180.2 s (master) -> 147.9 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants