MCPcopy Create free account
hub / github.com/apache/cloudberry / CdbMergeComparator

Function CdbMergeComparator

src/backend/executor/nodeMotion.c:1038–1082  ·  view source on GitHub ↗

* CdbMergeComparator: * Used to compare tuples for a sorted motion node. */

Source from the content-addressed store, hash-verified

1036 * Used to compare tuples for a sorted motion node.
1037 */
1038static int
1039CdbMergeComparator(Datum lhs, Datum rhs, void *context)
1040{
1041 MotionState *node = (MotionState *) context;
1042 int lSegIdx = DatumGetInt32(lhs);
1043 int rSegIdx = DatumGetInt32(rhs);
1044
1045 TupleTableSlot *lslot = node->slots[lSegIdx];
1046 TupleTableSlot *rslot = node->slots[rSegIdx];
1047 SortSupport sortKeys = node->sortKeys;
1048 int nkey;
1049 int compare;
1050
1051 Assert(lslot && rslot);
1052
1053 for (nkey = 0; nkey < node->numSortCols; nkey++)
1054 {
1055 SortSupport ssup = &sortKeys[nkey];
1056 AttrNumber attno = ssup->ssup_attno;
1057 Datum datum1,
1058 datum2;
1059 bool isnull1,
1060 isnull2;
1061
1062 /*
1063 * The caller has called slot_getsomeattrs() to ensure
1064 * that all the columns we need are available directly in
1065 * the values/isnull arrays.
1066 */
1067 datum1 = lslot->tts_values[attno - 1];
1068 isnull1 = lslot->tts_isnull[attno - 1];
1069 datum2 = rslot->tts_values[attno - 1];
1070 isnull2 = rslot->tts_isnull[attno - 1];
1071
1072 compare = ApplySortComparator(datum1, isnull1,
1073 datum2, isnull2,
1074 ssup);
1075 if (compare != 0)
1076 {
1077 INVERT_COMPARE_RESULT(compare);
1078 return compare;
1079 }
1080 }
1081 return 0;
1082} /* CdbMergeComparator */
1083
1084/*
1085 * Experimental code that will be replaced later with new hashing mechanism

Callers

nothing calls this directly

Calls 2

DatumGetInt32Function · 0.85
ApplySortComparatorFunction · 0.85

Tested by

no test coverage detected