pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feedpg_plan_advice: fix empty FOREIGN_JOIN sublist validation
11+ messages / 4 participants
[nested] [flat]
Commits from this thread:
2026-08-27 8c9c2e5c09 400c810ddb Fix empty FOREIGN_JOIN sublist validation
* pg_plan_advice: fix empty FOREIGN_JOIN sublist validation
@ 2026-07-20 04:45 Chao Li <li.evan.chao@gmail.com>
0 siblings, 1 reply; 11+ messages in thread
From: Chao Li @ 2026-07-20 04:45 UTC (permalink / raw)
To: PostgreSQL-development <pgsql-hackers@lists.postgresql.org>; +Cc: Robert Haas <robertmhaas@gmail.com>
Hi,
While playing with pg_plan_advice, I noticed another small issue.
Each FOREIGN_JOIN target sublist must contain at least two relation identifiers, as the error message states:
```
evantest=# SET pg_plan_advice.advice = 'FOREIGN_JOIN((x))';
ERROR: invalid value for parameter "pg_plan_advice.advice": "FOREIGN_JOIN((x))"
DETAIL: Could not parse advice: FOREIGN_JOIN targets must contain more than one relation identifier at or near ")"
```
However, it silently accepts an empty sublist:
```
evantest=# SET pg_plan_advice.advice = 'FOREIGN_JOIN(())';
SET
```
The problem is that, the parser currently checks whether the sublist length is == 1, rather than < 2:
```
if ($$->tag == PGPA_TAG_FOREIGN_JOIN)
{
foreach_ptr(pgpa_advice_target, target, $3)
{
if (target->ttype == PGPA_TARGET_IDENTIFIER ||
list_length(target->children) == 1)
pgpa_yyerror(result, parse_error_msg_p, yyscanner,
"FOREIGN_JOIN targets must contain more than one relation identifier");
}
}
```
So the fix is simply to change == 1 to < 2. With the fix, FOREIGN_JOIN(()) is rejected:
```
evantest=# SET pg_plan_advice.advice = 'FOREIGN_JOIN(())';
ERROR: invalid value for parameter "pg_plan_advice.advice": "FOREIGN_JOIN(())"
DETAIL: Could not parse advice: FOREIGN_JOIN targets must contain more than one relation identifier at or near ")"
```
FOREIGN_JOIN() is still accepted. As documented in the opening comments of syntax.sql, empty target lists are allowed for most advice tags, except JOIN_ORDER:
```
-- An empty string is allowed. Empty target lists are allowed for most advice
-- tags, but not for JOIN_ORDER. "Supplied Plan Advice" should be omitted in
-- text format when there is no actual advice, but not in non-text format.
```
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: pg_plan_advice: fix empty FOREIGN_JOIN sublist validation
@ 2026-07-21 05:00 Chao Li <li.evan.chao@gmail.com>
parent: Chao Li <li.evan.chao@gmail.com>
0 siblings, 2 replies; 11+ messages in thread
From: Chao Li @ 2026-07-21 05:00 UTC (permalink / raw)
To: PostgreSQL-development <pgsql-hackers@lists.postgresql.org>; +Cc: Robert Haas <robertmhaas@gmail.com>
> On Jul 20, 2026, at 12:45, Chao Li <li.evan.chao@gmail.com> wrote:
>
> Hi,
>
> While playing with pg_plan_advice, I noticed another small issue.
>
> Each FOREIGN_JOIN target sublist must contain at least two relation identifiers, as the error message states:
> ```
> evantest=# SET pg_plan_advice.advice = 'FOREIGN_JOIN((x))';
> ERROR: invalid value for parameter "pg_plan_advice.advice": "FOREIGN_JOIN((x))"
> DETAIL: Could not parse advice: FOREIGN_JOIN targets must contain more than one relation identifier at or near ")"
> ```
>
> However, it silently accepts an empty sublist:
> ```
> evantest=# SET pg_plan_advice.advice = 'FOREIGN_JOIN(())';
> SET
> ```
>
> The problem is that, the parser currently checks whether the sublist length is == 1, rather than < 2:
> ```
> if ($$->tag == PGPA_TAG_FOREIGN_JOIN)
> {
> foreach_ptr(pgpa_advice_target, target, $3)
> {
> if (target->ttype == PGPA_TARGET_IDENTIFIER ||
> list_length(target->children) == 1)
> pgpa_yyerror(result, parse_error_msg_p, yyscanner,
> "FOREIGN_JOIN targets must contain more than one relation identifier");
> }
> }
> ```
>
> So the fix is simply to change == 1 to < 2. With the fix, FOREIGN_JOIN(()) is rejected:
> ```
> evantest=# SET pg_plan_advice.advice = 'FOREIGN_JOIN(())';
> ERROR: invalid value for parameter "pg_plan_advice.advice": "FOREIGN_JOIN(())"
> DETAIL: Could not parse advice: FOREIGN_JOIN targets must contain more than one relation identifier at or near ")"
> ```
>
> FOREIGN_JOIN() is still accepted. As documented in the opening comments of syntax.sql, empty target lists are allowed for most advice tags, except JOIN_ORDER:
> ```
> -- An empty string is allowed. Empty target lists are allowed for most advice
> -- tags, but not for JOIN_ORDER. "Supplied Plan Advice" should be omitted in
> -- text format when there is no actual advice, but not in non-text format.
> ```
OOPS! Missed the attachment.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
Attachments:
v1-0001-Fix-empty-FOREIGN_JOIN-sublist-validation.patch (application/octet-stream, 2.9K) download
From 4a0e610157b0d7c6885339d9e64ff19cde14a862 Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Mon, 20 Jul 2026 12:40:20 +0800
Subject: [PATCH v1] Fix empty FOREIGN_JOIN sublist validation
FOREIGN_JOIN target sublists must contain at least two relation identifiers.
However, the parser checked only for sublists with exactly one identifier, so
FOREIGN_JOIN(()) was accepted.
Reject sublists with fewer than two relation identifiers, and add regression
coverage.
Author: Chao Li <lic@highgo.com>
---
contrib/pg_plan_advice/expected/syntax.out | 3 +++
contrib/pg_plan_advice/pgpa_parser.y | 2 +-
contrib/pg_plan_advice/sql/syntax.sql | 1 +
3 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/contrib/pg_plan_advice/expected/syntax.out b/contrib/pg_plan_advice/expected/syntax.out
index 3b57bb2bf57..d53d9598634 100644
--- a/contrib/pg_plan_advice/expected/syntax.out
+++ b/contrib/pg_plan_advice/expected/syntax.out
@@ -209,6 +209,9 @@ DETAIL: Could not parse advice: FOREIGN_JOIN targets must contain more than one
SET pg_plan_advice.advice = 'FOREIGN_JOIN((a))';
ERROR: invalid value for parameter "pg_plan_advice.advice": "FOREIGN_JOIN((a))"
DETAIL: Could not parse advice: FOREIGN_JOIN targets must contain more than one relation identifier at or near ")"
+SET pg_plan_advice.advice = 'FOREIGN_JOIN(())';
+ERROR: invalid value for parameter "pg_plan_advice.advice": "FOREIGN_JOIN(())"
+DETAIL: Could not parse advice: FOREIGN_JOIN targets must contain more than one relation identifier at or near ")"
-- Tag keywords used as alias names work fine, because the 'identifier'
-- nonterminal accepts all token types.
SET pg_plan_advice.advice = 'SEQ_SCAN(hash_join)';
diff --git a/contrib/pg_plan_advice/pgpa_parser.y b/contrib/pg_plan_advice/pgpa_parser.y
index 5811a6e5e56..295f16ad064 100644
--- a/contrib/pg_plan_advice/pgpa_parser.y
+++ b/contrib/pg_plan_advice/pgpa_parser.y
@@ -135,7 +135,7 @@ advice_item: TOK_TAG_JOIN_ORDER '(' join_order_target_list ')'
foreach_ptr(pgpa_advice_target, target, $3)
{
if (target->ttype == PGPA_TARGET_IDENTIFIER ||
- list_length(target->children) == 1)
+ list_length(target->children) < 2)
pgpa_yyerror(result, parse_error_msg_p, yyscanner,
"FOREIGN_JOIN targets must contain more than one relation identifier");
}
diff --git a/contrib/pg_plan_advice/sql/syntax.sql b/contrib/pg_plan_advice/sql/syntax.sql
index 5af7607db42..de11e8c6fc2 100644
--- a/contrib/pg_plan_advice/sql/syntax.sql
+++ b/contrib/pg_plan_advice/sql/syntax.sql
@@ -73,6 +73,7 @@ SET pg_plan_advice.advice = '/*/* stuff */*/';
-- Foreign join requires multiple relation identifiers.
SET pg_plan_advice.advice = 'FOREIGN_JOIN(a)';
SET pg_plan_advice.advice = 'FOREIGN_JOIN((a))';
+SET pg_plan_advice.advice = 'FOREIGN_JOIN(())';
-- Tag keywords used as alias names work fine, because the 'identifier'
-- nonterminal accepts all token types.
--
2.50.1 (Apple Git-155)
=
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: pg_plan_advice: fix empty FOREIGN_JOIN sublist validation
@ 2026-08-20 15:02 Pierre Forstmann <pierre.forstmann@gmail.com>
parent: Chao Li <li.evan.chao@gmail.com>
1 sibling, 0 replies; 11+ messages in thread
From: Pierre Forstmann @ 2026-08-20 15:02 UTC (permalink / raw)
To: pgsql-hackers@lists.postgresql.org; +Cc: Chao Li <li.evan.chao@gmail.com>
The following review has been posted through the commitfest application:
make installcheck-world: tested, passed
Implements feature: tested, passed
Spec compliant: not tested
Documentation: not tested
Hello,
I have reviewed this patch and it looks good to me.
I can reproduce the issue in master branch and applying the patch in a specific branch has fixed the issue: new test case looks also good to me.
I don't think it is needed to check SQL compliance or to update documentation.
Regards
Pierre Forstmann.
The new status of this patch is: Ready for Committer
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: pg_plan_advice: fix empty FOREIGN_JOIN sublist validation
@ 2026-08-25 19:55 Nathan Bossart <nathandbossart@gmail.com>
parent: Chao Li <li.evan.chao@gmail.com>
1 sibling, 1 reply; 11+ messages in thread
From: Nathan Bossart @ 2026-08-25 19:55 UTC (permalink / raw)
To: Chao Li <li.evan.chao@gmail.com>; +Cc: PostgreSQL-development <pgsql-hackers@lists.postgresql.org>; Robert Haas <robertmhaas@gmail.com>
Does this one deserve a mention on the open items wiki [0]?
[0] https://wiki.postgresql.org/wiki/PostgreSQL_19_Open_Items
--
nathan
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: pg_plan_advice: fix empty FOREIGN_JOIN sublist validation
@ 2026-08-26 01:12 Chao Li <li.evan.chao@gmail.com>
parent: Nathan Bossart <nathandbossart@gmail.com>
0 siblings, 1 reply; 11+ messages in thread
From: Chao Li @ 2026-08-26 01:12 UTC (permalink / raw)
To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: PostgreSQL-development <pgsql-hackers@lists.postgresql.org>; Robert Haas <robertmhaas@gmail.com>
> On Aug 26, 2026, at 03:55, Nathan Bossart <nathandbossart@gmail.com> wrote:
>
> Does this one deserve a mention on the open items wiki [0]?
>
> [0] https://wiki.postgresql.org/wiki/PostgreSQL_19_Open_Items
>
> --
> nathan
Hi Nathan,
Thanks for noticing this patch and for asking.
This issue is 19-only, and it is a bug, so I think it meets the criteria. I didn’t add it because I thought it was a tiny bug with a one-line fix and assumed it might be processed soon. Given that it has been left open for a long time, let me add it for better tracking.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: pg_plan_advice: fix empty FOREIGN_JOIN sublist validation
@ 2026-08-26 22:10 Nathan Bossart <nathandbossart@gmail.com>
parent: Chao Li <li.evan.chao@gmail.com>
0 siblings, 1 reply; 11+ messages in thread
From: Nathan Bossart @ 2026-08-26 22:10 UTC (permalink / raw)
To: Chao Li <li.evan.chao@gmail.com>; +Cc: PostgreSQL-development <pgsql-hackers@lists.postgresql.org>; Robert Haas <robertmhaas@gmail.com>
On Wed, Aug 26, 2026 at 09:12:42AM +0800, Chao Li wrote:
>> On Aug 26, 2026, at 03:55, Nathan Bossart <nathandbossart@gmail.com> wrote:
>> Does this one deserve a mention on the open items wiki [0]?
>
> Thanks for noticing this patch and for asking.
>
> This issue is 19-only, and it is a bug, so I think it meets the criteria.
> I didn’t add it because I thought it was a tiny bug with a one-line fix
> and assumed it might be processed soon. Given that it has been left open
> for a long time, let me add it for better tracking.
Robert, what do you think about the proposed patch?
--
nathan
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: pg_plan_advice: fix empty FOREIGN_JOIN sublist validation
@ 2026-08-27 15:53 Robert Haas <robertmhaas@gmail.com>
parent: Nathan Bossart <nathandbossart@gmail.com>
0 siblings, 1 reply; 11+ messages in thread
From: Robert Haas @ 2026-08-27 15:53 UTC (permalink / raw)
To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: Chao Li <li.evan.chao@gmail.com>; PostgreSQL-development <pgsql-hackers@lists.postgresql.org>
On Wed, Aug 26, 2026 at 6:11 PM Nathan Bossart <nathandbossart@gmail.com> wrote:
> Robert, what do you think about the proposed patch?
Looks fine to me. If you feel like taking care of it, awesome,
otherwise I can do it.
--
Robert Haas
EDB: http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: pg_plan_advice: fix empty FOREIGN_JOIN sublist validation
@ 2026-08-27 15:56 Nathan Bossart <nathandbossart@gmail.com>
parent: Robert Haas <robertmhaas@gmail.com>
0 siblings, 1 reply; 11+ messages in thread
From: Nathan Bossart @ 2026-08-27 15:56 UTC (permalink / raw)
To: Robert Haas <robertmhaas@gmail.com>; +Cc: Chao Li <li.evan.chao@gmail.com>; PostgreSQL-development <pgsql-hackers@lists.postgresql.org>
On Thu, Aug 27, 2026 at 11:53:46AM -0400, Robert Haas wrote:
> On Wed, Aug 26, 2026 at 6:11 PM Nathan Bossart <nathandbossart@gmail.com> wrote:
>> Robert, what do you think about the proposed patch?
>
> Looks fine to me. If you feel like taking care of it, awesome,
> otherwise I can do it.
I would be grateful if you could take it.
--
nathan
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: pg_plan_advice: fix empty FOREIGN_JOIN sublist validation
@ 2026-08-27 20:40 Robert Haas <robertmhaas@gmail.com>
parent: Nathan Bossart <nathandbossart@gmail.com>
0 siblings, 1 reply; 11+ messages in thread
From: Robert Haas @ 2026-08-27 20:40 UTC (permalink / raw)
To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: Chao Li <li.evan.chao@gmail.com>; PostgreSQL-development <pgsql-hackers@lists.postgresql.org>
On Thu, Aug 27, 2026 at 11:56 AM Nathan Bossart
<nathandbossart@gmail.com> wrote:
> I would be grateful if you could take it.
Sure thing, done, and I marked the open item resolved.
--
Robert Haas
EDB: http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: pg_plan_advice: fix empty FOREIGN_JOIN sublist validation
@ 2026-08-28 02:52 Chao Li <li.evan.chao@gmail.com>
parent: Robert Haas <robertmhaas@gmail.com>
0 siblings, 1 reply; 11+ messages in thread
From: Chao Li @ 2026-08-28 02:52 UTC (permalink / raw)
To: Robert Haas <robertmhaas@gmail.com>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; PostgreSQL-development <pgsql-hackers@lists.postgresql.org>
> On Aug 28, 2026, at 04:40, Robert Haas <robertmhaas@gmail.com> wrote:
>
> On Thu, Aug 27, 2026 at 11:56 AM Nathan Bossart
> <nathandbossart@gmail.com> wrote:
>> I would be grateful if you could take it.
>
> Sure thing, done, and I marked the open item resolved.
>
> --
> Robert Haas
> EDB: http://www.enterprisedb.com
Thanks for taking care of this patch.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
^ permalink raw reply [nested|flat] 11+ messages in thread
* Re: pg_plan_advice: fix empty FOREIGN_JOIN sublist validation
@ 2026-08-28 12:28 Robert Haas <robertmhaas@gmail.com>
parent: Chao Li <li.evan.chao@gmail.com>
0 siblings, 0 replies; 11+ messages in thread
From: Robert Haas @ 2026-08-28 12:28 UTC (permalink / raw)
To: Chao Li <li.evan.chao@gmail.com>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; PostgreSQL-development <pgsql-hackers@lists.postgresql.org>
On Thu, Aug 27, 2026 at 10:53 PM Chao Li <li.evan.chao@gmail.com> wrote:
> Thanks for taking care of this patch.
Likewise, thanks for the report.
--
Robert Haas
EDB: http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 11+ messages in thread
end of thread, other threads:[~2026-08-28 12:28 UTC | newest]
Thread overview: 11+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-07-20 04:45 pg_plan_advice: fix empty FOREIGN_JOIN sublist validation Chao Li <li.evan.chao@gmail.com>
2026-07-21 05:00 ` Chao Li <li.evan.chao@gmail.com>
2026-08-20 15:02 ` Pierre Forstmann <pierre.forstmann@gmail.com>
2026-08-25 19:55 ` Nathan Bossart <nathandbossart@gmail.com>
2026-08-26 01:12 ` Chao Li <li.evan.chao@gmail.com>
2026-08-26 22:10 ` Nathan Bossart <nathandbossart@gmail.com>
2026-08-27 15:53 ` Robert Haas <robertmhaas@gmail.com>
2026-08-27 15:56 ` Nathan Bossart <nathandbossart@gmail.com>
2026-08-27 20:40 ` Robert Haas <robertmhaas@gmail.com>
2026-08-28 02:52 ` Chao Li <li.evan.chao@gmail.com>
2026-08-28 12:28 ` Robert Haas <robertmhaas@gmail.com>
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