Skip to content

Add an XGBOOST dictionary layout and the predictXGBoost function - #109999

Merged
Manerone merged 65 commits into
ClickHouse:masterfrom
Manerone:matheus-xgboost
Oct 9, 2026
Merged

Manerone merged 65 commits into
ClickHouse:masterfrom
Manerone:matheus-xgboost

Conversation

@Manerone

@Manerone Manerone commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Related: #80363

XGBoost gradient-boosted models can be trained and served as ClickHouse dictionaries, using the same lifecycle as any other dictionary: CREATE DICTIONARY, SYSTEM RELOAD DICTIONARY, LIFETIME, access control and system.dictionaries.

What changed

A dictionary declared with the XGBOOST layout trains an XGBoost model at load time from its source table. The feature columns are the PRIMARY KEY and the single remaining attribute is the target, so the "key" is the feature vector to predict from rather than a lookup key. Training hyperparameters are given as layout parameters:

SET enable_xgboost = 1;

CREATE DICTIONARY model (x1 Float64, x2 Float64, y Float64)
PRIMARY KEY (x1, x2)
SOURCE(CLICKHOUSE(TABLE 'training_data'))
LAYOUT(XGBOOST(objective 'reg:squarederror' num_iterations 100 max_depth 6))
LIFETIME(0);

SELECT predictXGBoost('model', 1.0, 2.0);      -- Float64 prediction

Inference is exposed through a single function, predictXGBoost(dictionary_name, feature1, feature2, ...[, params]): the features are passed positionally in key order, with an optional trailing Map of prediction parameters. Both the training hyperparameters and the prediction parameters are validated against an allowlist, so a typo fails the load rather than being silently ignored.

The integration is experimental and gated behind the new enable_xgboost setting, which defaults to false:

  • CREATE DICTIONARY ... LAYOUT(XGBOOST(...)) is rejected with SUPPORT_IS_DISABLED unless the setting is enabled. The check runs only when the loading strictness level is CREATE, so ATTACH, RESTORE and replicated DDL replay are not affected: a dictionary created while the feature was enabled still attaches after a server restart, and a backup taken then stays restorable on a server where the setting is off.
  • predictXGBoost is rejected unless the setting is enabled, even against an already-created dictionary. Since it is the only way to reach the model, the setting governs every prediction.

Notes and limitations

  • The generic dictionary interface is not supported for this layout. dictGet, dictHas, SELECT * FROM dict and joining the dictionary as a table all report UNSUPPORTED_METHOD and point at predictXGBoost instead. A trained model has no stored attribute to look up and no keys to test.
  • The model is not persisted, so it is retrained every time the dictionary loads: both SYSTEM RELOAD DICTIONARY and a LIFETIME-driven reload retrain it. A reload that fails keeps serving the previously trained model rather than failing predictions; last_successful_update_time and last_exception in system.dictionaries show whether the model still reflects the source data.
  • Training and prediction are single-threaded, because the bundled XGBoost is built without OpenMP. nthread is accepted and forwarded but currently has no effect. Concurrent predictions on one model are serialized with a mutex, since XGBoost's prediction is not thread-safe on a shared booster.
  • predictXGBoost returns one Float64 per row, so the multi-value prediction types (SHAP contributions, feature interactions, leaf index) are rejected, and so are multiclass objectives, which would need num_class.
  • system.dictionaries reports element_count and bytes_allocated as 0, as a direct dictionary does: this dictionary holds a model instead of rows. query_count and found_rate count the rows predicted through predictXGBoost.
  • XGBoost is an optional third-party contrib, so the layout only exists in builds that include it, and the stateless tests are tagged no-fasttest. It is disabled on loongarch64, whose sysroot does not ship <linux/mempolicy.h>.
  • Documentation is at docs/reference/statements/create/dictionary/layouts/xgboost.mdx; predictXGBoost is documented through its FunctionDocumentation.

Changelog category (leave one):

  • Experimental Feature

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

Added support for training and serving XGBoost gradient-boosted models as dictionaries. A dictionary with the XGBOOST layout trains a model at load time from its source table - the feature columns are the key and the single attribute is the target - and the new predictXGBoost function runs inference. The generic dictionary interface, such as dictGet, is not supported for this layout. Training hyperparameters such as objective, max_depth, eta and num_iterations are passed as layout parameters. The feature is experimental and must be enabled with the enable_xgboost setting. Available only in builds that include the XGBoost contrib library.


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

