Skip to content

Crash with old analyzer if JOIN and duplicated aliases#96405

Merged
vdimir merged 5 commits intoClickHouse:masterfrom
ilejn:join_alias_dups
Feb 10, 2026
Merged

Crash with old analyzer if JOIN and duplicated aliases#96405
vdimir merged 5 commits intoClickHouse:masterfrom
ilejn:join_alias_dups

Conversation

@ilejn
Copy link
Copy Markdown
Contributor

@ilejn ilejn commented Feb 8, 2026

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC) or LOGICAL_ERROR

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

Fixed crash in old analyzer if JOIN and duplicated aliases

@ilejn
Copy link
Copy Markdown
Contributor Author

ilejn commented Feb 8, 2026

Query

SET enable_analyzer=0;
SELECT 1::Int8 as d, g, 42::Int32 AS g FROM ( SELECT '128' AS g );

gets
1, 42, 42

although

SET enable_analyzer=0;
SELECT A.g
FROM ( SELECT 1::Int8 AS d ) AS B
JOIN ( SELECT 1::Int8 as d, g, 42::Int32 AS g FROM ( SELECT '128' AS g ) ) AS A
USING (d);

gets
128

This fact indicates that pipeline is broken (result columns and their types cannot be different because result is estimated based on subqueries) and a very similar query causes application crash. Let me know if it is Ok to share such query in public.

In release version it is actual crash, in debug it looks like

2026.02.09 08:08:58.187795 [ 1922930 ] {} <Fatal> : Logical error: 'Bad cast from type DB::ColumnString to DB::ColumnVector<int>'.                                                                                                                            
2026.02.09 08:08:58.187810 [ 1922930 ] {} <Fatal> : Format string: 'Bad cast from type {} to {}'.                                                                                                                                                             
2026.02.09 08:08:58.319352 [ 1922930 ] {} <Fatal> : Stack trace (when copying this message, always include the lines below):                                                                                                                                  
                                                                                                                                                                                                                                                              
