Repository navigation
Conversation
Re-analyzing the original AST resolved a `DataLakeCatalog` table again and repeated the REST catalog lookup. Co-authored-by: Cursor <cursoragent@cursor.com>
Keep existing header analysis for all other clustered storage reads. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dbe0f46f39
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| sample_block = InterpreterSelectQueryAnalyzer::getSampleBlock(query_to_send, context, SelectQueryOptions(processed_stage)); | ||
| /// For an unchanged query, calculate the header from the resolved query tree. Re-analyzing | ||
| /// the original AST resolves DataLakeCatalog tables once more and repeats a remote catalog lookup. | ||
| if (canReuseResolvedQueryTreeForHeader() && query_to_send == query_info.query && query_info.query_tree) |
There was a problem hiding this comment.
Reuse the resolved tree after query rewrites
When a DataLakeCatalog query contains a JOIN or a table-referencing IN/WHERE that must remain on the initiator, updateQueryWithJoinToSendIfNeeded replaces query_to_send with a new AST. This condition then falls through to InterpreterSelectQueryAnalyzer::getSampleBlock, which resolves the catalog table again, so these supported cluster requests still perform duplicate catalog metadata reads despite the stated fix. Preserve the rewritten query tree for header calculation, or otherwise calculate the rewritten header without re-resolving the catalog; a focused test with a catalog table joined to a local Memory table would expose the duplicate lookup.
Useful? React with 👍 / 👎.
Re-analyzing the rewritten shard AST resolved the catalog table a second time. Co-authored-by: Cursor <cursoragent@cursor.com>
CI triage for f281aab (run 40862005818, still in progress)TL;DR: 6 red checks. 1 is caused by this PR (Swarms regression,
❌ Swarms regression (caused by this PR)The base-branch failures appear on #2730 and #2715 too: Nearly all the new failures have the same error: Counts: Root cause: this is the new branch at else if (canReuseResolvedQueryTreeForHeader() && query_to_send == query_info.query && query_info.query_tree)
sample_block = getHeaderForProcessingStage(column_names, storage_snapshot, query_info, context, processed_stage);When the join is not rewritten ( Suggested fix: use the shortcut only when it is safe, i.e. when this storage is the left/only table expression. For example: else if (canReuseResolvedQueryTreeForHeader() && query_to_send == query_info.query && query_info.query_tree
&& query_info.table_expression
&& extractLeftTableExpression(query_info.query_tree->as<QueryNode &>().getJoinTree()) == query_info.table_expression)The simpler option is to skip the shortcut whenever the query has a JOIN (
Report: swarms/report.html Pre-existing (not caused by this PR)The evidence is the same for all of these: the same test sets with the same counts fail on #2730 (fa0e5fe) and #2715 (afa617e), which don't touch this code.
PR's own tests ✅
Analysis is static, from the praktika/regression reports. A fix would be validated by the next CI run on this PR. |
The resolved tree kept the outer `__tableN` alias, so a non-leftmost catalog table did not match the shard block. Co-authored-by: Cursor <cursoragent@cursor.com>
CI triage for 6a9a4cbVerdict: 6 failing checks. 0 are clearly caused by this PR and 5 already fail on the base branch. One swarms scenario might be linked to this PR and needs a re-run to tell.
How I checked "pre-existing": I compared against praktika Integration tests: pre-existing, not this PRNone of these tests use
Regression oauth: pre-existingThe same 7 scenarios fail on #2735 and #2730, e.g. Regression swarms: mostly pre-existing, one scenario needs a lookThese 3 fail on every sibling PR (#2735, #2737, #2730, #2715):
What the test does (
This goes through exactly the branch the PR adds: a DataLakeCatalog table, analyzer on, The test is timing-sensitive by design: its own comments call stopping a node mid-query "inherently racy". So the likely explanation is that the shorter dispatch path changed the race, not that results are wrong. But this is one sample and I can't rule out a behaviour change from one run. Suggested next step:
Other notes
|
mkmkme
left a comment
There was a problem hiding this comment.
🤖 [Posted by an LLM agent on behalf of @mkmkme]
A few things before merge:
-
Path 1 doesn't get the alias renumbering. 6a9a4cb renumbers
__tableNto__table1only on thegetHeaderForProcessingStagepath. The join-rewrite path builds its tree from the same left table expression and goes straight togetSampleBlock. Details inline. -
Some cluster paths still read the catalog twice. With
object_storage_cluster_join_mode = 'global'and a join,query_to_sendis rewritten butresolved_query_treeis never set, so the header falls back to re-analyzing the AST. The same happens inreadFromRemoteInitiatorwhen the query was rewritten (InterpreterSelectQueryAnalyzer(query_for_remote)), and with the old analyzer. That's fine as a first step, but the changelog entry should then say which cases are fixed, or these paths should be covered too. -
The tests check the number of catalog calls, but not the results. The risk in this change is a header that no longer matches what the shards return, and swarms
joins/unionalready broke once because of that. Could you add result checks for:count(), orGROUP BYwithWHERE(the query from #2721; it runs atWithMergeableState);UNION ALLof two catalog tables;- a catalog table that isn't leftmost, with an
IN (SELECT ... FROM local_table)filter (this hits path 1); object_storage_cluster_join_mode = 'global', just to show it still works.
-
Swarms
node failure/check restart swarm nodefails only on this PR. It's timing-sensitive, but please re-run it to rule this change out.
Metadata nits:
- Duplicate remote calls are latency rather than wrong results, so
Performance Improvementfits better thanBug Fix. - A more specific changelog entry would help, e.g.: "Tables from a
DataLakeCatalogdatabase read withobject_storage_clusterno longer request table metadata from the catalog twice per query." - Please replace
Solved #2721withCloses: https://github.com/Altinity/ClickHouse/issues/2721.
| if (canReuseResolvedQueryTreeForHeader() && resolved_query_tree) | ||
| sample_block = InterpreterSelectQueryAnalyzer::getSampleBlock(resolved_query_tree, context, SelectQueryOptions(processed_stage)); |
There was a problem hiding this comment.
🤖 [Posted by an LLM agent on behalf of @mkmkme]
This path needs the same renumbering as the branch below. rewritten_query_tree is built from left_table_expression of query_info.query_tree. When the planner wraps a catalog table that isn't leftmost, that table keeps its outer alias (__table2). The shard re-analyzes the AST from queryNodeToDistributedSelectQuery, and createUniqueAliasesIfNecessary there starts again at __table1. So the header here can have __table2.* columns while the shard returns __table1.*.
I haven't run it, but from reading the code this should hit it:
SELECT t.symbol
FROM mem AS m
INNER JOIN lake.`ns.tbl` AS t ON m.symbol = t.symbol
WHERE t.symbol IN (SELECT symbol FROM local_table)
SETTINGS object_storage_cluster = 'cluster_simple'Suggested fix:
if (canReuseResolvedQueryTreeForHeader() && resolved_query_tree)
{
auto header_tree = resolved_query_tree->clone();
createUniqueAliasesIfNecessary(header_tree, context);
sample_block = InterpreterSelectQueryAnalyzer::getSampleBlock(header_tree, context, SelectQueryOptions(processed_stage));
}| assert node2.query(f"SELECT * FROM {CATALOG_NAME}.`{root_namespace}.{table_name}`", settings={"parallel_replicas_for_cluster_engines": 1, "enable_parallel_replicas": 2, "cluster_for_parallel_replicas": "cluster_simple"}) == 'pablo\n' | ||
|
|
||
|
|
||
| def test_object_storage_cluster_loads_rest_catalog_table_once(started_cluster): |
There was a problem hiding this comment.
🤖 [Posted by an LLM agent on behalf of @mkmkme]
These three tests only check DataLakeRestCatalogGetTableMetadata = 1. If the header from the reused tree didn't match what the shard sends, they would only catch it for SELECT * and a simple join. Could you also check the results of an aggregate (SELECT count() ... WHERE ..., as in #2721) and of a UNION ALL of two catalog tables? Those are the shapes that broke in swarms.
|
One more thing here Audit review: PR #2729 — Read Iceberg catalog once during cluster requestsPR: #2729 (head Related: #2721 Confirmed defects1. Medium — A catalog table read by a secondary query fails with
|
| @@ -205,6 +203,7 @@ class StorageObjectStorageCluster : public IStorageCluster | |||
|
|
|||
| /// Whether this query is served by `pure_storage` instead of being distributed over a cluster. | |||
| bool readsFromPureStorage(ContextPtr context) const; | |||
| bool canReuseResolvedQueryTreeForHeader() const override { return is_datalake_catalog_table; } | |||
There was a problem hiding this comment.
Why only catalogs can do it?
|
|
||
| if (settings[Setting::allow_experimental_analyzer]) | ||
| { | ||
| sample_block = InterpreterSelectQueryAnalyzer::getSampleBlock(query_to_send, context, SelectQueryOptions(processed_stage)); | ||
| /// Re-analyzing the shard AST resolves a `DataLakeCatalog` table again and repeats a remote catalog lookup. |
There was a problem hiding this comment.
Nit: I would make this comment a bit more descriptive, something along the following lines:
Try to avoid unnecessary catalog calls in the following cases:
- query tree has already been resolved, this is ok because of xyz
- ...
I still don`t understand case 2 very well tho, looking into it
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Read Iceberg catalog once during cluster requests.
Documentation entry for user-facing changes
Solved #2721
CI/CD Options
Exclude tests:
Regression jobs to run: