| 214 | } |
| 215 | |
| 216 | StoragePtr JoinedTables::getLeftTableStorage() |
| 217 | { |
| 218 | if (isLeftTableSubquery()) |
| 219 | return {}; |
| 220 | |
| 221 | if (isLeftTableFunction()) |
| 222 | { |
| 223 | /// For parameterized views in refreshable materialized views, use the current context's database |
| 224 | /// instead of the query context's database. This ensures unqualified parameterized view |
| 225 | /// references resolve in the correct database (MV's database, not session's database). |
| 226 | auto table_function_context = context->getQueryContext(); |
| 227 | if (is_create_parameterized_view) |
| 228 | { |
| 229 | /// Temporarily set the current database to match the context we're analyzing in |
| 230 | table_function_context = Context::createCopy(table_function_context); |
| 231 | table_function_context->setCurrentDatabase(context->getCurrentDatabase()); |
| 232 | } |
| 233 | return table_function_context->executeTableFunction(left_table_expression, &select_query); |
| 234 | } |
| 235 | |
| 236 | StorageID table_id = StorageID::createEmpty(); |
| 237 | if (left_db_and_table) |
| 238 | { |
| 239 | table_id = context->resolveStorageID(StorageID(left_db_and_table->database, left_db_and_table->table, left_db_and_table->uuid)); |
| 240 | } |
| 241 | else /// If the table is not specified - use the table `system.one`. |
| 242 | { |
| 243 | table_id = StorageID("system", "one"); |
| 244 | } |
| 245 | |
| 246 | if (auto view_source = context->getViewSource()) |
| 247 | { |
| 248 | const auto & storage_values = static_cast<const StorageValues &>(*view_source); |
| 249 | auto tmp_table_id = storage_values.getStorageID(); |
| 250 | if (tmp_table_id.database_name == table_id.database_name && tmp_table_id.table_name == table_id.table_name) |
| 251 | { |
| 252 | /// Read from view source. |
| 253 | return context->getViewSource(); |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | /// Read from table. Even without table expression (implicit SELECT ... FROM system.one). |
| 258 | return DatabaseCatalog::instance().getTable(table_id, context); |
| 259 | } |
| 260 | |
| 261 | bool JoinedTables::resolveTables() |
| 262 | { |
no test coverage detected