0. /home/ilejn/projects/ClickHouse_add_enum/contrib/llvm-project/libcxx/include/__exception/exception.h:113: Poco::Exception::Exception(String const&, int) @ 0x00000000227513b2                                                                              
1. /home/ilejn/projects/ClickHouse_add_enum/src/Common/Exception.cpp:136: DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x00000000140b9329                                                                                            
2. /home/ilejn/projects/ClickHouse_add_enum/src/Common/Exception.h:172: DB::Exception::Exception(String&&, int, String, bool) @ 0x000000000ba04a8e                                                                                                            
3. /home/ilejn/projects/ClickHouse_add_enum/src/Common/Exception.h:58: DB::Exception::Exception(PreformattedMessage&&, int) @ 0x000000000ba04551                                                                                                              
4. /home/ilejn/projects/ClickHouse_add_enum/src/Common/Exception.h:190: DB::Exception::Exception<String, String>(int, FormatStringHelperImpl<std::type_identity<String>::type, std::type_identity<String>::type>, String&&, String&&) @ 0x000000000ba02936    
5. /home/ilejn/projects/ClickHouse_add_enum/src/Common/assert_cast.h:48: DB::ColumnVector<int> const& assert_cast<DB::ColumnVector<int> const&, DB::IColumn const&>(DB::IColumn const&) @ 0x00000000126deece                                                  
6. /home/ilejn/projects/ClickHouse_add_enum/src/DataTypes/Serializations/SerializationNumber.cpp:21: DB::SerializationNumber<int>::serializeText(DB::IColumn const&, unsigned long, DB::WriteBuffer&, DB::FormatSettings const&) const @ 0x0000000018ef6452   
7. /home/ilejn/projects/ClickHouse_add_enum/src/Processors/Formats/Impl/PrettyBlockOutputFormat.cpp:89: DB::PrettyBlockOutputFormat::calculateWidths(DB::Block const&, DB::Chunk const&, bool, bool&, std::vector<DB::PODArray<unsigned long, 4096ul, Allocato
r<false, false>, 0ul, 0ul>, std::allocator<DB::PODArray<unsigned long, 4096ul, Allocator<false, false>, 0ul, 0ul>>>&, DB::PODArray<unsigned long, 4096ul, Allocator<false, false>, 0ul, 0ul>&, DB::PODArray<unsigned long, 4096ul, Allocator<false, false>, 0u
l, 0ul>&, std::vector<String, std::allocator<String>>&) @ 0x000000001d97d9ab                                                                                                                                                                                  
8. /home/ilejn/projects/ClickHouse_add_enum/src/Processors/Formats/Impl/PrettyBlockOutputFormat.cpp:221: DB::PrettyBlockOutputFormat::writeChunk(DB::Chunk const&, DB::IOutputFormat::PortKind) @ 0x000000001d97e956                                          
9. /home/ilejn/projects/ClickHouse_add_enum/src/Processors/Formats/Impl/PrettyBlockOutputFormat.cpp:763: DB::PrettyBlockOutputFormat::writeMonoChunkIfNeeded() @ 0x000000001d97e70b                                                                           
10. /home/ilejn/projects/ClickHouse_add_enum/src/Processors/Formats/Impl/PrettyBlockOutputFormat.cpp:789: DB::PrettyBlockOutputFormat::writeSuffix() @ 0x000000001d982929                                                                                     
11. /home/ilejn/projects/ClickHouse_add_enum/src/Processors/Formats/IOutputFormat.h:124: DB::IOutputFormat::finalize() @ 0x000000001d7c6582                                                                                                                   
12. /home/ilejn/projects/ClickHouse_add_enum/src/Client/ClientBase.cpp:1562: DB::ClientBase::onEndOfStream() @ 0x000000001d4cedc9                                                                                                                             
13. /home/ilejn/projects/ClickHouse_add_enum/src/Client/ClientBase.cpp:1491: DB::ClientBase::receiveAndProcessPacket(boost::intrusive_ptr<DB::IAST>, bool) @ 0x000000001d4ce8b3                                                                               
14. /home/ilejn/projects/ClickHouse_add_enum/src/Client/ClientBase.cpp:1427: DB::ClientBase::receiveResult(boost::intrusive_ptr<DB::IAST>, int, bool) @ 0x000000001d4ce0af                                                                                    
15. /home/ilejn/projects/ClickHouse_add_enum/src/Client/ClientBase.cpp:1330: DB::ClientBase::processOrdinaryQuery(String, boost::intrusive_ptr<DB::IAST>) @ 0x000000001d4ccbd8                                                                                
16. /home/ilejn/projects/ClickHouse_add_enum/src/Client/ClientBase.cpp:2382: DB::ClientBase::processParsedSingleQuery(std::basic_string_view<char, std::char_traits<char>>, boost::intrusive_ptr<DB::IAST>, bool&, unsigned long) @ 0x000000001d4cad6e        
17. /home/ilejn/projects/ClickHouse_add_enum/src/Client/ClientBase.cpp:2759: DB::ClientBase::executeMultiQuery(String const&) @ 0x000000001d4d6a23                                                                                                            
18. /home/ilejn/projects/ClickHouse_add_enum/src/Client/ClientBase.cpp:3000: DB::ClientBase::processQueryText(String const&) @ 0x000000001d4d7b8a                                                                                                             
19. /home/ilejn/projects/ClickHouse_add_enum/src/Client/ClientBase.cpp:3716: DB::ClientBase::runInteractive() @ 0x000000001d4e160b                                                                                                                            
20. /home/ilejn/projects/ClickHouse_add_enum/programs/local/LocalServer.cpp:0: DB::LocalServer::main(std::vector<String, std::allocator<String>> const&) @ 0x00000000143a434a                                                                                 

@ilejn ilejn marked this pull request as ready for review February 9, 2026 10:41
@ilejn
Copy link
Copy Markdown
Contributor Author

ilejn commented Feb 9, 2026

If I am right that editing PR titles is prohibited (why?),
please fix typo in title 'aliased' => 'aliases'.

@vdimir vdimir added the can be tested Allows running workflows for external contributors label Feb 9, 2026
@vdimir vdimir changed the title Crash with old analyzer if JOIN and duplicated aliased Crash with old analyzer if JOIN and duplicated aliases Feb 9, 2026
@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Feb 9, 2026

Workflow [PR], commit [164d3ed]

Summary:

job_name test_name status info comment
Integration tests (amd_tsan, 3/6) failure
test_ttl_move/test.py::TestCancelBackgroundMoving::test_cancel_background_moving_on_stop_moves_query FAIL cidb, issue ISSUE EXISTS

