Skip to content

Commit 28d2049

Browse files
committed
don't remove DESC sorting for sys view reads
1 parent fe21f71 commit 28d2049

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ydb/core/kqp/opt/physical/kqp_opt_phy_sort.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ TExprBase KqpRemoveRedundantSortOverReadTable(TExprBase node, TExprContext& ctx,
9393
}
9494

9595
if (direction == ESortDirection::Reverse) {
96+
// For sys views, we need to set reverse flag even if UseSource returns false
97+
// because sys view actors can handle reverse direction
98+
bool isSysView = tableDesc.Metadata->Kind == EKikimrTableKind::SysView;
99+
if (isSysView) {
100+
return node;
101+
}
102+
96103
if (!UseSource(kqpCtx, tableDesc) && kqpCtx.IsScanQuery()) {
97104
return node;
98105
}
@@ -206,7 +213,10 @@ TExprBase KqpRemoveRedundantSortOverReadTableFSM(
206213
}
207214

208215
if (isReversed) {
209-
if (!UseSource(kqpCtx, tableDesc) && kqpCtx.IsScanQuery()) {
216+
// For sys views, we need to set reverse flag even if UseSource returns false
217+
// because sys view actors can handle reverse direction
218+
bool isSysView = tableDesc.Metadata->Kind == EKikimrTableKind::SysView;
219+
if (!UseSource(kqpCtx, tableDesc) && kqpCtx.IsScanQuery() && !isSysView) {
210220
return node;
211221
}
212222

0 commit comments

Comments
 (0)