Skip to content

Clear the explain_todo statements added by parameter substitution - #145

Open
kyleconroy wants to merge 7 commits into
claude/project-thread-wk8rxb-paramsfrom
claude/project-thread-wk8rxb-params-todo
Open

kyleconroy wants to merge 7 commits into
claude/project-thread-wk8rxb-paramsfrom
claude/project-thread-wk8rxb-params-todo

Conversation

@kyleconroy

Copy link
Copy Markdown
Collaborator

Requested by Kyle · project thread

Summary

Stacked on #144. This fixes the 49 explain_todo statements that #144 added, so explain_todo is empty again.

Test harness substitution, now closer to ClickHouse's ReplaceQueryParameterVisitor

  • String parameters are substituted after parsing through a new ast.Parameter.Value field. EXPLAIN prints the literal, but the AST keeps its parameter shape, so IN ({a:String}, {b:String}) stays Function tuple instead of folding into a tuple literal.
  • Parameters inside quoted strings, and in the body of a CREATE VIEW, are left alone. ClickHouse doesn't substitute there either.

Parser and EXPLAIN

  • TRUNCATE [ALL] TABLES FROM [IF EXISTS] db [[NOT] [I]LIKE ...]
  • RENAME a TO b without TABLE
  • UPDATE db.t prints the database identifier and accepts ON CLUSTER
  • CREATE TABLE ... AS SELECT ... FORMAT x puts FORMAT on the CREATE query
  • CREATE DATABASE ... SETTINGS with no engine prints query settings
  • Table names in CREATE are escaped like other dumped names (test%_\\_)
  • ATTACH DATABASE ... ENGINE = MySQL(...) hides the password, as CREATE does
  • ALTER TABLE ... MODIFY REFRESH. The REFRESH parsing for CREATE is now a shared parseRefreshStrategy method.

go test ./... passes. -check-explain leaves no pending statements.


Generated by Claude Code

kyleconroy and others added 5 commits December 1, 2026 05:21
ALTER QUOTA now goes through the CREATE QUOTA parser, which matches the
CreateQuotaQuery node ClickHouse prints for both. SHOW CREATE QUOTA with
more than one name prints as SHOW CREATE QUOTAS. Clears all 24 todo
statements in 01297_create_quota.


Claude-Session: https://claude.ai/code/session_01LuRZ4GWXBrmUXAf6RUPFSs

Co-authored-by: Claude <noreply@anthropic.com>
)

- SHOW TABLES accepts IN as well as FROM.
- COLUMN can be an implicit alias (select x column).
- Double-quoted identifiers use the same escape rules as backquoted ones,
  so unknown escapes keep their backslash; identifier and column names
  are escaped like ClickHouse's writeEscapedString when printed.
- The DISTINCT group of a mixed union flattens nested unions, matching
  NormalizeSelectWithUnionQueryMatcher.
- EXPLAIN CURRENT TRANSACTION works as a subquery (viewExplain with two
  arguments).
- A query parameter in WITH keeps its alias.
- INTERVAL CASE ... END <unit> parses as an interval.
- WITH elements cloned into later SELECTs of a union print TableJoin
  before TableExpression, as ASTTablesInSelectQueryElement::clone does.

explain_todo is empty again.


Claude-Session: https://claude.ai/code/session_01LuRZ4GWXBrmUXAf6RUPFSs

Co-authored-by: Claude <noreply@anthropic.com>
ClickHouse reads "# " and "#!" as line comments. Both statement splitters
joined such a line into the next statement, so the comment swallowed it
and ClickHouse returned an error instead of EXPLAIN output. Both splitters
now skip these lines, except inside a multi-line string literal.

Regenerating adds 53 explain files, and all of them pass.


Claude-Session: https://claude.ai/code/session_01LuRZ4GWXBrmUXAf6RUPFSs

Co-authored-by: Claude <noreply@anthropic.com>
Statements that use {CLICKHOUSE_DATABASE:Identifier} and similar never
got explain files, because ClickHouse refuses to explain them without a
value and substitutes the value before printing when one is given.
regenerate-explain now sends fixed values (test_db, test_db_1,
test_db_2), and the parser tests substitute the same names before parsing.

This adds 2,055 explain files. 2,006 statements pass; the other 49 are
recorded in explain_todo.


Claude-Session: https://claude.ai/code/session_01LuRZ4GWXBrmUXAf6RUPFSs

Co-authored-by: Claude <noreply@anthropic.com>
Test harness:
- String parameters are substituted after parsing (ast.Parameter.Value),
  so (p1, p2) stays a tuple function as in ClickHouse.
- Parameters inside quoted strings and in a view's body are left alone.

Parser and EXPLAIN:
- TRUNCATE [ALL] TABLES FROM [IF EXISTS] db [[NOT] [I]LIKE ...].
- RENAME without TABLE.
- UPDATE db.table prints the database identifier; ON CLUSTER is accepted.
- CREATE TABLE ... AS SELECT ... FORMAT x puts FORMAT on the CREATE query.
- CREATE DATABASE ... SETTINGS without an engine prints query settings.
- Table names in CREATE are escaped like other dumped names.
- ATTACH DATABASE hides engine secrets as CREATE does.
- ALTER TABLE ... MODIFY REFRESH.

explain_todo is empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LuRZ4GWXBrmUXAf6RUPFSs
@kyleconroy kyleconroy self-assigned this Dec 1, 2026
@kyleconroy
kyleconroy added this pull request to stack #142 December 1, 2026 13:29
…-wk8rxb-params-todo

# Conflicts:
#	parser/parser_test.go
#	parser/testdata/00080_show_tables_and_system_tables/metadata.json
The merge took main's explain_todo entries for statements this branch
fixes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LuRZ4GWXBrmUXAf6RUPFSs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants