ClickHouse/dbms/Interpreters/JoinedTables.h

58 lines
1.7 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>
2020-02-28 15:23:32 +00:00
#include <Storages/IStorage_fwd.h>
namespace DB
{
class ASTSelectQuery;
class Context;
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();
void makeFakeTable(StoragePtr storage, const Block & source_header);
2020-03-02 19:39:39 +00:00
const std::vector<TableWithColumnNamesAndTypes> & tablesWithColumns() const { return tables_with_columns; }
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;
std::vector<TableWithColumnNamesAndTypes> tables_with_columns;
/// 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
};
}