Skip to content

sql: Fix autorouting for expensive functions#35413

Merged
def- merged 2 commits intoMaterializeInc:mainfrom
def-:pr-auto-route-expensive
Mar 16, 2026
Merged

sql: Fix autorouting for expensive functions#35413
def- merged 2 commits intoMaterializeInc:mainfrom
def-:pr-auto-route-expensive

Conversation

@def-
Copy link
Contributor

@def- def- commented Mar 11, 2026

Only top-level expensive functions were considered in the auto-routing

Broken in #20994

One line fix, the rest is adding tests that actually made me find this. Without the production code change the tests fail like this:

    EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
    (SELECT 1) UNION ALL (SELECT 1 + 2)
    OutputFailure:test/sqllogictest/explain/auto_route_expensive.slt:41
            expected: Values(["Explained Query (fast path):\n  Constant\n    - (1)\n    - (3)\n\nTarget cluster: quickstart\n"])
            actually: Values(["Explained Query (fast path):\n  Constant\n    - (1)\n    - (3)\n\nTarget cluster: mz_catalog_server\n"])
            actual raw: [Row { columns: [Column { name: "Optimized Plan", table_oid: None, column_id: None, type: Text }] }]
    ----
    EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
    SELECT 1 WHERE EXISTS (SELECT 1 + 2)
    OutputFailure:test/sqllogictest/explain/auto_route_expensive.slt:54
            expected: Values(["Explained Query (fast path):\n  Constant\n    - (1)\n\nTarget cluster: quickstart\n"])
            actually: Values(["Explained Query (fast path):\n  Constant\n    - (1)\n\nTarget cluster: mz_catalog_server\n"])
            actual raw: [Row { columns: [Column { name: "Optimized Plan", table_oid: None, column_id: None, type: Text }] }]
    ----
    EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
    SELECT 1 WHERE (SELECT 1 + 2) > 0
    OutputFailure:test/sqllogictest/explain/auto_route_expensive.slt:66
            expected: Values(["Explained Query (fast path):\n  Constant\n    - (1)\n\nTarget cluster: quickstart\n"])
            actually: Values(["Explained Query (fast path):\n  Constant\n    - (1)\n\nTarget cluster: mz_catalog_server\n"])
            actual raw: [Row { columns: [Column { name: "Optimized Plan", table_oid: None, column_id: None, type: Text }] }]
    ----
    FAIL: output-failure=3 success=3 total=6

@def- def- requested a review from ggevay March 11, 2026 09:18
@def- def- requested a review from a team as a code owner March 11, 2026 09:18
@github-actions
Copy link

Thanks for opening this PR! Here are a few tips to help make the review process smooth for everyone.

PR title guidelines

  • Use imperative mood: "Fix X" not "Fixed X" or "Fixes X"
  • Be specific: "Fix panic in catalog sync when controller restarts" not "Fix bug" or "Update catalog code"
  • Prefix with area if helpful: compute: , storage: , adapter: , sql:

Pre-merge checklist

  • The PR title is descriptive and will make sense in the git log.
  • This PR has adequate test coverage / QA involvement has been duly considered. (trigger-ci for additional test/nightly runs)
  • If this PR includes major user-facing behavior changes, I have pinged the relevant PM to schedule a changelog post.
  • This PR has an associated up-to-date design doc, is a design doc (template), or is sufficiently small to not require a design.
  • If this PR evolves an existing $T ⇔ Proto$T mapping (possibly in a backwards-incompatible way), then it is tagged with a T-proto label.
  • If this PR will require changes to cloud orchestration or tests, there is a companion cloud PR to account for those changes that is tagged with the release-blocker label (example).

Copy link
Contributor

@ggevay ggevay left a comment

Choose a reason for hiding this comment

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

Yes, thank you, this is definitely fixing a bug!

(I hope fixing this won't break somebody's dbt workflows. The PR will make some queries not run on mz_catalog_server, but on the active cluster, and 6a93648's commit msg says that the auto-routing of simple queries was introduced to "help some dbt use cases". I hope those dbt queries will still be covered. Unfortunately that commit doesn't seem to have added tests for the specific dbt queries. Tbh, this whole auto-routing feels quite messy.)

def- added 2 commits March 16, 2026 18:20
Only top-level expensive functions were considered in the auto-routing

Broken in MaterializeInc#20994

One line fix, the rest is adding tests that actually made me find this.
@def- def- force-pushed the pr-auto-route-expensive branch from 7c63dfb to 0af11ce Compare March 16, 2026 18:21
@def- def- enabled auto-merge (squash) March 16, 2026 18:21
@def- def- merged commit 02decf6 into MaterializeInc:main Mar 16, 2026
126 checks passed
@def- def- deleted the pr-auto-route-expensive branch March 16, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants