Skip to content

Commit e797d39

Browse files
LordParagshuaitian-git
authored andcommitted
Merged PR 1766738: [Perf] Reduce CPU cycles for UpdateOneInternal.
### Does this PR have any customer impact? ### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc) ### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes) ### Are you introducing any new config? If yes, do you have tests with and without them being set? ### ChangeLog (Refer [Template](../oss/CHANGELOG.md)) ### Description Save Some Cpu Cycle In UpdateOne CodePath by not coverting pgbson to bson value, let's use existing one. ![image.png](https://msdata.visualstudio.com/ba574a88-a171-48e0-8fcb-5fef6d23739c/_apis/git/repositories/501a5e7e-ffdc-4d1e-a5e6-910f73c6eb9a/pullRequests/1766738/attachments/image.png) ---- #### AI description (iteration 1) #### PR Classification Performance optimization in the update code path. #### PR Summary This PR refines the update process by eliminating an early and redundant BSON conversion for query extraction, thereby reducing CPU cycles. It replaces the call to get the object ID filter with a more direct approach while still initializing the BSON query later when needed. - `oss/pg_documentdb/src/commands/update.c`: Removed the premature `PgbsonInitFromDocumentBsonValue` call and replaced `GetObjectIdFilterFromQueryDocument` with `GetObjectIdFilterFromQueryDocumentValue`, using `updateOneParams->query` directly. - `oss/pg_documentdb/src/commands/update.c`: Reintroduced BSON query initialization later in the function for proper argument type handling. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
1 parent 6b95258 commit e797d39

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

pg_documentdb/src/commands/update.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3249,13 +3249,13 @@ SelectUpdateCandidate(uint64 collectionId, const char *shardTableName, int64 sha
32493249
NIL;
32503250
int argCount = list_length(sortFieldDocuments);
32513251

3252-
pgbson *query = PgbsonInitFromDocumentBsonValue(updateOneParams->query);
3252+
32533253
bool queryHasNonIdFilters = false;
32543254
bool isIdFilterCollationAwareIgnore = false;
3255-
pgbson *objectIdFilter = GetObjectIdFilterFromQueryDocument(query,
3256-
&queryHasNonIdFilters,
3257-
&
3258-
isIdFilterCollationAwareIgnore);
3255+
pgbson *objectIdFilter =
3256+
GetObjectIdFilterFromQueryDocumentValue(updateOneParams->query,
3257+
&queryHasNonIdFilters,
3258+
&isIdFilterCollationAwareIgnore);
32593259
*hasOnlyObjectIdFilter = objectIdFilter != NULL && !queryHasNonIdFilters;
32603260

32613261
int nextSqlArgIndex = 1;
@@ -3348,6 +3348,7 @@ SelectUpdateCandidate(uint64 collectionId, const char *shardTableName, int64 sha
33483348
argNulls[0] = ' ';
33493349

33503350
Oid bsonTypeId = BsonTypeId();
3351+
pgbson *query = PgbsonInitFromDocumentBsonValue(updateOneParams->query);
33513352

33523353
/* set query value*/
33533354
argTypes[1] = bsonTypeId;

0 commit comments

Comments
 (0)