Skip to content

fix: reset reused join result vectors after empty probe - #24273

Merged
mergify[bot] merged 4 commits into
matrixorigin:3.0-devfrom
LeftHandCold:issue-24270-loopjoin-const-reset
May 7, 2026
Merged

mergify[bot] merged 4 commits into
matrixorigin:3.0-devfrom
LeftHandCold:issue-24270-loopjoin-const-reset

Conversation

@LeftHandCold

@LeftHandCold LeftHandCold commented May 5, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #24270

What this PR does / why we need it:

This fixes the panic caused by reusing join result batches after an empty probe path.

When emptyProbe builds const output vectors, the next execution could reuse the same result batch with only CleanOnlyData(). That does not clear const vector state, so a later probe can append into a const vector and panic with append to const vector.

The PR now resets reused result vectors with ResetWithSameType() before writing probe results again. It also uses vector.SetConstNull() for empty-probe right-side NULL output, so reused vectors cannot retain stale data and accidentally become non-null constants after a previous non-empty probe.

Regression tests cover loopjoin / left / single join reuse in both directions: empty probe followed by non-empty probe, and non-empty probe followed by empty probe.

Validation

  • go test ./pkg/sql/colexec/left ./pkg/sql/colexec/single ./pkg/sql/colexec/loopjoin -count=1

Copilot AI review requested due to automatic review settings May 5, 2026 10:38
@LeftHandCold
LeftHandCold requested a review from a user May 5, 2026 10:38
@qodo-code-review

Copy link
Copy Markdown
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR is broader than the title/description suggest. It includes the stated join-batch reuse fix in the columnar join operators, but it also adds new SQL surface area (<=>, JSON ->/->>), JSON-to-numeric cast behavior, and multi-table DROP TABLE planning/authentication changes.

Changes:

  • Reset reused join result vectors in loopjoin, left, and single after empty-probe paths, with regression tests.
  • Add null-safe equality support and JSON arrow operator parsing/execution coverage, plus JSON-to-numeric cast behavior/tests.
  • Add multi-table DROP TABLE plan/compile/authentication handling and distributed SQL tests.

Reviewed changes

Copilot reviewed 36 out of 38 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/distributed/cases/join/apply.result Updates distributed join/apply expected output.
test/distributed/cases/function/func_null_safe_equal.sql Adds SQL coverage for <=>.
test/distributed/cases/function/func_null_safe_equal.result Expected results for <=> coverage.
test/distributed/cases/function/func_json_arrow.sql Adds SQL coverage for -> / ->>.
test/distributed/cases/function/func_json_arrow.result Expected results for JSON arrow coverage.
test/distributed/cases/ddl/drop_table_multiple.sql Adds distributed tests for multi-table drop.
test/distributed/cases/ddl/drop_table_multiple.result Expected results for multi-table drop tests.
proto/plan.proto Extends DropTable protobuf shape for multi-target drop.
pkg/sql/plan/function/list_operator.go Registers <=> operator metadata.
pkg/sql/plan/function/init.go Adds encoded name/id helpers for <=>.
pkg/sql/plan/function/function_id.go Assigns function id for <=>.
pkg/sql/plan/function/function_id_test.go Updates function id assertions.
pkg/sql/plan/function/func_compare.go Implements <=> dispatch and updates mixed-type compare callbacks.
pkg/sql/plan/function/func_compare_test.go Adds comparison regression/unit tests.
pkg/sql/plan/function/func_compare_fix.go Reworks mixed numeric comparison fallback logic.
pkg/sql/plan/function/func_cast.go Adds JSON-to-numeric cast support.
pkg/sql/plan/function/func_cast_test.go Adds JSON cast regression tests.
pkg/sql/plan/deepcopy.go Adds deep-copy support for nested drop-table plans.
pkg/sql/plan/build_expr_test.go Adds binder tests for tuple <=>.
pkg/sql/plan/build_ddl.go Builds multi-table drop plans.
pkg/sql/plan/build_ddl_test.go Adds unit tests for multi-drop FK target checks.
pkg/sql/plan/build_alter_table_test.go Verifies JSON→numeric remains blocked for DDL type change.
pkg/sql/plan/build_alter_modify_column.go Blocks JSON→numeric ALTER COLUMN conversions.
pkg/sql/plan/base_binder.go Binds tuple <=> expressions.
pkg/sql/parsers/dialect/mysql/scanner.go Tokenizes ->> as LONG_ARROW.
pkg/sql/parsers/dialect/mysql/mysql_sql.y Parses JSON arrow operators into function calls.
pkg/sql/parsers/dialect/mysql/mysql_sql_test.go Adds parser coverage for JSON arrow syntax.
pkg/sql/compile/ddl.go Executes multi-table drop entries sequentially.
pkg/sql/colexec/single/join.go Resets reused result vectors after empty probe.
pkg/sql/colexec/single/join_test.go Adds regression test for single join reuse.
pkg/sql/colexec/loopjoin/join.go Resets reused result vectors after empty probe.
pkg/sql/colexec/loopjoin/join_test.go Adds regression test for loop join reuse.
pkg/sql/colexec/left/join.go Resets reused result vectors after empty probe.
pkg/sql/colexec/left/join_test.go Adds regression test for left join reuse.
pkg/frontend/authenticate.go Extends auth/privilege handling for multi-table drop.
pkg/frontend/authenticate_test.go Adds auth regression tests for multi-table drop.

Comment thread pkg/sql/plan/function/list_operator.go Resolved
@mergify
mergify Bot requested a review from XuPeng-SH May 5, 2026 12:07

@XuPeng-SH XuPeng-SH 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.

LGTM. The fix is correct and minimal.

The root cause is clear: CleanOnlyData() doesn't reset the vector class, so a vector left as CONSTANT from a previous empty-probe execution panics on append in the next non-empty-probe execution.

The two-part fix is correct:

  1. ResetWithSameType() after CleanOnlyData() in the non-empty path — clears CONSTANT class back to FLAT, resets length and null bitmap
  2. vector.SetConstNull() in the empty-probe path — properly sets both class and length atomically, and truncates stale data

Verified:

  • SetConstNull doesn't use mp internally, so passing nil in single/join.go is safe
  • ResetWithSameType preserves the type but resets all mutable state (class, length, nsp, gsp, sorted, area)
  • Tests cover both directions: empty→non-empty and non-empty→empty, with memory leak assertions
  • Pattern is applied consistently across left/single/loopjoin

@mergify mergify Bot added the queued label May 7, 2026
@mergify

mergify Bot commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-05-07 09:48 UTC · Rule: release-3.0
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-05-07 10:42 UTC · at 63f7244f89e7bead0d2e660fe45b61005f8f6d24 · squash

This pull request spent 53 minutes 47 seconds in the queue, including 53 minutes 23 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI (3.0) / Coverage
    • check-neutral = Matrixone Utils CI (3.0) / Coverage
    • check-skipped = Matrixone Utils CI (3.0) / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)

This branch was previously deployed

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

Labels

kind/bug Something isn't working kind/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants