* Prepare to finalize and project based on the specified representative tuple * slot and grouping set. * * In the specified tuple slot, force to null all attributes that should be * read as null in the context of the current grouping set. Also stash the * current group bitmap where GroupingExpr can get at it. * * This relies on three conditions: * * 1) Nothing is ever going to try and ex
| 1306 | * alternative was worse. |
| 1307 | */ |
| 1308 | static void |
| 1309 | prepare_projection_slot(AggState *aggstate, TupleTableSlot *slot, int currentSet) |
| 1310 | { |
| 1311 | if (aggstate->phase->grouped_cols) |
| 1312 | { |
| 1313 | Bitmapset *grouped_cols = aggstate->phase->grouped_cols[currentSet]; |
| 1314 | |
| 1315 | aggstate->grouped_cols = grouped_cols; |
| 1316 | aggstate->group_id = aggstate->phase->group_id[currentSet]; |
| 1317 | aggstate->gset_id = aggstate->phase->gset_id[currentSet]; |
| 1318 | |
| 1319 | if (TTS_EMPTY(slot)) |
| 1320 | { |
| 1321 | /* |
| 1322 | * Force all values to be NULL if working on an empty input tuple |
| 1323 | * (i.e. an empty grouping set for which no input rows were |
| 1324 | * supplied). |
| 1325 | */ |
| 1326 | ExecStoreAllNullTuple(slot); |
| 1327 | } |
| 1328 | else if (aggstate->all_grouped_cols) |
| 1329 | { |
| 1330 | ListCell *lc; |
| 1331 | |
| 1332 | /* all_grouped_cols is arranged in desc order */ |
| 1333 | slot_getsomeattrs(slot, linitial_int(aggstate->all_grouped_cols)); |
| 1334 | |
| 1335 | foreach(lc, aggstate->all_grouped_cols) |
| 1336 | { |
| 1337 | int attnum = lfirst_int(lc); |
| 1338 | |
| 1339 | if (!bms_is_member(attnum, grouped_cols)) |
| 1340 | slot->tts_isnull[attnum - 1] = true; |
| 1341 | } |
| 1342 | } |
| 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | /* |
| 1347 | * Compute the final value of all aggregates for one group. |
no test coverage detected