ScyllaDB University Live | Free Virtual Training Event
Learn more
ScyllaDB Documentation Logo Documentation
  • Server
  • Cloud
  • Tools
    • ScyllaDB Manager
    • ScyllaDB Monitoring Stack
    • ScyllaDB Operator
  • Drivers
    • CQL Drivers
    • DynamoDB Drivers
  • Resources
    • ScyllaDB University
    • Community Forum
    • Tutorials
Download
ScyllaDB Docs ScyllaDB C# driver Features Routing queries

Routing queries¶

When using the default load-balancing policy (DefaultLoadBalancingPolicy) or TokenAwarePolicy, the driver uses the RoutingKey to determine which node is used as coordinator for a given statement.

Note that the internal TokenMap must be up to date in order for this feature to work correctly. If metadata synchronization is enabled (which it is by default), then the driver will automatically keep it up to date. For more information on metadata synchronization, check out this page.

Prepared statements¶

When using prepared statements, the driver will determine which of the query parameters compose the partition key based on the prepared statement metadata.

Consider a table users that has a single partition key, id.

PreparedStatement prepared = session.Prepare(
      "INSERT INTO users (id, name) VALUES (?, ?)");

When binding the parameters, the driver knows which parameter corresponds to the partition key.

BoundStatement bound = prepared.Bind(Guid.NewGuid(), "Franz Ferdinand");
session.Execute(bound);

As a rule of thumb, use prepared statements and the driver does all the routing for you.

Simple statements¶

If you need to use a simple statement with routing, you must specify the routing values.

var id = Guid.NewGuid();
var query = new SimpleStatement(
      "INSERT INTO users (id, name) VALUES (?, ?)", id, "Franz Ferdinand");
// You must specify the values that compose the partition key
query.SetRoutingValues(id);
session.Execute(query);

Batch statements¶

If you want to enable routing for batch statements, you must specify the routing values.

var partitionKey = Guid.NewGuid();
var batch = new BatchStatement();
// ... Add statements to the query
// You must specify the values that compose the partition key
batch.SetRoutingValues(partitionKey);
session.Execute(batch);

Was this page helpful?

PREVIOUS
Request Tracker
NEXT
Speculative query execution
  • Create an issue
  • Edit this page

On this page

  • Routing queries
    • Prepared statements
    • Simple statements
    • Batch statements
ScyllaDB C# driver
  • master
    • master
  • Features
    • Address resolution
    • Authentication and Authorization
    • Automatic failover
    • Column Encryption
    • Driver components
      • ADO.NET
      • Core component
        • Statements
          • Batch statements
          • Per-query keyspace
          • Prepared statements
          • Simple statements
      • Linq component
        • Batch statements with LINQ
      • Mapper component
        • Batch statements with the Mapper
    • Connection heartbeat
    • Connection pooling
    • CQL data types to C# types
      • Date and time representation
      • Nulls and unset
    • Execution Profiles
    • Graph support
    • Cluster and schema metadata
    • Metrics
      • App.Metrics Provider
      • List of metrics
    • Native protocol
    • OpenTelemetry
    • Result paging
    • Parameterized queries
    • Query timestamps
    • Query warnings
    • Request Tracker
    • Routing queries
    • Speculative query execution
    • TLS/SSL
    • Tuning policies
    • User-defined functions and aggregates
    • User-defined types
    • Vector support
  • FAQ
  • Upgrade Guide
  • Examples
  • API Reference
Docs Tutorials University Contact Us About Us
© 2025 ScyllaDB | Terms of Service | Privacy Policy | ScyllaDB, and ScyllaDB Cloud, are registered trademarks of ScyllaDB, Inc.
Last updated on 01 Aug 2025.
Powered by Sphinx 7.4.7 & ScyllaDB Theme 1.8.7
Ask AI