From 4d0e994eed83c845a05da6e9a417b4efec67efaf Mon Sep 17 00:00:00 2001 From: Stephen Frost Date: Tue, 2 Apr 2019 12:35:32 -0400 Subject: Add support for partial TOAST decompression When asked for a slice of a TOAST entry, decompress enough to return the slice instead of decompressing the entire object. For use cases where the slice is at, or near, the beginning of the entry, this avoids a lot of unnecessary decompression work. This changes the signature of pglz_decompress() by adding a boolean to indicate if it's ok for the call to finish before consuming all of the source or destination buffers. Author: Paul Ramsey Reviewed-By: Rafia Sabih, Darafei Praliaskouski, Regina Obe Discussion: https://postgr.es/m/CACowWR07EDm7Y4m2kbhN_jnys%3DBBf9A6768RyQdKm_%3DNpkcaWg%40mail.gmail.com --- src/backend/utils/adt/varlena.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/backend/utils/adt/varlena.c') diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index 68a6e49aeb4..f82ce92ce3d 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -1894,7 +1894,7 @@ text_starts_with(PG_FUNCTION_ARGS) result = false; else { - text *targ1 = DatumGetTextPP(arg1); + text *targ1 = text_substring(arg1, 1, len2, false); text *targ2 = DatumGetTextPP(arg2); result = (memcmp(VARDATA_ANY(targ1), VARDATA_ANY(targ2), @@ -5346,17 +5346,21 @@ text_concat_ws(PG_FUNCTION_ARGS) Datum text_left(PG_FUNCTION_ARGS) { - text *str = PG_GETARG_TEXT_PP(0); - const char *p = VARDATA_ANY(str); - int len = VARSIZE_ANY_EXHDR(str); - int n = PG_GETARG_INT32(1); - int rlen; + int n = PG_GETARG_INT32(1); if (n < 0) - n = pg_mbstrlen_with_len(p, len) + n; - rlen = pg_mbcharcliplen(p, len, n); + { + text *str = PG_GETARG_TEXT_PP(0); + const char *p = VARDATA_ANY(str); + int len = VARSIZE_ANY_EXHDR(str); + int rlen; - PG_RETURN_TEXT_P(cstring_to_text_with_len(p, rlen)); + n = pg_mbstrlen_with_len(p, len) + n; + rlen = pg_mbcharcliplen(p, len, n); + PG_RETURN_TEXT_P(cstring_to_text_with_len(p, rlen)); + } + else + PG_RETURN_TEXT_P(text_substring(PG_GETARG_DATUM(0), 1, n, false)); } /* -- cgit v1.2.3