Skip to content

Validate the argument list of an optimization of mergeTreeAnalyzeIndexes - #118644

Merged
alexey-milovidov merged 7 commits into
masterfrom
analyze-indexes-optimization-args-117610
Sep 25, 2026
Merged

alexey-milovidov merged 7 commits into
masterfrom
analyze-indexes-optimization-args-117610

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

Closes: #117610

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

A malformed argument list of an optimization of the mergeTreeAnalyzeIndexes table function is now reported as BAD_ARGUMENTS instead of a logical error or a raw std::exception.

Description

parseArgumentsForOptimizations navigated two levels of raw AST children of its args_array argument without validating its shape, so

  • a subquery there raised Logical error: Trying to get name of not a column: ExpressionList (which aborts a debug build, and the AST fuzzer generates exactly this shape), and
  • a bare literal escaped as boost::container::out_of_range: vector::at out of range (STD_EXCEPTION).

The argument is now extracted the same way extractParts extracts the neighbouring parts_array - accepting an array literal wrapped in a _CAST, or a bare array(...) call, which is what an argument list of mixed types (the shape buildAnalyzeIndexQuery sends) stays as - and reporting BAD_ARGUMENTS for anything else. Each element is evaluated on its own, so it keeps its own type.

The six parameters of vector_search_index_analysis are then checked explicitly, one by one: a wrong element type - ['v', 'L2Distance', 3, 1, 1, 0], [1, 'L2Distance', 3, [1.0], 1, 0], a negative limit, a flag other than true / false / 0 / 1 - is reported as BAD_ARGUMENTS naming the offending parameter and its position, instead of escaping as an internal BAD_GET. A wrong number of parameters lists the expected ones.


Workflow [PR]
Sync PR [sync-upstream/pr/118644]

Version info

  • Merged into: 26.10.1.648-master (included in 26.10 and later)

`parseArgumentsForOptimizations` navigated two levels of raw AST children of its
`args_array` argument without validating its shape, so

- a subquery there raised `Logical error: Trying to get name of not a column:
  ExpressionList`, which aborts a debug build and which the AST fuzzer generates,
  and
- a bare literal escaped as `boost::container::out_of_range: vector::at out of
  range` (`STD_EXCEPTION`).

The argument is now extracted the way `extractParts` extracts the neighbouring
`parts_array` - an array literal wrapped in a `_CAST` with the analyzer, a bare
`array(...)` call without it - and anything else is reported as
`BAD_ARGUMENTS`.

As `extractParts` does, each element is evaluated on its own. That also fixes
the argument list `buildAnalyzeIndexQuery` itself sends when the old interpreter
is used: evaluating `array('col', 'L2Distance', 3, [1.5, 2.5], 1, 0)` as a whole
coerces every element to `String`, and the reference vector then failed with
`Bad get: has String, requested Array`.

Closes: #117610

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5c58e57]

Summary: ✅


AI Review

Summary

This PR hardens mergeTreeAnalyzeIndexes optimization-argument parsing so malformed vector_search_index_analysis lists now fail with user-facing BAD_ARGUMENTS instead of internal exceptions, and it adds focused stateless coverage for malformed shapes, per-parameter validation, and accepted mixed-type inputs. I did not find any remaining correctness or compatibility issues in the current diff.

Missing context / blind spots
  • ⚠️ I did not run tests/queries/0_stateless/05218_analyze_indexes_malformed_optimization_args.sql locally because this workspace has no configured build directory or ClickHouse binary. Running that stateless test on the PR head would close the execution gap.
Final Verdict

✅ No remaining review findings at the current PR head.

LLVM Coverage Report

Measured on commit 5c58e57.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.40% 79.40% +0.00%

Changed lines: Changed C/C++ lines covered: 72/79 (91.14%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 7, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). label Sep 7, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The two reds on 440f9892 are not this change.

  • Stress test (arm_msan) reports Hung check failed, possible deadlock found, but the reason under it is a ConnectionResetError while the hung check was still collecting build flags (SELECT value FROM system.build_options), i.e. the server was not reachable when the check started - no query of the run is reported as hung.
  • Build profile diff fails inside ci/jobs/build_profile_diff_job.py with CI logs cluster query failed while looking up binary_sizes; it fails the same way on every pull request opened today, including ones that touch only a test.

This change validates the args_array argument of one table function and touches nothing else.

The happy path of `vector_search_index_analysis` was asserted only with the
analyzer, while the change also fixes the argument list
`buildAnalyzeIndexQuery` sends when the old interpreter is used: evaluating the
array as a whole coerced every element to `String` there.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Addressed: the accepted argument list is now asserted on the old interpreter as well, which is the shape buildAnalyzeIndexQuery sends - evaluating the array as a whole coerced every element to String there before this change.

@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 5c58e57b2 with master ed7bae423 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

4 object files changed (+61.78 KiB total), 0 added.

Object file Master PR Δ
src/TableFunctions/CMakeFiles/clickhouse_table_functions.dir/TableFunctionMergeTreeAnalyzeIndexes.c… 193.33 KiB 255.10 KiB +61.77 KiB (+31.95%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline.

Job report

alexey-milovidov and others added 2 commits September 16, 2026 17:24
…ysis` explicitly

`extractOptimizationArguments` only guaranteed that the argument list of the optimization is
array-like; the six elements were still decoded with raw `Field::safeGet`, so a list with a wrong
element type - `['v', 'L2Distance', 3, 1, 1, 0]`, `[1, 'L2Distance', 3, [1.0], 1, 0]` - escaped
as an internal `BAD_GET` instead of the `BAD_ARGUMENTS` this change promises.

Every slot is now checked by type and a mismatch is reported as `BAD_ARGUMENTS` that names the
offending parameter and its position. The flags accept `true` / `false` (the shape
`buildAnalyzeIndexQuery` sends) as well as `0` / `1`, the search vector accepts integer literals
next to floats. A wrong number of parameters lists the expected ones.

The test is renumbered to 05218 (05142 is taken on master) and covers a wrong type in each slot,
in both the `array(...)` and the array-literal shape. Its old-interpreter section is dropped:
`enable_analyzer = 0` is rejected since 26.9.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
alexey-milovidov and others added 3 commits September 24, 2026 07:55
…index_analysis`

`toInt64(3)` evaluates to an `Int64` field; it was accepted by the previous
`safeGet<UInt64>` path, so keep accepting it after the `>= 0` check.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…o `Array(Variant)`

After the merge of master, the analyzer folds `array('v', 'L2Distance', 3, ...)` into
`_CAST(array(...), 'Array(Variant(...))')`, so `extractOptimizationArguments` must look
through the `_CAST` into the `array` call; otherwise every argument list, including the
one `buildAnalyzeIndexQuery` sends, was rejected with `BAD_ARGUMENTS`.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

2 participants