* execTuplesUnequal * Return true if two tuples are definitely unequal in the indicated * fields. * * Nulls are neither equal nor unequal to anything else. A true result * is obtained only if there are non-null fields that compare not-equal. * * slot1, slot2: the tuples to compare (must have same columns!) * numCols: the number of attributes to be examined * matchColIdx: array of attri
| 657 | * evalContext: short-term memory context for executing the functions |
| 658 | */ |
| 659 | static bool |
| 660 | execTuplesUnequal(TupleTableSlot *slot1, |
| 661 | TupleTableSlot *slot2, |
| 662 | int numCols, |
| 663 | AttrNumber *matchColIdx, |
| 664 | FmgrInfo *eqfunctions, |
| 665 | const Oid *collations, |
| 666 | MemoryContext evalContext) |
| 667 | { |
| 668 | MemoryContext oldContext; |
| 669 | bool result; |
| 670 | int i; |
| 671 | |
| 672 | /* Reset and switch into the temp context. */ |
| 673 | MemoryContextReset(evalContext); |
| 674 | oldContext = MemoryContextSwitchTo(evalContext); |
| 675 | |
| 676 | /* |
| 677 | * We cannot report a match without checking all the fields, but we can |
| 678 | * report a non-match as soon as we find unequal fields. So, start |
| 679 | * comparing at the last field (least significant sort key). That's the |
| 680 | * most likely to be different if we are dealing with sorted input. |
| 681 | */ |
| 682 | result = false; |
| 683 | |
| 684 | for (i = numCols; --i >= 0;) |
| 685 | { |
| 686 | AttrNumber att = matchColIdx[i]; |
| 687 | Datum attr1, |
| 688 | attr2; |
| 689 | bool isNull1, |
| 690 | isNull2; |
| 691 | |
| 692 | attr1 = slot_getattr(slot1, att, &isNull1); |
| 693 | |
| 694 | if (isNull1) |
| 695 | continue; /* can't prove anything here */ |
| 696 | |
| 697 | attr2 = slot_getattr(slot2, att, &isNull2); |
| 698 | |
| 699 | if (isNull2) |
| 700 | continue; /* can't prove anything here */ |
| 701 | |
| 702 | /* Apply the type-specific equality function */ |
| 703 | if (!DatumGetBool(FunctionCall2Coll(&eqfunctions[i], |
| 704 | collations[i], |
| 705 | attr1, attr2))) |
| 706 | { |
| 707 | result = true; /* they are unequal */ |
| 708 | break; |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | MemoryContextSwitchTo(oldContext); |
| 713 | |
| 714 | return result; |
| 715 | } |
| 716 |
no test coverage detected