@clickhouse-gh clickhouse-gh bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Feb 9, 2026
Copy link
Copy Markdown
Member

@vdimir vdimir left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Let me know if it is Ok to share such query in public.

That is okay, you may add it as a test case if you want.

I'm not quite sure if we can back-port the change since the old analyzer is deprecated. If this fix is crucial for you, could you share what prevents you from migrating to the new one? Are there any particular issues?

@vdimir vdimir self-assigned this Feb 9, 2026
@ilejn
Copy link
Copy Markdown
Contributor Author

ilejn commented Feb 9, 2026

That is okay, you may add it as a test case if you want.

https://fiddle.clickhouse.com/19146386-c660-45be-b2bf-89512d07568e

I'm not quite sure if we can back-port the change since the old analyzer is deprecated.

It is deprecated, though it is available for customers of public clouds, so technically it is a CVE.

If this fix is crucial for you, could you share what prevents you from migrating to the new one? Are there any particular issues?

The reasons vary from a customer to another.
Usually some queries run faster with old analyzer.

@ilejn
Copy link
Copy Markdown
Contributor Author

ilejn commented Feb 10, 2026

Integration test failure

File: test_ttl_move/test.py:1888 - in test_cancel_background_moving_on_stop_moves_query
    assert_logs_contain_with_retry(
File: helpers/test_tools.py:138 - in assert_logs_contain_with_retry
    raise AssertionError("'{}' not found in logs".format(substring))
E   AssertionError: 'MergeTreeBackgroundExecutor.*Cancelled moving parts' not found in logs

does not seem related.

@vdimir vdimir added this pull request to the merge queue Feb 10, 2026
Merged via the queue into ClickHouse:master with commit f9e36b0 Feb 10, 2026
132 of 134 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 10, 2026
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Feb 10, 2026
robot-ch-test-poll4 added a commit that referenced this pull request Feb 10, 2026
Cherry pick #96405 to 25.3: Crash with old analyzer if JOIN and duplicated aliases
robot-ch-test-poll4 added a commit that referenced this pull request Feb 10, 2026
Cherry pick #96405 to 25.8: Crash with old analyzer if JOIN and duplicated aliases
robot-ch-test-poll4 added a commit that referenced this pull request Feb 10, 2026
Cherry pick #96405 to 25.11: Crash with old analyzer if JOIN and duplicated aliases
robot-clickhouse added a commit that referenced this pull request Feb 10, 2026
robot-ch-test-poll4 added a commit that referenced this pull request Feb 10, 2026
Cherry pick #96405 to 25.12: Crash with old analyzer if JOIN and duplicated aliases
robot-clickhouse added a commit that referenced this pull request Feb 10, 2026
robot-ch-test-poll4 added a commit that referenced this pull request Feb 10, 2026
Cherry pick #96405 to 26.1: Crash with old analyzer if JOIN and duplicated aliases
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Feb 10, 2026
clickhouse-gh bot added a commit that referenced this pull request Feb 10, 2026
Backport #96405 to 25.8: Crash with old analyzer if JOIN and duplicated aliases
vdimir added a commit that referenced this pull request Feb 11, 2026
Backport #96405 to 26.1: Crash with old analyzer if JOIN and duplicated aliases
zvonand pushed a commit to Altinity/ClickHouse that referenced this pull request Feb 13, 2026
Crash with old analyzer if JOIN and duplicated aliases
zvonand added a commit to Altinity/ClickHouse that referenced this pull request Feb 14, 2026
…14/96405

24.8.14 Stable backport of ClickHouse#96405: Crash with old analyzer if JOIN and duplicated aliases
zvonand pushed a commit to Altinity/ClickHouse that referenced this pull request Feb 18, 2026
Crash with old analyzer if JOIN and duplicated aliases
vdimir added a commit that referenced this pull request Mar 16, 2026
Backport #96405 to 25.12: Crash with old analyzer if JOIN and duplicated aliases
@vdimir vdimir added the post-approved Approved, but after the PR is merged. label Mar 16, 2026
zvonand pushed a commit to Altinity/ClickHouse that referenced this pull request Mar 17, 2026
Crash with old analyzer if JOIN and duplicated aliases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors post-approved Approved, but after the PR is merged. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

7 participants