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

Function bson_query_match

pg_documentdb/src/query/query_operator.c:285–365  ·  view source on GitHub ↗

* bson_query_match is a lazy, inefficient implementation of the @@ * operator and bson_query_match, used only when we cannot replace it in the planner hook. */

Source from the content-addressed store, hash-verified

283 * operator and bson_query_match, used only when we cannot replace it in the planner hook.
284 */
285Datum
286bson_query_match(PG_FUNCTION_ARGS)
287{
288 pgbson *document = PG_GETARG_PGBSON(0);
289 pgbson *query = PG_GETARG_PGBSON(1);
290
291 Const *documentConst = MakeBsonConst(document);
292 Const *queryConst = MakeBsonConst(query);
293
294 ereport(NOTICE, (errmsg("using bson_query_match implementation")));
295
296 ReplaceBsonQueryOperatorsContext context;
297 memset(&context, 0, sizeof(context));
298
299 Node *quals = NULL;
300 if (PG_NARGS() == 2)
301 {
302 /* Expand the @@ operator into regular BSON operators */
303 OpExpr *queryExpr = makeNode(OpExpr);
304 queryExpr->opno = BsonQueryOperatorId();
305 queryExpr->opfuncid = BsonQueryMatchFunctionId();
306 queryExpr->inputcollid = InvalidOid;
307 queryExpr->opresulttype = BsonTypeId();
308 queryExpr->args = list_make2(documentConst, queryConst);
309 queryExpr->location = -1;
310
311 quals = ReplaceBsonQueryOperatorsMutator((Node *) queryExpr, &context);
312 }
313 else if (PG_NARGS() == 4)
314 {
315 /* TODO: Remove after v0.110 when function has only STRICT forms */
316 if (PG_ARGISNULL(0) && PG_ARGISNULL(1))
317 {
318 PG_RETURN_NULL();
319 }
320
321 Const *variableSpecConst = NULL;
322 if (PG_ARGISNULL(2))
323 {
324 variableSpecConst = MakeBsonConst(PgbsonInitEmpty());
325 }
326 else
327 {
328 pgbson *variableSpecBson = PG_GETARG_PGBSON(2);
329 variableSpecConst = MakeBsonConst(variableSpecBson);
330 }
331
332 Const *collationConst = NULL;
333 if (PG_ARGISNULL(3))
334 {
335 collationConst = makeConst(TEXTOID, -1, InvalidOid, -1,
336 CStringGetDatum(""), false, false);
337 }
338 else
339 {
340 Datum collationDatum = CStringGetDatum(PG_GETARG_CSTRING(3));
341 collationConst = makeConst(TEXTOID, -1, InvalidOid, -1, collationDatum,
342 false, false);

Callers

nothing calls this directly

Calls 7

BsonQueryOperatorIdFunction · 0.85
BsonQueryMatchFunctionIdFunction · 0.85
BsonTypeIdFunction · 0.85
PgbsonInitEmptyFunction · 0.85
MakeBsonConstFunction · 0.70

Tested by

no test coverage detected