diff options
author | Alexander Korotkov <akorotkov@postgresql.org> | 2024-11-12 01:44:20 +0200 |
---|---|---|
committer | Alexander Korotkov <akorotkov@postgresql.org> | 2024-11-12 01:51:20 +0200 |
commit | a6fa869cfa4e8f0226f22f717f5b0aa5eed60588 (patch) | |
tree | ef362996ccb91f09df8a8d72038961f8c9a1d5d2 /src | |
parent | 91f20bc2f7e4fcf5de5c65a6cb1190e0afa91c0b (diff) |
Fix arrays comparison in CompareOpclassOptions()
The current code calls array_eq() and does not provide FmgrInfo. This commit
provides initialization of FmgrInfo and uses C collation as the safe option
for text comparison because we don't know anything about the semantics of
opclass options.
Backpatch to 13, where opclass options were introduced.
Reported-by: Nicolas Maus
Discussion: https://postgr.es/m/18692-72ea398df3ec6712%40postgresql.org
Backpatch-through: 13
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/commands/indexcmds.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 3d8df046dad..f7fe1fae91c 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -28,6 +28,7 @@ #include "catalog/namespace.h" #include "catalog/pg_am.h" #include "catalog/pg_authid.h" +#include "catalog/pg_collation.h" #include "catalog/pg_constraint.h" #include "catalog/pg_database.h" #include "catalog/pg_inherits.h" @@ -359,10 +360,12 @@ static bool CompareOpclassOptions(const Datum *opts1, const Datum *opts2, int natts) { int i; + FmgrInfo fm; if (!opts1 && !opts2) return true; + fmgr_info(F_ARRAY_EQ, &fm); for (i = 0; i < natts; i++) { Datum opt1 = opts1 ? opts1[i] : (Datum) 0; @@ -378,8 +381,12 @@ CompareOpclassOptions(const Datum *opts1, const Datum *opts2, int natts) else if (opt2 == (Datum) 0) return false; - /* Compare non-NULL text[] datums. */ - if (!DatumGetBool(DirectFunctionCall2(array_eq, opt1, opt2))) + /* + * Compare non-NULL text[] datums. Use C collation to enforce binary + * equivalence of texts, because we don't know anything about the + * semantics of opclass options. + */ + if (!DatumGetBool(FunctionCall2Coll(&fm, C_COLLATION_OID, opt1, opt2))) return false; } |