Make tuplesort_set_bound() assertions more comprehensible, hopefully.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 13 Sep 2019 20:56:58 +0000 (16:56 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 13 Sep 2019 20:57:07 +0000 (16:57 -0400)
Add the comments that I griped were missing.  Also re-order tests
so that parallelism-related tests aren't randomly separated from
each other.

Discussion: https://postgr.es/m/CAAaqYe9GD__4Crm=ddz+-XXcNhfY_V5gFYdLdmkFNq=2VHO56Q@mail.gmail.com

src/backend/utils/sort/tuplesort.c

index 152daa72e1c1f300f816aa062ebfbb8b4fc82f53..ab55e69975cb4ed94b1623480e35696304710d21 100644 (file)
@@ -1187,20 +1187,21 @@ tuplesort_set_bound(Tuplesortstate *state, int64 bound)
 {
    /* Assert we're called before loading any tuples */
    Assert(state->status == TSS_INITIAL && state->memtupcount == 0);
-
+   /* Can't set the bound twice, either */
    Assert(!state->bounded);
+   /* Also, this shouldn't be called in a parallel worker */
    Assert(!WORKER(state));
 
+   /* Parallel leader allows but ignores hint */
+   if (LEADER(state))
+       return;
+
 #ifdef DEBUG_BOUNDED_SORT
    /* Honor GUC setting that disables the feature (for easy testing) */
    if (!optimize_bounded_sort)
        return;
 #endif
 
-   /* Parallel leader ignores hint */
-   if (LEADER(state))
-       return;
-
    /* We want to be able to compute bound * 2, so limit the setting */
    if (bound > (int64) (INT_MAX / 2))
        return;