Skip to content

Forbid to create a table as viewIfPermitted - #116885

Merged
alexey-milovidov merged 11 commits into
ClickHouse:masterfrom
groeneai:groeneai/forbid-create-table-as-view-if-permitted
Sep 7, 2026
Merged

alexey-milovidov merged 11 commits into
ClickHouse:masterfrom
groeneai:groeneai/forbid-create-table-as-view-if-permitted

Conversation

@groeneai

@groeneai groeneai commented Aug 28, 2026 •

Copy link
Copy Markdown
Collaborator

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):

Forbid CREATE TABLE ... AS viewIfPermitted(...), including viewIfPermitted nested in another table function such as remote, which now fails with BAD_ARGUMENTS, as it already does for eval and the *Cluster table functions. The function chooses between its SELECT query and the ELSE function according to the current user, but a persisted table is resolved with no user and therefore full access: reading one reported the source table's column names and types to a user with no grant on it, and the ELSE fallback was unreachable. Tables created before this change keep loading; drop them to close the disclosure.

Description

Related: #116793, where a review bot reported this (discussion_r3878677312); my measurements are in discussion_r3878897538. Pre-existing, not caused by #116793.

CREATE TABLE ... AS <table function> resolves the function under the global context (InterpreterCreateQuery.cpp:2412 -> ITableFunction::execute:67), which has no user and is full access, so isPermitted always took the view branch. From a user holding only GRANT CREATE TABLE ON <db>.*, the structure-mismatch exception reported the source table's complete column list and types to a caller denied DESCRIBE on it; with a matching ELSE structure the fallback became unreachable and the read raised ACCESS_DENIED.

