diff --git a/src/Interpreters/Set.cpp b/src/Interpreters/Set.cpp index 54992eeff2c..a4fea5dd705 100644 --- a/src/Interpreters/Set.cpp +++ b/src/Interpreters/Set.cpp @@ -87,10 +87,7 @@ void NO_INLINE Set::insertFromBlockImplCase( { if ((*null_map)[i]) { - if (transform_null_in) - { - has_null = true; - } + has_null = true; if constexpr (build_filter) { @@ -397,7 +394,7 @@ void NO_INLINE Set::executeImplCase( { if (has_null_map && (*null_map)[i]) { - if (has_null) + if (transform_null_in && has_null) vec_res[i] = !negative; else vec_res[i] = negative; diff --git a/src/Storages/StorageSet.cpp b/src/Storages/StorageSet.cpp index 7d2a7ee128f..79f5198b304 100644 --- a/src/Storages/StorageSet.cpp +++ b/src/Storages/StorageSet.cpp @@ -112,7 +112,7 @@ StorageSet::StorageSet( const ConstraintsDescription & constraints_, const Context & context_) : StorageSetOrJoinBase{relative_path_, table_id_, columns_, constraints_, context_}, - set(std::make_shared(SizeLimits(), false, context_.getSettingsRef().transform_null_in)) + set(std::make_shared(SizeLimits(), false, true)) { Block header = getSampleBlock(); header = header.sortColumns(); @@ -127,7 +127,7 @@ void StorageSet::finishInsert() { set->finishInsert(); } size_t StorageSet::getSize() const { return set->getTotalRowCount(); } -void StorageSet::truncate(const ASTPtr &, const Context & context, TableStructureWriteLockHolder &) +void StorageSet::truncate(const ASTPtr &, const Context &, TableStructureWriteLockHolder &) { Poco::File(path).remove(true); Poco::File(path).createDirectories(); @@ -137,7 +137,7 @@ void StorageSet::truncate(const ASTPtr &, const Context & context, TableStructur header = header.sortColumns(); increment = 0; - set = std::make_shared(SizeLimits(), false, context.getSettingsRef().transform_null_in); + set = std::make_shared(SizeLimits(), false, true); set->setHeader(header); } diff --git a/tests/queries/0_stateless/01231_operator_null_in.reference b/tests/queries/0_stateless/01231_operator_null_in.reference index 5cd5e5ee5fb..b76f42e9af4 100644 --- a/tests/queries/0_stateless/01231_operator_null_in.reference +++ b/tests/queries/0_stateless/01231_operator_null_in.reference @@ -62,3 +62,19 @@ 1 1 1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 diff --git a/tests/queries/0_stateless/01231_operator_null_in.sql b/tests/queries/0_stateless/01231_operator_null_in.sql index 3c4333c8ea6..ddebaf23900 100644 --- a/tests/queries/0_stateless/01231_operator_null_in.sql +++ b/tests/queries/0_stateless/01231_operator_null_in.sql @@ -40,8 +40,46 @@ SELECT count() == 3 FROM null_in WHERE i global not in (1, 3); SELECT count() == 3 FROM null_in WHERE i global not in range(4); SELECT count() == 3 FROM null_in WHERE s global not in ('1', '3'); +DROP TABLE IF EXISTS test_set; +CREATE TABLE test_set (i Nullable(int)) ENGINE = Set(); +INSERT INTO test_set VALUES (1), (NULL); + +SET transform_null_in = 0; + +SELECT count() == 1 FROM null_in WHERE i in test_set; +SELECT count() == 2 FROM null_in WHERE i not in test_set; +SELECT count() == 1 FROM null_in WHERE i global in test_set; +SELECT count() == 2 FROM null_in WHERE i global not in test_set; + +SET transform_null_in = 1; + +SELECT count() == 3 FROM null_in WHERE i in test_set; +SELECT count() == 2 FROM null_in WHERE i not in test_set; +SELECT count() == 3 FROM null_in WHERE i global in test_set; +SELECT count() == 2 FROM null_in WHERE i global not in test_set; + +-- Create with transform_null_in +CREATE TABLE test_set2 (i Nullable(int)) ENGINE = Set(); +INSERT INTO test_set2 VALUES (1), (NULL); + +SET transform_null_in = 0; + +SELECT count() == 1 FROM null_in WHERE i in test_set2; +SELECT count() == 2 FROM null_in WHERE i not in test_set2; +SELECT count() == 1 FROM null_in WHERE i global in test_set2; +SELECT count() == 2 FROM null_in WHERE i global not in test_set2; + +SET transform_null_in = 1; + +SELECT count() == 3 FROM null_in WHERE i in test_set2; +SELECT count() == 2 FROM null_in WHERE i not in test_set2; +SELECT count() == 3 FROM null_in WHERE i global in test_set2; +SELECT count() == 2 FROM null_in WHERE i global not in test_set2; + +DROP TABLE IF EXISTS test_set; DROP TABLE IF EXISTS null_in; + DROP TABLE IF EXISTS null_in_subquery; CREATE TABLE null_in_subquery (dt DateTime, idx int, i Nullable(UInt64)) ENGINE = MergeTree() PARTITION BY dt ORDER BY idx; INSERT INTO null_in_subquery SELECT number % 3, number, number FROM system.numbers LIMIT 99999;