Repository navigation
PostgreSQL: Add support for CREATE STATISTICS - #3040
lei-jia-xing wants to merge 3 commits into
Conversation
LucaCappelletti94
left a comment
There was a problem hiding this comment.
Please add the fuzzer seeds, then run the differential fuzzer harness with pg_query to identify whether you are fully covering this syntax. Do ping me when that is done.
60c3676 to
032b489
Compare
|
@LucaCappelletti94 Fixed two gaps against PostgreSQL's gram.y https://github.com/postgres/postgres/blob/REL_17_7/src/backend/parser/gram.y#L4593-L4620:
fuzz test passed. Ready to review |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3040 +/- ##
==========================================
+ Coverage 83.57% 83.61% +0.03%
==========================================
Files 42 42
Lines 35719 35787 +68
Branches 35719 35787 +68
==========================================
+ Hits 29853 29922 +69
+ Misses 2425 2424 -1
Partials 3441 3441 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| "CREATE STATISTICS s ON row_number() OVER () FROM t", | ||
| "CREATE STATISTICS IF NOT EXISTS ON a FROM t", | ||
| ] { | ||
| pg_and_generic() |
There was a problem hiding this comment.
Actually assert against the expected error type so we avoid these strings failing on the wrong errors.
4295f97 to
e2792ea
Compare
|
@LucaCappelletti94 impove the code coverage & do assert like previous test |
| } else if self.dialect.supports_create_statistics() | ||
| && self.parse_keyword(Keyword::STATISTICS) | ||
| { | ||
| if has_modifier { |
There was a problem hiding this comment.
Could you please open an issue / if you have time also a PR to try and refactor these has_modifier checks into a single standardized error? I see it repeats several times.
There was a problem hiding this comment.
Ah, I see.There were already three has_modifier guards; this PR just adds a fourth. I'll open a tracking issue to consolidate them into one helper with a single standardized error, and send the refactor as a separate PR after this PR lands.
There was a problem hiding this comment.
But the guard is still opt-in: CREATE TEMP POLICY/DOMAIN/RULE parse and lose TEMP on Display. Should the tracking issue cover that structural fix too, or just the helper?
There was a problem hiding this comment.
I dug into the has_modifier guard a bit more. It's a single bool checked only in four branches (STATISTICS, USER MAPPING, FOREIGN TABLE, FOREIGN DATA WRAPPER). Other branches whose AST cannot store modifiers don't check it, and silently drop them
There was a problem hiding this comment.
for a such illegal test.sql
CREATE TEMP POLICY p ON t USING (true);
run with
cargo run --quiet --example cli -- ./test.sql --postgres
Round-trip:
'CREATE POLICY p ON t USING (true)'
It parses and remove the temp. But it can't be parsed
There was a problem hiding this comment.
Hi @LucaCappelletti94, I've opened a follow-up issue to track this.
Before opening a PR, could you please let me know if the CreateModifiers struct approach (consuming valid modifiers per target and rejecting any unconsumed ones via ensure_empty()) aligns with what you have in mind?
There was a problem hiding this comment.
Yes a struct approach is most likely the cleanest refactoring.
Closes #3035.
CREATE STATISTICS s ON a, b FROM t;now parses in the PostgreSQL and Generic dialects. The AST preserves the statistics name, kinds, expressions, and target table. Tests cover SQL round trips and a missingFROMclause.PostgreSQL syntax reference
AI assistance was used to draft the implementation and tests.