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>
|
2020-09-15 09:16:10 +00:00
|
|
|
#include <Storages/JoinSettings.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ASTTablesInSelectQuery.h>
|
2015-01-27 21:24:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2020-04-07 09:48:47 +00:00
|
|
|
class TableJoin;
|
|
|
|
class HashJoin;
|
|
|
|
using HashJoinPtr = std::shared_ptr<HashJoin>;
|
2017-01-14 09:00:19 +00:00
|
|
|
|
2021-02-20 15:00:59 +00:00
|
|
|
class HashJoinHolder
|
|
|
|
{
|
|
|
|
std::shared_lock<std::shared_mutex> lock;
|
|
|
|
public:
|
|
|
|
HashJoinPtr join;
|
|
|
|
|
|
|
|
HashJoinHolder(std::shared_mutex & rwlock, HashJoinPtr join_)
|
|
|
|
: lock(rwlock)
|
|
|
|
, join(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
|
|
|
*/
|
2020-03-19 23:48:53 +00:00
|
|
|
class StorageJoin final : 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"; }
|
|
|
|
|
2020-06-18 16:10:47 +00:00
|
|
|
void truncate(const ASTPtr &, const StorageMetadataPtr & metadata_snapshot, const Context &, TableExclusiveLockHolder &) override;
|
2018-06-09 16:09:37 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// Access the innards.
|
2021-02-20 15:00:59 +00:00
|
|
|
std::shared_ptr<HashJoinHolder> getJoin() { return std::make_shared<HashJoinHolder>(rwlock, join); }
|
2020-04-07 09:48:47 +00:00
|
|
|
HashJoinPtr getJoin(std::shared_ptr<TableJoin> analyzed_join) const;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-08-03 13:54:14 +00:00
|
|
|
Pipe read(
|
2018-11-30 14:49:35 +00:00
|
|
|
const Names & column_names,
|
2020-06-15 19:08:58 +00:00
|
|
|
const StorageMetadataPtr & /*metadata_snapshot*/,
|
2020-09-20 17:52:17 +00:00
|
|
|
SelectQueryInfo & query_info,
|
2018-11-30 14:49:35 +00:00
|
|
|
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;
|
|
|
|
|
2020-11-25 13:47:32 +00:00
|
|
|
std::optional<UInt64> totalRows(const Settings & settings) const override;
|
|
|
|
std::optional<UInt64> totalBytes(const Settings & settings) const override;
|
2020-10-23 18:11:55 +00:00
|
|
|
|
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
|
2020-03-29 10:07:51 +00:00
|
|
|
bool overwrite;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-04-07 09:48:47 +00:00
|
|
|
std::shared_ptr<TableJoin> table_join;
|
2019-09-09 19:43:37 +00:00
|
|
|
HashJoinPtr join;
|
2021-02-20 15:00:59 +00:00
|
|
|
mutable std::shared_mutex rwlock;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-11-03 21:50:22 +00:00
|
|
|
void insertBlock(const Block & block) override;
|
2019-11-01 11:03:35 +00:00
|
|
|
void finishInsert() override {}
|
2017-11-03 21:50:22 +00:00
|
|
|
size_t getSize() const override;
|
|
|
|
|
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
StorageJoin(
|
2020-12-15 16:45:13 +00:00
|
|
|
DiskPtr disk_,
|
2019-10-25 19:07:47 +00:00
|
|
|
const String & relative_path_,
|
2019-12-04 16:06:55 +00:00
|
|
|
const StorageID & table_id_,
|
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_,
|
2019-10-25 19:07:47 +00:00
|
|
|
bool overwrite,
|
2020-09-18 12:58:27 +00:00
|
|
|
bool persistent_);
|
2015-01-27 21:24:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|