Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita6fa869

Browse files
committed
Fix arrays comparison in CompareOpclassOptions()
The current code calls array_eq() and does not provide FmgrInfo. This commitprovides initialization of FmgrInfo and uses C collation as the safe optionfor text comparison because we don't know anything about the semantics ofopclass options.Backpatch to 13, where opclass options were introduced.Reported-by: Nicolas MausDiscussion:https://postgr.es/m/18692-72ea398df3ec6712%40postgresql.orgBackpatch-through: 13
1 parent91f20bc commita6fa869

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

‎contrib/pg_trgm/expected/pg_trgm.out

Lines changed: 3 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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
createindextrgm_idxon 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+
altertable test_trgm alter column t typevarchar(768);
57+
altertable test_trgm alter column t typetext;
58+
5559
select t,similarity(t,'qwertyu0988')as smlfrom test_trgmwhere t %'qwertyu0988'order by smldesc, t;
5660
select t,similarity(t,'gwertyu0988')as smlfrom test_trgmwhere t %'gwertyu0988'order by smldesc, t;
5761
select t,similarity(t,'gwertyu1988')as smlfrom test_trgmwhere t %'gwertyu1988'order by smldesc, t;

‎src/backend/commands/indexcmds.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include"catalog/namespace.h"
2929
#include"catalog/pg_am.h"
3030
#include"catalog/pg_authid.h"
31+
#include"catalog/pg_collation.h"
3132
#include"catalog/pg_constraint.h"
3233
#include"catalog/pg_database.h"
3334
#include"catalog/pg_inherits.h"
@@ -359,10 +360,12 @@ static bool
359360
CompareOpclassOptions(constDatum*opts1,constDatum*opts2,intnatts)
360361
{
361362
inti;
363+
FmgrInfofm;
362364

363365
if (!opts1&& !opts2)
364366
return true;
365367

368+
fmgr_info(F_ARRAY_EQ,&fm);
366369
for (i=0;i<natts;i++)
367370
{
368371
Datumopt1=opts1 ?opts1[i] : (Datum)0;
@@ -378,8 +381,12 @@ CompareOpclassOptions(const Datum *opts1, const Datum *opts2, int natts)
378381
elseif (opt2== (Datum)0)
379382
return false;
380383

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp