vitess.io/vitess@v0.16.2/go/vt/vtgate/planbuilder/operators/correlated_subquery.go (about) 1 /* 2 Copyright 2022 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package operators 18 19 import ( 20 "vitess.io/vitess/go/vt/sqlparser" 21 "vitess.io/vitess/go/vt/vtgate/planbuilder/operators/ops" 22 ) 23 24 type ( 25 CorrelatedSubQueryOp struct { 26 Outer, Inner ops.Operator 27 Extracted *sqlparser.ExtractedSubquery 28 29 // JoinCols are the columns from the LHS used for the join. 30 // These are the same columns pushed on the LHS that are now used in the Vars field 31 LHSColumns []*sqlparser.ColName 32 33 // arguments that need to be copied from the outer to inner 34 Vars map[string]int 35 36 noColumns 37 noPredicates 38 } 39 40 SubQueryOp struct { 41 Outer, Inner ops.Operator 42 Extracted *sqlparser.ExtractedSubquery 43 44 noColumns 45 noPredicates 46 } 47 ) 48 49 var _ ops.PhysicalOperator = (*SubQueryOp)(nil) 50 var _ ops.PhysicalOperator = (*CorrelatedSubQueryOp)(nil) 51 52 // IPhysical implements the PhysicalOperator interface 53 func (s *SubQueryOp) IPhysical() {} 54 55 // Clone implements the Operator interface 56 func (s *SubQueryOp) Clone(inputs []ops.Operator) ops.Operator { 57 result := &SubQueryOp{ 58 Outer: inputs[0], 59 Inner: inputs[1], 60 Extracted: s.Extracted, 61 } 62 return result 63 } 64 65 // Inputs implements the Operator interface 66 func (s *SubQueryOp) Inputs() []ops.Operator { 67 return []ops.Operator{s.Outer, s.Inner} 68 } 69 70 // IPhysical implements the PhysicalOperator interface 71 func (c *CorrelatedSubQueryOp) IPhysical() {} 72 73 // Clone implements the Operator interface 74 func (c *CorrelatedSubQueryOp) Clone(inputs []ops.Operator) ops.Operator { 75 columns := make([]*sqlparser.ColName, len(c.LHSColumns)) 76 copy(columns, c.LHSColumns) 77 vars := make(map[string]int, len(c.Vars)) 78 for k, v := range c.Vars { 79 vars[k] = v 80 } 81 82 result := &CorrelatedSubQueryOp{ 83 Outer: inputs[0], 84 Inner: inputs[1], 85 Extracted: c.Extracted, 86 LHSColumns: columns, 87 Vars: vars, 88 } 89 return result 90 } 91 92 // Inputs implements the Operator interface 93 func (c *CorrelatedSubQueryOp) Inputs() []ops.Operator { 94 return []ops.Operator{c.Outer, c.Inner} 95 }