Files
Vinod Sridharan 10b395a75b Merged PR 1773514: [Orderby] Improve order by pushdown behavior & selectivity
### Does this PR have any customer impact?
Yes

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Feature

### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No

### Are you introducing any new config? If yes, do you have tests with and without them being set?
Yes

### ChangeLog (Refer [Template](../oss/CHANGELOG.md))

### Description

Pushing down order by and filters to a composite index should prefer the smallest index with the highest number of order by columns matching.

To do this we need to participate in the core add_path set up as opposed to after.
Consequently, we mutate the indexPath when its created in create_index_path as opposed to modifying it in the relpathlist_hook. We also reorder the indexes by paths so that for filters, we prefer indexes with fewer paths over many that can match the same paths.

----
#### AI description  (iteration 1)
#### PR Classification
This pull request refines the ORDER BY pushdown mechanism in index scans by adding new processing logic and improving index selectivity while introducing a feature flag for the legacy behavior.

#### PR Summary
The changes enhance query performance by introducing distinct pushdown paths for ORDER BY clauses, refining composite index handling, and updating test expectations to reflect the new "orderByScan" operator. The following key modifications were made:
- **`oss/pg_documentdb/src/opclass/index_support.c`**: Added new functions (e.g., `ConsiderIndexOrderByPushdownNew`, `ProcessOrderByStatements`) to split new versus legacy ORDER BY pushdown logic.
- **Test Files** (under `/oss/internal/pg_documentdb_distributed/src/test/regress/expected/` and `/pgmongo/src/test/docdb_compat/expected/`): Updated expected query plans to use the new "orderByScan" predicate instead of "fullScan".
- **Index and Planner Modules** (e.g., `oss/pg_documentdb/src/index_am/rum.c` and `planner/documents_planner.c`): Enhanced composite index ranking to factor in the number of index paths.
- **Configuration Files** (e.g., `oss/pg_documentdb/src/configs/feature_flag_configs.c`): Introduced the `EnableIndexOrderbyPushdownLegacy` flag for toggling the legacy behavior.
- **Supporting Modules** (in aggregation and query operators): Adjusted functions in files like `bson_query_common.c` and related headers to handle new order-by scan directions consistently.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
2025-08-21 20:14:39 +08:00
..