Skip to content

[Bug]: [4.1.6-hotfix] nullable NOT IN needs a bounded NULL-aware membership path #32263

Closed

Description

@ck89119

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Related to closed #25821 and #12212. This is a 4.1.6-hotfix follow-up, not a new report of the already-addressed main-branch work. PR #32085 is being narrowed to the UNION/outer-join CTAS failures from matrixflow #20285; MARK optimization is deliberately excluded.

Branch Name

4.1.6-hotfix

Commit ID

Base 77052f8d1f9e6833ff5e5b41ae2343b5bcf0d152; measured metadata-corrected source 04d4098d5ecb19827152bfe8104c7a102674ee13 (also the production source at fcf51e4d13864acdbbd986878aa802eeba50340c).

Other Environment Information

Isolated local single-CN MO; GOMAXPROCS=4, GOMEMLIMIT=4GiB. Persistent SQL connection, one warmup and three measured executions. No production replay.

Actual Behavior

Correct UNION nullability makes nullable NOT IN require MARK semantics. This release branch compiles MARK as LoopJoin, exposing quadratic probe/build work instead of the previously selected, but semantically unsound, ANTI path.

For equivalent no-actual-NULL data, baseline/corrected median SQL times were:

Probe rows Baseline Corrected metadata
3000 0.759 ms 18.882 ms
6000 0.890 ms 70.680 ms

Adding an actual NULL to the second UNION branch makes the correct result zero; baseline incorrectly returns N/2. Restoring incorrect NotNullable to regain ANTI speed is not a valid fix.

Expected Behavior

Provide an efficient NULL-aware membership path while retaining SQL three-valued semantics, empty/all-NULL build behavior, safe evaluation ordering, cancellation and bounded concurrent memory use. Keep unsupported predicates on the evaluator. Independently assess a minimal backport versus a branch-local implementation; do not automatically import shuffle/spill or broad main changes.

Steps to Reproduce

CREATE TABLE l(id INT NOT NULL);
CREATE TABLE r(id INT NOT NULL);
CREATE TABLE extra(d INT);
-- Seed l with 1..N, r with 1..N/2, extra with N+1 (N=3000 and 6000).
SELECT COUNT(*) FROM l
WHERE id NOT IN (SELECT id FROM r UNION ALL SELECT d FROM extra);
-- Compare EXPLAIN and timing, then separately add NULL to extra and assert zero.

Use IN and a non-null constant second UNION branch as nearby controls. Timing is local evidence, not a production SLA.

Additional information

An unmerged experimental implementation remains in PR #32085 history through 53cdb1286a80d9b1025bbac885207fddc7807bc9; it is not a production-ready patch to cherry-pick. In particular, review #32085 (comment) found uncharged build encoding buffers. This was independently reproduced with 44 actual optional builders, 256 repeated 4KiB keys each, shared 64MiB MPool: charged 47,849,472 bytes + retained key buffers 54,788,096 bytes = 102,637,568 bytes, above the 67,108,864-byte cap. No OOM kill was observed.

Acceptance must cover both build and probe scratch with cap-enforced allocation/atomic reservation, shared-index ownership, budget/OOM fallback preserving RHS batches, unrelated-error propagation, cancellation, continuation, Reset/Free and deterministic concurrent consumers/builders. Non-null proofs do not prove eager evaluation cannot introduce an earlier error. Keep per-worker full RHS indexes and uncharged retained string buffers out of the final design. Any wire-format change needs its own explicit scope/review.

