Skip to content

Conversation

@yjhjstz
Copy link
Member

@yjhjstz yjhjstz commented Jan 23, 2026

Check IsSorted before Sort to reduce O(n log n) to O(n-1) comparisons for pre-sorted IN lists, improving ORCA optimization time.

Fixes #ISSUE_Number

What does this PR do?

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Breaking Changes

Test Plan

  • Unit tests added/updated
  • Integration tests added/updated
  • Passed make installcheck
  • Passed make -C src/test installcheck-cbdb-parallel

Impact

Performance:

User-facing changes:

Dependencies:

Checklist

Additional Context

CI Skip Instructions


Check IsSorted before Sort to reduce O(n log n) to O(n-1) comparisons                                                                      for pre-sorted IN lists, improving ORCA optimization time.
Copilot AI review requested due to automatic review settings January 23, 2026 20:45
Copy link

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 optimizes CDatumSortedSet construction by avoiding an unnecessary sort when the underlying array of datums is already sorted, reducing the common-case complexity for pre-sorted IN lists.

Changes:

  • Replace unconditional Sort(&CUtils::IDatumCmp) on the temporary IDatumArray with a preceding IsSorted(&CUtils::IDatumCmp) check.
  • Add an explanatory comment documenting the complexity difference and motivation (pre-sorted IN lists).

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

@reshke
Copy link
Contributor

reshke commented Jan 23, 2026

nice spotted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants