=== Applying patches on top of PostgreSQL commit ID 81b2179b492e3af891544813b7e22a42386b34d0 === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Sun Nov 15 05:44:33 UTC 2026 On branch cf/4971 nothing to commit, working tree clean === using 'git am' to apply patch ./v40-0001-Add-stress-tests-for-concurrent-index-builds.patch === Applying: Add stress tests for concurrent index builds === using 'git am' to apply patch ./v40-0002-Add-STIR-access-method-and-validate_index-flag-i.patch === Applying: Add STIR access method and validate_index flag in IndexVacuumInfo === using 'git am' to apply patch ./v40-0003-Add-Datum-storage-support-to-tuplestore.patch === Applying: Add Datum storage support to tuplestore === using 'git am' to apply patch ./v40-0004-Use-auxiliary-indexes-for-concurrent-index-opera.patch === Applying: Use auxiliary indexes for concurrent index operations error: sha1 information is lacking or useless (src/backend/catalog/index.c). error: could not build fake ancestor hint: Use 'git am --show-current-patch=diff' to see the failed patch Patch failed at 0001 Use auxiliary indexes for concurrent index operations When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". === using patch(1) to apply patch ./v40-0004-Use-auxiliary-indexes-for-concurrent-index-opera.patch === patching file contrib/test_decoding/expected/repack.out patching file doc/src/sgml/monitoring.sgml patching file doc/src/sgml/ref/create_index.sgml patching file doc/src/sgml/ref/reindex.sgml patching file src/backend/access/heap/README.HOT patching file src/backend/access/heap/heapam_handler.c Hunk #2 FAILED at 1706. 1 out of 2 hunks FAILED -- saving rejects to file src/backend/access/heap/heapam_handler.c.rej patching file src/backend/access/stir/stir.c patching file src/backend/catalog/index.c patching file src/backend/catalog/system_views.sql Hunk #1 succeeded at 1427 (offset 2 lines). patching file src/backend/catalog/toasting.c patching file src/backend/commands/indexcmds.c Hunk #1 succeeded at 196 (offset 3 lines). Hunk #2 succeeded at 247 (offset 3 lines). Hunk #3 succeeded at 259 (offset 3 lines). Hunk #4 succeeded at 573 (offset 3 lines). Hunk #5 succeeded at 583 (offset 3 lines). Hunk #6 succeeded at 605 (offset 3 lines). Hunk #7 succeeded at 856 (offset 3 lines). Hunk #8 succeeded at 959 (offset 3 lines). Hunk #9 succeeded at 1634 (offset -11 lines). Hunk #10 succeeded at 1672 (offset -11 lines). Hunk #11 succeeded at 1686 (offset -11 lines). Hunk #12 succeeded at 1725 (offset -11 lines). Hunk #13 succeeded at 1737 (offset -11 lines). Hunk #14 succeeded at 1809 (offset -11 lines). Hunk #15 succeeded at 1848 (offset -11 lines). Hunk #16 succeeded at 1882 (offset -11 lines). Hunk #17 succeeded at 1907 (offset -11 lines). Hunk #18 succeeded at 3894 (offset 30 lines). Hunk #19 succeeded at 4000 (offset 30 lines). Hunk #20 succeeded at 4060 (offset 30 lines). Hunk #21 succeeded at 4129 (offset 30 lines). Hunk #22 succeeded at 4239 (offset 30 lines). Hunk #23 succeeded at 4301 (offset 30 lines). Hunk #24 succeeded at 4323 (offset 30 lines). Hunk #25 succeeded at 4342 (offset 30 lines). Hunk #26 succeeded at 4361 (offset 30 lines). Hunk #27 succeeded at 4449 (offset 30 lines). Hunk #28 succeeded at 4560 (offset 39 lines). Hunk #29 succeeded at 4602 (offset 39 lines). Hunk #30 succeeded at 4646 with fuzz 2 (offset 46 lines). Hunk #31 succeeded at 4677 (offset 48 lines). Hunk #32 succeeded at 4768 (offset 48 lines). Hunk #33 succeeded at 4800 (offset 48 lines). Hunk #34 succeeded at 4835 (offset 48 lines). Hunk #35 succeeded at 4860 (offset 48 lines). patching file src/backend/nodes/makefuncs.c patching file src/backend/utils/misc/guc_parameters.dat Hunk #1 succeeded at 641 (offset 9 lines). patching file src/include/access/tableam.h patching file src/include/catalog/index.h patching file src/include/commands/progress.h Hunk #1 succeeded at 124 (offset 2 lines). patching file src/include/miscadmin.h patching file src/include/nodes/execnodes.h patching file src/include/nodes/makefuncs.h patching file src/test/regress/expected/create_index.out Hunk #2 succeeded at 3249 (offset 27 lines). Hunk #3 succeeded at 3262 (offset 27 lines). Hunk #4 succeeded at 3293 (offset 27 lines). patching file src/test/regress/expected/indexing.out patching file src/test/regress/expected/rules.out patching file src/test/regress/sql/create_index.sql Hunk #2 succeeded at 1341 (offset 21 lines). Hunk #3 succeeded at 1358 (offset 21 lines). Unstaged changes after reset: M contrib/test_decoding/expected/repack.out M doc/src/sgml/monitoring.sgml M doc/src/sgml/ref/create_index.sgml M doc/src/sgml/ref/reindex.sgml M src/backend/access/heap/README.HOT M src/backend/access/heap/heapam_handler.c M src/backend/access/stir/stir.c M src/backend/catalog/index.c M src/backend/catalog/system_views.sql M src/backend/catalog/toasting.c M src/backend/commands/indexcmds.c M src/backend/nodes/makefuncs.c M src/backend/utils/misc/guc_parameters.dat M src/include/access/tableam.h M src/include/catalog/index.h M src/include/commands/progress.h M src/include/miscadmin.h M src/include/nodes/execnodes.h M src/include/nodes/makefuncs.h M src/test/regress/expected/create_index.out M src/test/regress/expected/indexing.out M src/test/regress/expected/rules.out M src/test/regress/sql/create_index.sql Removing src/backend/access/heap/heapam_handler.c.rej === using 'git apply' to apply patch ./v40-0004-Use-auxiliary-indexes-for-concurrent-index-opera.patch === Applied patch to 'contrib/test_decoding/expected/repack.out' cleanly. Applied patch to 'doc/src/sgml/monitoring.sgml' cleanly. Applied patch to 'doc/src/sgml/ref/create_index.sgml' cleanly. Applied patch to 'doc/src/sgml/ref/reindex.sgml' cleanly. Applied patch to 'src/backend/access/heap/README.HOT' cleanly. Applied patch to 'src/backend/access/heap/heapam_handler.c' with conflicts. Applied patch to 'src/backend/access/stir/stir.c' cleanly. error: repository lacks the necessary blob to perform 3-way merge. Falling back to direct application... Applied patch to 'src/backend/catalog/system_views.sql' cleanly. Applied patch to 'src/backend/catalog/toasting.c' cleanly. Applied patch to 'src/backend/commands/indexcmds.c' with conflicts. Applied patch to 'src/backend/nodes/makefuncs.c' cleanly. Applied patch to 'src/backend/utils/misc/guc_parameters.dat' cleanly. Applied patch to 'src/include/access/tableam.h' cleanly. Applied patch to 'src/include/catalog/index.h' cleanly. Applied patch to 'src/include/commands/progress.h' cleanly. Applied patch to 'src/include/miscadmin.h' cleanly. Applied patch to 'src/include/nodes/execnodes.h' cleanly. Applied patch to 'src/include/nodes/makefuncs.h' cleanly. Applied patch to 'src/test/regress/expected/create_index.out' cleanly. Applied patch to 'src/test/regress/expected/indexing.out' cleanly. Applied patch to 'src/test/regress/expected/rules.out' cleanly. Applied patch to 'src/test/regress/sql/create_index.sql' cleanly. U src/backend/access/heap/heapam_handler.c U src/backend/commands/indexcmds.c diff --cc src/backend/access/heap/heapam_handler.c index 05a81e4557a,86c6b5b705a..00000000000 --- a/src/backend/access/heap/heapam_handler.c +++ b/src/backend/access/heap/heapam_handler.c @@@ -1775,167 -2039,79 +2039,87 @@@ heapam_index_validate_scan(Relation hea CHECK_FOR_INTERRUPTS(); - state->htups += 1; + LockBuffer(buf, BUFFER_LOCK_SHARE); + block_number = BufferGetBlockNumber(buf); - if ((previous_blkno == InvalidBlockNumber) || - (hscan->rs_cblock != previous_blkno)) + i = 0; + while ((off = tuples[i]) != InvalidOffsetNumber) { - pgstat_progress_update_param(PROGRESS_SCAN_BLOCKS_DONE, - hscan->rs_cblock); - previous_blkno = hscan->rs_cblock; + ItemPointerData tid; + bool all_dead, found; + ItemPointerSet(&tid, block_number, off); + + found = heap_hot_search_buffer(&tid, heapRelation, buf, snapshot, + &heap_tuple_data[i], &all_dead, true); + if (!found) + ItemPointerSetInvalid(&heap_tuple_data[i].t_self); + i++; + state->htups += 1; } + LockBuffer(buf, BUFFER_LOCK_UNLOCK); /* - * As commented in table_index_build_scan, we should index heap-only - * tuples under the TIDs of their root tuples; so when we advance onto - * a new heap page, build a map of root item offsets on the page. - * - * This complicates merging against the tuplesort output: we will - * visit the live tuples in order by their offsets, but the root - * offsets that we need to compare against the index contents might be - * ordered differently. So we might have to "look back" within the - * tuplesort output, but only within the current page. We handle that - * by keeping a bool array in_index[] showing all the - * already-passed-over tuplesort output TIDs of the current page. We - * clear that array here, when advancing onto a new heap page. + * It is safe to access tuple data after releasing the buffer lock + * because the buffer pin is still held, and the only operation that + * could physically move tuple data on the page is + * PageRepairFragmentation via heap_page_prune. VACUUM conflicts with + * CIC (both take ShareUpdateExclusiveLock), and opportunistic pruning + * from concurrent DML cannot affect root tuples we are referencing. */ - if (hscan->rs_cblock != root_blkno) - { - Page page = BufferGetPage(hscan->rs_cbuf); - - LockBuffer(hscan->rs_cbuf, BUFFER_LOCK_SHARE); - heap_get_root_tuples(page, root_offsets); - LockBuffer(hscan->rs_cbuf, BUFFER_LOCK_UNLOCK); - - memset(in_index, 0, sizeof(in_index)); - - root_blkno = hscan->rs_cblock; - } - - /* Convert actual tuple TID to root TID */ - rootTuple = *heapcursor; - root_offnum = ItemPointerGetOffsetNumber(heapcursor); - - if (HeapTupleIsHeapOnly(heapTuple)) - { - root_offnum = root_offsets[root_offnum - 1]; - if (!OffsetNumberIsValid(root_offnum)) - ereport(ERROR, - (errcode(ERRCODE_DATA_CORRUPTED), - errmsg_internal("failed to find parent tuple for heap-only tuple at (%u,%u) in table \"%s\"", - ItemPointerGetBlockNumber(heapcursor), - ItemPointerGetOffsetNumber(heapcursor), - RelationGetRelationName(heapRelation)))); - ItemPointerSetOffsetNumber(&rootTuple, root_offnum); - } - /* - * "merge" by skipping through the index tuples until we find or pass - * the current root tuple. + * No predicate evaluation is needed here: the auxiliary STIR index + * only contains TIDs for tuples that already satisfied the partial + * index predicate at DML time (checked in ExecInsertIndexTuples). */ - while (!tuplesort_empty && - (!indexcursor || - ItemPointerCompare(indexcursor, &rootTuple) < 0)) + i = 0; + while ((off = tuples[i]) != InvalidOffsetNumber) { - Datum ts_val; - bool ts_isnull; - - if (indexcursor) - { - /* - * Remember index items seen earlier on the current heap page - */ - if (ItemPointerGetBlockNumber(indexcursor) == root_blkno) - in_index[ItemPointerGetOffsetNumber(indexcursor) - 1] = true; - } - - tuplesort_empty = !tuplesort_getdatum(state->tuplesort, true, - false, &ts_val, &ts_isnull, - NULL); - Assert(tuplesort_empty || !ts_isnull); - if (!tuplesort_empty) - { - itemptr_decode(&decoded, DatumGetInt64(ts_val)); - indexcursor = &decoded; - } - else + if (ItemPointerIsValid(&heap_tuple_data[i].t_self)) { - /* Be tidy */ - indexcursor = NULL; - } - } + ItemPointerData root_tid; + ItemPointerSet(&root_tid, block_number, off); - /* - * If the tuplesort has overshot *and* we didn't see a match earlier, - * then this tuple is missing from the index, so insert it. - */ - if ((tuplesort_empty || - ItemPointerCompare(indexcursor, &rootTuple) > 0) && - !in_index[root_offnum - 1]) - { - MemoryContextReset(econtext->ecxt_per_tuple_memory); + /* Reset the per-tuple memory context for the next fetch. */ + MemoryContextReset(econtext->ecxt_per_tuple_memory); + ExecStoreBufferHeapTuple(&heap_tuple_data[i], slot, buf); - /* Set up for predicate or expression evaluation */ - ExecStoreHeapTuple(heapTuple, slot, false); + /* Compute the key values and null flags for this tuple. */ + FormIndexDatum(indexInfo, + slot, + estate, + values, + isnull); - /* - * In a partial index, discard tuples that don't satisfy the - * predicate. - */ - if (predicate != NULL) - { - if (!ExecQual(predicate, econtext)) - continue; + /* + * Insert the tuple into the target index. + */ + index_insert(indexRelation, + values, + isnull, + &root_tid, /* insert root tuple */ + heapRelation, + indexInfo->ii_Unique ? + UNIQUE_CHECK_YES : UNIQUE_CHECK_NO, + false, + indexInfo); + + state->tups_inserted += 1; } - /* - * For the current heap tuple, extract all the attributes we use - * in this index, and note which are null. This also performs - * evaluation of any expressions needed. - */ - FormIndexDatum(indexInfo, - slot, - estate, - values, - isnull); - - /* - * You'd think we should go ahead and build the index tuple here, - * but some index AMs want to do further processing on the data - * first. So pass the values[] and isnull[] arrays, instead. - */ - - /* - * If the tuple is already committed dead, you might think we - * could suppress uniqueness checking, but this is no longer true - * in the presence of HOT, because the insert is actually a proxy - * for a uniqueness check on the whole HOT-chain. That is, the - * tuple we have here could be dead because it was already - * HOT-updated, and if so the updating transaction will not have - * thought it should insert index entries. The index AM will - * check the whole HOT-chain and correctly detect a conflict if - * there is one. - */ - - index_insert(indexRelation, - values, - isnull, - &rootTuple, - heapRelation, - indexInfo->ii_Unique ? - UNIQUE_CHECK_YES : UNIQUE_CHECK_NO, - false, - indexInfo); - - state->tups_inserted += 1; + pgstat_progress_incr_param(PROGRESS_CREATEIDX_TUPLES_DONE, 1); + i++; } - } ++<<<<<<< ours + /* Report scan progress, one last time. */ + pgstat_progress_update_param(PROGRESS_SCAN_BLOCKS_DONE, + hscan->rs_nblocks); + + table_endscan(scan); ++======= + ReleaseBuffer(buf); + } ++>>>>>>> theirs ExecDropSingleTupleTableSlot(slot); diff --cc src/backend/commands/indexcmds.c index 68fc87b76a0,e51de897324..00000000000 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@@ -4411,15 -4600,7 +4640,19 @@@ ReindexRelationConcurrently(const Reind progress_vals[3] = newidx->amId; pgstat_progress_update_multi_param(4, progress_index, progress_vals); ++<<<<<<< ours + /* + * Index expressions and predicates are evaluated below, so pin the + * relations. + */ + pinnedRels = ReindexPinRelations(relationLocks); + + validate_index(newidx->tableId, newidx->indexId, snapshot); ++======= + validate_index(newidx->tableId, newidx->indexId, newidx->auxIndexId, snapshot); ++>>>>>>> theirs + + ReindexUnpinRelations(pinnedRels); /* * We can now do away with our active snapshot, we still need to save