Skip to content

Commit a7b05c0

Browse files

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

lib/nbtree/nbtsort-18.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* This code isn't concerned about the FSM at all. The caller is responsible
3030
* for initializing that.
3131
*
32-
* Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
32+
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
3333
* Portions Copyright (c) 1994, Regents of the University of California
3434
*
3535
* IDENTIFICATION
@@ -45,14 +45,13 @@
4545
#include "access/relscan.h"
4646
#include "access/table.h"
4747
#include "access/xact.h"
48-
#include "access/xloginsert.h"
4948
#include "catalog/index.h"
5049
#include "commands/progress.h"
5150
#include "executor/instrument.h"
5251
#include "miscadmin.h"
5352
#include "pgstat.h"
5453
#include "storage/bulk_write.h"
55-
#include "tcop/tcopprot.h" /* pgrminclude ignore */
54+
#include "tcop/tcopprot.h"
5655
#include "utils/rel.h"
5756
#include "utils/sortsupport.h"
5857
#include "utils/tuplesort.h"
@@ -105,6 +104,9 @@ typedef struct BTShared
105104
bool isconcurrent;
106105
int scantuplesortstates;
107106

107+
/* Query ID, for report in worker processes */
108+
uint64 queryid;
109+
108110
/*
109111
* workersdonecv is used to monitor the progress of workers. All parallel
110112
* participants must indicate that they are done before leader can use
@@ -473,7 +475,7 @@ _bt_spools_heapscan(Relation heap, Relation index, BTBuildState *buildstate,
473475
/* Fill spool using either serial or parallel heap scan */
474476
if (!buildstate->btleader)
475477
reltuples = table_index_build_scan(heap, index, indexInfo, true, true,
476-
_bt_build_callback, (void *) buildstate,
478+
_bt_build_callback, buildstate,
477479
NULL);
478480
else
479481
reltuples = _bt_parallel_heapscan(buildstate,
@@ -827,7 +829,7 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup,
827829
* make use of the reserved space. This should never fail on internal
828830
* pages.
829831
*/
830-
if (unlikely(itupsz > BTMaxItemSize(npage)))
832+
if (unlikely(itupsz > BTMaxItemSize))
831833
_bt_check_third_page(wstate->index, wstate->heap, isleaf, npage,
832834
itup);
833835

@@ -1303,7 +1305,7 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
13031305
*/
13041306
dstate->maxpostingsize = MAXALIGN_DOWN((BLCKSZ * 10 / 100)) -
13051307
sizeof(ItemIdData);
1306-
Assert(dstate->maxpostingsize <= BTMaxItemSize((Page) state->btps_buf) &&
1308+
Assert(dstate->maxpostingsize <= BTMaxItemSize &&
13071309
dstate->maxpostingsize <= INDEX_SIZE_MASK);
13081310
dstate->htids = palloc(dstate->maxpostingsize);
13091311

@@ -1505,6 +1507,7 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
15051507
btshared->nulls_not_distinct = btspool->nulls_not_distinct;
15061508
btshared->isconcurrent = isconcurrent;
15071509
btshared->scantuplesortstates = scantuplesortstates;
1510+
btshared->queryid = pgstat_get_my_query_id();
15081511
ConditionVariableInit(&btshared->workersdonecv);
15091512
SpinLockInit(&btshared->mutex);
15101513
/* Initialize mutable state */
@@ -1787,6 +1790,9 @@ _bt_parallel_build_main(dsm_segment *seg, shm_toc *toc)
17871790
indexLockmode = RowExclusiveLock;
17881791
}
17891792

1793+
/* Track query ID */
1794+
pgstat_report_query_id(btshared->queryid, false);
1795+
17901796
/* Open relations within worker */
17911797
heapRel = table_open(btshared->heaprelid, heapLockmode);
17921798
indexRel = index_open(btshared->indexrelid, indexLockmode);
@@ -1924,7 +1930,7 @@ _bt_parallel_scan_and_sort(BTSpool *btspool, BTSpool *btspool2,
19241930
ParallelTableScanFromBTShared(btshared));
19251931
reltuples = table_index_build_scan(btspool->heap, btspool->index, indexInfo,
19261932
true, progress, _bt_build_callback,
1927-
(void *) &buildstate, scan);
1933+
&buildstate, scan);
19281934

19291935
/* Execute this worker's part of the sort */
19301936
if (progress)

0 commit comments

Comments
 (0)