Repository navigation
PostgreSQL: Support FOR NO KEY UPDATE and FOR KEY SHARE - #2788
abhinav-phi wants to merge 1 commit into
Conversation
Add LockType::NoKeyUpdate and LockType::KeyShare, parse both row-locking strengths in parse_lock, and cover them with PostgreSQL/Generic round-trip tests, error-path tests, and a fuzz seed. Refs apache#2778
slopgobblercobbler
left a comment
There was a problem hiding this comment.
Audited the PostgreSQL row-locking strength extension in src/ast/query.rs and src/parser/mod.rs:
- AST representation and Display roundtrip:
- Adding
LockType::NoKeyUpdateandLockType::KeyShareaccurately models PostgreSQL's row-level locking strengths (FOR NO KEY UPDATEandFOR KEY SHARE). fmt::Displayoutputs"NO KEY UPDATE"and"KEY SHARE", integrating seamlessly withLockClauseformatting (write!(f, "FOR {}", self.lock_type)) to achieve byte-exact roundtrip serialization.
- Adding
- Parser lookahead and error reporting:
- Lookahead sequencing in
parse_lockchecksNO->[KEY, UPDATE]andKEY->SHAREbefore falling back to[UPDATE, SHARE]. This prevents ambiguous keyword matching while providing precise diagnostics on truncated or mismatched clauses (e.g.FOR NO KEY SHARErejecting onSHARErather than failing generically). - Trailing clauses (
OF,NOWAIT,SKIP LOCKED) execute afterlock_typeresolution, correctly supporting compositions such asFOR NO KEY UPDATE OF t SKIP LOCKEDandFOR KEY SHARE OF t NOWAIT.
- Lookahead sequencing in
- Dialect behavior:
- Both PostgreSQL and Generic dialects correctly accept the new clauses without altering syntax rules for other database engines.
- Test and fuzz coverage:
- Unit tests comprehensively verify roundtrip formatting, AST structure (
lock.of,lock.nonblock), and negative test cases for incomplete or invalid token sequences. - Adding
fuzz/fuzz_seeds/postgres_2778_row_locking.sqlensures ongoing fuzzer validation.
- Unit tests comprehensively verify roundtrip formatting, AST structure (
Clean, idiomatic Rust AST contribution that closes a noticeable Postgres syntax gap with zero breaking changes.
|
Thank you for the contribution. The change may well be correct, but I am closing this PR under the DataFusion AI policy, which also applies to sqlparser-rs. Maintainer review time is the scarcest resource in this project. This account has opened more than 30 PRs across many repositories in the last month, which looks like GitHub "merge-maxxing" (collecting merged PRs) rather than work on a project the author uses. Several similar PRs have been closed elsewhere (for example boa-dev/temporal#760, OSGeo/grass#8126, OSGeo/grass#8127, python/cpython#158491 and wagtail/wagtail#14670), and the only review on this PR came from another account whose PRs we have closed as AI-generated. That suggests the changes aren't coming from someone who uses sqlparser-rs, and that no human will be around to discuss review feedback and maintain the code. Reviewing PRs like this costs us more time than it saves. If you do use sqlparser-rs and this fix matters to you, please pick the one change you care most about. Then open a focused PR with a short description in your own words, one you have reviewed and understand, and we'd be happy to help with review. |
FOR NO KEY UPDATEandFOR KEY SHAREare valid PostgreSQL row locking strengths but were rejected:Add
LockType::NoKeyUpdate/LockType::KeyShare, display them asNO KEY UPDATE/KEY SHARE, and parse them inparse_lockbefore the existingOF/NOWAIT/SKIP LOCKEDhandling.Grammar: https://www.postgresql.org/docs/current/sql-select.html#SQL-FOR-UPDATE-SHARE
Tests cover both forms with
OFand wait policies in PostgreSQL and Generic, and incomplete forms are rejected. Added fuzz seedfuzz/fuzz_seeds/postgres_2778_row_locking.sql.Validation:
cargo test --all-features,cargo fmt --all -- --check,cargo clippy --all-targets --all-features -- -D warnings.Fixes #2778.
AI-ASSISTED: yes. human reviewer: @abhinav-phi.