aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/indexcmds.c
diff options
context:
space:
mode:
authorAlexander Korotkov <akorotkov@postgresql.org>2024-11-12 01:44:20 +0200
committerAlexander Korotkov <akorotkov@postgresql.org>2024-11-12 01:54:30 +0200
commit713b8546aba66be102bdd8b320c06ea3b2813fd9 (patch)
tree87e6b1ea03630a97820b82e76855ab1c6d847a43 /src/backend/commands/indexcmds.c
parent0c53d54c812cea0d840490fd107910ed949e18c2 (diff)
downloadpostgresql-713b8546aba66be102bdd8b320c06ea3b2813fd9.tar.gz
postgresql-713b8546aba66be102bdd8b320c06ea3b2813fd9.zip
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/backend/commands/indexcmds.c')
-rw-r--r--src/backend/commands/indexcmds.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 157455c52b4..77aa99496fa 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -26,6 +26,7 @@
#include "catalog/index.h"
#include "catalog/indexing.h"
#include "catalog/pg_am.h"
+#include "catalog/pg_collation.h"
#include "catalog/pg_constraint.h"
#include "catalog/pg_inherits.h"
#include "catalog/pg_opclass.h"
@@ -349,10 +350,12 @@ static bool
CompareOpclassOptions(Datum *opts1, 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;
@@ -368,8 +371,12 @@ CompareOpclassOptions(Datum *opts1, 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;
}