agora inbox for [email protected]help / color / mirror / Atom feed
[PATCH v2] Reverse collations 4+ messages / 3 participants [nested] [flat]
* [PATCH v2] Reverse collations @ 2019-11-16 17:29 David Fetter <[email protected]> 0 siblings, 0 replies; 4+ messages in thread From: David Fetter @ 2019-11-16 17:29 UTC (permalink / raw) Make it possible to define collations which reverse the usual meanings of <, <=, >, and >= for their corresponding collations. This in turn makes it easier to do keyset pagination on text with mixes of ASC and DESC in the ORDER BY. diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index 55694c4368..3086936515 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -2106,6 +2106,13 @@ SCRAM-SHA-256$<replaceable><iteration count></replaceable>:<replaceable>&l <entry>Is the collation deterministic?</entry> </row> + <row> + <entry><structfield>collisreverse</structfield></entry> + <entry><type>bool</type></entry> + <entry></entry> + <entry>Is the collation reversed?</entry> + </row> + <row> <entry><structfield>collencoding</structfield></entry> <entry><type>int4</type></entry> diff --git a/doc/src/sgml/ref/create_collation.sgml b/doc/src/sgml/ref/create_collation.sgml index def4dda6e8..cb913871b7 100644 --- a/doc/src/sgml/ref/create_collation.sgml +++ b/doc/src/sgml/ref/create_collation.sgml @@ -24,7 +24,8 @@ CREATE COLLATION [ IF NOT EXISTS ] <replaceable>name</replaceable> ( [ LC_CTYPE = <replaceable>lc_ctype</replaceable>, ] [ PROVIDER = <replaceable>provider</replaceable>, ] [ DETERMINISTIC = <replaceable>boolean</replaceable>, ] - [ VERSION = <replaceable>version</replaceable> ] + [ VERSION = <replaceable>version</replaceable>, ] + [ REVERSE = <replaceable>boolean</replaceable> ] ) CREATE COLLATION [ IF NOT EXISTS ] <replaceable>name</replaceable> FROM <replaceable>existing_collation</replaceable> </synopsis> @@ -166,6 +167,16 @@ CREATE COLLATION [ IF NOT EXISTS ] <replaceable>name</replaceable> FROM <replace </listitem> </varlistentry> + <varlistentry> + <term><literal>REVERSE</literal></term> + + <listitem> + <para> + Specifies whether the collation should sort in reverse. Defaults to false. + </para> + </listitem> + </varlistentry> + <varlistentry> <term><replaceable>existing_collation</replaceable></term> @@ -225,6 +236,13 @@ CREATE COLLATION german_phonebook (provider = icu, locale = 'de-u-co-phonebk'); </programlisting> </para> + <para> + To create a collation from the <literal>C</literal> locale that sorts backwards: +<programlisting> +CREATE COLLATION C_sdrawckab (locale = 'C', reverse = true); +</programlisting> + </para> + <para> To create a collation from an existing collation: <programlisting> diff --git a/src/backend/catalog/pg_collation.c b/src/backend/catalog/pg_collation.c index dd99d53547..6198f77f36 100644 --- a/src/backend/catalog/pg_collation.c +++ b/src/backend/catalog/pg_collation.c @@ -47,6 +47,7 @@ CollationCreate(const char *collname, Oid collnamespace, Oid collowner, char collprovider, bool collisdeterministic, + bool collisreverse, int32 collencoding, const char *collcollate, const char *collctype, const char *collversion, @@ -162,6 +163,7 @@ CollationCreate(const char *collname, Oid collnamespace, values[Anum_pg_collation_collowner - 1] = ObjectIdGetDatum(collowner); values[Anum_pg_collation_collprovider - 1] = CharGetDatum(collprovider); values[Anum_pg_collation_collisdeterministic - 1] = BoolGetDatum(collisdeterministic); + values[Anum_pg_collation_collisreverse - 1] = BoolGetDatum(collisreverse); values[Anum_pg_collation_collencoding - 1] = Int32GetDatum(collencoding); namestrcpy(&name_collate, collcollate); values[Anum_pg_collation_collcollate - 1] = NameGetDatum(&name_collate); diff --git a/src/backend/commands/collationcmds.c b/src/backend/commands/collationcmds.c index 919e092483..ab37705b27 100644 --- a/src/backend/commands/collationcmds.c +++ b/src/backend/commands/collationcmds.c @@ -60,11 +60,13 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e DefElem *lcctypeEl = NULL; DefElem *providerEl = NULL; DefElem *deterministicEl = NULL; + DefElem *reverseEl = NULL; DefElem *versionEl = NULL; char *collcollate = NULL; char *collctype = NULL; char *collproviderstr = NULL; bool collisdeterministic = true; + bool collisreverse = false; int collencoding = 0; char collprovider = 0; char *collversion = NULL; @@ -95,6 +97,8 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e defelp = &providerEl; else if (strcmp(defel->defname, "deterministic") == 0) defelp = &deterministicEl; + else if (strcmp(defel->defname, "reverse") == 0) + defelp = &reverseEl; else if (strcmp(defel->defname, "version") == 0) defelp = &versionEl; else @@ -130,6 +134,7 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e collctype = pstrdup(NameStr(((Form_pg_collation) GETSTRUCT(tp))->collctype)); collprovider = ((Form_pg_collation) GETSTRUCT(tp))->collprovider; collisdeterministic = ((Form_pg_collation) GETSTRUCT(tp))->collisdeterministic; + collisreverse = ((Form_pg_collation) GETSTRUCT(tp))->collisreverse; collencoding = ((Form_pg_collation) GETSTRUCT(tp))->collencoding; ReleaseSysCache(tp); @@ -165,6 +170,9 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e if (deterministicEl) collisdeterministic = defGetBoolean(deterministicEl); + if (reverseEl) + collisreverse = defGetBoolean(reverseEl); + if (versionEl) collversion = defGetString(versionEl); @@ -222,6 +230,7 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e GetUserId(), collprovider, collisdeterministic, + collisreverse, collencoding, collcollate, collctype, @@ -605,7 +614,7 @@ pg_import_system_collations(PG_FUNCTION_ARGS) * about existing ones. */ collid = CollationCreate(localebuf, nspid, GetUserId(), - COLLPROVIDER_LIBC, true, enc, + COLLPROVIDER_LIBC, true, false, enc, localebuf, localebuf, get_collation_actual_version(COLLPROVIDER_LIBC, localebuf), true, true); @@ -666,7 +675,7 @@ pg_import_system_collations(PG_FUNCTION_ARGS) int enc = aliases[i].enc; collid = CollationCreate(alias, nspid, GetUserId(), - COLLPROVIDER_LIBC, true, enc, + COLLPROVIDER_LIBC, true, false, enc, locale, locale, get_collation_actual_version(COLLPROVIDER_LIBC, locale), true, true); @@ -728,7 +737,7 @@ pg_import_system_collations(PG_FUNCTION_ARGS) collid = CollationCreate(psprintf("%s-x-icu", langtag), nspid, GetUserId(), - COLLPROVIDER_ICU, true, -1, + COLLPROVIDER_ICU, true, false, -1, collcollate, collcollate, get_collation_actual_version(COLLPROVIDER_ICU, collcollate), true, true); diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index fcdbaae37b..f9e47c8bff 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -1155,7 +1155,8 @@ lookup_collation_cache(Oid collation, bool set_flags) collcollate = NameStr(collform->collcollate); collctype = NameStr(collform->collctype); - cache_entry->collate_is_c = ((strcmp(collcollate, "C") == 0) || + cache_entry->collate_is_c = !collform->collisreverse && + ((strcmp(collcollate, "C") == 0) || (strcmp(collcollate, "POSIX") == 0)); cache_entry->ctype_is_c = ((strcmp(collctype, "C") == 0) || (strcmp(collctype, "POSIX") == 0)); @@ -1357,6 +1358,7 @@ pg_newlocale_from_collation(Oid collid) memset(&result, 0, sizeof(result)); result.provider = collform->collprovider; result.deterministic = collform->collisdeterministic; + result.reverse = collform->collisreverse; if (collform->collprovider == COLLPROVIDER_LIBC) { diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index 69165eb311..61ab9720c5 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -84,6 +84,7 @@ typedef struct int last_returned; /* Last comparison result (cache) */ bool cache_blob; /* Does buf2 contain strxfrm() blob, etc? */ bool collate_c; + bool reverse; Oid typid; /* Actual datatype (text/bpchar/bytea/name) */ hyperLogLogState abbr_card; /* Abbreviated key cardinality state */ hyperLogLogState full_card; /* Full key cardinality state */ @@ -1603,6 +1604,9 @@ varstr_cmp(const char *arg1, int len1, const char *arg2, int len2, Oid collid) if (a2p != a2buf) pfree(a2p); + if (collid != DEFAULT_COLLATION_OID && mylocale->reverse) + INVERT_COMPARE_RESULT(result); + return result; } #endif /* WIN32 */ @@ -1681,6 +1685,9 @@ varstr_cmp(const char *arg1, int len1, const char *arg2, int len2, Oid collid) (!mylocale || mylocale->deterministic)) result = strcmp(a1p, a2p); + if (collid != DEFAULT_COLLATION_OID && mylocale->reverse) + INVERT_COMPARE_RESULT(result); + if (a1p != a1buf) pfree(a1p); if (a2p != a2buf) @@ -2084,6 +2091,7 @@ varstr_sortsupport(SortSupport ssup, Oid typid, Oid collid) /* Initialize */ sss->last_returned = 0; sss->locale = locale; + sss->reverse = (locale != 0) && locale->reverse; /* * To avoid somehow confusing a strxfrm() blob and an original string, @@ -2395,6 +2403,9 @@ varstrfastcmp_locale(char *a1p, int len1, char *a2p, int len2, SortSupport ssup) (!sss->locale || sss->locale->deterministic)) result = strcmp(sss->buf1, sss->buf2); + if (sss->reverse) + INVERT_COMPARE_RESULT(result); + /* Cache result, perhaps saving an expensive strcoll() call next time */ sss->cache_blob = false; sss->last_returned = result; @@ -2657,6 +2668,13 @@ done: */ res = DatumBigEndianToNative(res); + /* + * Account for reverse-ordering locales by flipping the bits. Note that + * Datum is an unsigned type (uintptr_t). + */ + if (sss->reverse) + res ^= ~(Datum)0; + /* Don't leak memory here */ if (PointerGetDatum(authoritative) != original) pfree(authoritative); diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 27602fa49c..61daf205d8 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -954,6 +954,22 @@ get_collation_isdeterministic(Oid colloid) return result; } +bool +get_collation_isreverse(Oid colloid) +{ + HeapTuple tp; + Form_pg_collation colltup; + bool result; + + tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(colloid)); + if (!HeapTupleIsValid(tp)) + elog(ERROR, "cache lookup failed for collation %u", colloid); + colltup = (Form_pg_collation) GETSTRUCT(tp); + result = colltup->collisreverse; + ReleaseSysCache(tp); + return result; +} + /* ---------- CONSTRAINT CACHE ---------- */ /* diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 88a261d9bd..33e357c300 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -1712,8 +1712,8 @@ setup_collation(FILE *cmdfd) * in pg_collation.h. But add it before reading system collations, so * that it wins if libc defines a locale named ucs_basic. */ - PG_CMD_PRINTF("INSERT INTO pg_collation (oid, collname, collnamespace, collowner, collprovider, collisdeterministic, collencoding, collcollate, collctype)" - "VALUES (pg_nextoid('pg_catalog.pg_collation', 'oid', 'pg_catalog.pg_collation_oid_index'), 'ucs_basic', 'pg_catalog'::regnamespace, %u, '%c', true, %d, 'C', 'C');\n\n", + PG_CMD_PRINTF("INSERT INTO pg_collation (oid, collname, collnamespace, collowner, collprovider, collisdeterministic, collisreverse, collencoding, collcollate, collctype)" + "VALUES (pg_nextoid('pg_catalog.pg_collation', 'oid', 'pg_catalog.pg_collation_oid_index'), 'ucs_basic', 'pg_catalog'::regnamespace, %u, '%c', true, false, %d, 'C', 'C');\n\n", BOOTSTRAP_SUPERUSERID, COLLPROVIDER_LIBC, PG_UTF8); /* Now import all collations we can find in the operating system */ diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index bf69adc2f4..32801744b9 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -13466,6 +13466,7 @@ dumpCollation(Archive *fout, CollInfo *collinfo) PGresult *res; int i_collprovider; int i_collisdeterministic; + int i_collisreverse; int i_collcollate; int i_collctype; const char *collprovider; @@ -13501,6 +13502,13 @@ dumpCollation(Archive *fout, CollInfo *collinfo) appendPQExpBufferStr(query, "true AS collisdeterministic, "); + if (fout->remoteVersion >= 130000) + appendPQExpBufferStr(query, + "collisreverse, "); + else + appendPQExpBufferStr(query, + "false as collisreverse, "); + appendPQExpBuffer(query, "collcollate, " "collctype " @@ -13512,6 +13520,7 @@ dumpCollation(Archive *fout, CollInfo *collinfo) i_collprovider = PQfnumber(res, "collprovider"); i_collisdeterministic = PQfnumber(res, "collisdeterministic"); + i_collisreverse = PQfnumber(res, "collisreverse"); i_collcollate = PQfnumber(res, "collcollate"); i_collctype = PQfnumber(res, "collctype"); @@ -13540,6 +13549,9 @@ dumpCollation(Archive *fout, CollInfo *collinfo) if (strcmp(PQgetvalue(res, 0, i_collisdeterministic), "f") == 0) appendPQExpBufferStr(q, ", deterministic = false"); + if (strcmp(PQgetvalue(res, 0, i_collisreverse), "t") == 0) + appendPQExpBufferStr(q, ", reverse = true"); + if (strcmp(collcollate, collctype) == 0) { appendPQExpBufferStr(q, ", locale = "); diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index b3b9313b36..d87aa96915 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -4525,6 +4525,17 @@ listCollations(const char *pattern, bool verbose, bool showSystem) gettext_noop("yes"), gettext_noop("Deterministic?")); + if (pset.sversion >= 130000) + appendPQExpBuffer(&buf, + ",\n CASE WHEN c.collisreverse THEN '%s' ELSE '%s' END AS \"%s\"", + gettext_noop("yes"), gettext_noop("no"), + gettext_noop("Reverse?")); + else + appendPQExpBuffer(&buf, + ",\n '%s' AS \"%s\"", + gettext_noop("no"), + gettext_noop("Reverse?")); + if (verbose) appendPQExpBuffer(&buf, ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"", diff --git a/src/include/catalog/pg_collation.h b/src/include/catalog/pg_collation.h index d3366f361d..929d521d05 100644 --- a/src/include/catalog/pg_collation.h +++ b/src/include/catalog/pg_collation.h @@ -34,6 +34,7 @@ CATALOG(pg_collation,3456,CollationRelationId) Oid collowner; /* owner of collation */ char collprovider; /* see constants below */ bool collisdeterministic BKI_DEFAULT(t); + bool collisreverse BKI_DEFAULT(f); int32 collencoding; /* encoding for this collation; -1 = "all" */ NameData collcollate; /* LC_COLLATE setting */ NameData collctype; /* LC_CTYPE setting */ @@ -63,6 +64,7 @@ extern Oid CollationCreate(const char *collname, Oid collnamespace, Oid collowner, char collprovider, bool collisdeterministic, + bool collisreverse, int32 collencoding, const char *collcollate, const char *collctype, const char *collversion, diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index c8df5bff9f..90e1fbc33a 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -92,6 +92,7 @@ extern void get_atttypetypmodcoll(Oid relid, AttrNumber attnum, Oid *typid, int32 *typmod, Oid *collid); extern char *get_collation_name(Oid colloid); extern bool get_collation_isdeterministic(Oid colloid); +extern bool get_collation_isreverse(Oid colloid); extern char *get_constraint_name(Oid conoid); extern char *get_language_name(Oid langoid, bool missing_ok); extern Oid get_opclass_family(Oid opclass); diff --git a/src/include/utils/pg_locale.h b/src/include/utils/pg_locale.h index b4b3aa5843..d571eab4c6 100644 --- a/src/include/utils/pg_locale.h +++ b/src/include/utils/pg_locale.h @@ -83,6 +83,7 @@ struct pg_locale_struct { char provider; bool deterministic; + bool reverse; union { #ifdef HAVE_LOCALE_T diff --git a/src/test/regress/expected/collate.out b/src/test/regress/expected/collate.out index 0dee7d783a..2e51dde931 100644 --- a/src/test/regress/expected/collate.out +++ b/src/test/regress/expected/collate.out @@ -11,6 +11,7 @@ */ CREATE SCHEMA collate_tests; SET search_path = collate_tests; +CREATE COLLATION "C_sdrawckab" (locale = 'C', reverse = true); CREATE TABLE collate_test1 ( a int, b text COLLATE "C" NOT NULL @@ -66,6 +67,14 @@ SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'abc' COLLATE "C"; 3 | bbc (2 rows) +SELECT * FROM collate_test1 WHERE b COLLATE "C_sdrawckab" >= 'abc' COLLATE "C_sdrawckab"; + a | b +---+----- + 1 | abc + 2 | Abc + 4 | ABD +(3 rows) + SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc' COLLATE "POSIX"; -- fail ERROR: collation mismatch between explicit collations "C" and "POSIX" LINE 1: ...* FROM collate_test1 WHERE b COLLATE "C" >= 'bbc' COLLATE "P... @@ -682,8 +691,9 @@ SELECT collation for ((SELECT b FROM collate_test1 LIMIT 1)); -- must get rid of them. -- DROP SCHEMA collate_tests CASCADE; -NOTICE: drop cascades to 17 other objects -DETAIL: drop cascades to table collate_test1 +NOTICE: drop cascades to 18 other objects +DETAIL: drop cascades to collation "C_sdrawckab" +drop cascades to table collate_test1 drop cascades to table collate_test_like drop cascades to table collate_test2 drop cascades to type testdomain_p diff --git a/src/test/regress/sql/collate.sql b/src/test/regress/sql/collate.sql index 89de26a227..1317ad4733 100644 --- a/src/test/regress/sql/collate.sql +++ b/src/test/regress/sql/collate.sql @@ -13,6 +13,8 @@ CREATE SCHEMA collate_tests; SET search_path = collate_tests; +CREATE COLLATION "C_sdrawckab" (locale = 'C', reverse = true); + CREATE TABLE collate_test1 ( a int, b text COLLATE "C" NOT NULL @@ -42,6 +44,7 @@ INSERT INTO collate_test2 SELECT * FROM collate_test1; SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'abc'; SELECT * FROM collate_test1 WHERE b >= 'abc' COLLATE "C"; SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'abc' COLLATE "C"; +SELECT * FROM collate_test1 WHERE b COLLATE "C_sdrawckab" >= 'abc' COLLATE "C_sdrawckab"; SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc' COLLATE "POSIX"; -- fail CREATE DOMAIN testdomain_p AS text COLLATE "POSIX"; ^ permalink raw reply [nested|flat] 4+ messages in thread
* [PATCH v1 1/2] Add allocator attributes. @ 2023-06-26 19:17 Andres Freund <[email protected]> 0 siblings, 0 replies; 4+ messages in thread From: Andres Freund @ 2023-06-26 19:17 UTC (permalink / raw) Author: Reviewed-By: Discussion: https://postgr.es/m/ Backpatch: --- src/include/c.h | 9 ++++ src/include/nodes/bitmapset.h | 40 ++++++++++----- src/include/nodes/pg_list.h | 97 +++++++++++++++++++++++++++++++++++ src/include/utils/palloc.h | 55 ++++++++++++-------- 4 files changed, 167 insertions(+), 34 deletions(-) diff --git a/src/include/c.h b/src/include/c.h index f69d739be57..920fdf983a1 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -295,6 +295,15 @@ #define unlikely(x) ((x) != 0) #endif +#if defined(__GNUC__) && !defined(__clang__) +#define pg_malloc_attr(deallocator) malloc(deallocator) +#define pg_malloc_attr_i(deallocator, ptr_at) malloc(deallocator, ptr_at) +#else +#define pg_malloc_attr(deallocator) +#define pg_malloc_attr_i(deallocator, ptr_at) +#endif + + /* * CppAsString * Convert the argument to a string, using the C preprocessor. diff --git a/src/include/nodes/bitmapset.h b/src/include/nodes/bitmapset.h index 14de6a9ff1e..5037f6907ec 100644 --- a/src/include/nodes/bitmapset.h +++ b/src/include/nodes/bitmapset.h @@ -78,15 +78,27 @@ typedef enum * function prototypes in nodes/bitmapset.c */ -extern Bitmapset *bms_copy(const Bitmapset *a); -extern bool bms_equal(const Bitmapset *a, const Bitmapset *b); -extern int bms_compare(const Bitmapset *a, const Bitmapset *b); -extern Bitmapset *bms_make_singleton(int x); +extern Bitmapset *bms_add_member(Bitmapset *a, int x); +extern Bitmapset *bms_del_member(Bitmapset *a, int x); +extern Bitmapset *bms_add_members(Bitmapset *a, const Bitmapset *b); +extern Bitmapset *bms_add_range(Bitmapset *a, int lower, int upper); +extern Bitmapset *bms_int_members(Bitmapset *a, const Bitmapset *b); +extern Bitmapset *bms_del_members(Bitmapset *a, const Bitmapset *b); +extern Bitmapset *bms_join(Bitmapset *a, Bitmapset *b); extern void bms_free(Bitmapset *a); -extern Bitmapset *bms_union(const Bitmapset *a, const Bitmapset *b); -extern Bitmapset *bms_intersect(const Bitmapset *a, const Bitmapset *b); -extern Bitmapset *bms_difference(const Bitmapset *a, const Bitmapset *b); +#define BMS_ALLOC_ATTRIBUTES __attribute__((pg_malloc_attr(bms_free), pg_malloc_attr(bms_add_member), pg_malloc_attr(bms_del_member), pg_malloc_attr(bms_add_members), pg_malloc_attr(bms_add_range), pg_malloc_attr(bms_int_members), pg_malloc_attr(bms_del_members), pg_malloc_attr(bms_join), warn_unused_result)) + +extern Bitmapset *bms_copy(const Bitmapset *a) BMS_ALLOC_ATTRIBUTES; +extern bool bms_equal(const Bitmapset *a, const Bitmapset *b); +extern int bms_compare(const Bitmapset *a, const Bitmapset *b); +extern Bitmapset *bms_make_singleton(int x) BMS_ALLOC_ATTRIBUTES; +extern void bms_free(Bitmapset *a); + +extern Bitmapset *bms_union(const Bitmapset *a, const Bitmapset *b) BMS_ALLOC_ATTRIBUTES; +extern Bitmapset *bms_intersect(const Bitmapset *a, const Bitmapset *b) BMS_ALLOC_ATTRIBUTES; +extern Bitmapset *bms_difference(const Bitmapset *a, const Bitmapset *b) BMS_ALLOC_ATTRIBUTES; + extern bool bms_is_subset(const Bitmapset *a, const Bitmapset *b); extern BMS_Comparison bms_subset_compare(const Bitmapset *a, const Bitmapset *b); extern bool bms_is_member(int x, const Bitmapset *a); @@ -106,13 +118,13 @@ extern BMS_Membership bms_membership(const Bitmapset *a); /* these routines recycle (modify or free) their non-const inputs: */ -extern Bitmapset *bms_add_member(Bitmapset *a, int x); -extern Bitmapset *bms_del_member(Bitmapset *a, int x); -extern Bitmapset *bms_add_members(Bitmapset *a, const Bitmapset *b); -extern Bitmapset *bms_add_range(Bitmapset *a, int lower, int upper); -extern Bitmapset *bms_int_members(Bitmapset *a, const Bitmapset *b); -extern Bitmapset *bms_del_members(Bitmapset *a, const Bitmapset *b); -extern Bitmapset *bms_join(Bitmapset *a, Bitmapset *b); +extern Bitmapset *bms_add_member(Bitmapset *a, int x) BMS_ALLOC_ATTRIBUTES; +extern Bitmapset *bms_del_member(Bitmapset *a, int x) BMS_ALLOC_ATTRIBUTES; +extern Bitmapset *bms_add_members(Bitmapset *a, const Bitmapset *b) BMS_ALLOC_ATTRIBUTES; +extern Bitmapset *bms_add_range(Bitmapset *a, int lower, int upper) BMS_ALLOC_ATTRIBUTES; +extern Bitmapset *bms_int_members(Bitmapset *a, const Bitmapset *b) BMS_ALLOC_ATTRIBUTES; +extern Bitmapset *bms_del_members(Bitmapset *a, const Bitmapset *b) BMS_ALLOC_ATTRIBUTES; +extern Bitmapset *bms_join(Bitmapset *a, Bitmapset *b) BMS_ALLOC_ATTRIBUTES; /* support for iterating through the integer elements of a set: */ extern int bms_next_member(const Bitmapset *a, int prevbit); diff --git a/src/include/nodes/pg_list.h b/src/include/nodes/pg_list.h index 529a382d284..285d8c2c7ed 100644 --- a/src/include/nodes/pg_list.h +++ b/src/include/nodes/pg_list.h @@ -632,4 +632,101 @@ extern void list_sort(List *list, list_sort_comparator cmp); extern int list_int_cmp(const ListCell *p1, const ListCell *p2); extern int list_oid_cmp(const ListCell *p1, const ListCell *p2); + +#define PG_LIST_ALLOC_ATTR __attribute__(( \ + pg_malloc_attr(lappend), \ + pg_malloc_attr(lappend_int), \ + pg_malloc_attr(lappend_oid), \ + pg_malloc_attr(lappend_xid), \ + pg_malloc_attr(list_insert_nth), \ + pg_malloc_attr(list_insert_nth_int), \ + pg_malloc_attr(list_insert_nth_oid), \ + pg_malloc_attr_i(lcons, 2), \ + pg_malloc_attr_i(lcons_int, 2), \ + pg_malloc_attr_i(lcons_oid, 2), \ + pg_malloc_attr(list_concat), \ + pg_malloc_attr(list_truncate), \ + pg_malloc_attr(list_delete), \ + pg_malloc_attr(list_delete_ptr), \ + pg_malloc_attr(list_delete_int), \ + pg_malloc_attr(list_delete_oid), \ + pg_malloc_attr(list_delete_first), \ + pg_malloc_attr(list_delete_last), \ + pg_malloc_attr(list_delete_first_n), \ + pg_malloc_attr(list_delete_nth_cell), \ + pg_malloc_attr(list_delete_cell), \ + pg_malloc_attr(list_union), \ + pg_malloc_attr(list_append_unique), \ + pg_malloc_attr(list_append_unique_ptr), \ + pg_malloc_attr(list_append_unique_int), \ + pg_malloc_attr(list_append_unique_oid), \ + pg_malloc_attr(list_concat_unique), \ + pg_malloc_attr(list_concat_unique_ptr), \ + pg_malloc_attr(list_concat_unique_int), \ + pg_malloc_attr(list_concat_unique_oid), \ + pg_malloc_attr(list_free), \ + pg_malloc_attr(list_free_deep), \ + warn_unused_result)) + +extern PG_LIST_ALLOC_ATTR List *list_make1_impl(NodeTag t, ListCell datum1); +extern PG_LIST_ALLOC_ATTR List *list_make2_impl(NodeTag t, ListCell datum1, ListCell datum2); +extern PG_LIST_ALLOC_ATTR List *list_make3_impl(NodeTag t, ListCell datum1, ListCell datum2, + ListCell datum3); +extern PG_LIST_ALLOC_ATTR List *list_make4_impl(NodeTag t, ListCell datum1, ListCell datum2, + ListCell datum3, ListCell datum4); +extern PG_LIST_ALLOC_ATTR List *list_make5_impl(NodeTag t, ListCell datum1, ListCell datum2, + ListCell datum3, ListCell datum4, + ListCell datum5); + +extern PG_LIST_ALLOC_ATTR List *lappend(List *list, void *datum); +extern PG_LIST_ALLOC_ATTR List *lappend_int(List *list, int datum); +extern PG_LIST_ALLOC_ATTR List *lappend_oid(List *list, Oid datum); +extern PG_LIST_ALLOC_ATTR List *lappend_xid(List *list, TransactionId datum); + +extern PG_LIST_ALLOC_ATTR List *list_insert_nth(List *list, int pos, void *datum); +extern PG_LIST_ALLOC_ATTR List *list_insert_nth_int(List *list, int pos, int datum); +extern PG_LIST_ALLOC_ATTR List *list_insert_nth_oid(List *list, int pos, Oid datum); + +extern PG_LIST_ALLOC_ATTR List *lcons(void *datum, List *list); +extern PG_LIST_ALLOC_ATTR List *lcons_int(int datum, List *list); +extern PG_LIST_ALLOC_ATTR List *lcons_oid(Oid datum, List *list); + +extern PG_LIST_ALLOC_ATTR List *list_concat(List *list1, const List *list2); +extern PG_LIST_ALLOC_ATTR List *list_concat_copy(const List *list1, const List *list2); + +extern PG_LIST_ALLOC_ATTR List *list_truncate(List *list, int new_size); + +extern PG_LIST_ALLOC_ATTR List *list_delete(List *list, void *datum); +extern PG_LIST_ALLOC_ATTR List *list_delete_ptr(List *list, void *datum); +extern PG_LIST_ALLOC_ATTR List *list_delete_int(List *list, int datum); +extern PG_LIST_ALLOC_ATTR List *list_delete_oid(List *list, Oid datum); +extern PG_LIST_ALLOC_ATTR List *list_delete_first(List *list); +extern PG_LIST_ALLOC_ATTR List *list_delete_last(List *list); +extern PG_LIST_ALLOC_ATTR List *list_delete_first_n(List *list, int n); +extern PG_LIST_ALLOC_ATTR List *list_delete_nth_cell(List *list, int n); +extern PG_LIST_ALLOC_ATTR List *list_delete_cell(List *list, ListCell *cell); + +extern PG_LIST_ALLOC_ATTR List *list_union(const List *list1, const List *list2); +extern PG_LIST_ALLOC_ATTR List *list_union_ptr(const List *list1, const List *list2); +extern PG_LIST_ALLOC_ATTR List *list_union_int(const List *list1, const List *list2); +extern PG_LIST_ALLOC_ATTR List *list_union_oid(const List *list1, const List *list2); + +extern PG_LIST_ALLOC_ATTR List *list_intersection(const List *list1, const List *list2); +extern PG_LIST_ALLOC_ATTR List *list_intersection_int(const List *list1, const List *list2); + +extern PG_LIST_ALLOC_ATTR List *list_append_unique(List *list, void *datum); +extern PG_LIST_ALLOC_ATTR List *list_append_unique_ptr(List *list, void *datum); +extern PG_LIST_ALLOC_ATTR List *list_append_unique_int(List *list, int datum); +extern PG_LIST_ALLOC_ATTR List *list_append_unique_oid(List *list, Oid datum); + +extern PG_LIST_ALLOC_ATTR List *list_concat_unique(List *list1, const List *list2); +extern PG_LIST_ALLOC_ATTR List *list_concat_unique_ptr(List *list1, const List *list2); +extern PG_LIST_ALLOC_ATTR List *list_concat_unique_int(List *list1, const List *list2); +extern PG_LIST_ALLOC_ATTR List *list_concat_unique_oid(List *list1, const List *list2); + +extern PG_LIST_ALLOC_ATTR List *list_copy(const List *oldlist); +extern PG_LIST_ALLOC_ATTR List *list_copy_head(const List *oldlist, int len); +extern PG_LIST_ALLOC_ATTR List *list_copy_tail(const List *oldlist, int nskip); +extern PG_LIST_ALLOC_ATTR List *list_copy_deep(const List *oldlist); + #endif /* PG_LIST_H */ diff --git a/src/include/utils/palloc.h b/src/include/utils/palloc.h index d1146c12351..a9e8063023f 100644 --- a/src/include/utils/palloc.h +++ b/src/include/utils/palloc.h @@ -65,25 +65,40 @@ extern PGDLLIMPORT MemoryContext CurrentMemoryContext; #define MCXT_ALLOC_NO_OOM 0x02 /* no failure if out-of-memory */ #define MCXT_ALLOC_ZERO 0x04 /* zero allocated memory */ +#define pg_alloc_attributes(size_at) \ + __attribute__((malloc, pg_malloc_attr_i(pfree, 1), alloc_size(size_at), assume_aligned(MAXIMUM_ALIGNOF), returns_nonnull, warn_unused_result)) +#define pg_alloc_noerr_attributes(size_at) \ + __attribute__((malloc, pg_malloc_attr_i(pfree, 1), alloc_size(size_at), assume_aligned(MAXIMUM_ALIGNOF), warn_unused_result)) +#define pg_realloc_attributes(old_at, size_at) \ + __attribute__((alloc_size(size_at), assume_aligned(MAXIMUM_ALIGNOF), \ + nonnull(old_at), returns_nonnull, warn_unused_result)) +#define pg_realloc_noerr_attributes(old_at, size_at) \ + __attribute__((alloc_size(size_at), assume_aligned(MAXIMUM_ALIGNOF), \ + nonnull(old_at), warn_unused_result)) +#define pg_dup_attributes(source_at) \ + __attribute__((malloc, pg_malloc_attr_i(pfree, 1), assume_aligned(MAXIMUM_ALIGNOF), returns_nonnull, nonnull(source_at), warn_unused_result)) + +extern void pfree(void *pointer); + /* * Fundamental memory-allocation operations (more are in utils/memutils.h) */ -extern void *MemoryContextAlloc(MemoryContext context, Size size); -extern void *MemoryContextAllocZero(MemoryContext context, Size size); -extern void *MemoryContextAllocZeroAligned(MemoryContext context, Size size); +extern void *MemoryContextAlloc(MemoryContext context, Size size) pg_alloc_attributes(2); +extern void *MemoryContextAllocZero(MemoryContext context, Size size) pg_alloc_attributes(2); +extern void *MemoryContextAllocZeroAligned(MemoryContext context, Size size) pg_alloc_attributes(2); extern void *MemoryContextAllocExtended(MemoryContext context, - Size size, int flags); + Size size, int flags) pg_alloc_noerr_attributes(2); extern void *MemoryContextAllocAligned(MemoryContext context, - Size size, Size alignto, int flags); + Size size, Size alignto, int flags) pg_alloc_noerr_attributes(2); -extern void *palloc(Size size); -extern void *palloc0(Size size); -extern void *palloc_extended(Size size, int flags); -extern void *palloc_aligned(Size size, Size alignto, int flags); -extern pg_nodiscard void *repalloc(void *pointer, Size size); +extern void *palloc(Size size) pg_alloc_attributes(1); +extern void *palloc0(Size size) pg_alloc_attributes(1); +extern void *palloc_extended(Size size, int flags) pg_alloc_noerr_attributes(1); +extern void *palloc_aligned(Size size, Size alignto, int flags) pg_alloc_noerr_attributes(1); +extern pg_nodiscard void *repalloc(void *pointer, Size size) pg_realloc_attributes(1, 2); extern pg_nodiscard void *repalloc_extended(void *pointer, - Size size, int flags); -extern pg_nodiscard void *repalloc0(void *pointer, Size oldsize, Size size); + Size size, int flags) pg_realloc_noerr_attributes(1, 2); +extern pg_nodiscard void *repalloc0(void *pointer, Size oldsize, Size size) pg_realloc_attributes(1, 2); extern void pfree(void *pointer); /* @@ -123,8 +138,8 @@ extern void pfree(void *pointer); MemoryContextAllocZero(CurrentMemoryContext, sz) ) /* Higher-limit allocators. */ -extern void *MemoryContextAllocHuge(MemoryContext context, Size size); -extern pg_nodiscard void *repalloc_huge(void *pointer, Size size); +extern void *MemoryContextAllocHuge(MemoryContext context, Size size) pg_alloc_attributes(2); +extern pg_nodiscard void *repalloc_huge(void *pointer, Size size) pg_realloc_attributes(1, 2); /* * Although this header file is nominally backend-only, certain frontend @@ -152,14 +167,14 @@ extern void MemoryContextRegisterResetCallback(MemoryContext context, * These are like standard strdup() except the copied string is * allocated in a context, not with malloc(). */ -extern char *MemoryContextStrdup(MemoryContext context, const char *string); -extern char *pstrdup(const char *in); -extern char *pnstrdup(const char *in, Size len); +extern char *MemoryContextStrdup(MemoryContext context, const char *string) pg_dup_attributes(2); +extern char *pstrdup(const char *in) pg_dup_attributes(1); +extern char *pnstrdup(const char *in, Size len) pg_dup_attributes(1); -extern char *pchomp(const char *in); +extern char *pchomp(const char *in) pg_dup_attributes(1); /* sprintf into a palloc'd buffer --- these are in psprintf.c */ -extern char *psprintf(const char *fmt,...) pg_attribute_printf(1, 2); -extern size_t pvsnprintf(char *buf, size_t len, const char *fmt, va_list args) pg_attribute_printf(3, 0); +extern char *psprintf(const char *fmt,...) pg_attribute_printf(1, 2) __attribute__((malloc, returns_nonnull, warn_unused_result)); +extern size_t pvsnprintf(char *buf, size_t len, const char *fmt, va_list args) pg_attribute_printf(3, 0) __attribute__((warn_unused_result)); #endif /* PALLOC_H */ -- 2.38.0 --dqvxegae2emmr5ba-- ^ permalink raw reply [nested|flat] 4+ messages in thread
* [PATCH v1 1/2] Add allocator attributes. @ 2023-06-26 19:17 Andres Freund <[email protected]> 0 siblings, 0 replies; 4+ messages in thread From: Andres Freund @ 2023-06-26 19:17 UTC (permalink / raw) Author: Reviewed-By: Discussion: https://postgr.es/m/ Backpatch: --- src/include/c.h | 9 ++++ src/include/nodes/bitmapset.h | 40 ++++++++++----- src/include/nodes/pg_list.h | 97 +++++++++++++++++++++++++++++++++++ src/include/utils/palloc.h | 55 ++++++++++++-------- 4 files changed, 167 insertions(+), 34 deletions(-) diff --git a/src/include/c.h b/src/include/c.h index f69d739be57..920fdf983a1 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -295,6 +295,15 @@ #define unlikely(x) ((x) != 0) #endif +#if defined(__GNUC__) && !defined(__clang__) +#define pg_malloc_attr(deallocator) malloc(deallocator) +#define pg_malloc_attr_i(deallocator, ptr_at) malloc(deallocator, ptr_at) +#else +#define pg_malloc_attr(deallocator) +#define pg_malloc_attr_i(deallocator, ptr_at) +#endif + + /* * CppAsString * Convert the argument to a string, using the C preprocessor. diff --git a/src/include/nodes/bitmapset.h b/src/include/nodes/bitmapset.h index 14de6a9ff1e..5037f6907ec 100644 --- a/src/include/nodes/bitmapset.h +++ b/src/include/nodes/bitmapset.h @@ -78,15 +78,27 @@ typedef enum * function prototypes in nodes/bitmapset.c */ -extern Bitmapset *bms_copy(const Bitmapset *a); -extern bool bms_equal(const Bitmapset *a, const Bitmapset *b); -extern int bms_compare(const Bitmapset *a, const Bitmapset *b); -extern Bitmapset *bms_make_singleton(int x); +extern Bitmapset *bms_add_member(Bitmapset *a, int x); +extern Bitmapset *bms_del_member(Bitmapset *a, int x); +extern Bitmapset *bms_add_members(Bitmapset *a, const Bitmapset *b); +extern Bitmapset *bms_add_range(Bitmapset *a, int lower, int upper); +extern Bitmapset *bms_int_members(Bitmapset *a, const Bitmapset *b); +extern Bitmapset *bms_del_members(Bitmapset *a, const Bitmapset *b); +extern Bitmapset *bms_join(Bitmapset *a, Bitmapset *b); extern void bms_free(Bitmapset *a); -extern Bitmapset *bms_union(const Bitmapset *a, const Bitmapset *b); -extern Bitmapset *bms_intersect(const Bitmapset *a, const Bitmapset *b); -extern Bitmapset *bms_difference(const Bitmapset *a, const Bitmapset *b); +#define BMS_ALLOC_ATTRIBUTES __attribute__((pg_malloc_attr(bms_free), pg_malloc_attr(bms_add_member), pg_malloc_attr(bms_del_member), pg_malloc_attr(bms_add_members), pg_malloc_attr(bms_add_range), pg_malloc_attr(bms_int_members), pg_malloc_attr(bms_del_members), pg_malloc_attr(bms_join), warn_unused_result)) + +extern Bitmapset *bms_copy(const Bitmapset *a) BMS_ALLOC_ATTRIBUTES; +extern bool bms_equal(const Bitmapset *a, const Bitmapset *b); +extern int bms_compare(const Bitmapset *a, const Bitmapset *b); +extern Bitmapset *bms_make_singleton(int x) BMS_ALLOC_ATTRIBUTES; +extern void bms_free(Bitmapset *a); + +extern Bitmapset *bms_union(const Bitmapset *a, const Bitmapset *b) BMS_ALLOC_ATTRIBUTES; +extern Bitmapset *bms_intersect(const Bitmapset *a, const Bitmapset *b) BMS_ALLOC_ATTRIBUTES; +extern Bitmapset *bms_difference(const Bitmapset *a, const Bitmapset *b) BMS_ALLOC_ATTRIBUTES; + extern bool bms_is_subset(const Bitmapset *a, const Bitmapset *b); extern BMS_Comparison bms_subset_compare(const Bitmapset *a, const Bitmapset *b); extern bool bms_is_member(int x, const Bitmapset *a); @@ -106,13 +118,13 @@ extern BMS_Membership bms_membership(const Bitmapset *a); /* these routines recycle (modify or free) their non-const inputs: */ -extern Bitmapset *bms_add_member(Bitmapset *a, int x); -extern Bitmapset *bms_del_member(Bitmapset *a, int x); -extern Bitmapset *bms_add_members(Bitmapset *a, const Bitmapset *b); -extern Bitmapset *bms_add_range(Bitmapset *a, int lower, int upper); -extern Bitmapset *bms_int_members(Bitmapset *a, const Bitmapset *b); -extern Bitmapset *bms_del_members(Bitmapset *a, const Bitmapset *b); -extern Bitmapset *bms_join(Bitmapset *a, Bitmapset *b); +extern Bitmapset *bms_add_member(Bitmapset *a, int x) BMS_ALLOC_ATTRIBUTES; +extern Bitmapset *bms_del_member(Bitmapset *a, int x) BMS_ALLOC_ATTRIBUTES; +extern Bitmapset *bms_add_members(Bitmapset *a, const Bitmapset *b) BMS_ALLOC_ATTRIBUTES; +extern Bitmapset *bms_add_range(Bitmapset *a, int lower, int upper) BMS_ALLOC_ATTRIBUTES; +extern Bitmapset *bms_int_members(Bitmapset *a, const Bitmapset *b) BMS_ALLOC_ATTRIBUTES; +extern Bitmapset *bms_del_members(Bitmapset *a, const Bitmapset *b) BMS_ALLOC_ATTRIBUTES; +extern Bitmapset *bms_join(Bitmapset *a, Bitmapset *b) BMS_ALLOC_ATTRIBUTES; /* support for iterating through the integer elements of a set: */ extern int bms_next_member(const Bitmapset *a, int prevbit); diff --git a/src/include/nodes/pg_list.h b/src/include/nodes/pg_list.h index 529a382d284..285d8c2c7ed 100644 --- a/src/include/nodes/pg_list.h +++ b/src/include/nodes/pg_list.h @@ -632,4 +632,101 @@ extern void list_sort(List *list, list_sort_comparator cmp); extern int list_int_cmp(const ListCell *p1, const ListCell *p2); extern int list_oid_cmp(const ListCell *p1, const ListCell *p2); + +#define PG_LIST_ALLOC_ATTR __attribute__(( \ + pg_malloc_attr(lappend), \ + pg_malloc_attr(lappend_int), \ + pg_malloc_attr(lappend_oid), \ + pg_malloc_attr(lappend_xid), \ + pg_malloc_attr(list_insert_nth), \ + pg_malloc_attr(list_insert_nth_int), \ + pg_malloc_attr(list_insert_nth_oid), \ + pg_malloc_attr_i(lcons, 2), \ + pg_malloc_attr_i(lcons_int, 2), \ + pg_malloc_attr_i(lcons_oid, 2), \ + pg_malloc_attr(list_concat), \ + pg_malloc_attr(list_truncate), \ + pg_malloc_attr(list_delete), \ + pg_malloc_attr(list_delete_ptr), \ + pg_malloc_attr(list_delete_int), \ + pg_malloc_attr(list_delete_oid), \ + pg_malloc_attr(list_delete_first), \ + pg_malloc_attr(list_delete_last), \ + pg_malloc_attr(list_delete_first_n), \ + pg_malloc_attr(list_delete_nth_cell), \ + pg_malloc_attr(list_delete_cell), \ + pg_malloc_attr(list_union), \ + pg_malloc_attr(list_append_unique), \ + pg_malloc_attr(list_append_unique_ptr), \ + pg_malloc_attr(list_append_unique_int), \ + pg_malloc_attr(list_append_unique_oid), \ + pg_malloc_attr(list_concat_unique), \ + pg_malloc_attr(list_concat_unique_ptr), \ + pg_malloc_attr(list_concat_unique_int), \ + pg_malloc_attr(list_concat_unique_oid), \ + pg_malloc_attr(list_free), \ + pg_malloc_attr(list_free_deep), \ + warn_unused_result)) + +extern PG_LIST_ALLOC_ATTR List *list_make1_impl(NodeTag t, ListCell datum1); +extern PG_LIST_ALLOC_ATTR List *list_make2_impl(NodeTag t, ListCell datum1, ListCell datum2); +extern PG_LIST_ALLOC_ATTR List *list_make3_impl(NodeTag t, ListCell datum1, ListCell datum2, + ListCell datum3); +extern PG_LIST_ALLOC_ATTR List *list_make4_impl(NodeTag t, ListCell datum1, ListCell datum2, + ListCell datum3, ListCell datum4); +extern PG_LIST_ALLOC_ATTR List *list_make5_impl(NodeTag t, ListCell datum1, ListCell datum2, + ListCell datum3, ListCell datum4, + ListCell datum5); + +extern PG_LIST_ALLOC_ATTR List *lappend(List *list, void *datum); +extern PG_LIST_ALLOC_ATTR List *lappend_int(List *list, int datum); +extern PG_LIST_ALLOC_ATTR List *lappend_oid(List *list, Oid datum); +extern PG_LIST_ALLOC_ATTR List *lappend_xid(List *list, TransactionId datum); + +extern PG_LIST_ALLOC_ATTR List *list_insert_nth(List *list, int pos, void *datum); +extern PG_LIST_ALLOC_ATTR List *list_insert_nth_int(List *list, int pos, int datum); +extern PG_LIST_ALLOC_ATTR List *list_insert_nth_oid(List *list, int pos, Oid datum); + +extern PG_LIST_ALLOC_ATTR List *lcons(void *datum, List *list); +extern PG_LIST_ALLOC_ATTR List *lcons_int(int datum, List *list); +extern PG_LIST_ALLOC_ATTR List *lcons_oid(Oid datum, List *list); + +extern PG_LIST_ALLOC_ATTR List *list_concat(List *list1, const List *list2); +extern PG_LIST_ALLOC_ATTR List *list_concat_copy(const List *list1, const List *list2); + +extern PG_LIST_ALLOC_ATTR List *list_truncate(List *list, int new_size); + +extern PG_LIST_ALLOC_ATTR List *list_delete(List *list, void *datum); +extern PG_LIST_ALLOC_ATTR List *list_delete_ptr(List *list, void *datum); +extern PG_LIST_ALLOC_ATTR List *list_delete_int(List *list, int datum); +extern PG_LIST_ALLOC_ATTR List *list_delete_oid(List *list, Oid datum); +extern PG_LIST_ALLOC_ATTR List *list_delete_first(List *list); +extern PG_LIST_ALLOC_ATTR List *list_delete_last(List *list); +extern PG_LIST_ALLOC_ATTR List *list_delete_first_n(List *list, int n); +extern PG_LIST_ALLOC_ATTR List *list_delete_nth_cell(List *list, int n); +extern PG_LIST_ALLOC_ATTR List *list_delete_cell(List *list, ListCell *cell); + +extern PG_LIST_ALLOC_ATTR List *list_union(const List *list1, const List *list2); +extern PG_LIST_ALLOC_ATTR List *list_union_ptr(const List *list1, const List *list2); +extern PG_LIST_ALLOC_ATTR List *list_union_int(const List *list1, const List *list2); +extern PG_LIST_ALLOC_ATTR List *list_union_oid(const List *list1, const List *list2); + +extern PG_LIST_ALLOC_ATTR List *list_intersection(const List *list1, const List *list2); +extern PG_LIST_ALLOC_ATTR List *list_intersection_int(const List *list1, const List *list2); + +extern PG_LIST_ALLOC_ATTR List *list_append_unique(List *list, void *datum); +extern PG_LIST_ALLOC_ATTR List *list_append_unique_ptr(List *list, void *datum); +extern PG_LIST_ALLOC_ATTR List *list_append_unique_int(List *list, int datum); +extern PG_LIST_ALLOC_ATTR List *list_append_unique_oid(List *list, Oid datum); + +extern PG_LIST_ALLOC_ATTR List *list_concat_unique(List *list1, const List *list2); +extern PG_LIST_ALLOC_ATTR List *list_concat_unique_ptr(List *list1, const List *list2); +extern PG_LIST_ALLOC_ATTR List *list_concat_unique_int(List *list1, const List *list2); +extern PG_LIST_ALLOC_ATTR List *list_concat_unique_oid(List *list1, const List *list2); + +extern PG_LIST_ALLOC_ATTR List *list_copy(const List *oldlist); +extern PG_LIST_ALLOC_ATTR List *list_copy_head(const List *oldlist, int len); +extern PG_LIST_ALLOC_ATTR List *list_copy_tail(const List *oldlist, int nskip); +extern PG_LIST_ALLOC_ATTR List *list_copy_deep(const List *oldlist); + #endif /* PG_LIST_H */ diff --git a/src/include/utils/palloc.h b/src/include/utils/palloc.h index d1146c12351..a9e8063023f 100644 --- a/src/include/utils/palloc.h +++ b/src/include/utils/palloc.h @@ -65,25 +65,40 @@ extern PGDLLIMPORT MemoryContext CurrentMemoryContext; #define MCXT_ALLOC_NO_OOM 0x02 /* no failure if out-of-memory */ #define MCXT_ALLOC_ZERO 0x04 /* zero allocated memory */ +#define pg_alloc_attributes(size_at) \ + __attribute__((malloc, pg_malloc_attr_i(pfree, 1), alloc_size(size_at), assume_aligned(MAXIMUM_ALIGNOF), returns_nonnull, warn_unused_result)) +#define pg_alloc_noerr_attributes(size_at) \ + __attribute__((malloc, pg_malloc_attr_i(pfree, 1), alloc_size(size_at), assume_aligned(MAXIMUM_ALIGNOF), warn_unused_result)) +#define pg_realloc_attributes(old_at, size_at) \ + __attribute__((alloc_size(size_at), assume_aligned(MAXIMUM_ALIGNOF), \ + nonnull(old_at), returns_nonnull, warn_unused_result)) +#define pg_realloc_noerr_attributes(old_at, size_at) \ + __attribute__((alloc_size(size_at), assume_aligned(MAXIMUM_ALIGNOF), \ + nonnull(old_at), warn_unused_result)) +#define pg_dup_attributes(source_at) \ + __attribute__((malloc, pg_malloc_attr_i(pfree, 1), assume_aligned(MAXIMUM_ALIGNOF), returns_nonnull, nonnull(source_at), warn_unused_result)) + +extern void pfree(void *pointer); + /* * Fundamental memory-allocation operations (more are in utils/memutils.h) */ -extern void *MemoryContextAlloc(MemoryContext context, Size size); -extern void *MemoryContextAllocZero(MemoryContext context, Size size); -extern void *MemoryContextAllocZeroAligned(MemoryContext context, Size size); +extern void *MemoryContextAlloc(MemoryContext context, Size size) pg_alloc_attributes(2); +extern void *MemoryContextAllocZero(MemoryContext context, Size size) pg_alloc_attributes(2); +extern void *MemoryContextAllocZeroAligned(MemoryContext context, Size size) pg_alloc_attributes(2); extern void *MemoryContextAllocExtended(MemoryContext context, - Size size, int flags); + Size size, int flags) pg_alloc_noerr_attributes(2); extern void *MemoryContextAllocAligned(MemoryContext context, - Size size, Size alignto, int flags); + Size size, Size alignto, int flags) pg_alloc_noerr_attributes(2); -extern void *palloc(Size size); -extern void *palloc0(Size size); -extern void *palloc_extended(Size size, int flags); -extern void *palloc_aligned(Size size, Size alignto, int flags); -extern pg_nodiscard void *repalloc(void *pointer, Size size); +extern void *palloc(Size size) pg_alloc_attributes(1); +extern void *palloc0(Size size) pg_alloc_attributes(1); +extern void *palloc_extended(Size size, int flags) pg_alloc_noerr_attributes(1); +extern void *palloc_aligned(Size size, Size alignto, int flags) pg_alloc_noerr_attributes(1); +extern pg_nodiscard void *repalloc(void *pointer, Size size) pg_realloc_attributes(1, 2); extern pg_nodiscard void *repalloc_extended(void *pointer, - Size size, int flags); -extern pg_nodiscard void *repalloc0(void *pointer, Size oldsize, Size size); + Size size, int flags) pg_realloc_noerr_attributes(1, 2); +extern pg_nodiscard void *repalloc0(void *pointer, Size oldsize, Size size) pg_realloc_attributes(1, 2); extern void pfree(void *pointer); /* @@ -123,8 +138,8 @@ extern void pfree(void *pointer); MemoryContextAllocZero(CurrentMemoryContext, sz) ) /* Higher-limit allocators. */ -extern void *MemoryContextAllocHuge(MemoryContext context, Size size); -extern pg_nodiscard void *repalloc_huge(void *pointer, Size size); +extern void *MemoryContextAllocHuge(MemoryContext context, Size size) pg_alloc_attributes(2); +extern pg_nodiscard void *repalloc_huge(void *pointer, Size size) pg_realloc_attributes(1, 2); /* * Although this header file is nominally backend-only, certain frontend @@ -152,14 +167,14 @@ extern void MemoryContextRegisterResetCallback(MemoryContext context, * These are like standard strdup() except the copied string is * allocated in a context, not with malloc(). */ -extern char *MemoryContextStrdup(MemoryContext context, const char *string); -extern char *pstrdup(const char *in); -extern char *pnstrdup(const char *in, Size len); +extern char *MemoryContextStrdup(MemoryContext context, const char *string) pg_dup_attributes(2); +extern char *pstrdup(const char *in) pg_dup_attributes(1); +extern char *pnstrdup(const char *in, Size len) pg_dup_attributes(1); -extern char *pchomp(const char *in); +extern char *pchomp(const char *in) pg_dup_attributes(1); /* sprintf into a palloc'd buffer --- these are in psprintf.c */ -extern char *psprintf(const char *fmt,...) pg_attribute_printf(1, 2); -extern size_t pvsnprintf(char *buf, size_t len, const char *fmt, va_list args) pg_attribute_printf(3, 0); +extern char *psprintf(const char *fmt,...) pg_attribute_printf(1, 2) __attribute__((malloc, returns_nonnull, warn_unused_result)); +extern size_t pvsnprintf(char *buf, size_t len, const char *fmt, va_list args) pg_attribute_printf(3, 0) __attribute__((warn_unused_result)); #endif /* PALLOC_H */ -- 2.38.0 --dqvxegae2emmr5ba-- ^ permalink raw reply [nested|flat] 4+ messages in thread
* [PATCH] Introduce an option to make logical replication database specific. @ 2026-04-03 10:34 Antonin Houska <[email protected]> 0 siblings, 0 replies; 4+ messages in thread From: Antonin Houska @ 2026-04-03 10:34 UTC (permalink / raw) By default, the logical decoding assumes access to shared catalogs, so the snapshot builder needs to consider cluster-wide XIDs during startup. That in turn means that, if any transaction is already running (and has XID assigned), the snapshot builder needs to wait for its completion, as it does not know if that transaction performed catalog changes earlier. Possible problem with this concept is that if REPACK (CONCURRENTLY) is running in some database, backends running the same command in other databases get stuck until the first one has committed. Thus only as single backend in the cluster can run REPACK (CONCURRENTLY) at any time. Likewise, REPACK (CONCURRENTLY) can block walsenders starting on behalf of subscriptions throughout the cluster. This patch introduces the possibility for a backend to declare that its output plugin does not use shared catalogs (i.e. catalogs that can be changed by transactions running in other databases in the cluster). In that case, no snapshot the backend will use during the decoding needs to contain information about transactions running in other databases. Thus the snapshot builder only needs to wait for completion of transactions in the current database. Currently we only use this option in the REPACK background worker. It could possibly be used in walsender involved in logical replication too, however that would need thorough analysis of its output plugin. The patch bumps WAL version number, due to a new field in xl_running_xacts. --- contrib/pg_visibility/pg_visibility.c | 4 ++-- src/backend/access/index/genam.c | 18 ++++++++++++++++ src/backend/access/rmgrdesc/standbydesc.c | 2 ++ src/backend/access/transam/xlog.c | 2 +- src/backend/access/transam/xlogfuncs.c | 2 +- src/backend/commands/repack_worker.c | 8 +++++++ src/backend/postmaster/bgwriter.c | 2 +- src/backend/replication/logical/snapbuild.c | 10 ++++++++- src/backend/replication/slot.c | 12 +++++++++-- src/backend/storage/ipc/procarray.c | 23 ++++++++++++++++++++- src/backend/storage/ipc/standby.c | 14 +++++++++++-- src/include/access/genam.h | 8 +++++++ src/include/access/xlog_internal.h | 2 +- src/include/storage/procarray.h | 2 +- src/include/storage/standby.h | 3 ++- src/include/storage/standbydefs.h | 1 + 16 files changed, 99 insertions(+), 14 deletions(-) diff --git a/contrib/pg_visibility/pg_visibility.c b/contrib/pg_visibility/pg_visibility.c index dfab0b64cf5..d564bd2a00c 100644 --- a/contrib/pg_visibility/pg_visibility.c +++ b/contrib/pg_visibility/pg_visibility.c @@ -621,7 +621,7 @@ GetStrictOldestNonRemovableTransactionId(Relation rel) else if (rel == NULL || rel->rd_rel->relisshared) { /* Shared relation: take into account all running xids */ - runningTransactions = GetRunningTransactionData(); + runningTransactions = GetRunningTransactionData(InvalidOid); LWLockRelease(ProcArrayLock); LWLockRelease(XidGenLock); return runningTransactions->oldestRunningXid; @@ -632,7 +632,7 @@ GetStrictOldestNonRemovableTransactionId(Relation rel) * Normal relation: take into account xids running within the current * database */ - runningTransactions = GetRunningTransactionData(); + runningTransactions = GetRunningTransactionData(InvalidOid); LWLockRelease(ProcArrayLock); LWLockRelease(XidGenLock); return runningTransactions->oldestDatabaseRunningXid; diff --git a/src/backend/access/index/genam.c b/src/backend/access/index/genam.c index 1408989c568..97ea882cf71 100644 --- a/src/backend/access/index/genam.c +++ b/src/backend/access/index/genam.c @@ -37,6 +37,14 @@ #include "utils/ruleutils.h" #include "utils/snapmgr.h" +/* + * If a backend is going to do logical decoding and if the output plugin does + * not need to access shared catalogs, setting this variable to false can make + * the decoding startup faster. In particular, the backend will not need to + * wait for completion of already running transactions in other databases. + */ +bool accessSharedCatalogsInDecoding = true; + /* ---------------------------------------------------------------- * general access method routines @@ -394,6 +402,16 @@ systable_beginscan(Relation heapRelation, SysScanDesc sysscan; Relation irel; + /* + * If this backend promised that it won't access shared catalogs during + * logical decoding, this seems to be the right place to check. + * + * XXX Should this be ereport(ERROR) ? + */ + Assert(!HistoricSnapshotActive() || + accessSharedCatalogsInDecoding || + !heapRelation->rd_rel->relisshared); + if (indexOK && !IgnoreSystemIndexes && !ReindexIsProcessingIndex(indexId)) diff --git a/src/backend/access/rmgrdesc/standbydesc.c b/src/backend/access/rmgrdesc/standbydesc.c index 0a291354ae2..685d1bdb024 100644 --- a/src/backend/access/rmgrdesc/standbydesc.c +++ b/src/backend/access/rmgrdesc/standbydesc.c @@ -41,6 +41,8 @@ standby_desc_running_xacts(StringInfo buf, xl_running_xacts *xlrec) for (i = 0; i < xlrec->subxcnt; i++) appendStringInfo(buf, " %u", xlrec->xids[xlrec->xcnt + i]); } + + appendStringInfo(buf, "; dbid: %u", xlrec->dbid); } void diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 2c1c6f88b74..8da8eff93e4 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7336,7 +7336,7 @@ CreateCheckPoint(int flags) * recovery we don't need to write running xact data. */ if (!shutdown && XLogStandbyInfoActive()) - LogStandbySnapshot(); + LogStandbySnapshot(InvalidOid); START_CRIT_SECTION(); diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c index 65bbaeda59c..0f5979691e6 100644 --- a/src/backend/access/transam/xlogfuncs.c +++ b/src/backend/access/transam/xlogfuncs.c @@ -245,7 +245,7 @@ pg_log_standby_snapshot(PG_FUNCTION_ARGS) (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("pg_log_standby_snapshot() can only be used if \"wal_level\" >= \"replica\""))); - recptr = LogStandbySnapshot(); + recptr = LogStandbySnapshot(InvalidOid); /* * As a convenience, return the WAL location of the last inserted record diff --git a/src/backend/commands/repack_worker.c b/src/backend/commands/repack_worker.c index 00b21ede481..c25dbeadff3 100644 --- a/src/backend/commands/repack_worker.c +++ b/src/backend/commands/repack_worker.c @@ -16,6 +16,7 @@ */ #include "postgres.h" +#include "access/genam.h" #include "access/table.h" #include "access/xlog_internal.h" #include "access/xlogutils.h" @@ -233,6 +234,13 @@ repack_setup_logical_decoding(Oid relid) EnsureLogicalDecodingEnabled(); + /* + * By declaring that our output plugin does not need shared catalogs, we + * avoid waiting for completion of transactions running in other databases + * than the one we're connected to. + */ + accessSharedCatalogsInDecoding = false; + /* * Neither prepare_write nor do_write callback nor update_progress is * useful for us. diff --git a/src/backend/postmaster/bgwriter.c b/src/backend/postmaster/bgwriter.c index 1d8947774a9..a30de4262eb 100644 --- a/src/backend/postmaster/bgwriter.c +++ b/src/backend/postmaster/bgwriter.c @@ -289,7 +289,7 @@ BackgroundWriterMain(const void *startup_data, size_t startup_data_len) if (now >= timeout && last_snapshot_lsn <= GetLastImportantRecPtr()) { - last_snapshot_lsn = LogStandbySnapshot(); + last_snapshot_lsn = LogStandbySnapshot(InvalidOid); last_snapshot_ts = now; } } diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c index 0f6b5df322c..16009fa75a4 100644 --- a/src/backend/replication/logical/snapbuild.c +++ b/src/backend/replication/logical/snapbuild.c @@ -125,6 +125,7 @@ #include <sys/stat.h> #include <unistd.h> +#include "access/genam.h" #include "access/heapam_xlog.h" #include "access/transam.h" #include "access/xact.h" @@ -1470,7 +1471,14 @@ SnapBuildWaitSnapshot(xl_running_xacts *running, TransactionId cutoff) */ if (!RecoveryInProgress()) { - LogStandbySnapshot(); + Oid dbid; + + /* + * Only consider transactions of the current database if our plugin is + * not supposed to access shared catalogs. + */ + dbid = accessSharedCatalogsInDecoding ? InvalidOid : MyDatabaseId; + LogStandbySnapshot(dbid); } } diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index fe6bfeba25e..0d415f5f8f2 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -39,6 +39,7 @@ #include <unistd.h> #include <sys/stat.h> +#include "access/genam.h" #include "access/transam.h" #include "access/xlog_internal.h" #include "access/xlogrecovery.h" @@ -1776,9 +1777,16 @@ ReplicationSlotReserveWal(void) if (!RecoveryInProgress() && SlotIsLogical(slot)) { XLogRecPtr flushptr; + Oid dbid; - /* make sure we have enough information to start */ - flushptr = LogStandbySnapshot(); + /* + * Make sure we have enough information to start. + * + * Only consider transactions of the current database if our plugin + * is not supposed to access shared catalogs. + */ + dbid = accessSharedCatalogsInDecoding ? InvalidOid : MyDatabaseId; + flushptr = LogStandbySnapshot(dbid); /* and make sure it's fsynced to disk */ XLogFlush(flushptr); diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index cc207cb56e3..49d1bf4bfac 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -2631,9 +2631,11 @@ ProcArrayInstallRestoredXmin(TransactionId xmin, PGPROC *proc) * * Note that if any transaction has overflowed its cached subtransactions * then there is no real need include any subtransactions. + * + * If 'dbid' is valid, only gather transactions running in that database. */ RunningTransactions -GetRunningTransactionData(void) +GetRunningTransactionData(Oid dbid) { /* result workspace */ static RunningTransactionsData CurrentRunningXactsData; @@ -2708,6 +2710,18 @@ GetRunningTransactionData(void) if (!TransactionIdIsValid(xid)) continue; + /* + * Filter by database OID if requested. + */ + if (OidIsValid(dbid)) + { + int pgprocno = arrayP->pgprocnos[index]; + PGPROC *proc = &allProcs[pgprocno]; + + if (proc->databaseId != dbid) + continue; + } + /* * Be careful not to exclude any xids before calculating the values of * oldestRunningXid and suboverflowed, since these are used to clean @@ -2758,6 +2772,12 @@ GetRunningTransactionData(void) PGPROC *proc = &allProcs[pgprocno]; int nsubxids; + /* + * Filter by database OID if requested. + */ + if (OidIsValid(dbid) && proc->databaseId != dbid) + continue; + /* * Save subtransaction XIDs. Other backends can't add or remove * entries while we're holding XidGenLock. @@ -2791,6 +2811,7 @@ GetRunningTransactionData(void) * increases if slots do. */ + CurrentRunningXacts->dbid = dbid; CurrentRunningXacts->xcnt = count - subcount; CurrentRunningXacts->subxcnt = subcount; CurrentRunningXacts->subxid_status = suboverflowed ? SUBXIDS_IN_SUBTRANS : SUBXIDS_IN_ARRAY; diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c index de9092fdf5b..c653ea742bc 100644 --- a/src/backend/storage/ipc/standby.c +++ b/src/backend/storage/ipc/standby.c @@ -1188,6 +1188,14 @@ standby_redo(XLogReaderState *record) xl_running_xacts *xlrec = (xl_running_xacts *) XLogRecGetData(record); RunningTransactionsData running; + /* + * Records issued for specific database are not suitable for physical + * replication because that affects the whole cluster. In particular, + * the list of XID is probably incomplete here. + */ + if (OidIsValid(xlrec->dbid)) + return; + running.xcnt = xlrec->xcnt; running.subxcnt = xlrec->subxcnt; running.subxid_status = xlrec->subxid_overflow ? SUBXIDS_MISSING : SUBXIDS_IN_ARRAY; @@ -1277,11 +1285,12 @@ standby_redo(XLogReaderState *record) * as there's no independent knob to just enable logical decoding. For * details of how this is used, check snapbuild.c's introductory comment. * + * If 'dbid' is valid, only gather transactions running in that database. * * Returns the RecPtr of the last inserted record. */ XLogRecPtr -LogStandbySnapshot(void) +LogStandbySnapshot(Oid dbid) { XLogRecPtr recptr; RunningTransactions running; @@ -1314,7 +1323,7 @@ LogStandbySnapshot(void) * Log details of all in-progress transactions. This should be the last * record we write, because standby will open up when it sees this. */ - running = GetRunningTransactionData(); + running = GetRunningTransactionData(dbid); /* * GetRunningTransactionData() acquired ProcArrayLock, we must release it. @@ -1358,6 +1367,7 @@ LogCurrentRunningXacts(RunningTransactions CurrRunningXacts) xl_running_xacts xlrec; XLogRecPtr recptr; + xlrec.dbid = CurrRunningXacts->dbid; xlrec.xcnt = CurrRunningXacts->xcnt; xlrec.subxcnt = CurrRunningXacts->subxcnt; xlrec.subxid_overflow = (CurrRunningXacts->subxid_status != SUBXIDS_IN_ARRAY); diff --git a/src/include/access/genam.h b/src/include/access/genam.h index b69320a7fc8..56c573399ab 100644 --- a/src/include/access/genam.h +++ b/src/include/access/genam.h @@ -136,6 +136,14 @@ typedef struct IndexOrderByDistance bool isnull; } IndexOrderByDistance; +/* + * Is the backend interested in shared catalogs when performing logical + * decoding? + * + * XXX Is there a better place for this declaration? + */ +extern bool accessSharedCatalogsInDecoding; + /* * generalized index_ interface routines (in indexam.c) */ diff --git a/src/include/access/xlog_internal.h b/src/include/access/xlog_internal.h index 755835d63bf..ae19982d88d 100644 --- a/src/include/access/xlog_internal.h +++ b/src/include/access/xlog_internal.h @@ -31,7 +31,7 @@ /* * Each page of XLOG file has a header like this: */ -#define XLOG_PAGE_MAGIC 0xD11E /* can be used as WAL version indicator */ +#define XLOG_PAGE_MAGIC 0xD11F /* can be used as WAL version indicator */ typedef struct XLogPageHeaderData { diff --git a/src/include/storage/procarray.h b/src/include/storage/procarray.h index abdf021e66e..377b3060b9f 100644 --- a/src/include/storage/procarray.h +++ b/src/include/storage/procarray.h @@ -49,7 +49,7 @@ extern bool ProcArrayInstallImportedXmin(TransactionId xmin, VirtualTransactionId *sourcevxid); extern bool ProcArrayInstallRestoredXmin(TransactionId xmin, PGPROC *proc); -extern RunningTransactions GetRunningTransactionData(void); +extern RunningTransactions GetRunningTransactionData(Oid dbid); extern bool TransactionIdIsInProgress(TransactionId xid); extern TransactionId GetOldestNonRemovableTransactionId(Relation rel); diff --git a/src/include/storage/standby.h b/src/include/storage/standby.h index 6a314c693cd..8715c08e94f 100644 --- a/src/include/storage/standby.h +++ b/src/include/storage/standby.h @@ -126,6 +126,7 @@ typedef enum typedef struct RunningTransactionsData { + Oid dbid; /* only track xacts in this database */ int xcnt; /* # of xact ids in xids[] */ int subxcnt; /* # of subxact ids in xids[] */ subxids_array_status subxid_status; @@ -143,7 +144,7 @@ typedef RunningTransactionsData *RunningTransactions; extern void LogAccessExclusiveLock(Oid dbOid, Oid relOid); extern void LogAccessExclusiveLockPrepare(void); -extern XLogRecPtr LogStandbySnapshot(void); +extern XLogRecPtr LogStandbySnapshot(Oid dbid); extern void LogStandbyInvalidations(int nmsgs, SharedInvalidationMessage *msgs, bool relcacheInitFileInval); diff --git a/src/include/storage/standbydefs.h b/src/include/storage/standbydefs.h index 231d251fd51..e75b7078766 100644 --- a/src/include/storage/standbydefs.h +++ b/src/include/storage/standbydefs.h @@ -46,6 +46,7 @@ typedef struct xl_standby_locks */ typedef struct xl_running_xacts { + Oid dbid; /* only track xacts in this database */ int xcnt; /* # of xact ids in xids[] */ int subxcnt; /* # of subxact ids in xids[] */ bool subxid_overflow; /* snapshot overflowed, subxids missing */ -- 2.47.3 --=-=-=-- ^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2026-04-03 10:34 UTC | newest] Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2019-11-16 17:29 [PATCH v2] Reverse collations David Fetter <[email protected]> 2023-06-26 19:17 [PATCH v1 1/2] Add allocator attributes. Andres Freund <[email protected]> 2023-06-26 19:17 [PATCH v1 1/2] Add allocator attributes. Andres Freund <[email protected]> 2026-04-03 10:34 [PATCH] Introduce an option to make logical replication database specific. Antonin Houska <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox