Skip to content

Add coverage for two untested branches in ATTACH and JSONColumns - #114293

Merged
PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:group-d-analyzer-views-refile-batch26
Aug 12, 2026
Merged

PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:group-d-analyzer-views-refile-batch26

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

Related: #101781
Related: #103925
Related: #103930
Related: #103914
Related: #101743
Related: #103923

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

Test-only, 6 files, 19 insertions. @ zlareb1 asked me to re-file five closed clickgapai coverage PRs (linked above); this is the analyzer/views group.

I did not take them on trust: for each one I mutated the line it claims to cover and required that test to fail, with neighbouring tests staying green. Three survived, two did not.

  • 103925 -> 04201_attach_table_missing_database: short ATTACH TABLE into a missing database. Nothing under tests/ asserts UNKNOWN_DATABASE for an ATTACH, and master's qualified bare-ATTACH tests all attach into a database that exists. The sibling throw on the createTable path is uncovered too, and out of scope here. One statement, since ATTACH DICTIONARY reaches the identical throw before any is_dictionary check.
  • 103914 -> 04201_force_null_for_omitted_jsoncolumns. input_format_force_null_for_omitted_fields has six copies in src/; 03004 covers five, not the JSONColumns one. Two rows, not eight: JSONColumns, JSONCompactColumns and JSONColumnsWithMetadata emit a byte-identical exception from one base class, so they are one dispatch.
  • 103930 -> one added assertion in the existing 02884_create_view_with_sql_security_option, not a new file. Everything it needs is already set up; only the negative check that DEFINER = is gone after MODIFY SQL SECURITY INVOKER was missing. The equals sign matters, since a bare DEFINER also matches SQL SECURITY DEFINER.
  • 101743 declined (reason posted there). Its .reference would freeze an unresolved semantic: CREATE-time validation reads getSampleBlockInsertable() (MATERIALIZED excluded) while the runtime sink reads getSampleBlock() (included), so the runtime path accepts what CREATE rejects. Owner-level call.
  • 103923 declined (reason posted there). Its only site beyond 04338 is the cache-hit copy, which leaves the cached query tree unrewritten, and _table comes from getStorageID(), not the alias, so what it predicted is not SQL-observable.

Already covered elsewhere, so the gaps are not oversights: MODIFY DEFINER by 04126 and 02884, the materialized-view form by 04201_alter_materialized_view_modify_sql_security_invoker_error.

Validation

Debug build, clickhouse-test, randomization on (the CI default). Every mutation changes the branch's output rather than deleting it, so a fall-through to an equivalent path cannot be mistaken for a vacuous test. Each arm was reverted and rebuilt before the next, with the Build ID asserted to move both ways.

test mutation result
04201_attach_table_missing_database InterpreterCreateQuery.cpp:1758 thrown code swapped FAIL alone. Since the mutation is at that line, only a statement resolving there can redden, which is what pins the site; two other UNKNOWN_DATABASE tests stayed OK as non-interference checks
02884_create_view_with_sql_security_option StorageInMemoryMetadata.cpp:126 definer not cleared the new assertion flips 0 to 1, nothing else changes; the existing SQL SECURITY INVOKER row stays 1, so a 0 cannot mean the ALTER no-opped
04201_force_null_for_omitted_jsoncolumns JSONColumnsBlockInputFormatBase.cpp:206 type predicate negated FAIL alone; 03004 stayed OK, so the sibling copies are untouched

The ATTACH reference is 0 bytes, correct for a serverError-only test: verified on stderr, and a stray newline or wrong code both fail. Both new tests passed 50/50 runs with randomization and 50/50 with --no-random-settings, plus 4x concurrently with themselves and alongside 03004, 04126, 04010, 04141 and 02884, so neither needs no-parallel.

Re-files three of five closed clickgapai coverage PRs (103925, 103930, 103914)
that zlareb1 asked to be re-filed via ClickHouse#101781. Two of the five are declined with
the reason posted on their own threads: 101743 (its reference would freeze an
unresolved CREATE-time-vs-runtime MV validation semantic, an owner-level call)
and 103923 (its only site beyond 04338 is the cache-hit copy, which leaves the
cached query tree unrewritten, so it is not observable from SQL).

Each shipped test was falsified rather than taken on trust: the exact line it
claims to cover was mutated, the binary rebuilt with the Build ID asserted to
move, and the test required to fail while neighbouring tests stayed green.

