branch-2.1: [Bug](sort) fix wrong result coz push down sort with null last #51472 (#51507)

Cherry-picked from #51472

Co-authored-by: Pxl <xl@selectdb.com>
This commit is contained in:
github-actions[bot]
2025-06-16 14:51:12 +08:00
committed by GitHub
parent 1ee58b216b
commit c9623c32f0
4 changed files with 199 additions and 6 deletions

View File

@ -2753,9 +2753,9 @@ public class PhysicalPlanTranslator extends DefaultPlanVisitor<PlanFragment, Pla
if (sortExpr instanceof SlotRef) {
SlotRef slotRef = (SlotRef) sortExpr;
if (sortColumn.equals(slotRef.getColumn())) {
// ORDER BY DESC NULLS FIRST can not be optimized to only read file tail,
// since NULLS is at file head but data is at tail
if (sortColumn.isAllowNull() && nullsFirsts.get(i) && !isAscOrders.get(i)) {
// [ORDER BY DESC NULLS FIRST] or [ORDER BY ASC NULLS LAST] can not be optimized
// to only read file tail, since NULLS is at file head but data is at tail
if (sortColumn.isAllowNull() && nullsFirsts.get(i) != isAscOrders.get(i)) {
return false;
}
} else {

View File

@ -1235,9 +1235,9 @@ public class OlapScanNode extends ScanNode {
if (sortExpr instanceof SlotRef) {
SlotRef slotRef = (SlotRef) sortExpr;
if (tableKey.equals(slotRef.getColumn())) {
// ORDER BY DESC NULLS FIRST can not be optimized to only read file tail,
// since NULLS is at file head but data is at tail
if (tableKey.isAllowNull() && nullsFirsts.get(i) && !isAscOrders.get(i)) {
// [ORDER BY DESC NULLS FIRST] or [ORDER BY ASC NULLS LAST] can not be optimized
// to only read file tail, since NULLS is at file head but data is at tail
if (tableKey.isAllowNull() && (nullsFirsts.get(i) != isAscOrders.get(i))) {
return false;
}
} else {