Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit db22b90

Browse files
committed
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
1 parent 73c9f91 commit db22b90

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

contrib/pg_trgm/expected/pg_trgm.out

+3
Original file line numberDiff line numberDiff line change
@@ -2372,6 +2372,9 @@ ERROR: value 2025 out of bounds for option "siglen"
23722372
DETAIL: Valid values are between "1" and "2024".
23732373
create index trgm_idx on test_trgm using gist (t gist_trgm_ops(siglen=2024));
23742374
set enable_seqscan=off;
2375+
-- check index compatibility handling when opclass option is specified
2376+
alter table test_trgm alter column t type varchar(768);
2377+
alter table test_trgm alter column t type text;
23752378
select t,similarity(t,'qwertyu0988') as sml from test_trgm where t % 'qwertyu0988' order by sml desc, t;
23762379
t | sml
23772380
-------------+----------

contrib/pg_trgm/sql/pg_trgm.sql

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ create index trgm_idx on test_trgm using gist (t gist_trgm_ops(siglen=2025));
5252
create index trgm_idx on test_trgm using gist (t gist_trgm_ops(siglen=2024));
5353
set enable_seqscan=off;
5454

55+
-- check index compatibility handling when opclass option is specified
56+
alter table test_trgm alter column t type varchar(768);
57+
alter table test_trgm alter column t type text;
58+
5559
select t,similarity(t,'qwertyu0988') as sml from test_trgm where t % 'qwertyu0988' order by sml desc, t;
5660
select t,similarity(t,'gwertyu0988') as sml from test_trgm where t % 'gwertyu0988' order by sml desc, t;
5761
select t,similarity(t,'gwertyu1988') as sml from test_trgm where t % 'gwertyu1988' order by sml desc, t;

src/backend/commands/indexcmds.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "catalog/namespace.h"
3030
#include "catalog/pg_am.h"
3131
#include "catalog/pg_authid.h"
32+
#include "catalog/pg_collation.h"
3233
#include "catalog/pg_constraint.h"
3334
#include "catalog/pg_database.h"
3435
#include "catalog/pg_inherits.h"
@@ -362,10 +363,12 @@ static bool
362363
CompareOpclassOptions(const Datum *opts1, const Datum *opts2, int natts)
363364
{
364365
int i;
366+
FmgrInfo fm;
365367

366368
if (!opts1 && !opts2)
367369
return true;
368370

371+
fmgr_info(F_ARRAY_EQ, &fm);
369372
for (i = 0; i < natts; i++)
370373
{
371374
Datum opt1 = opts1 ? opts1[i] : (Datum) 0;
@@ -381,8 +384,12 @@ CompareOpclassOptions(const Datum *opts1, const Datum *opts2, int natts)
381384
else if (opt2 == (Datum) 0)
382385
return false;
383386

384-
/* Compare non-NULL text[] datums. */
385-
if (!DatumGetBool(DirectFunctionCall2(array_eq, opt1, opt2)))
387+
/*
388+
* Compare non-NULL text[] datums. Use C collation to enforce binary
389+
* equivalence of texts, because we don't know anything about the
390+
* semantics of opclass options.
391+
*/
392+
if (!DatumGetBool(FunctionCall2Coll(&fm, C_COLLATION_OID, opt1, opt2)))
386393
return false;
387394
}
388395

0 commit comments

Comments
 (0)