Skip to content

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

Open
LeftHandCold wants to merge 3 commits intomatrixorigin:3.0-devfrom
LeftHandCold:issue-24270-loopjoin-const-reset
Open

fix: reset reused join result vectors after empty probe#24273
LeftHandCold wants to merge 3 commits intomatrixorigin:3.0-devfrom
LeftHandCold:issue-24270-loopjoin-const-reset

Conversation

@LeftHandCold
Copy link
Copy Markdown
Contributor

@LeftHandCold LeftHandCold commented May 5, 2026

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

Copy link
Copy Markdown

Copilot AI left a comment

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/func_compare_fix.go
Comment thread pkg/sql/plan/function/list_operator.go
LeftHandCold and others added 2 commits May 5, 2026 19:00
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@LeftHandCold
Copy link
Copy Markdown
Contributor Author

Reviewed and updated this PR.

Changes made:

  • Rebuilt the branch on current upstream 3.0-dev; the PR diff now contains only the intended join fix files.
  • Added a follow-up fix to use vector.SetConstNull() for empty-probe right-side NULL output, avoiding stale data when a reused result vector previously held non-empty probe data.
  • Added regression coverage for non-empty -> empty reuse in left, single, and loop join paths.
  • Updated the PR body to use Fixes #24270.

Validation:

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

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

4 participants