spanner.proto 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. // Copyright 2021 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. syntax = "proto3";
  15. package google.spanner.v1;
  16. import public "google/spanner/v1/commit_response.proto";
  17. import "google/api/annotations.proto";
  18. import "google/api/client.proto";
  19. import "google/api/field_behavior.proto";
  20. import "google/api/resource.proto";
  21. import "google/protobuf/empty.proto";
  22. import "google/protobuf/struct.proto";
  23. import "google/protobuf/timestamp.proto";
  24. import "google/rpc/status.proto";
  25. import "google/spanner/v1/keys.proto";
  26. import "google/spanner/v1/mutation.proto";
  27. import "google/spanner/v1/result_set.proto";
  28. import "google/spanner/v1/transaction.proto";
  29. import "google/spanner/v1/type.proto";
  30. option csharp_namespace = "Google.Cloud.Spanner.V1";
  31. option go_package = "google.golang.org/genproto/googleapis/spanner/v1;spanner";
  32. option java_multiple_files = true;
  33. option java_outer_classname = "SpannerProto";
  34. option java_package = "com.google.spanner.v1";
  35. option php_namespace = "Google\\Cloud\\Spanner\\V1";
  36. option ruby_package = "Google::Cloud::Spanner::V1";
  37. option (google.api.resource_definition) = {
  38. type: "spanner.googleapis.com/Database"
  39. pattern: "projects/{project}/instances/{instance}/databases/{database}"
  40. };
  41. // Cloud Spanner API
  42. //
  43. // The Cloud Spanner API can be used to manage sessions and execute
  44. // transactions on data stored in Cloud Spanner databases.
  45. service Spanner {
  46. option (google.api.default_host) = "spanner.googleapis.com";
  47. option (google.api.oauth_scopes) =
  48. "https://www.googleapis.com/auth/cloud-platform,"
  49. "https://www.googleapis.com/auth/spanner.data";
  50. // Creates a new session. A session can be used to perform
  51. // transactions that read and/or modify data in a Cloud Spanner database.
  52. // Sessions are meant to be reused for many consecutive
  53. // transactions.
  54. //
  55. // Sessions can only execute one transaction at a time. To execute
  56. // multiple concurrent read-write/write-only transactions, create
  57. // multiple sessions. Note that standalone reads and queries use a
  58. // transaction internally, and count toward the one transaction
  59. // limit.
  60. //
  61. // Active sessions use additional server resources, so it is a good idea to
  62. // delete idle and unneeded sessions.
  63. // Aside from explicit deletes, Cloud Spanner may delete sessions for which no
  64. // operations are sent for more than an hour. If a session is deleted,
  65. // requests to it return `NOT_FOUND`.
  66. //
  67. // Idle sessions can be kept alive by sending a trivial SQL query
  68. // periodically, e.g., `"SELECT 1"`.
  69. rpc CreateSession(CreateSessionRequest) returns (Session) {
  70. option (google.api.http) = {
  71. post: "/v1/{database=projects/*/instances/*/databases/*}/sessions"
  72. body: "*"
  73. };
  74. option (google.api.method_signature) = "database";
  75. }
  76. // Creates multiple new sessions.
  77. //
  78. // This API can be used to initialize a session cache on the clients.
  79. // See https://goo.gl/TgSFN2 for best practices on session cache management.
  80. rpc BatchCreateSessions(BatchCreateSessionsRequest) returns (BatchCreateSessionsResponse) {
  81. option (google.api.http) = {
  82. post: "/v1/{database=projects/*/instances/*/databases/*}/sessions:batchCreate"
  83. body: "*"
  84. };
  85. option (google.api.method_signature) = "database,session_count";
  86. }
  87. // Gets a session. Returns `NOT_FOUND` if the session does not exist.
  88. // This is mainly useful for determining whether a session is still
  89. // alive.
  90. rpc GetSession(GetSessionRequest) returns (Session) {
  91. option (google.api.http) = {
  92. get: "/v1/{name=projects/*/instances/*/databases/*/sessions/*}"
  93. };
  94. option (google.api.method_signature) = "name";
  95. }
  96. // Lists all sessions in a given database.
  97. rpc ListSessions(ListSessionsRequest) returns (ListSessionsResponse) {
  98. option (google.api.http) = {
  99. get: "/v1/{database=projects/*/instances/*/databases/*}/sessions"
  100. };
  101. option (google.api.method_signature) = "database";
  102. }
  103. // Ends a session, releasing server resources associated with it. This will
  104. // asynchronously trigger cancellation of any operations that are running with
  105. // this session.
  106. rpc DeleteSession(DeleteSessionRequest) returns (google.protobuf.Empty) {
  107. option (google.api.http) = {
  108. delete: "/v1/{name=projects/*/instances/*/databases/*/sessions/*}"
  109. };
  110. option (google.api.method_signature) = "name";
  111. }
  112. // Executes an SQL statement, returning all results in a single reply. This
  113. // method cannot be used to return a result set larger than 10 MiB;
  114. // if the query yields more data than that, the query fails with
  115. // a `FAILED_PRECONDITION` error.
  116. //
  117. // Operations inside read-write transactions might return `ABORTED`. If
  118. // this occurs, the application should restart the transaction from
  119. // the beginning. See [Transaction][google.spanner.v1.Transaction] for more details.
  120. //
  121. // Larger result sets can be fetched in streaming fashion by calling
  122. // [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] instead.
  123. rpc ExecuteSql(ExecuteSqlRequest) returns (ResultSet) {
  124. option (google.api.http) = {
  125. post: "/v1/{session=projects/*/instances/*/databases/*/sessions/*}:executeSql"
  126. body: "*"
  127. };
  128. }
  129. // Like [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], except returns the result
  130. // set as a stream. Unlike [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], there
  131. // is no limit on the size of the returned result set. However, no
  132. // individual row in the result set can exceed 100 MiB, and no
  133. // column value can exceed 10 MiB.
  134. rpc ExecuteStreamingSql(ExecuteSqlRequest) returns (stream PartialResultSet) {
  135. option (google.api.http) = {
  136. post: "/v1/{session=projects/*/instances/*/databases/*/sessions/*}:executeStreamingSql"
  137. body: "*"
  138. };
  139. }
  140. // Executes a batch of SQL DML statements. This method allows many statements
  141. // to be run with lower latency than submitting them sequentially with
  142. // [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql].
  143. //
  144. // Statements are executed in sequential order. A request can succeed even if
  145. // a statement fails. The [ExecuteBatchDmlResponse.status][google.spanner.v1.ExecuteBatchDmlResponse.status] field in the
  146. // response provides information about the statement that failed. Clients must
  147. // inspect this field to determine whether an error occurred.
  148. //
  149. // Execution stops after the first failed statement; the remaining statements
  150. // are not executed.
  151. rpc ExecuteBatchDml(ExecuteBatchDmlRequest) returns (ExecuteBatchDmlResponse) {
  152. option (google.api.http) = {
  153. post: "/v1/{session=projects/*/instances/*/databases/*/sessions/*}:executeBatchDml"
  154. body: "*"
  155. };
  156. }
  157. // Reads rows from the database using key lookups and scans, as a
  158. // simple key/value style alternative to
  159. // [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. This method cannot be used to
  160. // return a result set larger than 10 MiB; if the read matches more
  161. // data than that, the read fails with a `FAILED_PRECONDITION`
  162. // error.
  163. //
  164. // Reads inside read-write transactions might return `ABORTED`. If
  165. // this occurs, the application should restart the transaction from
  166. // the beginning. See [Transaction][google.spanner.v1.Transaction] for more details.
  167. //
  168. // Larger result sets can be yielded in streaming fashion by calling
  169. // [StreamingRead][google.spanner.v1.Spanner.StreamingRead] instead.
  170. rpc Read(ReadRequest) returns (ResultSet) {
  171. option (google.api.http) = {
  172. post: "/v1/{session=projects/*/instances/*/databases/*/sessions/*}:read"
  173. body: "*"
  174. };
  175. }
  176. // Like [Read][google.spanner.v1.Spanner.Read], except returns the result set as a
  177. // stream. Unlike [Read][google.spanner.v1.Spanner.Read], there is no limit on the
  178. // size of the returned result set. However, no individual row in
  179. // the result set can exceed 100 MiB, and no column value can exceed
  180. // 10 MiB.
  181. rpc StreamingRead(ReadRequest) returns (stream PartialResultSet) {
  182. option (google.api.http) = {
  183. post: "/v1/{session=projects/*/instances/*/databases/*/sessions/*}:streamingRead"
  184. body: "*"
  185. };
  186. }
  187. // Begins a new transaction. This step can often be skipped:
  188. // [Read][google.spanner.v1.Spanner.Read], [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and
  189. // [Commit][google.spanner.v1.Spanner.Commit] can begin a new transaction as a
  190. // side-effect.
  191. rpc BeginTransaction(BeginTransactionRequest) returns (Transaction) {
  192. option (google.api.http) = {
  193. post: "/v1/{session=projects/*/instances/*/databases/*/sessions/*}:beginTransaction"
  194. body: "*"
  195. };
  196. option (google.api.method_signature) = "session,options";
  197. }
  198. // Commits a transaction. The request includes the mutations to be
  199. // applied to rows in the database.
  200. //
  201. // `Commit` might return an `ABORTED` error. This can occur at any time;
  202. // commonly, the cause is conflicts with concurrent
  203. // transactions. However, it can also happen for a variety of other
  204. // reasons. If `Commit` returns `ABORTED`, the caller should re-attempt
  205. // the transaction from the beginning, re-using the same session.
  206. //
  207. // On very rare occasions, `Commit` might return `UNKNOWN`. This can happen,
  208. // for example, if the client job experiences a 1+ hour networking failure.
  209. // At that point, Cloud Spanner has lost track of the transaction outcome and
  210. // we recommend that you perform another read from the database to see the
  211. // state of things as they are now.
  212. rpc Commit(CommitRequest) returns (CommitResponse) {
  213. option (google.api.http) = {
  214. post: "/v1/{session=projects/*/instances/*/databases/*/sessions/*}:commit"
  215. body: "*"
  216. };
  217. option (google.api.method_signature) = "session,transaction_id,mutations";
  218. option (google.api.method_signature) = "session,single_use_transaction,mutations";
  219. }
  220. // Rolls back a transaction, releasing any locks it holds. It is a good
  221. // idea to call this for any transaction that includes one or more
  222. // [Read][google.spanner.v1.Spanner.Read] or [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] requests and
  223. // ultimately decides not to commit.
  224. //
  225. // `Rollback` returns `OK` if it successfully aborts the transaction, the
  226. // transaction was already aborted, or the transaction is not
  227. // found. `Rollback` never returns `ABORTED`.
  228. rpc Rollback(RollbackRequest) returns (google.protobuf.Empty) {
  229. option (google.api.http) = {
  230. post: "/v1/{session=projects/*/instances/*/databases/*/sessions/*}:rollback"
  231. body: "*"
  232. };
  233. option (google.api.method_signature) = "session,transaction_id";
  234. }
  235. // Creates a set of partition tokens that can be used to execute a query
  236. // operation in parallel. Each of the returned partition tokens can be used
  237. // by [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] to specify a subset
  238. // of the query result to read. The same session and read-only transaction
  239. // must be used by the PartitionQueryRequest used to create the
  240. // partition tokens and the ExecuteSqlRequests that use the partition tokens.
  241. //
  242. // Partition tokens become invalid when the session used to create them
  243. // is deleted, is idle for too long, begins a new transaction, or becomes too
  244. // old. When any of these happen, it is not possible to resume the query, and
  245. // the whole operation must be restarted from the beginning.
  246. rpc PartitionQuery(PartitionQueryRequest) returns (PartitionResponse) {
  247. option (google.api.http) = {
  248. post: "/v1/{session=projects/*/instances/*/databases/*/sessions/*}:partitionQuery"
  249. body: "*"
  250. };
  251. }
  252. // Creates a set of partition tokens that can be used to execute a read
  253. // operation in parallel. Each of the returned partition tokens can be used
  254. // by [StreamingRead][google.spanner.v1.Spanner.StreamingRead] to specify a subset of the read
  255. // result to read. The same session and read-only transaction must be used by
  256. // the PartitionReadRequest used to create the partition tokens and the
  257. // ReadRequests that use the partition tokens. There are no ordering
  258. // guarantees on rows returned among the returned partition tokens, or even
  259. // within each individual StreamingRead call issued with a partition_token.
  260. //
  261. // Partition tokens become invalid when the session used to create them
  262. // is deleted, is idle for too long, begins a new transaction, or becomes too
  263. // old. When any of these happen, it is not possible to resume the read, and
  264. // the whole operation must be restarted from the beginning.
  265. rpc PartitionRead(PartitionReadRequest) returns (PartitionResponse) {
  266. option (google.api.http) = {
  267. post: "/v1/{session=projects/*/instances/*/databases/*/sessions/*}:partitionRead"
  268. body: "*"
  269. };
  270. }
  271. }
  272. // The request for [CreateSession][google.spanner.v1.Spanner.CreateSession].
  273. message CreateSessionRequest {
  274. // Required. The database in which the new session is created.
  275. string database = 1 [
  276. (google.api.field_behavior) = REQUIRED,
  277. (google.api.resource_reference) = {
  278. type: "spanner.googleapis.com/Database"
  279. }
  280. ];
  281. // The session to create.
  282. Session session = 2;
  283. }
  284. // The request for [BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions].
  285. message BatchCreateSessionsRequest {
  286. // Required. The database in which the new sessions are created.
  287. string database = 1 [
  288. (google.api.field_behavior) = REQUIRED,
  289. (google.api.resource_reference) = {
  290. type: "spanner.googleapis.com/Database"
  291. }
  292. ];
  293. // Parameters to be applied to each created session.
  294. Session session_template = 2;
  295. // Required. The number of sessions to be created in this batch call.
  296. // The API may return fewer than the requested number of sessions. If a
  297. // specific number of sessions are desired, the client can make additional
  298. // calls to BatchCreateSessions (adjusting
  299. // [session_count][google.spanner.v1.BatchCreateSessionsRequest.session_count] as necessary).
  300. int32 session_count = 3 [(google.api.field_behavior) = REQUIRED];
  301. }
  302. // The response for [BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions].
  303. message BatchCreateSessionsResponse {
  304. // The freshly created sessions.
  305. repeated Session session = 1;
  306. }
  307. // A session in the Cloud Spanner API.
  308. message Session {
  309. option (google.api.resource) = {
  310. type: "spanner.googleapis.com/Session"
  311. pattern: "projects/{project}/instances/{instance}/databases/{database}/sessions/{session}"
  312. };
  313. // Output only. The name of the session. This is always system-assigned.
  314. string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
  315. // The labels for the session.
  316. //
  317. // * Label keys must be between 1 and 63 characters long and must conform to
  318. // the following regular expression: `[a-z]([-a-z0-9]*[a-z0-9])?`.
  319. // * Label values must be between 0 and 63 characters long and must conform
  320. // to the regular expression `([a-z]([-a-z0-9]*[a-z0-9])?)?`.
  321. // * No more than 64 labels can be associated with a given session.
  322. //
  323. // See https://goo.gl/xmQnxf for more information on and examples of labels.
  324. map<string, string> labels = 2;
  325. // Output only. The timestamp when the session is created.
  326. google.protobuf.Timestamp create_time = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
  327. // Output only. The approximate timestamp when the session is last used. It is
  328. // typically earlier than the actual last use time.
  329. google.protobuf.Timestamp approximate_last_use_time = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
  330. }
  331. // The request for [GetSession][google.spanner.v1.Spanner.GetSession].
  332. message GetSessionRequest {
  333. // Required. The name of the session to retrieve.
  334. string name = 1 [
  335. (google.api.field_behavior) = REQUIRED,
  336. (google.api.resource_reference) = {
  337. type: "spanner.googleapis.com/Session"
  338. }
  339. ];
  340. }
  341. // The request for [ListSessions][google.spanner.v1.Spanner.ListSessions].
  342. message ListSessionsRequest {
  343. // Required. The database in which to list sessions.
  344. string database = 1 [
  345. (google.api.field_behavior) = REQUIRED,
  346. (google.api.resource_reference) = {
  347. type: "spanner.googleapis.com/Database"
  348. }
  349. ];
  350. // Number of sessions to be returned in the response. If 0 or less, defaults
  351. // to the server's maximum allowed page size.
  352. int32 page_size = 2;
  353. // If non-empty, `page_token` should contain a
  354. // [next_page_token][google.spanner.v1.ListSessionsResponse.next_page_token] from a previous
  355. // [ListSessionsResponse][google.spanner.v1.ListSessionsResponse].
  356. string page_token = 3;
  357. // An expression for filtering the results of the request. Filter rules are
  358. // case insensitive. The fields eligible for filtering are:
  359. //
  360. // * `labels.key` where key is the name of a label
  361. //
  362. // Some examples of using filters are:
  363. //
  364. // * `labels.env:*` --> The session has the label "env".
  365. // * `labels.env:dev` --> The session has the label "env" and the value of
  366. // the label contains the string "dev".
  367. string filter = 4;
  368. }
  369. // The response for [ListSessions][google.spanner.v1.Spanner.ListSessions].
  370. message ListSessionsResponse {
  371. // The list of requested sessions.
  372. repeated Session sessions = 1;
  373. // `next_page_token` can be sent in a subsequent
  374. // [ListSessions][google.spanner.v1.Spanner.ListSessions] call to fetch more of the matching
  375. // sessions.
  376. string next_page_token = 2;
  377. }
  378. // The request for [DeleteSession][google.spanner.v1.Spanner.DeleteSession].
  379. message DeleteSessionRequest {
  380. // Required. The name of the session to delete.
  381. string name = 1 [
  382. (google.api.field_behavior) = REQUIRED,
  383. (google.api.resource_reference) = {
  384. type: "spanner.googleapis.com/Session"
  385. }
  386. ];
  387. }
  388. // Common request options for various APIs.
  389. message RequestOptions {
  390. // The relative priority for requests. Note that priority is not applicable
  391. // for [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction].
  392. //
  393. // The priority acts as a hint to the Cloud Spanner scheduler and does not
  394. // guarantee priority or order of execution. For example:
  395. //
  396. // * Some parts of a write operation always execute at `PRIORITY_HIGH`,
  397. // regardless of the specified priority. This may cause you to see an
  398. // increase in high priority workload even when executing a low priority
  399. // request. This can also potentially cause a priority inversion where a
  400. // lower priority request will be fulfilled ahead of a higher priority
  401. // request.
  402. // * If a transaction contains multiple operations with different priorities,
  403. // Cloud Spanner does not guarantee to process the higher priority
  404. // operations first. There may be other constraints to satisfy, such as
  405. // order of operations.
  406. enum Priority {
  407. // `PRIORITY_UNSPECIFIED` is equivalent to `PRIORITY_HIGH`.
  408. PRIORITY_UNSPECIFIED = 0;
  409. // This specifies that the request is low priority.
  410. PRIORITY_LOW = 1;
  411. // This specifies that the request is medium priority.
  412. PRIORITY_MEDIUM = 2;
  413. // This specifies that the request is high priority.
  414. PRIORITY_HIGH = 3;
  415. }
  416. // Priority for the request.
  417. Priority priority = 1;
  418. // A per-request tag which can be applied to queries or reads, used for
  419. // statistics collection.
  420. // Both request_tag and transaction_tag can be specified for a read or query
  421. // that belongs to a transaction.
  422. // This field is ignored for requests where it's not applicable (e.g.
  423. // CommitRequest).
  424. // Legal characters for `request_tag` values are all printable characters
  425. // (ASCII 32 - 126) and the length of a request_tag is limited to 50
  426. // characters. Values that exceed this limit are truncated.
  427. string request_tag = 2;
  428. // A tag used for statistics collection about this transaction.
  429. // Both request_tag and transaction_tag can be specified for a read or query
  430. // that belongs to a transaction.
  431. // The value of transaction_tag should be the same for all requests belonging
  432. // to the same transaction.
  433. // If this request doesn’t belong to any transaction, transaction_tag will be
  434. // ignored.
  435. // Legal characters for `transaction_tag` values are all printable characters
  436. // (ASCII 32 - 126) and the length of a transaction_tag is limited to 50
  437. // characters. Values that exceed this limit are truncated.
  438. string transaction_tag = 3;
  439. }
  440. // The request for [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and
  441. // [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql].
  442. message ExecuteSqlRequest {
  443. // Query optimizer configuration.
  444. message QueryOptions {
  445. // An option to control the selection of optimizer version.
  446. //
  447. // This parameter allows individual queries to pick different query
  448. // optimizer versions.
  449. //
  450. // Specifying `latest` as a value instructs Cloud Spanner to use the
  451. // latest supported query optimizer version. If not specified, Cloud Spanner
  452. // uses the optimizer version set at the database level options. Any other
  453. // positive integer (from the list of supported optimizer versions)
  454. // overrides the default optimizer version for query execution.
  455. //
  456. // The list of supported optimizer versions can be queried from
  457. // SPANNER_SYS.SUPPORTED_OPTIMIZER_VERSIONS.
  458. //
  459. // Executing a SQL statement with an invalid optimizer version fails with
  460. // an `INVALID_ARGUMENT` error.
  461. //
  462. // See
  463. // https://cloud.google.com/spanner/docs/query-optimizer/manage-query-optimizer
  464. // for more information on managing the query optimizer.
  465. //
  466. // The `optimizer_version` statement hint has precedence over this setting.
  467. string optimizer_version = 1;
  468. // An option to control the selection of optimizer statistics package.
  469. //
  470. // This parameter allows individual queries to use a different query
  471. // optimizer statistics package.
  472. //
  473. // Specifying `latest` as a value instructs Cloud Spanner to use the latest
  474. // generated statistics package. If not specified, Cloud Spanner uses
  475. // the statistics package set at the database level options, or the latest
  476. // package if the database option is not set.
  477. //
  478. // The statistics package requested by the query has to be exempt from
  479. // garbage collection. This can be achieved with the following DDL
  480. // statement:
  481. //
  482. // ```
  483. // ALTER STATISTICS <package_name> SET OPTIONS (allow_gc=false)
  484. // ```
  485. //
  486. // The list of available statistics packages can be queried from
  487. // `INFORMATION_SCHEMA.SPANNER_STATISTICS`.
  488. //
  489. // Executing a SQL statement with an invalid optimizer statistics package
  490. // or with a statistics package that allows garbage collection fails with
  491. // an `INVALID_ARGUMENT` error.
  492. string optimizer_statistics_package = 2;
  493. }
  494. // Mode in which the statement must be processed.
  495. enum QueryMode {
  496. // The default mode. Only the statement results are returned.
  497. NORMAL = 0;
  498. // This mode returns only the query plan, without any results or
  499. // execution statistics information.
  500. PLAN = 1;
  501. // This mode returns both the query plan and the execution statistics along
  502. // with the results.
  503. PROFILE = 2;
  504. }
  505. // Required. The session in which the SQL query should be performed.
  506. string session = 1 [
  507. (google.api.field_behavior) = REQUIRED,
  508. (google.api.resource_reference) = {
  509. type: "spanner.googleapis.com/Session"
  510. }
  511. ];
  512. // The transaction to use.
  513. //
  514. // For queries, if none is provided, the default is a temporary read-only
  515. // transaction with strong concurrency.
  516. //
  517. // Standard DML statements require a read-write transaction. To protect
  518. // against replays, single-use transactions are not supported. The caller
  519. // must either supply an existing transaction ID or begin a new transaction.
  520. //
  521. // Partitioned DML requires an existing Partitioned DML transaction ID.
  522. TransactionSelector transaction = 2;
  523. // Required. The SQL string.
  524. string sql = 3 [(google.api.field_behavior) = REQUIRED];
  525. // Parameter names and values that bind to placeholders in the SQL string.
  526. //
  527. // A parameter placeholder consists of the `@` character followed by the
  528. // parameter name (for example, `@firstName`). Parameter names must conform
  529. // to the naming requirements of identifiers as specified at
  530. // https://cloud.google.com/spanner/docs/lexical#identifiers.
  531. //
  532. // Parameters can appear anywhere that a literal value is expected. The same
  533. // parameter name can be used more than once, for example:
  534. //
  535. // `"WHERE id > @msg_id AND id < @msg_id + 100"`
  536. //
  537. // It is an error to execute a SQL statement with unbound parameters.
  538. google.protobuf.Struct params = 4;
  539. // It is not always possible for Cloud Spanner to infer the right SQL type
  540. // from a JSON value. For example, values of type `BYTES` and values
  541. // of type `STRING` both appear in [params][google.spanner.v1.ExecuteSqlRequest.params] as JSON strings.
  542. //
  543. // In these cases, `param_types` can be used to specify the exact
  544. // SQL type for some or all of the SQL statement parameters. See the
  545. // definition of [Type][google.spanner.v1.Type] for more information
  546. // about SQL types.
  547. map<string, Type> param_types = 5;
  548. // If this request is resuming a previously interrupted SQL statement
  549. // execution, `resume_token` should be copied from the last
  550. // [PartialResultSet][google.spanner.v1.PartialResultSet] yielded before the interruption. Doing this
  551. // enables the new SQL statement execution to resume where the last one left
  552. // off. The rest of the request parameters must exactly match the
  553. // request that yielded this token.
  554. bytes resume_token = 6;
  555. // Used to control the amount of debugging information returned in
  556. // [ResultSetStats][google.spanner.v1.ResultSetStats]. If [partition_token][google.spanner.v1.ExecuteSqlRequest.partition_token] is set, [query_mode][google.spanner.v1.ExecuteSqlRequest.query_mode] can only
  557. // be set to [QueryMode.NORMAL][google.spanner.v1.ExecuteSqlRequest.QueryMode.NORMAL].
  558. QueryMode query_mode = 7;
  559. // If present, results will be restricted to the specified partition
  560. // previously created using PartitionQuery(). There must be an exact
  561. // match for the values of fields common to this message and the
  562. // PartitionQueryRequest message used to create this partition_token.
  563. bytes partition_token = 8;
  564. // A per-transaction sequence number used to identify this request. This field
  565. // makes each request idempotent such that if the request is received multiple
  566. // times, at most one will succeed.
  567. //
  568. // The sequence number must be monotonically increasing within the
  569. // transaction. If a request arrives for the first time with an out-of-order
  570. // sequence number, the transaction may be aborted. Replays of previously
  571. // handled requests will yield the same response as the first execution.
  572. //
  573. // Required for DML statements. Ignored for queries.
  574. int64 seqno = 9;
  575. // Query optimizer configuration to use for the given query.
  576. QueryOptions query_options = 10;
  577. // Common options for this request.
  578. RequestOptions request_options = 11;
  579. }
  580. // The request for [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml].
  581. message ExecuteBatchDmlRequest {
  582. // A single DML statement.
  583. message Statement {
  584. // Required. The DML string.
  585. string sql = 1;
  586. // Parameter names and values that bind to placeholders in the DML string.
  587. //
  588. // A parameter placeholder consists of the `@` character followed by the
  589. // parameter name (for example, `@firstName`). Parameter names can contain
  590. // letters, numbers, and underscores.
  591. //
  592. // Parameters can appear anywhere that a literal value is expected. The
  593. // same parameter name can be used more than once, for example:
  594. //
  595. // `"WHERE id > @msg_id AND id < @msg_id + 100"`
  596. //
  597. // It is an error to execute a SQL statement with unbound parameters.
  598. google.protobuf.Struct params = 2;
  599. // It is not always possible for Cloud Spanner to infer the right SQL type
  600. // from a JSON value. For example, values of type `BYTES` and values
  601. // of type `STRING` both appear in [params][google.spanner.v1.ExecuteBatchDmlRequest.Statement.params] as JSON strings.
  602. //
  603. // In these cases, `param_types` can be used to specify the exact
  604. // SQL type for some or all of the SQL statement parameters. See the
  605. // definition of [Type][google.spanner.v1.Type] for more information
  606. // about SQL types.
  607. map<string, Type> param_types = 3;
  608. }
  609. // Required. The session in which the DML statements should be performed.
  610. string session = 1 [
  611. (google.api.field_behavior) = REQUIRED,
  612. (google.api.resource_reference) = {
  613. type: "spanner.googleapis.com/Session"
  614. }
  615. ];
  616. // Required. The transaction to use. Must be a read-write transaction.
  617. //
  618. // To protect against replays, single-use transactions are not supported. The
  619. // caller must either supply an existing transaction ID or begin a new
  620. // transaction.
  621. TransactionSelector transaction = 2 [(google.api.field_behavior) = REQUIRED];
  622. // Required. The list of statements to execute in this batch. Statements are executed
  623. // serially, such that the effects of statement `i` are visible to statement
  624. // `i+1`. Each statement must be a DML statement. Execution stops at the
  625. // first failed statement; the remaining statements are not executed.
  626. //
  627. // Callers must provide at least one statement.
  628. repeated Statement statements = 3 [(google.api.field_behavior) = REQUIRED];
  629. // Required. A per-transaction sequence number used to identify this request. This field
  630. // makes each request idempotent such that if the request is received multiple
  631. // times, at most one will succeed.
  632. //
  633. // The sequence number must be monotonically increasing within the
  634. // transaction. If a request arrives for the first time with an out-of-order
  635. // sequence number, the transaction may be aborted. Replays of previously
  636. // handled requests will yield the same response as the first execution.
  637. int64 seqno = 4 [(google.api.field_behavior) = REQUIRED];
  638. // Common options for this request.
  639. RequestOptions request_options = 5;
  640. }
  641. // The response for [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. Contains a list
  642. // of [ResultSet][google.spanner.v1.ResultSet] messages, one for each DML statement that has successfully
  643. // executed, in the same order as the statements in the request. If a statement
  644. // fails, the status in the response body identifies the cause of the failure.
  645. //
  646. // To check for DML statements that failed, use the following approach:
  647. //
  648. // 1. Check the status in the response message. The [google.rpc.Code][google.rpc.Code] enum
  649. // value `OK` indicates that all statements were executed successfully.
  650. // 2. If the status was not `OK`, check the number of result sets in the
  651. // response. If the response contains `N` [ResultSet][google.spanner.v1.ResultSet] messages, then
  652. // statement `N+1` in the request failed.
  653. //
  654. // Example 1:
  655. //
  656. // * Request: 5 DML statements, all executed successfully.
  657. // * Response: 5 [ResultSet][google.spanner.v1.ResultSet] messages, with the status `OK`.
  658. //
  659. // Example 2:
  660. //
  661. // * Request: 5 DML statements. The third statement has a syntax error.
  662. // * Response: 2 [ResultSet][google.spanner.v1.ResultSet] messages, and a syntax error (`INVALID_ARGUMENT`)
  663. // status. The number of [ResultSet][google.spanner.v1.ResultSet] messages indicates that the third
  664. // statement failed, and the fourth and fifth statements were not executed.
  665. message ExecuteBatchDmlResponse {
  666. // One [ResultSet][google.spanner.v1.ResultSet] for each statement in the request that ran successfully,
  667. // in the same order as the statements in the request. Each [ResultSet][google.spanner.v1.ResultSet] does
  668. // not contain any rows. The [ResultSetStats][google.spanner.v1.ResultSetStats] in each [ResultSet][google.spanner.v1.ResultSet] contain
  669. // the number of rows modified by the statement.
  670. //
  671. // Only the first [ResultSet][google.spanner.v1.ResultSet] in the response contains valid
  672. // [ResultSetMetadata][google.spanner.v1.ResultSetMetadata].
  673. repeated ResultSet result_sets = 1;
  674. // If all DML statements are executed successfully, the status is `OK`.
  675. // Otherwise, the error status of the first failed statement.
  676. google.rpc.Status status = 2;
  677. }
  678. // Options for a PartitionQueryRequest and
  679. // PartitionReadRequest.
  680. message PartitionOptions {
  681. // **Note:** This hint is currently ignored by PartitionQuery and
  682. // PartitionRead requests.
  683. //
  684. // The desired data size for each partition generated. The default for this
  685. // option is currently 1 GiB. This is only a hint. The actual size of each
  686. // partition may be smaller or larger than this size request.
  687. int64 partition_size_bytes = 1;
  688. // **Note:** This hint is currently ignored by PartitionQuery and
  689. // PartitionRead requests.
  690. //
  691. // The desired maximum number of partitions to return. For example, this may
  692. // be set to the number of workers available. The default for this option
  693. // is currently 10,000. The maximum value is currently 200,000. This is only
  694. // a hint. The actual number of partitions returned may be smaller or larger
  695. // than this maximum count request.
  696. int64 max_partitions = 2;
  697. }
  698. // The request for [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery]
  699. message PartitionQueryRequest {
  700. // Required. The session used to create the partitions.
  701. string session = 1 [
  702. (google.api.field_behavior) = REQUIRED,
  703. (google.api.resource_reference) = {
  704. type: "spanner.googleapis.com/Session"
  705. }
  706. ];
  707. // Read only snapshot transactions are supported, read/write and single use
  708. // transactions are not.
  709. TransactionSelector transaction = 2;
  710. // Required. The query request to generate partitions for. The request will fail if
  711. // the query is not root partitionable. The query plan of a root
  712. // partitionable query has a single distributed union operator. A distributed
  713. // union operator conceptually divides one or more tables into multiple
  714. // splits, remotely evaluates a subquery independently on each split, and
  715. // then unions all results.
  716. //
  717. // This must not contain DML commands, such as INSERT, UPDATE, or
  718. // DELETE. Use [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] with a
  719. // PartitionedDml transaction for large, partition-friendly DML operations.
  720. string sql = 3 [(google.api.field_behavior) = REQUIRED];
  721. // Parameter names and values that bind to placeholders in the SQL string.
  722. //
  723. // A parameter placeholder consists of the `@` character followed by the
  724. // parameter name (for example, `@firstName`). Parameter names can contain
  725. // letters, numbers, and underscores.
  726. //
  727. // Parameters can appear anywhere that a literal value is expected. The same
  728. // parameter name can be used more than once, for example:
  729. //
  730. // `"WHERE id > @msg_id AND id < @msg_id + 100"`
  731. //
  732. // It is an error to execute a SQL statement with unbound parameters.
  733. google.protobuf.Struct params = 4;
  734. // It is not always possible for Cloud Spanner to infer the right SQL type
  735. // from a JSON value. For example, values of type `BYTES` and values
  736. // of type `STRING` both appear in [params][google.spanner.v1.PartitionQueryRequest.params] as JSON strings.
  737. //
  738. // In these cases, `param_types` can be used to specify the exact
  739. // SQL type for some or all of the SQL query parameters. See the
  740. // definition of [Type][google.spanner.v1.Type] for more information
  741. // about SQL types.
  742. map<string, Type> param_types = 5;
  743. // Additional options that affect how many partitions are created.
  744. PartitionOptions partition_options = 6;
  745. }
  746. // The request for [PartitionRead][google.spanner.v1.Spanner.PartitionRead]
  747. message PartitionReadRequest {
  748. // Required. The session used to create the partitions.
  749. string session = 1 [
  750. (google.api.field_behavior) = REQUIRED,
  751. (google.api.resource_reference) = {
  752. type: "spanner.googleapis.com/Session"
  753. }
  754. ];
  755. // Read only snapshot transactions are supported, read/write and single use
  756. // transactions are not.
  757. TransactionSelector transaction = 2;
  758. // Required. The name of the table in the database to be read.
  759. string table = 3 [(google.api.field_behavior) = REQUIRED];
  760. // If non-empty, the name of an index on [table][google.spanner.v1.PartitionReadRequest.table]. This index is
  761. // used instead of the table primary key when interpreting [key_set][google.spanner.v1.PartitionReadRequest.key_set]
  762. // and sorting result rows. See [key_set][google.spanner.v1.PartitionReadRequest.key_set] for further information.
  763. string index = 4;
  764. // The columns of [table][google.spanner.v1.PartitionReadRequest.table] to be returned for each row matching
  765. // this request.
  766. repeated string columns = 5;
  767. // Required. `key_set` identifies the rows to be yielded. `key_set` names the
  768. // primary keys of the rows in [table][google.spanner.v1.PartitionReadRequest.table] to be yielded, unless [index][google.spanner.v1.PartitionReadRequest.index]
  769. // is present. If [index][google.spanner.v1.PartitionReadRequest.index] is present, then [key_set][google.spanner.v1.PartitionReadRequest.key_set] instead names
  770. // index keys in [index][google.spanner.v1.PartitionReadRequest.index].
  771. //
  772. // It is not an error for the `key_set` to name rows that do not
  773. // exist in the database. Read yields nothing for nonexistent rows.
  774. KeySet key_set = 6 [(google.api.field_behavior) = REQUIRED];
  775. // Additional options that affect how many partitions are created.
  776. PartitionOptions partition_options = 9;
  777. }
  778. // Information returned for each partition returned in a
  779. // PartitionResponse.
  780. message Partition {
  781. // This token can be passed to Read, StreamingRead, ExecuteSql, or
  782. // ExecuteStreamingSql requests to restrict the results to those identified by
  783. // this partition token.
  784. bytes partition_token = 1;
  785. }
  786. // The response for [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery]
  787. // or [PartitionRead][google.spanner.v1.Spanner.PartitionRead]
  788. message PartitionResponse {
  789. // Partitions created by this request.
  790. repeated Partition partitions = 1;
  791. // Transaction created by this request.
  792. Transaction transaction = 2;
  793. }
  794. // The request for [Read][google.spanner.v1.Spanner.Read] and
  795. // [StreamingRead][google.spanner.v1.Spanner.StreamingRead].
  796. message ReadRequest {
  797. // Required. The session in which the read should be performed.
  798. string session = 1 [
  799. (google.api.field_behavior) = REQUIRED,
  800. (google.api.resource_reference) = {
  801. type: "spanner.googleapis.com/Session"
  802. }
  803. ];
  804. // The transaction to use. If none is provided, the default is a
  805. // temporary read-only transaction with strong concurrency.
  806. TransactionSelector transaction = 2;
  807. // Required. The name of the table in the database to be read.
  808. string table = 3 [(google.api.field_behavior) = REQUIRED];
  809. // If non-empty, the name of an index on [table][google.spanner.v1.ReadRequest.table]. This index is
  810. // used instead of the table primary key when interpreting [key_set][google.spanner.v1.ReadRequest.key_set]
  811. // and sorting result rows. See [key_set][google.spanner.v1.ReadRequest.key_set] for further information.
  812. string index = 4;
  813. // Required. The columns of [table][google.spanner.v1.ReadRequest.table] to be returned for each row matching
  814. // this request.
  815. repeated string columns = 5 [(google.api.field_behavior) = REQUIRED];
  816. // Required. `key_set` identifies the rows to be yielded. `key_set` names the
  817. // primary keys of the rows in [table][google.spanner.v1.ReadRequest.table] to be yielded, unless [index][google.spanner.v1.ReadRequest.index]
  818. // is present. If [index][google.spanner.v1.ReadRequest.index] is present, then [key_set][google.spanner.v1.ReadRequest.key_set] instead names
  819. // index keys in [index][google.spanner.v1.ReadRequest.index].
  820. //
  821. // If the [partition_token][google.spanner.v1.ReadRequest.partition_token] field is empty, rows are yielded
  822. // in table primary key order (if [index][google.spanner.v1.ReadRequest.index] is empty) or index key order
  823. // (if [index][google.spanner.v1.ReadRequest.index] is non-empty). If the [partition_token][google.spanner.v1.ReadRequest.partition_token] field is not
  824. // empty, rows will be yielded in an unspecified order.
  825. //
  826. // It is not an error for the `key_set` to name rows that do not
  827. // exist in the database. Read yields nothing for nonexistent rows.
  828. KeySet key_set = 6 [(google.api.field_behavior) = REQUIRED];
  829. // If greater than zero, only the first `limit` rows are yielded. If `limit`
  830. // is zero, the default is no limit. A limit cannot be specified if
  831. // `partition_token` is set.
  832. int64 limit = 8;
  833. // If this request is resuming a previously interrupted read,
  834. // `resume_token` should be copied from the last
  835. // [PartialResultSet][google.spanner.v1.PartialResultSet] yielded before the interruption. Doing this
  836. // enables the new read to resume where the last read left off. The
  837. // rest of the request parameters must exactly match the request
  838. // that yielded this token.
  839. bytes resume_token = 9;
  840. // If present, results will be restricted to the specified partition
  841. // previously created using PartitionRead(). There must be an exact
  842. // match for the values of fields common to this message and the
  843. // PartitionReadRequest message used to create this partition_token.
  844. bytes partition_token = 10;
  845. // Common options for this request.
  846. RequestOptions request_options = 11;
  847. }
  848. // The request for [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction].
  849. message BeginTransactionRequest {
  850. // Required. The session in which the transaction runs.
  851. string session = 1 [
  852. (google.api.field_behavior) = REQUIRED,
  853. (google.api.resource_reference) = {
  854. type: "spanner.googleapis.com/Session"
  855. }
  856. ];
  857. // Required. Options for the new transaction.
  858. TransactionOptions options = 2 [(google.api.field_behavior) = REQUIRED];
  859. // Common options for this request.
  860. // Priority is ignored for this request. Setting the priority in this
  861. // request_options struct will not do anything. To set the priority for a
  862. // transaction, set it on the reads and writes that are part of this
  863. // transaction instead.
  864. RequestOptions request_options = 3;
  865. }
  866. // The request for [Commit][google.spanner.v1.Spanner.Commit].
  867. message CommitRequest {
  868. // Required. The session in which the transaction to be committed is running.
  869. string session = 1 [
  870. (google.api.field_behavior) = REQUIRED,
  871. (google.api.resource_reference) = {
  872. type: "spanner.googleapis.com/Session"
  873. }
  874. ];
  875. // Required. The transaction in which to commit.
  876. oneof transaction {
  877. // Commit a previously-started transaction.
  878. bytes transaction_id = 2;
  879. // Execute mutations in a temporary transaction. Note that unlike
  880. // commit of a previously-started transaction, commit with a
  881. // temporary transaction is non-idempotent. That is, if the
  882. // `CommitRequest` is sent to Cloud Spanner more than once (for
  883. // instance, due to retries in the application, or in the
  884. // transport library), it is possible that the mutations are
  885. // executed more than once. If this is undesirable, use
  886. // [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction] and
  887. // [Commit][google.spanner.v1.Spanner.Commit] instead.
  888. TransactionOptions single_use_transaction = 3;
  889. }
  890. // The mutations to be executed when this transaction commits. All
  891. // mutations are applied atomically, in the order they appear in
  892. // this list.
  893. repeated Mutation mutations = 4;
  894. // If `true`, then statistics related to the transaction will be included in
  895. // the [CommitResponse][google.spanner.v1.CommitResponse.commit_stats]. Default value is
  896. // `false`.
  897. bool return_commit_stats = 5;
  898. // Common options for this request.
  899. RequestOptions request_options = 6;
  900. }
  901. // The request for [Rollback][google.spanner.v1.Spanner.Rollback].
  902. message RollbackRequest {
  903. // Required. The session in which the transaction to roll back is running.
  904. string session = 1 [
  905. (google.api.field_behavior) = REQUIRED,
  906. (google.api.resource_reference) = {
  907. type: "spanner.googleapis.com/Session"
  908. }
  909. ];
  910. // Required. The transaction to roll back.
  911. bytes transaction_id = 2 [(google.api.field_behavior) = REQUIRED];
  912. }