* GinBsonExtractQueryLess generates the index term needed to match * $lg and $lte on a dotted path and value. * In this case, We return a lower bound value of the min value for that path. * Since we set the PartialMatch value to be true, the min value will be considered * a lower bound for the indexed search. * We also pass 'extraData' being the value being queried. This will later be treated
| 2305 | * i.e. a BsonElement. |
| 2306 | */ |
| 2307 | static Datum * |
| 2308 | GinBsonExtractQueryLess(BsonExtractQueryArgs *args, bool isNegation) |
| 2309 | { |
| 2310 | int32 *nentries = args->nentries; |
| 2311 | bool **partialmatch = args->partialmatch; |
| 2312 | Pointer **extra_data = args->extra_data; |
| 2313 | Datum *entries; |
| 2314 | pgbsonelement documentElement = args->filterElement; |
| 2315 | |
| 2316 | /* Clone it for now */ |
| 2317 | pgbsonelement queryElement = documentElement; |
| 2318 | |
| 2319 | int numEntries = isNegation ? 5 : 2; |
| 2320 | entries = (Datum *) palloc(sizeof(Datum) * numEntries); |
| 2321 | *partialmatch = (bool *) palloc(sizeof(bool) * numEntries); |
| 2322 | *nentries = 1; |
| 2323 | (*partialmatch)[0] = true; |
| 2324 | |
| 2325 | /* store the query value in extra data - this allows us to compute upper bound using */ |
| 2326 | /* this extra value. */ |
| 2327 | |
| 2328 | /* Also serialize the actual index term */ |
| 2329 | BsonIndexTermSerialized serializedTerm = |
| 2330 | SerializeBsonIndexTerm(&queryElement, &args->termMetadata); |
| 2331 | |
| 2332 | *extra_data = (Pointer *) palloc0(sizeof(Pointer) * numEntries); |
| 2333 | (*extra_data)[0] = (Pointer) serializedTerm.indexTermVal; |
| 2334 | |
| 2335 | /* now create a bson for that path which has the min value for the field */ |
| 2336 | /* Today we set this as the min value for the equivalent */ |
| 2337 | /* type (i.e. the lowest possible value for that type OR the highest possible value of the prior type) */ |
| 2338 | /* When we don't have the table of these values, we safely start out with Minkey. */ |
| 2339 | documentElement.bsonValue = GetLowerBoundForLessThan( |
| 2340 | queryElement.bsonValue.value_type); |
| 2341 | entries[0] = PointerGetDatum(SerializeBsonIndexTerm(&documentElement, |
| 2342 | &args->termMetadata). |
| 2343 | indexTermVal); |
| 2344 | |
| 2345 | /* In the case where we have truncation, also track equality on $lt */ |
| 2346 | if (serializedTerm.isIndexTermTruncated || isNegation) |
| 2347 | { |
| 2348 | *nentries = 2; |
| 2349 | (*partialmatch)[1] = false; |
| 2350 | entries[1] = PointerGetDatum(serializedTerm.indexTermVal); |
| 2351 | } |
| 2352 | |
| 2353 | if (isNegation) |
| 2354 | { |
| 2355 | GenerateNegationTerms(entries, *nentries, *partialmatch, &args->termMetadata); |
| 2356 | *nentries += 3; |
| 2357 | } |
| 2358 | |
| 2359 | return entries; |
| 2360 | } |
| 2361 | |
| 2362 | |
| 2363 | /* |
no test coverage detected