2015-01-27 21:24:24 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-06-06 17:18:32 +00:00
|
|
|
#include <ext/shared_ptr_helper.h>
|
2016-08-26 21:25:05 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Storages/StorageSet.h>
|
|
|
|
#include <Parsers/ASTTablesInSelectQuery.h>
|
2015-01-27 21:24:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2019-09-09 19:43:37 +00:00
|
|
|
class AnalyzedJoin;
|
2017-01-14 09:00:19 +00:00
|
|
|
class Join;
|
2019-09-09 19:43:37 +00:00
|
|
|
using HashJoinPtr = std::shared_ptr<Join>;
|
2017-01-14 09:00:19 +00:00
|
|
|
|
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/** Allows you save the state for later use on the right side of the JOIN.
|
|
|
|
* When inserted into a table, the data will be inserted into the state,
|
|
|
|
* and also written to the backup file, to restore after the restart.
|
|
|
|
* Reading from the table is not possible directly - only specifying on the right side of JOIN is possible.
|
2015-01-28 00:38:10 +00:00
|
|
|
*
|
2017-04-16 15:00:33 +00:00
|
|
|
* When using, JOIN must be of the appropriate type (ANY|ALL LEFT|INNER ...).
|
2015-01-27 21:24:24 +00:00
|
|
|
*/
|
2017-06-06 18:36:13 +00:00
|
|
|
class StorageJoin : public ext::shared_ptr_helper<StorageJoin>, public StorageSetOrJoinBase
|
2015-01-27 21:24:24 +00:00
|
|
|
{
|
2019-08-26 19:07:29 +00:00
|
|
|
friend struct ext::shared_ptr_helper<StorageJoin>;
|
2015-01-27 21:24:24 +00:00
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
String getName() const override { return "Join"; }
|
|
|
|
|
2019-08-27 20:43:08 +00:00
|
|
|
void truncate(const ASTPtr &, const Context &, TableStructureWriteLockHolder &) override;
|
2018-06-09 16:09:37 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// Access the innards.
|
2019-09-09 19:43:37 +00:00
|
|
|
HashJoinPtr & getJoin() { return join; }
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// Verify that the data structure is suitable for implementing this type of JOIN.
|
2017-04-01 07:20:54 +00:00
|
|
|
void assertCompatible(ASTTableJoin::Kind kind_, ASTTableJoin::Strictness strictness_) const;
|
2015-01-28 02:37:05 +00:00
|
|
|
|
2018-11-30 14:49:35 +00:00
|
|
|
BlockInputStreams read(
|
|
|
|
const Names & column_names,
|
|
|
|
const SelectQueryInfo & query_info,
|
|
|
|
const Context & context,
|
|
|
|
QueryProcessingStage::Enum processed_stage,
|
2019-02-18 23:38:44 +00:00
|
|
|
size_t max_block_size,
|
2018-11-30 14:49:35 +00:00
|
|
|
unsigned num_streams) override;
|
|
|
|
|
2015-01-27 21:24:24 +00:00
|
|
|
private:
|
2018-11-30 14:49:35 +00:00
|
|
|
Block sample_block;
|
2019-05-28 06:12:20 +00:00
|
|
|
const Names key_names;
|
2018-11-30 14:49:35 +00:00
|
|
|
bool use_nulls;
|
|
|
|
SizeLimits limits;
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTTableJoin::Kind kind; /// LEFT | INNER ...
|
|
|
|
ASTTableJoin::Strictness strictness; /// ANY | ALL
|
|
|
|
|
2019-09-09 19:43:37 +00:00
|
|
|
std::shared_ptr<AnalyzedJoin> table_join;
|
|
|
|
HashJoinPtr join;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-11-03 21:50:22 +00:00
|
|
|
void insertBlock(const Block & block) override;
|
|
|
|
size_t getSize() const override;
|
|
|
|
|
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
StorageJoin(
|
|
|
|
const String & path_,
|
2019-07-09 15:40:21 +00:00
|
|
|
const String & database_name_,
|
|
|
|
const String & table_name_,
|
2017-04-01 07:20:54 +00:00
|
|
|
const Names & key_names_,
|
2018-11-30 14:49:35 +00:00
|
|
|
bool use_nulls_,
|
|
|
|
SizeLimits limits_,
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTTableJoin::Kind kind_, ASTTableJoin::Strictness strictness_,
|
2018-12-30 15:54:45 +00:00
|
|
|
const ColumnsDescription & columns_,
|
2019-08-24 21:20:20 +00:00
|
|
|
const ConstraintsDescription & constraints_,
|
2018-12-30 15:54:45 +00:00
|
|
|
bool overwrite);
|
2015-01-27 21:24:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|