Skip to content

Merge table 'Unknown identifier' in GROUP BY for joined column #15228

@UnamedRus

Description

@UnamedRus

How to reproduce
Clickhouse server version 20.3.17

CREATE TABLE table_2(key UInt32, ID UInt32) ENGINE = MergeTree PARTITION BY tuple() ORDER BY key;
CREATE TABLE merge_table (key UInt32) ENGINE=Merge(default,'^table');
CREATE TABLE table (key UInt32) ENGINE=MergeTree PARTITION BY tuple() ORDER BY key;}

SELECT ID, key FROM merge_table INNER JOIN table_2 USING(key) GROUP BY ID, key;

[a5342ff16411] 2020.09.24 10:45:40.732748 [ 72 ] {42a90654-6796-4584-a7f0-5113d0b3d721} <Debug> executeQuery: (from 127.0.0.1:40086) SELECT ID, key FROM merge_table INNER JOIN table_2 USING (key) GROUP BY ID, key
[a5342ff16411] 2020.09.24 10:45:40.733291 [ 72 ] {42a90654-6796-4584-a7f0-5113d0b3d721} <Trace> AccessRightsContext (default): Access granted: SELECT(key, ID) ON default.table_2
[a5342ff16411] 2020.09.24 10:45:40.733356 [ 72 ] {42a90654-6796-4584-a7f0-5113d0b3d721} <Debug> Join: setSampleBlock: table_2.key UInt32 UInt32(size = 0), ID UInt32 UInt32(size = 0)
[a5342ff16411] 2020.09.24 10:45:40.733928 [ 72 ] {42a90654-6796-4584-a7f0-5113d0b3d721} <Debug> MemoryTracker: Peak memory usage (total): 0.00 B.
[a5342ff16411] 2020.09.24 10:45:40.734072 [ 72 ] {42a90654-6796-4584-a7f0-5113d0b3d721} <Error> executeQuery: Code: 47, e.displayText() = DB::Exception: Unknown identifier (in GROUP BY): ID (version 20.3.17.173 (official build)) (from 127.0.0.1:40086) (in query: SELECT ID, key FROM merge_table INNER JOIN table_2 USING (key) GROUP BY ID, key), Stack trace (when copying this message, always include the lines below):