Activity

  1. added
    kind/bug
    on Nov 5, 2026
  2. added
    severity/s0
    and removed on Nov 5, 2026
  3. assigned and unassigned on Nov 11, 2026
  4. slyunnn commented on Nov 12, 2026

    @slyunnn

    Partially fixed — the original INT/UNION witness and supported bounded membership path pass; the related expression/DOUBLE release risk explicitly retained by #32519 remains unresolved.

    Target: 4.1.6-hotfix@bf18d1090466825da1d1c67742491af5c1da2605, [4.1.6-hotfix] fix(plan): infer result nullability from explicit proofs (#32519), frozen from remote at test start. Built from clean source using Go 1.26.4 and matching freshly built native libraries. All three endpoints returned git_version()=bf18d10904.

    Topology: local macOS arm64, 2 CN / 1 TN / 1 Log service / Proxy. Proxy 127.0.0.1:6001, CN1 127.0.0.1:16001, CN2 127.0.0.1:16002 were connected and actually used for original and extended SQL through PyMySQL text protocol. Existing BVT used Java/JDBC with metadata comparison enabled. No result is projected onto main or 4.2-dev.

    Fixed scope. PR #32315, fix(sql): bound shared MARK membership on 4.1.6-hotfix, merge 54feca6423c2e2e24b57f58e66eaf951891607cc, is present together with #32461 and #32519. The original nullable UNION query returns N/2 without an actual RHS NULL and 0 after inserting NULL, at N=3,000/6,000 on all three endpoints. Plans retain MARK rather than relying on an unsound ANTI shortcut. Warmed text-protocol medians were approximately 0.84–1.00 ms / 0.95–1.14 ms; actual MARK memory records show the bounded index. IN and non-NULL-constant controls passed.

    Resource and lifecycle evidence. The existing mark_membership.sql passed 48/48 at each endpoint, with metadata comparison enabled, including empty/all-NULL RHS, duplicates, NULL probes, prepared generations and evaluator controls. Focused normal tests passed across planner/LoopJoin/message (34 top-level tests); focused race tests passed across LoopJoin/message (32 top-level tests), including shared consumers/builders, pool cap, allocation failures, unrelated errors, cancellation, continuation and Reset/Free.

    Real scale verification used 2,000,000 RHS rows on every endpoint. One-probe hit/miss controls retained approximately 7.63 MiB MARK memory; 256 misses produced correct global counts and approximately 39.63 MiB, including the actual 32 MiB index. Plans exposed scan dop=12; this is engine execution evidence, not MOTR case scheduling. The concurrent ownership/cap assertions are component/race evidence rather than a production concurrency claim.

    Remaining release gate. The merged #32519 description explicitly links the following expression/DOUBLE performance risk to this issue and requires resolution or an explicit release decision. Minimal reproduction:

    CREATE DATABASE qa_mark_expression;
    USE qa_mark_expression;
    CREATE TABLE lhs(v INT NOT NULL);
    CREATE TABLE rhs(n INT NOT NULL);
    -- Repeat with N=3000 and N=6000, rebuilding both fixtures each time.
    INSERT INTO lhs SELECT result FROM generate_series(1,3000,1) g;
    INSERT INTO rhs SELECT result FROM generate_series(1,3000,1) g;
    SELECT COUNT(*) FROM lhs WHERE v NOT IN (SELECT 1/n FROM rhs);
    EXPLAIN ANALYZE
    SELECT COUNT(*) FROM lhs WHERE v NOT IN (SELECT 1/n FROM rhs);
    INSERT INTO rhs VALUES(0);
    SELECT COUNT(*) FROM lhs WHERE v NOT IN (SELECT 1/n FROM rhs);
    DROP DATABASE qa_mark_expression;

    Actual: correct counts 2,999 / 5,999, and 0 after division generates NULL. The evaluator remains MARK with warmed medians approximately 105–107 ms / 424–426 ms, about 4× growth when input sizes double. Reproduced independently on Proxy/CN1/CN2, one warmup plus three measurements each. This confirms a retained performance limitation, not a new result-correctness failure.

    The accepted #32315 design intentionally keeps unsupported expression/type domains on the evaluator. Please resolve the performance gate or explicitly record the release decision accepting this domain boundary; this report does not demand unsafe eager expression evaluation or restoration of incorrect NOT NULL metadata. The original INT witness is fixed, but no complete release acceptance is asserted while that explicitly retained decision remains open. No duplicate bug was filed.

    Large-data regression required: Yes, for the adaptive work and memory boundary; the real 2,000,000-row controls above completed locally. A TKE/production throughput or memory-soak claim is not made. The remaining quadratic expression witness requires only 3,000/6,000 rows to expose its scaling.

    Reused maintained BVT/UT coverage; no duplicate MOTR commit or PR was created. Shared fixture execution was serialized. An initial overlapping BVT/scale attempt produced a fixture lock conflict and is excluded; the clean serial scale run passed. No service source was modified. This issue remains open pending the release-gate resolution/decision.

  5. assigned and unassigned on Nov 12, 2026
  6. ck89119 commented on Nov 13, 2026

    @ck89119
    ContributorAuthor

    The design review accepts the current boundary: expression/DOUBLE cases remain on the evaluator without acceleration. Given the limited usage scope of 4.1.6-hotfix, there is no need to expand the optimization to this domain in this hotfix. We explicitly accept this performance limitation for the release.

  7. slyunnn commented on Nov 13, 2026

    @slyunnn

    Fixed within the accepted 4.1.6-hotfix scope, based on the completed regression above.

    Per the developer’s release decision, expression/DOUBLE cases intentionally remain on the evaluator, and their performance limitation is accepted for this hotfix. The pending release decision is resolved; this issue is closed as completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions