spanner.proto 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  1. // Copyright 2022 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 "google/api/annotations.proto";
  17. import "google/api/client.proto";
  18. import "google/api/field_behavior.proto";
  19. import "google/api/resource.proto";
  20. import "google/protobuf/empty.proto";
  21. import "google/protobuf/struct.proto";
  22. import "google/protobuf/timestamp.proto";
  23. import "google/rpc/status.proto";
  24. import public "google/spanner/v1/commit_response.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. // Required. The session to create.
  282. Session session = 2 [(google.api.field_behavior) = REQUIRED];
  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. // The database role which created this session.
  331. string creator_role = 5;
  332. }
  333. // The request for [GetSession][google.spanner.v1.Spanner.GetSession].
  334. message GetSessionRequest {
  335. // Required. The name of the session to retrieve.
  336. string name = 1 [
  337. (google.api.field_behavior) = REQUIRED,
  338. (google.api.resource_reference) = {
  339. type: "spanner.googleapis.com/Session"
  340. }
  341. ];
  342. }
  343. // The request for [ListSessions][google.spanner.v1.Spanner.ListSessions].
  344. message ListSessionsRequest {
  345. // Required. The database in which to list sessions.
  346. string database = 1 [
  347. (google.api.field_behavior) = REQUIRED,
  348. (google.api.resource_reference) = {
  349. type: "spanner.googleapis.com/Database"
  350. }
  351. ];
  352. // Number of sessions to be returned in the response. If 0 or less, defaults
  353. // to the server's maximum allowed page size.
  354. int32 page_size = 2;
  355. // If non-empty, `page_token` should contain a
  356. // [next_page_token][google.spanner.v1.ListSessionsResponse.next_page_token] from a previous
  357. // [ListSessionsResponse][google.spanner.v1.ListSessionsResponse].
  358. string page_token = 3;
  359. // An expression for filtering the results of the request. Filter rules are
  360. // case insensitive. The fields eligible for filtering are:
  361. //
  362. // * `labels.key` where key is the name of a label
  363. //
  364. // Some examples of using filters are:
  365. //
  366. // * `labels.env:*` --> The session has the label "env".
  367. // * `labels.env:dev` --> The session has the label "env" and the value of
  368. // the label contains the string "dev".
  369. string filter = 4;
  370. }
  371. // The response for [ListSessions][google.spanner.v1.Spanner.ListSessions].
  372. message ListSessionsResponse {
  373. // The list of requested sessions.
  374. repeated Session sessions = 1;
  375. // `next_page_token` can be sent in a subsequent
  376. // [ListSessions][google.spanner.v1.Spanner.ListSessions] call to fetch more of the matching
  377. // sessions.
  378. string next_page_token = 2;
  379. }
  380. // The request for [DeleteSession][google.spanner.v1.Spanner.DeleteSession].
  381. message DeleteSessionRequest {
  382. // Required. The name of the session to delete.
  383. string name = 1 [
  384. (google.api.field_behavior) = REQUIRED,
  385. (google.api.resource_reference) = {
  386. type: "spanner.googleapis.com/Session"
  387. }
  388. ];
  389. }
  390. // Common request options for various APIs.
  391. message RequestOptions {
  392. // The relative priority for requests. Note that priority is not applicable
  393. // for [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction].
  394. //
  395. // The priority acts as a hint to the Cloud Spanner scheduler and does not
  396. // guarantee priority or order of execution. For example:
  397. //
  398. // * Some parts of a write operation always execute at `PRIORITY_HIGH`,
  399. // regardless of the specified priority. This may cause you to see an
  400. // increase in high priority workload even when executing a low priority
  401. // request. This can also potentially cause a priority inversion where a
  402. // lower priority request will be fulfilled ahead of a higher priority
  403. // request.
  404. // * If a transaction contains multiple operations with different priorities,
  405. // Cloud Spanner does not guarantee to process the higher priority
  406. // operations first. There may be other constraints to satisfy, such as
  407. // order of operations.
  408. enum Priority {
  409. // `PRIORITY_UNSPECIFIED` is equivalent to `PRIORITY_HIGH`.
  410. PRIORITY_UNSPECIFIED = 0;
  411. // This specifies that the request is low priority.
  412. PRIORITY_LOW = 1;
  413. // This specifies that the request is medium priority.
  414. PRIORITY_MEDIUM = 2;
  415. // This specifies that the request is high priority.
  416. PRIORITY_HIGH = 3;
  417. }
  418. // Priority for the request.
  419. Priority priority = 1;
  420. // A per-request tag which can be applied to queries or reads, used for
  421. // statistics collection.
  422. // Both request_tag and transaction_tag can be specified for a read or query
  423. // that belongs to a transaction.
  424. // This field is ignored for requests where it's not applicable (e.g.
  425. // CommitRequest).
  426. // Legal characters for `request_tag` values are all printable characters
  427. // (ASCII 32 - 126) and the length of a request_tag is limited to 50
  428. // characters. Values that exceed this limit are truncated.
  429. // Any leading underscore (_) characters will be removed from the string.
  430. string request_tag = 2;
  431. // A tag used for statistics collection about this transaction.
  432. // Both request_tag and transaction_tag can be specified for a read or query
  433. // that belongs to a transaction.
  434. // The value of transaction_tag should be the same for all requests belonging
  435. // to the same transaction.
  436. // If this request doesn't belong to any transaction, transaction_tag will be
  437. // ignored.
  438. // Legal characters for `transaction_tag` values are all printable characters
  439. // (ASCII 32 - 126) and the length of a transaction_tag is limited to 50
  440. // characters. Values that exceed this limit are truncated.
  441. // Any leading underscore (_) characters will be removed from the string.
  442. string transaction_tag = 3;
  443. }
  444. // The request for [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and
  445. // [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql].
  446. message ExecuteSqlRequest {
  447. // Mode in which the statement must be processed.
  448. enum QueryMode {
  449. // The default mode. Only the statement results are returned.
  450. NORMAL = 0;
  451. // This mode returns only the query plan, without any results or
  452. // execution statistics information.
  453. PLAN = 1;
  454. // This mode returns both the query plan and the execution statistics along
  455. // with the results.
  456. PROFILE = 2;
  457. }
  458. // Query optimizer configuration.
  459. message QueryOptions {
  460. // An option to control the selection of optimizer version.
  461. //
  462. // This parameter allows individual queries to pick different query
  463. // optimizer versions.
  464. //
  465. // Specifying `latest` as a value instructs Cloud Spanner to use the
  466. // latest supported query optimizer version. If not specified, Cloud Spanner
  467. // uses the optimizer version set at the database level options. Any other
  468. // positive integer (from the list of supported optimizer versions)
  469. // overrides the default optimizer version for query execution.
  470. //
  471. // The list of supported optimizer versions can be queried from
  472. // SPANNER_SYS.SUPPORTED_OPTIMIZER_VERSIONS.
  473. //
  474. // Executing a SQL statement with an invalid optimizer version fails with
  475. // an `INVALID_ARGUMENT` error.
  476. //
  477. // See
  478. // https://cloud.google.com/spanner/docs/query-optimizer/manage-query-optimizer
  479. // for more information on managing the query optimizer.
  480. //
  481. // The `optimizer_version` statement hint has precedence over this setting.
  482. string optimizer_version = 1;
  483. // An option to control the selection of optimizer statistics package.
  484. //
  485. // This parameter allows individual queries to use a different query
  486. // optimizer statistics package.
  487. //
  488. // Specifying `latest` as a value instructs Cloud Spanner to use the latest
  489. // generated statistics package. If not specified, Cloud Spanner uses
  490. // the statistics package set at the database level options, or the latest
  491. // package if the database option is not set.
  492. //
  493. // The statistics package requested by the query has to be exempt from
  494. // garbage collection. This can be achieved with the following DDL
  495. // statement:
  496. //
  497. // ```
  498. // ALTER STATISTICS <package_name> SET OPTIONS (allow_gc=false)
  499. // ```
  500. //
  501. // The list of available statistics packages can be queried from
  502. // `INFORMATION_SCHEMA.SPANNER_STATISTICS`.
  503. //
  504. // Executing a SQL statement with an invalid optimizer statistics package
  505. // or with a statistics package that allows garbage collection fails with
  506. // an `INVALID_ARGUMENT` error.
  507. string optimizer_statistics_package = 2;
  508. }
  509. // Required. The session in which the SQL query should be performed.
  510. string session = 1 [
  511. (google.api.field_behavior) = REQUIRED,
  512. (google.api.resource_reference) = {
  513. type: "spanner.googleapis.com/Session"
  514. }
  515. ];
  516. // The transaction to use.
  517. //
  518. // For queries, if none is provided, the default is a temporary read-only
  519. // transaction with strong concurrency.
  520. //
  521. // Standard DML statements require a read-write transaction. To protect
  522. // against replays, single-use transactions are not supported. The caller
  523. // must either supply an existing transaction ID or begin a new transaction.
  524. //
  525. // Partitioned DML requires an existing Partitioned DML transaction ID.
  526. TransactionSelector transaction = 2;
  527. // Required. The SQL string.
  528. string sql = 3 [(google.api.field_behavior) = REQUIRED];
  529. // Parameter names and values that bind to placeholders in the SQL string.
  530. //
  531. // A parameter placeholder consists of the `@` character followed by the
  532. // parameter name (for example, `@firstName`). Parameter names must conform
  533. // to the naming requirements of identifiers as specified at
  534. // https://cloud.google.com/spanner/docs/lexical#identifiers.
  535. //
  536. // Parameters can appear anywhere that a literal value is expected. The same
  537. // parameter name can be used more than once, for example:
  538. //
  539. // `"WHERE id > @msg_id AND id < @msg_id + 100"`
  540. //
  541. // It is an error to execute a SQL statement with unbound parameters.
  542. google.protobuf.Struct params = 4;
  543. // It is not always possible for Cloud Spanner to infer the right SQL type
  544. // from a JSON value. For example, values of type `BYTES` and values
  545. // of type `STRING` both appear in [params][google.spanner.v1.ExecuteSqlRequest.params] as JSON strings.
  546. //
  547. // In these cases, `param_types` can be used to specify the exact
  548. // SQL type for some or all of the SQL statement parameters. See the
  549. // definition of [Type][google.spanner.v1.Type] for more information
  550. // about SQL types.
  551. map<string, Type> param_types = 5;
  552. // If this request is resuming a previously interrupted SQL statement
  553. // execution, `resume_token` should be copied from the last
  554. // [PartialResultSet][google.spanner.v1.PartialResultSet] yielded before the interruption. Doing this
  555. // enables the new SQL statement execution to resume where the last one left
  556. // off. The rest of the request parameters must exactly match the
  557. // request that yielded this token.
  558. bytes resume_token = 6;
  559. // Used to control the amount of debugging information returned in
  560. // [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
  561. // be set to [QueryMode.NORMAL][google.spanner.v1.ExecuteSqlRequest.QueryMode.NORMAL].
  562. QueryMode query_mode = 7;
  563. // If present, results will be restricted to the specified partition
  564. // previously created using PartitionQuery(). There must be an exact
  565. // match for the values of fields common to this message and the
  566. // PartitionQueryRequest message used to create this partition_token.
  567. bytes partition_token = 8;
  568. // A per-transaction sequence number used to identify this request. This field
  569. // makes each request idempotent such that if the request is received multiple
  570. // times, at most one will succeed.
  571. //
  572. // The sequence number must be monotonically increasing within the
  573. // transaction. If a request arrives for the first time with an out-of-order
  574. // sequence number, the transaction may be aborted. Replays of previously
  575. // handled requests will yield the same response as the first execution.
  576. //
  577. // Required for DML statements. Ignored for queries.
  578. int64 seqno = 9;
  579. // Query optimizer configuration to use for the given query.
  580. QueryOptions query_options = 10;
  581. // Common options for this request.
  582. RequestOptions request_options = 11;
  583. }
  584. // The request for [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml].
  585. message ExecuteBatchDmlRequest {
  586. // A single DML statement.
  587. message Statement {
  588. // Required. The DML string.
  589. string sql = 1 [(google.api.field_behavior) = REQUIRED];
  590. // Parameter names and values that bind to placeholders in the DML string.
  591. //
  592. // A parameter placeholder consists of the `@` character followed by the
  593. // parameter name (for example, `@firstName`). Parameter names can contain
  594. // letters, numbers, and underscores.
  595. //
  596. // Parameters can appear anywhere that a literal value is expected. The
  597. // same parameter name can be used more than once, for example:
  598. //
  599. // `"WHERE id > @msg_id AND id < @msg_id + 100"`
  600. //
  601. // It is an error to execute a SQL statement with unbound parameters.
  602. google.protobuf.Struct params = 2;
  603. // It is not always possible for Cloud Spanner to infer the right SQL type
  604. // from a JSON value. For example, values of type `BYTES` and values
  605. // of type `STRING` both appear in [params][google.spanner.v1.ExecuteBatchDmlRequest.Statement.params] as JSON strings.
  606. //
  607. // In these cases, `param_types` can be used to specify the exact
  608. // SQL type for some or all of the SQL statement parameters. See the
  609. // definition of [Type][google.spanner.v1.Type] for more information
  610. // about SQL types.
  611. map<string, Type> param_types = 3;
  612. }
  613. // Required. The session in which the DML statements should be performed.
  614. string session = 1 [
  615. (google.api.field_behavior) = REQUIRED,
  616. (google.api.resource_reference) = {
  617. type: "spanner.googleapis.com/Session"
  618. }
  619. ];
  620. // Required. The transaction to use. Must be a read-write transaction.
  621. //
  622. // To protect against replays, single-use transactions are not supported. The
  623. // caller must either supply an existing transaction ID or begin a new
  624. // transaction.
  625. TransactionSelector transaction = 2 [(google.api.field_behavior) = REQUIRED];
  626. // Required. The list of statements to execute in this batch. Statements are executed
  627. // serially, such that the effects of statement `i` are visible to statement
  628. // `i+1`. Each statement must be a DML statement. Execution stops at the
  629. // first failed statement; the remaining statements are not executed.
  630. //
  631. // Callers must provide at least one statement.
  632. repeated Statement statements = 3 [(google.api.field_behavior) = REQUIRED];
  633. // Required. A per-transaction sequence number used to identify this request. This field
  634. // makes each request idempotent such that if the request is received multiple
  635. // times, at most one will succeed.
  636. //
  637. // The sequence number must be monotonically increasing within the
  638. // transaction. If a request arrives for the first time with an out-of-order
  639. // sequence number, the transaction may be aborted. Replays of previously
  640. // handled requests will yield the same response as the first execution.
  641. int64 seqno = 4 [(google.api.field_behavior) = REQUIRED];
  642. // Common options for this request.
  643. RequestOptions request_options = 5;
  644. }
  645. // The response for [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. Contains a list
  646. // of [ResultSet][google.spanner.v1.ResultSet] messages, one for each DML statement that has successfully
  647. // executed, in the same order as the statements in the request. If a statement
  648. // fails, the status in the response body identifies the cause of the failure.
  649. //
  650. // To check for DML statements that failed, use the following approach:
  651. //
  652. // 1. Check the status in the response message. The [google.rpc.Code][google.rpc.Code] enum
  653. // value `OK` indicates that all statements were executed successfully.
  654. // 2. If the status was not `OK`, check the number of result sets in the
  655. // response. If the response contains `N` [ResultSet][google.spanner.v1.ResultSet] messages, then
  656. // statement `N+1` in the request failed.
  657. //
  658. // Example 1:
  659. //
  660. // * Request: 5 DML statements, all executed successfully.
  661. // * Response: 5 [ResultSet][google.spanner.v1.ResultSet] messages, with the status `OK`.
  662. //
  663. // Example 2:
  664. //
  665. // * Request: 5 DML statements. The third statement has a syntax error.
  666. // * Response: 2 [ResultSet][google.spanner.v1.ResultSet] messages, and a syntax error (`INVALID_ARGUMENT`)
  667. // status. The number of [ResultSet][google.spanner.v1.ResultSet] messages indicates that the third
  668. // statement failed, and the fourth and fifth statements were not executed.
  669. message ExecuteBatchDmlResponse {
  670. // One [ResultSet][google.spanner.v1.ResultSet] for each statement in the request that ran successfully,
  671. // in the same order as the statements in the request. Each [ResultSet][google.spanner.v1.ResultSet] does
  672. // not contain any rows. The [ResultSetStats][google.spanner.v1.ResultSetStats] in each [ResultSet][google.spanner.v1.ResultSet] contain
  673. // the number of rows modified by the statement.
  674. //
  675. // Only the first [ResultSet][google.spanner.v1.ResultSet] in the response contains valid
  676. // [ResultSetMetadata][google.spanner.v1.ResultSetMetadata].
  677. repeated ResultSet result_sets = 1;
  678. // If all DML statements are executed successfully, the status is `OK`.
  679. // Otherwise, the error status of the first failed statement.
  680. google.rpc.Status status = 2;
  681. }
  682. // Options for a PartitionQueryRequest and
  683. // PartitionReadRequest.
  684. message PartitionOptions {
  685. // **Note:** This hint is currently ignored by PartitionQuery and
  686. // PartitionRead requests.
  687. //
  688. // The desired data size for each partition generated. The default for this
  689. // option is currently 1 GiB. This is only a hint. The actual size of each
  690. // partition may be smaller or larger than this size request.
  691. int64 partition_size_bytes = 1;
  692. // **Note:** This hint is currently ignored by PartitionQuery and
  693. // PartitionRead requests.
  694. //
  695. // The desired maximum number of partitions to return. For example, this may
  696. // be set to the number of workers available. The default for this option
  697. // is currently 10,000. The maximum value is currently 200,000. This is only
  698. // a hint. The actual number of partitions returned may be smaller or larger
  699. // than this maximum count request.
  700. int64 max_partitions = 2;
  701. }
  702. // The request for [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery]
  703. message PartitionQueryRequest {
  704. // Required. The session used to create the partitions.
  705. string session = 1 [
  706. (google.api.field_behavior) = REQUIRED,
  707. (google.api.resource_reference) = {
  708. type: "spanner.googleapis.com/Session"
  709. }
  710. ];
  711. // Read only snapshot transactions are supported, read/write and single use
  712. // transactions are not.
  713. TransactionSelector transaction = 2;
  714. // Required. The query request to generate partitions for. The request will fail if
  715. // the query is not root partitionable. The query plan of a root
  716. // partitionable query has a single distributed union operator. A distributed
  717. // union operator conceptually divides one or more tables into multiple
  718. // splits, remotely evaluates a subquery independently on each split, and
  719. // then unions all results.
  720. //
  721. // This must not contain DML commands, such as INSERT, UPDATE, or
  722. // DELETE. Use [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] with a
  723. // PartitionedDml transaction for large, partition-friendly DML operations.
  724. string sql = 3 [(google.api.field_behavior) = REQUIRED];
  725. // Parameter names and values that bind to placeholders in the SQL string.
  726. //
  727. // A parameter placeholder consists of the `@` character followed by the
  728. // parameter name (for example, `@firstName`). Parameter names can contain
  729. // letters, numbers, and underscores.
  730. //
  731. // Parameters can appear anywhere that a literal value is expected. The same
  732. // parameter name can be used more than once, for example:
  733. //
  734. // `"WHERE id > @msg_id AND id < @msg_id + 100"`
  735. //
  736. // It is an error to execute a SQL statement with unbound parameters.
  737. google.protobuf.Struct params = 4;
  738. // It is not always possible for Cloud Spanner to infer the right SQL type
  739. // from a JSON value. For example, values of type `BYTES` and values
  740. // of type `STRING` both appear in [params][google.spanner.v1.PartitionQueryRequest.params] as JSON strings.
  741. //
  742. // In these cases, `param_types` can be used to specify the exact
  743. // SQL type for some or all of the SQL query parameters. See the
  744. // definition of [Type][google.spanner.v1.Type] for more information
  745. // about SQL types.
  746. map<string, Type> param_types = 5;
  747. // Additional options that affect how many partitions are created.
  748. PartitionOptions partition_options = 6;
  749. }
  750. // The request for [PartitionRead][google.spanner.v1.Spanner.PartitionRead]
  751. message PartitionReadRequest {
  752. // Required. The session used to create the partitions.
  753. string session = 1 [
  754. (google.api.field_behavior) = REQUIRED,
  755. (google.api.resource_reference) = {
  756. type: "spanner.googleapis.com/Session"
  757. }
  758. ];
  759. // Read only snapshot transactions are supported, read/write and single use
  760. // transactions are not.
  761. TransactionSelector transaction = 2;
  762. // Required. The name of the table in the database to be read.
  763. string table = 3 [(google.api.field_behavior) = REQUIRED];
  764. // If non-empty, the name of an index on [table][google.spanner.v1.PartitionReadRequest.table]. This index is
  765. // used instead of the table primary key when interpreting [key_set][google.spanner.v1.PartitionReadRequest.key_set]
  766. // and sorting result rows. See [key_set][google.spanner.v1.PartitionReadRequest.key_set] for further information.
  767. string index = 4;
  768. // The columns of [table][google.spanner.v1.PartitionReadRequest.table] to be returned for each row matching
  769. // this request.
  770. repeated string columns = 5;
  771. // Required. `key_set` identifies the rows to be yielded. `key_set` names the
  772. // primary keys of the rows in [table][google.spanner.v1.PartitionReadRequest.table] to be yielded, unless [index][google.spanner.v1.PartitionReadRequest.index]
  773. // is present. If [index][google.spanner.v1.PartitionReadRequest.index] is present, then [key_set][google.spanner.v1.PartitionReadRequest.key_set] instead names
  774. // index keys in [index][google.spanner.v1.PartitionReadRequest.index].
  775. //
  776. // It is not an error for the `key_set` to name rows that do not
  777. // exist in the database. Read yields nothing for nonexistent rows.
  778. KeySet key_set = 6 [(google.api.field_behavior) = REQUIRED];
  779. // Additional options that affect how many partitions are created.
  780. PartitionOptions partition_options = 9;
  781. }
  782. // Information returned for each partition returned in a
  783. // PartitionResponse.
  784. message Partition {
  785. // This token can be passed to Read, StreamingRead, ExecuteSql, or
  786. // ExecuteStreamingSql requests to restrict the results to those identified by
  787. // this partition token.
  788. bytes partition_token = 1;
  789. }
  790. // The response for [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery]
  791. // or [PartitionRead][google.spanner.v1.Spanner.PartitionRead]
  792. message PartitionResponse {
  793. // Partitions created by this request.
  794. repeated Partition partitions = 1;
  795. // Transaction created by this request.
  796. Transaction transaction = 2;
  797. }
  798. // The request for [Read][google.spanner.v1.Spanner.Read] and
  799. // [StreamingRead][google.spanner.v1.Spanner.StreamingRead].
  800. message ReadRequest {
  801. // Required. The session in which the read should be performed.
  802. string session = 1 [
  803. (google.api.field_behavior) = REQUIRED,
  804. (google.api.resource_reference) = {
  805. type: "spanner.googleapis.com/Session"
  806. }
  807. ];
  808. // The transaction to use. If none is provided, the default is a
  809. // temporary read-only transaction with strong concurrency.
  810. TransactionSelector transaction = 2;
  811. // Required. The name of the table in the database to be read.
  812. string table = 3 [(google.api.field_behavior) = REQUIRED];
  813. // If non-empty, the name of an index on [table][google.spanner.v1.ReadRequest.table]. This index is
  814. // used instead of the table primary key when interpreting [key_set][google.spanner.v1.ReadRequest.key_set]
  815. // and sorting result rows. See [key_set][google.spanner.v1.ReadRequest.key_set] for further information.
  816. string index = 4;
  817. // Required. The columns of [table][google.spanner.v1.ReadRequest.table] to be returned for each row matching
  818. // this request.
  819. repeated string columns = 5 [(google.api.field_behavior) = REQUIRED];
  820. // Required. `key_set` identifies the rows to be yielded. `key_set` names the
  821. // primary keys of the rows in [table][google.spanner.v1.ReadRequest.table] to be yielded, unless [index][google.spanner.v1.ReadRequest.index]
  822. // is present. If [index][google.spanner.v1.ReadRequest.index] is present, then [key_set][google.spanner.v1.ReadRequest.key_set] instead names
  823. // index keys in [index][google.spanner.v1.ReadRequest.index].
  824. //
  825. // If the [partition_token][google.spanner.v1.ReadRequest.partition_token] field is empty, rows are yielded
  826. // in table primary key order (if [index][google.spanner.v1.ReadRequest.index] is empty) or index key order
  827. // (if [index][google.spanner.v1.ReadRequest.index] is non-empty). If the [partition_token][google.spanner.v1.ReadRequest.partition_token] field is not
  828. // empty, rows will be yielded in an unspecified order.
  829. //
  830. // It is not an error for the `key_set` to name rows that do not
  831. // exist in the database. Read yields nothing for nonexistent rows.
  832. KeySet key_set = 6 [(google.api.field_behavior) = REQUIRED];
  833. // If greater than zero, only the first `limit` rows are yielded. If `limit`
  834. // is zero, the default is no limit. A limit cannot be specified if
  835. // `partition_token` is set.
  836. int64 limit = 8;
  837. // If this request is resuming a previously interrupted read,
  838. // `resume_token` should be copied from the last
  839. // [PartialResultSet][google.spanner.v1.PartialResultSet] yielded before the interruption. Doing this
  840. // enables the new read to resume where the last read left off. The
  841. // rest of the request parameters must exactly match the request
  842. // that yielded this token.
  843. bytes resume_token = 9;
  844. // If present, results will be restricted to the specified partition
  845. // previously created using PartitionRead(). There must be an exact
  846. // match for the values of fields common to this message and the
  847. // PartitionReadRequest message used to create this partition_token.
  848. bytes partition_token = 10;
  849. // Common options for this request.
  850. RequestOptions request_options = 11;
  851. }
  852. // The request for [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction].
  853. message BeginTransactionRequest {
  854. // Required. The session in which the transaction runs.
  855. string session = 1 [
  856. (google.api.field_behavior) = REQUIRED,
  857. (google.api.resource_reference) = {
  858. type: "spanner.googleapis.com/Session"
  859. }
  860. ];
  861. // Required. Options for the new transaction.
  862. TransactionOptions options = 2 [(google.api.field_behavior) = REQUIRED];
  863. // Common options for this request.
  864. // Priority is ignored for this request. Setting the priority in this
  865. // request_options struct will not do anything. To set the priority for a
  866. // transaction, set it on the reads and writes that are part of this
  867. // transaction instead.
  868. RequestOptions request_options = 3;
  869. }
  870. // The request for [Commit][google.spanner.v1.Spanner.Commit].
  871. message CommitRequest {
  872. // Required. The session in which the transaction to be committed is running.
  873. string session = 1 [
  874. (google.api.field_behavior) = REQUIRED,
  875. (google.api.resource_reference) = {
  876. type: "spanner.googleapis.com/Session"
  877. }
  878. ];
  879. // Required. The transaction in which to commit.
  880. oneof transaction {
  881. // Commit a previously-started transaction.
  882. bytes transaction_id = 2;
  883. // Execute mutations in a temporary transaction. Note that unlike
  884. // commit of a previously-started transaction, commit with a
  885. // temporary transaction is non-idempotent. That is, if the
  886. // `CommitRequest` is sent to Cloud Spanner more than once (for
  887. // instance, due to retries in the application, or in the
  888. // transport library), it is possible that the mutations are
  889. // executed more than once. If this is undesirable, use
  890. // [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction] and
  891. // [Commit][google.spanner.v1.Spanner.Commit] instead.
  892. TransactionOptions single_use_transaction = 3;
  893. }
  894. // The mutations to be executed when this transaction commits. All
  895. // mutations are applied atomically, in the order they appear in
  896. // this list.
  897. repeated Mutation mutations = 4;
  898. // If `true`, then statistics related to the transaction will be included in
  899. // the [CommitResponse][google.spanner.v1.CommitResponse.commit_stats]. Default value is
  900. // `false`.
  901. bool return_commit_stats = 5;
  902. // Common options for this request.
  903. RequestOptions request_options = 6;
  904. }
  905. // The request for [Rollback][google.spanner.v1.Spanner.Rollback].
  906. message RollbackRequest {
  907. // Required. The session in which the transaction to roll back is running.
  908. string session = 1 [
  909. (google.api.field_behavior) = REQUIRED,
  910. (google.api.resource_reference) = {
  911. type: "spanner.googleapis.com/Session"
  912. }
  913. ];
  914. // Required. The transaction to roll back.
  915. bytes transaction_id = 2 [(google.api.field_behavior) = REQUIRED];
  916. }