From 6f8a450805f3e84611fe53f0623b00264db81834 Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Tue, 28 Mar 2023 20:55:28 +0000 Subject: [PATCH 1/2] Sort output of SHOW statements Sorting is strictly speaking not necessary, but 1. sorted output is more user-friendly, 2. SQL currently does not allow to sort the output of SHOW otherwise, e.g. SELECT * FROM (SHOW ...) ORDER BY is rejected. 3. SQL tests can take advantage of that. --- .../InterpreterShowEngineQuery.cpp | 2 +- .../InterpreterShowTablesQuery.cpp | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Interpreters/InterpreterShowEngineQuery.cpp b/src/Interpreters/InterpreterShowEngineQuery.cpp index 5aae6ad5d28..8fd829f39ec 100644 --- a/src/Interpreters/InterpreterShowEngineQuery.cpp +++ b/src/Interpreters/InterpreterShowEngineQuery.cpp @@ -12,7 +12,7 @@ namespace DB BlockIO InterpreterShowEnginesQuery::execute() { - return executeQuery("SELECT * FROM system.table_engines", getContext(), true); + return executeQuery("SELECT * FROM system.table_engines ORDER BY name", getContext(), true); } } diff --git a/src/Interpreters/InterpreterShowTablesQuery.cpp b/src/Interpreters/InterpreterShowTablesQuery.cpp index 4e0dfdc9236..bd29a933bcf 100644 --- a/src/Interpreters/InterpreterShowTablesQuery.cpp +++ b/src/Interpreters/InterpreterShowTablesQuery.cpp @@ -28,7 +28,6 @@ InterpreterShowTablesQuery::InterpreterShowTablesQuery(const ASTPtr & query_ptr_ { } - String InterpreterShowTablesQuery::getRewrittenQuery() { const auto & query = query_ptr->as(); @@ -51,6 +50,9 @@ String InterpreterShowTablesQuery::getRewrittenQuery() if (query.limit_length) rewritten_query << " LIMIT " << query.limit_length; + /// (*) + rewritten_query << " ORDER BY name"; + return rewritten_query.str(); } @@ -72,6 +74,9 @@ String InterpreterShowTablesQuery::getRewrittenQuery() if (query.limit_length) rewritten_query << " LIMIT " << query.limit_length; + /// (*) + rewritten_query << " ORDER BY cluster"; + return rewritten_query.str(); } else if (query.cluster) @@ -81,6 +86,9 @@ String InterpreterShowTablesQuery::getRewrittenQuery() rewritten_query << " WHERE cluster = " << DB::quote << query.cluster_str; + /// (*) + rewritten_query << " ORDER BY cluster"; + return rewritten_query.str(); } @@ -101,6 +109,9 @@ String InterpreterShowTablesQuery::getRewrittenQuery() << DB::quote << query.like; } + /// (*) + rewritten_query << " ORDER BY name, type, value "; + return rewritten_query.str(); } @@ -146,6 +157,9 @@ String InterpreterShowTablesQuery::getRewrittenQuery() else if (query.where_expression) rewritten_query << " AND (" << query.where_expression << ")"; + /// (*) + rewritten_query << " ORDER BY name "; + if (query.limit_length) rewritten_query << " LIMIT " << query.limit_length; @@ -176,5 +190,8 @@ BlockIO InterpreterShowTablesQuery::execute() return executeQuery(getRewrittenQuery(), getContext(), true); } +/// (*) Sorting is strictly speaking not necessary but 1. it is convenient for users, 2. SQL currently does not allow to +/// sort the output of SHOW otherwise (SELECT * FROM (SHOW ...) ORDER BY ...) is rejected) and 3. some +/// SQL tests can take advantage of this. } From d0f4c63d27d272b492d55379f0751b52ae5557a7 Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Wed, 29 Mar 2023 10:29:17 +0000 Subject: [PATCH 2/2] Fix tests --- src/Interpreters/InterpreterShowTablesQuery.cpp | 6 +++--- tests/queries/0_stateless/01293_show_settings.reference | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Interpreters/InterpreterShowTablesQuery.cpp b/src/Interpreters/InterpreterShowTablesQuery.cpp index bd29a933bcf..a631cb72722 100644 --- a/src/Interpreters/InterpreterShowTablesQuery.cpp +++ b/src/Interpreters/InterpreterShowTablesQuery.cpp @@ -71,12 +71,12 @@ String InterpreterShowTablesQuery::getRewrittenQuery() << DB::quote << query.like; } - if (query.limit_length) - rewritten_query << " LIMIT " << query.limit_length; - /// (*) rewritten_query << " ORDER BY cluster"; + if (query.limit_length) + rewritten_query << " LIMIT " << query.limit_length; + return rewritten_query.str(); } else if (query.cluster) diff --git a/tests/queries/0_stateless/01293_show_settings.reference b/tests/queries/0_stateless/01293_show_settings.reference index f11956e1893..f053387d1c5 100644 --- a/tests/queries/0_stateless/01293_show_settings.reference +++ b/tests/queries/0_stateless/01293_show_settings.reference @@ -3,6 +3,6 @@ connect_timeout Seconds 10 connect_timeout_with_failover_ms Milliseconds 2000 connect_timeout_with_failover_secure_ms Milliseconds 3000 external_storage_connect_timeout_sec UInt64 10 +filesystem_prefetch_max_memory_usage UInt64 1073741824 max_untracked_memory UInt64 1048576 memory_profiler_step UInt64 1048576 -filesystem_prefetch_max_memory_usage UInt64 1073741824