Skip to content

Commit b227b0b

Browse files
committed
Reduce ExecSeqScan* code size using pg_assume()
fb9f955 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 d65eb5b, 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
1 parent 01d6832 commit b227b0b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/backend/executor/nodeSeqscan.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,12 @@ ExecSeqScanWithQual(PlanState *pstate)
131131
{
132132
SeqScanState *node = castNode(SeqScanState, pstate);
133133

134+
/*
135+
* Use pg_assume() for != NULL tests to make the compiler realize no
136+
* runtime check for the field is needed in ExecScanExtended().
137+
*/
134138
Assert(pstate->state->es_epq_active == NULL);
135-
Assert(pstate->qual != NULL);
139+
pg_assume(pstate->qual != NULL);
136140
Assert(pstate->ps_ProjInfo == NULL);
137141

138142
return ExecScanExtended(&node->ss,
@@ -153,7 +157,7 @@ ExecSeqScanWithProject(PlanState *pstate)
153157

154158
Assert(pstate->state->es_epq_active == NULL);
155159
Assert(pstate->qual == NULL);
156-
Assert(pstate->ps_ProjInfo != NULL);
160+
pg_assume(pstate->ps_ProjInfo != NULL);
157161

158162
return ExecScanExtended(&node->ss,
159163
(ExecScanAccessMtd) SeqNext,
@@ -173,8 +177,8 @@ ExecSeqScanWithQualProject(PlanState *pstate)
173177
SeqScanState *node = castNode(SeqScanState, pstate);
174178

175179
Assert(pstate->state->es_epq_active == NULL);
176-
Assert(pstate->qual != NULL);
177-
Assert(pstate->ps_ProjInfo != NULL);
180+
pg_assume(pstate->qual != NULL);
181+
pg_assume(pstate->ps_ProjInfo != NULL);
178182

179183
return ExecScanExtended(&node->ss,
180184
(ExecScanAccessMtd) SeqNext,

0 commit comments

Comments
 (0)