Files
Vinod Sridharan a7b1076f31 Merged PR 1773571: Improve IndexScan and IndexOnlyScan Performance
### 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

Improve performance of indexscans and indexonlyscans

IndexTerm:
>1) BsonIndexTerm is used in several places - reduce the size of this struct by removing isTruncated bool from the struct.
>2)  Add options to check metadata state without parsing the index term at all.
>3) InitializeBsonIndexTerm - do not create a wrapper bson_value_t - just initialize the term directly.

OrderedScans:
>1) For every page we visit, we free the prior buffer and call PageGetTempPageCopy. Instead, keep one buffer per scan and just copy the buffer into the static buffer created per scan
>2) When doing indexonlyscan, don't recreate an indextuple very time - instead reuse the memory and just fill the tuple buffer with what was previously allocated

PgbsonWriter:
>1) Add support for reusing the same writer across invocations by calling reset on the buffer
>2) Add options to retrieve the value from a pgbsonwriter

Composite:
>1) Use a case dispatch for strategies rather than multiple if/else
>2) Work on the serialized bson index terms as much as possible and lazy load the index terms
>3) Skip Compare on bounds calls if there's no bounds declared

----
#### AI description  (iteration 1)
#### PR Classification
This pull request delivers performance improvements and code refactoring for index scan operations.

#### PR Summary
The changes optimize index scans by refactoring tuple construction and buffer page handling for RUM indexes, while also unifying and streamlining BSON composite index term processing.
- `pgmongo_rum/src/rumget.c`: Introduced `IndexBuildTupleDynamic` to build tuples without compression and reuse memory, and refactored page copy logic using `CopyPageContents` and an added `isPageValid` flag.
- `oss/pg_documentdb/src/opclass/bson_gin_composite_entrypoint.c` (and related files): Replaced direct truncation checks with function calls (e.g., `IsIndexTermTruncated`), updated serialized composite index term initialization, and adjusted ordering transform logic.
- `oss/pg_documentdb/src/opclass/bson_gin_index_term.c` (and accompanying headers): Added functions for handling serialized composite index terms and metadata, consolidating truncation flag logic.
- `oss/pg_documentdb_core/src/io/pgbson.c`/`pgbson_writer.h`: Added new writer functions (e.g., reset and value retrieval) to improve memory reuse and reduce allocation overhead.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
2025-08-21 20:14:39 +08:00
..