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

Commit4eb49db

Browse files
committed
Fix contrib/pg_trgm to have smoother updates from 9.0.
Take care of some loose ends in the update-from-unpackaged script, andapply some ugly hacks to ensure that it produces the same catalog stateas the fresh-install script. Per discussion, this seems like a saferplan than having two different catalog states that both call themselves"pg_trgm 1.0", even if it's not immediately clear that the subtledifferences would ever matter.Also, fix the stub function gin_extract_trgm() so that it works insteadof just bleating. Needed because this function will get called during aregular dump and reload, if there are any indexes using its opclass.The user won't have an opportunity to update the extension till later,so telling him to do so is unhelpful.
1 parent3472a2b commit4eb49db

File tree

3 files changed

+83
-15
lines changed

3 files changed

+83
-15
lines changed

‎contrib/pg_trgm/pg_trgm--1.0.sql

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,26 @@ CREATE OPERATOR CLASS gist_trgm_ops
109109
FOR TYPEtext USING gist
110110
AS
111111
OPERATOR1 % (text,text),
112-
OPERATOR2<-> (text,text) FORORDER BYpg_catalog.float_ops,
113-
OPERATOR3 pg_catalog.~~ (text,text),
114-
OPERATOR4 pg_catalog.~~* (text,text),
115112
FUNCTION1 gtrgm_consistent (internal,text,int,oid, internal),
116113
FUNCTION2 gtrgm_union (bytea, internal),
117114
FUNCTION3 gtrgm_compress (internal),
118115
FUNCTION4 gtrgm_decompress (internal),
119116
FUNCTION5 gtrgm_penalty (internal, internal, internal),
120117
FUNCTION6 gtrgm_picksplit (internal, internal),
121118
FUNCTION7 gtrgm_same (gtrgm, gtrgm, internal),
122-
FUNCTION8 gtrgm_distance (internal,text,int,oid),
123119
STORAGE gtrgm;
124120

121+
-- Add operators and support functions that are new in 9.1. We do it like
122+
-- this, leaving them "loose" in the operator family rather than bound into
123+
-- the gist_trgm_ops opclass, because that's the only state that can be
124+
-- reproduced during an upgrade from 9.0 (see pg_trgm--unpackaged--1.0.sql).
125+
126+
ALTEROPERATOR FAMILY gist_trgm_ops USING gist ADD
127+
OPERATOR2<-> (text,text) FORORDER BYpg_catalog.float_ops,
128+
OPERATOR3 pg_catalog.~~ (text,text),
129+
OPERATOR4 pg_catalog.~~* (text,text),
130+
FUNCTION8 (text,text) gtrgm_distance (internal,text,int,oid);
131+
125132
-- support functions for gin
126133
CREATEFUNCTIONgin_extract_value_trgm(text, internal)
127134
RETURNS internal
@@ -143,10 +150,14 @@ CREATE OPERATOR CLASS gin_trgm_ops
143150
FOR TYPEtext USING gin
144151
AS
145152
OPERATOR1 % (text,text),
146-
OPERATOR3 pg_catalog.~~ (text,text),
147-
OPERATOR4 pg_catalog.~~* (text,text),
148153
FUNCTION1 btint4cmp (int4, int4),
149154
FUNCTION2 gin_extract_value_trgm (text, internal),
150155
FUNCTION3 gin_extract_query_trgm (text, internal, int2, internal, internal, internal, internal),
151156
FUNCTION4 gin_trgm_consistent (internal, int2,text, int4, internal, internal, internal, internal),
152157
STORAGE int4;
158+
159+
-- Add operators that are new in 9.1.
160+
161+
ALTEROPERATOR FAMILY gin_trgm_ops USING gin ADD
162+
OPERATOR3 pg_catalog.~~ (text,text),
163+
OPERATOR4 pg_catalog.~~* (text,text);

‎contrib/pg_trgm/pg_trgm--unpackaged--1.0.sql

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ ALTER EXTENSION pg_trgm ADD type gtrgm;
1010
ALTER EXTENSION pg_trgm ADD function gtrgm_in(cstring);
1111
ALTER EXTENSION pg_trgm ADD function gtrgm_out(gtrgm);
1212
ALTER EXTENSION pg_trgm ADD function gtrgm_consistent(internal,text,integer,oid,internal);
13-
ALTER EXTENSION pg_trgm ADD function gtrgm_distance(internal,text,integer,oid);
1413
ALTER EXTENSION pg_trgm ADD function gtrgm_compress(internal);
1514
ALTER EXTENSION pg_trgm ADD function gtrgm_decompress(internal);
1615
ALTER EXTENSION pg_trgm ADD function gtrgm_penalty(internal,internal,internal);
@@ -19,13 +18,52 @@ ALTER EXTENSION pg_trgm ADD function gtrgm_union(bytea,internal);
1918
ALTER EXTENSION pg_trgm ADD function gtrgm_same(gtrgm,gtrgm,internal);
2019
ALTER EXTENSION pg_trgm ADD operator family gist_trgm_ops using gist;
2120
ALTER EXTENSION pg_trgm ADD operator class gist_trgm_ops using gist;
22-
ALTER EXTENSION pg_trgm ADD function gin_extract_value_trgm(text,internal);
23-
ALTER EXTENSION pg_trgm ADD function gin_extract_query_trgm(text,internal,smallint,internal,internal,internal,internal);
24-
ALTER EXTENSION pg_trgm ADD function gin_trgm_consistent(internal,smallint,text,integer,internal,internal,internal,internal);
2521
ALTER EXTENSION pg_trgm ADD operator family gin_trgm_ops using gin;
2622
ALTER EXTENSION pg_trgm ADD operator class gin_trgm_ops using gin;
2723

28-
-- these were not in 9.0:
24+
-- These functions had different names/signatures in 9.0. We can't just
25+
-- drop and recreate them because they are linked into the GIN opclass,
26+
-- so we need some ugly hacks.
27+
28+
-- First, absorb them into the extension under their old names.
29+
30+
ALTER EXTENSION pg_trgm ADD function gin_extract_trgm(text, internal);
31+
ALTER EXTENSION pg_trgm ADD function gin_extract_trgm(text, internal, int2, internal, internal);
32+
ALTER EXTENSION pg_trgm ADD function gin_trgm_consistent(internal,smallint,text,integer,internal,internal);
33+
34+
-- Fix the names, and then do CREATE OR REPLACE to adjust the function
35+
-- bodies to be correct (ie, reference the correct C symbol).
36+
37+
ALTERFUNCTION gin_extract_trgm(text, internal)
38+
RENAME TO gin_extract_value_trgm;
39+
CREATE OR REPLACEFUNCTIONgin_extract_value_trgm(text, internal)
40+
RETURNS internal
41+
AS'MODULE_PATHNAME'
42+
LANGUAGE C IMMUTABLE STRICT;
43+
44+
ALTERFUNCTION gin_extract_trgm(text, internal, int2, internal, internal)
45+
RENAME TO gin_extract_query_trgm;
46+
CREATE OR REPLACEFUNCTIONgin_extract_query_trgm(text, internal, int2, internal, internal)
47+
RETURNS internal
48+
AS'MODULE_PATHNAME'
49+
LANGUAGE C IMMUTABLE STRICT;
50+
51+
-- gin_trgm_consistent didn't change name.
52+
53+
-- Last, fix the parameter lists by means of direct UPDATE on the pg_proc
54+
-- entries. This is ugly as can be, but there's no other way to do it
55+
-- while preserving the identities (OIDs) of the functions.
56+
57+
UPDATEpg_catalog.pg_proc
58+
SET pronargs=7, proargtypes='25 2281 21 2281 2281 2281 2281'
59+
WHEREoid='gin_extract_query_trgm(text,internal,int2,internal,internal)'::pg_catalog.regprocedure;
60+
61+
UPDATEpg_catalog.pg_proc
62+
SET pronargs=8, proargtypes='2281 21 25 23 2281 2281 2281 2281'
63+
WHEREoid='gin_trgm_consistent(internal,smallint,text,integer,internal,internal)'::pg_catalog.regprocedure;
64+
65+
66+
-- These were not in 9.0:
2967

3068
CREATEFUNCTIONsimilarity_dist(text,text)
3169
RETURNS float4
@@ -38,3 +76,20 @@ CREATE OPERATOR <-> (
3876
PROCEDURE= similarity_dist,
3977
COMMUTATOR='<->'
4078
);
79+
80+
CREATEFUNCTIONgtrgm_distance(internal,text,int,oid)
81+
RETURNS float8
82+
AS'MODULE_PATHNAME'
83+
LANGUAGE C IMMUTABLE STRICT;
84+
85+
-- Add new stuff to the operator classes. See comment in pg_trgm--1.0.sql.
86+
87+
ALTEROPERATOR FAMILY gist_trgm_ops USING gist ADD
88+
OPERATOR2<-> (text,text) FORORDER BYpg_catalog.float_ops,
89+
OPERATOR3 pg_catalog.~~ (text,text),
90+
OPERATOR4 pg_catalog.~~* (text,text),
91+
FUNCTION8 (text,text) gtrgm_distance (internal,text,int,oid);
92+
93+
ALTEROPERATOR FAMILY gin_trgm_ops USING gin ADD
94+
OPERATOR3 pg_catalog.~~ (text,text),
95+
OPERATOR4 pg_catalog.~~* (text,text);

‎contrib/pg_trgm/trgm_gin.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ Datumgin_trgm_consistent(PG_FUNCTION_ARGS);
2929
/*
3030
* This function can only be called if a pre-9.1 version of the GIN operator
3131
* class definition is present in the catalogs (probably as a consequence
32-
* of upgrade-in-place).Complain.
32+
* of upgrade-in-place).Cope.
3333
*/
3434
Datum
3535
gin_extract_trgm(PG_FUNCTION_ARGS)
3636
{
37-
ereport(ERROR,
38-
(errmsg("GIN operator class for pg_trgm is out of date"),
39-
errhint("Please drop and re-create the pg_trgm catalog entries.")));
37+
if (PG_NARGS()==3)
38+
returngin_extract_value_trgm(fcinfo);
39+
if (PG_NARGS()==7)
40+
returngin_extract_query_trgm(fcinfo);
41+
elog(ERROR,"unexpected number of arguments to gin_extract_trgm");
4042
PG_RETURN_NULL();
4143
}
4244

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp