-------------------------------- * MakeTupleTableSlot * * Basic routine to make an empty TupleTableSlot of given * TupleTableSlotType. If tupleDesc is specified the slot's descriptor is * fixed for its lifetime, gaining some efficiency. If that's * undesirable, pass NULL. * -------------------------------- */
| 1126 | * -------------------------------- |
| 1127 | */ |
| 1128 | TupleTableSlot * |
| 1129 | MakeTupleTableSlot(TupleDesc tupleDesc, |
| 1130 | const TupleTableSlotOps *tts_ops) |
| 1131 | { |
| 1132 | Size basesz, |
| 1133 | allocsz; |
| 1134 | TupleTableSlot *slot; |
| 1135 | |
| 1136 | basesz = tts_ops->base_slot_size; |
| 1137 | |
| 1138 | /* |
| 1139 | * When a fixed descriptor is specified, we can reduce overhead by |
| 1140 | * allocating the entire slot in one go. |
| 1141 | */ |
| 1142 | if (tupleDesc) |
| 1143 | allocsz = MAXALIGN(basesz) + |
| 1144 | MAXALIGN(tupleDesc->natts * sizeof(Datum)) + |
| 1145 | MAXALIGN(tupleDesc->natts * sizeof(bool)); |
| 1146 | else |
| 1147 | allocsz = basesz; |
| 1148 | |
| 1149 | slot = palloc0(allocsz); |
| 1150 | /* const for optimization purposes, OK to modify at allocation time */ |
| 1151 | *((const TupleTableSlotOps **) &slot->tts_ops) = tts_ops; |
| 1152 | slot->type = T_TupleTableSlot; |
| 1153 | slot->tts_flags |= TTS_FLAG_EMPTY; |
| 1154 | if (tupleDesc != NULL) |
| 1155 | slot->tts_flags |= TTS_FLAG_FIXED; |
| 1156 | slot->tts_tupleDescriptor = tupleDesc; |
| 1157 | slot->tts_mcxt = CurrentMemoryContext; |
| 1158 | slot->tts_nvalid = 0; |
| 1159 | |
| 1160 | if (tupleDesc != NULL) |
| 1161 | { |
| 1162 | slot->tts_values = (Datum *) |
| 1163 | (((char *) slot) |
| 1164 | + MAXALIGN(basesz)); |
| 1165 | slot->tts_isnull = (bool *) |
| 1166 | (((char *) slot) |
| 1167 | + MAXALIGN(basesz) |
| 1168 | + MAXALIGN(tupleDesc->natts * sizeof(Datum))); |
| 1169 | |
| 1170 | PinTupleDesc(tupleDesc); |
| 1171 | } |
| 1172 | |
| 1173 | /* |
| 1174 | * And allow slot type specific initialization. |
| 1175 | */ |
| 1176 | slot->tts_ops->init(slot); |
| 1177 | |
| 1178 | return slot; |
| 1179 | } |
| 1180 | |
| 1181 | /* -------------------------------- |
| 1182 | * ExecAllocTableSlot |