Re: Avoid rescanning prefixes in appendStringLiteralDQ()

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Avoid rescanning prefixes in appendStringLiteralDQ()
Date: 2026-11-19 11:43:41
Message-ID: 2584e9d9-5e5b-4ff7-a773-1f38037b69af@iki.fi
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 19/11/2026 08:32, Chao Li wrote:
> While reviewing another patch, I spotted a trivial optimization in
> appendStringLiteralDQ().
>
> Looking at the code:
> ```
> /*
> * Make sure we choose a delimiter which (without the trailing $) is not
> * present in the string being quoted. We don't check with the trailing $
> * because a string ending in $foo must not be quoted with $foo$.
> */
> while (strstr(str, delimBuf->data) != NULL)
> {
> appendPQExpBufferChar(delimBuf, suffixes[nextchar++]);
> nextchar %= sizeof(suffixes) - 1;
> }
> ```
>
> The while loop always searches from the beginning of str. But
> actually, a later search can just start from the previously returned
> pointer. This function is currently only used by pg_dump. I don’t
> expect a noticeable performance improvement in typical use, but it
> seems to me to be a tiny but harmless optimization.

Makes sense. There's a similar loop in pg_get_functiondef(), too. I
applied the same optimization there, and pushed.

- Heikki

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bertrand Drouvot 2026-11-19 11:59:59 Re: Report buffer access strategies in EXPLAIN
Previous Message Nazir Bilal Yavuz 2026-11-19 10:59:22 Re: Switching XLog source from archive to streaming when primary available