* 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. */
| 283 | * operator and bson_query_match, used only when we cannot replace it in the planner hook. |
| 284 | */ |
| 285 | Datum |
| 286 | bson_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); |
nothing calls this directly
no test coverage detected