Skip to content

Commit

Permalink
Fix wrong number of maxAttrNum in TupleSplitState (#14927)
Browse files Browse the repository at this point in the history
we cannot get corrent number of projecting targets for executing TupleSplit Node
if wrong maxAttrNum in TupleSplitState, that cause wrong results in multi-dqa sql.
```
select count(distinct a), count(distinct b) from dqa_f4 group by c;
```
For each splited tuple, we also need to project column `c` as group column besides
distinct column `a` and `b`. As a result, toal maxAttrNum of TupleSplit is three instead of two,
which also decided totals projection columns of Node Tuplesplit.
To figure maxAttrNum correctly, we need to calculate again after we initiated all elements
in TupleSplitState.
  • Loading branch information
charliettxx authored and my-ship-it committed Jan 24, 2025
1 parent 2bbaddc commit 7bc6fd4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/backend/executor/nodeTupleSplit.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ ExecInitTupleSplit(TupleSplit *node, EState *estate, int eflags)
i ++;
}

tup_spl_state->maxAttrNum = maxAttrNum;

/*
* fetch group by expr bitmap set
*/
Expand Down Expand Up @@ -146,6 +144,15 @@ ExecInitTupleSplit(TupleSplit *node, EState *estate, int eflags)
bms_free(orig_bms);
}

/*
* Update maxAttrNum which is used to calculate projection number
* of ExecTupleSplit
*/
int x = bms_prev_member(skip_split_bms, -1);
if (x > maxAttrNum)
maxAttrNum = x;
tup_spl_state->maxAttrNum = maxAttrNum;

bms_free(skip_split_bms);

return tup_spl_state;
Expand Down

0 comments on commit 7bc6fd4

Please sign in to comment.