Skip to content
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

Fix 0-Task Plans in Single-Shard Router When Updating a Local Table with Reference Table in Subquery #7897

Merged
merged 13 commits into from
Feb 25, 2025

Conversation

m3hm3t
Copy link
Contributor

@m3hm3t m3hm3t commented Feb 12, 2025

This PR fixes an issue #7891 in the Citus planner where an UPDATE on a local table with a subquery referencing a reference table could produce a 0-task plan. Historically, the planner sometimes failed to detect that both the target and referenced tables were effectively “local,” assigning INVALID_SHARD_ID and yielding a no-op plan.

Root Cause

  • In the Citus router logic (PlanRouterQuery), we relied on shardId to determine whether a query should be routed to a single shard.
  • If shardId == INVALID_SHARD_ID, but we also had not marked the query as a “local table modification,” the code path would produce zero tasks.
  • Local + reference tables do not require multi-shard routing. Failing to detect this “purely local” scenario caused Citus to incorrectly route to zero tasks.

Changes

Enhanced Local Table Detection

  • Updated IsLocalTableModification and related checks to consider both local and reference tables as “local” for planning, preventing the 0-task scenario.
  • Expanded ContainsOnlyLocalOrReferenceTables to return true if there are no fully distributed tables in the query.

Added Regress Test

  • Introduced a new regress test (issue_7891.sql) which reproduces the scenario.
  • Verifies we get a valid single- or local-task plan rather than a 0-task plan.

@m3hm3t m3hm3t self-assigned this Feb 12, 2025
Copy link

codecov bot commented Feb 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.46%. Comparing base (c55bc8c) to head (6fd8a85).
Report is 22 commits behind head on release-13.0.

Additional details and impacted files
@@               Coverage Diff                @@
##           release-13.0    #7897      +/-   ##
================================================
- Coverage         89.48%   89.46%   -0.02%     
================================================
  Files               276      276              
  Lines             60063    60009      -54     
  Branches           7524     7516       -8     
================================================
- Hits              53747    53687      -60     
- Misses             4166     4173       +7     
+ Partials           2150     2149       -1     

@m3hm3t m3hm3t changed the title Simplify ContainsOnlyLocalTables function to check only for distribut… Fix 0-Task Plans in Single-Shard Router When Updating a Local Table with Reference Table in Subquery Feb 12, 2025
@m3hm3t m3hm3t added the bug label Feb 12, 2025
@m3hm3t m3hm3t marked this pull request as ready for review February 13, 2025 08:16
Copy link
Contributor

@colm-mchugh colm-mchugh left a comment

Choose a reason for hiding this comment

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

Lgtm, thanks for accommodating the test requests.

@m3hm3t m3hm3t merged commit 2b96422 into release-13.0 Feb 25, 2025
119 checks passed
@m3hm3t m3hm3t deleted the m3hm3t/issue_7891 branch February 25, 2025 17:49
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.

2 participants