mirror of
https://github.com/FerretDB/documentdb.git
synced 2026-11-25 19:59:54 -05:00
### Does this PR have any customer impact? Yes ### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc) Perf ### 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 A few miscellaneous perf changes focused on Point reads 1) When parsing the find spec, we do a bunch of if/elses which means we're doing 10ish ifs for the keys that are lower in the if. Use a switch and dispatch on the first character to speed this up 2) When doing a point read and local execution, we can skip setting up yet another Portal and Transaction since we're already in a func context and we can leverage the same snapshot for the reads. Also we don't need to hold a SPI Destination and copy it to the target pgbson_array_writer, use a custom DestReceiver that takes hte Tuple and directly writes it to the target. 3) Cleanup the Gateway Dispatch functions and remove an unnecessary PG_TRY/PG_FINALLY (this is already handled by PG). ---- #### AI description (iteration 1) #### PR Classification Performance improvement. #### PR Summary This pull request introduces various performance enhancements to the read operations in the codebase, focusing on optimizing BSON aggregation and cursor handling. - `bson_aggregation_pipeline.c`: Refactored the `GenerateFindQuery` function to use a switch-case structure for improved performance and readability. - `cursors.c`: Added new functions `DrainStatementViaExecutor` and `DrainStatementViaPortal` to optimize query execution and result handling. - `command_funcs.c`: Simplified argument handling in `HelioExternalFunctionCall` and introduced `DoAclCheck` for access control. - `PostgresMongoCursorBuilder.BackendCursor.cs`: Simplified cursor page statement generation by removing unnecessary parameters. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
60 lines
2.3 KiB
C
60 lines
2.3 KiB
C
/*-------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
*
|
|
* include/commands/cursor_private.h
|
|
*
|
|
* Private declarations of functions and types shared between
|
|
* cursors.c and aggregation_cursors.c
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
|
|
#ifndef CURSOR_PRIVATE_H
|
|
#define CURSOR_PRIVATE_H
|
|
|
|
bool DrainStreamingQuery(HTAB *cursorMap, Query *query, int batchSize,
|
|
int32_t *numIterations, uint32_t accumulatedSize,
|
|
pgbson_array_writer *arrayWriters);
|
|
pgbson * DrainTailableQuery(HTAB *cursorMap, Query *query, int batchSize,
|
|
int32_t *numIterations, uint32_t accumulatedSize,
|
|
pgbson_array_writer *arrayWriter);
|
|
bool CreateAndDrainPersistedQuery(const char *cursorName, Query *query,
|
|
int batchSize, int32_t *numIterations, uint32_t
|
|
accumulatedSize,
|
|
pgbson_array_writer *arrayWriter, bool isHoldCursor,
|
|
bool closeCursor);
|
|
bool DrainPersistedCursor(const char *cursorName, int batchSize,
|
|
int32_t *numIterations, uint32_t accumulatedSize,
|
|
pgbson_array_writer *arrayWriter);
|
|
|
|
bool CreateAndDrainPointReadQuery(const char *cursorName, Query *query,
|
|
int32_t *numIterations, uint32_t
|
|
accumulatedSize,
|
|
pgbson_array_writer *arrayWriter);
|
|
|
|
TupleDesc ConstructCursorResultTupleDesc(AttrNumber maxAttrNum);
|
|
|
|
Datum PostProcessCursorPage(pgbson_writer *cursorDoc,
|
|
pgbson_array_writer *arrayWriter,
|
|
pgbson_writer *topLevelWriter, int64_t cursorId,
|
|
pgbson *continuation, bool persistConnection,
|
|
pgbson *lastContinuationToken,
|
|
TupleDesc tupleDesc);
|
|
|
|
HTAB * CreateCursorHashSet(void);
|
|
HTAB * CreateTailableCursorHashSet(void);
|
|
void BuildContinuationMap(pgbson *continuationValue, HTAB *cursorMap);
|
|
void BuildTailableCursorContinuationMap(pgbson *continuationValue, HTAB *cursorMap);
|
|
void SerializeContinuationsToWriter(pgbson_writer *writer, HTAB *cursorMap);
|
|
void SerializeTailableContinuationsToWriter(pgbson_writer *writer, HTAB *cursorMap);
|
|
|
|
pgbson * DrainSingleResultQuery(Query *query);
|
|
|
|
void SetupCursorPagePreamble(pgbson_writer *topLevelWriter,
|
|
pgbson_writer *cursorDoc,
|
|
pgbson_array_writer *arrayWriter,
|
|
const char *namespaceName, bool isFirstPage,
|
|
uint32_t *accumulatedLength);
|
|
|
|
#endif
|