From ce443f7d8bab454e610275e031bcc3dbda688f03 Mon Sep 17 00:00:00 2001 From: csun5285 Date: Mon, 27 Apr 2026 18:02:44 +0800 Subject: [PATCH] [fix](be) Move #include directives outside namespace blocks to avoid ODR violations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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`, `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` — `` included inside `namespace doris {` (under `#ifdef __AVX2__`); also redundant because `` is already included at file scope. - `be/src/exec/common/sip_hash.h` — `` included inside `namespace doris {`; lower impact (mostly typedefs) but still wrong. - `be/src/util/hash/murmur_hash3.cpp` — `` 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. --- be/src/exec/common/sip_hash.h | 3 +-- be/src/exprs/table_function/vexplode_v2.cpp | 3 +-- .../segment/variant/variant_doc_snpashot_compact_iterator.h | 4 ++-- be/src/util/hash/murmur_hash3.cpp | 6 ++++-- be/src/util/simd/vstring_function.h | 1 - 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/be/src/exec/common/sip_hash.h b/be/src/exec/common/sip_hash.h index 6c348960e1b581..e30b9f3b68e197 100644 --- a/be/src/exec/common/sip_hash.h +++ b/be/src/exec/common/sip_hash.h @@ -33,6 +33,7 @@ * (~ 700 MB/sec, 15 million strings per second) */ +#include #include #include @@ -209,8 +210,6 @@ class SipHash { #undef ROTL #undef SIPROUND -#include - inline void sip_hash128(const char* data, const size_t size, char* out) { SipHash hash; hash.update(data, size); diff --git a/be/src/exprs/table_function/vexplode_v2.cpp b/be/src/exprs/table_function/vexplode_v2.cpp index f83e705905a79e..b21802690a84b8 100644 --- a/be/src/exprs/table_function/vexplode_v2.cpp +++ b/be/src/exprs/table_function/vexplode_v2.cpp @@ -30,6 +30,7 @@ #include "core/column/column.h" #include "core/column/column_array.h" #include "core/column/column_nothing.h" +#include "core/column/column_struct.h" #include "core/column/column_variant.h" #include "core/data_type/data_type.h" #include "core/data_type/data_type_array.h" @@ -41,8 +42,6 @@ namespace doris { -#include "core/column/column_struct.h" - VExplodeV2TableFunction::VExplodeV2TableFunction() { _fn_name = "vexplode"; } diff --git a/be/src/storage/segment/variant/variant_doc_snpashot_compact_iterator.h b/be/src/storage/segment/variant/variant_doc_snpashot_compact_iterator.h index 226ff6f68dc7a2..2a707adec86425 100644 --- a/be/src/storage/segment/variant/variant_doc_snpashot_compact_iterator.h +++ b/be/src/storage/segment/variant/variant_doc_snpashot_compact_iterator.h @@ -15,11 +15,11 @@ // specific language governing permissions and limitations // under the License. -namespace doris::segment_v2 { - #include "core/column/column_variant.h" #include "storage/segment/column_reader.h" +namespace doris::segment_v2 { + class VariantDocValueCompactIterator : public ColumnIterator { public: VariantDocValueCompactIterator(ColumnIteratorUPtr&& column_iterator) diff --git a/be/src/util/hash/murmur_hash3.cpp b/be/src/util/hash/murmur_hash3.cpp index 58740d72b3907f..7cd22dd59ec0ed 100644 --- a/be/src/util/hash/murmur_hash3.cpp +++ b/be/src/util/hash/murmur_hash3.cpp @@ -26,6 +26,10 @@ #include "util/hash/murmur_hash3.h" +#if defined(_MSC_VER) +#include +#endif + #include "util/unaligned.h" namespace doris { @@ -34,8 +38,6 @@ namespace doris { #define FORCE_INLINE __forceinline -#include - #define ROTL32(x, y) _rotl(x, y) #define ROTL64(x, y) _rotl64(x, y) diff --git a/be/src/util/simd/vstring_function.h b/be/src/util/simd/vstring_function.h index 71f722ac758840..b583dd67fc473e 100644 --- a/be/src/util/simd/vstring_function.h +++ b/be/src/util/simd/vstring_function.h @@ -73,7 +73,6 @@ inline bool validate_ascii_fast(const char* src, size_t len) { } #ifdef __AVX2__ -#include // The function returns true (1) if all chars passed in src are // 7-bit values (0x00..0x7F). Otherwise, it returns false (0). inline bool validate_ascii_fast_avx(const char* src, size_t len) {