[Bug](filter) fix not in(null) return true (#15466)

fix not in(null) return true
This commit is contained in:
Pxl
2023-01-03 21:14:50 +08:00
committed by GitHub
parent 4380f1ec54
commit 85fe9d2496
4 changed files with 25 additions and 12 deletions

View File

@ -797,6 +797,9 @@ Status VScanNode::_normalize_not_in_and_not_eq_predicate(VExpr* expr, VExprConte
->get_function_state(FunctionContext::FRAGMENT_LOCAL));
HybridSetBase::IteratorBase* iter = state->hybrid_set->begin();
auto fn_name = std::string("");
if (!is_fixed_range && state->null_in_set) {
_eos = true;
}
while (iter->has_next()) {
// column not in (nullptr) is always true
if (nullptr == iter->get_value()) {

View File

@ -23,6 +23,7 @@
#include "exprs/create_predicate_function.h"
#include "vec/columns/column_nullable.h"
#include "vec/columns/columns_number.h"
#include "vec/data_types/data_type.h"
#include "vec/data_types/data_type_nullable.h"
#include "vec/data_types/data_type_number.h"
#include "vec/functions/function.h"
@ -108,7 +109,7 @@ public:
vec_res.resize(input_rows_count);
ColumnUInt8::MutablePtr col_null_map_to;
col_null_map_to = ColumnUInt8::create(input_rows_count);
col_null_map_to = ColumnUInt8::create(input_rows_count, false);
auto& vec_null_map_to = col_null_map_to->get_data();
/// First argument may be a single column.
@ -150,11 +151,12 @@ public:
}
} else {
for (size_t i = 0; i < input_rows_count; ++i) {
vec_null_map_to[i] = null_bitmap[i] || (negative == vec_res[i]);
vec_null_map_to[i] = null_bitmap[i] || negative == vec_res[i];
}
}
} else { // non-nullable
DCHECK(!in_state->null_in_set);
auto search_hash_set = [&](auto* col_ptr) {
for (size_t i = 0; i < input_rows_count; ++i) {
@ -175,16 +177,6 @@ public:
} else {
search_hash_set(materialized_column.get());
}
if (in_state->null_in_set) {
for (size_t i = 0; i < input_rows_count; ++i) {
vec_null_map_to[i] = negative == vec_res[i];
}
} else {
for (size_t i = 0; i < input_rows_count; ++i) {
vec_null_map_to[i] = false;
}
}
}
} else {
std::vector<ColumnPtr> set_columns;

View File

@ -5,6 +5,16 @@
-- !select --
4
-- !select --
-- !select --
103 4 d
-- !select --
103 4 d
-- !select --
-- !select --
c

View File

@ -65,6 +65,14 @@ suite("test_in_expr", "query") {
// 1.1.2 string + null_in_set
qt_select "select t1.number from ${nullTableName} t1 left join ${nullTableName} t2 on t1.cid=t2.cid where t2.addr in ('d', null)"
qt_select "select * from ${nullTableName} where addr not in ('d', null)"
qt_select "select * from ${nullTableName} where not(addr not in ('d', null))"
qt_select "select * from ${nullTableName} where addr in ('d', null)"
qt_select "select * from ${nullTableName} where not(addr in ('d', null))"
// 1.1.3 non-string
qt_select "select t1.addr from ${nullTableName} t1 left join ${nullTableName} t2 on t1.cid=t2.cid where t2.number in (3)"