From 65fbcdc91d53bb48efff3bb41c23732b6c4b32fc Mon Sep 17 00:00:00 2001 From: azevaykin Date: Tue, 7 Jul 2026 11:48:39 +0300 Subject: KIKIMR-25621: Introduce multi-column statistics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### Introduce multi-column statistics support ✎ - Adds support for defining multi-column statistics in table schemas, allowing users to specify statistics for combinations of columns rather than individual columns - Introduces new SQL syntax for CREATE TABLE and ALTER TABLE statements to declare statistics with optional type specifications - Implements validation for statistics definitions, ensuring column references are valid and names are unique - Extends the query processing pipeline to handle statistics declarations during table creation and modification operations - Updates syntax highlighting and parsing rules to recognize the new statistics keyword and related constructs - Adds comprehensive unit tests covering various statistics scenarios including multi-column definitions, type specifications, and validation rules Autodescription by Yandex Code Assistant commit_hash:5ca3f8721d3e3660f2bb890c1408e420cf7c3e81 --- yql/essentials/sql/v1/sql_translation.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'yql/essentials/sql/v1/sql_translation.cpp') diff --git a/yql/essentials/sql/v1/sql_translation.cpp b/yql/essentials/sql/v1/sql_translation.cpp index b95e1c61b56..17596ab4d9c 100644 --- a/yql/essentials/sql/v1/sql_translation.cpp +++ b/yql/essentials/sql/v1/sql_translation.cpp @@ -790,6 +790,28 @@ bool TSqlTranslation::CreateTableIndex(const TRule_table_index& node, TVector& statistics) { + statistics.emplace_back(IdEx(node.GetRule_an_id2(), *this)); + auto& stat = statistics.back(); + + // ON (columns) + stat.Columns.emplace_back(IdEx(node.GetRule_an_id_schema5(), *this)); + for (const auto& block : node.GetBlock6()) { + stat.Columns.emplace_back(IdEx(block.GetRule_an_id_schema2(), *this)); + } + + // WITH (types) — optional; omission means "all supported statistic types" + if (node.HasBlock8()) { + const auto& withTypes = node.GetBlock8().GetRule_with_statistics_types1(); + stat.Types.emplace_back(IdEx(withTypes.GetRule_an_id_or_type3(), *this)); + for (const auto& block : withTypes.GetBlock4()) { + stat.Types.emplace_back(IdEx(block.GetRule_an_id_or_type2(), *this)); + } + } + + return true; +} + bool TSqlTranslation::ParseDatabaseSettings(const TRule_database_settings& in, THashMap& out) { if (!ParseDatabaseSetting(in.GetRule_database_setting1(), out)) { return false; @@ -2156,6 +2178,14 @@ bool TSqlTranslation::CreateTableEntry(const TRule_create_table_entry& node, TCr params.Columns.push_back({.Pos = pos, .Name = name, .Nullable = true}); break; } + case TRule_create_table_entry::kAltCreateTableEntry7: { + // table_statistics + auto& table_statistics = node.GetAlt_create_table_entry7().GetRule_table_statistics1(); + if (!CreateTableStatistics(table_statistics, params.Statistics)) { + return false; + } + break; + } case NSQLv1Generated::TRule_create_table_entry::ALT_NOT_SET: YQL_ENSURE(false, "Unreachable"); } -- cgit v1.3