Skip to content

fix: stop silent wrong answers in distributed planner - #57

Merged
renecannao merged 5 commits into
fix/shard-dml-routingfrom
fix/shard-planner-correctness
Aug 19, 2026
Merged

fix: stop silent wrong answers in distributed planner#57
renecannao merged 5 commits into
fix/shard-dml-routingfrom
fix/shard-planner-correctness

Conversation

@renecannao

Copy link
Copy Markdown
Collaborator

Summary

Stacked on #56.

  • COUNT(DISTINCT) / unknown aggs: no longer two-phase SUM_OF_COUNTS / SUM_OF_SUMS. Gather rows and aggregate locally. Parser records FLAG_FUNC_DISTINCT; AggregateOperator honors it.
  • GROUP BY … HAVING … ORDER BY: keep FILTER and SORT above MERGE_AGGREGATE (previously dropped when ORDER BY was present).
  • WINDOW: distribute as gather-then-window. ORDER BY / LIMIT no longer replace a WINDOW node with MERGE_SORT.
  • Live proof: LiveShardedWriteTest.InsertThenPointSelect (skips unless MySQL is on 13306+13307). test_sqlengine.sh sharded INSERTs id=11 then point-SELECTs it.

Validation

  • ./run_tests --gtest_brief=1: 1309 passed, 38 skipped, 0 failed
  • ./run_tests --gtest_filter='DistributedPlannerTest.CountDistinct*:DistributedPlannerTest.GroupBy*:DistributedPlannerTest.Window*:PlanExecutorTest.CountDistinctDept'

COUNT(DISTINCT) and unknown aggs no longer merge as SUM_OF_COUNTS.
They gather rows and aggregate locally, with DISTINCT honored in
AggregateOperator. GROUP BY keeps HAVING and ORDER BY. WINDOW is
distributed as gather-then-window so ORDER BY cannot drop it.

Adds mock coverage plus a live 2-shard INSERT-then-point-SELECT
gtest (skips without 13306/13307) and a sqlengine sharded INSERT check.
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 805451de-fbe6-4948-a724-aaab210ffb64

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Rewrite DERIVED_SCAN inner plans so FROM (SELECT ...) hits remote
shards. Store remote_sql_len as uint32_t so statements longer than
64KB are not truncated. Resolve ORDER BY position/alias in the plan
builder, and only MERGE_SORT when every key is a table column —
expressions gather and sort locally instead of comparing column 0.
Refuse multi-table UPDATE/DELETE when any table is sharded or backends
differ. Evaluate HAVING against aggregate output so COUNT(*) filters
work locally and distributed. Push equi-joins of same-layout sharded
tables to each shard. sqlengine and mysql_server use 2PC when backends
are configured; SELECTs inside an open distributed txn hit pinned
sessions. Optional --txn-log on sqlengine.
fix: close remaining sharding correctness holes
fix: distribute derived tables and stop silent sort/SQL bugs
@renecannao
renecannao merged commit 7e0a05f into fix/shard-dml-routing Aug 19, 2026
1 check passed
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.

1 participant