pg_plan_advice: fix empty FOREIGN_JOIN sublist validation
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/
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/
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
Does this one deserve a mention on the open items wiki [0]https://wiki.postgresql.org/wiki/PostgreSQL_19_Open_Items?
[0]: https://wiki.postgresql.org/wiki/PostgreSQL_19_Open_Items
--
nathan
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/
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
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
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
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
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/
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