Commit 7ced34d
authored
fix: support PostgreSQL composite row expansion (function()).* (#2463)
PostgreSQL expands a composite-returning function call into its columns with
(function_call).*, e.g. SELECT (json_populate_record(NULL::users, data)).*
FROM staging_users. JSQLParser rejected the trailing .* .
Composite row expansion was implemented in #2207 but afterwards disabled,
because the speculative syntactic LOOKAHEAD(FunctionAllColumns()) at the
PrimaryExpression entry caused a severe regression (393 ms/op vs ~86 ms/op).
The AST node, deparser, validator and all visitors stayed in place; only the
grammar call site was commented out.
Re-enable the feature without the speculative lookahead: after a
ParenthesedExpressionList wrapping a single Function is parsed, a bounded
semantic follower check (isFunctionAllColumnsAhead) peeks .* and wraps the
result into FunctionAllColumns. The check first compares the next two tokens
and only then unwraps the already-parsed expression, so the common path (a
parenthesised expression not followed by .*) bails out in two comparisons
without any speculative production or backtracking. TablesNamesFinder now
descends into the wrapped function so column/table references inside the
expansion are not lost.
Scope: only (function_call).* is supported; arbitrary (non-function
expression).* remains unsupported and fails cleanly as before. Redundant
surrounding parentheses are unwrapped to the inner function.
Performance (gradle jmh, parseSQLStatements on performance.sql, version=latest,
10 forks x 10 iterations, 100 samples, dedicated 32-core host):
master (disabled): 3.632 +/- 0.020 ms/op
this change: 3.639 +/- 0.023 ms/op
The +0.19% delta lies within the confidence intervals and is far from the
393 ms/op toll that motivated disabling the feature.
Testing: CompositeRowExpansionTest covers the issue case, simple and no-arg
functions, the INSERT...SELECT use case, multiple surrounding parentheses,
and negative cases (no trailing .*, RowGet expression, non-function
expression). The positive tests fail on master and pass with this change.
Fixes #2412
Signed-off-by: 付典 <fudianchn@gmail.com>1 parent b5adb60 commit 7ced34d
3 files changed
Lines changed: 156 additions & 1 deletion
File tree
- src
- main
- java/net/sf/jsqlparser/util
- jjtree/net/sf/jsqlparser/parser
- test/java/net/sf/jsqlparser/statement/select
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
925 | 925 | | |
926 | 926 | | |
927 | 927 | | |
928 | | - | |
| 928 | + | |
929 | 929 | | |
930 | 930 | | |
931 | 931 | | |
| |||
Lines changed: 58 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
594 | 594 | | |
595 | 595 | | |
596 | 596 | | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
597 | 646 | | |
598 | 647 | | |
599 | 648 | | |
| |||
7903 | 7952 | | |
7904 | 7953 | | |
7905 | 7954 | | |
| 7955 | + | |
| 7956 | + | |
| 7957 | + | |
| 7958 | + | |
| 7959 | + | |
| 7960 | + | |
| 7961 | + | |
| 7962 | + | |
| 7963 | + | |
7906 | 7964 | | |
7907 | 7965 | | |
7908 | 7966 | | |
| |||
Lines changed: 97 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
0 commit comments