| From: | Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Avoid rescanning prefixes when choosing a dollar-quote delimiter |
| Date: | 2026-11-19 11:43:37 |
| Message-ID: | E1xU0YC-00000000NLl-1RAy@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
Avoid rescanning prefixes when choosing a dollar-quote delimiter
appendStringLiteralDQ() and pg_get_functiondef() pick a dollar-quote
delimiter by repeatedly extending a candidate until it no longer
occurs in the string being quoted, restarting the strstr() search from
the beginning each time. Since each candidate extends the previous
one, it cannot match before that position, so we can resume the search
at the previous match.
It's easy to show a performance benefit with a specially-crafted
function body. In functions that occur in the real world, this won't
make any difference, but it's a very straightforward optimization so
might as well do it.
Author: Chao Li <lic(at)highgo(dot)com>
Discussion: https://www.postgresql.org/message-id/6E01C9AD-0446-4C2C-BA28-375FC4DA800A@gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/514bfe2c6dffba2d7a6b7ea7cf029e04a7c41563
Modified Files
--------------
src/backend/utils/adt/ruleutils.c | 8 ++++++--
src/fe_utils/string_utils.c | 7 ++++++-
2 files changed, 12 insertions(+), 3 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | Heikki Linnakangas | 2026-11-19 10:37:02 | pgsql: Fix incorrect pointer increment in pgtypes_defmt_scan() |