ClickHouse/src/Interpreters/JoinedTables.h

64 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;
2020-02-28 15:23:32 +00:00
/// Joined tables' columns resolver.
/// We want to get each table structure at most once per table occurance. Or even better once per table.
/// TODO: joins tree with costs to change joins order by CBO.
class JoinedTables
{
public:
JoinedTables(Context && contex, const ASTSelectQuery & select_query);
2020-02-28 15:23:32 +00:00
2020-03-02 19:39:39 +00:00
void reset(const ASTSelectQuery & select_query)
{
*this = JoinedTables(std::move(context), select_query);
2020-03-02 19:39:39 +00:00
}
StoragePtr getLeftTableStorage();
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 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; }
TablesWithColumns moveTablesWithColumns() { return std::move(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
2020-03-12 12:16:16 +00:00
const StorageID & leftTableID() const { return table_id; }
2020-02-28 15:23:32 +00:00
void rewriteDistributedInAndJoins(ASTPtr & query);
std::unique_ptr<InterpreterSelectWithUnionQuery> makeLeftTableSubquery(const SelectQueryOptions & select_options);
2020-02-28 15:23:32 +00:00
private:
Context context;
2020-03-02 19:39:39 +00:00
std::vector<const ASTTableExpression *> table_expressions;
TablesWithColumns tables_with_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;
/// left_db_and_table or 'system.one'
2020-03-12 12:16:16 +00:00
StorageID table_id = StorageID::createEmpty();
2020-02-28 15:23:32 +00:00
};
}