* ExecIndexEvalRuntimeKeys * Evaluate any runtime key values, and update the scankeys. */
| 599 | * Evaluate any runtime key values, and update the scankeys. |
| 600 | */ |
| 601 | void |
| 602 | ExecIndexEvalRuntimeKeys(ExprContext *econtext, |
| 603 | IndexRuntimeKeyInfo *runtimeKeys, int numRuntimeKeys) |
| 604 | { |
| 605 | int j; |
| 606 | MemoryContext oldContext; |
| 607 | |
| 608 | /* We want to keep the key values in per-tuple memory */ |
| 609 | oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory); |
| 610 | |
| 611 | for (j = 0; j < numRuntimeKeys; j++) |
| 612 | { |
| 613 | ScanKey scan_key = runtimeKeys[j].scan_key; |
| 614 | ExprState *key_expr = runtimeKeys[j].key_expr; |
| 615 | Datum scanvalue; |
| 616 | bool isNull; |
| 617 | |
| 618 | /* |
| 619 | * For each run-time key, extract the run-time expression and evaluate |
| 620 | * it with respect to the current context. We then stick the result |
| 621 | * into the proper scan key. |
| 622 | * |
| 623 | * Note: the result of the eval could be a pass-by-ref value that's |
| 624 | * stored in some outer scan's tuple, not in |
| 625 | * econtext->ecxt_per_tuple_memory. We assume that the outer tuple |
| 626 | * will stay put throughout our scan. If this is wrong, we could copy |
| 627 | * the result into our context explicitly, but I think that's not |
| 628 | * necessary. |
| 629 | * |
| 630 | * It's also entirely possible that the result of the eval is a |
| 631 | * toasted value. In this case we should forcibly detoast it, to |
| 632 | * avoid repeat detoastings each time the value is examined by an |
| 633 | * index support function. |
| 634 | */ |
| 635 | scanvalue = ExecEvalExpr(key_expr, |
| 636 | econtext, |
| 637 | &isNull); |
| 638 | if (isNull) |
| 639 | { |
| 640 | scan_key->sk_argument = scanvalue; |
| 641 | scan_key->sk_flags |= SK_ISNULL; |
| 642 | } |
| 643 | else |
| 644 | { |
| 645 | if (runtimeKeys[j].key_toastable) |
| 646 | scanvalue = PointerGetDatum(PG_DETOAST_DATUM(scanvalue)); |
| 647 | scan_key->sk_argument = scanvalue; |
| 648 | scan_key->sk_flags &= ~SK_ISNULL; |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | MemoryContextSwitchTo(oldContext); |
| 653 | } |
| 654 | |
| 655 | /* |
| 656 | * ExecIndexEvalArrayKeys |
no test coverage detected