github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/pipeline/types.go (about) 1 // Copyright 2021 Matrix Origin 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 pipeline 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/vm" 19 "github.com/matrixorigin/matrixone/pkg/vm/process" 20 ) 21 22 // Pipeline contains the information associated with a pipeline in a query execution plan. 23 // A query execution plan may contains one or more pipelines. 24 // As an example: 25 // 26 // CREATE TABLE order 27 // ( 28 // order_id INT, 29 // uid INT, 30 // item_id INT, 31 // year INT, 32 // nation VARCHAR(100) 33 // ); 34 // 35 // CREATE TABLE customer 36 // ( 37 // uid INT, 38 // nation VARCHAR(100), 39 // city VARCHAR(100) 40 // ); 41 // 42 // CREATE TABLE supplier 43 // ( 44 // item_id INT, 45 // nation VARCHAR(100), 46 // city VARCHAR(100) 47 // ); 48 // 49 // SELECT c.city, s.city, sum(o.revenue) AS revenue 50 // FROM customer c, order o, supplier s 51 // WHERE o.uid = c.uid 52 // AND o.item_id = s.item_id 53 // AND c.nation = 'CHINA' 54 // AND s.nation = 'CHINA' 55 // AND o.year >= 1992 and o.year <= 1997 56 // GROUP BY c.city, s.city, o.year 57 // ORDER BY o.year asc, revenue desc; 58 // 59 // AST PLAN: 60 // order 61 // | 62 // group 63 // | 64 // filter 65 // | 66 // join 67 // / \ 68 // s join 69 // / \ 70 // l c 71 // 72 // In this example, a possible pipeline is as follows: 73 // 74 // pipeline: 75 // o ⨝ c ⨝ s 76 // 77 // -> σ(c.nation = 'CHINA' ∧ o.year >= 1992 ∧ o.year <= 1997 ∧ s.nation = 'CHINA') 78 // -> γ([c.city, s.city, o.year, sum(o.revenue) as revenue], c.city, s.city, o.year) 79 // -> τ(o.year asc, revenue desc) 80 // -> π(c.city, s.city, revenue) 81 type Pipeline struct { 82 tableID uint64 83 // attrs, column list. 84 attrs []string 85 // orders to be executed 86 instructions vm.Instructions 87 reg *process.WaitRegister 88 } 89 90 // Cleanup do memory release work for whole pipeline. 91 // we deliver the error because some operator may need to know what the error it is. 92 func (p *Pipeline) Cleanup(proc *process.Process, pipelineFailed bool, err error) { 93 // should cancel the context before clean the pipeline to avoid more batch inputting while cleaning. 94 proc.Cancel() 95 96 // clean all the coming batches. 97 // if pipelineFailed { 98 // bat := proc.InputBatch() 99 // if bat != nil { 100 // cnt := bat.GetCnt() 101 // for cnt > 0 { 102 // cnt-- 103 // bat.Clean(proc.Mp()) 104 // } 105 // } 106 // proc.SetInputBatch(nil) 107 // } 108 109 // clean operator hold memory. 110 for i := range p.instructions { 111 p.instructions[i].Arg.Free(proc, pipelineFailed, err) 112 } 113 }