Skip to content

Commit

Permalink
docs: add caveat about unpaged SELECTs' drawbacks
Browse files Browse the repository at this point in the history
We shouldn't encourage users to perform unpaged SELECTs. Normally,
SELECTs should be paged, therefore caveat about that is added in two
relevant places in docs.
  • Loading branch information
wprzytula committed Aug 27, 2024
1 parent 112ed5d commit 5b2ea32
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
15 changes: 15 additions & 0 deletions docs/source/queries/result.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
`Session::query_unpaged`, `Session::query_single_page`, `Session::execute_unpaged` and `Session::execute_single_page`
return a `QueryResult` with rows represented as `Option<Vec<Row>>`.

> ***Note***\
> Using unpaged queries for SELECTs is discouraged in general.
> Query results may be so big that it is not preferable to fetch them all at once.
> However, `query_unpaged` will return all results in one, possibly giant, piece
> (unless a timeout occurs due to high load incurred by the cluster).
> This:
> - increases latency,
> - has large memory footprint,
> - puts high load on the cluster,
> - is more likely to time out (because big work takes more time than little work,
> and returning one large piece of data is more work than returning one chunk of data).
> To sum up, for SELECTs that may return return a lot of data prefer paged queries,
> e.g. with `Session::query_iter()` (see [Paged queries](paged.md)).
### Basic representation
`Row` is a basic representation of a received row. It can be used by itself, but it's a bit awkward to use:
```rust
Expand Down
15 changes: 14 additions & 1 deletion docs/source/queries/simple.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ session
> ***Warning***\
> Don't use simple query to receive large amounts of data.\
> By default the query is unpaged and might cause heavy load on the cluster.\
> In such cases set a page size and use [paged query](paged.md) instead.\
> In such cases use [paged query](paged.md) instead.\
>
> `query_unpaged` will return all results in one, possibly giant, piece
> (unless a timeout occurs due to high load incurred by the cluster).
Expand Down Expand Up @@ -84,6 +84,19 @@ Each row can be parsed as a tuple of rust types using `rows_typed`:
# async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
use scylla::IntoTypedRows;

// NOTE: using unpaged queries for SELECTs is discouraged in general.
// Query results may be so big that it is not preferable to fetch them all at once.
// However, `query_unpaged` will return all results in one, possibly giant, piece
// (unless a timeout occurs due to high load incurred by the cluster).
// This:
// - increases latency,
// - has large memory footprint,
// - puts high load on the cluster,
// - is more likely to time out (because big work takes more time than little work,
// and returning one large piece of data is more work than returning one chunk of data).
// To sum up, for SELECTs that may return return a lot of data prefer paged queries,
// e.g. with `Session::query_iter()`.

// Query rows from the table and print them
let result = session.query_unpaged("SELECT a FROM ks.tab", &[]).await?;
let mut iter = result.rows_typed::<(i32,)>()?;
Expand Down

0 comments on commit 5b2ea32

Please sign in to comment.