An option to control the selection of optimizer statistics package.
This parameter allows individual queries to use a different query
optimizer statistics package.
Specifying latest as a value instructs Cloud Spanner to use the latest
generated statistics package. If not specified, Cloud Spanner uses
the statistics package set at the database level options, or the latest
package if the database option is not set.
The statistics package requested by the query has to be exempt from
garbage collection. This can be achieved with the following DDL
statement:
ALTER STATISTICS <package_name> SET OPTIONS (allow_gc=false)
The list of available statistics packages can be queried from
INFORMATION_SCHEMA.SPANNER_STATISTICS.
Executing a SQL statement with an invalid optimizer statistics package
or with a statistics package that allows garbage collection fails with
an INVALID_ARGUMENT error.
An option to control the selection of optimizer version.
This parameter allows individual queries to pick different query
optimizer versions.
Specifying latest as a value instructs Cloud Spanner to use the
latest supported query optimizer version. If not specified, Cloud Spanner
uses the optimizer version set at the database level options. Any other
positive integer (from the list of supported optimizer versions)
overrides the default optimizer version for query execution.
The list of supported optimizer versions can be queried from
SPANNER_SYS.SUPPORTED_OPTIMIZER_VERSIONS.
Executing a SQL statement with an invalid optimizer version fails with
an INVALID_ARGUMENT error.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThis webpage provides documentation for the \u003ccode\u003eExecuteSqlRequest.Types.QueryOptions\u003c/code\u003e class within the Google Cloud Spanner v1 API for .NET.\u003c/p\u003e\n"],["\u003cp\u003eThe class \u003ccode\u003eExecuteSqlRequest.Types.QueryOptions\u003c/code\u003e offers configuration options for the query optimizer, including version selection and statistics package choice.\u003c/p\u003e\n"],["\u003cp\u003eThe latest available version for \u003ccode\u003eExecuteSqlRequest.Types.QueryOptions\u003c/code\u003e is 5.0.0-beta05, with a list of other available versions ranging from 3.5.0 to 5.0.0-beta04.\u003c/p\u003e\n"],["\u003cp\u003eUsers can choose the \u003ccode\u003elatest\u003c/code\u003e statistics package, or a specific one, in addition to being able to choose the \u003ccode\u003elatest\u003c/code\u003e query optimizer version or one of the supported options.\u003c/p\u003e\n"],["\u003cp\u003eThe two configurable properties of this class, \u003ccode\u003eOptimizerStatisticsPackage\u003c/code\u003e and \u003ccode\u003eOptimizerVersion\u003c/code\u003e will allow users to use a different query optimizer statistics package or a specific version from the supported list.\u003c/p\u003e\n"]]],[],null,["# Google Cloud Spanner v1 API - Class ExecuteSqlRequest.Types.QueryOptions (5.1.0)\n\nVersion latestkeyboard_arrow_down\n\n- [5.1.0 (latest)](/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions)\n- [5.0.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/5.0.0/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions)\n- [4.6.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/4.6.0/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions)\n- [4.5.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/4.5.0/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions)\n- [4.4.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/4.4.0/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions)\n- [4.3.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/4.3.0/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions)\n- [4.2.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/4.2.0/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions)\n- [4.1.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/4.1.0/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions)\n- [4.0.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/4.0.0/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions)\n- [3.15.1](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.15.1/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions)\n- [3.14.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.14.0/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions)\n- [3.13.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.13.0/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions)\n- [3.12.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.12.0/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions)\n- [3.11.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.11.0/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions)\n- [3.10.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.10.0/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions)\n- [3.9.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.9.0/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions)\n- [3.8.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.8.0/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions)\n- [3.7.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.7.0/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions)\n- [3.6.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.6.0/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions)\n- [3.5.0](/dotnet/docs/reference/Google.Cloud.Spanner.V1/3.5.0/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions) \n\n public sealed class ExecuteSqlRequest.Types.QueryOptions : IMessage\u003cExecuteSqlRequest.Types.QueryOptions\u003e, IEquatable\u003cExecuteSqlRequest.Types.QueryOptions\u003e, IDeepCloneable\u003cExecuteSqlRequest.Types.QueryOptions\u003e, IBufferMessage, IMessage\n\nReference documentation and code samples for the Google Cloud Spanner v1 API class ExecuteSqlRequest.Types.QueryOptions.\n\nQuery optimizer configuration. \n\nInheritance\n-----------\n\n[object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e ExecuteSqlRequest.Types.QueryOptions \n\nImplements\n----------\n\n[IMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage-1.html)[ExecuteSqlRequest](/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ExecuteSqlRequest)[Types](/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types)[QueryOptions](/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions), [IEquatable](https://learn.microsoft.com/dotnet/api/system.iequatable-1)[ExecuteSqlRequest](/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ExecuteSqlRequest)[Types](/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types)[QueryOptions](/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions), [IDeepCloneable](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IDeepCloneable-1.html)[ExecuteSqlRequest](/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ExecuteSqlRequest)[Types](/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types)[QueryOptions](/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.ExecuteSqlRequest.Types.QueryOptions), [IBufferMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IBufferMessage.html), [IMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage.html) \n\nInherited Members\n-----------------\n\n[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) \n[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) \n[object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)\n\nNamespace\n---------\n\n[Google.Cloud.Spanner.V1](/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1)\n\nAssembly\n--------\n\nGoogle.Cloud.Spanner.V1.dll\n\nConstructors\n------------\n\n### QueryOptions()\n\n public QueryOptions()\n\n### QueryOptions(QueryOptions)\n\n public QueryOptions(ExecuteSqlRequest.Types.QueryOptions other)\n\nProperties\n----------\n\n### OptimizerStatisticsPackage\n\n public string OptimizerStatisticsPackage { get; set; }\n\nAn option to control the selection of optimizer statistics package.\n\nThis parameter allows individual queries to use a different query\noptimizer statistics package.\n\nSpecifying `latest` as a value instructs Cloud Spanner to use the latest\ngenerated statistics package. If not specified, Cloud Spanner uses\nthe statistics package set at the database level options, or the latest\npackage if the database option is not set.\n\nThe statistics package requested by the query has to be exempt from\ngarbage collection. This can be achieved with the following DDL\nstatement: \n\n ALTER STATISTICS \u003cpackage_name\u003e SET OPTIONS (allow_gc=false)\n\nThe list of available statistics packages can be queried from\n`INFORMATION_SCHEMA.SPANNER_STATISTICS`.\n\nExecuting a SQL statement with an invalid optimizer statistics package\nor with a statistics package that allows garbage collection fails with\nan `INVALID_ARGUMENT` error.\n\n### OptimizerVersion\n\n public string OptimizerVersion { get; set; }\n\nAn option to control the selection of optimizer version.\n\nThis parameter allows individual queries to pick different query\noptimizer versions.\n\nSpecifying `latest` as a value instructs Cloud Spanner to use the\nlatest supported query optimizer version. If not specified, Cloud Spanner\nuses the optimizer version set at the database level options. Any other\npositive integer (from the list of supported optimizer versions)\noverrides the default optimizer version for query execution.\n\nThe list of supported optimizer versions can be queried from\nSPANNER_SYS.SUPPORTED_OPTIMIZER_VERSIONS.\n\nExecuting a SQL statement with an invalid optimizer version fails with\nan `INVALID_ARGUMENT` error.\n\nSee\n\u003chttps://cloud.google.com/spanner/docs/query-optimizer/manage-query-optimizer\u003e\nfor more information on managing the query optimizer.\n\nThe `optimizer_version` statement hint has precedence over this setting."]]