Fix StorageJoin truncate reset overwrite flag

This commit is contained in:
Amos Bird 2020-03-29 18:07:51 +08:00
parent 4003dcd12e
commit 93b7b0bd3a
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
4 changed files with 34 additions and 2 deletions

View File

@ -43,7 +43,7 @@ StorageJoin::StorageJoin(
ASTTableJoin::Strictness strictness_,
const ColumnsDescription & columns_,
const ConstraintsDescription & constraints_,
bool overwrite,
bool overwrite_,
const Context & context_)
: StorageSetOrJoinBase{relative_path_, table_id_, columns_, constraints_, context_}
, key_names(key_names_)
@ -51,6 +51,7 @@ StorageJoin::StorageJoin(
, limits(limits_)
, kind(kind_)
, strictness(strictness_)
, overwrite(overwrite_)
{
for (const auto & key : key_names)
if (!getColumns().hasPhysical(key))
@ -69,7 +70,7 @@ void StorageJoin::truncate(const ASTPtr &, const Context &, TableStructureWriteL
Poco::File(path + "tmp/").createDirectories();
increment = 0;
join = std::make_shared<Join>(table_join, getSampleBlock().sortColumns());
join = std::make_shared<Join>(table_join, getSampleBlock().sortColumns(), overwrite);
}

View File

@ -51,6 +51,7 @@ private:
SizeLimits limits;
ASTTableJoin::Kind kind; /// LEFT | INNER ...
ASTTableJoin::Strictness strictness; /// ANY | ALL
bool overwrite;
std::shared_ptr<AnalyzedJoin> table_join;
HashJoinPtr join;

View File

@ -0,0 +1,3 @@
500
1000
1000

View File

@ -0,0 +1,27 @@
DROP TABLE IF EXISTS join_test;
CREATE TABLE join_test (id UInt16, num UInt16) engine = Join(ANY, LEFT, id) settings join_any_take_last_row = 1;
INSERT INTO join_test (id, num) SELECT number, number FROM system.numbers LIMIT 1000;
SELECT joinGet('join_test', 'num', 500);
-- joinGet('join_test', 'num', 500) will be 500 and it is fine
-- replace all the values
INSERT INTO join_test (id, num) SELECT number, number * 2 FROM system.numbers LIMIT 1000;
SELECT joinGet ('join_test', 'num', 500);
-- joinGet('join_test', 'num', 500) will be 1000 and it is fine
TRUNCATE TABLE join_test;
INSERT INTO join_test (id, num) SELECT number, number FROM system.numbers LIMIT 1000;
INSERT INTO join_test (id, num) SELECT number, number * 2 FROM system.numbers LIMIT 1000;
SELECT joinGet('join_test', 'num', 500);
-- joinGet('join_test', 'num', 500) will be 1000 and it is not fine
DROP TABLE join_test;