yiguolei opened a new pull request, #70552: URL: https://github.com/apache/doris/pull/70552
### Background ANN indexes identify vectors by their row IDs within a segment. Skipping empty arrays must preserve those IDs and exclude missing vectors from range-search complements. Distance expressions also execute without an index when training is skipped or a query falls back to a scan. ### What problem does this PR solve? Issue Number: None Related PR: #70479 (related DELETE and Group Commit validation), #70270 and #70271 (ANN storage interface integrated from master), #70788 (ANN load-error handling integrated from master) PR Type: Enhancement Problem Summary: Allow empty arrays in ANN-indexed columns through the mutable, default-off BE option `enable_ann_index_empty_array`. Preserve row IDs and return NULL distances for whole-array NULL or empty vectors. Reject NULL coordinates on every ANN write path, including Group Commit before asynchronous acknowledgement. Most of the diff is tests and regression outputs; NULL/empty distance semantics apply even when the write option is off. ### Details - **Change map:** Production changes cover sparse ANN row IDs and query handling, pre-acknowledgement Group Commit validation, nullable FE/BE distance results, and strict/inclusive range boundaries. Tests cover these paths through BE/FE units and five SQL suites. Most output lines record the same deterministic SQL across index types, metrics, cache states, reload and compaction. - **Before and after:** Empty arrays are rejected by default. With the option enabled, valid vectors retain their original data-file row IDs. Range complements exclude missing vectors; indexed TopN ranks only nonempty indexed vectors, regardless of NULLS FIRST/LAST. It does not pad results with missing vectors and can return fewer rows than LIMIT; all-empty indexed segments contribute no TopN rows. NULL or empty query vectors still use scalar evaluation. - **Configs and defaults:** `enable_ann_index_empty_array=false`. Enable it on every BE before empty-array writes and retain it for compaction, rebuilds and WAL replay. Readers do not consult the flag; disabling it does not convert stored data. - **Impact on existing users:** Array distance/similarity results become nullable FLOAT. Whole-array NULL and empty arrays yield NULL; NULL coordinates and mismatched nonempty dimensions remain errors. Nonempty zero-vector behavior and the MAP overload of `inner_product` are unchanged. Nullable ANN columns remain unsupported. - **Behavior change:** The array overloads of `l1_distance`, `l2_distance`, `inner_product`, `cosine_distance`, `cosine_similarity`, `l2_distance_approximate` and `inner_product_approximate` adopt the missing-vector semantics. Indexed range comparisons also preserve strict versus inclusive boundaries in native searches and cache keys. - **Index implementation:** IVF stores explicit IDs natively; sparse HNSW uses IDMap. All-empty segments persist without training. Sparse complement domains are reconstructed lazily; dense IVF avoids full ID collection. FAISS versions and filenames are unchanged. - **Compatibility:** Mixed-version rolling query compatibility is not established. Upgrade FEs and BEs together before enabling empty-array writes. Downgrading persisted sparse ANN data to BEs without sparse support is unsupported. ### Testing Latest SIMD follow-up `a7289fc99b50c9623b6fc4de39e6a276aa03124b`: - Replace the per-vector `memchr(..., 1, ...)` null-map check with the existing `simd::contain_one()` helper, matching ANN writer validation. Outer NULL rows and empty arrays remain skipped; canonical 0/1 null maps behave unchanged, and all nonzero flags are treated as NULL. - Repository clang-format 16 fix/check, BE header hygiene and diff whitespace checks passed. Existing SIMD helper boundary tests were inspected, not executed. No performance gain is claimed without measurement. - Builds, BEUT and regression tests were not rerun for this follow-up, following the author's preference. Runtime results below apply to `ea9c88689ac`, before this helper substitution. Current sparse-TopN validation on `ea9c88689acfec9d6cef3397f7b40f612dfca076` (2026-11-26), with runner-generated outputs committed in `08ece8c0d1418f1cd3f3140db3b5b41adf8b4d4b`: - ASAN BE and FE builds passed through `build.sh` in an isolated checkout. Runtime binary hashes were checked before regression execution. - `run-regression-test.sh --run -d ann_index_p0 -s ann_empty_array_queries,ann_empty_array_mow,ann_delete_group_commit -parallel 1 -forceGenOut` passed all 3 suites. A normal comparison including `ann_const_expr_vector` and `cast_string_as_array` passed all 5 suites; `test_array_distance_functions` also passed separately. No suites failed or were skipped. - The output-only follow-up copies the generated files unchanged. All 3,942 query-matrix blocks were inspected: 222 changed as expected for indexed TopN, including empty results for all-empty segments; unaffected blocks are unchanged. MoW output removes six NULL-distance rows. Group Commit output is unchanged. - `run-be-ut.sh -j 16 --run --filter=AnnIndexLoadTest.SparseTopNRanksOnlyIndexedCandidates` passed 1 test and exited 0 with default sanitizers, without suppression or an OpenMP workaround. - The combined focused ASAN BEUT run passed all 277 test assertions across 29 suites, but exited 134 because LeakSanitizer found 224 bytes in 2 allocations with an OpenMP `___kmp_allocate_align` stack. This remains a failed sanitizer run. - clang-tidy exited 1: missing `stddef.h` prevented complete analysis of both changed translation units; the output also includes existing size/constness diagnostics. No clean clang-tidy result is claimed. - These results cover the indexed-only TopN change. Fallback segments still retain NULL-distance rows; mixed indexed/unindexed segments can therefore use inconsistent candidate sets under NULL ordering. The proposed unified fallback filtering has not been implemented or tested. Previous merge update `14316491746710f3c2216b20bc2505588fb09231` (2026-11-25): - Merge master `141d3212aab` and resolve ANN persistence conflicts through `AnnIndexSource`/`AnnIndexSink`, retaining sparse labels and indexed-row cache invalidation. - Adapt four persistence tests to the current directory adapters and initialize the TopN load-error fixture with a non-empty query so it still reaches the load-error path. - Repository clang-format 16 fix/check scripts passed for the three manually adapted files; BE header hygiene and scoped diff whitespace checks passed. - Builds, unit tests, regression tests and clang-tidy were not rerun for this merge, following the author's preference. All runtime results below apply to earlier revisions, not this head. Remote validation on `0c1d02e2330` (the parent of the test-only follow-up): - ASAN BE and FE builds passed through `build.sh`. FEUT `ArrayDistanceTest,InnerProductTest,ArrayArithmeticTest` passed all 8 tests. - Five Groovy suites passed automatic `.out` generation and a subsequent normal comparison with `-parallel 1`: `ann_empty_array_queries`, `ann_empty_array_mow`, `ann_delete_group_commit`, `cast_string_as_array`, and `test_array_distance_functions`. The generated results are now committed. - Default combined ASAN BEUT: 201 tests passed their assertions, but the process exited 134 with 224 bytes leaked in static `libomp`; this is a failed run. A standalone OpenMP program reproduced the same leak after nested parallel execution followed by shrinking the thread team from 4 to 2. A diagnostic rerun with `KMP_HOT_TEAMS_MAX_LEVEL=0` passed all 201 tests and exited 0 with leak detection enabled. No suppression or production configuration workaround is included. The earlier test-only follow-up moves connection-only constant-folding checks into the regular `test_array_distance_functions` suite. All SQL and error checks are retained, and 28 generated output blocks are relocated byte-for-byte. Static inspection confirmed that all 3,822 generated query-matrix blocks match the corresponding exact-query phase and that projection rows agree with the deterministic fixture. Production code is unchanged from the runtime-tested parent. Follow-up validation for `dc727716b4b` plus the regression-only change committed as `d268047102d`: - `IndexBuilderTest.BuildAnnIndexRejectsAllEmptyBlock` now checks the default-off opt-in diagnostic and saves/restores the flag. `run-be-ut.sh -j 24 --run --filter=IndexBuilderTest.BuildAnnIndexRejectsAllEmptyBlock` passed 1 test and exited 0 with ASAN defaults. - `ann_const_expr_vector` now checks the empty constant query vector through a generated `.out` NULL result, instead of expecting the removed exception. `run-regression-test.sh --run -d ann_index_p0 -s ann_const_expr_vector -forceGenOut -parallel 1` and a subsequent normal comparison both passed, each running 1 suite with no failures or skips. Only distance is selected to avoid an arbitrary row ID among tied NULL values. Existing output blocks are unchanged. - The full BE UT run announced 17,075 tests; 7,245 completed successfully and 3 Iceberg tests failed on temporary-file permissions before a Lance multi-vector test looped on repeated read failures. The stuck process was terminated (exit 143); full BE coverage is incomplete. - The full FE UT command exited 1. Its reports contain 23,439 tests, 0 assertion failures, 6 errors in `FlussJniScannerPkTest`, and 77 skips. This is a failed run. Repeated/concurrent regression stability, recovery/WAL replay and mixed-version compatibility remain unverified. The focused passes do not establish a passing full test suite. ### Notes for Reviewers The three ANN suites retain `nonConcurrent` because their fixture writes/rebuilds modify BE-wide settings and query reload checks clear shared caches. Constant folding and unindexed distance checks run in the regular distance-function suite. `nonConcurrent` only isolates suites within one regression process; these ANN fixtures still require a cluster not shared with another runner. The query-matrix HNSW fixture is fully connected to keep recall from obscuring row-ID assertions. The rebase preserves master's ANN build-resource cleanup and includes sparse row-ID buffers. Review writer validation and sparse IDs first, then query semantics and boundary handling. The large output diff contains runner-generated results, not handwritten expectations. ### Release note Add default-off empty-array ANN writes and NULL distances for whole-array NULL or empty vectors. Indexed TopN ranks only nonempty indexed vectors, irrespective of NULLS FIRST/LAST, and may return fewer rows than LIMIT. Reject NULL coordinates before Group Commit acknowledgement and preserve strict/inclusive ANN range boundaries. Upgrade FEs and BEs together before enabling empty-array writes; do not downgrade persisted sparse ANN data to older BEs. ### Check List (For Author) - Behavior changed: Yes (see Details). - Does this need documentation: Yes; document the write option, NULL semantics and upgrade/downgrade restrictions in ANN and distance-function documentation. - Pre-submission status: Not ready: full BE coverage is incomplete, full FE UT reports 6 errors, and the earlier combined ASAN run reports a libomp leak. Local review also identified unresolved Group Commit atomicity and DOUBLE-to-FLOAT range-boundary concerns. The two stale-expectation fixes passed targeted validation on earlier revisions. The current sparse-TopN update has passing focused regression and standalone-test results with refreshed outputs, but its combined ASAN run still fails on the OpenMP leak, clang-tidy is incomplete, and mixed indexed/fallback NULL candidate consistency remains unresolved. Known review concerns remain open. ### AI Disclosure - Tool: OpenAI Codex. - Generated: Code, tests, rebase/merge conflict resolution, test isolation changes and this description. - Human review: The author reviewed selected implementation details and specified NULL/empty semantics, write validation and test scope. Final implementation review is pending. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
