You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Storage Join(ALL, RIGHT, ...) + QUALIFY NULL: rewriting WHERE p to WHERE p AND 1 flips 0 rows → all right-side rows with left columns defaulted (no-op rewrite changes result + breaks join matching) #106949
Wrong result: WHERE p AND 1 + QUALIFY NULL over a Join-engine RIGHT JOIN drops both filters (and join matching)
Summary
Over an ALL RIGHT JOIN against a Join(ALL, RIGHT, ...) engine table,
wrapping the WHERE predicate in a no-op conjunction (p → p AND 1)
flips the result from correct to wrong when a QUALIFY clause is present:
WHERE p QUALIFY NULL → 0 rows (correct — QUALIFY NULL filters every row);
WHERE (p AND 1) QUALIFY NULL → all right-side rows, with the
left-side columns defaulted even for keys that do match.
Both the WHERE and the QUALIFY filters are effectively dropped, and the
join stops matching. The predicate must reference left-table columns through
a null-safe comparison (t.key <=> tj.key) composed inside another
expression; a plain t.val > 0 predicate or a Memory right table behaves
correctly, so the bug needs the storage-Join right side + the composed <=> predicate + QUALIFY + the extra AND.
Found by the AST-fuzzer correctness-oracle suite from PR #99980 (Identity WHERE
oracle, p AND 1 variant).
Minimal repro
CREATETABLEtmin (key2 UInt64, key1 Int64) ENGINE = Memory;
INSERT INTO tmin VALUES (2,-2),(3,-3);
CREATETABLEtjmin (key2 UInt64, key1 Int64) ENGINE =Join(ALL, RIGHT, key1, key2);
INSERT INTO tjmin VALUES (2,-2),(6,-6);
SELECT*FROM tmin ALL RIGHT JOIN tjmin ONtjmin.key2=tmin.key2ANDtjmin.key1=tmin.key1WHERE (tmin.key2<=>tjmin.key2) =tmin.key2
QUALIFY NULL;
-- 0 rows (correct)SELECT*FROM tmin ALL RIGHT JOIN tjmin ONtjmin.key2=tmin.key2ANDtjmin.key1=tmin.key1WHEREand((tmin.key2<=>tjmin.key2) =tmin.key2, 1)
QUALIFY NULL;
-- 2 rows (WRONG):-- 0 0 2 -2 <- left side defaulted although (2,-2) matches-- 0 0 6 -6
Reproduced on 26.6.1.1 (master 76c2edca2fd, release build), default
settings (no compatibility needed). Without QUALIFY the two forms agree;
with a Memory right table they agree; with the bare predicate tmin.key2 <=> tjmin.key2 they agree.
Fix area
Interaction of QUALIFY-clause planning with filter pushdown into StorageJoin reads: with the extra conjunction the combined WHERE+QUALIFY filter appears to be pushed into (or eliminated around)
the storage-join read incorrectly. Likely in the analyzer/planner QUALIFY
handling (src/Planner/) combined with StorageJoin's ALL RIGHT non-matched-row generation.
Original fuzzer hit (for reference)
2026-06-10 10:34:50, fuzz-lab cycle 9i instance 04 (release, batch with --compatibility=25.3), run dir tmp/fuzz_lab/runs/20260610-1020-58419a326d5/inst/04/
(mismatch_artifacts/run_1/). Identity WHERE (p AND 1) oracle on a
fuzzed query from the storage-join name-clash stateless test.
Root cause is in OUTER JOIN filter push-down. getConjunctionNodes() marks a WHERE conjunct pushable to a join side when all its children are allowed inputs of that side. A pure constant (1, or the NULL literal that QUALIFY NULL folds into WHERE) has no children, so it is trivially pushable to ANY side, including the non-preserved side of a RIGHT JOIN (whose allowed-input set is empty). The constant was pushed into the left input and dropped from the post-join filter, so the NULL filtered out the left rows, the join fabricated non-matched rows with left columns defaulted, and they escaped the now constant-free filter.
The Join(ALL, RIGHT, ...) engine is needed only because it makes the planner take the FilledJoin direct-read path; the underlying defect also reproduces over a Memory right table with WHERE and(<left predicate>, 1, NULL) (the minimal trigger, no QUALIFY required).
Fix: push a conjunct to a join side only if it actually depends on an allowed input of that side. Constants stay in the post-join filter. Regression test added; it returns 2 rows on master and 0 with the fix.
Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.
TL;DR
Storage Join(ALL, RIGHT, ...) + QUALIFY NULL: rewriting WHERE p to WHERE p AND 1 flips 0 rows → all right-side rows with left columns defaulted (no-op rewrite changes result + breaks join matching)
ClickGap verified: reproduced it with the script below on master; tested 4 version(s) — 4 affected, 0 clean (see Affects).
Reproduction
#!/bin/bash
# Issue #106949 — Join(ALL,RIGHT) + QUALIFY NULL: WHERE p vs WHERE (p AND 1)
# Correct result of q2 = 0 rows (QUALIFY NULL filters every row).
# Bug: q2 emits right-side rows with left columns defaulted (e.g. "0\t0\t2\t-2").
# exit 1 = bug reproduces ; exit 0 = clean ; exit 125 = inconclusive ; exit 124 = timeout
set -uo pipefail
BIN="$1"
PFX="CREATE TABLE tmin (key2 UInt64, key1 Int64) ENGINE = Memory; INSERT INTO tmin VALUES (2,-2),(3,-3); CREATE TABLE tjmin (key2 UInt64, key1 Int64) ENGINE = Join(ALL, RIGHT, key1, key2); INSERT INTO tjmin VALUES (2,-2),(6,-6);"
Q2="SELECT * FROM tmin ALL RIGHT JOIN tjmin ON tjmin.key2 = tmin.key2 AND tjmin.key1 = tmin.key1 WHERE and((tmin.key2 <=> tjmin.key2) = tmin.key2, 1) QUALIFY NULL;"
ERRF="$(mktemp)"
out=$(timeout 60 "$BIN" local --multiquery ${CLICKGAP_REPRO_SETTINGS:+--$CLICKGAP_REPRO_SETTINGS} --query "$PFX $Q2" </dev/null 2>"$ERRF")
rc=$?
err=$(cat "$ERRF"); rm -f "$ERRF"
[ "$rc" -eq 124 ] && { echo "TIMEOUT"; exit 124; }
if echo "$err" | grep -qiE "exception|Code: [0-9]+|NOT_IMPLEMENTED|UNKNOWN_|SYNTAX_ERROR|window function"; then
echo "INCONCLUSIVE (error/unsupported): $err"; exit 125
fi
[ "$rc" -ne 0 ] && { echo "INCONCLUSIVE (rc=$rc): $err"; exit 125; }
if [ -n "$out" ]; then
echo "BUG: q2 returned rows (expected 0):"; echo "$out"; exit 1
fi
echo "CLEAN: q2 returned 0 rows"; exit 0
Bisect
Bisected on master in 10 steps (confidence: MEDIUM); a single introducing PR could not be pinned (untested merges with no prebuilt binary in the boundary range).
Candidate range: b24615b6e963..a1f135baca60
A source-build bisect over the range was attempted but could not produce a verdict; the range above is the most precise information available.
Affects
Reproduces on: master, 26.5, 26.4, 26.3
Could not test (binary unavailable): 25.8
Suggested next step
Manual triage of the comp-query-optimizer path is needed. The reproducer above should be a fast first check.
Activity
qoega commentedon Jun 10, 2026
@groeneai could you please reproduce and fix this one? Repro is in the issue body — deterministic on master
76c2edca2fd, default settings.groeneai commentedon Jun 10, 2026
Reproduced on master and fixed in #107084.
Root cause is in OUTER JOIN filter push-down.
getConjunctionNodes()marks a WHERE conjunct pushable to a join side when all its children are allowed inputs of that side. A pure constant (1, or theNULLliteral thatQUALIFY NULLfolds into WHERE) has no children, so it is trivially pushable to ANY side, including the non-preserved side of a RIGHT JOIN (whose allowed-input set is empty). The constant was pushed into the left input and dropped from the post-join filter, so theNULLfiltered out the left rows, the join fabricated non-matched rows with left columns defaulted, and they escaped the now constant-free filter.The
Join(ALL, RIGHT, ...)engine is needed only because it makes the planner take theFilledJoindirect-read path; the underlying defect also reproduces over aMemoryright table withWHERE and(<left predicate>, 1, NULL)(the minimal trigger, noQUALIFYrequired).Fix: push a conjunct to a join side only if it actually depends on an allowed input of that side. Constants stay in the post-join filter. Regression test added; it returns 2 rows on master and 0 with the fix.
clickgapai commentedon Jun 10, 2026
Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.
TL;DR
Storage
Join(ALL, RIGHT, ...)+QUALIFY NULL: rewritingWHERE ptoWHERE p AND 1flips 0 rows → all right-side rows with left columns defaulted (no-op rewrite changes result + breaks join matching)ClickGap verified: reproduced it with the script below on
master; tested 4 version(s) — 4 affected, 0 clean (see Affects).Reproduction
Bisect
b24615b6e963..a1f135baca60Affects
master, 26.5, 26.4, 26.325.8Suggested next step
Manual triage of the
comp-query-optimizerpath is needed. The reproducer above should be a fast first check.Component:
comp-query-optimizerSeverity:
P2ClickGap · Finding:
h_issue_106949Triage metadata
comp-query-optimizercomp-query-analyzer,comp-joinsFix constant filter conjunct pushed to non-preserved side of OUTER JOIN
Fix constant filter conjunct pushed to non-preserved side of OUTER JOIN
Fix constant filter conjunct pushed to non-preserved side of OUTER JOIN
Do not reduce an outer join side on conjuncts independent of that side
Do not reduce an outer join side on a constant conjunct atom
Do not convert outer join to inner for storage join
rschu1ze commentedon Jul 21, 2026
#106949 (comment)
Fix constant filter conjunct pushed to non-preserved side of OUTER JOIN
Do not reduce an outer join side on a constant conjunct atom
Do not convert outer join to inner for storage join