Re: pg_plan_advice: fix parsing underscore in numbers

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Daniel Gustafsson <daniel(at)yesql(dot)se>
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 20:53:09
Message-ID: 4CC6F6E9-3D19-4765-85D6-F9DA2075877C@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Jul 17, 2026, at 18:16, Daniel Gustafsson <daniel(at)yesql(dot)se> wrote:
>
>
>> 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
>
> <v2-0001-Fix-parsing-of-underscores-in-pg_plan_advice-occu.patch>

Agreed, v2 is more correct. I missed the integerjunk part.

I also added a test case for 1_0_. There is already a syntax-error section in the test script, so I added the case there.

PFA v3, which only adds this test case.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2026-07-17 20:58:09 Re: index prefetching
Previous Message Melanie Plageman 2026-07-17 20:51:46 Re: Why clearing the VM doesn't require registering vm buffer in wal record