Statement Types
Unprepared Statements (Query)
Unprepared statements are simple CQL query strings that are sent directly to the database. They are easy to use but have performance limitations compared to prepared statements.- One-time queries
- Schema-altering statements (CREATE, ALTER, DROP)
- Administrative commands
- Queries without bind values
Prepared Statements
Prepared statements are pre-compiled on the server and offer significant performance benefits. They are the recommended choice for queries that will be executed multiple times.- Performance: Database parses the query only once
- Type safety: Bound values are validated against server metadata
- Token-aware routing: Driver can compute partition keys for optimal routing
- Result optimization: Cached metadata can skip result metadata transmission
Batch Statements
Batch statements allow you to execute multiple statements (prepared or unprepared) atomically in a single request.Execution Methods
The driver provides different execution methods depending on whether you’re using unprepared or prepared statements:| Operation | Unprepared Statement | Prepared Statement |
|---|---|---|
| Single unpaged request | query_unpaged() | execute_unpaged() |
| Single page with manual paging | query_single_page() | execute_single_page() |
| Automatic paging (iterator) | query_iter() | execute_iter() |
| Batch execution | batch() (supports both) |
Common Configuration
All statement types support common configuration options:For queries with bind values, always prefer prepared statements. Using
query_unpaged() or query_iter() with values requires the driver to prepare the statement internally, resulting in 2 round trips instead of 1.Next Steps
Unprepared Statements
Learn about executing unprepared CQL queries
Prepared Statements
Optimize performance with prepared statements
Batch Statements
Execute multiple statements atomically
Paged Queries
Handle large result sets efficiently
