Re: pg_plan_advice: fix parsing underscore in numbers

From: Daniel Gustafsson <daniel(at)yesql(dot)se>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: Re: pg_plan_advice: fix parsing underscore in numbers
Date: 2026-07-17 10:16:16
Message-ID: 47C78B8C-AE64-4CA5-A0C5-FFA5FF782C37@yesql.se
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On 17 Jul 2026, at 11:22, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:

> PG supports underscores between digits; for example, 1_0 is parsed as 10:
> ```
> evantest=# SELECT 1_0;
> ?column?
> ----------
> 10
> (1 row)
> ```
>
> pg_plan_advice seems to intend to support the same syntax, based on pgpa_scanner.l:

Agreed.

> The attached patch fixes this by using pg_strtoint32_safe() in the same way as the core scanner.

Yes, but I think we need a bit more since we otherwise accept this case:

postgres=# set pg_plan_advice.advice = 'SEQ_SCAN(x#1_0_)';
SET
postgres=# explain (plan_advice) select 1;
QUERY PLAN
------------------------------------------
Result (cost=0.00..0.01 rows=1 width=4)
Supplied Plan Advice:
SEQ_SCAN(x#10) /* not matched */
SEQ_SCAN(_) /* not matched */
Generated Plan Advice:
NO_GATHER("*RESULT*")
(6 rows)

If we also match on integerjunk like in the attached v2 we instead get the
below which I think is more correct:

postgres=# set pg_plan_advice.advice = 'SEQ_SCAN(x#1_0_)';
ERROR: invalid value for parameter "pg_plan_advice.advice": "SEQ_SCAN(x#1_0_)"
DETAIL: Could not parse advice: trailing junk after numeric literal at or near "1_0_"

AFAICT this shouldn't break parsing for any legitimate cases, but I've only had
a quick look (the tests still pass though).

--
Daniel Gustafsson

Attachment Content-Type Size
v2-0001-Fix-parsing-of-underscores-in-pg_plan_advice-occu.patch application/octet-stream 3.3 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Atsushi Ogawa 2026-07-17 10:23:08 Re: [PATCH] Use Boyer-Moore-Horspool for simple LIKE contains patterns
Previous Message Fujii Masao 2026-07-17 10:00:21 Re: doc: clarify wal_sender_shutdown_timeout behavior for small values