9
9
*
10
10
*
11
11
* 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 $
13
13
*
14
14
*-------------------------------------------------------------------------
15
15
*/
46
46
#include "utils/syscache.h"
47
47
48
48
49
- static HeapTuple UpdateTSConfiguration (AlterTSConfigurationStmt * stmt ,
50
- HeapTuple tup );
51
49
static void MakeConfigurationMapping (AlterTSConfigurationStmt * stmt ,
52
- HeapTuple tup );
50
+ HeapTuple tup , Relation relMap );
53
51
static void DropConfigurationMapping (AlterTSConfigurationStmt * stmt ,
54
- HeapTuple tup );
52
+ HeapTuple tup , Relation relMap );
55
53
56
54
57
55
/* --------------------- TS Parser commands ------------------------ */
@@ -1265,7 +1263,6 @@ DefineTSConfiguration(List *names, List *parameters)
1265
1263
Oid namespaceoid ;
1266
1264
char * cfgname ;
1267
1265
NameData cname ;
1268
- List * sourceName = NIL ;
1269
1266
Oid sourceOid = InvalidOid ;
1270
1267
Oid prsOid = InvalidOid ;
1271
1268
Oid cfgOid ;
@@ -1290,23 +1287,26 @@ DefineTSConfiguration(List *names, List *parameters)
1290
1287
if (pg_strcasecmp (defel -> defname ,"parser" )== 0 )
1291
1288
prsOid = TSParserGetPrsid (defGetQualifiedName (defel ), false);
1292
1289
else if (pg_strcasecmp (defel -> defname ,"copy" )== 0 )
1293
- sourceName = defGetQualifiedName (defel );
1290
+ sourceOid = TSConfigGetCfgid ( defGetQualifiedName (defel ), false );
1294
1291
else
1295
1292
ereport (ERROR ,
1296
1293
(errcode (ERRCODE_SYNTAX_ERROR ),
1297
1294
errmsg ("text search configuration parameter \"%s\" not recognized" ,
1298
1295
defel -> defname )));
1299
1296
}
1300
1297
1298
+ if (OidIsValid (sourceOid )&& OidIsValid (prsOid ))
1299
+ ereport (ERROR ,
1300
+ (errcode (ERRCODE_SYNTAX_ERROR ),
1301
+ errmsg ("cannot specify both PARSER and COPY options" )));
1302
+
1301
1303
/*
1302
1304
* Look up source config if given.
1303
1305
*/
1304
- if (sourceName )
1306
+ if (OidIsValid ( sourceOid ) )
1305
1307
{
1306
1308
Form_pg_ts_config cfg ;
1307
1309
1308
- sourceOid = TSConfigGetCfgid (sourceName , false);
1309
-
1310
1310
tup = SearchSysCache (TSCONFIGOID ,
1311
1311
ObjectIdGetDatum (sourceOid ),
1312
1312
0 ,0 ,0 );
@@ -1316,9 +1316,8 @@ DefineTSConfiguration(List *names, List *parameters)
1316
1316
1317
1317
cfg = (Form_pg_ts_config )GETSTRUCT (tup );
1318
1318
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 ;
1322
1321
1323
1322
ReleaseSysCache (tup );
1324
1323
}
@@ -1626,8 +1625,7 @@ void
1626
1625
AlterTSConfiguration (AlterTSConfigurationStmt * stmt )
1627
1626
{
1628
1627
HeapTuple tup ;
1629
- HeapTuple newtup ;
1630
- Relation mapRel ;
1628
+ Relation relMap ;
1631
1629
1632
1630
/* Find the configuration */
1633
1631
tup = GetTSConfigTuple (stmt -> cfgname );
@@ -1642,84 +1640,22 @@ AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
1642
1640
aclcheck_error (ACLCHECK_NOT_OWNER ,ACL_KIND_TSCONFIGURATION ,
1643
1641
NameListToString (stmt -> cfgname ));
1644
1642
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 );
1650
1644
1651
- /* Add or drop mappings? */
1645
+ /* Add or drop mappings */
1652
1646
if (stmt -> dicts )
1653
- MakeConfigurationMapping (stmt ,newtup );
1647
+ MakeConfigurationMapping (stmt ,tup , relMap );
1654
1648
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 );
1662
1650
1663
1651
/* Update dependencies */
1664
- makeConfigurationDependencies (newtup , true,mapRel );
1652
+ makeConfigurationDependencies (tup , true,relMap );
1665
1653
1666
- heap_close (mapRel , AccessShareLock );
1654
+ heap_close (relMap , RowExclusiveLock );
1667
1655
1668
1656
ReleaseSysCache (tup );
1669
1657
}
1670
1658
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
-
1723
1659
/*
1724
1660
* Translate a list of token type names to an array of token type numbers
1725
1661
*/
@@ -1780,10 +1716,10 @@ getTokenTypes(Oid prsId, List *tokennames)
1780
1716
* ALTER TEXT SEARCH CONFIGURATION ADD/ALTER MAPPING
1781
1717
*/
1782
1718
static void
1783
- MakeConfigurationMapping (AlterTSConfigurationStmt * stmt ,HeapTuple tup )
1719
+ MakeConfigurationMapping (AlterTSConfigurationStmt * stmt ,
1720
+ HeapTuple tup ,Relation relMap )
1784
1721
{
1785
1722
Oid cfgId = HeapTupleGetOid (tup );
1786
- Relation relMap ;
1787
1723
ScanKeyData skey [2 ];
1788
1724
SysScanDesc scan ;
1789
1725
HeapTuple maptup ;
@@ -1801,8 +1737,6 @@ MakeConfigurationMapping(AlterTSConfigurationStmt *stmt, HeapTuple tup)
1801
1737
tokens = getTokenTypes (prsId ,stmt -> tokentype );
1802
1738
ntoken = list_length (stmt -> tokentype );
1803
1739
1804
- relMap = heap_open (TSConfigMapRelationId ,RowExclusiveLock );
1805
-
1806
1740
if (stmt -> override )
1807
1741
{
1808
1742
/*
@@ -1938,18 +1872,16 @@ MakeConfigurationMapping(AlterTSConfigurationStmt *stmt, HeapTuple tup)
1938
1872
}
1939
1873
}
1940
1874
}
1941
-
1942
- heap_close (relMap ,RowExclusiveLock );
1943
1875
}
1944
1876
1945
1877
/*
1946
1878
* ALTER TEXT SEARCH CONFIGURATION DROP MAPPING
1947
1879
*/
1948
1880
static void
1949
- DropConfigurationMapping (AlterTSConfigurationStmt * stmt ,HeapTuple tup )
1881
+ DropConfigurationMapping (AlterTSConfigurationStmt * stmt ,
1882
+ HeapTuple tup ,Relation relMap )
1950
1883
{
1951
1884
Oid cfgId = HeapTupleGetOid (tup );
1952
- Relation relMap ;
1953
1885
ScanKeyData skey [2 ];
1954
1886
SysScanDesc scan ;
1955
1887
HeapTuple maptup ;
@@ -1964,8 +1896,6 @@ DropConfigurationMapping(AlterTSConfigurationStmt *stmt, HeapTuple tup)
1964
1896
tokens = getTokenTypes (prsId ,stmt -> tokentype );
1965
1897
ntoken = list_length (stmt -> tokentype );
1966
1898
1967
- relMap = heap_open (TSConfigMapRelationId ,RowExclusiveLock );
1968
-
1969
1899
i = 0 ;
1970
1900
foreach (c ,stmt -> tokentype )
1971
1901
{
@@ -2011,8 +1941,6 @@ DropConfigurationMapping(AlterTSConfigurationStmt *stmt, HeapTuple tup)
2011
1941
2012
1942
i ++ ;
2013
1943
}
2014
-
2015
- heap_close (relMap ,RowExclusiveLock );
2016
1944
}
2017
1945
2018
1946