Reduce ExecSeqScan* code size using pg_assume()

fb9f955025 optimized code generation by using specialized variants of
ExecSeqScan* for [not] having a qual, projection etc. This allowed the
compiler to optimize the code out the code for qual / projection. However, as
observed by David Rowley at the time, the compiler couldn't prove the
opposite, i.e. that the qual etc *are* present.

By using pg_assume(), introduced in d65eb5b1b8, we can tell the compiler that
the relevant variables are non-null.

This reduces the code size to a surprising degree and seems to lead to a small
but reproducible performance gain.

Reviewed-by: Amit Langote <amitlangote09@gmail.com> Discussion:
https://postgr.es/m/CA+HiwqFk-MbwhfX_kucxzL8zLmjEt9MMcHi2YF=DyhPrSjsBEA@mail.gmail.com
pull/239/head
Andres Freund 1 month ago
parent 01d6832c10
commit b227b0bb4e
  1. 12
      src/backend/executor/nodeSeqscan.c

@ -131,8 +131,12 @@ ExecSeqScanWithQual(PlanState *pstate)
{ {
SeqScanState *node = castNode(SeqScanState, pstate); SeqScanState *node = castNode(SeqScanState, pstate);
/*
* Use pg_assume() for != NULL tests to make the compiler realize no
* runtime check for the field is needed in ExecScanExtended().
*/
Assert(pstate->state->es_epq_active == NULL); Assert(pstate->state->es_epq_active == NULL);
Assert(pstate->qual != NULL); pg_assume(pstate->qual != NULL);
Assert(pstate->ps_ProjInfo == NULL); Assert(pstate->ps_ProjInfo == NULL);
return ExecScanExtended(&node->ss, return ExecScanExtended(&node->ss,
@ -153,7 +157,7 @@ ExecSeqScanWithProject(PlanState *pstate)
Assert(pstate->state->es_epq_active == NULL); Assert(pstate->state->es_epq_active == NULL);
Assert(pstate->qual == NULL); Assert(pstate->qual == NULL);
Assert(pstate->ps_ProjInfo != NULL); pg_assume(pstate->ps_ProjInfo != NULL);
return ExecScanExtended(&node->ss, return ExecScanExtended(&node->ss,
(ExecScanAccessMtd) SeqNext, (ExecScanAccessMtd) SeqNext,
@ -173,8 +177,8 @@ ExecSeqScanWithQualProject(PlanState *pstate)
SeqScanState *node = castNode(SeqScanState, pstate); SeqScanState *node = castNode(SeqScanState, pstate);
Assert(pstate->state->es_epq_active == NULL); Assert(pstate->state->es_epq_active == NULL);
Assert(pstate->qual != NULL); pg_assume(pstate->qual != NULL);
Assert(pstate->ps_ProjInfo != NULL); pg_assume(pstate->ps_ProjInfo != NULL);
return ExecScanExtended(&node->ss, return ExecScanExtended(&node->ss,
(ExecScanAccessMtd) SeqNext, (ExecScanAccessMtd) SeqNext,

Loading…
Cancel
Save