Skip to content

Make \d <table> of the interactive client describe the table - #118281

Merged
alexey-milovidov merged 1 commit into
masterfrom
psql-describe-table-118180
Sep 5, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
psql-describe-table-118180

Conversation

@alexey-milovidov

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

Copy link
Copy Markdown
Member

The psql-style \d of the interactive client is a textual alias of SHOW TABLES, so \d hits became SHOW TABLES hits, which is a syntax error. In psql a bare \d lists the relations and \d <name> describes one, and that is what it does here now: given a table name it expands to DESCRIBE TABLE, while a bare \d still lists the tables.

An argument that continues the listing query instead - \d FROM system, \d LIKE 'hits%' - keeps the listing, as it does today. A table whose name is spelled as one of the clauses that SHOW TABLES accepts (FROM, IN, NOT, LIKE, ILIKE, WHERE, LIMIT, INTO, FORMAT, SETTINGS, PARALLEL) has to be quoted, which is also what tells it apart from the clause.

The alias can now be followed by a ; as well, so \d; and \l; are no longer syntax errors.

Closes: #118180

Changelog category (leave one):

  • Improvement

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

The psql-style \d of the interactive client now describes a table when a table name is given (\d hits), like it does in psql; without an argument it still lists the tables.


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

The `psql`-style `\d` is a textual alias of `SHOW TABLES`, so `\d hits`
became `SHOW TABLES hits`, which is a syntax error. In `psql`, a bare
`\d` lists the relations and `\d <name>` describes one, and that is what
it does here now: given a table name it expands to `DESCRIBE TABLE`,
while a bare `\d` still lists the tables.

An argument that continues the listing query instead - `\d FROM system`,
`\d LIKE 'hits%'` - keeps the listing. A table whose name is spelled as
one of these clauses has to be quoted, which is also what tells it apart
from the clause.

The alias can now be followed by a `;` as well, so `\d;` and `\l;` are
no longer syntax errors.

Closes: #118180

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

mintlify Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
ClickHouse-docs 🟢 Ready View Preview Sep 5, 2026, 3:20 PM

@clickhouse-gh

clickhouse-gh Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2a7ccd7]

Summary: ✅


AI Review

Summary

This PR changes the interactive client's \d alias so \d <table> expands to DESCRIBE TABLE, keeps bare \d as SHOW TABLES, accepts a trailing ;, and documents/tests that behavior. The implementation is close, but the new routing heuristic only separates the first clause token on whitespace, so some valid SHOW TABLES continuations are still misclassified as table names. I am requesting changes for that parsing gap.

Findings

⚠️ Majors

  • [src/Client/ClientBase.cpp:255] \d promises to keep any argument that continues the SHOW TABLES query on the listing path, but first_word is cut only at whitespace. ClickHouse keywords are tokenized on SQL token boundaries, so valid forms such as \d WHERE(name LIKE 'd%'), \d LIKE'd%', or \d FROM/*x*/system arrive here as WHERE(name, LIKE'd%', and FROM/*x*/system and fall through to DESCRIBE TABLE .... That turns a valid listing continuation into a client-side misparse.
    Suggested fix: determine the first token using SQL token boundaries, or reuse the lexer/parser to ask whether the suffix starts with a SHOW TABLES clause, instead of scanning until whitespace.
Tests
  • ⚠️ Add one focused interactive expect case where the continuation keyword is immediately followed by punctuation or a comment, for example \d WHERE(name LIKE 'd%') or \d LIKE'd%', so the token-boundary behavior stays covered.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: fix the clause-token detection for \d so valid SHOW TABLES continuations are recognized on SQL token boundaries, then extend the expect coverage with one punctuation-adjacent continuation case.

LLVM Coverage Report

Measured on commit 2a7ccd7.

Metric Baseline Current Δ
Lines 88.80% 88.80% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 81.10% 81.20% +0.10%

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

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements comp-cli clickhouse-client (interactive CLI) and client library. labels Sep 5, 2026
Comment thread src/Client/ClientBase.cpp
|| !(isValidIdentifierBegin(argument.front()) || argument.front() == '`' || argument.front() == '"'))
return false;

const std::string_view first_word(argument.begin(), std::ranges::find_if(argument, isWhitespaceASCII));

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.

Valid SHOW TABLES continuations are tokenized on SQL token boundaries, not whitespace. Here first_word becomes WHERE(name, LIKE'd%', or FROM/*x*/system, so inputs like \d WHERE(name LIKE 'd%'), \d LIKE'd%', and \d FROM/*x*/system get routed to DESCRIBE TABLE ... instead of staying on the listing path. Since the new contract is that any argument continuing the SHOW TABLES query keeps the listing, this needs to split on the first SQL token boundary (or reuse the lexer/parser) rather than only on isWhitespaceASCII.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Minor.

@clickhouse-gh

clickhouse-gh Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 2a7ccd72b with master d37d2ea3f (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 5b8a4ca24; 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

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

Job report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Sep 5, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 5, 2026
Merged via the queue into master with commit 246dfd6 Sep 5, 2026
175 checks passed
@alexey-milovidov
alexey-milovidov deleted the psql-describe-table-118180 branch September 5, 2026 20:23
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 5, 2026

This branch was successfully deployed

1 active deployment
staging - docs — 2a7ccd72 Deployed Sep 5, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-cli clickhouse-client (interactive CLI) and client library. pr-improvement Pull request with some product improvements 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.

New Postgres-like \d syntax doesn't work for showing table definitions

2 participants