Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
f6c1342
Add check for large files in meson.build
michaelpq Nov 12, 2025
f30cd34
Report better object limits in error messages for injection points
michaelpq Nov 12, 2025
d5c3275
doc: Fix incorrect synopsis for ALTER PUBLICATION ... DROP ...
MasaoFujii Nov 12, 2025
cb2ef0e
Fix pg_upgrade around multixid and mxoff wraparound
hlinnaka Nov 12, 2025
1aa5a02
Fix range for commit_siblings in sample conf
danielgustafsson Nov 12, 2025
a00c961
doc: Document effects of ownership change on privileges
danielgustafsson Nov 12, 2025
b821c92
Escalate ERRORs during async notify processing to FATAL
hlinnaka Nov 12, 2025
d02c03d
Fix bug where we truncated CLOG that was still needed by LISTEN/NOTIFY
hlinnaka Nov 12, 2025
c268281
Fix remaining race condition with CLOG truncation and LISTEN/NOTIFY
hlinnaka Nov 12, 2025
d80d5f0
Clear 'xid' in dummy async notify entries written to fill up pages
hlinnaka Nov 12, 2025
ac2800d
Teach DSM registry to ERROR if attaching to an uninitialized entry.
nathan-bossart Nov 12, 2025
d60dabf
doc: Improve description of RLS policies applied by command type.
deanrasheed Nov 13, 2025
5bc251b
pgbench: Fix assertion failure with multiple \syncpipeline in pipelin…
MasaoFujii Nov 14, 2025
505ce19
Add note about CreateStatistics()'s selective use of check_rights.
nathan-bossart Nov 14, 2025
213596a
Doc: include MERGE in variable substitution command list
david-rowley Nov 16, 2025
d6c415c
Fix Assert failure in EXPLAIN ANALYZE MERGE with a concurrent update.
deanrasheed Nov 16, 2025
d66a922
Define PS_USE_CLOBBER_ARGV on GNU/Hurd.
macdice Nov 16, 2025
1cd0203
Update .abi-compliance-history for change to CreateStatistics().
nathan-bossart Nov 17, 2025
075a763
Don't allow CTEs to determine semantic levels of aggregates.
tglsfdc Nov 18, 2025
f2e0ca0
Print new OldestXID value in pg_resetwal when it's being changed
hlinnaka Nov 19, 2025
60215ea
jit: Adjust AArch64-only code for LLVM 21.
macdice Nov 22, 2025
232e0f5
Fix incorrect IndexOptInfo header comment
david-rowley Nov 24, 2025
427e886
lwlock: Fix, currently harmless, bug in LWLockWakeup()
anarazel Nov 24, 2025
cbb69a6
doc: Clarify passphrase command reloading on Windows
danielgustafsson Nov 26, 2025
c7e0f26
Revert "Teach DSM registry to ERROR if attaching to an uninitialized …
nathan-bossart Nov 26, 2025
2fc5c50
Teach DSM registry to retry entry initialization if needed.
nathan-bossart Nov 26, 2025
b5511fe
Fix error reporting for SQL/JSON path type mismatches
amitlan Nov 27, 2025
d797766
doc: Fix misleading synopsis for CREATE/ALTER PUBLICATION.
MasaoFujii Nov 27, 2025
e79b276
Allow indexscans on partial hash indexes with implied quals.
tglsfdc Nov 27, 2025
c090965
Avoid rewriting data-modifying CTEs more than once.
deanrasheed Nov 29, 2025
5a2d1df
Fix amcheck's handling of incomplete root splits in B-tree
hlinnaka Dec 2, 2025
e8ae594
Fix amcheck's handling of half-dead B-tree pages
hlinnaka Dec 2, 2025
8ba61bc
Set next multixid's offset when creating a new multixid
hlinnaka Dec 3, 2025
ce2f575
amcheck: Fix snapshot usage in bt_index_parent_check
alvherre Dec 4, 2025
9d4f6d1
Show version of nodes in output of TAP tests
michaelpq Dec 5, 2025
cad40ce
Fix setting next multixid's offset at offset wraparound
hlinnaka Dec 5, 2025
ca98d8b
Doc: fix typo in hash index documentation
david-rowley Dec 9, 2025
f281886
Fix LOCK_TIMEOUT handling in slotsync worker.
Dec 9, 2025
7a02ac2
doc: Fix statement about ON CONFLICT and deferrable constraints.
deanrasheed Dec 9, 2025
f24af0e
Fix O_CLOEXEC flag handling in Windows port.
macdice Dec 9, 2025
d0518e9
Fix failures with cross-version pg_upgrade tests
michaelpq Dec 10, 2025
998d100
Fix some near-bugs related to ResourceOwner function arguments
hlinnaka Dec 10, 2025
807b2f2
Fix bogus extra arguments to query_safe in test
hlinnaka Dec 10, 2025
0bab0c3
Fix allocation formula in llvmjit_expr.c
michaelpq Dec 11, 2025
cd1a887
Clarify comment on multixid offset wraparound check
hlinnaka Dec 15, 2025
f5927da
Fail recovery when missing redo checkpoint record without backup_label
michaelpq Dec 16, 2025
1d0fc24
Switch memory contexts in ReinitializeParallelDSM.
robertmhaas Dec 16, 2025
b8cfe9d
Fix multibyte issue in ltree_strncasecmp().
jeff-davis Dec 16, 2025
0f69bed
For inplace update, send nontransactional invalidations.
nmisch Dec 17, 2025
d3e5d89
WAL-log inplace update before revealing it to other sessions.
nmisch Dec 17, 2025
bcb784e
Assert lack of hazardous buffer locks before possible catalog read.
nmisch Dec 17, 2025
a3e7bbd
Update .abi-compliance-history for PrepareToInvalidateCacheTuple().
nmisch Dec 17, 2025
4b6d096
Do not emit WAL for unlogged BRIN indexes
hlinnaka Dec 18, 2025
1cdc07a
Sort DO_SUBSCRIPTION_REL dump objects independent of OIDs.
nmisch Dec 18, 2025
699293d
Add guard to prevent recursive memory context logging.
MasaoFujii Dec 19, 2025
0451859
Clean up test_cloexec.c and Makefile.
macdice Dec 21, 2025
d454917
Fix printf format string warning on MinGW.
macdice Dec 5, 2024
e063ccc
Fix orphaned origin in shared memory after DROP SUBSCRIPTION
michaelpq Dec 23, 2025
4c9f262
Add missing .gitignore for src/test/modules/test_cloexec.
tglsfdc Dec 22, 2025
bb87d7f
Fix bug in following update chain when locking a heap tuple
hlinnaka Dec 23, 2025
0ed8f1a
Don't advance origin during apply failure.
Dec 24, 2025
a1cdb81
Update comments to reflect changes in 8e0d32a4a1.
Dec 24, 2025
862ed6e
doc: Remove duplicate word in ECPG description
michaelpq Dec 26, 2025
02dc089
doc: warn about the use of "ctid" queries beyond the examples
bmomjian Dec 26, 2025
52b27f5
Fix pg_stat_get_backend_activity() to use multi-byte truncated result
michaelpq Dec 27, 2025
b3c8119
Fix Mkvcbuild.pm builds of test_cloexec.c.
macdice Dec 29, 2025
a989237
jit: Remove -Wno-deprecated-declarations in 18+.
macdice Dec 30, 2025
123b851
Fix a race condition in updating procArray->replication_slot_xmin.
MasahikoSawada Dec 30, 2025
174bbc0
jit: Fix jit_profiling_support when unavailable.
macdice Dec 31, 2025
625e449
Update copyright for 2026
bmomjian Jan 1, 2026
a5f2dc4
Fix selectivity estimation integer overflow in contrib/intarray
david-rowley Jan 4, 2026
498b163
Doc: add missing punctuation
david-rowley Jan 4, 2026
7a990e8
Honor GUC settings specified in CREATE SUBSCRIPTION CONNECTION.
MasaoFujii Jan 6, 2026
3587846
Add TAP test for GUC settings passed via CONNECTION in logical replic…
MasaoFujii Jan 6, 2026
bb08ac7
Fix issue with EVENT TRIGGERS and ALTER PUBLICATION
david-rowley Jan 6, 2026
8dd074a
createuser: Update docs to reflect defaults
j-naylor Jan 7, 2026
608f957
Fix typo
petere Jan 7, 2026
3510ebe
Prevent invalidation of newly created replication slots.
Jan 8, 2026
84b787a
Fix possible incorrect column reference in ERROR message
david-rowley Jan 8, 2026
862f83f
doc: Improve description of publish_via_partition_root
jchampio Jan 9, 2026
930a050
doc: Document DEFAULT option in file_fdw.
MasaoFujii Jan 13, 2026
a244e17
pg_waldump: Relax LSN comparison check in TAP test
michaelpq Jan 14, 2026
d3ad4ce
Add check for invalid offset at multixid truncation
hlinnaka Jan 15, 2026
c377018
Fix 'unexpected data beyond EOF' on replica restart
hlinnaka Jan 15, 2026
4071fe9
Fix segfault from releasing locks in detached DSM segments
amitlan Jan 16, 2026
6ad01b1
Fix crash in test function on removable_cutoff(NULL)
hlinnaka Jan 16, 2026
05ef237
Fix error message related to end TLI in backup manifest
michaelpq Jan 18, 2026
f87c0b8
Update time zone data files to tzdata release 2025c.
tglsfdc Jan 18, 2026
ad569b5
Don't set the truncation block length greater than RELSEG_SIZE.
robertmhaas Jan 19, 2026
e1a327d
amcheck: Fix snapshot usage in bt_index_parent_check
alvherre Jan 21, 2026
d0bb0e5
jit: Add missing inline pass for LLVM >= 17.
macdice Jan 22, 2026
f1cb59e
doc: Mention pg_get_partition_constraintdef()
michaelpq Jan 22, 2026
3fabfc6
Remove faulty Assert in partitioned INSERT...ON CONFLICT DO UPDATE.
tglsfdc Jan 22, 2026
933f67f
Fix bogus ctid requirement for dummy-root partitioned targets
amitlan Jan 23, 2026
c5fc17d
Fix trigger transition table capture for MERGE in CTE queries.
deanrasheed Jan 24, 2026
cae8127
Fix possible issue of a WindowFunc being in the wrong WindowClause
david-rowley Jan 26, 2026
cf3170f
Reduce length of TAP test file name.
robertmhaas Jan 26, 2026
3243c01
Prevent invalidation of newly synced replication slots.
Jan 27, 2026
9649f1a
Fix CI failure introduced in commit 851f6649cc.
Jan 29, 2026
661d55e
Update .abi-compliance-history for change to TransitionCaptureState.
deanrasheed Jan 30, 2026
f356e28
Improve guards against false regex matches in BackgroundPsql.pm.
tglsfdc Jan 30, 2026
241803f
Fix build inconsistency due to the generation of wait-event code
michaelpq Feb 1, 2026
5995135
Fix error message in RemoveWalSummaryIfOlderThan()
michaelpq Feb 2, 2026
4bb1dff
Add the injection point for testing SMGR (#878)
a-masterov Feb 2, 2026
3b15032
Fix incorrect errno in OpenWalSummaryFile()
michaelpq Feb 3, 2026
263af45
pg_resetwal: Fix incorrect error message related to pg_wal/summaries/
michaelpq Feb 4, 2026
1662cd0
Fix various instances of undefined behavior
j-naylor Feb 4, 2026
c423bf6
Fix logical replication TAP test to read publisher log correctly.
MasaoFujii Feb 4, 2026
f6a263e
doc: Move synchronized_standby_slots to "Primary Server" section.
MasaoFujii Feb 6, 2026
4dac22a
Add file_extend_method=posix_fallocate,write_zeros.
macdice May 31, 2025
67ad438
Fix some error message inconsistencies
michaelpq Feb 6, 2026
5d61bdd
Protect against small overread in SASLprep validation
jchampio Feb 6, 2026
c7f7057
Placate ABI checker.
macdice Feb 6, 2026
5449fd2
Further error message fix
petere Feb 7, 2026
59c2f7e
meson: host_system value for Solaris is 'sunos' not 'solaris'.
tglsfdc Feb 8, 2026
2a53576
Translation updates
petere Feb 8, 2026
4d3d888
Release notes for 18.2, 17.8, 16.12, 15.16, 14.21.
tglsfdc Feb 8, 2026
7a7d969
pgcrypto: Fix buffer overflow in pgp_pub_decrypt_bytea()
michaelpq Feb 8, 2026
838248b
Fix encoding length for EUC_CN.
macdice Feb 4, 2026
7a52203
Fix mb2wchar functions on short input.
macdice Jan 25, 2026
319e8a6
Replace pg_mblen() with bounds-checked versions.
macdice Jan 7, 2026
10ebc4b
Code coverage for most pg_mblen* calls.
macdice Jan 11, 2026
dc072a0
Require PGP-decrypted text to pass encoding validation.
nmisch Feb 9, 2026
3d16040
Guard against unexpected dimensions of oidvector/int2vector.
tglsfdc Feb 9, 2026
dbb09fd
Add a syscache on pg_extension.oid.
tglsfdc Feb 9, 2026
bbf5bcf
Require superuser to install a non-built-in selectivity estimator.
tglsfdc Feb 9, 2026
dd3ad2a
Harden _int_matchsel() against being attached to the wrong operator.
tglsfdc Feb 9, 2026
955433e
Fix test "NUL byte in text decrypt" for --without-zlib builds.
nmisch Feb 9, 2026
a3acb40
Last-minute updates for release notes.
tglsfdc Feb 9, 2026
6af8851
Stamp 17.8.
tglsfdc Feb 9, 2026
fe308f8
Update Postgres 17 to 17.8
thesuhas Feb 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
37 changes: 37 additions & 0 deletions .abi-compliance-history
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,43 @@
# Be sure to replace "<ADD JUSTIFICATION HERE>" with details of your change and
# why it is deemed acceptable.

4dac22aa10d2882c2e6fb465d7c314cc2d8fb754
#
# Add file_extend_method=posix_fallocate,write_zeros.
# 2026-02-06 17:41:42 +1300
#
# Modifying GUC tables isn't really an ABI break: the relevant object has
# incomplete type so its layout is inaccessible from other C translation units.
#
# Discussion: https://www.postgresql.org/message-id/flat/e1f0cd3b-0164-45f5-9705-e922e59df90f%40dunslane.net#8a350b54012c0042f9869d288e978cfe

c5fc17ddaccff14bc22217df2b06ed43a5af16ba
#
# Fix trigger transition table capture for MERGE in CTE queries.
# 2026-01-24 11:30:49 +0000
#
# This commit changed the TransitionCaptureState structure, replacing
# the "tcs_private" field with 3 separate fields. This structure can
# only be built using MakeTransitionCaptureState(), and PGXN contained
# no calls to MakeTransitionCaptureState() or uses of the
# TransitionCaptureState structure.

0f69beddea113dd1d6c5b6f6d82df577ef3c21f2
#
# For inplace update, send nontransactional invalidations.
# 2025-12-16 16:13:54 -0800
#
# This changed PrepareToInvalidateCacheTuple() parameters. PGXN contained no
# calls to that function.

e2fb3dfa817fbe89494a62c100e9cb442f4d6b15
#
# Check for CREATE privilege on the schema in CREATE STATISTICS.
# 2025-11-10 09:00:00 -0600
#
# This commit added a parameter to CreateStatistics(). We are unaware of any
# impacted third-party code.

24f6c1bd41d0631a04cc956cc8cafa0b117ab625
#
# Fix the handling of two GUCs during upgrade.
Expand Down
2 changes: 1 addition & 1 deletion .cirrus.tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ task:
env:
CPUS: 4 # always get that much for cirrusci macOS instances
BUILD_JOBS: $CPUS
# Test performance regresses noticably when using all cores. 8 seems to
# Test performance regresses noticeably when using all cores. 8 seems to
# work OK. See
# https://postgr.es/m/20220927040208.l3shfcidovpzqxfh%40awork3.anarazel.de
TEST_JOBS: 8
Expand Down
2 changes: 1 addition & 1 deletion COPYRIGHT
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PostgreSQL Database Management System
(also known as Postgres, formerly known as Postgres95)

Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group

Portions Copyright (c) 1994, The Regents of the University of California

Expand Down
18 changes: 9 additions & 9 deletions configure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for PostgreSQL 17.7.
# Generated by GNU Autoconf 2.69 for PostgreSQL 17.8.
#
# Report bugs to <pgsql-bugs@lists.postgresql.org>.
#
Expand Down Expand Up @@ -582,8 +582,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='PostgreSQL'
PACKAGE_TARNAME='postgresql'
PACKAGE_VERSION='17.7'
PACKAGE_STRING='PostgreSQL 17.7'
PACKAGE_VERSION='17.8'
PACKAGE_STRING='PostgreSQL 17.8'
PACKAGE_BUGREPORT='pgsql-bugs@lists.postgresql.org'
PACKAGE_URL='https://www.postgresql.org/'

Expand Down Expand Up @@ -1452,7 +1452,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures PostgreSQL 17.7 to adapt to many kinds of systems.
\`configure' configures PostgreSQL 17.8 to adapt to many kinds of systems.

Usage: $0 [OPTION]... [VAR=VALUE]...

Expand Down Expand Up @@ -1517,7 +1517,7 @@ fi

if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of PostgreSQL 17.7:";;
short | recursive ) echo "Configuration of PostgreSQL 17.8:";;
esac
cat <<\_ACEOF

Expand Down Expand Up @@ -1693,7 +1693,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
PostgreSQL configure 17.7
PostgreSQL configure 17.8
generated by GNU Autoconf 2.69

Copyright (C) 2012 Free Software Foundation, Inc.
Expand Down Expand Up @@ -2446,7 +2446,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by PostgreSQL $as_me 17.7, which was
It was created by PostgreSQL $as_me 17.8, which was
generated by GNU Autoconf 2.69. Invocation command line was

$ $0 $@
Expand Down Expand Up @@ -19952,7 +19952,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by PostgreSQL $as_me 17.7, which was
This file was extended by PostgreSQL $as_me 17.8, which was
generated by GNU Autoconf 2.69. Invocation command line was

CONFIG_FILES = $CONFIG_FILES
Expand Down Expand Up @@ -20023,7 +20023,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
PostgreSQL config.status 17.7
PostgreSQL config.status 17.8
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dnl Read the Autoconf manual for details.
dnl
m4_pattern_forbid(^PGAC_)dnl to catch undefined macros

AC_INIT([PostgreSQL], [17.7], [pgsql-bugs@lists.postgresql.org], [], [https://www.postgresql.org/])
AC_INIT([PostgreSQL], [17.8], [pgsql-bugs@lists.postgresql.org], [], [https://www.postgresql.org/])

m4_if(m4_defn([m4_PACKAGE_VERSION]), [2.69], [], [m4_fatal([Autoconf version 2.69 is required.
Untested combinations of 'autoconf' and PostgreSQL versions are not
Expand Down
24 changes: 24 additions & 0 deletions contrib/amcheck/t/002_cic.pl
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,29 @@
)
});

# Test bt_index_parent_check() with indexes created with
# CREATE INDEX CONCURRENTLY.
$node->safe_psql('postgres', q(CREATE TABLE quebec(i int primary key)));
# Insert two rows into index
$node->safe_psql('postgres',
q(INSERT INTO quebec SELECT i FROM generate_series(1, 2) s(i);));

# start background transaction
my $in_progress_h = $node->background_psql('postgres');
$in_progress_h->query_safe(q(BEGIN; SELECT pg_current_xact_id();));

# delete one row from table, while background transaction is in progress
$node->safe_psql('postgres', q(DELETE FROM quebec WHERE i = 1;));
# create index concurrently, which will skip the deleted row
$node->safe_psql('postgres',
q(CREATE INDEX CONCURRENTLY oscar ON quebec(i);));

# check index using bt_index_parent_check
$result = $node->psql('postgres',
q(SELECT bt_index_parent_check('oscar', heapallindexed => true)));
is($result, '0', 'bt_index_parent_check for CIC after removed row');

$in_progress_h->quit;

$node->stop;
done_testing();
90 changes: 39 additions & 51 deletions contrib/amcheck/verify_nbtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ typedef struct BtreeCheckState
BufferAccessStrategy checkstrategy;

/*
* Info for uniqueness checking. Fill these fields once per index check.
* Info for uniqueness checking. Fill this field and the one below once
* per index check.
*/
IndexInfo *indexinfo;
/* Table scan snapshot for heapallindexed and checkunique */
Snapshot snapshot;

/*
Expand Down Expand Up @@ -508,7 +510,6 @@ bt_check_every_level(Relation rel, Relation heaprel, bool heapkeyspace,
BTMetaPageData *metad;
uint32 previouslevel;
BtreeLevel current;
Snapshot snapshot = SnapshotAny;

if (!readonly)
elog(DEBUG1, "verifying consistency of tree structure for index \"%s\"",
Expand Down Expand Up @@ -559,54 +560,46 @@ bt_check_every_level(Relation rel, Relation heaprel, bool heapkeyspace,
state->heaptuplespresent = 0;

/*
* Register our own snapshot in !readonly case, rather than asking
* Register our own snapshot for heapallindexed, rather than asking
* table_index_build_scan() to do this for us later. This needs to
* happen before index fingerprinting begins, so we can later be
* certain that index fingerprinting should have reached all tuples
* returned by table_index_build_scan().
*/
if (!state->readonly)
{
snapshot = RegisterSnapshot(GetTransactionSnapshot());
state->snapshot = RegisterSnapshot(GetTransactionSnapshot());

/*
* GetTransactionSnapshot() always acquires a new MVCC snapshot in
* READ COMMITTED mode. A new snapshot is guaranteed to have all
* the entries it requires in the index.
*
* We must defend against the possibility that an old xact
* snapshot was returned at higher isolation levels when that
* snapshot is not safe for index scans of the target index. This
* is possible when the snapshot sees tuples that are before the
* index's indcheckxmin horizon. Throwing an error here should be
* very rare. It doesn't seem worth using a secondary snapshot to
* avoid this.
*/
if (IsolationUsesXactSnapshot() && rel->rd_index->indcheckxmin &&
!TransactionIdPrecedes(HeapTupleHeaderGetXmin(rel->rd_indextuple->t_data),
snapshot->xmin))
ereport(ERROR,
(errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
errmsg("index \"%s\" cannot be verified using transaction snapshot",
RelationGetRelationName(rel))));
}
/*
* GetTransactionSnapshot() always acquires a new MVCC snapshot in
* READ COMMITTED mode. A new snapshot is guaranteed to have all the
* entries it requires in the index.
*
* We must defend against the possibility that an old xact snapshot
* was returned at higher isolation levels when that snapshot is not
* safe for index scans of the target index. This is possible when
* the snapshot sees tuples that are before the index's indcheckxmin
* horizon. Throwing an error here should be very rare. It doesn't
* seem worth using a secondary snapshot to avoid this.
*/
if (IsolationUsesXactSnapshot() && rel->rd_index->indcheckxmin &&
!TransactionIdPrecedes(HeapTupleHeaderGetXmin(rel->rd_indextuple->t_data),
state->snapshot->xmin))
ereport(ERROR,
errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
errmsg("index \"%s\" cannot be verified using transaction snapshot",
RelationGetRelationName(rel)));
}

/*
* We need a snapshot to check the uniqueness of the index. For better
* performance take it once per index check. If snapshot already taken
* reuse it.
* We need a snapshot to check the uniqueness of the index. For better
* performance, take it once per index check. If one was already taken
* above, use that.
*/
if (state->checkunique)
{
state->indexinfo = BuildIndexInfo(state->rel);
if (state->indexinfo->ii_Unique)
{
if (snapshot != SnapshotAny)
state->snapshot = snapshot;
else
state->snapshot = RegisterSnapshot(GetTransactionSnapshot());
}

if (state->indexinfo->ii_Unique && state->snapshot == InvalidSnapshot)
state->snapshot = RegisterSnapshot(GetTransactionSnapshot());
}

Assert(!state->rootdescend || state->readonly);
Expand Down Expand Up @@ -681,30 +674,28 @@ bt_check_every_level(Relation rel, Relation heaprel, bool heapkeyspace,
/*
* Create our own scan for table_index_build_scan(), rather than
* getting it to do so for us. This is required so that we can
* actually use the MVCC snapshot registered earlier in !readonly
* case.
* actually use the MVCC snapshot registered earlier.
*
* Note that table_index_build_scan() calls heap_endscan() for us.
*/
scan = table_beginscan_strat(state->heaprel, /* relation */
snapshot, /* snapshot */
state->snapshot, /* snapshot */
0, /* number of keys */
NULL, /* scan key */
true, /* buffer access strategy OK */
true); /* syncscan OK? */

/*
* Scan will behave as the first scan of a CREATE INDEX CONCURRENTLY
* behaves in !readonly case.
* behaves.
*
* It's okay that we don't actually use the same lock strength for the
* heap relation as any other ii_Concurrent caller would in !readonly
* case. We have no reason to care about a concurrent VACUUM
* operation, since there isn't going to be a second scan of the heap
* that needs to be sure that there was no concurrent recycling of
* TIDs.
* heap relation as any other ii_Concurrent caller would. We have no
* reason to care about a concurrent VACUUM operation, since there
* isn't going to be a second scan of the heap that needs to be sure
* that there was no concurrent recycling of TIDs.
*/
indexinfo->ii_Concurrent = !state->readonly;
indexinfo->ii_Concurrent = true;

/*
* Don't wait for uncommitted tuple xact commit/abort when index is a
Expand All @@ -728,14 +719,11 @@ bt_check_every_level(Relation rel, Relation heaprel, bool heapkeyspace,
state->heaptuplespresent, RelationGetRelationName(heaprel),
100.0 * bloom_prop_bits_set(state->filter))));

if (snapshot != SnapshotAny)
UnregisterSnapshot(snapshot);

bloom_free(state->filter);
}

/* Be tidy: */
if (snapshot == SnapshotAny && state->snapshot != InvalidSnapshot)
if (state->snapshot != InvalidSnapshot)
UnregisterSnapshot(state->snapshot);
MemoryContextDelete(state->targetcontext);
}
Expand Down
21 changes: 16 additions & 5 deletions contrib/btree_gist/btree_utils_var.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,36 +116,47 @@ gbt_var_leaf2node(GBT_VARKEY *leaf, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)

/*
* returns the common prefix length of a node key
*
* If the underlying type is character data, the prefix length may point in
* the middle of a multibyte character.
*/
static int32
gbt_var_node_cp_len(const GBT_VARKEY *node, const gbtree_vinfo *tinfo)
{
GBT_VARKEY_R r = gbt_var_key_readable(node);
int32 i = 0;
int32 l = 0;
int32 l_left_to_match = 0;
int32 l_total = 0;
int32 t1len = VARSIZE(r.lower) - VARHDRSZ;
int32 t2len = VARSIZE(r.upper) - VARHDRSZ;
int32 ml = Min(t1len, t2len);
char *p1 = VARDATA(r.lower);
char *p2 = VARDATA(r.upper);
const char *end1 = p1 + t1len;
const char *end2 = p2 + t2len;

if (ml == 0)
return 0;

while (i < ml)
{
if (tinfo->eml > 1 && l == 0)
if (tinfo->eml > 1 && l_left_to_match == 0)
{
if ((l = pg_mblen(p1)) != pg_mblen(p2))
l_total = pg_mblen_range(p1, end1);
if (l_total != pg_mblen_range(p2, end2))
{
return i;
}
l_left_to_match = l_total;
}
if (*p1 != *p2)
{
if (tinfo->eml > 1)
{
return (i - l + 1);
int32 l_matched_subset = l_total - l_left_to_match;

/* end common prefix at final byte of last matching char */
return i - l_matched_subset;
}
else
{
Expand All @@ -155,7 +166,7 @@ gbt_var_node_cp_len(const GBT_VARKEY *node, const gbtree_vinfo *tinfo)

p1++;
p2++;
l--;
l_left_to_match--;
i++;
}
return ml; /* lower == upper */
Expand Down
Loading