Skip to content

Conversation

@gridnevvvit
Copy link
Member

Changelog entry

Changelog category

  • Not for changelog (changelog entry is not required)

Description for reviewers

fixes #12585

@gridnevvvit gridnevvvit requested a review from a team as a code owner November 15, 2025 12:48
Copilot AI review requested due to automatic review settings November 15, 2025 12:48
Copilot finished reviewing on behalf of gridnevvvit November 15, 2025 12:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes issue #12585 where ORDER BY DESC was being incorrectly removed from query plans for system views. The fix prevents the optimizer from removing DESC sorting when querying sys views, as these actors can handle reverse direction.

Key changes:

  • Added logic to preserve DESC sorting for sys views in query optimization
  • Added a test case to verify DESC ordering works correctly for the nodes sys view

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
ydb/core/kqp/opt/physical/kqp_opt_phy_sort.cpp Modified two optimization functions to check if table is a sys view and preserve reverse sorting accordingly
ydb/core/kqp/ut/sysview/kqp_sys_view_ut.cpp Added NodesOrderByDesc test to verify DESC ordering works, plus minor whitespace cleanup

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +96 to +101
// For sys views, we need to set reverse flag even if UseSource returns false
// because sys view actors can handle reverse direction
bool isSysView = tableDesc.Metadata->Kind == EKikimrTableKind::SysView;
if (isSysView) {
return node;
}
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for checking if a table is a sys view is duplicated in both KqpRemoveRedundantSortOverReadTable (lines 96-101) and KqpRemoveRedundantSortOverReadTableFSM (lines 216-219). Consider extracting this check into a helper function to reduce code duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
Comment on lines +216 to +219
// For sys views, we need to set reverse flag even if UseSource returns false
// because sys view actors can handle reverse direction
bool isSysView = tableDesc.Metadata->Kind == EKikimrTableKind::SysView;
if (isSysView) {
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sys view check is embedded in a complex boolean expression. This differs from the implementation in KqpRemoveRedundantSortOverReadTable (lines 96-101) where the sys view check uses an early return. Consider using a consistent approach in both functions for better code clarity and maintainability.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

github-actions bot commented Nov 15, 2025

🟢 2025-11-16 10:26:08 UTC The validation of the Pull Request description is successful.

@github-actions
Copy link

github-actions bot commented Nov 15, 2025

2025-11-15 12:51:35 UTC Pre-commit check linux-x86_64-release-asan for 08f9bd0 has started.
2025-11-15 12:51:52 UTC Artifacts will be uploaded here
2025-11-15 12:54:06 UTC ya make is running...
2025-11-15 14:02:48 UTC Check cancelled

@github-actions
Copy link

github-actions bot commented Nov 15, 2025

2025-11-15 12:51:36 UTC Pre-commit check linux-x86_64-relwithdebinfo for 08f9bd0 has started.
2025-11-15 12:51:53 UTC Artifacts will be uploaded here
2025-11-15 12:54:10 UTC ya make is running...
2025-11-15 14:02:48 UTC Check cancelled

@github-actions
Copy link

github-actions bot commented Nov 15, 2025

2025-11-15 14:05:06 UTC Pre-commit check linux-x86_64-relwithdebinfo for 015896c has started.
2025-11-15 14:05:22 UTC Artifacts will be uploaded here
2025-11-15 14:07:38 UTC ya make is running...
🟡 2025-11-15 15:33:45 UTC Some tests failed, follow the links below. Going to retry failed tests...

Ya make output | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
38931 36108 0 8 2795 20

2025-11-15 15:33:57 UTC ya make is running... (failed tests rerun, try 2)
🟡 2025-11-15 15:42:16 UTC Some tests failed, follow the links below. Going to retry failed tests...

Ya make output | Test bloat | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
58 (only retried tests) 42 0 1 0 15

2025-11-15 15:42:22 UTC ya make is running... (failed tests rerun, try 3)
🔴 2025-11-15 15:50:16 UTC Some tests failed, follow the links below.

Ya make output | Test bloat | Test bloat | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
32 (only retried tests) 17 0 1 0 14

🟢 2025-11-15 15:50:23 UTC Build successful.
🟢 2025-11-15 15:50:46 UTC ydbd size 2.3 GiB changed* by +18.5 KiB, which is < 100.0 KiB vs main: OK

ydbd size dash main: c2dac27 merge: 015896c diff diff %
ydbd size 2 480 125 272 Bytes 2 480 144 240 Bytes +18.5 KiB +0.001%
ydbd stripped size 520 947 032 Bytes 520 950 680 Bytes +3.6 KiB +0.001%

*please be aware that the difference is based on comparing your commit and the last completed build from the post-commit, check comparation

@github-actions
Copy link

github-actions bot commented Nov 15, 2025

2025-11-15 14:05:31 UTC Pre-commit check linux-x86_64-release-asan for 015896c has started.
2025-11-15 14:05:48 UTC Artifacts will be uploaded here
2025-11-15 14:08:04 UTC ya make is running...
🟡 2025-11-15 16:06:02 UTC Some tests failed, follow the links below. This fail is not in blocking policy yet

Ya make output | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
15599 15036 0 325 214 24

🟢 2025-11-15 16:06:11 UTC Build successful.
🟢 2025-11-15 16:06:39 UTC ydbd size 3.9 GiB changed* by -4.3 KiB, which is <= 0 Bytes vs main: OK

ydbd size dash main: ec12505 merge: 015896c diff diff %
ydbd size 4 137 029 936 Bytes 4 137 025 520 Bytes -4.3 KiB -0.000%
ydbd stripped size 1 522 946 272 Bytes 1 522 945 056 Bytes -1.2 KiB -0.000%

*please be aware that the difference is based on comparing your commit and the last completed build from the post-commit, check comparation

@github-actions
Copy link

github-actions bot commented Nov 15, 2025

2025-11-15 20:01:34 UTC Pre-commit check linux-x86_64-relwithdebinfo for fa436d3 has started.
2025-11-15 20:02:48 UTC Artifacts will be uploaded here
2025-11-15 20:04:57 UTC ya make is running...
🟡 2025-11-15 21:30:36 UTC Some tests failed, follow the links below. Going to retry failed tests...

Ya make output | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
38931 36108 0 2 2796 25

2025-11-15 21:30:48 UTC ya make is running... (failed tests rerun, try 2)
🟢 2025-11-15 21:38:48 UTC Tests successful.

Ya make output | Test bloat | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
59 (only retried tests) 43 0 0 0 16

🟢 2025-11-15 21:38:55 UTC Build successful.
🟢 2025-11-15 21:39:15 UTC ydbd size 2.3 GiB changed* by +18.5 KiB, which is < 100.0 KiB vs main: OK

ydbd size dash main: c2dac27 merge: fa436d3 diff diff %
ydbd size 2 480 125 272 Bytes 2 480 144 240 Bytes +18.5 KiB +0.001%
ydbd stripped size 520 947 032 Bytes 520 950 680 Bytes +3.6 KiB +0.001%

*please be aware that the difference is based on comparing your commit and the last completed build from the post-commit, check comparation

@github-actions
Copy link

github-actions bot commented Nov 15, 2025

2025-11-15 20:05:55 UTC Pre-commit check linux-x86_64-release-asan for fa436d3 has started.
2025-11-15 20:06:13 UTC Artifacts will be uploaded here
2025-11-15 20:08:26 UTC ya make is running...
🟡 2025-11-15 22:04:57 UTC Some tests failed, follow the links below. This fail is not in blocking policy yet

Ya make output | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
15599 15050 0 264 265 20

🟢 2025-11-15 22:05:07 UTC Build successful.
🟢 2025-11-15 22:05:36 UTC ydbd size 3.9 GiB changed* by -4.3 KiB, which is <= 0 Bytes vs main: OK

ydbd size dash main: ec12505 merge: fa436d3 diff diff %
ydbd size 4 137 029 936 Bytes 4 137 025 520 Bytes -4.3 KiB -0.000%
ydbd stripped size 1 522 946 272 Bytes 1 522 945 056 Bytes -1.2 KiB -0.000%

*please be aware that the difference is based on comparing your commit and the last completed build from the post-commit, check comparation

@gridnevvvit gridnevvvit changed the title don't remove DESC sorting from plan for nodes sys view don't remove DESC sorting from plan for sys view Nov 16, 2025
@gridnevvvit gridnevvvit merged commit 57fa13e into ydb-platform:main Nov 16, 2025
12 checks passed
gridnevvvit added a commit to gridnevvvit/ydb that referenced this pull request Nov 16, 2025
gridnevvvit added a commit to gridnevvvit/ydb that referenced this pull request Nov 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ORDER BY doesn't work for Sys Views

2 participants