MCPcopy Create free account
hub / github.com/apache/cloudberry / lookup_ts_parser_cache

Function lookup_ts_parser_cache

src/backend/utils/cache/ts_cache.c:110–202  ·  view source on GitHub ↗

* Fetch parser cache entry */

Source from the content-addressed store, hash-verified

108 * Fetch parser cache entry
109 */
110TSParserCacheEntry *
111lookup_ts_parser_cache(Oid prsId)
112{
113 TSParserCacheEntry *entry;
114
115 if (TSParserCacheHash == NULL)
116 {
117 /* First time through: initialize the hash table */
118 HASHCTL ctl;
119
120 ctl.keysize = sizeof(Oid);
121 ctl.entrysize = sizeof(TSParserCacheEntry);
122 TSParserCacheHash = hash_create("Tsearch parser cache", 4,
123 &ctl, HASH_ELEM | HASH_BLOBS);
124 /* Flush cache on pg_ts_parser changes */
125 CacheRegisterSyscacheCallback(TSPARSEROID, InvalidateTSCacheCallBack,
126 PointerGetDatum(TSParserCacheHash));
127
128 /* Also make sure CacheMemoryContext exists */
129 if (!CacheMemoryContext)
130 CreateCacheMemoryContext();
131 }
132
133 /* Check single-entry cache */
134 if (lastUsedParser && lastUsedParser->prsId == prsId &&
135 lastUsedParser->isvalid)
136 return lastUsedParser;
137
138 /* Try to look up an existing entry */
139 entry = (TSParserCacheEntry *) hash_search(TSParserCacheHash,
140 (void *) &prsId,
141 HASH_FIND, NULL);
142 if (entry == NULL || !entry->isvalid)
143 {
144 /*
145 * If we didn't find one, we want to make one. But first look up the
146 * object to be sure the OID is real.
147 */
148 HeapTuple tp;
149 Form_pg_ts_parser prs;
150
151 tp = SearchSysCache1(TSPARSEROID, ObjectIdGetDatum(prsId));
152 if (!HeapTupleIsValid(tp))
153 elog(ERROR, "cache lookup failed for text search parser %u",
154 prsId);
155 prs = (Form_pg_ts_parser) GETSTRUCT(tp);
156
157 /*
158 * Sanity checks
159 */
160 if (!OidIsValid(prs->prsstart))
161 elog(ERROR, "text search parser %u has no prsstart method", prsId);
162 if (!OidIsValid(prs->prstoken))
163 elog(ERROR, "text search parser %u has no prstoken method", prsId);
164 if (!OidIsValid(prs->prsend))
165 elog(ERROR, "text search parser %u has no prsend method", prsId);
166
167 if (entry == NULL)

Callers 8

getTokenTypesFunction · 0.85
parsetextFunction · 0.85
hlparsetextFunction · 0.85
tt_setup_firstcallFunction · 0.85
prs_setup_firstcallFunction · 0.85
ts_headline_byid_optFunction · 0.85

Calls 8

hash_createFunction · 0.85
CreateCacheMemoryContextFunction · 0.85
hash_searchFunction · 0.85
SearchSysCache1Function · 0.85
ObjectIdGetDatumFunction · 0.85
ReleaseSysCacheFunction · 0.85
fmgr_info_cxtFunction · 0.85

Tested by

no test coverage detected