This is an automated email from the ASF dual-hosted git repository.

Mryange pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new c98e4437e5f [fix](function) Preserve NULL rows in IP range index 
results (#68051)
c98e4437e5f is described below

commit c98e4437e5fba1d0db0a76b466b6fc01a01b313f
Author: Mryange <[email protected]>
AuthorDate: Fri Sep 18 12:55:00 2026 +0800

    [fix](function) Preserve NULL rows in IP range index results (#68051)
    
    Inverted-index evaluation for `is_ip_address_in_range` discarded the
    source column's NULL bitmap. A `NOT` predicate could therefore treat
    NULL rows as ordinary non-matching rows and return them incorrectly. The
    evaluator now reads and propagates the index NULL bitmap so bitmap
    complement evaluation preserves SQL three-valued logic.
    
    ### Release note
    
    None
    
    ### Check List (For Author)
    
    - Test <!-- At least one of them must be included. -->
        - [ ] Regression test
        - [ ] Unit Test
        - [ ] Manual test (add detailed scripts or steps below)
        - [ ] No need to test or manual test. Explain why:
    - [ ] This is a refactor/code format and no logic has been changed.
            - [ ] Previous test can cover this change.
            - [ ] No code files have been changed.
            - [ ] Other reason <!-- Add your reason?  -->
    
    - Behavior changed:
        - [ ] No.
        - [ ] Yes. <!-- Explain the behavior change -->
    
    - Does this need documentation?
        - [ ] No.
    - [ ] Yes. <!-- Add document PR link here. eg:
    https://github.com/apache/doris-website/pull/1214 -->
    
    ### Check List (For Reviewer who merge this PR)
    
    - [ ] Confirm the release note
    - [ ] Confirm test cases
    - [ ] Confirm document
    - [ ] Add branch pick label <!-- Add branch pick label that this PR
    should merge into -->
---
 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 a734f55881e..f0cf8c86712 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]

Reply via email to