* Fetch configuration cache entry */
| 382 | * Fetch configuration cache entry |
| 383 | */ |
| 384 | TSConfigCacheEntry * |
| 385 | lookup_ts_config_cache(Oid cfgId) |
| 386 | { |
| 387 | TSConfigCacheEntry *entry; |
| 388 | |
| 389 | if (TSConfigCacheHash == NULL) |
| 390 | { |
| 391 | /* First time through: initialize the hash table */ |
| 392 | init_ts_config_cache(); |
| 393 | } |
| 394 | |
| 395 | /* Check single-entry cache */ |
| 396 | if (lastUsedConfig && lastUsedConfig->cfgId == cfgId && |
| 397 | lastUsedConfig->isvalid) |
| 398 | return lastUsedConfig; |
| 399 | |
| 400 | /* Try to look up an existing entry */ |
| 401 | entry = (TSConfigCacheEntry *) hash_search(TSConfigCacheHash, |
| 402 | (void *) &cfgId, |
| 403 | HASH_FIND, NULL); |
| 404 | if (entry == NULL || !entry->isvalid) |
| 405 | { |
| 406 | /* |
| 407 | * If we didn't find one, we want to make one. But first look up the |
| 408 | * object to be sure the OID is real. |
| 409 | */ |
| 410 | HeapTuple tp; |
| 411 | Form_pg_ts_config cfg; |
| 412 | Relation maprel; |
| 413 | Relation mapidx; |
| 414 | ScanKeyData mapskey; |
| 415 | SysScanDesc mapscan; |
| 416 | HeapTuple maptup; |
| 417 | ListDictionary maplists[MAXTOKENTYPE + 1]; |
| 418 | Oid mapdicts[MAXDICTSPERTT]; |
| 419 | int maxtokentype; |
| 420 | int ndicts; |
| 421 | int i; |
| 422 | |
| 423 | tp = SearchSysCache1(TSCONFIGOID, ObjectIdGetDatum(cfgId)); |
| 424 | if (!HeapTupleIsValid(tp)) |
| 425 | elog(ERROR, "cache lookup failed for text search configuration %u", |
| 426 | cfgId); |
| 427 | cfg = (Form_pg_ts_config) GETSTRUCT(tp); |
| 428 | |
| 429 | /* |
| 430 | * Sanity checks |
| 431 | */ |
| 432 | if (!OidIsValid(cfg->cfgparser)) |
| 433 | elog(ERROR, "text search configuration %u has no parser", cfgId); |
| 434 | |
| 435 | if (entry == NULL) |
| 436 | { |
| 437 | bool found; |
| 438 | |
| 439 | /* Now make the cache entry */ |
| 440 | entry = (TSConfigCacheEntry *) |
| 441 | hash_search(TSConfigCacheHash, |
no test coverage detected