Skip to content

Commit fc6e7cb

Browse files
authored
perf(parser): short-circuit _parse_pivots when next token isn't PIVOT/UNPIVOT (#7557)
_parse_pivots runs once per Join and most table refs, but always builds an iter+list even when the next token can never start a PIVOT clause. Guard on the token type up front so the common no-pivot path is a single check. Small but consistent win under mypyc (~1-3% on join-heavy queries like many_joins). No behavior change.
1 parent ee69e0a commit fc6e7cb

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

sqlglot/parser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5010,6 +5010,8 @@ def _parse_table_sample(self, as_modifier: bool = False) -> exp.TableSample | No
50105010
)
50115011

50125012
def _parse_pivots(self) -> list[exp.Pivot] | None:
5013+
if self._curr.token_type not in (TokenType.PIVOT, TokenType.UNPIVOT):
5014+
return None
50135015
return list(iter(self._parse_pivot, None)) or None
50145016

50155017
def _parse_joins(self) -> t.Iterator[exp.Join]:

0 commit comments

Comments
 (0)