ClickHouse/src/Interpreters/JoinedTables.h

60 lines
2.0 KiB
C++
Raw Normal View History

2020-02-28 15:23:32 +00:00
#pragma once
#include <Core/NamesAndTypes.h>
#include <Interpreters/DatabaseAndTableWithAlias.h>
#include <Interpreters/InterpreterSelectWithUnionQuery.h>
#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;
struct SelectQueryOptions;
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:
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
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
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
const TablesWithColumns & tablesWithColumns() const { return tables_with_columns; }
2020-03-02 19:39:39 +00:00
bool isLeftTableSubquery() const;
bool isLeftTableFunction() const;
size_t tablesCount() const { return table_expressions.size(); }
2020-03-02 19:39:39 +00:00
void rewriteDistributedInAndJoins(ASTPtr & query);
std::unique_ptr<InterpreterSelectWithUnionQuery> makeLeftTableSubquery(const SelectQueryOptions & select_options);
2020-02-28 15:23:32 +00:00
private:
ContextPtr context;
2020-03-02 19:39:39 +00:00
std::vector<const ASTTableExpression *> table_expressions;
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;
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
};
}