diff options
| author | Noah Misch | 2017-03-12 23:35:34 +0000 |
|---|---|---|
| committer | Noah Misch | 2017-03-12 23:35:34 +0000 |
| commit | 3a0d473192b2045cbaf997df8437e7762d34f3ba (patch) | |
| tree | 8bdf7e5e8f6a69041ff3fd4b2114cb9e8cbd69d4 /src/backend/tsearch | |
| parent | 9d7726c2ba06b932f791f2d0cc5acf73cc0b4dca (diff) | |
Use wrappers of PG_DETOAST_DATUM_PACKED() more.
This makes almost all core code follow the policy introduced in the
previous commit. Specific decisions:
- Text search support functions with char* and length arguments, such as
prsstart and lexize, may receive unaligned strings. I doubt
maintainers of non-core text search code will notice.
- Use plain VARDATA() on values detoasted or synthesized earlier in the
same function. Use VARDATA_ANY() on varlenas sourced outside the
function, even if they happen to always have four-byte headers. As an
exception, retain the universal practice of using VARDATA() on return
values of SendFunctionCall().
- Retain PG_GETARG_BYTEA_P() in pageinspect. (Page images are too large
for a one-byte header, so this misses no optimization.) Sites that do
not call get_page_from_raw() typically need the four-byte alignment.
- For now, do not change btree_gist. Its use of four-byte headers in
memory is partly entangled with storage of 4-byte headers inside
GBT_VARKEY, on disk.
- For now, do not change gtrgm_consistent() or gtrgm_distance(). They
incorporate the varlena header into a cache, and there are multiple
credible implementation strategies to consider.
Diffstat (limited to 'src/backend/tsearch')
| -rw-r--r-- | src/backend/tsearch/dict.c | 10 | ||||
| -rw-r--r-- | src/backend/tsearch/to_tsany.c | 22 | ||||
| -rw-r--r-- | src/backend/tsearch/wparser.c | 19 |
3 files changed, 26 insertions, 25 deletions
diff --git a/src/backend/tsearch/dict.c b/src/backend/tsearch/dict.c index 87ee8bfe2e0..ba8a3d79a83 100644 --- a/src/backend/tsearch/dict.c +++ b/src/backend/tsearch/dict.c @@ -26,7 +26,7 @@ Datum ts_lexize(PG_FUNCTION_ARGS) { Oid dictId = PG_GETARG_OID(0); - text *in = PG_GETARG_TEXT_P(1); + text *in = PG_GETARG_TEXT_PP(1); ArrayType *a; TSDictionaryCacheEntry *dict; TSLexeme *res, @@ -38,8 +38,8 @@ ts_lexize(PG_FUNCTION_ARGS) res = (TSLexeme *) DatumGetPointer(FunctionCall4(&dict->lexize, PointerGetDatum(dict->dictData), - PointerGetDatum(VARDATA(in)), - Int32GetDatum(VARSIZE(in) - VARHDRSZ), + PointerGetDatum(VARDATA_ANY(in)), + Int32GetDatum(VARSIZE_ANY_EXHDR(in)), PointerGetDatum(&dstate))); if (dstate.getnext) @@ -47,8 +47,8 @@ ts_lexize(PG_FUNCTION_ARGS) dstate.isend = true; ptr = (TSLexeme *) DatumGetPointer(FunctionCall4(&dict->lexize, PointerGetDatum(dict->dictData), - PointerGetDatum(VARDATA(in)), - Int32GetDatum(VARSIZE(in) - VARHDRSZ), + PointerGetDatum(VARDATA_ANY(in)), + Int32GetDatum(VARSIZE_ANY_EXHDR(in)), PointerGetDatum(&dstate))); if (ptr != NULL) res = ptr; diff --git a/src/backend/tsearch/to_tsany.c b/src/backend/tsearch/to_tsany.c index 6e5de8f9202..398a781c037 100644 --- a/src/backend/tsearch/to_tsany.c +++ b/src/backend/tsearch/to_tsany.c @@ -216,19 +216,19 @@ Datum to_tsvector_byid(PG_FUNCTION_ARGS) { Oid cfgId = PG_GETARG_OID(0); - text *in = PG_GETARG_TEXT_P(1); + text *in = PG_GETARG_TEXT_PP(1); ParsedText prs; TSVector out; - prs.lenwords = (VARSIZE(in) - VARHDRSZ) / 6; /* just estimation of - * word's number */ + prs.lenwords = VARSIZE_ANY_EXHDR(in) / 6; /* just estimation of word's + * number */ if (prs.lenwords == 0) prs.lenwords = 2; prs.curwords = 0; prs.pos = 0; prs.words = (ParsedWord *) palloc(sizeof(ParsedWord) * prs.lenwords); - parsetext(cfgId, &prs, VARDATA(in), VARSIZE(in) - VARHDRSZ); + parsetext(cfgId, &prs, VARDATA_ANY(in), VARSIZE_ANY_EXHDR(in)); PG_FREE_IF_COPY(in, 1); if (prs.curwords) @@ -247,7 +247,7 @@ to_tsvector_byid(PG_FUNCTION_ARGS) Datum to_tsvector(PG_FUNCTION_ARGS) { - text *in = PG_GETARG_TEXT_P(0); + text *in = PG_GETARG_TEXT_PP(0); Oid cfgId; cfgId = getTSCurrentConfig(true); @@ -362,7 +362,7 @@ pushval_morph(Datum opaque, TSQueryParserState state, char *strval, int lenval, Datum to_tsquery_byid(PG_FUNCTION_ARGS) { - text *in = PG_GETARG_TEXT_P(1); + text *in = PG_GETARG_TEXT_PP(1); TSQuery query; MorphOpaque data; @@ -380,7 +380,7 @@ to_tsquery_byid(PG_FUNCTION_ARGS) Datum to_tsquery(PG_FUNCTION_ARGS) { - text *in = PG_GETARG_TEXT_P(0); + text *in = PG_GETARG_TEXT_PP(0); Oid cfgId; cfgId = getTSCurrentConfig(true); @@ -392,7 +392,7 @@ to_tsquery(PG_FUNCTION_ARGS) Datum plainto_tsquery_byid(PG_FUNCTION_ARGS) { - text *in = PG_GETARG_TEXT_P(1); + text *in = PG_GETARG_TEXT_PP(1); TSQuery query; MorphOpaque data; @@ -410,7 +410,7 @@ plainto_tsquery_byid(PG_FUNCTION_ARGS) Datum plainto_tsquery(PG_FUNCTION_ARGS) { - text *in = PG_GETARG_TEXT_P(0); + text *in = PG_GETARG_TEXT_PP(0); Oid cfgId; cfgId = getTSCurrentConfig(true); @@ -423,7 +423,7 @@ plainto_tsquery(PG_FUNCTION_ARGS) Datum phraseto_tsquery_byid(PG_FUNCTION_ARGS) { - text *in = PG_GETARG_TEXT_P(1); + text *in = PG_GETARG_TEXT_PP(1); TSQuery query; MorphOpaque data; @@ -441,7 +441,7 @@ phraseto_tsquery_byid(PG_FUNCTION_ARGS) Datum phraseto_tsquery(PG_FUNCTION_ARGS) { - text *in = PG_GETARG_TEXT_P(0); + text *in = PG_GETARG_TEXT_PP(0); Oid cfgId; cfgId = getTSCurrentConfig(true); diff --git a/src/backend/tsearch/wparser.c b/src/backend/tsearch/wparser.c index 8ca1c62713e..d8f2f65542b 100644 --- a/src/backend/tsearch/wparser.c +++ b/src/backend/tsearch/wparser.c @@ -123,7 +123,7 @@ ts_token_type_byname(PG_FUNCTION_ARGS) if (SRF_IS_FIRSTCALL()) { - text *prsname = PG_GETARG_TEXT_P(0); + text *prsname = PG_GETARG_TEXT_PP(0); Oid prsId; funcctx = SRF_FIRSTCALL_INIT(); @@ -172,8 +172,8 @@ prs_setup_firstcall(FuncCallContext *funcctx, Oid prsid, text *txt) st->list = (LexemeEntry *) palloc(sizeof(LexemeEntry) * st->len); prsdata = (void *) DatumGetPointer(FunctionCall2(&prs->prsstart, - PointerGetDatum(VARDATA(txt)), - Int32GetDatum(VARSIZE(txt) - VARHDRSZ))); + PointerGetDatum(VARDATA_ANY(txt)), + Int32GetDatum(VARSIZE_ANY_EXHDR(txt)))); while ((type = DatumGetInt32(FunctionCall3(&prs->prstoken, PointerGetDatum(prsdata), @@ -248,7 +248,7 @@ ts_parse_byid(PG_FUNCTION_ARGS) if (SRF_IS_FIRSTCALL()) { - text *txt = PG_GETARG_TEXT_P(1); + text *txt = PG_GETARG_TEXT_PP(1); funcctx = SRF_FIRSTCALL_INIT(); prs_setup_firstcall(funcctx, PG_GETARG_OID(0), txt); @@ -270,8 +270,8 @@ ts_parse_byname(PG_FUNCTION_ARGS) if (SRF_IS_FIRSTCALL()) { - text *prsname = PG_GETARG_TEXT_P(0); - text *txt = PG_GETARG_TEXT_P(1); + text *prsname = PG_GETARG_TEXT_PP(0); + text *txt = PG_GETARG_TEXT_PP(1); Oid prsId; funcctx = SRF_FIRSTCALL_INIT(); @@ -289,9 +289,9 @@ ts_parse_byname(PG_FUNCTION_ARGS) Datum ts_headline_byid_opt(PG_FUNCTION_ARGS) { - text *in = PG_GETARG_TEXT_P(1); + text *in = PG_GETARG_TEXT_PP(1); TSQuery query = PG_GETARG_TSQUERY(2); - text *opt = (PG_NARGS() > 3 && PG_GETARG_POINTER(3)) ? PG_GETARG_TEXT_P(3) : NULL; + text *opt = (PG_NARGS() > 3 && PG_GETARG_POINTER(3)) ? PG_GETARG_TEXT_PP(3) : NULL; HeadlineParsedText prs; List *prsoptions; text *out; @@ -310,7 +310,8 @@ ts_headline_byid_opt(PG_FUNCTION_ARGS) prs.lenwords = 32; prs.words = (HeadlineWordEntry *) palloc(sizeof(HeadlineWordEntry) * prs.lenwords); - hlparsetext(cfg->cfgId, &prs, query, VARDATA(in), VARSIZE(in) - VARHDRSZ); + hlparsetext(cfg->cfgId, &prs, query, + VARDATA_ANY(in), VARSIZE_ANY_EXHDR(in)); if (opt) prsoptions = deserialize_deflist(PointerGetDatum(opt)); |
