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 15syntax = "proto3"; 16 17package google.spanner.v1; 18 19import "google/protobuf/struct.proto"; 20 21option csharp_namespace = "Google.Cloud.Spanner.V1"; 22option go_package = "cloud.google.com/go/spanner/apiv1/spannerpb;spannerpb"; 23option java_multiple_files = true; 24option java_outer_classname = "QueryPlanProto"; 25option java_package = "com.google.spanner.v1"; 26option php_namespace = "Google\\Cloud\\Spanner\\V1"; 27option ruby_package = "Google::Cloud::Spanner::V1"; 28 29// Node information for nodes appearing in a [QueryPlan.plan_nodes][google.spanner.v1.QueryPlan.plan_nodes]. 30message PlanNode { 31 // The kind of [PlanNode][google.spanner.v1.PlanNode]. Distinguishes between the two different kinds of 32 // nodes that can appear in a query plan. 33 enum Kind { 34 // Not specified. 35 KIND_UNSPECIFIED = 0; 36 37 // Denotes a Relational operator node in the expression tree. Relational 38 // operators represent iterative processing of rows during query execution. 39 // For example, a `TableScan` operation that reads rows from a table. 40 RELATIONAL = 1; 41 42 // Denotes a Scalar node in the expression tree. Scalar nodes represent 43 // non-iterable entities in the query plan. For example, constants or 44 // arithmetic operators appearing inside predicate expressions or references 45 // to column names. 46 SCALAR = 2; 47 } 48 49 // Metadata associated with a parent-child relationship appearing in a 50 // [PlanNode][google.spanner.v1.PlanNode]. 51 message ChildLink { 52 // The node to which the link points. 53 int32 child_index = 1; 54 55 // The type of the link. For example, in Hash Joins this could be used to 56 // distinguish between the build child and the probe child, or in the case 57 // of the child being an output variable, to represent the tag associated 58 // with the output variable. 59 string type = 2; 60 61 // Only present if the child node is [SCALAR][google.spanner.v1.PlanNode.Kind.SCALAR] and corresponds 62 // to an output variable of the parent node. The field carries the name of 63 // the output variable. 64 // For example, a `TableScan` operator that reads rows from a table will 65 // have child links to the `SCALAR` nodes representing the output variables 66 // created for each column that is read by the operator. The corresponding 67 // `variable` fields will be set to the variable names assigned to the 68 // columns. 69 string variable = 3; 70 } 71 72 // Condensed representation of a node and its subtree. Only present for 73 // `SCALAR` [PlanNode(s)][google.spanner.v1.PlanNode]. 74 message ShortRepresentation { 75 // A string representation of the expression subtree rooted at this node. 76 string description = 1; 77 78 // A mapping of (subquery variable name) -> (subquery node id) for cases 79 // where the `description` string of this node references a `SCALAR` 80 // subquery contained in the expression subtree rooted at this node. The 81 // referenced `SCALAR` subquery may not necessarily be a direct child of 82 // this node. 83 map<string, int32> subqueries = 2; 84 } 85 86 // The `PlanNode`'s index in [node list][google.spanner.v1.QueryPlan.plan_nodes]. 87 int32 index = 1; 88 89 // Used to determine the type of node. May be needed for visualizing 90 // different kinds of nodes differently. For example, If the node is a 91 // [SCALAR][google.spanner.v1.PlanNode.Kind.SCALAR] node, it will have a condensed representation 92 // which can be used to directly embed a description of the node in its 93 // parent. 94 Kind kind = 2; 95 96 // The display name for the node. 97 string display_name = 3; 98 99 // List of child node `index`es and their relationship to this parent. 100 repeated ChildLink child_links = 4; 101 102 // Condensed representation for [SCALAR][google.spanner.v1.PlanNode.Kind.SCALAR] nodes. 103 ShortRepresentation short_representation = 5; 104 105 // Attributes relevant to the node contained in a group of key-value pairs. 106 // For example, a Parameter Reference node could have the following 107 // information in its metadata: 108 // 109 // { 110 // "parameter_reference": "param1", 111 // "parameter_type": "array" 112 // } 113 google.protobuf.Struct metadata = 6; 114 115 // The execution statistics associated with the node, contained in a group of 116 // key-value pairs. Only present if the plan was returned as a result of a 117 // profile query. For example, number of executions, number of rows/time per 118 // execution etc. 119 google.protobuf.Struct execution_stats = 7; 120} 121 122// Contains an ordered list of nodes appearing in the query plan. 123message QueryPlan { 124 // The nodes in the query plan. Plan nodes are returned in pre-order starting 125 // with the plan root. Each [PlanNode][google.spanner.v1.PlanNode]'s `id` corresponds to its index in 126 // `plan_nodes`. 127 repeated PlanNode plan_nodes = 1; 128} 129