|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +// This test verifies that when both MINMAX and IN runtime filters target the same |
| 19 | +// key column, and the IN filter's value count exceeds max_pushdown_conditions_per_column, |
| 20 | +// the IN_LIST predicate is NOT incorrectly erased by the key range construction logic. |
| 21 | +// Regression test for the bug where _build_key_ranges_and_filters() erased IN_LIST |
| 22 | +// predicates when the ColumnValueRange was a scope range (from MINMAX filter). |
| 23 | +suite("test_rf_in_list_not_erased_by_scope_range") { |
| 24 | + sql "drop table if exists rf_scope_probe;" |
| 25 | + sql "drop table if exists rf_scope_build;" |
| 26 | + |
| 27 | + sql """ |
| 28 | + CREATE TABLE rf_scope_probe ( |
| 29 | + k1 BIGINT, |
| 30 | + v1 INT |
| 31 | + ) |
| 32 | + DUPLICATE KEY(k1) |
| 33 | + DISTRIBUTED BY HASH(k1) BUCKETS 1 |
| 34 | + PROPERTIES ("replication_num" = "1"); |
| 35 | + """ |
| 36 | + |
| 37 | + sql """ |
| 38 | + CREATE TABLE rf_scope_build ( |
| 39 | + k1 BIGINT, |
| 40 | + v1 INT |
| 41 | + ) |
| 42 | + DUPLICATE KEY(k1) |
| 43 | + DISTRIBUTED BY HASH(k1) BUCKETS 1 |
| 44 | + PROPERTIES ("replication_num" = "1"); |
| 45 | + """ |
| 46 | + |
| 47 | + // Probe table: insert 20 rows with k1 from 1 to 20. |
| 48 | + // The build side will only match a subset (k1 in {2,4,6,8,10,12}). |
| 49 | + // Rows NOT in this subset (k1=1,3,5,7,9,11,13..20) should be filtered out |
| 50 | + // by the IN_LIST runtime filter. |
| 51 | + sql """ |
| 52 | + INSERT INTO rf_scope_probe VALUES |
| 53 | + (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), |
| 54 | + (6, 6), (7, 7), (8, 8), (9, 9), (10, 10), |
| 55 | + (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), |
| 56 | + (16, 16), (17, 17), (18, 18), (19, 19), (20, 20); |
| 57 | + """ |
| 58 | + |
| 59 | + // Build table: 6 distinct k1 values. This exceeds max_pushdown_conditions_per_column=5 |
| 60 | + // so the IN values are NOT added to ColumnValueRange, but the IN_LIST predicate is created. |
| 61 | + // MINMAX range: [2, 12] |
| 62 | + sql """ |
| 63 | + INSERT INTO rf_scope_build VALUES |
| 64 | + (2, 100), (4, 200), (6, 300), (8, 400), (10, 500), (12, 600); |
| 65 | + """ |
| 66 | + |
| 67 | + sql "sync;" |
| 68 | + |
| 69 | + // Set max_pushdown_conditions_per_column to 5, so the 6 IN values exceed it. |
| 70 | + // This causes IN values to NOT be added to the ColumnValueRange (it stays as |
| 71 | + // a scope range from the MINMAX filter), but the IN_LIST ColumnPredicate is still created. |
| 72 | + sql "set max_pushdown_conditions_per_column = 5;" |
| 73 | + // Use both IN and MIN_MAX runtime filter types so both are generated on the join key. |
| 74 | + sql "set runtime_filter_type = 'IN_OR_BLOOM_FILTER,MIN_MAX';" |
| 75 | + sql "set runtime_filter_wait_time_ms = 10000;" |
| 76 | + sql "set runtime_filter_wait_infinitely = true;" |
| 77 | + sql "set enable_runtime_filter_prune = false;" |
| 78 | + sql "set enable_left_semi_direct_return_opt = true;" |
| 79 | + sql "set parallel_pipeline_task_num = 1;" |
| 80 | + |
| 81 | + // The join should only return 6 rows (matching k1 in {2,4,6,8,10,12}). |
| 82 | + // If the IN_LIST predicate is incorrectly erased, the MINMAX scope [2,12] |
| 83 | + // would let through rows with k1 in {3,5,7,9,11} as well, producing wrong results. |
| 84 | + // We verify correctness by checking the result. |
| 85 | + order_qt_join """ |
| 86 | + SELECT p.k1, p.v1 |
| 87 | + FROM rf_scope_probe p |
| 88 | + LEFT SEMI JOIN rf_scope_build b ON p.k1 = b.k1 |
| 89 | + ORDER BY p.k1; |
| 90 | + """ |
| 91 | +} |
0 commit comments