github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/opt/memo/group.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 memo 12 13 import ( 14 "github.com/cockroachdb/cockroach/pkg/sql/opt/props" 15 "github.com/cockroachdb/cockroach/pkg/sql/opt/props/physical" 16 ) 17 18 // exprGroup represents a group of relational query plans that are logically 19 // equivalent to on another. The group points to the first member of the group, 20 // and subsequent members can be accessed via calls to RelExpr.NextExpr. The 21 // group maintains the logical properties shared by members of the group, as 22 // well as the physical properties and cost of the best expression in the group 23 // once optimization is complete. 24 // 25 // See comments for Memo, RelExpr, Relational, and Physical for more details. 26 type exprGroup interface { 27 // memo is the memo which contains the group. 28 memo() *Memo 29 30 // firstExpr points to the first member expression in the group. Other members 31 // of the group can be accessed via calls to RelExpr.NextExpr. 32 firstExpr() RelExpr 33 34 // relational are the relational properties shared by members of the group. 35 relational() *props.Relational 36 37 // bestProps returns a per-group instance of bestProps. This is the zero 38 // value until optimization is complete. 39 bestProps() *bestProps 40 } 41 42 // bestProps contains the properties of the "best" expression in group. The best 43 // expression is the expression which is part of the lowest-cost tree for the 44 // overall query. It is well-defined because the lowest-cost tree does not 45 // contain multiple expressions from the same group. 46 // 47 // These are not properties of the group per se but they are stored within each 48 // group for efficiency. 49 type bestProps struct { 50 // Required properties with respect to which the best expression was 51 // optimized. 52 required *physical.Required 53 54 // Provided properties, which must be compatible with the required properties. 55 // 56 // We store these properties in-place because the structure is very small; if 57 // that changes we will want to intern them, similar to the required 58 // properties. 59 provided physical.Provided 60 61 // Cost of the best expression. 62 cost Cost 63 }