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

Function evalHashKey

src/backend/executor/nodeMotion.c:1087–1139  ·  view source on GitHub ↗

* Experimental code that will be replaced later with new hashing mechanism */

Source from the content-addressed store, hash-verified

1085 * Experimental code that will be replaced later with new hashing mechanism
1086 */
1087uint32
1088evalHashKey(ExprContext *econtext, List *hashkeys, CdbHash * h)
1089{
1090 ListCell *hk;
1091 MemoryContext oldContext;
1092 unsigned int target_seg;
1093
1094 ResetExprContext(econtext);
1095
1096 oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
1097
1098 /*
1099 * If we have 1 or more distribution keys for this relation, hash them.
1100 * However, If this happens to be a relation with an empty policy
1101 * (partitioning policy with a NULL distribution key list) then we have no
1102 * hash key value to feed in, so use cdbhashrandomseg() to pick a segment
1103 * at random.
1104 */
1105 if (list_length(hashkeys) > 0)
1106 {
1107 int i;
1108
1109 cdbhashinit(h);
1110
1111 i = 0;
1112 foreach(hk, hashkeys)
1113 {
1114 ExprState *keyexpr = (ExprState *) lfirst(hk);
1115 Datum keyval;
1116 bool isNull;
1117
1118 /*
1119 * Get the attribute value of the tuple
1120 */
1121 keyval = ExecEvalExpr(keyexpr, econtext, &isNull);
1122
1123 /*
1124 * Compute the hash function
1125 */
1126 cdbhash(h, i + 1, keyval, isNull);
1127 i++;
1128 }
1129 target_seg = cdbhashreduce(h);
1130 }
1131 else
1132 {
1133 target_seg = cdbhashrandomseg(h->numsegs);
1134 }
1135
1136 MemoryContextSwitchTo(oldContext);
1137
1138 return target_seg;
1139}
1140
1141
1142void

Callers 1

doSendTupleFunction · 0.70

Calls 8

MemoryContextSwitchToFunction · 0.85
list_lengthFunction · 0.85
cdbhashinitFunction · 0.85
ExecEvalExprFunction · 0.85
cdbhashFunction · 0.85
cdbhashreduceFunction · 0.85
cdbhashrandomsegFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected