Skip to content

Commit 8a5592d

Browse files
committed
Remove option to change parser of an existing text search configuration.
This prevents needing to do complex and poorly-defined updates of the mapping table if the new parser has different token types than the old. Per discussion.
1 parent 40c1d7c commit 8a5592d

File tree

5 files changed

+33
-139
lines changed

5 files changed

+33
-139
lines changed

doc/src/sgml/ref/alter_tsconfig.sgml

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_tsconfig.sgml,v 1.1 2007/08/21 21:08:47 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_tsconfig.sgml,v 1.2 2007/08/22 05:13:50 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -20,9 +20,6 @@ PostgreSQL documentation
2020

2121
<refsynopsisdiv>
2222
<synopsis>
23-
ALTER TEXT SEARCH CONFIGURATION <replaceable>name</replaceable> (
24-
PARSER = <replaceable class="parameter">parser_name</replaceable>
25-
)
2623
ALTER TEXT SEARCH CONFIGURATION <replaceable>name</replaceable>
2724
ADD MAPPING FOR <replaceable class="parameter">token_type</replaceable> [, ... ] WITH <replaceable class="parameter">dictionary_name</replaceable> [, ... ]
2825
ALTER TEXT SEARCH CONFIGURATION <replaceable>name</replaceable>
@@ -43,8 +40,8 @@ ALTER TEXT SEARCH CONFIGURATION <replaceable>name</replaceable> OWNER TO <replac
4340

4441
<para>
4542
<command>ALTER TEXT SEARCH CONFIGURATION</command> changes the definition of
46-
a text search configuration. You can change which parser it uses, modify
47-
its mapping from token types to dictionaries,
43+
a text search configuration. You can modify
44+
its mappings from token types to dictionaries,
4845
or change the configuration's name or owner.
4946
</para>
5047

@@ -68,15 +65,6 @@ ALTER TEXT SEARCH CONFIGURATION <replaceable>name</replaceable> OWNER TO <replac
6865
</listitem>
6966
</varlistentry>
7067

71-
<varlistentry>
72-
<term><replaceable class="parameter">parser_name</replaceable></term>
73-
<listitem>
74-
<para>
75-
The name of a new text search parser to use for this configuration.
76-
</para>
77-
</listitem>
78-
</varlistentry>
79-
8068
<varlistentry>
8169
<term><replaceable class="parameter">token_type</replaceable></term>
8270
<listitem>
@@ -154,19 +142,7 @@ ALTER TEXT SEARCH CONFIGURATION <replaceable>name</replaceable> OWNER TO <replac
154142
</para>
155143

156144
</refsect1>
157-
158-
<refsect1>
159-
<title>Notes</title>
160145

161-
<para>
162-
While changing the text search parser used by a configuration is allowed,
163-
this will only work nicely if old and new parsers use the same set of
164-
token types. It is advisable to drop the mappings for any incompatible
165-
token types before changing parsers.
166-
</para>
167-
168-
</refsect1>
169-
170146
<refsect1>
171147
<title>Examples</title>
172148

doc/src/sgml/ref/create_tsconfig.sgml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_tsconfig.sgml,v 1.1 2007/08/21 21:08:47 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_tsconfig.sgml,v 1.2 2007/08/22 05:13:50 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -98,10 +98,9 @@ CREATE TEXT SEARCH CONFIGURATION <replaceable class="parameter">name</replaceabl
9898
<title>Notes</title>
9999

100100
<para>
101-
It is allowed to specify both <literal>PARSER</> and <literal>COPY</>,
102-
resulting in the specified parser being used with whatever mappings
103-
are in the source configuration. This is generally inadvisable,
104-
unless you know that both parsers involved use the same token type set.
101+
The <literal>PARSER</> and <literal>COPY</> options are mutually
102+
exclusive, because when an existing configuration is copied, its
103+
parser selection is copied too.
105104
</para>
106105

107106
</refsect1>

src/backend/commands/tsearchcmds.c

Lines changed: 23 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/commands/tsearchcmds.c,v 1.3 2007/08/22 01:39:44 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/commands/tsearchcmds.c,v 1.4 2007/08/22 05:13:50 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -46,12 +46,10 @@
4646
#include "utils/syscache.h"
4747

4848

49-
static HeapTuple UpdateTSConfiguration(AlterTSConfigurationStmt *stmt,
50-
HeapTuple tup);
5149
static void MakeConfigurationMapping(AlterTSConfigurationStmt *stmt,
52-
HeapTuple tup);
50+
HeapTuple tup, Relation relMap);
5351
static void DropConfigurationMapping(AlterTSConfigurationStmt *stmt,
54-
HeapTuple tup);
52+
HeapTuple tup, Relation relMap);
5553

5654

5755
/* --------------------- TS Parser commands ------------------------ */
@@ -1265,7 +1263,6 @@ DefineTSConfiguration(List *names, List *parameters)
12651263
Oid namespaceoid;
12661264
char *cfgname;
12671265
NameData cname;
1268-
List *sourceName = NIL;
12691266
Oid sourceOid = InvalidOid;
12701267
Oid prsOid = InvalidOid;
12711268
Oid cfgOid;
@@ -1290,23 +1287,26 @@ DefineTSConfiguration(List *names, List *parameters)
12901287
if (pg_strcasecmp(defel->defname, "parser") == 0)
12911288
prsOid = TSParserGetPrsid(defGetQualifiedName(defel), false);
12921289
else if (pg_strcasecmp(defel->defname, "copy") == 0)
1293-
sourceName = defGetQualifiedName(defel);
1290+
sourceOid = TSConfigGetCfgid(defGetQualifiedName(defel), false);
12941291
else
12951292
ereport(ERROR,
12961293
(errcode(ERRCODE_SYNTAX_ERROR),
12971294
errmsg("text search configuration parameter \"%s\" not recognized",
12981295
defel->defname)));
12991296
}
13001297

1298+
if (OidIsValid(sourceOid) && OidIsValid(prsOid))
1299+
ereport(ERROR,
1300+
(errcode(ERRCODE_SYNTAX_ERROR),
1301+
errmsg("cannot specify both PARSER and COPY options")));
1302+
13011303
/*
13021304
* Look up source config if given.
13031305
*/
1304-
if (sourceName)
1306+
if (OidIsValid(sourceOid))
13051307
{
13061308
Form_pg_ts_config cfg;
13071309

1308-
sourceOid = TSConfigGetCfgid(sourceName, false);
1309-
13101310
tup = SearchSysCache(TSCONFIGOID,
13111311
ObjectIdGetDatum(sourceOid),
13121312
0, 0, 0);
@@ -1316,9 +1316,8 @@ DefineTSConfiguration(List *names, List *parameters)
13161316

13171317
cfg = (Form_pg_ts_config) GETSTRUCT(tup);
13181318

1319-
/* Use source's parser if no other was specified */
1320-
if (!OidIsValid(prsOid))
1321-
prsOid = cfg->cfgparser;
1319+
/* use source's parser */
1320+
prsOid = cfg->cfgparser;
13221321

13231322
ReleaseSysCache(tup);
13241323
}
@@ -1626,8 +1625,7 @@ void
16261625
AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
16271626
{
16281627
HeapTuple tup;
1629-
HeapTuple newtup;
1630-
Relation mapRel;
1628+
Relation relMap;
16311629

16321630
/* Find the configuration */
16331631
tup = GetTSConfigTuple(stmt->cfgname);
@@ -1642,84 +1640,22 @@ AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
16421640
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TSCONFIGURATION,
16431641
NameListToString(stmt->cfgname));
16441642

1645-
/* Update fields of config tuple? */
1646-
if (stmt->options)
1647-
newtup = UpdateTSConfiguration(stmt, tup);
1648-
else
1649-
newtup = tup;
1643+
relMap = heap_open(TSConfigMapRelationId, RowExclusiveLock);
16501644

