This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.1 by this push:
new 9e2aae70135 branch-4.1: [fix](function) Preserve NULL rows in IP range
index results #68051 (#68421)
9e2aae70135 is described below
commit 9e2aae70135756cddca7746dce11b91630d0fa23
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Thu Sep 24 09:25:59 2026 +0800
branch-4.1: [fix](function) Preserve NULL rows in IP range index results
#68051 (#68421)
Cherry-picked from #68051
Co-authored-by: Mryange <[email protected]>
---
be/src/exprs/function/function_ip.h | 9 ++++
.../inverted_index_p0/test_ip_cidr_not_null.out | 9 ++++
.../inverted_index_p0/test_ip_cidr_not_null.groovy | 63 ++++++++++++++++++++++
3 files changed, 81 insertions(+)
diff --git a/be/src/exprs/function/function_ip.h
b/be/src/exprs/function/function_ip.h
index 2dba40459e6..f17d414e955 100644
--- a/be/src/exprs/function/function_ip.h
+++ b/be/src/exprs/function/function_ip.h
@@ -708,6 +708,8 @@ public:
}
// apply for inverted index
std::shared_ptr<roaring::Roaring> null_bitmap =
std::make_shared<roaring::Roaring>();
+ bool has_null = DORIS_TRY(iter->has_null());
+ segment_v2::InvertedIndexQueryCacheHandle null_bitmap_cache_handle;
// >= min ip
segment_v2::InvertedIndexParam min_param;
@@ -717,7 +719,14 @@ public:
min_param.query_value = min_ip;
min_param.num_rows = num_rows;
min_param.roaring = std::make_shared<roaring::Roaring>();
+ if (has_null) {
+ // Fetch the NULL bitmap together with the first range query to
reuse its index reader.
+ min_param.null_bitmap_cache_handle = &null_bitmap_cache_handle;
+ }
RETURN_IF_ERROR(iter->read_from_index(&min_param));
+ if (has_null) {
+ null_bitmap = null_bitmap_cache_handle.get_bitmap();
+ }
// <= max ip
segment_v2::InvertedIndexParam max_param;
diff --git a/regression-test/data/inverted_index_p0/test_ip_cidr_not_null.out
b/regression-test/data/inverted_index_p0/test_ip_cidr_not_null.out
new file mode 100644
index 00000000000..66457fb92b2
--- /dev/null
+++ b/regression-test/data/inverted_index_p0/test_ip_cidr_not_null.out
@@ -0,0 +1,9 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !sql_without_inverted_index --
+3
+
+-- !sql_with_inverted_index --
+3
+
+-- !sql_with_inverted_index_repeat --
+3
diff --git
a/regression-test/suites/inverted_index_p0/test_ip_cidr_not_null.groovy
b/regression-test/suites/inverted_index_p0/test_ip_cidr_not_null.groovy
new file mode 100644
index 00000000000..d45186bf37f
--- /dev/null
+++ b/regression-test/suites/inverted_index_p0/test_ip_cidr_not_null.groovy
@@ -0,0 +1,63 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_ip_cidr_not_null", "nonConcurrent") {
+ sql "DROP TABLE IF EXISTS test_ip_cidr_not_null"
+ sql """
+ CREATE TABLE test_ip_cidr_not_null (
+ id INT NOT NULL,
+ address IPV4 NULL,
+ INDEX address_index (address) USING INVERTED
+ ) ENGINE=OLAP
+ DUPLICATE KEY(id)
+ DISTRIBUTED BY HASH(id) BUCKETS 1
+ PROPERTIES ('replication_num' = '1')
+ """
+ sql """
+ INSERT INTO test_ip_cidr_not_null VALUES
+ (1, '192.168.1.1'),
+ (2, NULL),
+ (3, '192.168.2.1'),
+ (4, '192.168.1.255')
+ """
+
+ sql "SET debug_skip_fold_constant = true"
+ sql "SET inverted_index_skip_threshold = 0"
+ sql "SET enable_segment_limit_pushdown = true"
+
+ sql "SET enable_inverted_index_query = false"
+ qt_sql_without_inverted_index """
+ SELECT id
+ FROM test_ip_cidr_not_null
+ WHERE NOT is_ip_address_in_range(address, '192.168.1.0/24')
+ ORDER BY id
+ """
+
+ sql "SET enable_inverted_index_query = true"
+ qt_sql_with_inverted_index """
+ SELECT id
+ FROM test_ip_cidr_not_null
+ WHERE NOT is_ip_address_in_range(address, '192.168.1.0/24')
+ ORDER BY id
+ """
+ qt_sql_with_inverted_index_repeat """
+ SELECT id
+ FROM test_ip_cidr_not_null
+ WHERE NOT is_ip_address_in_range(address, '192.168.1.0/24')
+ ORDER BY id
+ """
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]