github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/filter.go (about) 1 // Copyright 2016 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 sql 12 13 import ( 14 "context" 15 16 "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" 17 "github.com/cockroachdb/cockroach/pkg/sql/types" 18 ) 19 20 // filterNode implements a filtering stage. It is intended to be used 21 // during plan optimizations in order to avoid instantiating a fully 22 // blown selectTopNode/renderNode pair. 23 type filterNode struct { 24 source planDataSource 25 filter tree.TypedExpr 26 ivarHelper tree.IndexedVarHelper 27 reqOrdering ReqOrdering 28 } 29 30 // filterNode implements tree.IndexedVarContainer 31 var _ tree.IndexedVarContainer = &filterNode{} 32 33 // IndexedVarEval implements the tree.IndexedVarContainer interface. 34 func (f *filterNode) IndexedVarEval(idx int, ctx *tree.EvalContext) (tree.Datum, error) { 35 return f.source.plan.Values()[idx].Eval(ctx) 36 } 37 38 // IndexedVarResolvedType implements the tree.IndexedVarContainer interface. 39 func (f *filterNode) IndexedVarResolvedType(idx int) *types.T { 40 return f.source.columns[idx].Typ 41 } 42 43 // IndexedVarNodeFormatter implements the tree.IndexedVarContainer interface. 44 func (f *filterNode) IndexedVarNodeFormatter(idx int) tree.NodeFormatter { 45 return f.source.columns.NodeFormatter(idx) 46 } 47 48 func (f *filterNode) startExec(runParams) error { 49 return nil 50 } 51 52 // Next implements the planNode interface. 53 func (f *filterNode) Next(params runParams) (bool, error) { 54 panic("filterNode cannot be run in local mode") 55 } 56 57 func (f *filterNode) Values() tree.Datums { 58 panic("filterNode cannot be run in local mode") 59 } 60 61 func (f *filterNode) Close(ctx context.Context) { f.source.plan.Close(ctx) } 62 63 func isFilterTrue(expr tree.TypedExpr) bool { 64 return expr == nil || expr == tree.DBoolTrue 65 }