Skip to content

feat: side-effect SELECT #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: attempt to send to all shards
  • Loading branch information
denysvitali committed May 12, 2025
commit fbeb81fc59272b67b3336c36637e8832094b12a1
10 changes: 4 additions & 6 deletions pgdog/src/frontend/router/parser/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@ impl QueryParser {
debug!(
"Query contains side-effect function, routing to a single primary shard."
);
return Ok(Command::Query(Route::write(Some(
round_robin::next() % cluster.shards().len(),
))));
return Ok(Command::Query(Route::write(None)));
}
// `SELECT NOW()`, `SELECT 1`, etc.
else if ast.tables().is_empty() {
Expand Down Expand Up @@ -1143,21 +1141,21 @@ mod test {
#[test]
fn test_lock() {
let route = query!("SELECT pg_advisory_lock('test')::bool");
assert!(matches!(route.shard(), Shard::Direct(_)));
assert!(matches!(route.shard(), Shard::All));
assert!(route.is_write());
}

#[test]
fn test_lock_param() {
let route = query!("SELECT pg_advisory_lock($1)");
assert!(matches!(route.shard(), Shard::Direct(_)));
assert!(matches!(route.shard(), Shard::All));
assert!(route.is_write());
}

#[test]
fn test_lock_2() {
let route = query!("SELECT pg_advisory_lock('test')");
assert!(matches!(route.shard(), Shard::Direct(_)));
assert!(matches!(route.shard(), Shard::All));
assert!(route.is_write());
}

Expand Down