0. Poco::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) @ 0x1059b460 in /usr/bin/clickhouse
1. DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) @ 0x8f9972d in /usr/bin/clickhouse
2. ? @ 0xd34aca0 in /usr/bin/clickhouse
3. DB::ExpressionAnalyzer::ExpressionAnalyzer(std::__1::shared_ptr<DB::IAST> const&, std::__1::shared_ptr<DB::SyntaxAnalyzerResult const> const&, DB::Context const&, unsigned long, bool) @ 0xd346e65 in /usr/bin/clickhouse
4. DB::KeyCondition::getBlockWithConstants(std::__1::shared_ptr<DB::IAST> const&, std::__1::shared_ptr<DB::SyntaxAnalyzerResult const> const&, DB::Context const&) @ 0xd910f68 in /usr/bin/clickhouse
5. DB::KeyCondition::KeyCondition(DB::SelectQueryInfo const&, DB::Context const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::shared_ptr<DB::ExpressionActions> const&) @ 0xd9178a1 in /usr/bin/clickhouse
6. DB::MergeTreeDataSelectExecutor::readFromParts(std::__1::vector<std::__1::shared_ptr<DB::IMergeTreeDataPart const>, std::__1::allocator<std::__1::shared_ptr<DB::IMergeTreeDataPart const> > >, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, DB::SelectQueryInfo const&, DB::Context const&, unsigned long, unsigned int, std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, long, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, long> > > const*) const @ 0xda02303 in /usr/bin/clickhouse
7. DB::MergeTreeDataSelectExecutor::read(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, DB::SelectQueryInfo const&, DB::Context const&, unsigned long, unsigned int, std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, long, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, long> > > const*) const @ 0xda08103 in /usr/bin/clickhouse
8. DB::StorageMergeTree::read(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, DB::SelectQueryInfo const&, DB::Context const&, DB::QueryProcessingStage::Enum, unsigned long, unsigned int) @ 0xd765f45 in /usr/bin/clickhouse
9. DB::StorageMerge::createSources(DB::SelectQueryInfo const&, DB::QueryProcessingStage::Enum const&, unsigned long, DB::Block const&, std::__1::tuple<std::__1::shared_ptr<DB::IStorage>, DB::TableStructureReadLockHolder, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&, std::__1::shared_ptr<DB::Context> const&, unsigned long, bool, bool) @ 0xd75a276 in /usr/bin/clickhouse
10. DB::StorageMerge::read(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, DB::SelectQueryInfo const&, DB::Context const&, DB::QueryProcessingStage::Enum, unsigned long, unsigned int) @ 0xd75b95f in /usr/bin/clickhouse
11. void DB::InterpreterSelectQuery::executeFetchColumns<DB::QueryPipeline>(DB::QueryProcessingStage::Enum, DB::QueryPipeline&, std::__1::shared_ptr<DB::PrewhereInfo> const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, DB::QueryPipeline&) @ 0xd1ba65d in /usr/bin/clickhouse
12. void DB::InterpreterSelectQuery::executeImpl<DB::QueryPipeline>(DB::QueryPipeline&, std::__1::shared_ptr<DB::IBlockInputStream> const&, std::__1::optional<DB::Pipe>, DB::QueryPipeline&) @ 0xd1bddc7 in /usr/bin/clickhouse
13. DB::InterpreterSelectQuery::executeWithProcessors() @ 0xd180155 in /usr/bin/clickhouse
14. DB::InterpreterSelectWithUnionQuery::executeWithProcessors() @ 0xd38c8f8 in /usr/bin/clickhouse
15. ? @ 0xd59ff3a in /usr/bin/clickhouse
16. DB::executeQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::Context&, bool, DB::QueryProcessingStage::Enum, bool, bool) @ 0xd5a0a01 in /usr/bin/clickhouse
17. DB::TCPHandler::runImpl() @ 0x907b5c9 in /usr/bin/clickhouse
18. DB::TCPHandler::run() @ 0x907c5b0 in /usr/bin/clickhouse
19. Poco::Net::TCPServerConnection::start() @ 0xe402b9b in /usr/bin/clickhouse
20. Poco::Net::TCPServerDispatcher::run() @ 0xe40301d in /usr/bin/clickhouse
21. Poco::PooledThread::run() @ 0x106295c7 in /usr/bin/clickhouse
22. Poco::ThreadImpl::runnableEntry(void*) @ 0x106253cc in /usr/bin/clickhouse
23. ? @ 0x10626d6d in /usr/bin/clickhouse
24. start_thread @ 0x76db in /lib/x86_64-linux-gnu/libpthread-2.27.so
25. __clone @ 0x121a3f in /lib/x86_64-linux-gnu/libc-2.27.so


Received exception from server (version 20.3.17):
Code: 47. DB::Exception: Received from localhost:9000. DB::Exception: Unknown identifier (in GROUP BY): ID.

0 rows in set. Elapsed: 0.004 sec.

Expected behavior

Clickhouse server version 20.3.15

SELECT
    ID,
    key
FROM merge_table
INNER JOIN table_2 USING (key)

