github.com/dolthub/go-mysql-server@v0.18.0/sql/plan/range_heap.go (about) 1 // Copyright 2023 Dolthub, Inc. 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 15 package plan 16 17 import ( 18 "fmt" 19 20 "github.com/dolthub/go-mysql-server/sql" 21 "github.com/dolthub/go-mysql-server/sql/expression" 22 ) 23 24 // RangeHeap is a Node that wraps a table with min and max range columns. When used as a secondary provider in Join 25 // operations, it can efficiently compute the rows whose ranges bound the value from the other table. When the ranges 26 // don't overlap, the amortized complexity is O(1) for each result row. 27 type RangeHeap struct { 28 UnaryNode 29 ValueColumnIndex int 30 MinColumnIndex int 31 MaxColumnIndex int 32 ValueColumnGf sql.Expression 33 MinColumnGf sql.Expression 34 MaxColumnGf sql.Expression 35 ComparisonType sql.Type 36 RangeIsClosedBelow bool 37 RangeIsClosedAbove bool 38 } 39 40 var _ sql.Node = (*RangeHeap)(nil) 41 42 func NewRangeHeap(child sql.Node, value, min, max *expression.GetField, rangeIsClosedBelow, rangeIsClosedAbove bool) (*RangeHeap, error) { 43 newSr := &RangeHeap{ 44 RangeIsClosedBelow: rangeIsClosedBelow, 45 RangeIsClosedAbove: rangeIsClosedAbove, 46 ValueColumnGf: value, 47 MinColumnGf: min, 48 MaxColumnGf: max, 49 } 50 newSr.Child = child 51 return newSr, nil 52 } 53 54 func (s *RangeHeap) String() string { 55 return s.Child.String() 56 } 57 58 func (s *RangeHeap) DebugString() string { 59 return sql.DebugString(s.Child) 60 } 61 62 func (s *RangeHeap) IsReadOnly() bool { 63 return s.Child.IsReadOnly() 64 } 65 66 func (s *RangeHeap) WithChildren(children ...sql.Node) (sql.Node, error) { 67 if len(children) != 1 { 68 return nil, fmt.Errorf("ds") 69 } 70 71 s2 := *s 72 s2.UnaryNode = UnaryNode{Child: children[0]} 73 return &s2, nil 74 } 75 76 func (s *RangeHeap) CheckPrivileges(ctx *sql.Context, opChecker sql.PrivilegedOperationChecker) bool { 77 return s.Child.CheckPrivileges(ctx, opChecker) 78 } 79 80 var _ sql.Node = (*RangeHeap)(nil)