ScyllaDB University Live | Free Virtual Training Event
Learn more
ScyllaDB Documentation Logo Documentation
  • Deployments
    • Cloud
    • Server
  • Tools
    • ScyllaDB Manager
    • ScyllaDB Monitoring Stack
    • ScyllaDB Operator
  • Drivers
    • CQL Drivers
    • DynamoDB Drivers
  • Resources
    • ScyllaDB University
    • Community Forum
    • Tutorials
Install
Ask AI
ScyllaDB Docs ScyllaDB CPP-Rust Driver Using the Driver Batches

BatchesΒΆ

Batches can be used to group multiple mutations (UPDATE, INSERT, DELETE) together into a single statement; simple or prepared. There are three different types of batches.

  • CASS_BATCH_TYPE_LOGGED is used to make sure that multiple mutations across multiple partitions happen atomically, that is, all the included mutations will eventually succeed. However, there is a performance penalty imposed by atomicity guarantee.

  • CASS_BATCH_TYPE_UNLOGGED is generally used to group mutations for a single partition and do not suffer from the performance penalty imposed by logged batches, but there is no atomicity guarantee for multi-partition updates.

  • CASS_BATCH_TYPE_COUNTER is used to group counters updates.

Important: Be careful when using batches as a performance optimization.

void execute_batch(CassSession* session) {
  /* This logged batch will make sure that all the mutations eventually succeed */
  CassBatch* batch = cass_batch_new(CASS_BATCH_TYPE_LOGGED);

  /* Statements can be immediately freed after being added to the batch */

  {
    CassStatement* statement
      = cass_statement_new("INSERT INTO example1(key, value) VALUES ('a', '1')", 0);
    cass_batch_add_statement(batch, statement);
    cass_statement_free(statement);
  }

  {
    CassStatement* statement
      = cass_statement_new("UPDATE example2 set value = '2' WHERE key = 'b'", 0);
    cass_batch_add_statement(batch, statement);
    cass_statement_free(statement);
  }

  {
    CassStatement* statement
      = cass_statement_new("DELETE FROM example3 WHERE key = 'c'", 0);
    cass_batch_add_statement(batch, statement);
    cass_statement_free(statement);
  }

  CassFuture* batch_future = cass_session_execute_batch(session, batch);

  /* Batch objects can be freed immediately after being executed */
  cass_batch_free(batch);

  /* This will block until the query has finished */
  CassError rc = cass_future_error_code(batch_future);

  printf("Batch result: %s\n", cass_error_desc(rc));

  cass_future_free(batch_future);
}

Was this page helpful?

PREVIOUS
Using the Driver
NEXT
Binding Parameters
  • Create an issue
  • Edit this page
ScyllaDB CPP-Rust Driver
  • master
    • master
  • CPP-over-Rust Driver
  • API Documentation
    • CassAggregateMeta
    • CassAuthenticator
    • CassAuthenticatorCallbacks
    • CassBatch
    • CassCluster
    • CassCollection
    • CassColumnMeta
    • CassCustomPayload
    • CassDataType
    • CassErrorResult
    • CassExecProfile
    • CassFunctionMeta
    • CassFuture
    • CassIndexMeta
    • CassInet
    • CassIterator
    • CassKeyspaceMeta
    • CassLogMessage
    • CassMaterializedViewMeta
    • CassMetrics
    • CassNode
    • CassPrepared
    • CassResult
    • CassRetryPolicy
    • CassRow
    • CassSchemaMeta
    • CassSession
    • CassSpeculativeExecutionMetrics
    • CassSsl
    • CassStatement
    • CassTableMeta
    • CassTimestampGen
    • CassTuple
    • CassUserType
    • CassUuid
    • CassUuidGen
    • CassValue
    • CassVersion
  • Getting Started
  • Architecture Overview
  • Installation
  • Building
  • Testing
  • Using the Driver
    • Batches
    • Binding Parameters
    • Client-side timestamps
    • Consistency
    • Data Types
      • The date and time Types
      • Tuples
      • User-Defined Types (UDTs)
      • UUIDs
    • Futures
    • Handling Results
    • Keyspaces
    • Prepared Statements
    • Schema Metadata
  • Configuration
    • Load balancing
    • Retry policies
    • Speculative Execution
    • Connection
    • Execution Profiles
    • Performance Tips
    • Client Configuration
  • Security
    • Authentication
    • TLS
  • Observability
    • Logging
    • Tracing
    • Metrics
Docs Tutorials University Contact Us About Us
© 2025, ScyllaDB. All rights reserved. | Terms of Service | Privacy Policy | ScyllaDB, and ScyllaDB Cloud, are registered trademarks of ScyllaDB, Inc.
Last updated on 16 Sep 2025.
Powered by Sphinx 7.4.7 & ScyllaDB Theme 1.8.8
Ask AI