Class QueryOptions
Options related to defaults for individual queries.
Inheritance
Inherited Members
Namespace: Cassandra
Assembly: Cassandra.dll
Syntax
public class QueryOptions
Fields
DefaultConsistencyLevel
The default consistency level for queries: ConsistencyLevel.LocalOne
.
For DataStax Astra, this constant should be ignored as the default is LocalQuorum.
Declaration
public const ConsistencyLevel DefaultConsistencyLevel = LocalOne
Field Value
Type | Description |
---|---|
ConsistencyLevel |
DefaultPageSize
The default page size for SELECT queries: 5000.
Declaration
public const int DefaultPageSize = 5000
Field Value
Type | Description |
---|---|
int |
DefaultRetryOnTimeout
Default value for RetryOnTimeout
Declaration
public const bool DefaultRetryOnTimeout = true
Field Value
Type | Description |
---|---|
bool |
DefaultSerialConsistencyLevel
The default serial consistency level for conditional updates: ConsistencyLevel.Serial
.
Declaration
public const ConsistencyLevel DefaultSerialConsistencyLevel = Serial
Field Value
Type | Description |
---|---|
ConsistencyLevel |
Properties
RetryOnTimeout
Gets a value that determines if the client should retry when it didn't hear back from a host within ReadTimeoutMillis.
DEPRECATED: Instead, use OnRequestError(IStatement, Configuration, Exception, int) to control the behavior when OperationTimedOutException is obtained.
Declaration
public bool RetryOnTimeout { get; }
Property Value
Type | Description |
---|---|
bool |
Methods
GetConsistencyLevel()
The default consistency level used by queries.
Declaration
public ConsistencyLevel GetConsistencyLevel()
Returns
Type | Description |
---|---|
ConsistencyLevel | the default consistency level used by queries. |
GetDefaultIdempotence()
Gets the default idempotence for all queries.
Declaration
public bool GetDefaultIdempotence()
Returns
Type | Description |
---|---|
bool |
GetPageSize()
The default page size used by queries.
Declaration
public int GetPageSize()
Returns
Type | Description |
---|---|
int | the default page size used by queries. |
GetSerialConsistencyLevel()
The default serial consistency level used by queries.
Declaration
public ConsistencyLevel GetSerialConsistencyLevel()
Returns
Type | Description |
---|---|
ConsistencyLevel | the default serial consistency level used by queries. |
IsPrepareOnAllHosts()
Determines whether the driver should prepare statements on all hosts in the cluster.
Declaration
public bool IsPrepareOnAllHosts()
Returns
Type | Description |
---|---|
bool |
IsReprepareOnUp()
Determines whether the driver should re-prepare all cached prepared statements on a host when its marks that host back up.
Declaration
public bool IsReprepareOnUp()
Returns
Type | Description |
---|---|
bool |
SetConsistencyLevel(ConsistencyLevel)
Sets the default consistency level to use for queries.
The consistency level set through this method will be use for queries that don't explicitely have a consistency level.
Declaration
public QueryOptions SetConsistencyLevel(ConsistencyLevel consistencyLevel)
Parameters
Type | Name | Description |
---|---|---|
ConsistencyLevel | consistencyLevel | the new consistency level to set as default. |
Returns
Type | Description |
---|---|
QueryOptions | this QueryOptions instance |
SetDefaultIdempotence(bool)
Sets the default idempotence for all queries.
Declaration
public QueryOptions SetDefaultIdempotence(bool idempotence)
Parameters
Type | Name | Description |
---|---|---|
bool | idempotence |
Returns
Type | Description |
---|---|
QueryOptions |
SetPageSize(int)
Sets the default page size to use for SELECT queries. The page size set through this method will be use for queries that don't explicitely have a page size.
Declaration
public QueryOptions SetPageSize(int pageSize)
Parameters
Type | Name | Description |
---|---|---|
int | pageSize | the new page size to set as default. It must be strictly positive but you can use int.MaxValue to disable paging. |
Returns
Type | Description |
---|---|
QueryOptions | this QueryOptions instance |
SetPrepareOnAllHosts(bool)
Sets whether the driver should prepare statements on all hosts in the cluster.
A statement is normally prepared in two steps: prepare the query on a single host in the cluster; if that succeeds, prepare on all other hosts.
This option controls whether step 2 is executed. It is enabled by default.
Declaration
public QueryOptions SetPrepareOnAllHosts(bool prepareOnAllHosts)
Parameters
Type | Name | Description |
---|---|---|
bool | prepareOnAllHosts |
Returns
Type | Description |
---|---|
QueryOptions |
Remarks
The reason why you might want to disable it is to optimize network usage if you have a large number of clients preparing the same set of statements at startup. If your load balancing policy distributes queries randomly, each client will pick a different host to prepare its statements, and on the whole each host has a good chance of having been hit by at least one client for each statement.
On the other hand, if that assumption turns out to be wrong and one host hasn't prepared a given statement, it needs to be re-prepared on the fly the first time it gets executed; this causes a performance penalty (one extra roundtrip to resend the query to prepare, and another to retry the execution).
SetReprepareOnUp(bool)
Set whether the driver should re-prepare all cached prepared statements on a host when it marks it back up.
This option is enabled by default.
Declaration
public QueryOptions SetReprepareOnUp(bool reprepareOnUp)
Parameters
Type | Name | Description |
---|---|---|
bool | reprepareOnUp |
Returns
Type | Description |
---|---|
QueryOptions |
Remarks
The reason why you might want to disable it is to optimize reconnection time when you believe hosts often get marked down because of temporary network issues, rather than the host really crashing. In that case, the host still has prepared statements in its cache when the driver reconnects, so re-preparing is redundant.
On the other hand, if that assumption turns out to be wrong and the host had really restarted, its prepared statement cache is empty, and statements need to be re-prepared on the fly the first time they get executed; this causes a performance penalty (one extra roundtrip to resend the query to prepare, and another to retry the execution).
SetRetryOnTimeout(bool)
Determines if the client should retry when it didn't hear back from a host within ReadTimeoutMillis.
DEPRECATED: Instead, use OnRequestError(IStatement, Configuration, Exception, int) to control the behavior when OperationTimedOutException is obtained.
Declaration
public QueryOptions SetRetryOnTimeout(bool retry)
Parameters
Type | Name | Description |
---|---|---|
bool | retry |
Returns
Type | Description |
---|---|
QueryOptions |
SetSerialConsistencyLevel(ConsistencyLevel)
Sets the default serial consistency level to use for queries. The serial consistency level set through this method will be use for queries that don't explicitely have a serial consistency level.
Declaration
public QueryOptions SetSerialConsistencyLevel(ConsistencyLevel serialConsistencyLevel)
Parameters
Type | Name | Description |
---|---|---|
ConsistencyLevel | serialConsistencyLevel | the new serial consistency level to set as default. |
Returns
Type | Description |
---|---|
QueryOptions | this QueryOptions instance. |