|
29 | 29 | * This code isn't concerned about the FSM at all. The caller is responsible |
30 | 30 | * for initializing that. |
31 | 31 | * |
32 | | - * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group |
| 32 | + * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group |
33 | 33 | * Portions Copyright (c) 1994, Regents of the University of California |
34 | 34 | * |
35 | 35 | * IDENTIFICATION |
|
45 | 45 | #include "access/relscan.h" |
46 | 46 | #include "access/table.h" |
47 | 47 | #include "access/xact.h" |
48 | | -#include "access/xloginsert.h" |
49 | 48 | #include "catalog/index.h" |
50 | 49 | #include "commands/progress.h" |
51 | 50 | #include "executor/instrument.h" |
52 | 51 | #include "miscadmin.h" |
53 | 52 | #include "pgstat.h" |
54 | 53 | #include "storage/bulk_write.h" |
55 | | -#include "tcop/tcopprot.h" /* pgrminclude ignore */ |
| 54 | +#include "tcop/tcopprot.h" |
56 | 55 | #include "utils/rel.h" |
57 | 56 | #include "utils/sortsupport.h" |
58 | 57 | #include "utils/tuplesort.h" |
@@ -105,6 +104,9 @@ typedef struct BTShared |
105 | 104 | bool isconcurrent; |
106 | 105 | int scantuplesortstates; |
107 | 106 |
|
| 107 | + /* Query ID, for report in worker processes */ |
| 108 | + uint64 queryid; |
| 109 | + |
108 | 110 | /* |
109 | 111 | * workersdonecv is used to monitor the progress of workers. All parallel |
110 | 112 | * participants must indicate that they are done before leader can use |
@@ -473,7 +475,7 @@ _bt_spools_heapscan(Relation heap, Relation index, BTBuildState *buildstate, |
473 | 475 | /* Fill spool using either serial or parallel heap scan */ |
474 | 476 | if (!buildstate->btleader) |
475 | 477 | reltuples = table_index_build_scan(heap, index, indexInfo, true, true, |
476 | | - _bt_build_callback, (void *) buildstate, |
| 478 | + _bt_build_callback, buildstate, |
477 | 479 | NULL); |
478 | 480 | else |
479 | 481 | reltuples = _bt_parallel_heapscan(buildstate, |
@@ -827,7 +829,7 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup, |
827 | 829 | * make use of the reserved space. This should never fail on internal |
828 | 830 | * pages. |
829 | 831 | */ |
830 | | - if (unlikely(itupsz > BTMaxItemSize(npage))) |
| 832 | + if (unlikely(itupsz > BTMaxItemSize)) |
831 | 833 | _bt_check_third_page(wstate->index, wstate->heap, isleaf, npage, |
832 | 834 | itup); |
833 | 835 |
|
@@ -1303,7 +1305,7 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2) |
1303 | 1305 | */ |
1304 | 1306 | dstate->maxpostingsize = MAXALIGN_DOWN((BLCKSZ * 10 / 100)) - |
1305 | 1307 | sizeof(ItemIdData); |
1306 | | - Assert(dstate->maxpostingsize <= BTMaxItemSize((Page) state->btps_buf) && |
| 1308 | + Assert(dstate->maxpostingsize <= BTMaxItemSize && |
1307 | 1309 | dstate->maxpostingsize <= INDEX_SIZE_MASK); |
1308 | 1310 | dstate->htids = palloc(dstate->maxpostingsize); |
1309 | 1311 |
|
@@ -1505,6 +1507,7 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request) |
1505 | 1507 | btshared->nulls_not_distinct = btspool->nulls_not_distinct; |
1506 | 1508 | btshared->isconcurrent = isconcurrent; |
1507 | 1509 | btshared->scantuplesortstates = scantuplesortstates; |
| 1510 | + btshared->queryid = pgstat_get_my_query_id(); |
1508 | 1511 | ConditionVariableInit(&btshared->workersdonecv); |
1509 | 1512 | SpinLockInit(&btshared->mutex); |
1510 | 1513 | /* Initialize mutable state */ |
@@ -1787,6 +1790,9 @@ _bt_parallel_build_main(dsm_segment *seg, shm_toc *toc) |
1787 | 1790 | indexLockmode = RowExclusiveLock; |
1788 | 1791 | } |
1789 | 1792 |
|
| 1793 | + /* Track query ID */ |
| 1794 | + pgstat_report_query_id(btshared->queryid, false); |
| 1795 | + |
1790 | 1796 | /* Open relations within worker */ |
1791 | 1797 | heapRel = table_open(btshared->heaprelid, heapLockmode); |
1792 | 1798 | indexRel = index_open(btshared->indexrelid, indexLockmode); |
@@ -1924,7 +1930,7 @@ _bt_parallel_scan_and_sort(BTSpool *btspool, BTSpool *btspool2, |
1924 | 1930 | ParallelTableScanFromBTShared(btshared)); |
1925 | 1931 | reltuples = table_index_build_scan(btspool->heap, btspool->index, indexInfo, |
1926 | 1932 | true, progress, _bt_build_callback, |
1927 | | - (void *) &buildstate, scan); |
| 1933 | + &buildstate, scan); |
1928 | 1934 |
|
1929 | 1935 | /* Execute this worker's part of the sort */ |
1930 | 1936 | if (progress) |
|
0 commit comments