1651-
/* Add or drop mappings? */
1645+
/* Add or drop mappings */
16521646
if (stmt->dicts)
1653-
MakeConfigurationMapping(stmt, newtup);
1647+
MakeConfigurationMapping(stmt, tup, relMap);
16541648
else if (stmt->tokentype)
1655-
DropConfigurationMapping(stmt, newtup);
1656-
1657-
/*
1658-
* Even if we aren't changing mappings, there could already be some,
1659-
* so makeConfigurationDependencies always has to look.
1660-
*/
1661-
mapRel = heap_open(TSConfigMapRelationId, AccessShareLock);
1649+
DropConfigurationMapping(stmt, tup, relMap);
16621650

16631651
/* Update dependencies */
1664-
makeConfigurationDependencies(newtup, true, mapRel);
1652+
makeConfigurationDependencies(tup, true, relMap);
16651653

1666-
heap_close(mapRel, AccessShareLock);
1654+
heap_close(relMap, RowExclusiveLock);
16671655

16681656
ReleaseSysCache(tup);
16691657
}
16701658

1671-
/*
1672-
* ALTER TEXT SEARCH CONFIGURATION - update fields of pg_ts_config tuple
1673-
*/
1674-
static HeapTuple
1675-
UpdateTSConfiguration(AlterTSConfigurationStmt *stmt, HeapTuple tup)
1676-
{
1677-
Relation cfgRel;
1678-
ListCell *pl;
1679-
Datum repl_val[Natts_pg_ts_config];
1680-
char repl_null[Natts_pg_ts_config];
1681-
char repl_repl[Natts_pg_ts_config];
1682-
HeapTuple newtup;
1683-
1684-
memset(repl_val, 0, sizeof(repl_val));
1685-
memset(repl_null, ' ', sizeof(repl_null));
1686-
memset(repl_repl, ' ', sizeof(repl_repl));
1687-
1688-
cfgRel = heap_open(TSConfigRelationId, RowExclusiveLock);
1689-
1690-
foreach(pl, stmt->options)
1691-
{
1692-
DefElem *defel = (DefElem *) lfirst(pl);
1693-
1694-
if (pg_strcasecmp(defel->defname, "parser") == 0)
1695-
{
1696-
Oid newPrs;
1697-
1698-
newPrs = TSParserGetPrsid(defGetQualifiedName(defel), false);
1699-
repl_val[Anum_pg_ts_config_cfgparser - 1] = ObjectIdGetDatum(newPrs);
1700-
repl_repl[Anum_pg_ts_config_cfgparser - 1] = 'r';
1701-
}
1702-
else
1703-
ereport(ERROR,
1704-
(errcode(ERRCODE_SYNTAX_ERROR),
1705-
errmsg("text search configuration parameter \"%s\" not recognized",
1706-
defel->defname)));
1707-
}
1708-
1709-
newtup = heap_modifytuple(tup, RelationGetDescr(cfgRel),
1710-
repl_val, repl_null, repl_repl);
1711-
1712-
simple_heap_update(cfgRel, &newtup->t_self, newtup);
1713-
1714-
CatalogUpdateIndexes(cfgRel, newtup);
1715-
1716-
heap_close(cfgRel, RowExclusiveLock);
1717-
1718-
return newtup;
1719-
}
1720-
1721-
/*------------------- TS Configuration mapping stuff ----------------*/
1722-
17231659
/*
17241660
* Translate a list of token type names to an array of token type numbers
17251661
*/
@@ -1780,10 +1716,10 @@ getTokenTypes(Oid prsId, List *tokennames)
17801716
* ALTER TEXT SEARCH CONFIGURATION ADD/ALTER MAPPING
17811717
*/
17821718
static void
1783-
MakeConfigurationMapping(AlterTSConfigurationStmt *stmt, HeapTuple tup)
1719+
MakeConfigurationMapping(AlterTSConfigurationStmt *stmt,
1720+
HeapTuple tup, Relation relMap)
17841721
{
17851722
Oid cfgId = HeapTupleGetOid(tup);
1786-
Relation relMap;
17871723
ScanKeyData skey[2];
17881724
SysScanDesc scan;
17891725
HeapTuple maptup;
@@ -1801,8 +1737,6 @@ MakeConfigurationMapping(AlterTSConfigurationStmt *stmt, HeapTuple tup)
18011737
tokens = getTokenTypes(prsId, stmt->tokentype);
18021738
ntoken = list_length(stmt->tokentype);
18031739

1804-
relMap = heap_open(TSConfigMapRelationId, RowExclusiveLock);
1805-
18061740
if (stmt->override)
18071741
{
18081742
/*
@@ -1938,18 +1872,16 @@ MakeConfigurationMapping(AlterTSConfigurationStmt *stmt, HeapTuple tup)
19381872
}
19391873
}
19401874
}
1941-
1942-
heap_close(relMap, RowExclusiveLock);
19431875
}
19441876

19451877
/*
19461878
* ALTER TEXT SEARCH CONFIGURATION DROP MAPPING
19471879
*/
19481880
static void
1949-
DropConfigurationMapping(AlterTSConfigurationStmt *stmt, HeapTuple tup)
1881+
DropConfigurationMapping(AlterTSConfigurationStmt *stmt,
1882+
HeapTuple tup, Relation relMap)
19501883
{
19511884
Oid cfgId = HeapTupleGetOid(tup);
1952-
Relation relMap;
19531885
ScanKeyData skey[2];
19541886
SysScanDesc scan;
19551887
HeapTuple maptup;
@@ -1964,8 +1896,6 @@ DropConfigurationMapping(AlterTSConfigurationStmt *stmt, HeapTuple tup)
19641896
tokens = getTokenTypes(prsId, stmt->tokentype);
19651897
ntoken = list_length(stmt->tokentype);
19661898

1967-
relMap = heap_open(TSConfigMapRelationId, RowExclusiveLock);
1968-
19691899
i = 0;
19701900
foreach(c, stmt->tokentype)
19711901
{
@@ -2011,8 +1941,6 @@ DropConfigurationMapping(AlterTSConfigurationStmt *stmt, HeapTuple tup)
20111941

20121942
i++;
20131943
}
2014-
2015-
heap_close(relMap, RowExclusiveLock);
20161944
}
20171945

20181946

src/backend/parser/gram.y

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.599 2007/08/21 15:13:42 tgl Exp $
14+
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.600 2007/08/22 05:13:50 tgl Exp $
1515
*
1616
* HISTORY
1717
* AUTHOR DATE MAJOR EVENT
@@ -5523,14 +5523,7 @@ AlterTSDictionaryStmt:
55235523
;
55245524

55255525
AlterTSConfigurationStmt:
5526-
ALTER TEXT_P SEARCH CONFIGURATION any_name definition
5527-
{
5528-
AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
5529-
n->cfgname = $5;
5530-
n->options = $6;
5531-
$$ = (Node *)n;
5532-
}
5533-
| ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
5526+
ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list WITH any_name_list
55345527
{
55355528
AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
55365529
n->cfgname = $5;

src/include/nodes/parsenodes.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.351 2007/08/21 01:11:28 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.352 2007/08/22 05:13:50 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -2054,10 +2054,8 @@ typedef struct AlterTSConfigurationStmt
20542054
{
20552055
NodeTag type;
20562056
List *cfgname; /* qualified name (list of Value strings) */
2057-
List *options; /* List of DefElem nodes */
20582057

20592058
/*
2060-
* These fields are used for ADD/ALTER/DROP MAPPING variants.
20612059
* dicts will be non-NIL if ADD/ALTER MAPPING was specified.
20622060
* If dicts is NIL, but tokentype isn't, DROP MAPPING was specified.
20632061
*/

0 commit comments

Comments
 (0)