- 04201_attach_table_missing_database pins the UNKNOWN_DATABASE throw in the
  stub-ATTACH block of InterpreterCreateQuery.cpp. No file under tests/ asserts
  UNKNOWN_DATABASE for an ATTACH, and the qualified bare-ATTACH tests on master
  all attach into a database that exists first. The sibling throw on the
  createTable path is uncovered too and stays out of scope here. Because the
  mutation is injected at that throw, only a statement resolving there can
  redden, which is what pins the site. One statement: ATTACH DICTIONARY reaches
  the identical throw before any is_dictionary discrimination.

- 04201_force_null_for_omitted_jsoncolumns pins the force-null check in
  JSONColumnsBlockInputFormatBase. That setting has six independent copies in
  src/ and 03004 covers five, not this one. Two rows rather than eight:
  JSONColumns, JSONCompactColumns and JSONColumnsWithMetadata were measured to
  emit a byte-identical exception from the same base class, so they are one
  dispatch. Negating the type predicate reddens this test while 03004 stays
  green, so the sibling copies are untouched.

- 02884_create_view_with_sql_security_option gains one assertion instead of a
  new file. It already performs the definer-to-invoker transition and reads
  SHOW CREATE TABLE; only the negative check that the definer is gone was
  missing. The pattern needs the equals sign, since a bare DEFINER also matches
  SQL SECURITY DEFINER. Leaving the definer uncleared flips that assertion from
  0 to 1 and changes nothing else in the file, while its existing
  SQL SECURITY INVOKER row stays 1 and so serves as the did-the-ALTER-run
  control.

The ATTACH reference is empty, which is correct for a serverError-only test, and
was verified on stderr: a stray newline or a wrong error code both fail. The
02884 reference line was placed by running the test and rebuilding the file from
its output, not by hand. The ATTACH test is scoped to CLICKHOUSE_DATABASE_1
rather than a server-global database name so it is safe to run against itself.

Both new tests passed 50 runs with randomized settings and 50 with
--no-random-settings, plus four concurrent copies of themselves and a joint run
with 03004, 04126, 04010, 04141 and 02884, so neither needs no-parallel.
@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 rounds) plus my own cold review
of the resulting tree, done before reading the implementation notes. One fix round happened: my
own review found a false claim in the description and the notes, the tree went back for a
text-only correction, and the corrected text was re-reviewed. No change under tests/ resulted
from that round, so the tree that was reviewed is the tree that is published.

# Sev Finding Verdict Evidence / action
1 ⚠️ The Nullable success row may silently stop exercising the exemption, since default insertion into Nullable also yields NULL; and its LowCardinality(Nullable) sibling is missing DISAGREE on the liveness half, disclosed on the breadth half The liveness half needs the setting to possibly NOT reach format() at that nesting level, and the mutation arm measures that it does. The arm drops the ! from isNullableOrLowCardinalityNullable at JSONColumnsBlockInputFormatBase.cpp:206, so the condition becomes force_null_for_omitted_fields && isNullableOrLowCardinalityNullable(type); under it the Nullable row throws Cannot insert NULL value into a column 'bar' of type 'Nullable(UInt32)', which is unreachable unless the setting is true there. The LowCardinality(Nullable) cell is genuinely uncovered for this format, but it exercises the same two-term predicate (IDataType.h:560-563) that 03004 already covers for five of the six copies in src/, so it was cut deliberately for minimality, not missed. Happy to add it if a maintainer wants the breadth
2 💡 The title names two branches, but a third (view SQL security) is also covered; rename it DISAGREE The third item is not a new test: it is one added assertion inside the pre-existing 02884_create_view_with_sql_security_option, which already performed the definer-to-invoker transition at :99-101 and already read SHOW CREATE TABLE. It is named in the description. The suggested title is 96 chars, over the 70-char budget, and would give a one-line strengthening equal billing with two new files
3 💡 Backtick literals (ATTACH TABLE, UNKNOWN_DATABASE, DEFINER, ...) in the new test comments DISAGREE That rule governs changelog and GitHub-facing text, not test comments, and it is not the in-tree convention: of 46,667 comment lines in tests/queries/0_stateless/*.sql only 16.5% contain a backtick, and of 25,419 in *.sh only 14.4%. In a .sh file a backtick also opens command substitution

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

The fix round came from my own review, not from the gate. The description, the notes and the
commit message all stated that the pre-existing UNKNOWN_DATABASE tests reach the sibling throw
on the createTable path, and that their staying green is what pins the ATTACH site. Measured:
not one of them enters InterpreterCreateQuery at all (the ten existing assertions resolve in
hasColumnInTable, DatabaseCatalog, StorageMerge, DROP TABLE, SYSTEM SYNC REPLICA, and
one materialized view whose missing object is its SELECT source), and that sibling throw is
uncovered too. So the sentence asserted coverage that exists nowhere, and the two named controls
could not have failed under that mutation. The site attribution itself is unaffected and is in
fact simpler: the mutation is injected at the line, so only a statement reaching it can redden.
All counts in the description were then re-measured from scratch.

What I checked that could have failed, rather than what passed: each new test's liveness against
a revert of the branch it claims; that no other test in the tree asserts UNKNOWN_DATABASE for
an ATTACH (four files mention both, and the three pre-existing ones are a log allowlist, a
RENAME, and a successful ATTACH into a database that exists); that the runner never creates
CLICKHOUSE_DATABASE_1, so the assertion cannot silently degrade into a different error; that
all three JSONColumns formats instantiate one base class with no subclass and no override of
the method carrying the guard; the full definer-clearing path from AlterCommands.cpp:1152
through setSQLSecurity to ASTSQLSecurity::formatImpl, including that a bare DEFINER pattern
could never reach 0; that 02884's reference differs from master by exactly one line, in the
right position, and that no local cluster or database name leaked into it; and that a grep -c
returning 0 is safe in that file, which has no set -e and three existing 0 lines from the
same idiom.

Session id: cron:clickhouse-review-slot-11:20260811-082600

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? This PR adds coverage, so the equivalent obligation is falsification, not defect reproduction. Each shipped test has a deterministic mutation that reddens it on demand: 3 arms, one per test, each injected at the exact cited line, rebuilt, and run under the real runner.
b Root cause explained? Each test closes a named branch-coverage gap, verified per test rather than assumed. InterpreterCreateQuery.cpp:1758 is reached only by the short ATTACH form, and measured on this tree: no file under tests/ contains both an ATTACH and an UNKNOWN_DATABASE assertion (0 of the 30 files that mention UNKNOWN_DATABASE), the 10 pre-existing serverError UNKNOWN_DATABASE assertion lines across 7 0_stateless files resolve in hasColumnInTable, DatabaseCatalog, the show-tables path, StorageMerge, InterpreterDropQuery and InterpreterSystemQuery rather than in InterpreterCreateQuery, and every master test with a qualified bare ATTACH attaches into a database that exists first (checked exhaustively rather than by count, since the count is regex-sensitive: each one either issues its own CREATE DATABASE or targets {CLICKHOUSE_DATABASE}, which the runner creates at clickhouse-test:2244-2250). The sibling UNKNOWN_DATABASE throw at :1954 (the createTable path) is uncovered as well and is deliberately not addressed here. force_null_for_omitted_fields has six independent copies in src/ and 03004 covers five, not the JSONColumns one. For 02884 the missing thing was narrower than the original PR assumed: the file already performs the definer-to-invoker transition and reads SHOW CREATE TABLE; only the negative DEFINER = assertion was absent.
c Fix matches root cause? Yes. Test-only, no src/ change. Each assertion targets exactly the line claimed, proven by a mutation injected at that line reddening that test: since the mutation is local to the line, only a statement that resolves there can redden. Neighbouring tests were run alongside each arm and stayed green, which is non-interference evidence rather than site attribution.
d Test intent preserved / new tests added? 2 new tests, 1 existing test gains one assertion, 0 removed, 0 weakened. 02884 keeps its tags, users, objects and existing assertions; its pre-existing SQL SECURITY INVOKER row now doubles as the did-the-ALTER-run control. Arms were cut only where measured non-distinct, each recorded with its dispatch citation: the three JSONColumns formats emit a byte-identical exception from one base class, and ATTACH DICTIONARY reaches the same throw before any is_dictionary discrimination.
e Both directions demonstrated? Yes, per test under the real runner: green on the pristine binary, red under its mutation, green again after revert, with the Build ID asserted to move on every transition and asserted equal between the on-disk binary and the running server. 02884's arm was pinned to the exact line: the new assertion flips 0 to 1 at reference line 17 and nothing else in the file changes.
f Fix is general across code paths? Carriers enumerated, each covered or explicitly out of scope with its citation. One mutation of StorageInMemoryMetadata.cpp:126 reddens all four setSQLSecurity callers, so redness proves non-vacuity but not per-storage attribution, and the PR body does not overclaim. Left out of scope and named in the body: the MODIFY DEFINER parser arm (pinned by 04126 and 02884:361) and the materialized-view form of MODIFY SQL SECURITY INVOKER (covered by 04201_alter_materialized_view_modify_sql_security_invoker_error). The five sibling force_null_for_omitted_fields copies are covered by 03004, which stayed green under the arm.
g Fix generalizes across inputs? Exactly the wrapper coverage that maps to a distinct dispatch, and no more: non-Nullable (throws) plus Nullable (succeeds), since LowCardinality(Nullable(...)) goes through the same isNullableOrLowCardinalityNullable predicate and is already covered by 03004. allow_suspicious_low_cardinality_types was dropped along with that arm rather than left as a dead SET.
h Backward compatible? N/A. Test-only: no setting default, no serialization format, no new validation, so no SettingsChangesHistory.cpp entry applies.
i Invariants and contracts preserved? N/A for source invariants (no src/ change). Test-level contracts checked: no default.-qualified name and no database name in either reference; no no-parallel tag on either new test (4x concurrent with itself, plus a joint run with 03004, 04126, 04010, 04141 and 02884, all OK); the ATTACH test scoped to {CLICKHOUSE_DATABASE_1:Identifier} instead of a server-global database name; the 02884 reference regenerated by running and asserted to differ from the committed file by exactly one added line; filenames free-checked case-insensitively against live master, all-author open PRs and live fleet worktrees, each with a passing positive control.

Session id: cron:clickhouse-review-slot-11:20260811-082600

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @pufit, could you review this? It is test-only: it pins the UNKNOWN_DATABASE throw in the stub-ATTACH block of InterpreterCreateQuery, the force-null check in JSONColumnsBlockInputFormatBase (the one copy of that setting 03004 does not reach), and adds one assertion to 02884 that the definer is actually cleared by MODIFY SQL SECURITY INVOKER.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Aug 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4a5ef5d]

Summary: ❌

job_name test_name status info comment
Stress test (arm_asan_ubsan) FAIL
Sanitizer (STID: 2064-22d0) FAIL cidb, issue ISSUE EXISTS

AI Review

Summary

This PR is test-only. It adds focused coverage for the short ATTACH missing-database path and the JSONColumnsBlockInputFormatBase omitted-column nullability check, and it strengthens the existing SQL security view test by asserting that MODIFY SQL SECURITY INVOKER removes the stored DEFINER. I did not find correctness, determinism, or coverage-scope problems in the current diff.

Final Verdict

✅ No findings.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 11, 2026
@PedroTadim PedroTadim self-assigned this Aug 11, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 4a5ef5d

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens.

Check / test Reason Owner / fixing PR
Stress test (arm_asan_ubsan) / Sanitizer (STID: 2064-22d0) LeakSanitizer, all-indirect (0 direct), trunk bug, not caused by this PR #113397 (external, open)

Notes on the single failure:

  • This PR changes 6 files, 19 insertions, under tests/ only, with no src/ change. The leak stack
    is engine code: Settings::Settings(Settings const&) (src/Core/Settings.cpp:9179) via
    ContextData::ContextData -> Context::createCopy (Context.cpp:1429) <-
    QueryTreeBuilder::buildSelectExpression (src/Analyzer/QueryTreeBuilder.cpp:272).
  • Breadth over 30 days, keyed on the STID: 40+ distinct unrelated pull requests and 12 master runs
    between 2026-08-08 and 2026-08-11, so it is reachable on master independently of this branch.
  • Frame check on this report: QueryTreeBuilder, createCopy and MaterializedCTE present;
    makeQueryContext, DDLWorker and DatabaseReplicated absent. That places it in the
    materialized-CTE query-path half of the family, which is what Fix a table permanently stuck in the drop queue after a failed materialized-CTE query #113397 fixes, and not in the
    DDL-finalizer half.
  • Build (arm_release) / Post Hooks shows a FAIL row in the CI database while the check itself is
    green; that row is a known reporting artifact and is not a failure of this PR.

Session id: cron:our-pr-ci-monitor:20260811-130000

@PedroTadim
PedroTadim added this pull request to the merge queue Aug 12, 2026
Merged via the queue into ClickHouse:master with commit 31372e9 Aug 12, 2026
179 of 181 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 12, 2026
@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Aug 19, 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 groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-ci 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