englefly commented on code in PR #71075:
URL: https://github.com/apache/doris/pull/71075#discussion_r4767343000
##########
fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionExprUtil.java:
##########
@@ -167,7 +165,9 @@ public static Map<String, AddPartitionOp>
getAddPartitionClauseFromPartitionValu
if (partitionType == PartitionType.RANGE) {
String beginTime = curPartitionValues.get(0); // have check
range type size must be 1
Type partitionColumnType = partitionColumn.get(0).getType();
- LiteralExpr beginDateTime =
DateLiteralUtils.createLiteral(beginTime, partitionColumnType);
+ LiteralExpr beginDateTime = beginTime == null
+ ? getNullRangeBegin(partitionColumnType)
Review Comment:
**[P1] Preserve NULL during partition pruning for daily DATE ranges**
With `AUTO PARTITION BY RANGE (date_trunc(d, 'day'))` on a nullable `DATE`
column, inserting one NULL row creates `[MIN_VALUE, 0000-01-02)`. Nereids'
`PartitionRangeExpander` expands this one-day range to the single non-NULL
literal `0000-01-01`. `OneRangePartitionEvaluator.visitIsNull` folds `d IS
NULL` to false before it consults `partitionSlotContainsNull`, so `SELECT
COUNT(*) FROM t WHERE d IS NULL` can return 0 for the inserted row. The current
DATE regression uses a monthly range, which does not exercise this expansion.
Please preserve the NULL possibility when evaluating predicates on a nullable
MIN_VALUE partition and add a daily DATE regression.
##########
fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionExprUtil.java:
##########
@@ -248,6 +248,24 @@ public static Map<String, AddPartitionOp>
getAddPartitionClauseFromPartitionValu
return result;
}
+ /**
+ * The start of the range partition that holds NULL values of a nullable
AUTO RANGE PARTITION column.
+ *
+ * <p>A range partition orders NULL below every value, so NULL belongs to
the first range: the one that
+ * starts at the type's minimum (0000-01-01 for date types). A lower bound
equal to MIN_VALUE reaches BE
+ * without a start key, which BE reads as "no lower bound", so the NULL
rows route to that partition. It is
+ * the same partition a row holding the minimum value would create (for
example p00000101000000), so the two
+ * never conflict. CREATE TABLE allows a nullable AUTO RANGE PARTITION
column only for these date types.
+ */
+ private static LiteralExpr getNullRangeBegin(Type partitionColumnType)
throws AnalysisException {
+ Preconditions.checkState(partitionColumnType.isDate() ||
partitionColumnType.isDateV2()
+ || partitionColumnType.isDatetime() ||
partitionColumnType.isDatetimeV2(),
+ "NULL value of AUTO RANGE PARTITION column type %s",
partitionColumnType);
+ String minValue = (partitionColumnType.isDate() ||
partitionColumnType.isDateV2())
+ ? "0000-01-01" : "0000-01-01 00:00:00";
+ return DateLiteralUtils.createLiteral(minValue, partitionColumnType);
Review Comment:
**[P1] Align the NULL partition's upper bound with the partition function**
The year-zero overlap described in the PR produces an insert failure or a
wrong query result, depending on load order. With `date_trunc(d, 'week')`, the
NULL range is `[MIN_VALUE, 0000-01-08)`, while the first full week is
`[0000-01-02, 0000-01-09)`. Inserting `0000-01-02` first and then inserting
NULL fails the overlap check. Inserting NULL first and then inserting
`0000-01-08` routes the date to the NULL partition because its truncated key is
`0000-01-02`. A query with `WHERE d = '0000-01-08'` can then prune the
partition containing that row. Please align the upper bound with the actual
partition boundaries and cover both insertion orders.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]