Skip to content

Commit

Permalink
[fix](nereids) temp partition is always pruned (apache#27636)
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly authored Nov 28, 2023
1 parent 31fe481 commit 2ea1e9d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ public Map<Long, PartitionItem> getIdToItem(boolean isTemp) {
}
}

/**
* @return both normal partition and temp partition
*/
public Map<Long, PartitionItem> getAllPartitions() {
HashMap all = new HashMap<>();
all.putAll(idToTempItem);
all.putAll(idToItem);
return all;
}

public PartitionItem getItem(long partitionId) {
PartitionItem item = idToItem.get(partitionId);
if (item == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public List<Long> prune() {
*/
public static List<Long> prune(List<Slot> partitionSlots, Expression partitionPredicate,
PartitionInfo partitionInfo, CascadesContext cascadesContext, PartitionTableType partitionTableType) {
return prune(partitionSlots, partitionPredicate, partitionInfo.getIdToItem(false), cascadesContext,
return prune(partitionSlots, partitionPredicate, partitionInfo.getAllPartitions(), cascadesContext,
partitionTableType);
}

Expand Down
3 changes: 3 additions & 0 deletions regression-test/data/nereids_syntax_p0/select_partition.out
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@
-- !sql --
1 aaa aaa

-- !sql --
16 1234 t

32 changes: 32 additions & 0 deletions regression-test/suites/nereids_syntax_p0/select_partition.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,36 @@ suite("query_on_specific_partition") {
qt_sql """
SELECT * FROM test_iot PARTITION p1;
"""

sql """
DROP TABLE IF EXISTS ut_p;
"""

sql """
CREATE TABLE ut_p (
id BIGINT,
val BIGINT,
str VARCHAR(114)
) unique KEY(`id`)
PARTITION BY RANGE(`id`)
(
PARTITION `p1` VALUES LESS THAN ('5'),
PARTITION `p2` VALUES LESS THAN ('10')
)
DISTRIBUTED BY HASH(`id`) BUCKETS 3
PROPERTIES (
"replication_num"="1"
);
"""

sql """ALTER TABLE ut_p ADD TEMPORARY PARTITION tp1 VALUES [("15"), ("20"));"""

sql "INSERT INTO ut_p TEMPORARY PARTITION(tp1) values(16,1234, 't');"

sql "SET enable_fallback_to_original_planner=false"

qt_sql """select * from ut_p temporary partitions(tp1);"""



}

0 comments on commit 2ea1e9d

Please sign in to comment.