2020-02-28 15:23:32 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Core/NamesAndTypes.h>
|
|
|
|
#include <Interpreters/DatabaseAndTableWithAlias.h>
|
2020-03-08 11:07:05 +00:00
|
|
|
#include <Interpreters/InterpreterSelectWithUnionQuery.h>
|
2020-05-20 20:16:32 +00:00
|
|
|
#include <Interpreters/Context.h>
|
|
|
|
#include <Interpreters/StorageID.h>
|
2020-02-28 15:23:32 +00:00
|
|
|
#include <Storages/IStorage_fwd.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class ASTSelectQuery;
|
2020-04-08 18:59:52 +00:00
|
|
|
class TableJoin;
|
2020-03-08 11:07:05 +00:00
|
|
|
struct SelectQueryOptions;
|
2020-06-17 16:39:58 +00:00
|
|
|
struct StorageInMemoryMetadata;
|
2020-06-18 11:02:31 +00:00
|
|
|
using StorageMetadataPtr = std::shared_ptr<const StorageInMemoryMetadata>;
|
2020-02-28 15:23:32 +00:00
|
|
|
|
|
|
|
/// Joined tables' columns resolver.
|
2020-08-08 01:01:47 +00:00
|
|
|
/// We want to get each table structure at most once per table occurrence. Or even better once per table.
|
2020-02-28 15:23:32 +00:00
|
|
|
/// TODO: joins tree with costs to change joins order by CBO.
|
|
|
|
class JoinedTables
|
|
|
|
{
|
|
|
|
public:
|
2023-03-19 18:41:19 +00:00
|
|
|
JoinedTables(ContextPtr context, const ASTSelectQuery & select_query_, bool include_all_columns_ = false, bool is_create_parameterized_view_ = false);
|
2020-02-28 15:23:32 +00:00
|
|
|
|
2021-07-08 10:49:13 +00:00
|
|
|
void reset(const ASTSelectQuery & select_query);
|
2020-03-02 19:39:39 +00:00
|
|
|
|
2020-03-08 11:07:05 +00:00
|
|
|
StoragePtr getLeftTableStorage();
|
2021-07-08 10:49:13 +00:00
|
|
|
bool resolveTables();
|
2020-04-14 14:43:09 +00:00
|
|
|
|
|
|
|
/// Make fake tables_with_columns[0] in case we have predefined input in InterpreterSelectQuery
|
2020-06-17 16:39:58 +00:00
|
|
|
void makeFakeTable(StoragePtr storage, const StorageMetadataPtr & metadata_snapshot, const Block & source_header);
|
2020-04-08 18:59:52 +00:00
|
|
|
std::shared_ptr<TableJoin> makeTableJoin(const ASTSelectQuery & select_query);
|
2020-03-02 19:39:39 +00:00
|
|
|
|
2020-06-15 12:36:10 +00:00
|
|
|
const TablesWithColumns & tablesWithColumns() const { return tables_with_columns; }
|
2020-03-02 19:39:39 +00:00
|
|
|
|
|
|
|
bool isLeftTableSubquery() const;
|
|
|
|
bool isLeftTableFunction() const;
|
2020-03-08 11:07:05 +00:00
|
|
|
size_t tablesCount() const { return table_expressions.size(); }
|
2020-03-02 19:39:39 +00:00
|
|
|
|
2020-03-27 20:12:14 +00:00
|
|
|
void rewriteDistributedInAndJoins(ASTPtr & query);
|
|
|
|
|
2020-03-08 11:07:05 +00:00
|
|
|
std::unique_ptr<InterpreterSelectWithUnionQuery> makeLeftTableSubquery(const SelectQueryOptions & select_options);
|
|
|
|
|
2020-02-28 15:23:32 +00:00
|
|
|
private:
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context;
|
2020-03-02 19:39:39 +00:00
|
|
|
std::vector<const ASTTableExpression *> table_expressions;
|
2020-06-15 12:36:10 +00:00
|
|
|
TablesWithColumns tables_with_columns;
|
2021-07-08 10:49:13 +00:00
|
|
|
const bool include_all_columns;
|
2020-03-02 19:39:39 +00:00
|
|
|
|
|
|
|
/// Legacy (duplicated left table values)
|
|
|
|
ASTPtr left_table_expression;
|
|
|
|
std::optional<DatabaseAndTableWithAlias> left_db_and_table;
|
2022-10-14 15:09:35 +00:00
|
|
|
const ASTSelectQuery & select_query;
|
2023-03-21 17:29:26 +00:00
|
|
|
const bool is_create_parameterized_view;
|
2020-02-28 15:23:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|