[4b6e47203a6d] 2020.09.24 10:47:41.508163 [ 248 ] {2c1bd414-7a2e-4025-ba12-aefbbb84b46c} <Debug> executeQuery: (from 172.17.0.1:52396) SELECT ID, key FROM merge_table INNER JOIN table_2 USING(key);
[4b6e47203a6d] 2020.09.24 10:47:41.508710 [ 248 ] {2c1bd414-7a2e-4025-ba12-aefbbb84b46c} <Trace> AccessRightsContext (default): Access granted: SELECT(key, ID) ON default.table_2
[4b6e47203a6d] 2020.09.24 10:47:41.508765 [ 248 ] {2c1bd414-7a2e-4025-ba12-aefbbb84b46c} <Debug> Join: setSampleBlock: table_2.key UInt32 UInt32(size = 0), ID UInt32 UInt32(size = 0)
[4b6e47203a6d] 2020.09.24 10:47:41.508943 [ 248 ] {2c1bd414-7a2e-4025-ba12-aefbbb84b46c} <Debug> default.table (SelectExecutor): Key condition: unknown
[4b6e47203a6d] 2020.09.24 10:47:41.508999 [ 248 ] {2c1bd414-7a2e-4025-ba12-aefbbb84b46c} <Debug> default.table (SelectExecutor): Selected 0 parts by date, 0 parts by key, 0 marks to read from 0 ranges
[4b6e47203a6d] 2020.09.24 10:47:41.509077 [ 248 ] {2c1bd414-7a2e-4025-ba12-aefbbb84b46c} <Debug> default.table_2 (SelectExecutor): Key condition: unknown
[4b6e47203a6d] 2020.09.24 10:47:41.509115 [ 248 ] {2c1bd414-7a2e-4025-ba12-aefbbb84b46c} <Debug> default.table_2 (SelectExecutor): Selected 0 parts by date, 0 parts by key, 0 marks to read from 0 ranges
[4b6e47203a6d] 2020.09.24 10:47:41.509166 [ 248 ] {2c1bd414-7a2e-4025-ba12-aefbbb84b46c} <Trace> InterpreterSelectQuery: FetchColumns -> Complete
[4b6e47203a6d] 2020.09.24 10:47:41.509563 [ 203 ] {2c1bd414-7a2e-4025-ba12-aefbbb84b46c} <Trace> CreatingSetsBlockInputStream: Creating join.
[4b6e47203a6d] 2020.09.24 10:47:41.509643 [ 203 ] {2c1bd414-7a2e-4025-ba12-aefbbb84b46c} <Debug> default.table_2 (SelectExecutor): Key condition: unknown
[4b6e47203a6d] 2020.09.24 10:47:41.509673 [ 203 ] {2c1bd414-7a2e-4025-ba12-aefbbb84b46c} <Debug> default.table_2 (SelectExecutor): Selected 0 parts by date, 0 parts by key, 0 marks to read from 0 ranges
[4b6e47203a6d] 2020.09.24 10:47:41.509713 [ 203 ] {2c1bd414-7a2e-4025-ba12-aefbbb84b46c} <Trace> InterpreterSelectQuery: FetchColumns -> Complete
[4b6e47203a6d] 2020.09.24 10:47:41.509791 [ 203 ] {2c1bd414-7a2e-4025-ba12-aefbbb84b46c} <Debug> CreatingSetsBlockInputStream: Subquery has empty result.
[4b6e47203a6d] 2020.09.24 10:47:41.510345 [ 248 ] {2c1bd414-7a2e-4025-ba12-aefbbb84b46c} <Information> executeQuery: Read 1 rows, 4.00 B in 0.002 sec., 478 rows/sec., 1.87 KiB/sec.
[4b6e47203a6d] 2020.09.24 10:47:41.510439 [ 248 ] {2c1bd414-7a2e-4025-ba12-aefbbb84b46c} <Debug> MemoryTracker: Peak memory usage (for query): 0.00 B.
Ok.

0 rows in set. Elapsed: 0.004 sec.

Additional context
Clickhouse server version 20.3.16 works correctly.
Clickhouse server version 20.3.18 doesn't work.
Clickhouse server version 20.9.2 doesn't work.

Metadata

Metadata

Assignees

Labels

bugConfirmed user-visible misbehaviour in official release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions