Repository navigation
Conversation
|
Generally LGTM. ClientBase::default_database seems a valid source of information. Concerns/questions.
If (2) is true, I suggest we should abandon the development. |
|
Thanks for the review!
|
c6905ed to
7d9b6fb
Compare
|
I've implemented alternative one rather than abandoning the PR. What changed: Added Key design decisions:
Happy to adjust the hook point in the connect flow if you see a better |
7d9b6fb to
2fffb34
Compare
|
That's really impressive. |
2fffb34 to
7801dfc
Compare
|
Valid point — I investigated this. Looking at TCPHandler.cpp, default_database is only applied to the session context once during the connection handshake via setCurrentDatabase(). After that, the session's current database is owned entirely by the session context and only changes via USE statements. SYSTEM RELOAD CONFIG in InterpreterSystemQuery.cpp has no code path that propagates default_database changes to existing sessions. So syncDefaultDatabase() at connect time is sufficient — an already running session cannot have its default database changed by a server config reload. I've added a code comment documenting this boundary for future readers/editors!
|
|
Hello @il9ue , I suggest we should mention |
|
I reviewed again and I have few concerns to share
|
|
Our options for non-interactive sessions
Further thoughts about ClientBase::syncDefaultDatabase .
|
805df09 to
45a94d8
Compare
|
Thanks for all the detailed feedback — addressed everything in the latest push: 1. Non-interactive sessions / extra round-trip cost if (is_interactive && default_database.empty() && prompt.find("{database}") != String::npos)
2. Test 3 too permissive 3. clickhouse-local not covered by tests
4. Changelog — explicitly mentioning both clickhouse-client and clickhouse-local Note on |
|
LGTM |
|
Hi @alexey-milovidov — hope you don't mind the ping. I wanted to flag PR #100607 (re-adding Quick summary of what's in the PR:
Would really appreciate it if you could trigger the workflow or leave any final feedback. Happy to address anything further. |
Backport of ClickHouse#100607 to antalya-25.8. - Dynamic {database} substitution in ClientBase::getPrompt() from default_database (updated by USE and --database). - ClientBase::syncDefaultDatabase() runs SELECT currentDatabase() after the handshake so the prompt reflects server-side default_database when --database is not passed. - Sync call in Client::connect() is guarded by is_interactive, default_database.empty(), and prompt contains {database}. - Expect tests for both clickhouse-client and clickhouse-local. Closes ClickHouse#49118
Backport ClickHouse#100607 to 25.8.16: Re-add {database} macro support in clickhouse-client prompt
…100607 Revert "Backport ClickHouse#100607 to 25.8.16: Re-add {database} macro support in clickhouse-client prompt"
The {database} macro was removed in PR ClickHouse#42508 because it read from
static config and did not update after USE statements. This re-adds
the macro by substituting it dynamically from the default_database
member variable, which is updated on USE and --database flag.
Closes ClickHouse#49118
…efault
Problem:
If the server has a non-default default_database configured server-side
and the client does not pass --database, the client's default_database
member was empty/wrong, causing {database} in the prompt to display an
incorrect value.
Solution:
Add ClientBase::syncDefaultDatabase() which fires a lightweight
SELECT currentDatabase() immediately after the connection handshake
completes and writes the result back into default_database. This ensures
the prompt always reflects the true current database regardless of
whether it was set via --database CLI flag or server-side configuration.
Details:
- Declared syncDefaultDatabase() in private section of ClientBase.h
- Implemented in ClientBase.cpp using the existing connection packet
send/receive pattern
- Called at the end of connect(), after handshake, before first prompt render
- Wrapped in try/catch: failure logs a WARNING and degrades gracefully
rather than breaking the connection
- default_database is only updated if the returned value is non-empty
- Added Test 3 to 04056_client_prompt_database.expect covering the
server-side default_database scenario
Closes ClickHouse#49118
Documents why syncing once at connect is sufficient: - TCPHandler.cpp only applies default_database to session context during the connection handshake - SYSTEM RELOAD CONFIG has no code path that propagates default_database changes to already-established sessions - Therefore, server config reloads cannot affect the current database of a running session
Changes:
programs/client/Client.cpp:
Guard syncDefaultDatabase() with three conditions:
if (is_interactive && default_database.empty() && prompt.find("{database}") != String::npos)
syncDefaultDatabase();
- is_interactive: prompt is never shown in batch mode; the extra
SELECT currentDatabase() round-trip would only add latency
- default_database.empty(): if --database was passed, default_database
is already correct; overriding it with the server value would be wrong
- prompt.find("{database}"): the query is meaningless if the macro
is not in the prompt at all
tests/queries/0_stateless/04056_client_prompt_database.expect:
Test 3 now expects the literal string "default" instead of the loose
regex [a-z_]+, which was underspecified and would pass even if an
incorrect database name were shown.
tests/queries/0_stateless/04057_local_prompt_database.expect (new):
Added expect test for clickhouse-local:
- Test 1: verifies {database} shows "default" when no --database flag
is passed, via the empty fallback in getPrompt()
- Test 2: verifies {database} updates to "system" after USE system;
src/Client/ClientBase.cpp / programs/local/LocalServer.cpp:
No changes needed. LocalServer::connect() never called
syncDefaultDatabase() to begin with, and the getPrompt() fallback
already handles the empty default_database case correctly for local.
5e7a557 to
fefa71a
Compare
|
Hello @alexey-milovidov , could you have a look please. |
…macro-in-prompt Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [da6c8d8] Summary: ❌
|
Move `syncDefaultDatabase` and `executeQueryForSingleString` out of the `USE_CLIENT_AI` block, so that the client links in builds without AI support. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Re-add
{database}macro support in clickhouse-client prompt{database}macro was removed in PR Remove support for the{database}macro from the client's prompt #42508 because it read from static config and did not update afterUSEstatements. This re-adds the macro by substituting it dynamically from thedefault_databasemember variable, which is updated onUSEand--databaseflag.Closes #49118
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
{database}macro in the client prompt (prompt_by_server_display_name). Unlike the previous implementation removed in Remove support for the{database}macro from the client's prompt #42508, the database name now updates dynamically afterUSEstatements and correctly reflects the--databaseCLI flag.Documentation entry for user-facing changes
Documentation is written (mandatory for new features)
The
{database}macro is now available again in theprompt_by_server_display_nameclient configuration setting, alongside{host},{port},{user}, and{display_name}. It displays the current database and updates dynamically when switching databases viaUSE.Example configuration:
Workflow [PR]
Sync PR [sync-upstream/pr/100607]