Skip to content

[fix](be) Move #include directives outside namespace blocks to avoid ODR violations#62871

Open
csun5285 wants to merge 1 commit intoapache:masterfrom
csun5285:fix/odr-include-inside-namespace
Open

[fix](be) Move #include directives outside namespace blocks to avoid ODR violations#62871
csun5285 wants to merge 1 commit intoapache:masterfrom
csun5285:fix/odr-include-inside-namespace

Conversation

@csun5285
Copy link
Copy Markdown
Contributor

@csun5285 csun5285 commented Apr 27, 2026

Several files placed #include directives inside an outer namespace { ... } block.

The preprocessor expands the included header verbatim at that point, so a header that opens its own namespace doris { namespace segment_v2 { ... } } ends up nested as doris::segment_v2::doris::segment_v2::ColumnIterator instead of
doris::segment_v2::ColumnIterator.

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary:

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

@hello-stephen
Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@csun5285
Copy link
Copy Markdown
Contributor Author

run buildall

…ODR violations

Five headers/sources had `#include` directives placed inside an outer
`namespace` block. The preprocessor expanded each included header in
the wrong nesting, producing differently-named (and potentially
differently-laid-out) class declarations from what the rest of the build
sees. Header guards then locked-in whichever expansion landed first per
TU, so the linker silently merged ODR-violating definitions and resolved
calls to mismatched vtables / member offsets. The observed symptom was
random SIGSEGV during variant doc-mode read paths
(`CombineMultipleBinaryColumnIterator::_collect_sparse_data_from_buckets`
sorting `std::tuple<string_view,...>`, `BinaryDictPageDecoder::next_batch`
null deref via `VariantDocValueCompactIterator`), but the latent issue
applied to every TU that included these files.

Files fixed:

- `be/src/storage/segment/variant/variant_doc_snpashot_compact_iterator.h`
  — Doris header `core/column/column_variant.h` /
  `storage/segment/column_reader.h` were included inside
  `namespace doris::segment_v2 {`, nesting their `namespace doris { ... }`
  declarations as `doris::segment_v2::doris::segment_v2::ColumnIterator`.
  This was the source of the variant-mode crashes.

- `be/src/exprs/table_function/vexplode_v2.cpp` — Same pattern with
  `core/column/column_struct.h` inside `namespace doris {`.

- `be/src/util/simd/vstring_function.h` — `<x86intrin.h>` included inside
  `namespace doris {` (under `#ifdef __AVX2__`); also redundant because
  `<immintrin.h>` is already included at file scope.

- `be/src/exec/common/sip_hash.h` — `<cstddef>` included inside
  `namespace doris {`; lower impact (mostly typedefs) but still wrong.

- `be/src/util/hash/murmur_hash3.cpp` — `<stdlib.h>` included inside
  `namespace doris {` under `#if defined(_MSC_VER)`; dead on
  Linux/macOS but corrected for consistency.

In every case the fix is the same: hoist the `#include` to file scope,
above any `namespace` open.
@csun5285 csun5285 force-pushed the fix/odr-include-inside-namespace branch from f467497 to ce443f7 Compare April 27, 2026 10:20
@csun5285
Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen
Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100% (0/0) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 73.89% (27708/37499)
Line Coverage 57.64% (299898/520264)
Region Coverage 54.71% (248977/455094)
Branch Coverage 56.40% (108010/191506)

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.

2 participants