summaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeWindowAgg.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2025-10-09 10:33:55 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2025-10-09 10:33:55 -0400
commit71540dcdcb2239d9398c586615761d5ea424aaf0 (patch)
tree1c37ee193df6775226c1e1c10e67b9cb9b056613 /src/backend/executor/nodeWindowAgg.c
parent36fd8bde1b77191eaf7d3499052c0636b6b93a87 (diff)
Avoid uninitialized-variable warnings from older compilers.
Some of the buildfarm is still unhappy with WinGetFuncArgInPartition even after 2273fa32b. While it seems to be just very old compilers, we can suppress the warnings and arguably make the code more readable by not initializing these variables till closer to where they are used. While at it, make a couple of cosmetic comment improvements.
Diffstat (limited to 'src/backend/executor/nodeWindowAgg.c')
-rw-r--r--src/backend/executor/nodeWindowAgg.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/src/backend/executor/nodeWindowAgg.c b/src/backend/executor/nodeWindowAgg.c
index 0698aae37a7..e6a53f95391 100644
--- a/src/backend/executor/nodeWindowAgg.c
+++ b/src/backend/executor/nodeWindowAgg.c
@@ -3271,7 +3271,7 @@ window_gettupleslot(WindowObject winobj, int64 pos, TupleTableSlot *slot)
}
/*
- * get tupple and evaluate in a partition
+ * get tuple and evaluate in partition
*/
static Datum
gettuple_eval_partition(WindowObject winobj, int argno,
@@ -3718,7 +3718,7 @@ WinGetFuncArgInPartition(WindowObject winobj, int argno,
WindowAggState *winstate;
int64 abs_pos;
Datum datum;
- bool null_treatment = false;
+ bool null_treatment;
int notnull_offset;
int notnull_relpos;
int forward;
@@ -3727,13 +3727,7 @@ WinGetFuncArgInPartition(WindowObject winobj, int argno,
Assert(WindowObjectIsValid(winobj));
winstate = winobj->winstate;
- if (winobj->ignore_nulls == IGNORE_NULLS && relpos != 0)
- {
- null_treatment = true;
- notnull_offset = 0;
- notnull_relpos = abs(relpos);
- forward = relpos > 0 ? 1 : -1;
- }
+ null_treatment = (winobj->ignore_nulls == IGNORE_NULLS && relpos != 0);
switch (seektype)
{
@@ -3759,9 +3753,10 @@ WinGetFuncArgInPartition(WindowObject winobj, int argno,
break;
}
- if (!null_treatment) /* IGNORE NULLS is not specified */
+ /* Easy case if IGNORE NULLS is not specified */
+ if (!null_treatment)
{
- /* get tupple and evaluate in a partition */
+ /* get tuple and evaluate in partition */
datum = gettuple_eval_partition(winobj, argno,
abs_pos, isnull, &myisout);
if (!myisout && set_mark)
@@ -3771,32 +3766,35 @@ WinGetFuncArgInPartition(WindowObject winobj, int argno,
return datum;
}
+ /* Prepare for loop */
+ notnull_offset = 0;
+ notnull_relpos = abs(relpos);
+ forward = relpos > 0 ? 1 : -1;
myisout = false;
datum = 0;
/*
* Get the next nonnull value in the partition, moving forward or backward
- * until we find a value or reach the partition's end.
+ * until we find a value or reach the partition's end. We cache the
+ * nullness status because we may repeat this process many times.
*/
do
{
- int nn_info; /* NOT NULL info */
+ int nn_info; /* NOT NULL status */
abs_pos += forward;
- if (abs_pos < 0) /* apparently out of partition */
+ if (abs_pos < 0) /* clearly out of partition */
break;
/* check NOT NULL cached info */
nn_info = get_notnull_info(winobj, abs_pos);
if (nn_info == NN_NOTNULL) /* this row is known to be NOT NULL */
notnull_offset++;
-
else if (nn_info == NN_NULL) /* this row is known to be NULL */
continue; /* keep on moving forward or backward */
-
else /* need to check NULL or not */
{
- /* get tupple and evaluate in a partition */
+ /* get tuple and evaluate in partition */
datum = gettuple_eval_partition(winobj, argno,
abs_pos, isnull, &myisout);
if (myisout) /* out of partition? */
@@ -3808,7 +3806,7 @@ WinGetFuncArgInPartition(WindowObject winobj, int argno,
}
} while (notnull_offset < notnull_relpos);
- /* get tupple and evaluate in a partition */
+ /* get tuple and evaluate in partition */
datum = gettuple_eval_partition(winobj, argno,
abs_pos, isnull, &myisout);
if (!myisout && set_mark)