99 *
1010 *
1111 * IDENTIFICATION
12- * $PostgreSQL: pgsql/src/backend/commands/tsearchcmds.c,v 1.3 2007/08/2201:39:44 tgl Exp $
12+ * $PostgreSQL: pgsql/src/backend/commands/tsearchcmds.c,v 1.4 2007/08/2205:13:50 tgl Exp $
1313 *
1414 *-------------------------------------------------------------------------
1515 */
4646#include "utils/syscache.h"
4747
4848
49- static HeapTuple UpdateTSConfiguration (AlterTSConfigurationStmt * stmt ,
50- HeapTuple tup );
5149static void MakeConfigurationMapping (AlterTSConfigurationStmt * stmt ,
52- HeapTuple tup );
50+ HeapTuple tup , Relation relMap );
5351static 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)
12651263Oid namespaceoid ;
12661264char * cfgname ;
12671265NameData cname ;
1268- List * sourceName = NIL ;
12691266Oid sourceOid = InvalidOid ;
12701267Oid prsOid = InvalidOid ;
12711268Oid cfgOid ;
@@ -1290,23 +1287,26 @@ DefineTSConfiguration(List *names, List *parameters)
12901287if (pg_strcasecmp (defel -> defname ,"parser" )== 0 )
12911288prsOid = TSParserGetPrsid (defGetQualifiedName (defel ), false);
12921289else if (pg_strcasecmp (defel -> defname ,"copy" )== 0 )
1293- sourceName = defGetQualifiedName (defel );
1290+ sourceOid = TSConfigGetCfgid ( defGetQualifiedName (defel ), false );
12941291else
12951292ereport (ERROR ,
12961293(errcode (ERRCODE_SYNTAX_ERROR ),
12971294errmsg ("text search configuration parameter \"%s\" not recognized" ,
12981295defel -> 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{
13061308Form_pg_ts_config cfg ;
13071309
1308- sourceOid = TSConfigGetCfgid (sourceName , false);
1309-
13101310tup = SearchSysCache (TSCONFIGOID ,
13111311ObjectIdGetDatum (sourceOid ),
131213120 ,0 ,0 );
@@ -1316,9 +1316,8 @@ DefineTSConfiguration(List *names, List *parameters)
13161316
13171317cfg = (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
13231322ReleaseSysCache (tup );
13241323}
@@ -1626,8 +1625,7 @@ void
16261625AlterTSConfiguration (AlterTSConfigurationStmt * stmt )
16271626{
16281627HeapTuple tup ;
1629- HeapTuple newtup ;
1630- Relation mapRel ;
1628+ Relation relMap ;
16311629
16321630/* Find the configuration */
16331631tup = GetTSConfigTuple (stmt -> cfgname );
@@ -1642,84 +1640,22 @@ AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
16421640aclcheck_error (ACLCHECK_NOT_OWNER ,ACL_KIND_TSCONFIGURATION ,
16431641NameListToString (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 */
16521646if (stmt -> dicts )
1653- MakeConfigurationMapping (stmt ,newtup );
1647+ MakeConfigurationMapping (stmt ,tup , relMap );
16541648else 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
16681656ReleaseSysCache (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 */
17821718static void
1783- MakeConfigurationMapping (AlterTSConfigurationStmt * stmt ,HeapTuple tup )
1719+ MakeConfigurationMapping (AlterTSConfigurationStmt * stmt ,
1720+ HeapTuple tup ,Relation relMap )
17841721{
17851722Oid cfgId = HeapTupleGetOid (tup );
1786- Relation relMap ;
17871723ScanKeyData skey [2 ];
17881724SysScanDesc scan ;
17891725HeapTuple maptup ;
@@ -1801,8 +1737,6 @@ MakeConfigurationMapping(AlterTSConfigurationStmt *stmt, HeapTuple tup)
18011737tokens = getTokenTypes (prsId ,stmt -> tokentype );
18021738ntoken = list_length (stmt -> tokentype );
18031739
1804- relMap = heap_open (TSConfigMapRelationId ,RowExclusiveLock );
1805-
18061740if (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 */
19481880static void
1949- DropConfigurationMapping (AlterTSConfigurationStmt * stmt ,HeapTuple tup )
1881+ DropConfigurationMapping (AlterTSConfigurationStmt * stmt ,
1882+ HeapTuple tup ,Relation relMap )
19501883{
19511884Oid cfgId = HeapTupleGetOid (tup );
1952- Relation relMap ;
19531885ScanKeyData skey [2 ];
19541886SysScanDesc scan ;
19551887HeapTuple maptup ;
@@ -1964,8 +1896,6 @@ DropConfigurationMapping(AlterTSConfigurationStmt *stmt, HeapTuple tup)
19641896tokens = getTokenTypes (prsId ,stmt -> tokentype );
19651897ntoken = list_length (stmt -> tokentype );
19661898
1967- relMap = heap_open (TSConfigMapRelationId ,RowExclusiveLock );
1968-
19691899i = 0 ;
19701900foreach (c ,stmt -> tokentype )
19711901{
@@ -2011,8 +1941,6 @@ DropConfigurationMapping(AlterTSConfigurationStmt *stmt, HeapTuple tup)
20111941
20121942i ++ ;
20131943}
2014-
2015- heap_close (relMap ,RowExclusiveLock );
20161944}
20171945
20181946