github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/opt/props/physical/provided.go (about) 1 // Copyright 2018 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package physical 12 13 import ( 14 "bytes" 15 16 "github.com/cockroachdb/cockroach/pkg/sql/opt" 17 ) 18 19 // Provided physical properties of an operator. An operator might be able to 20 // satisfy a required property in multiple ways, and additional information is 21 // necessary for execution. For example, the required properties may allow 22 // multiple ordering choices; the provided properties would describe the 23 // specific ordering that has to be respected during execution. 24 // 25 // Provided properties are derived bottom-up (on the lowest cost tree). 26 type Provided struct { 27 // Ordering is an ordering that needs to be maintained on the rows produced by 28 // this operator in order to satisfy its required ordering. This is useful for 29 // configuring execution in a distributed setting, where results from multiple 30 // nodes may need to be merged. A best-effort attempt is made to have as few 31 // columns as possible. 32 // 33 // The ordering, in conjunction with the functional dependencies (in the 34 // logical properties), must intersect the required ordering. 35 // 36 // See the documentation for the opt/ordering package for some examples. 37 Ordering opt.Ordering 38 39 // Note: we store a Provided structure in-place within each group because the 40 // struct is very small (see memo.bestProps). If we add more fields here, that 41 // decision needs to be revisited. 42 } 43 44 // Equals returns true if the two sets of provided properties are identical. 45 func (p *Provided) Equals(other *Provided) bool { 46 return p.Ordering.Equals(other.Ordering) 47 } 48 49 func (p *Provided) String() string { 50 var buf bytes.Buffer 51 52 if len(p.Ordering) > 0 { 53 buf.WriteString("[ordering: ") 54 p.Ordering.Format(&buf) 55 buf.WriteByte(']') 56 } 57 58 return buf.String() 59 }