Version info

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

@CLAassistant

CLAassistant commented Jul 10, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@clickhouse-gh

clickhouse-gh Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4d66a72]

Summary: ✅


AI Review

Summary

This PR adds an experimental XGBOOST dictionary layout plus predictXGBoost, wires in the contrib build, and documents/tests the new feature. The core training/prediction path looks much cleaner than earlier revisions, but there are still unresolved contract holes around unsupported entrypoints: several paths that the docs say are unsupported still instantiate and train the model before failing, and one wrapper DDL can persist metadata for a table that can never work.

Findings

⚠️ Majors

  • [src/Functions/FunctionsExternalDictionaries.h:98] [dismissed by author -- https://github.com/Add an XGBOOST dictionary layout and the predictXGBoost function #109999#discussion_r3705438677] dictGet / dictHas still call ExternalDictionariesLoader::getDictionary before the call ever reaches the UNSUPPORTED_METHOD checks in src/Dictionaries/XGBoostDictionary.cpp:90. On an unloaded XGBOOST dictionary that means an unsupported generic lookup can still instantiate and retrain the model, and with enable_xgboost = 0 it still pays the full training cost even though the feature is meant to be disabled for querying. Reject this layout before getDictionary constructs it.
  • [src/Storages/StorageDictionary.cpp:422] [dismissed by author -- https://github.com/Add an XGBOOST dictionary layout and the predictXGBoost function #109999#discussion_r3705438682] ENGINE = Dictionary('...') still succeeds for an XGBOOST dictionary because create-time validation only loads the dictionary and checks column compatibility. Any later read then fails in src/Dictionaries/XGBoostDictionary.cpp:114, so this path can persist table metadata for a wrapper that can never work. The same load-before-fail behavior still exists for SELECT * FROM dict and dictionary('dict') via src/Storages/StorageDictionary.cpp:219 and src/TableFunctions/TableFunctionDictionary.cpp:53 [dismissed by author -- https://github.com/Add an XGBOOST dictionary layout and the predictXGBoost function #109999#discussion_r3752694489]. These table entrypoints should reject XGBOOST up front instead of training the model and only then throwing UNSUPPORTED_METHOD.
Tests
  • ⚠️ [tests/queries/0_stateless/05264_xgboost_query_count.sql:34] The regression only checks that the constant-feature path increments query_count by something between 1 and the number of blocks, while the docs still promise exact once per block behavior in docs/reference/statements/create/dictionary/layouts/xgboost.mdx:81 and docs/reference/statements/create/dictionary/layouts/xgboost.mdx:169. Please either tighten the test to the exact block count or weaken the user-facing contract to at most once per block.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: fail closed on the unsupported generic/table entrypoints so they do not load or persist unusable XGBOOST wrappers, and align the constant-feature query_count contract with a focused regression or weaker docs.

LLVM Coverage Report

Measured on commit 4d66a72.

Metric Baseline Current Δ
Lines 88.30% 88.30% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 79.70% 79.80% +0.10%

Changed lines: Changed C/C++ lines covered: 637/685 (92.99%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-experimental Experimental Feature submodule changed At least one submodule changed in this PR. labels Jul 10, 2026
@Manerone Manerone added the can be tested Allows running workflows for external contributors label Jul 15, 2026
@Manerone
Manerone marked this pull request as ready for review July 15, 2026 11:05
@Manerone
Manerone marked this pull request as draft July 16, 2026 08:49
@Manerone Manerone removed the can be tested Allows running workflows for external contributors label Jul 17, 2026
@clickhouse-gh clickhouse-gh Bot added pr-feature Pull request with new product feature and removed pr-experimental Experimental Feature labels Jul 20, 2026
@Manerone Manerone added the can be tested Allows running workflows for external contributors label Jul 20, 2026
@Manerone
Manerone marked this pull request as ready for review July 24, 2026 13:59
Manerone added 2 commits July 28, 2026 09:19
…ost`

Add an `XGBOOST` dictionary layout that loads a trained XGBoost model, and a
scalar function `predictXGBoost` that scores rows against a loaded model. The
model file is removed when the dictionary is dropped.

Add `xgboost` as a contrib with a hand-written CMake build, and gate the whole
feature behind the experimental setting `allow_experimental_xgboost`.
`check_submodules.sh` rejects submodules whose pinned commit declares its own
submodules. This is not only a style issue: nothing in CI checks out submodules
recursively, so `contrib/xgboost/dmlc-core` would be an empty directory on a CI
machine and the build would fail on missing sources.

Point `contrib/xgboost` at the `ClickHouse/xgboost` fork, branch
`ClickHouse/v3.3.0` - upstream `v3.3.0` with the `dmlc-core` gitlink removed and
`.gitmodules` emptied - and add `dmlc-core` as a top-level submodule pinned at
`4baa84e`, the same commit upstream `v3.3.0` referenced. No version change.

Follows the existing `contrib/aws-crt-cpp` pattern.
Comment thread src/Dictionaries/XGBoostDictionary.cpp Resolved
Comment thread src/Dictionaries/XGBoostDictionary.cpp Resolved
Comment thread src/Storages/StorageDictionary.cpp Resolved
@Manerone Manerone changed the title [Draft] Integrate XGboost on ClickHouse Integrate XGboost on ClickHouse Jul 28, 2026
@clickhouse-gh clickhouse-gh Bot added pr-experimental Experimental Feature and removed pr-feature Pull request with new product feature labels Jul 30, 2026
Comment thread src/Dictionaries/XGBoostModel.cpp Resolved
Comment thread src/Dictionaries/XGBoostDictionary.h Resolved
@george-larionov

george-larionov commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Can you add a test that tests the access works correctly? Like tests/queries/0_stateless/04404_naive_bayes_access.sh

Probably add the following since it was covered in earlier reviews:

  • SELECT predictXGBoost('', 1.0, 2.0) FROM numbers(0) as the unprivileged user must still be ACCESS_DENIED. That's the whole reason checkAccess sits above the input_rows_count == 0 return at line 142.
  • An unprivileged call against a dictionary with a non-XGBOOST layout, and against a name that doesn't exist, must both give ACCESS_DENIED rather than a layout or not-found error — that's what the checkAccess → validateDictionaryIsXGBoost ordering in getReturnTypeImpl buys, and without a test nothing stops someone reordering those two lines later.

@george-larionov george-larionov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good overall, nice job! See my comments. A few more things:

  • Can you add a test running multiple blocks through it? You can use max_block_size to set a small block size and keep the test small that way.
  • Just a suggestion, probably you have already done this, but try running it on some larger datasets locally, maybe compare with the XGBoost library.

Comment thread src/Dictionaries/XGBoostDictionary.cpp Outdated
for (const auto & key_attribute : *dict_struct.key)
{
const WhichDataType which(key_attribute.type);
if (!which.isNativeNumber() || which.isEnum())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think something can be NativeNumber and an Enum.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, removed.

Comment thread src/Dictionaries/XGBoostModel.cpp Outdated
{
auto type = col.type;
WhichDataType which(type->getTypeId());
if (!which.isNativeNumber() || which.isEnum())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed here as well.

SELECT element_count, bytes_allocated FROM system.dictionaries
WHERE database = currentDatabase() AND name = 'model_04509_eager';
DROP DICTIONARY model_04509_eager;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a test testing query_count

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added 05264_xgboost_query_count: 0 before any prediction and after a call over no rows, +1000 for 1000 predicted rows, and +1 for a call over 1000 rows whose features are all constant, which the default implementation for constants now evaluates once. found_rate is checked alongside. 05266_xgboost_multiple_blocks also checks that every row of every block is counted.

Comment thread src/Dictionaries/XGBoostModel.cpp Outdated
throw Exception(ErrorCodes::BAD_ARGUMENTS, "No training data was provided");

// Validate the parameters provided by the user
const auto params = sanitizeTrainingParams(hps);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with the bot, there's no reason for this check to happen after all the data has been loaded, it should probably be moved into startTraining.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved sanitizeTrainingParams into startTraining, which XGBoostDictionary::trainModel calls before source_ptr->loadAll, so an invalid layout parameter is now rejected before any source data is read.

SELECT 'Error: num_iterations must be a positive integer';
CREATE DICTIONARY model_04509_bad (x1 Float64, x2 Float64, y Float64)
PRIMARY KEY (x1, x2) SOURCE(CLICKHOUSE(TABLE 'training_04509'))
LAYOUT(XGBOOST(num_iterations 0)) LIFETIME(0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a test for non numeric num_iterations? LAYOUT(XGBOOST(num_iterations 'abc'))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added in 05260_xgboost_num_iterations_parsing: 'abc', '10abc', 1.5, 0, 2147483647, 2147483648 and 4000000000, each checked against the expected error message.

Comment thread src/Dictionaries/XGBoostModel.cpp Outdated
if (key == "num_iterations")
{
int parsed_iterations = 0;
if (!tryParse(parsed_iterations, value) || parsed_iterations <= 0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe that tryParse will also return false if the value doesn't fit the type, something like 4000000000. Can you add a test for this? Also in this case the error would be a little confusing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed


-- `iteration_begin` and `iteration_end` address the boosting rounds of the model, so every round of the
-- default 100 is a valid bound.
SELECT sum(isFinite(predictXGBoost('model_04509_xgb', x1, x2, map('iteration_begin', 1, 'iteration_end', 100)))) FROM inference_04509;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These tests prove that the params passed don't error but they don't really prove that they are actually consumed since the result is never checked. It's pretty minor but would be quick to add/modify them to actually prove that some of these params produce different results.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Manerone and others added 6 commits October 6, 2026 10:07
`sanitizeTrainingParams` ran in `finalizeTraining`, after `loadAll` and `addTrainingData` had already
scanned and buffered the whole source table, so a typo in `LAYOUT(XGBOOST(...))` paid the full read
before failing. It now runs in `startTraining`, which `XGBoostDictionary::trainModel` calls before
`loadAll`.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`num_iterations` was parsed into an `int`, so a positive integer that does not fit, such as
`4000000000`, was rejected as "must be a positive integer". It is now parsed as `UInt64`, and a value
above the `int` iteration index of `XGBoosterUpdateOneIter` reports the maximum instead.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`WhichDataType::isNativeNumber` is already false for `Enum8` and `Enum16`, which have their own
`TypeIndex`, so `|| which.isEnum()` never changed the result. A dictionary cannot have an `Enum`
column anyway: `CREATE DICTIONARY` rejects it.

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

`predictXGBoost` inherited the default implementation for NULLs, so a NULL feature made the
prediction NULL and the result type `Nullable(Float64)`, contradicting the documented `Float64`. A
NULL feature is now passed to the model as NaN, the missing-value marker the matrix is created
with, so it is predicted the way the model was trained to handle a missing value.

The default implementation for constants is enabled, so with every feature constant the model is
evaluated once. As it unwraps an all-constant call, the check that `params` is constant moved from
`executeImpl` to `getReturnTypeImpl`.

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

The `xgboost.mdx` page was hand-written and outside the dictionary-layout documentation generator.
Its body is now the `Documentation.description` of the `xgboost` layout registration, the page is
regenerated with the `AUTOGENERATED` markers, and `xgboost` is checked by
`test_dictionary_layout_pages.py`. The repeated `CREATE DICTIONARY model` example is renamed and the
machine-specific `response` block is dropped.

The `predictXGBoost` documentation examples used a `model` dictionary that nothing created, without
`enable_xgboost`, so they failed the `Docs examples` check. They now set up the dictionary themselves.

XGBoost wrote its messages to `stderr`. They are now forwarded through `XGBRegisterLogCallback` to
the `XGBoost` logger, at the level XGBoost gives them and attached to the query, so they also reach
`system.text_log`. The callback is kept per thread by XGBoost, so it is registered before training
and before each prediction.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=109999&sha=97dd7ba6e68e9934d7f39b45d371931a4b2c9c20&name_0=PR&name_1=Docs%20examples
ClickHouse#109999

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

- `05264_xgboost_query_count`: `query_count` counts the rows passed to the model, and an all-constant
  call counts once.
- `05265_xgboost_parameters_change_result`: training and prediction parameters change the result,
  compared by value rather than only checked to be finite.
- `05266_xgboost_multiple_blocks`: predicting over many small blocks matches predicting over one.
- `05267_xgboost_access`: without the `dictGet` grant, `predictXGBoost` is denied before anything
  else, also for no rows, for a dictionary of another layout and for a missing dictionary.

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

@Manerone Manerone left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review! I addressed all of the comments.

Comment thread src/Dictionaries/XGBoostModel.cpp Outdated
throw Exception(ErrorCodes::BAD_ARGUMENTS, "No training data was provided");

// Validate the parameters provided by the user
const auto params = sanitizeTrainingParams(hps);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved sanitizeTrainingParams into startTraining, which XGBoostDictionary::trainModel calls before source_ptr->loadAll, so an invalid layout parameter is now rejected before any source data is read.

Comment thread src/Dictionaries/XGBoostDictionary.cpp Resolved
Comment thread src/Dictionaries/XGBoostModel.cpp Outdated
if (key == "num_iterations")
{
int parsed_iterations = 0;
if (!tryParse(parsed_iterations, value) || parsed_iterations <= 0)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

SELECT 'Error: num_iterations must be a positive integer';
CREATE DICTIONARY model_04509_bad (x1 Float64, x2 Float64, y Float64)
PRIMARY KEY (x1, x2) SOURCE(CLICKHOUSE(TABLE 'training_04509'))
LAYOUT(XGBOOST(num_iterations 0)) LIFETIME(0);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added in 05260_xgboost_num_iterations_parsing: 'abc', '10abc', 1.5, 0, 2147483647, 2147483648 and 4000000000, each checked against the expected error message.

Comment thread src/Dictionaries/XGBoostDictionary.cpp Outdated
for (const auto & key_attribute : *dict_struct.key)
{
const WhichDataType which(key_attribute.type);
if (!which.isNativeNumber() || which.isEnum())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, removed.

Comment thread src/Dictionaries/XGBoostDictionary.cpp Resolved
SELECT element_count, bytes_allocated FROM system.dictionaries
WHERE database = currentDatabase() AND name = 'model_04509_eager';
DROP DICTIONARY model_04509_eager;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added 05264_xgboost_query_count: 0 before any prediction and after a call over no rows, +1000 for 1000 predicted rows, and +1 for a call over 1000 rows whose features are all constant, which the default implementation for constants now evaluates once. found_rate is checked alongside. 05266_xgboost_multiple_blocks also checks that every row of every block is counted.


-- `iteration_begin` and `iteration_end` address the boosting rounds of the model, so every round of the
-- default 100 is a valid bound.
SELECT sum(isFinite(predictXGBoost('model_04509_xgb', x1, x2, map('iteration_begin', 1, 'iteration_end', 100)))) FROM inference_04509;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@Manerone

Manerone commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@george-larionov Regarding the suggestion to compare with XGBoost directly, I tested locally and found no significant differences. Here is the setup and the result.

Setup: 500k training rows (8 features, non-linear target with noise), trained with the same parameters in an XGBOOST dictionary and in the Python xgboost package (3.3.0 on both sides), with the rows in the same order. Predictions on 100k held-out rows, 5% of them with NULL features.

Config Result
reg:squarederror, 100 rounds bit-identical
binary:logistic, 50 rounds bit-identical up to float32 rounding (≤ 1.2e-7)
subsample 0.7, seed 42 bit-identical
colsample_bytree 0.8, seed 42 differs: XGBoost samples columns with std::shuffle, which is implemented differently in libc++ (ClickHouse) and libstdc++ (the Python wheel)

# Conflicts:
#	src/Common/ErrorCodes.cpp
#	src/Interpreters/InterpreterCreateQuery.cpp
Comment thread src/Dictionaries/XGBoostDictionary.cpp Resolved
Comment thread src/Dictionaries/XGBoostDictionary.cpp Resolved
The default implementation for constants evaluates `predictXGBoost` once per block, not once per
query, so the docs and the `query_count` note no longer promise a single evaluation for a whole
query. `05264_xgboost_query_count` pins `max_block_size` so that its expectation does not depend on
the randomized block size.

`iteration_end` is an exclusive bound, one past the last boosting round to include, and is now
described as such; `iteration_begin` is described as inclusive and counted from `0`.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Blargian Blargian added the pr-autogenerated-docs PR that regenerates docs artifacts from source; exempt from the autogenerated-region edit guard label Oct 7, 2026
…tion as introduced in 26.10

The checked-in `machine-learning-functions.mdx` had no `predictXGBoost` section, so the function was
missing from the published function reference. It is regenerated from the `FunctionDocumentation`.

The `XGBOOST` layout and `predictXGBoost` were marked as introduced in 26.9, which is already
released; they land in 26.10, as the `enable_xgboost` settings history already says.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`executeImpl` returns early on an empty block, so as not to load and train the dictionary, and the
checks of the number of features and of the prediction parameters came after that return: an
invalid call over no rows succeeded. The feature count is now checked in `getReturnTypeImpl` from
the dictionary structure, which does not load the dictionary, and so are the prediction parameters,
by the new `XGBoostModel::validatePredictParams`. Only the upper bound of `iteration_begin` and
`iteration_end`, which needs the trained model, is still checked when predicting.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
SELECT sum(isFinite(predictXGBoost('model_05264_xgb', toFloat64(number), 2.0))) FROM numbers(1000) SETTINGS max_block_size = 65536;
SELECT query_count, found_rate FROM system.dictionaries WHERE database = currentDatabase() AND name = 'model_05264_xgb';

SELECT 'All features constant: evaluated once per block';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This still does not prove the documented once per block behavior for constant features. With numbers(1000) and max_block_size = 65536, the query always runs as a single block, so the reference 1001 would also pass if constant folding regressed to once per query.

Please force at least two blocks here (or add a focused companion case) and assert that query_count increases by the number of blocks, not just by 1.

A `Map` may repeat a key, and `buildPredictParams` kept the first value, so a contradictory call such
as `map('iteration_end', 0, 'iteration_end', 1)` silently ran with one of them. A repeated
prediction parameter is now rejected with `BAD_ARGUMENTS`.

`05264_xgboost_query_count` checked the all-constant case over a single block, which could not tell
once per block from once per query. It now runs ten blocks and checks that `query_count` grows by
at least one and at most the number of blocks.

`05266_xgboost_multiple_blocks` reads a `MergeTree` table while predicting with a dictionary that
exists only on the initiator, so it is tagged `no-parallel-replicas` like the other such tests.

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

clickhouse-gh Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 31 queries analysed

This PR adds an experimental XGBoost integration: a new vendored library, an XGBOOST dictionary layout, the predictXGBoost function, an enable_xgboost setting (off by default) and an lgammaf compatibility shim. No ClickBench or TPC-H query calls any of this, so none of the flagged ClickBench slowdowns can be attributed to the PR. Q18 (+19.5%) and Q33 (+5.7%) are downgraded to not_sure. Q16 (+16.6%) and Q32 (+25.3%) were already within master's recent range and stay not_sure. All four are GROUP BY queries with more CPU time across the board, and both source ClickBench runs shared one machine, which matches environment variance rather than a code effect.

clickbench

⚠️ 4 inconclusive

Flagged queries (4 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 16 not_sure 516 602 +16.6% <0.0001 aggregation: This is a GROUP BY on the hits table, and it never calls the new XGBoost dictionary or predictXGBoost. The +16.6% falls inside master's recent range for this query, so it cannot be attributed to this PR.
⚠️ 18 not_sure 815 974 +19.5% <0.0001 aggregation: This GROUP BY never touches the new XGBoost dictionary, the predictXGBoost function or the lgammaf shim. The +19.5% median is still inside master's recent range, and the query's history is noisy.
⚠️ 32 not_sure 718 899 +25.3% <0.0001 aggregation: This heavy GROUP BY never executes XGBoost code. The +25.3% is inside master's recent range, and measurements on both sides were very noisy.
⚠️ 33 not_sure 1029 1088 +5.7% <0.0001 aggregation: The +5.7% is on a GROUP BY that never reaches the new XGBoost dictionary or function code. The query is noisy on master, and the slowdown matches the CPU rise seen on every other flagged ClickBench query.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 71835cda-36f3-4124-a051-66dfbabf3e56
  • MIRAI run: ff679715-958e-4cb5-ab6c-77a2ae7edb0b
  • PR check IDs:
    • clickbench_526607_1791543447
    • clickbench_526620_1791543447
    • clickbench_526626_1791543447
    • tpch_adapted_1_official_526898_1791543464
    • tpch_adapted_1_official_526912_1791543464
    • tpch_adapted_1_official_527105_1791543468

@Manerone
Manerone added this pull request to the merge queue Oct 9, 2026
Merged via the queue into ClickHouse:master with commit f16642d Oct 9, 2026
300 of 301 checks passed
@Manerone
Manerone deleted the matheus-xgboost branch October 9, 2026 16:07
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 9, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 9, 2026
…85293

Conflicts resolved:
- InterpreterCreateQuery.cpp: master's XGBoost layout gate (ClickHouse#109999), then
  the empty SQL SECURITY default kept to view shapes, since
  supportSQLSecurity() now also accepts dictionaries.

Picks up ClickHouse#124928 (05316_secret_arguments_declared_by_engines under
DatabaseReplicated).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-dictionary Dictionaries (in-memory key-value, periodically refreshed from sources). pr-autogenerated-docs PR that regenerates docs artifacts from source; exempt from the autogenerated-region edit guard pr-experimental Experimental Feature pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants