Files
documentdb/pg_documentdb/include/index_am/documentdb_rum.h
T
Vinod Sridharan 0ddb09436c Merged PR 1690832: [Composite] Remove array term generation for composite indexes
### Does this PR have any customer impact?
Not yet

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

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

### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))

### Description

This adds more changes for orderby support in the index
1) Fixes the correctness issue arising from indexing arrays for order by - we remove the top level array term from indexing. To handle this, we move the query operators to support querying the index correctly when the query is on an array
2) For `$elemMatch` this temporarily makes elemMatch just a full scan for now (a subsequent change wil tackle updating the logic)
3) Adds orderby to the top level schema for the internal extension
4) For exists false/true, we were pushing a lot more terms to the runtime recheck. Ensure that we're hitting the right index terms and evaluate correctly against the index.

----
#### AI description  (iteration 1)
#### PR Classification
This pull request is a code cleanup and enhancement that removes array term generation for composite indexes and updates related index term handling.

#### PR Summary
The changes streamline composite index generation by eliminating dedicated array terms, and they adjust boundary, metadata, and recheck logic to ensure consistent behavior. Key updates include:
- **`oss/pg_documentdb/src/opclass/bson_gin_composite_core.c`**: Removed redundant array term generation and introduced functions like `SetArrayEqualityBound` to properly handle equality bounds for arrays.
- **`oss/pg_documentdb/src/opclass/gin_index_term.c`**: Updated index term serialization and metadata management (including handling of undefined values via `GenerateValueUndefinedTerm`) to align with the new composite index behavior.
- **Test and expected output files**: Revised expected composite index term outputs and SQL tests to reflect the removal of array-specific terms.
- **Documentation and configuration**: Updated design docs and removed the configuration flag for skipping array term generation, consolidating the new composite index strategy.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
2025-06-05 10:31:32 +08:00

95 lines
3.4 KiB
C

/*-------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* include/index_am/documentdb_rum.h
*
* Common declarations for RUM specific helper functions.
*
*-------------------------------------------------------------------------
*/
#ifndef DOCUMENTDB_RUM_H
#define DOCUMENTDB_RUM_H
#include <fmgr.h>
#include <access/amapi.h>
#include <nodes/pathnodes.h>
typedef void *(*CreateIndexArrayTrackerState)(void);
typedef bool (*IndexArrayTrackerAdd)(void *state, ItemPointer item);
typedef void (*FreeIndexArrayTrackerState)(void *);
typedef void (*UpdateMultikeyStatusFunc)(bool isBuild, Relation index);
typedef bool (*GetMultikeyStatusFunc)(Relation indexRelation);
/*
* Adapter struct that provides function pointers to allow
* for extensibility in managing index array state for index scans.
* The current requirements on the interface is to provide an abstraction
* that can be used to deduplicate array entries in the index scan.
*/
typedef struct RumIndexArrayStateFuncs
{
/* Create opaque state to manage entries in this specific index scan */
CreateIndexArrayTrackerState createState;
/* Add an item to the index scan and return whether or not it is new or existing */
IndexArrayTrackerAdd addItem;
/* Frees the temporary state used for the adding of items */
FreeIndexArrayTrackerState freeState;
} RumIndexArrayStateFuncs;
/* Registers an extensibility that handles index array deduplication */
void RegisterIndexArrayStateFuncs(RumIndexArrayStateFuncs *funcs);
void LoadRumRoutine(void);
IndexAmRoutine *GetRumIndexHandler(PG_FUNCTION_ARGS);
IndexScanDesc extension_rumbeginscan_core(Relation rel, int nkeys, int norderbys,
IndexAmRoutine *coreRoutine);
void extension_rumendscan_core(IndexScanDesc scan, IndexAmRoutine *coreRoutine);
void extension_rumrescan_core(IndexScanDesc scan, ScanKey scankey, int nscankeys,
ScanKey orderbys, int norderbys,
IndexAmRoutine *coreRoutine,
GetMultikeyStatusFunc multiKeyStatusFunc);
int64 extension_rumgetbitmap_core(IndexScanDesc scan, TIDBitmap *tbm,
IndexAmRoutine *coreRoutine);
bool extension_rumgettuple_core(IndexScanDesc scan, ScanDirection direction,
IndexAmRoutine *coreRoutine);
void extension_rumcostestimate(PlannerInfo *root, IndexPath *path, double
loop_count,
Cost *indexStartupCost, Cost *indexTotalCost,
Selectivity *indexSelectivity,
double *indexCorrelation,
double *indexPages);
IndexBuildResult * extension_rumbuild_core(Relation heapRelation, Relation indexRelation,
struct IndexInfo *indexInfo,
IndexAmRoutine *coreRoutine,
UpdateMultikeyStatusFunc updateMultikeyStatus,
bool amCanBuildParallel);
bool extension_ruminsert_core(Relation indexRelation,
Datum *values,
bool *isnull,
ItemPointer heap_tid,
Relation heapRelation,
IndexUniqueCheck checkUnique,
bool indexUnchanged,
struct IndexInfo *indexInfo,
IndexAmRoutine *coreRoutine,
UpdateMultikeyStatusFunc updateMultikeyStatus);
void RumUpdateMultiKeyStatus(bool isBuild, Relation index);
bool RumGetMultikeyStatus(Relation indexRelation);
struct ExplainState;
void ExplainCompositeScan(IndexScanDesc scan, struct ExplainState *es);
void ExplainRegularIndexScan(IndexScanDesc scan, struct ExplainState *es);
#endif