From 7e3e6692b835bc871dc347470ba5a434eaada594 Mon Sep 17 00:00:00 2001 From: sibowu Date: Wed, 22 Apr 2026 22:31:34 +0000 Subject: [PATCH] add postgres19 compatibility --- expected/card_op_1.out | 65 ++++++++ expected/hash_1.out | 331 +++++++++++++++++++++++++++++++++++++++++ src/hll.c | 18 ++- 3 files changed, 412 insertions(+), 2 deletions(-) create mode 100644 expected/card_op_1.out create mode 100644 expected/hash_1.out diff --git a/expected/card_op_1.out b/expected/card_op_1.out new file mode 100644 index 0000000..c4c3df6 --- /dev/null +++ b/expected/card_op_1.out @@ -0,0 +1,65 @@ +-- ---------------------------------------------------------------- +-- Regression tests for cardinality operator. +-- ---------------------------------------------------------------- +set extra_float_digits=0; +SELECT hll_set_output_version(1); + hll_set_output_version +------------------------ + 1 +(1 row) + +SELECT #E'\\x108b49'::hll; + ?column? +---------- + +(1 row) + +SELECT #hll_empty(11,5,256,1); + ?column? +---------- + 0 +(1 row) + +-- # gets evaluated first so || hll_union(double, bigint) fails +SELECT #hll_empty(11,5,256,1) || hll_hash_integer(1,0); +ERROR: operator does not exist: double precision || hll_hashval +LINE 1: SELECT #hll_empty(11,5,256,1) || hll_hash_integer(1,0); + ^ +DETAIL: No operator of that name accepts the given argument types. +HINT: You might need to add explicit type casts. +SELECT #(hll_empty(11,5,256,1) || hll_hash_integer(1,0)); + ?column? +---------- + 1 +(1 row) + +SELECT #E'\\x128b498895a3f5af28cafe'::hll; + ?column? +---------- + 1 +(1 row) + +SELECT #E'\\x128b498895a3f5af28cafeda0ce907e4355b60'::hll; + ?column? +---------- + 2 +(1 row) + +SELECT #E'\\x138b4f0061'::hll; + ?column? +------------------ + 1.00024422012692 +(1 row) + +SELECT #E'\\x148B480800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'::hll; + ?column? +------------------ + 1.00024422012692 +(1 row) + +SELECT #E'\\x148B480842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084210842108421084200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'::hll; + ?column? +------------------ + 545.638878057197 +(1 row) + diff --git a/expected/hash_1.out b/expected/hash_1.out new file mode 100644 index 0000000..533fa4e --- /dev/null +++ b/expected/hash_1.out @@ -0,0 +1,331 @@ +-- ---------------------------------------------------------------- +-- Misc Tests on Hash Function +-- ---------------------------------------------------------------- +SELECT hll_set_output_version(1); + hll_set_output_version +------------------------ + 1 +(1 row) + +-- ---------------- boolean +SELECT hll_hash_boolean(FALSE); + hll_hash_boolean +--------------------- + 5048724184180415669 +(1 row) + +SELECT hll_hash_boolean(TRUE); + hll_hash_boolean +--------------------- + 8849112093580131862 +(1 row) + +-- ---------------- smallint +SELECT hll_hash_smallint(0::smallint); + hll_hash_smallint +--------------------- + 3478107235931676136 +(1 row) + +SELECT hll_hash_smallint(100::smallint); + hll_hash_smallint +--------------------- + 4631120266694327276 +(1 row) + +SELECT hll_hash_smallint(-100::smallint); + hll_hash_smallint +--------------------- + 5357168029120347761 +(1 row) + +-- ---------------- integer +SELECT hll_hash_integer(0); + hll_hash_integer +---------------------- + -3485513579396041028 +(1 row) + +SELECT hll_hash_integer(100); + hll_hash_integer +---------------------- + -5003248654201747171 +(1 row) + +SELECT hll_hash_integer(-100); + hll_hash_integer +---------------------- + -2771615523823720964 +(1 row) + +-- ---------------- bigint +SELECT hll_hash_bigint(0); + hll_hash_bigint +--------------------- + 2945182322382062539 +(1 row) + +SELECT hll_hash_bigint(100); + hll_hash_bigint +--------------------- + 8349353095166695771 +(1 row) + +SELECT hll_hash_bigint(-100); + hll_hash_bigint +--------------------- + -886862857196634693 +(1 row) + +-- ---------------- bytea +-- Check some small values. +SELECT hll_hash_bytea(E'\\x'); + hll_hash_bytea +---------------- + 0 +(1 row) + +SELECT hll_hash_bytea(E'\\x41'); + hll_hash_bytea +-------------------- + 243126998722523514 +(1 row) + +SELECT hll_hash_bytea(E'\\x42'); + hll_hash_bytea +---------------------- + -4837624800923759386 +(1 row) + +SELECT hll_hash_bytea(E'\\x4142'); + hll_hash_bytea +--------------------- + 5365230931951287672 +(1 row) + +-- ---------------- text +-- Check some small values. +SELECT hll_hash_text(''); + hll_hash_text +--------------- + 0 +(1 row) + +SELECT hll_hash_text('A'); + hll_hash_text +-------------------- + 243126998722523514 +(1 row) + +SELECT hll_hash_text('B'); + hll_hash_text +---------------------- + -4837624800923759386 +(1 row) + +SELECT hll_hash_text('AB'); + hll_hash_text +--------------------- + 5365230931951287672 +(1 row) + +-- ---------------- seed stuff +-- Seed 0 ok. +SELECT hll_hash_bigint(0, 0); + hll_hash_bigint +--------------------- + 2945182322382062539 +(1 row) + +-- Positive seed ok. +SELECT hll_hash_bigint(0, 1); + hll_hash_bigint +--------------------- + 8297479994805284640 +(1 row) + +-- Max positive seed ok. +SELECT hll_hash_bigint(0, 2147483647); + hll_hash_bigint +---------------------- + -4042198036618575253 +(1 row) + +-- WARNING: negative seed values not compatible +SELECT hll_hash_bigint(0, -1); +WARNING: negative seed values not compatible + hll_hash_bigint +---------------------- + -8352849679461500862 +(1 row) + +-- WARNING: negative seed values not compatible +SELECT hll_hash_bigint(0, -2); +WARNING: negative seed values not compatible + hll_hash_bigint +---------------------- + -8080898605520838299 +(1 row) + +-- WARNING: negative seed values not compatible +SELECT hll_hash_bigint(0, -2147483648); +WARNING: negative seed values not compatible + hll_hash_bigint +--------------------- + 8620050269462747046 +(1 row) + +-- WARNING: negative seed values not compatible +SELECT hll_hash_boolean(0, -1); +ERROR: function hll_hash_boolean(integer, integer) does not exist +LINE 1: SELECT hll_hash_boolean(0, -1); + ^ +DETAIL: No function of that name accepts the given argument types. +HINT: You might need to add explicit type casts. +SELECT hll_hash_smallint(0::smallint, -1); +WARNING: negative seed values not compatible + hll_hash_smallint +--------------------- + 1411828310742905942 +(1 row) + +SELECT hll_hash_integer(0, -1); +WARNING: negative seed values not compatible + hll_hash_integer +--------------------- + 7867003898269499267 +(1 row) + +SELECT hll_hash_bigint(0, -1); +WARNING: negative seed values not compatible + hll_hash_bigint +---------------------- + -8352849679461500862 +(1 row) + +SELECT hll_hash_bytea(E'\\x', -1); +WARNING: negative seed values not compatible + hll_hash_bytea +--------------------- + 7706185961851046380 +(1 row) + +SELECT hll_hash_text('AB', -1); +WARNING: negative seed values not compatible + hll_hash_text +---------------------- + -6228783906452318195 +(1 row) + +-- ---------------- Matches +SELECT hll_hash_boolean(FALSE, 0), hll_hash_bytea(E'\\x00', 0); + hll_hash_boolean | hll_hash_bytea +---------------------+--------------------- + 5048724184180415669 | 5048724184180415669 +(1 row) + +SELECT hll_hash_boolean(TRUE, 0), hll_hash_bytea(E'\\x01', 0); + hll_hash_boolean | hll_hash_bytea +---------------------+--------------------- + 8849112093580131862 | 8849112093580131862 +(1 row) + +SELECT hll_hash_smallint(0::smallint, 0), hll_hash_bytea(E'\\x0000', 0); + hll_hash_smallint | hll_hash_bytea +---------------------+--------------------- + 3478107235931676136 | 3478107235931676136 +(1 row) + +SELECT hll_hash_integer(0, 0), hll_hash_bytea(E'\\x00000000', 0); + hll_hash_integer | hll_hash_bytea +----------------------+---------------------- + -3485513579396041028 | -3485513579396041028 +(1 row) + +SELECT hll_hash_bigint(0, 0), hll_hash_bytea(E'\\x0000000000000000', 0); + hll_hash_bigint | hll_hash_bytea +---------------------+--------------------- + 2945182322382062539 | 2945182322382062539 +(1 row) + +SELECT hll_hash_bytea(E'\\x4142', 0), hll_hash_text('AB', 0); + hll_hash_bytea | hll_hash_text +---------------------+--------------------- + 5365230931951287672 | 5365230931951287672 +(1 row) + +-- ---------------- Default seed = 0 +SELECT hll_hash_boolean(TRUE) = hll_hash_boolean(TRUE, 0); + ?column? +---------- + t +(1 row) + +SELECT hll_hash_smallint(100::smallint) = hll_hash_smallint(100::smallint, 0); + ?column? +---------- + t +(1 row) + +SELECT hll_hash_integer(100) = hll_hash_integer(100, 0); + ?column? +---------- + t +(1 row) + +SELECT hll_hash_bigint(100) = hll_hash_bigint(100, 0); + ?column? +---------- + t +(1 row) + +SELECT hll_hash_bytea(E'\\x42') = hll_hash_bytea(E'\\x42', 0); + ?column? +---------- + t +(1 row) + +SELECT hll_hash_text('AB') = hll_hash_text('AB', 0); + ?column? +---------- + t +(1 row) + +-- ---------------- Explicit casts work for already hashed numbers. +SELECT hll_empty() || 42::hll_hashval; + ?column? +-------------------------- + \x128b7f000000000000002a +(1 row) + +SELECT hll_empty() || CAST(42 AS hll_hashval); + ?column? +-------------------------- + \x128b7f000000000000002a +(1 row) + +SELECT hll_empty() || 42::bigint::hll_hashval; + ?column? +-------------------------- + \x128b7f000000000000002a +(1 row) + +SELECT hll_empty() || CAST(42 AS bigint)::hll_hashval; + ?column? +-------------------------- + \x128b7f000000000000002a +(1 row) + +-- ERROR: doesn't cast implicitly +SELECT hll_empty() || 42; +ERROR: operator does not exist: hll || integer +LINE 1: SELECT hll_empty() || 42; + ^ +DETAIL: No operator of that name accepts the given argument types. +HINT: You might need to add explicit type casts. +SELECT hll_empty() || 42::bigint; +ERROR: operator does not exist: hll || bigint +LINE 1: SELECT hll_empty() || 42::bigint; + ^ +DETAIL: No operator of that name accepts the given argument types. +HINT: You might need to add explicit type casts. diff --git a/src/hll.c b/src/hll.c index 551fc8a..96c2e61 100644 --- a/src/hll.c +++ b/src/hll.c @@ -234,7 +234,7 @@ hll_aggregation_restriction_hook(PlannerInfo *root, UpperRelationKind stage, * InitializeHllAggregateOids initializes the array of hll aggregate oids. */ static void -InitializeHllAggregateOids() +InitializeHllAggregateOids(void) { Oid extensionId = get_extension_oid(EXTENSION_NAME, false); Oid hllSchemaOid = get_extension_schema(extensionId); @@ -336,7 +336,15 @@ FunctionOid(const char *schemaName, const char *functionName, int argumentCount, List *argumentList = NIL; const bool findVariadics = false; const bool findDefaults = false; -#if PG_VERSION_NUM >= 140000 +#if PG_VERSION_NUM >= 190000 + const bool includeOutArguments = false; + int fgc_flags; + + functionList = FuncnameGetCandidates(qualifiedFunctionNameList, argumentCount, + argumentList, findVariadics, + findDefaults, includeOutArguments, + true, &fgc_flags); +#elif PG_VERSION_NUM >= 140000 const bool includeOutArguments = false; functionList = FuncnameGetCandidates(qualifiedFunctionNameList, argumentCount, @@ -3156,11 +3164,17 @@ setup_multiset(MemoryContext rcontext) MemoryContext oldcontext; multiset_t * msp; +#if PG_VERSION_NUM >= 190000 + tmpcontext = AllocSetContextCreateInternal(rcontext, + "multiset", + ALLOCSET_DEFAULT_SIZES); +#else tmpcontext = AllocSetContextCreate(rcontext, "multiset", ALLOCSET_DEFAULT_MINSIZE, ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE); +#endif oldcontext = MemoryContextSwitchTo(tmpcontext);