MCPcopy Create free account
hub / github.com/documentdb/documentdb / bson_dollar_range

Function bson_dollar_range

pg_documentdb/src/query/bson_dollar_operators.c:1281–1355  ·  view source on GitHub ↗

* bson_dollar_range implements the DocumentDB API's version of the range * functionality in the runtime. Note that this is different from * $range array operator. This combines $gt and $lt conditions into a range * operator that can be used to traverse an index efficiently. * * The runtime version is needed if the index requires a recheck of * the range condition. It traverses the document b

Source from the content-addressed store, hash-verified

1279 *
1280 */
1281Datum
1282bson_dollar_range(PG_FUNCTION_ARGS)
1283{
1284 pgbson *document = PG_GETARG_PGBSON(0);
1285 pgbson *filter = PG_GETARG_PGBSON(1);
1286 const DollarRangeParams *cachedRangeParamsState;
1287 SetCachedFunctionState(
1288 cachedRangeParamsState,
1289 DollarRangeParams,
1290 1,
1291 PopulateRangeStateFromQuery,
1292 filter);
1293
1294 DollarRangeParams localState = { 0 };
1295 if (cachedRangeParamsState == NULL)
1296 {
1297 PopulateRangeStateFromQuery(&localState, filter);
1298 cachedRangeParamsState = &localState;
1299 }
1300
1301 TraverseRangeValidateState rangeState = { 0 };
1302
1303 /*
1304 * params (i.e., DollarRangeParams) remains unchanged throughout multiple invocations of bson_dollar_range()
1305 * during the execution of a query. The rest can be modified as the query execution progresses.
1306 *
1307 * We only use cached values for the unchanged parts.
1308 */
1309
1310 pgbsonelement filterElement;
1311 const char *collationString = PgbsonToSinglePgbsonElementWithCollation(filter,
1312 &filterElement);
1313
1314 if (IsCollationValid(collationString))
1315 {
1316 /* TODO (workitem=3423305): Index pushdwon on $range operator with collation (see method description for more details) */
1317 /* This code path is not expected to be excercised until $range with collation is pushed down to the index. */
1318 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR), errmsg(
1319 "operator $range or operators that can be optimized to $range is not supported with collation"),
1320 errdetail_log(
1321 "operator $range or operators that can be optimized to $range is not supported with collation : %s",
1322 collationString)));
1323 }
1324
1325 rangeState.elementState.filter = &filterElement;
1326 rangeState.params = *cachedRangeParamsState;
1327 rangeState.isMinConditionSet = false;
1328 rangeState.isMaxConditionSet = false;
1329
1330 if (rangeState.params.isFullScan || rangeState.params.isElemMatch)
1331 {
1332 /* if the range is a full scan, we don't need to traverse the document
1333 * similarly for $elemMatch this range query is only used on the index
1334 * so we bypass the runtime recheck and let the runtime filter handle it.
1335 */
1336 PG_RETURN_BOOL(true);
1337 }
1338

Callers

nothing calls this directly

Calls 6

IsCollationValidFunction · 0.85
PgbsonInitIteratorFunction · 0.85
TraverseBsonFunction · 0.85

Tested by

no test coverage detected