Skip to content

fix(scheduler): keep a null-aware anti join's probe coalesce in the static planner - #2898

Open
ewoodbury wants to merge 3 commits into
apache:mainfrom
ewoodbury:ewoodbury/null-aware-probe-stage
Open

ewoodbury wants to merge 3 commits into
apache:mainfrom
ewoodbury:ewoodbury/null-aware-probe-stage

Conversation

@ewoodbury

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #2849.

Rationale for this change

A NOT IN subquery that stays a null-aware anti join has to read the whole subquery result in one task to be correct. The static planner gets that by putting a coalesce in front of the join, but when there's an aggregate above the join, the planner later removes that coalesce. The join then runs as several tasks, and each one returns its own copy of the rows it didn't match.

Example: with the static planner and the NOT IN rewrite turned off, this query over a 4-file t2 returns 26/26/23 instead of 5/5/5:

select a % 3, count(*) from t1 where a not in (select b from t2) group by a % 3

It only happens with the static planner (or pipelined mode, which always uses it). Default settings don't hit it.

What changes are included in this PR?

The static planner now ends the stage right after a null-aware join, so nothing planned above it can remove the coalesce. The subquery side is still read in parallel. The cost is one extra stage, carrying the join's output, which is never larger than the table the join already holds in memory.

A one-partition coalesced shuffle reader would avoid the extra stage, but the static planner doesn't support those yet, so that's left as a follow-up.

Tests: the null_aware client test gets a static-planner case and a GROUP BY query (that combination fails on main), and a planner test checks the new stage.

Are there any user-facing changes?

Correct results. EXPLAIN shows one more stage for null-aware anti joins under the static planner.

…tatic planner

The static planner left the coalesce over a null-aware join's probe side
inside the join's stage. An aggregate above the join reran
EnsureRequirements over that stage and removed the coalesce, so the join
ran as several tasks and emitted unmatched build rows once per task.
Close the stage at the join so no later pass sees the coalesce.

Closes apache#2849.

@milenkovicm milenkovicm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks @ewoodbury one nit to be considered

// default adaptive planner; "rewrite_disabled_static" does the same
// under the static planner. Both run one partition per task, as on a
// cluster.
for variant in [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: The PR body says pipelined mode is affected too, because it always uses the static planner. Would it make sense to test it ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah definitely - pushed up a quick test covering pipelined mode

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.

Static planner: null-aware anti join loses its probe-side coalesce under an aggregate

2 participants