LCOV - differential code coverage report
Current view: top level - src/backend/executor - nodeSort.c (source / functions) Coverage Total Hit UBC CBC
Current: ba12a202ce1b5581dc0ed149cf3f637d7897ad5d vs 2866d8c7dbfc9d882a7d80fef93fbbe763709932 Lines: 97.7 % 131 128 3 128
Current Date: 2026-08-27 14:31:44 +0300 Functions: 100.0 % 10 10 10
Baseline: lcov-20260827-baseline Branches: 87.5 % 64 56 8 56
Baseline Date: 2026-08-27 14:31:58 +0300 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(30,360] days: 100.0 % 1 1 1
(360..) days: 97.7 % 130 127 3 127
Function coverage date bins:
(360..) days: 100.0 % 10 10 10
Branch coverage date bins:
(30,360] days: 50.0 % 2 1 1 1
(360..) days: 88.7 % 62 55 7 55

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*-------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * nodeSort.c
                                  4                 :                :  *    Routines to handle sorting of relations.
                                  5                 :                :  *
                                  6                 :                :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
                                  7                 :                :  * Portions Copyright (c) 1994, Regents of the University of California
                                  8                 :                :  *
                                  9                 :                :  *
                                 10                 :                :  * IDENTIFICATION
                                 11                 :                :  *    src/backend/executor/nodeSort.c
                                 12                 :                :  *
                                 13                 :                :  *-------------------------------------------------------------------------
                                 14                 :                :  */
                                 15                 :                : 
                                 16                 :                : #include "postgres.h"
                                 17                 :                : 
                                 18                 :                : #include "access/parallel.h"
                                 19                 :                : #include "executor/executor.h"
                                 20                 :                : #include "executor/nodeSort.h"
                                 21                 :                : #include "miscadmin.h"
                                 22                 :                : #include "utils/tuplesort.h"
                                 23                 :                : 
                                 24                 :                : 
                                 25                 :                : /* ----------------------------------------------------------------
                                 26                 :                :  *      ExecSort
                                 27                 :                :  *
                                 28                 :                :  *      Sorts tuples from the outer subtree of the node using tuplesort,
                                 29                 :                :  *      which saves the results in a temporary file or memory. After the
                                 30                 :                :  *      initial call, returns a tuple from the file with each call.
                                 31                 :                :  *
                                 32                 :                :  *      There are two distinct ways that this sort can be performed:
                                 33                 :                :  *
                                 34                 :                :  *      1) When the result is a single column we perform a Datum sort.
                                 35                 :                :  *
                                 36                 :                :  *      2) When the result contains multiple columns we perform a tuple sort.
                                 37                 :                :  *
                                 38                 :                :  *      We could do this by always performing a tuple sort, however sorting
                                 39                 :                :  *      Datums only can be significantly faster than sorting tuples,
                                 40                 :                :  *      especially when the Datums are of a pass-by-value type.
                                 41                 :                :  *
                                 42                 :                :  *      Conditions:
                                 43                 :                :  *        -- none.
                                 44                 :                :  *
                                 45                 :                :  *      Initial States:
                                 46                 :                :  *        -- the outer child is prepared to return the first tuple.
                                 47                 :                :  * ----------------------------------------------------------------
                                 48                 :                :  */
                                 49                 :                : static TupleTableSlot *
 3328 andres@anarazel.de         50                 :CBC     7303813 : ExecSort(PlanState *pstate)
                                 51                 :                : {
                                 52                 :        7303813 :     SortState  *node = castNode(SortState, pstate);
                                 53                 :                :     EState     *estate;
                                 54                 :                :     ScanDirection dir;
                                 55                 :                :     Tuplesortstate *tuplesortstate;
                                 56                 :                :     TupleTableSlot *slot;
                                 57                 :                : 
 3320                            58         [ +  + ]:        7303813 :     CHECK_FOR_INTERRUPTS();
                                 59                 :                : 
                                 60                 :                :     /*
                                 61                 :                :      * get state info from node
                                 62                 :                :      */
 8666 tgl@sss.pgh.pa.us          63                 :        7303813 :     estate = node->ss.ps.state;
10581 bruce@momjian.us           64                 :        7303813 :     dir = estate->es_direction;
 8666 tgl@sss.pgh.pa.us          65                 :        7303813 :     tuplesortstate = (Tuplesortstate *) node->tuplesortstate;
                                 66                 :                : 
                                 67                 :                :     /*
                                 68                 :                :      * If first time through, read all tuples from outer plan and pass them to
                                 69                 :                :      * tuplesort.c. Subsequent calls just fetch tuples from tuplesort.
                                 70                 :                :      */
                                 71                 :                : 
                                 72         [ +  + ]:        7303813 :     if (!node->sort_Done)
                                 73                 :                :     {
                                 74                 :          76501 :         Sort       *plannode = (Sort *) node->ss.ps.plan;
                                 75                 :                :         PlanState  *outerNode;
                                 76                 :                :         TupleDesc   tupDesc;
 1606 drowley@postgresql.o       77                 :          76501 :         int         tuplesortopts = TUPLESORT_NONE;
                                 78                 :                : 
                                 79                 :                :         /*
                                 80                 :                :          * Want to scan subplan in the forward direction while creating the
                                 81                 :                :          * sorted data.
                                 82                 :                :          */
10581 bruce@momjian.us           83                 :          76501 :         estate->es_direction = ForwardScanDirection;
                                 84                 :                : 
                                 85                 :                :         /*
                                 86                 :                :          * Initialize tuplesort module.
                                 87                 :                :          */
 8666 tgl@sss.pgh.pa.us          88                 :          76501 :         outerNode = outerPlanState(node);
 8515                            89                 :          76501 :         tupDesc = ExecGetResultType(outerNode);
                                 90                 :                : 
 1606 drowley@postgresql.o       91         [ +  + ]:          76501 :         if (node->randomAccess)
                                 92                 :           3863 :             tuplesortopts |= TUPLESORT_RANDOMACCESS;
                                 93         [ +  + ]:          76501 :         if (node->bounded)
                                 94                 :            628 :             tuplesortopts |= TUPLESORT_ALLOWBOUNDED;
                                 95                 :                : 
 1862                            96         [ +  + ]:          76501 :         if (node->datumSort)
                                 97                 :           5586 :             tuplesortstate = tuplesort_begin_datum(TupleDescAttr(tupDesc, 0)->atttypid,
                                 98                 :           5586 :                                                    plannode->sortOperators[0],
                                 99                 :           5586 :                                                    plannode->collations[0],
                                100                 :           5586 :                                                    plannode->nullsFirst[0],
                                101                 :                :                                                    work_mem,
                                102                 :                :                                                    NULL,
                                103                 :                :                                                    tuplesortopts);
                                104                 :                :         else
                                105                 :          70915 :             tuplesortstate = tuplesort_begin_heap(tupDesc,
                                106                 :                :                                                   plannode->numCols,
                                107                 :                :                                                   plannode->sortColIdx,
                                108                 :                :                                                   plannode->sortOperators,
                                109                 :                :                                                   plannode->collations,
                                110                 :                :                                                   plannode->nullsFirst,
                                111                 :                :                                                   work_mem,
                                112                 :                :                                                   NULL,
                                113                 :                :                                                   tuplesortopts);
 7055 tgl@sss.pgh.pa.us         114         [ +  + ]:          76493 :         if (node->bounded)
                                115                 :            628 :             tuplesort_set_bound(tuplesortstate, node->bound);
  637 peter@eisentraut.org      116                 :          76493 :         node->tuplesortstate = tuplesortstate;
                                117                 :                : 
                                118                 :                :         /*
                                119                 :                :          * Scan the subplan and feed all the tuples to tuplesort using the
                                120                 :                :          * appropriate method based on the type of sort we're doing.
                                121                 :                :          */
 1862 drowley@postgresql.o      122         [ +  + ]:          76493 :         if (node->datumSort)
                                123                 :                :         {
                                124                 :                :             for (;;)
                                125                 :                :             {
                                126                 :        1029217 :                 slot = ExecProcNode(outerNode);
                                127                 :                : 
                                128   [ +  +  +  + ]:        1029207 :                 if (TupIsNull(slot))
                                129                 :                :                     break;
                                130                 :        1023631 :                 slot_getsomeattrs(slot, 1);
                                131                 :        1023631 :                 tuplesort_putdatum(tuplesortstate,
                                132                 :        1023631 :                                    slot->tts_values[0],
                                133                 :        1023631 :                                    slot->tts_isnull[0]);
                                134                 :                :             }
                                135                 :                :         }
                                136                 :                :         else
                                137                 :                :         {
                                138                 :                :             for (;;)
                                139                 :                :             {
                                140                 :        7169622 :                 slot = ExecProcNode(outerNode);
                                141                 :                : 
                                142   [ +  +  +  + ]:        7169621 :                 if (TupIsNull(slot))
                                143                 :                :                     break;
                                144                 :        7098715 :                 tuplesort_puttupleslot(tuplesortstate, slot);
                                145                 :                :             }
                                146                 :                :         }
                                147                 :                : 
                                148                 :                :         /*
                                149                 :                :          * Complete the sort.
                                150                 :                :          */
 9811 tgl@sss.pgh.pa.us         151                 :          76482 :         tuplesort_performsort(tuplesortstate);
                                152                 :                : 
                                153                 :                :         /*
                                154                 :                :          * restore to user specified direction
                                155                 :                :          */
10581 bruce@momjian.us          156                 :          76482 :         estate->es_direction = dir;
                                157                 :                : 
                                158                 :                :         /*
                                159                 :                :          * finally set the sorted flag to true
                                160                 :                :          */
 8666 tgl@sss.pgh.pa.us         161                 :          76482 :         node->sort_Done = true;
 7055                           162                 :          76482 :         node->bounded_Done = node->bounded;
                                163                 :          76482 :         node->bound_Done = node->bound;
 3285 rhaas@postgresql.org      164   [ +  +  +  + ]:          76482 :         if (node->shared_info && node->am_worker)
                                165                 :                :         {
                                166                 :                :             TuplesortInstrumentation *si;
                                167                 :                : 
                                168         [ -  + ]:             64 :             Assert(IsParallelWorker());
  166 tomas.vondra@postgre      169         [ -  + ]:             64 :             Assert(ParallelWorkerNumber < node->shared_info->num_workers);
 3285 rhaas@postgresql.org      170                 :             64 :             si = &node->shared_info->sinstrument[ParallelWorkerNumber];
                                171                 :             64 :             tuplesort_get_stats(tuplesortstate, si);
                                172                 :                :         }
                                173                 :                :     }
                                174                 :                : 
 1862 drowley@postgresql.o      175                 :        7303794 :     slot = node->ss.ps.ps_ResultTupleSlot;
                                176                 :                : 
                                177                 :                :     /*
                                178                 :                :      * Fetch the next sorted item from the appropriate tuplesort function. For
                                179                 :                :      * datum sorts we must manage the slot ourselves and leave it clear when
                                180                 :                :      * tuplesort_getdatum returns false to indicate there are no more datums.
                                181                 :                :      * For tuple sorts, tuplesort_gettupleslot manages the slot for us and
                                182                 :                :      * empties the slot when it runs out of tuples.
                                183                 :                :      */
                                184         [ +  + ]:        7303794 :     if (node->datumSort)
                                185                 :                :     {
                                186                 :         834658 :         ExecClearTuple(slot);
                                187         [ +  + ]:         834658 :         if (tuplesort_getdatum(tuplesortstate, ScanDirectionIsForward(dir),
                                188                 :                :                                false, &(slot->tts_values[0]),
                                189                 :                :                                &(slot->tts_isnull[0]), NULL))
                                190                 :         829301 :             ExecStoreVirtualTuple(slot);
                                191                 :                :     }
                                192                 :                :     else
                                193                 :        6469136 :         (void) tuplesort_gettupleslot(tuplesortstate,
                                194                 :                :                                       ScanDirectionIsForward(dir),
                                195                 :                :                                       false, slot, NULL);
                                196                 :                : 
 7366 tgl@sss.pgh.pa.us         197                 :        7303794 :     return slot;
                                198                 :                : }
                                199                 :                : 
                                200                 :                : /* ----------------------------------------------------------------
                                201                 :                :  *      ExecInitSort
                                202                 :                :  *
                                203                 :                :  *      Creates the run-time state information for the sort node
                                204                 :                :  *      produced by the planner and initializes its outer subtree.
                                205                 :                :  * ----------------------------------------------------------------
                                206                 :                :  */
                                207                 :                : SortState *
 7485                           208                 :          54581 : ExecInitSort(Sort *node, EState *estate, int eflags)
                                209                 :                : {
                                210                 :                :     SortState  *sortstate;
                                211                 :                :     TupleDesc   outerTupDesc;
                                212                 :                : 
                                213                 :                :     /*
                                214                 :                :      * create state structure
                                215                 :                :      */
10581 bruce@momjian.us          216                 :          54581 :     sortstate = makeNode(SortState);
 8666 tgl@sss.pgh.pa.us         217                 :          54581 :     sortstate->ss.ps.plan = (Plan *) node;
                                218                 :          54581 :     sortstate->ss.ps.state = estate;
 3328 andres@anarazel.de        219                 :          54581 :     sortstate->ss.ps.ExecProcNode = ExecSort;
                                220                 :                : 
                                221                 :                :     /*
                                222                 :                :      * We must have random access to the sort output to do backward scan or
                                223                 :                :      * mark/restore.  We also prefer to materialize the sort output if we
                                224                 :                :      * might be called on to rewind and replay it many times.
                                225                 :                :      */
 7485 tgl@sss.pgh.pa.us         226                 :          54581 :     sortstate->randomAccess = (eflags & (EXEC_FLAG_REWIND |
                                227                 :                :                                          EXEC_FLAG_BACKWARD |
                                228                 :          54581 :                                          EXEC_FLAG_MARK)) != 0;
                                229                 :                : 
 7055                           230                 :          54581 :     sortstate->bounded = false;
 9811                           231                 :          54581 :     sortstate->sort_Done = false;
                                232                 :          54581 :     sortstate->tuplesortstate = NULL;
                                233                 :                : 
                                234                 :                :     /*
                                235                 :                :      * Miscellaneous initialization
                                236                 :                :      *
                                237                 :                :      * Sort nodes don't initialize their ExprContexts because they never call
                                238                 :                :      * ExecQual or ExecProject.
                                239                 :                :      */
                                240                 :                : 
                                241                 :                :     /*
                                242                 :                :      * initialize child nodes
                                243                 :                :      *
                                244                 :                :      * We shield the child node from the need to support REWIND, BACKWARD, or
                                245                 :                :      * MARK/RESTORE.
                                246                 :                :      */
 7485                           247                 :          54581 :     eflags &= ~(EXEC_FLAG_REWIND | EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK);
                                248                 :                : 
                                249                 :          54581 :     outerPlanState(sortstate) = ExecInitNode(outerPlan(node), estate, eflags);
                                250                 :                : 
                                251                 :                :     /*
                                252                 :                :      * Initialize scan slot and type.
                                253                 :                :      */
 2842 andres@anarazel.de        254                 :          54577 :     ExecCreateScanSlotFromOuterPlan(estate, &sortstate->ss, &TTSOpsVirtual);
                                255                 :                : 
                                256                 :                :     /*
                                257                 :                :      * Initialize return slot and type. No need to initialize projection info
                                258                 :                :      * because this node doesn't do projections.
                                259                 :                :      */
                                260                 :          54577 :     ExecInitResultTupleSlotTL(&sortstate->ss.ps, &TTSOpsMinimalTuple);
 8666 tgl@sss.pgh.pa.us         261                 :          54577 :     sortstate->ss.ps.ps_ProjInfo = NULL;
                                262                 :                : 
 1428 drowley@postgresql.o      263                 :          54577 :     outerTupDesc = ExecGetResultType(outerPlanState(sortstate));
                                264                 :                : 
                                265                 :                :     /*
                                266                 :                :      * We perform a Datum sort when we're sorting just a single column,
                                267                 :                :      * otherwise we perform a tuple sort.
                                268                 :                :      */
 1399                           269         [ +  + ]:          54577 :     if (outerTupDesc->natts == 1)
 1862                           270                 :           8166 :         sortstate->datumSort = true;
                                271                 :                :     else
                                272                 :          46411 :         sortstate->datumSort = false;
                                273                 :                : 
 8666 tgl@sss.pgh.pa.us         274                 :          54577 :     return sortstate;
                                275                 :                : }
                                276                 :                : 
                                277                 :                : /* ----------------------------------------------------------------
                                278                 :                :  *      ExecEndSort(node)
                                279                 :                :  * ----------------------------------------------------------------
                                280                 :                :  */
                                281                 :                : void
                                282                 :          54469 : ExecEndSort(SortState *node)
                                283                 :                : {
                                284                 :                :     /*
                                285                 :                :      * Release tuplesort resources
                                286                 :                :      */
                                287         [ +  + ]:          54469 :     if (node->tuplesortstate != NULL)
                                288                 :          48162 :         tuplesort_end((Tuplesortstate *) node->tuplesortstate);
                                289                 :          54469 :     node->tuplesortstate = NULL;
                                290                 :                : 
                                291                 :                :     /*
                                292                 :                :      * shut down the subplan
                                293                 :                :      */
 8656                           294                 :          54469 :     ExecEndNode(outerPlanState(node));
10581 bruce@momjian.us          295                 :          54469 : }
                                296                 :                : 
                                297                 :                : /* ----------------------------------------------------------------
                                298                 :                :  *      ExecSortMarkPos
                                299                 :                :  *
                                300                 :                :  *      Calls tuplesort to save the current position in the sorted file.
                                301                 :                :  * ----------------------------------------------------------------
                                302                 :                :  */
                                303                 :                : void
 8666 tgl@sss.pgh.pa.us         304                 :         356416 : ExecSortMarkPos(SortState *node)
                                305                 :                : {
                                306                 :                :     /*
                                307                 :                :      * if we haven't sorted yet, just return
                                308                 :                :      */
                                309         [ -  + ]:         356416 :     if (!node->sort_Done)
10581 bruce@momjian.us          310                 :UBC           0 :         return;
                                311                 :                : 
 8666 tgl@sss.pgh.pa.us         312                 :CBC      356416 :     tuplesort_markpos((Tuplesortstate *) node->tuplesortstate);
                                313                 :                : }
                                314                 :                : 
                                315                 :                : /* ----------------------------------------------------------------
                                316                 :                :  *      ExecSortRestrPos
                                317                 :                :  *
                                318                 :                :  *      Calls tuplesort to restore the last saved sort file position.
                                319                 :                :  * ----------------------------------------------------------------
                                320                 :                :  */
                                321                 :                : void
                                322                 :          24660 : ExecSortRestrPos(SortState *node)
                                323                 :                : {
                                324                 :                :     /*
                                325                 :                :      * if we haven't sorted yet, just return.
                                326                 :                :      */
                                327         [ -  + ]:          24660 :     if (!node->sort_Done)
10581 bruce@momjian.us          328                 :UBC           0 :         return;
                                329                 :                : 
                                330                 :                :     /*
                                331                 :                :      * restore the scan to the previously marked position
                                332                 :                :      */
 8666 tgl@sss.pgh.pa.us         333                 :CBC       24660 :     tuplesort_restorepos((Tuplesortstate *) node->tuplesortstate);
                                334                 :                : }
                                335                 :                : 
                                336                 :                : void
 5890                           337                 :          28838 : ExecReScanSort(SortState *node)
                                338                 :                : {
 4114 bruce@momjian.us          339                 :          28838 :     PlanState  *outerPlan = outerPlanState(node);
                                340                 :                : 
                                341                 :                :     /*
                                342                 :                :      * If we haven't sorted yet, just return. If outerplan's chgParam is not
                                343                 :                :      * NULL then it will be re-scanned by ExecProcNode, else no reason to
                                344                 :                :      * re-scan it at all.
                                345                 :                :      */
 8666 tgl@sss.pgh.pa.us         346         [ +  + ]:          28838 :     if (!node->sort_Done)
10412 vadim4o@yahoo.com         347                 :            588 :         return;
                                348                 :                : 
                                349                 :                :     /* must drop pointer to sort result tuple */
 8666 tgl@sss.pgh.pa.us         350                 :          28250 :     ExecClearTuple(node->ss.ps.ps_ResultTupleSlot);
                                351                 :                : 
                                352                 :                :     /*
                                353                 :                :      * If subnode is to be rescanned then we forget previous sort results; we
                                354                 :                :      * have to re-read the subplan and re-sort.  Also must re-sort if the
                                355                 :                :      * bounded-sort parameters changed or we didn't select randomAccess.
                                356                 :                :      *
                                357                 :                :      * Otherwise we can just rewind and rescan the sorted output.
                                358                 :                :      */
 4133 rhaas@postgresql.org      359         [ +  + ]:          28250 :     if (outerPlan->chgParam != NULL ||
 7055 tgl@sss.pgh.pa.us         360         [ +  - ]:            413 :         node->bounded != node->bounded_Done ||
                                361         [ +  + ]:            413 :         node->bound != node->bound_Done ||
 7485                           362         [ +  + ]:            377 :         !node->randomAccess)
                                363                 :                :     {
 8666                           364                 :          28231 :         node->sort_Done = false;
                                365                 :          28231 :         tuplesort_end((Tuplesortstate *) node->tuplesortstate);
                                366                 :          28231 :         node->tuplesortstate = NULL;
                                367                 :                : 
                                368                 :                :         /*
                                369                 :                :          * if chgParam of subnode is not null then plan will be re-scanned by
                                370                 :                :          * first ExecProcNode.
                                371                 :                :          */
 4133 rhaas@postgresql.org      372         [ +  + ]:          28231 :         if (outerPlan->chgParam == NULL)
                                373                 :            394 :             ExecReScan(outerPlan);
                                374                 :                :     }
                                375                 :                :     else
 8666 tgl@sss.pgh.pa.us         376                 :             19 :         tuplesort_rescan((Tuplesortstate *) node->tuplesortstate);
                                377                 :                : }
                                378                 :                : 
                                379                 :                : /* ----------------------------------------------------------------
                                380                 :                :  *                      Parallel Query Support
                                381                 :                :  * ----------------------------------------------------------------
                                382                 :                :  */
                                383                 :                : 
                                384                 :                : /* ----------------------------------------------------------------
                                385                 :                :  *      ExecSortEstimate
                                386                 :                :  *
                                387                 :                :  *      Estimate space required to propagate sort statistics.
                                388                 :                :  * ----------------------------------------------------------------
                                389                 :                :  */
                                390                 :                : void
 3285 rhaas@postgresql.org      391                 :            201 : ExecSortEstimate(SortState *node, ParallelContext *pcxt)
                                392                 :                : {
                                393                 :                :     Size        size;
                                394                 :                : 
                                395                 :                :     /* don't need this if not instrumenting or no workers */
                                396   [ +  +  -  + ]:            201 :     if (!node->ss.ps.instrument || pcxt->nworkers == 0)
                                397                 :            193 :         return;
                                398                 :                : 
                                399                 :              8 :     size = mul_size(pcxt->nworkers, sizeof(TuplesortInstrumentation));
                                400                 :              8 :     size = add_size(size, offsetof(SharedSortInfo, sinstrument));
                                401                 :              8 :     shm_toc_estimate_chunk(&pcxt->estimator, size);
                                402                 :              8 :     shm_toc_estimate_keys(&pcxt->estimator, 1);
                                403                 :                : }
                                404                 :                : 
                                405                 :                : /* ----------------------------------------------------------------
                                406                 :                :  *      ExecSortInitializeDSM
                                407                 :                :  *
                                408                 :                :  *      Initialize DSM space for sort statistics.
                                409                 :                :  * ----------------------------------------------------------------
                                410                 :                :  */
                                411                 :                : void
                                412                 :            201 : ExecSortInitializeDSM(SortState *node, ParallelContext *pcxt)
                                413                 :                : {
                                414                 :                :     Size        size;
                                415                 :                : 
                                416                 :                :     /* don't need this if not instrumenting or no workers */
                                417   [ +  +  -  + ]:            201 :     if (!node->ss.ps.instrument || pcxt->nworkers == 0)
                                418                 :            193 :         return;
                                419                 :                : 
                                420                 :              8 :     size = offsetof(SharedSortInfo, sinstrument)
                                421                 :              8 :         + pcxt->nworkers * sizeof(TuplesortInstrumentation);
                                422                 :              8 :     node->shared_info = shm_toc_allocate(pcxt->toc, size);
                                423                 :                :     /* ensure any unfilled slots will contain zeroes */
                                424                 :              8 :     memset(node->shared_info, 0, size);
                                425                 :              8 :     node->shared_info->num_workers = pcxt->nworkers;
                                426                 :              8 :     shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id,
                                427                 :              8 :                    node->shared_info);
                                428                 :                : }
                                429                 :                : 
                                430                 :                : /* ----------------------------------------------------------------
                                431                 :                :  *      ExecSortInitializeWorker
                                432                 :                :  *
                                433                 :                :  *      Attach worker to DSM space for sort statistics.
                                434                 :                :  * ----------------------------------------------------------------
                                435                 :                :  */
                                436                 :                : void
 3206 andres@anarazel.de        437                 :            501 : ExecSortInitializeWorker(SortState *node, ParallelWorkerContext *pwcxt)
                                438                 :                : {
 3285 rhaas@postgresql.org      439                 :            501 :     node->shared_info =
 3206 andres@anarazel.de        440                 :            501 :         shm_toc_lookup(pwcxt->toc, node->ss.ps.plan->plan_node_id, true);
 3285 rhaas@postgresql.org      441                 :            501 :     node->am_worker = true;
                                442                 :            501 : }
                                443                 :                : 
                                444                 :                : /* ----------------------------------------------------------------
                                445                 :                :  *      ExecSortRetrieveInstrumentation
                                446                 :                :  *
                                447                 :                :  *      Transfer sort statistics from DSM to private memory.
                                448                 :                :  * ----------------------------------------------------------------
                                449                 :                :  */
                                450                 :                : void
                                451                 :              8 : ExecSortRetrieveInstrumentation(SortState *node)
                                452                 :                : {
                                453                 :                :     Size        size;
                                454                 :                :     SharedSortInfo *si;
                                455                 :                : 
                                456         [ -  + ]:              8 :     if (node->shared_info == NULL)
 3285 rhaas@postgresql.org      457                 :UBC           0 :         return;
                                458                 :                : 
 3285 rhaas@postgresql.org      459                 :CBC           8 :     size = offsetof(SharedSortInfo, sinstrument)
                                460                 :              8 :         + node->shared_info->num_workers * sizeof(TuplesortInstrumentation);
                                461                 :              8 :     si = palloc(size);
                                462                 :              8 :     memcpy(si, node->shared_info, size);
                                463                 :              8 :     node->shared_info = si;
                                464                 :                : }
        

Generated by: LCOV version 2.0-1