Skip to content

Commit 3cc174e

Browse files
Chao Li (Evan)hackorum
authored andcommitted
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>
1 parent 44056f6 commit 3cc174e

3 files changed

Lines changed: 5 additions & 1 deletion

File tree

contrib/pg_plan_advice/expected/syntax.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ DETAIL: Could not parse advice: FOREIGN_JOIN targets must contain more than one
209209
SET pg_plan_advice.advice = 'FOREIGN_JOIN((a))';
210210
ERROR: invalid value for parameter "pg_plan_advice.advice": "FOREIGN_JOIN((a))"
211211
DETAIL: Could not parse advice: FOREIGN_JOIN targets must contain more than one relation identifier at or near ")"
212+
SET pg_plan_advice.advice = 'FOREIGN_JOIN(())';
213+
ERROR: invalid value for parameter "pg_plan_advice.advice": "FOREIGN_JOIN(())"
214+
DETAIL: Could not parse advice: FOREIGN_JOIN targets must contain more than one relation identifier at or near ")"
212215
-- Tag keywords used as alias names work fine, because the 'identifier'
213216
-- nonterminal accepts all token types.
214217
SET pg_plan_advice.advice = 'SEQ_SCAN(hash_join)';

contrib/pg_plan_advice/pgpa_parser.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ advice_item: TOK_TAG_JOIN_ORDER '(' join_order_target_list ')'
135135
foreach_ptr(pgpa_advice_target, target, $3)
136136
{
137137
if (target->ttype == PGPA_TARGET_IDENTIFIER ||
138-
list_length(target->children) == 1)
138+
list_length(target->children) < 2)
139139
pgpa_yyerror(result, parse_error_msg_p, yyscanner,
140140
"FOREIGN_JOIN targets must contain more than one relation identifier");
141141
}

contrib/pg_plan_advice/sql/syntax.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ SET pg_plan_advice.advice = '/*/* stuff */*/';
7373
-- Foreign join requires multiple relation identifiers.
7474
SET pg_plan_advice.advice = 'FOREIGN_JOIN(a)';
7575
SET pg_plan_advice.advice = 'FOREIGN_JOIN((a))';
76+
SET pg_plan_advice.advice = 'FOREIGN_JOIN(())';
7677

7778
-- Tag keywords used as alias names work fine, because the 'identifier'
7879
-- nonterminal accepts all token types.

0 commit comments

Comments
 (0)