Skip to content

Commit 06122f4

Browse files
committed
GpuSort + Limit without GpuJoin referenced pgstromSharedInnerState even though NULL pointer.
It fetched pts->inners[pts->num_inner_rels-1].dsm even though the query contains no GpuJoin to get input ntuples to the final stage.
1 parent 046fdfd commit 06122f4

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

src/executor.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3027,14 +3027,26 @@ pgstromExplainTaskState(CustomScanState *node,
30273027
pp_info->gpusort_htup_margin);
30283028
if (es->analyze && ps_state)
30293029
{
3030-
pgstromSharedInnerState *psis = pts->inners[pts->num_inner_rels-1].dsm;
3031-
30323030
appendStringInfo(&buf, " [buffer reconstruction: %umsec, GPU-sorting %umsec]",
30333031
pg_atomic_read_u32(&ps_state->final_reconstruction_msec),
30343032
pg_atomic_read_u32(&ps_state->final_sorting_msec));
3035-
final_nfiltered = (pg_atomic_read_u64(&psis->stats_join) +
3036-
pg_atomic_read_u64(&psis->stats_roj) -
3037-
pg_atomic_read_u64(&ps_state->final_nitems));
3033+
if (pts->num_inner_rels > 0)
3034+
{
3035+
pgstromSharedInnerState *psis = pts->inners[pts->num_inner_rels-1].dsm;
3036+
assert(psis != NULL);
3037+
final_nfiltered = (pg_atomic_read_u64(&psis->stats_join) +
3038+
pg_atomic_read_u64(&psis->stats_roj));
3039+
}
3040+
else
3041+
{
3042+
final_nfiltered = 0;
3043+
for (int k=0; k < pts->num_scan_rels; k++)
3044+
{
3045+
pgstromSharedScanState *psss = pts->scan_rels[k].dsm;
3046+
final_nfiltered += pg_atomic_read_u64(&psss->source_ntuples_in);
3047+
}
3048+
}
3049+
final_nfiltered -= pg_atomic_read_u64(&ps_state->final_nitems);
30383050
}
30393051
ExplainPropertyText("GPU-Sort keys", buf.data, es);
30403052

0 commit comments

Comments
 (0)