@@ -61,19 +61,6 @@ void replaceJoinedTable(const ASTSelectQuery & select_query)
6161 }
6262}
6363
64- template <typename T>
65- void checkTablesWithColumns (const std::vector<T> & tables_with_columns, const Context & context)
66- {
67- const auto & settings = context.getSettingsRef ();
68- if (settings.joined_subquery_requires_alias && tables_with_columns.size () > 1 )
69- {
70- for (auto & t : tables_with_columns)
71- if (t.table .table .empty () && t.table .alias .empty ())
72- throw Exception (" No alias for subquery or table function in JOIN (set joined_subquery_requires_alias=0 to disable restriction)." ,
73- ErrorCodes::ALIAS_REQUIRED);
74- }
75- }
76-
7764class RenameQualifiedIdentifiersMatcher
7865{
7966public:
@@ -200,7 +187,22 @@ StoragePtr JoinedTables::getLeftTableStorage()
200187bool JoinedTables::resolveTables ()
201188{
202189 tables_with_columns = getDatabaseAndTablesWithColumns (table_expressions, context);
203- checkTablesWithColumns (tables_with_columns, context);
190+ assert (tables_with_columns.size () == table_expressions.size ());
191+
192+ const auto & settings = context.getSettingsRef ();
193+ if (settings.joined_subquery_requires_alias && tables_with_columns.size () > 1 )
194+ {
195+ for (size_t i = 0 ; i < tables_with_columns.size (); ++i)
196+ {
197+ const auto & t = tables_with_columns[i];
198+ if (t.table .table .empty () && t.table .alias .empty ())
199+ {
200+ throw Exception (" No alias for subquery or table function in JOIN (set joined_subquery_requires_alias=0 to disable restriction). While processing '"
201+ + table_expressions[i]->formatForErrorMessage () + " '" ,
202+ ErrorCodes::ALIAS_REQUIRED);
203+ }
204+ }
205+ }
204206
205207 return !tables_with_columns.empty ();
206208}
0 commit comments