pg_plan_advice: fix empty FOREIGN_JOIN sublist validation

Поиск
Список
Период
Сортировка
Искать

pg_plan_advice: fix empty FOREIGN_JOIN sublist validation

От:
Chao Li <li.evan.chao@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/






Re: pg_plan_advice: fix empty FOREIGN_JOIN sublist validation

От:
Chao Li <li.evan.chao@gmail.com>
Дата:
Вложения:


> On Jul 20, 2026, at 12:45, Chao Li  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/




Re: pg_plan_advice: fix empty FOREIGN_JOIN sublist validation

От:
Pierre Forstmann <pierre.forstmann@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

Re: pg_plan_advice: fix empty FOREIGN_JOIN sublist validation

От:
Nathan Bossart <nathandbossart@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


Re: pg_plan_advice: fix empty FOREIGN_JOIN sublist validation

От:
Nathan Bossart <nathandbossart@gmail.com>
Дата:
On Wed, Aug 26, 2026 at 09:12:42AM +0800, Chao Li wrote:
>> On Aug 26, 2026, at 03:55, Nathan Bossart  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


FAQ