Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
35 changes: 35 additions & 0 deletions integration/rust/tests/integration/limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,41 @@ use crate::setup::admin_sqlx;
use crate::setup::connections_sqlx;
use sqlx::{Executor, Row, postgres::PgPool};

#[tokio::test]
async fn limit_without_order_by_across_shards() -> Result<(), Box<dyn std::error::Error>> {
let pools = connections_sqlx().await;
let mut transaction = pools[1].begin().await?;

transaction.execute("TRUNCATE sharded").await?;
// Guarantee five rows on each shard so a per-shard LIMIT exceeds the global limit.
for shard in [0, 1] {
transaction
.execute(
format!(
"/* pgdog_shard: {shard} */ INSERT INTO sharded (id) VALUES (1), (2), (3), (4), (5)"
)
.as_str(),
)
.await?;
}

for (limit, expected) in [(5_i64, 5), (0, 0), (100, 10)] {
let rows = sqlx::raw_sql(&format!("SELECT id FROM sharded LIMIT {limit}"))
.fetch_all(&mut *transaction)
.await?;
assert_eq!(rows.len(), expected, "simple protocol LIMIT {limit}");

let rows = sqlx::query("SELECT id FROM sharded LIMIT $1")
.bind(limit)
.fetch_all(&mut *transaction)
.await?;
assert_eq!(rows.len(), expected, "extended protocol LIMIT {limit}");
}

transaction.rollback().await?;
Ok(())
}

#[tokio::test]
async fn limit_across_shards() -> Result<(), Box<dyn std::error::Error>> {
let sharded = connections_sqlx().await.get(1).cloned().unwrap();
Expand Down
3 changes: 2 additions & 1 deletion pgdog/src/frontend/router/parser/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ impl Route {
!self.order_by().is_empty()
|| !self.aggregate().is_empty()
|| self.distinct().is_some()
|| self.limit().limit.is_some()
|| self.limit().offset.is_some()
}

Expand Down Expand Up @@ -741,7 +742,7 @@ mod test {
},
None,
);
assert!(!route.requires_post_processing());
assert!(route.requires_post_processing());
}

#[test]
Expand Down
Loading