From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Avoid rescanning prefixes when choosing a dollar-quote delimiter
Date: Thu, 19 Nov 2026 11:43:37 +0000
Message-ID: <E1xU0YC-00000000NLl-1RAy@gemulon.postgresql.org> (raw)
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@highgo.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(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: heikki.linnakangas@iki.fi
Subject: Re: pgsql: Avoid rescanning prefixes when choosing a dollar-quote delimiter
In-Reply-To: <E1xU0YC-00000000NLl-1RAy@gemulon.postgresql.org>
References: <E1xU0YC-00000000NLl-1RAy@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox