Skip to content

[BugFix] Fix nestloop join crash on const build/probe columns#74952

Closed
Wenjun7J wants to merge 1 commit into
StarRocks:mainfrom
Wenjun7J:fix/nljoin-const-column-crash
Closed

[BugFix] Fix nestloop join crash on const build/probe columns#74952
Wenjun7J wants to merge 1 commit into
StarRocks:mainfrom
Wenjun7J:fix/nljoin-const-column-crash

Conversation

@Wenjun7J

Copy link
Copy Markdown
Contributor

Why I'm doing:

A BE crashes with SIGSEGV while running a nested-loop join. The PC is in
BinaryColumnBase<uint32>::append(const Column&, size_t, size_t) and the fault
address is near-null, e.g.:

*** SIGSEGV (@0x834) received ...
PC: starrocks::BinaryColumnBase<unsigned int>::append(...)
    starrocks::pipeline::NLJoinProbeOperator::_permute_probe_row(...)
    starrocks::pipeline::NLJoinProbeOperator::_permute_chunk_for_other_join(...)
    starrocks::pipeline::NLJoinProbeOperator::_pull_chunk_for_other_join(...)
    starrocks::pipeline::NLJoinProbeOperator::pull_chunk(...)

Root cause: the pipeline nestloop-join permute path
(NLJoinProbeOperator::_permute_probe_row / _permute_left_join) copies columns
through Column::append / append_value_multiple_times, which down_cast the
source to the concrete column type. In release builds down_cast is an unchecked
static_cast, so a ConstColumn that reaches the permute path is type-confused
as the destination column type (e.g. BinaryColumn). Its _offsets / _bytes
are then read from unrelated memory, producing a wild pointer and a SIGSEGV at a
near-null address.

This is reachable for degenerate nestloop plans where a constant inline view / CTE
feeds the build or probe side of a cross join (the equi-keys collapse to constant
predicate pushdown, so the join degrades to a nestloop join with a constant side).

The legacy non-pipeline CrossJoinNode guards every append with is_constant()
branches; the pipeline operator (introduced in #9430) never carried that protection
over, and there is no single chokepoint that guarantees const columns are
materialized before the join.

What I'm doing:

Materialize const columns at the nestloop-join build and probe entry points
(NLJoinBuildOperator::push_chunk and NLJoinProbeOperator::push_chunk) via
Chunk::unpack_and_duplicate_const_columns(), so the permute code never sees a
ConstColumn. This mirrors the existing convention added at the local exchange
source operator (#43403) for the same class of bug.

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Status

Warning

Draft. Pending validation on a build environment:

  • BE build
  • Reproduce the crash on the unfixed binary, confirm it is gone after the fix
  • Add a regression test (SQL test for the degenerate constant-CTE nestloop plan)

Does this PR entail a change in behavior?

  • No, this PR will not change any behavior. (Const columns are semantically
    identical to their materialized form.)

🤖 Generated with Claude Code

The pipeline nestloop-join permute path (NLJoinProbeOperator::_permute_probe_row
and _permute_left_join) copies columns via Column::append /
append_value_multiple_times, which down_cast the source to the concrete column
type. In release builds down_cast is an unchecked static_cast, so a ConstColumn
reaching the permute path is type-confused as the destination column type (e.g.
BinaryColumn) and its internal pointers are read from unrelated memory, causing
a wild-pointer dereference and SIGSEGV (e.g. PC in BinaryColumnBase::append,
fault at a near-null address).

This is reachable for degenerate nestloop plans, e.g. a constant inline view /
CTE feeding the build or probe side of a cross join. The legacy non-pipeline
CrossJoinNode guards every append with is_constant() checks; the pipeline
operator (introduced in StarRocks#9430) never carried that protection over.

Materialize const columns at the build and probe entry points so the permute
code never sees a ConstColumn, matching the existing convention used at the
local exchange source (StarRocks#43403).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot requested review from stdpain and trueeyu June 17, 2026 09:03
@Wenjun7J Wenjun7J closed this Jun 17, 2026
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.

1 participant