The defect is not a missing check but a missing identity: no check can decide a per-user branch with no user. So viewIfPermitted overrides canBeUsedToCreateTable(), checked at InterpreterCreateQuery.cpp:2406 before anything is resolved. *Cluster (#73804) and eval (#110132) already use this mechanism, and CREATE TABLE ... AS view(...) is already denied at create time, so viewIfPermitted was the outlier. CREATE VIEW is the supported replacement. Using the function in a query is unchanged, and nothing in tests/ or docs/ uses the refused form.

Not addressed:

  • tables created before this change still load (DatabaseOnDisk::createTableFromAST does not consult this virtual) and still disclose on read; ATTACH TABLE, UNDROP TABLE, RESTORE and DatabaseReplicated lost-replica recovery of one now fail, as they already do for *Cluster and eval, though a restart still re-attaches it;
  • the check reads only the outermost table function addressed after review: a persisted remote(..., viewIfPermitted(...)) (or remote(..., loop(viewIfPermitted(...)))) disclosed the same way via the engine credentials on a local shard, so InterpreterCreateQuery now also refuses, at any nesting depth, a table function whose storage is chosen by the current user's grants (a new narrow ITableFunction::dependsOnCurrentUserGrants virtual, so user-independent nested functions such as clusterAllReplicas or eval are not newly refused). The same veto is now applied to the arguments of a table engine, because the Remote / RemoteSecure engines store a table function target of their own in remote_table_function_ptr: the SQL parser only produces viewIfPermitted(SELECT ... ELSE ...) in table-expression position, but the clickhouse_json dialect executes a deserialized AST and could carry that shape into engine arguments. Definitions loaded back from already-validated metadata are not re-checked, so a table created before this change still attaches instead of disappearing on startup. The veto runs before the structure is inferred for a definition without a column list, so remote('unreachable', viewIfPermitted(...)) or an ELSE remote(...) arm is refused with BAD_ARGUMENTS without contacting the shard or analyzing the arm. The query form of the same disclosure, SELECT ... FROM remote(..., viewIfPermitted(...)) with prefer_localhost_replica = 0, needs no table at all, so no create-time check reaches it: identical on master, tracked separately.
Validation

Debug build, 26.9.1.1. Fix build id 520db3a0176fe01b20010e6294308f9500507e94, base c523792320c65ef62e806fba02851d46b076b63c (master 438a6180ae9641a3).

Without the fix, from a user granted only CREATE TABLE ON <db>.*, the CREATE succeeds silently (engine Proxy) and the read discloses:

SELECT count() FROM d5060.dst1;
Code: 36. DB::Exception: Table function 'viewIfPermitted' requires a SELECT query with the result
columns matching a table function after 'ELSE'. Currently the result columns of the SELECT query are
columns format version: 1
4 columns:
`secret_a` UInt64
`secret_b` String
`salary` Decimal(18, 2)
`ssn` FixedString(11)
, and the table function after 'ELSE' gives ... `x` UInt64 . (BAD_ARGUMENTS)

The same user gets Code: 497 (ACCESS_DENIED) for DESCRIBE TABLE d5060.src.

run result
05060_view_if_permitted_not_persistable, fix OK
05060_view_if_permitted_not_persistable, base FAIL - the refusal lines are absent and the grep prints Decimal FixedString salary secret_a secret_b ssn
50 randomized runs, fix 50 OK, 0 FAIL
existing tests mentioning viewIfPermitted, plus 04028_describe_table_function_rbac_bypass and 03307_forbid_loop_table_function_as_engine OK
legacy table created with the base binary, opened with the patched one server starts, table loads, count() = 3
urlCluster / eval CREATE TABLE ... AS already refused, unchanged

Every arm is pinned by a mutant, and the three mutants redden different arm sets, so none is redundant.

04514_table_functions_access_rights_rewrite cannot run in my sandbox (its query_as_user helper uses $CLICKHOUSE_CLIENT_BINARY without $CLICKHOUSE_CLIENT_OPT, so it connects to port 9000) and fails identically on the base binary; its four viewIfPermitted assertions were replayed by hand against the patched build and all pass.


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

Version info

  • Merged into: 26.9.1.909 (included in 26.9 and later)

groeneai and others added 2 commits August 28, 2026 09:23
viewIfPermitted(query ELSE f(...)) chooses between the query and the ELSE
function according to the current user. CREATE TABLE ... AS <table function>
resolves the function under the global context (InterpreterCreateQuery.cpp:2412
-> ITableFunction::execute:67), which has no user and is therefore full access,
so isPermitted always took the view branch.

From a user holding only GRANT CREATE TABLE on one database and nothing on the
source table, that had two consequences. The structure mismatch exception
reported the source table's complete column list and types to a caller that is
denied DESCRIBE on it with ACCESS_DENIED, which is exactly what the comment
above that comparison says must not happen ("We check that columns match only
if permitted (otherwise we could reveal the structure to an user who must not
know it)"). And with a matching ELSE structure the persisted object became the
view branch, so reading it raised ACCESS_DENIED where the direct call returns
the fallback.

The defect is not a missing access check but a missing identity: no check can
decide a per-user branch when there is no user to decide for. The only sound
alternatives are to refuse persistence or to invent a persisted representation
of the decision, and the latter needs a new base class extension point, changes
what SHOW CREATE TABLE reports, and lands the user in a state they could have
written by hand. Redacting the structures from the message is not sufficient
either: a guessed ELSE structure that is correct creates the table while a wrong
one errors, so the schema stays recoverable by search.

So refuse it through canBeUsedToCreateTable(), read at
InterpreterCreateQuery.cpp:2406 before anything is resolved. This is the
mechanism the *Cluster functions and eval already use, and
CREATE TABLE ... AS view(...) is already denied at create time, so
viewIfPermitted was the outlier. Using the function in a query, where a user
exists, is unchanged.

Tables created before this change keep loading: DatabaseOnDisk does not consult
this virtual, so startup, ATTACH DATABASE and dropped table recovery are
unaffected. An explicit ATTACH TABLE of such a table is refused, the same as for
*Cluster and eval; a server restart re-attaches it.

Co-Authored-By: Claude Opus 5 <[email protected]>
The changelog entry promises that CREATE TABLE ... AS viewIfPermitted(...) now
fails with BAD_ARGUMENTS, and no reference line pinned that code: every
assertion matched message text only.

Assert it in the arm that carries an explicit column list. That arm is the one
where the assertion can fail, because its whole output is the refusal, and
before the fix its CREATE succeeded silently and produced nothing. The arm above
it captures a CREATE and a following SELECT together, so before the fix its
capture already contained the disclosed exception's own BAD_ARGUMENTS and a code
match there would hold in both directions.

The message assertion stays: "cannot be used to create a table" occurs once in
src/, so it pins the throw site more tightly than the code does.

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-review-bot PR origin: review-bot finding on a groeneai PR labels Aug 28, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 2 full passes, 4 findings, 2 fix
rounds).

# Sev Finding Verdict Evidence / action
1 ❌ Wrapping the call in view(...) bypasses the new refusal and re-opens the same schema disclosure AGREE (bypass), DISAGREE (disclosure), DISAGREE (remedy) The bypass is real and is disclosed in the second "Not addressed" bullet: canBeUsedToCreateTable() is read only for the outermost function (InterpreterCreateQuery.cpp:2404-2406), so the nested query is still resolved with no user. The disclosure is not: I measured all three read shapes (implicit columns, explicit columns, matching ELSE) on the patched and unpatched builds, and every one returns Code: 393 THERE_IS_NO_QUERY with no source identifier in the output, for the unprivileged user and for a full-access one. QueryAnalyzer.cpp:4983 calls getQueryContext(), which throws for a context with no query, inside the outer view()'s structure resolution, one frame above TableFunctionViewIfPermitted::executeImpl, so isPermitted and the column comparison are never reached. Controls: the bare form is refused on the patched build and accepted on the unpatched one; DESCRIBE, SHOW CREATE and SELECT * on the source are all Code: 497; persisted view(SELECT 1), view(SELECT * FROM t) and remote(...) all read back correctly. Making the veto transitive is declined here: the gap belongs to canBeUsedToCreateTable itself, so eval and the *Cluster functions have it identically, and closing it at that call site would newly refuse CREATE TABLE ... AS view(... clusterAllReplicas ...)
2 ❌ The veto can make UNDROP TABLE of a legacy table fail after its metadata move and drop-queue removal are already committed AGREE (fact), DISAGREE (severity and remedy), disclosed Correct, and I verified every citation: DatabaseCatalog::undropTable moves the metadata back at :1508 and erases the drop-queue entry at :1510-1521, then runs a short ATTACH through InterpreterCreateQuery at :1537-1549 with no rollback between them, and DatabaseOnDisk::createTableFromAST reloads at startup without consulting the veto. UNDROP TABLE is now named in the first "Not addressed" bullet, whose existing clause records that a restart still re-attaches. Not fixed here: the missing rollback is unconditional and pre-existing, so the same half-commit follows any attach failure, and it applies identically to the two merged precedents for this virtual, eval and *Cluster. Adding a pre-check inside DatabaseCatalog, or a rollback that restores tables_marked_dropped, its id set, the first_async_drop_in_queue iterator and the queue metric under the existing lock and against the race 04238_drop_undrop_race covers, is a separate fix to shared machinery that would also change those two merged decisions. On the two sub-points: a legacy definition cannot be produced on a patched binary at all, so the requested focused test is not writable from the API surface, and I will not fabricate metadata to fake one; and I left the remediation as DROP, because a plain DROP closes the disclosure immediately and SYNC only removes the UNDROP window
3 ⚠️ The test asserts the refusal text but not the promised BAD_ARGUMENTS code AGREE, fixed @ ee55ffc933f5687 Asserted on the explicit-column-list refusal, the only arm where it can fail: on the unpatched build that CREATE succeeds silently, so both of that arm's lines are absent, whereas the first arm's capture already contains the leaked exception's own BAD_ARGUMENTS. Both text assertions kept; the first arm keeps UNKNOWN_TABLE, which does discriminate
4 💡 The changelog category should be Critical Bug Fix because the defect is RBAC DISAGREE The template lists RBAC among the defects eligible for that category and this one qualifies, but I do not self-assign it. The precedent for this mechanism, #74137, shipped as Bug Fix. Say so and I will change it

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-8:20260828-121800

@clickhouse-gh

clickhouse-gh Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9549462]

Summary: ✅


AI Review

Summary

This PR closes the CREATE TABLE ... AS viewIfPermitted(...) disclosure by rejecting viewIfPermitted anywhere a persisted table definition can carry it, and by moving that veto ahead of schema inference so rejected definitions do not probe nested remote(...) targets first. I re-checked the current head against the earlier review threads and did not find any remaining correctness or coverage gaps in the touched surface.

Final Verdict

✅ No new findings in the current head.

LLVM Coverage Report

Measured on commit 9549462.

Metric Baseline Current Δ
Lines 88.80% 88.80% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.10% 81.10% +0.00%

Changed lines: Changed C/C++ lines covered: 31/31 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 28, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. clickhouse-test 05060_view_if_permitted_not_persistable, no randomization or timing involved: on the base binary the CREATE succeeds and the read discloses the source schema on every run.
b Root cause explained? Yes. InterpreterCreateQuery.cpp:2412 persists a table function with use_global_context=true; ITableFunction::execute:67 sets the global context; viewIfPermitted has no static structure so execute defers executeImpl into a StorageTableFunctionProxy closure (engine reads as Proxy); when it runs, isPermitted resolves the primary SELECT under a context with no user, i.e. full access, so the ACCESS_DENIED-to-false catch never fires and the disclosing structure comparison always runs.
c Fix matches root cause? Yes. The defect is a missing identity, not a missing check: a per-user branch cannot be decided where there is no user. The fix refuses the only path that has none, at the mechanism the codebase already provides (canBeUsedToCreateTable), before anything is resolved. Redacting the message was rejected: a guessed ELSE structure that is correct creates the table while a wrong one errors, so the schema stays recoverable by search.
d Test intent preserved / new tests added? Yes. No existing test was weakened or removed; no test and no doc in the tree uses the refused form (checked same-line and in a 3-line window). New stateless test 05060_view_if_permitted_not_persistable, 5 arms, parallel-safe, no no-parallel, modelled on 04028_describe_table_function_rbac_bypass. Each arm is justified by a mutant that reddens a disjoint subset: no override reddens the two CREATE arms; a throw in executeImpl reddens the three query-path arms; moving the check to the implicit-columns path reddens the explicit-columns arm alone.
e Both directions demonstrated? Yes. Fix build 520db3a0176fe01b20010e6294308f9500507e94 -> [ OK ]; base build c523792320c65ef62e806fba02851d46b076b63c -> [ FAIL ], with the refusal lines absent and the leak grep printing Decimal FixedString salary secret_a secret_b ssn. The changelog promises the form now fails with BAD_ARGUMENTS, so the arm carrying an explicit column list asserts that code as well as the message; both of its lines are absent from the base output, which is what makes the added assertion able to fail rather than merely present. 50 randomized runs on the fix: 50 OK, 0 FAIL.
f Fix is general across code paths? Yes. viewIfPermitted is the only table function whose returned storage depends on the current user; the others that read the user (TableFunctionRemote.cpp:62,64, TableFunctionLoop.cpp:113,142, ITableFunction.cpp:44,65) either throw or do not, and never change which storage is returned. Siblings already refusing persistence were re-verified on this build: urlCluster and eval. Both CREATE forms are covered because the check precedes either. CREATE TEMPORARY TABLE ... AS viewIfPermitted(...) fails earlier with Code: 80. SystemLog.cpp:1303 sets a merge table function and is unaffected.
g Fix generalizes across inputs (params/datatypes/wrappers)? Not applicable, by construction rather than by omission: the override is a context-free constant with no dependence on column types, Nullable / LowCardinality / Array / Map / Const, any setting, or either analyzer. The check runs before analysis, so no enable_analyzer pin exists in any arm.
h Backward compatible? No, and deliberately so: this is a precedented refusal of previously accepted DDL, disclosed in the PR body. No setting is added and no default changes, so no SettingsChangesHistory.cpp row is due. Three merged precedents use this exact mechanism: #73804 (which introduced canBeUsedToCreateTable and applied it to long pre-existing *Cluster functions), #74137 (ENGINE = Loop), and #110132 commit bba2223a3935b6cd, "Address AI review: forbid persisting eval". No semantics are lost, because under the global context the ELSE branch is unreachable, and the same CREATE over a source the creator cannot read is already denied at create time when written with view(...) instead, measured as Code: 497. If a reviewer prefers Backward Incompatible Change, or wants the old behaviour behind a setting, I will follow their choice.
i Invariants and contracts preserved? Yes. One virtual returning a constant, read on the CREATE TABLE ... AS path before any state is touched, so partial creation is impossible: no table exists after a refused CREATE, verified. Startup, ATTACH DATABASE and dropped-table recovery use DatabaseOnDisk::createTableFromAST, which does not consult this virtual: measured by creating such a table with the pre-fix binary and opening the same data path with the patched one, where the server starts and the table loads and reads. One caller does leave a transient inconsistency, disclosed in the PR body: DatabaseCatalog::undropTable commits the metadata move and clears the drop queue before running the short ATTACH, with no rollback, so UNDROP TABLE of such a legacy table now fails with the refusal and the table is unreachable until the next restart. Measured 25/25: the refusal text, the metadata file back in the live database directory, the table absent from system.tables, and after a restart all 25 tables loaded and read 3 rows, against 25/25 successful undrops on the base binary. The missing rollback is unconditional and pre-existing, so it applies identically to the merged eval and *Cluster uses of this virtual. No data is lost, and no format, ABI, setting, locking or error-path change.

Session id: cron:clickhouse-impl-slot-5:20260828-112400

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @vitlibar @kssenii, could you review this? CREATE TABLE ... AS viewIfPermitted(...) resolves the function under the global context, which has no user and therefore full access, so the branch that should depend on the caller's grants was decided as if the creator could read the source, and the structure-mismatch exception then reported the source table's column names and types to a user holding no grant on it. It now overrides canBeUsedToCreateTable() as eval and the *Cluster functions already do, which is a deliberate refusal of previously accepted DDL and is disclosed in the description.

@clickhouse-gh

clickhouse-gh Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 9549462c1 with master 5901f1827 (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.

Compile time of recompiled translation units

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

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

Follow-up on the residual this description mentions, viewIfPermitted nested in remote(...), because I do not think I should pick the fix myself.

The carrier, pre-existing on master and not affected by this PR: from a user with no grant of any kind on s.t_secret,

SELECT * FROM remote('127.0.0.1:<own tcp port>', viewIfPermitted(SELECT * FROM s.t_secret ELSE null('...')))
SETTINGS prefer_localhost_replica = 0;

returns the source table's full column list in a Code: 36 message, and the source rows when the ELSE structure matches. Measurements and controls are in discussion_r3881320576.

I planned to close it the way the local-shard check closes the named-table case, by refusing a target whose result is an access-denied fallback. Reviewing that plan showed the approach does not converge:

  • remote('127.0.0.1', loop(viewIfPermitted(...))) bypasses it: loop takes an inner table function as a plain argument and forwards structure resolution to it (TableFunctionLoop.cpp:103-110), and remote(..., loop(...)) is supported (03765_remote_loop_table_function.sql);
  • a query carried as a string, eval('SELECT * FROM viewIfPermitted(...)'), has no AST to inspect at all;
  • the same mismatch exists with no table function involved: row policies are applied from the executing context (ContextAccess.cpp:554), and merge resolves its structure with SHOW COLUMNS while its read needs SELECT (StorageMerge.cpp:306 versus :1854-1870).

The common cause is that the initiator and the executor are different principals. executeQuery.cpp:344-347 states that without a cluster secret the shard runs as the connection user, and :341 replaces initial_user for remote(). So an initiator-side check can only approximate what the shard will be allowed to do, never authorize it.

@alexey-milovidov, which of these do you want?

  1. keep completing the check per target function, accepting that compositions such as loop, and string-carried queries, stay open;
  2. read a local shard locally when the cluster has no secret, so there is no second principal. This changes what prefer_localhost_replica = 0 does, does not cover parallel replicas (SelectStreamFactory.cpp:226), and 85 stateless tests combine that setting with remote( or cluster(;
  3. propagate the initiator's identity to a local shard, so the shard enforces the caller's grants;
  4. refuse such reads outright.

I would rather implement your choice than guess. You wrote the local-shard check (029dbb82a9ba57b, c3e41a8a0a1fcaf), and @ pufit wrote getActualTableStructureWithAccess (63057e7e408ccc4), which is the call this defeats.

@alexey-milovidov alexey-milovidov self-assigned this Aug 28, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - ee55ffc

CI is fully finished: 147 OK, 22 skipped, 1 failure. The failure has an owner.

Check / test Reason Owner / fixing PR
Stress test (amd_asan_ubsan) / Logical error: Not-ready Set is passed as the second argument for function (STID 0250-41a5) Chronic trunk logical error, not caused by this PR. Measured over the last 30 days: 211 rows across 165 distinct PRs, and 21 distinct master commits. #102308 (external, open)
Sync - CH Inc sync (private, not actionable by me)

Session id: cron:our-pr-ci-monitor:20260828-180000

…function

The AI review found that `CREATE TABLE ... AS remote(..., viewIfPermitted(...))` persists the
nested function too, and a later read on a local shard with `prefer_localhost_replica = 0` decides
the guarded branch under the connection's credentials instead of the reader's grants, disclosing
the guarded structure in the `BAD_ARGUMENTS` mismatch text or the guarded rows.

Refuse a grant-dependent table function at any nesting depth in `InterpreterCreateQuery`, through a
new `ITableFunction::dependsOnCurrentUserGrants` virtual that only `viewIfPermitted` overrides. An
AST walk rather than a check inside `remote` argument parsing, because it also catches carriers such
as `remote(..., loop(viewIfPermitted(...)))` and stays out of the files ClickHouse#110073 is rewriting; keyed
on the new narrow predicate rather than `canBeUsedToCreateTable`, so `remote(..., clusterAllReplicas(...))`
and other user-independent nested functions are not newly refused.

The query form of the same disclosure, `SELECT ... FROM remote(..., viewIfPermitted(...))` with
`prefer_localhost_replica = 0`, needs no table and is unchanged here; it is tracked separately.
@groeneai

groeneai commented Aug 31, 2026 •

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - ff2f3f4

CI is fully finished at this commit: 170 checks, two failed jobs, and each has an owner.
Mergeable Check names exactly those two (Failed: Stress test (amd_debug),Upgrade check (amd_release)),
and Style check (Failures: 0/15) and CH Inc sync are green.

Check / test Reason Owner / fixing PR
Upgrade check (amd_release) / Cannot start clickhouse-server not PR-caused, CI-harness defect: tests/config/install.sh symlinks silk.xml with no version gate, so the previous-release server rejects the new elements with Code: 137. DB::Exception: Unknown elements 'enable_silk_runtime', 'silk' found in config /etc/clickhouse-server/config.xml (UNKNOWN_ELEMENT_IN_CONFIG) and never starts. Onset is a cliff at 2026-08-30 13:48:57Z: 156 rows across 143 distinct pull requests in 5 days. The owner PR merged at 2026-08-30T21:30:56Z, 8 minutes after this run was created, so the tree built here predates the fix and the next run on this branch picks it up. #117172 (ours, merged)
Upgrade check (amd_release) / Check failed the same job's second abort row, same event as the line above #117172 (ours, merged)
Stress test (amd_debug) / Logical error: Not-ready Set is passed as the second argument for function 'globalIn' (STID 0250-4e52) not PR-caused, long-running trunk logical error (server abort in a debug build, handled as an exception in a release build). The real function name is globalIn, recovered from the job's own fatal.log; the report page shows it truncated. The abort is the object-storage _path pre-filter executing a set that was never built: ReadFromObjectStorageStep::initializePipeline -> createIterator -> StorageObjectStorageSource::createFileIterator -> VirtualColumnUtils::getFilterByPathAndFileIndexes -> filterBlockWithExpression -> in.cpp:128. ReadFromObjectStorageStep::applyFilters (:94) builds its sets with buildSetsForDAGExcludingGlobalIn, which SKIPS the globalIn second-argument ColumnSet nodes by construction (VirtualColumnUtils.cpp:101-124, whose own comment gives the reason: ReadFromRemote has to attach the external tables first). The pre-filter is then executed at pipeline-build time, inside initializePipeline, while that set is still unbuilt. 24 rows across 24 distinct pull requests in Stress test (amd_debug) alone over 5 days, and 112 rows plus 2 master rows across all checks. The owner PR rewrites both of those frames (StorageObjectStorageSource.cpp, VirtualColumnUtils.cpp) and adds 04669_object_storage_path_filter_global_in. #112968 (external, open)

Neither failure is attributable to this diff, which only refuses persisting viewIfPermitted
(InterpreterCreateQuery.cpp, ITableFunction.h, TableFunctionViewIfPermitted.cpp plus one
stateless test). It touches no object-storage read path and no server configuration.

Reports:

Session id: cron:our-pr-ci-monitor:20260831-053000

…gine argument

`throwIfNestedTableFunctionDependsOnCurrentUserGrants` only ran on the
`CREATE TABLE ... AS <table function>` path, so the same grant-dependent
target was still persistable through the `Remote` / `RemoteSecure` engines,
which store a nested table function in `remote_table_function_ptr`. An AST
carrying `viewIfPermitted(SELECT ... ELSE ...)` in engine arguments (e.g.
through the `clickhouse_json` dialect) therefore created a persisted table
whose branch is later decided under the connection credentials instead of
the reader's grants.

Apply the same veto to the engine arguments, except when the definition is
loaded back from already-validated metadata, so a table created before this
check still attaches.
…sistable`

The SQL parser only produces `viewIfPermitted(SELECT ... ELSE ...)` in
table-expression position, so the engine-argument carrier is reachable through
the `clickhouse_json` dialect, which executes a deserialized AST. The test
splices the `viewIfPermitted` node into the engine arguments of a
`parseQueryToJSON` output instead of writing the JSON by hand, so it follows
the serialization format rather than pinning it, and checks a benign nested
table function is still accepted.
@groeneai

groeneai commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 590b750

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (amd_debug, parallel) / 05054_embedded_rocksdb_explicit_dir_file_grant trunk red, not caused by this branch: the test failed on master itself from 09:00Z today, on 8 master check arms and about 60 unrelated pull requests #117651 (external, merged 2026-09-02T11:07:18Z), rule 3c
Stateless tests (arm_binary, parallel) / 05054_embedded_rocksdb_explicit_dir_file_grant same trunk red, second arm #117651 (external, merged 2026-09-02T11:07:18Z), rule 3c
Finish Workflow / new_tests_check.py cascade of the two rows above, not an independent defect: the hook reports Bugfix validation (functional tests, amd64/aarch64): DROPPED (Dropped due to previous failure [Stateless tests (amd_debug, parallel)]) and concludes none did. All 102 dropped nodes name that one culprit #117651 (external, merged 2026-09-02T11:07:18Z), same owner
Parser memory check / Resolve master binary CI infrastructure, not caused by this branch: No master clickhouse-examples artifact was found, because the master artifact prefix moved in #110081 (merged 2026-08-31). Breadth: 49 error rows over 48 distinct pull requests, zero true-master rows, and the check was 100% green until 10:30:22Z today a fix task is created (a fix is already in progress; fixing-PR link to follow here)
CH Inc sync still running when I wrote this ledger CH Inc sync (private, not actionable by me)

#117651 reverts the merged #117428, which is what added 05054_embedded_rocksdb_explicit_dir_file_grant,
so the revert deletes the test and the row disappears once it is in the built tree. Rule 3c rather than
3d, measured two ways: the test itself executed here (a tree carrying the revert has no such file), and
from_existing_metadata in src/Storages/RocksDB/StorageEmbeddedRocksDB.cpp is present at this head
(2 hits) and absent on master now (0 hits).

I deliberately did not merge master and re-push. @ alexey-milovidov holds this head (the last five
commits are his) and is mid-change, so a push from me would land on top of his live work. A rerun could
not make the head green anyway while the Parser memory check fix is unpublished.

Session id: cron:our-pr-ci-monitor:20260902-133000

@clickhouse-gh clickhouse-gh Bot added the comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). label Sep 4, 2026
…e is inferred

`createTable` calls `getTablePropertiesAndNormalizeCreateQuery` before
`doCreateTable`, and for `CREATE TABLE ... AS f(...)` without a column list
that helper resolves the table function through
`getActualTableStructureWithAccess` to infer the structure. The veto
(`canBeUsedToCreateTable` plus the nested `dependsOnCurrentUserGrants`
walk) ran only in `doCreateTable`, so on that path the inference happened
first: `remote('unreachable', viewIfPermitted(...))` connected to the shard
and failed with `NO_REMOTE_SHARD_AVAILABLE` instead of the promised
`BAD_ARGUMENTS`, and `viewIfPermitted(... ELSE remote(...))` analyzed the
`ELSE` arm before the refusal.

Both checks are now one helper, `throwIfTableFunctionCannotBeUsedToCreateTable`,
called right before the structure inference in
`getTablePropertiesAndNormalizeCreateQuery` and kept in `doCreateTable` for
the explicit-column-list form, which skips the inference. Persisted metadata
always carries a column list, so the early pass does not affect attaching an
existing table.

The comment avoids `<table function>`: clang's `-Wdocumentation-html` treats
it as an unterminated HTML tag.
…itted_not_persistable`

Two statements without a column list where a late veto would have side
effects: an outer `remote('127.0.0.1:1', viewIfPermitted(...))` and an
`ELSE remote('127.0.0.1:1', system.one)` arm. With the check still in
`doCreateTable` only, both fail on the connection attempt with a `519`
class error; the reference pins `BAD_ARGUMENTS` and no leaked identifier.
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 The sole red on 76f996abfd70 was Fast test / 03100_lwu_01_basics: ALTER TABLE ... APPLY PATCHES SETTINGS mutations_sync = 2 waited 60 s because the merge-selecting task refused to assign the mutation under merges/mutations pool contention from concurrent tests (max_tasks_count (32) - occupied (25) < number_of_free_entries_in_pool_to_execute_mutation (8)) and, right after the test's ATTACH, backed off for the full max_merge_selecting_sleep_ms. Unrelated to this PR, which only touches InterpreterCreateQuery and the table-function veto. Fix in #118435. Master merged in 9549462c126b for a fresh run.

pull Bot pushed a commit to Mu-L/ClickHouse that referenced this pull request Sep 6, 2026
…ool contention

The test timed out in `ALTER TABLE t_shared APPLY PATCHES SETTINGS mutations_sync = 2`:
the merge-selecting task refused to assign the mutation because the server-global pool was
occupied by concurrent tests (`max_tasks_count (32) - occupied (25) < number_of_free_entries_in_pool_to_execute_mutation (8)`),
and since the table had just been re-attached, `merge_selecting_sleep_ms` started near
`max_merge_selecting_sleep_ms`, so the next attempt was scheduled only after 60000 ms and the
`mutations_sync = 2` wait hit its 60 s limit. Set
`number_of_free_entries_in_pool_to_execute_mutation = 0` on the table, as `02899_restore_parts_replicated_merge_tree`
already does for the same reason.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=116885&sha=76f996abfd704d65e2eeb35a9cc4de47ac9cf0ba&name_0=PR&name_1=Fast%20test
PR: ClickHouse#116885

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 7, 2026
Merged via the queue into ClickHouse:master with commit afaab02 Sep 7, 2026
175 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 7, 2026
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-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). groeneai-origin-review-bot PR origin: review-bot finding on a groeneai PR 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

Development

Successfully merging this pull request may close these issues.

3 participants