github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/compile/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 compile
    16  
    17  import (
    18  	"context"
    19  
    20  	"github.com/google/uuid"
    21  	"github.com/matrixorigin/matrixone/pkg/container/batch"
    22  	"github.com/matrixorigin/matrixone/pkg/container/types"
    23  	"github.com/matrixorigin/matrixone/pkg/pb/pipeline"
    24  	"github.com/matrixorigin/matrixone/pkg/pb/plan"
    25  	"github.com/matrixorigin/matrixone/pkg/pb/timestamp"
    26  	"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
    27  	plan2 "github.com/matrixorigin/matrixone/pkg/sql/plan"
    28  	"github.com/matrixorigin/matrixone/pkg/txn/client"
    29  	"github.com/matrixorigin/matrixone/pkg/vm"
    30  	"github.com/matrixorigin/matrixone/pkg/vm/engine"
    31  	"github.com/matrixorigin/matrixone/pkg/vm/process"
    32  )
    33  
    34  type (
    35  	TxnOperator = client.TxnOperator
    36  )
    37  
    38  const (
    39  	MinBlockNum = 200
    40  )
    41  
    42  // type of scope
    43  const (
    44  	Merge = iota
    45  	Normal
    46  	Remote
    47  	Parallel
    48  	Pushdown
    49  	CreateDatabase
    50  	CreateTable
    51  	CreateIndex
    52  	DropDatabase
    53  	DropTable
    54  	DropIndex
    55  	Deletion
    56  	Insert
    57  	Update
    58  	InsertValues
    59  	TruncateTable
    60  	AlterView
    61  	MergeInsert
    62  )
    63  
    64  // Source contains information of a relation which will be used in execution,
    65  type Source struct {
    66  	PushdownId   uint64
    67  	PushdownAddr string
    68  	SchemaName   string
    69  	RelationName string
    70  	Attributes   []string
    71  	R            engine.Reader
    72  	Bat          *batch.Batch
    73  	Expr         *plan.Expr
    74  	TableDef     *plan.TableDef
    75  	Timestamp    timestamp.Timestamp
    76  }
    77  
    78  // Col is the information of attribute
    79  type Col struct {
    80  	Typ  types.T
    81  	Name string
    82  }
    83  
    84  // Scope is the output of the compile process.
    85  // Each sql will be compiled to one or more execution unit scopes.
    86  type Scope struct {
    87  	// Magic specifies the type of Scope.
    88  	// 0 -  execution unit for reading data.
    89  	// 1 -  execution unit for processing intermediate results.
    90  	// 2 -  execution unit that requires remote call.
    91  	Magic int
    92  
    93  	// IsEnd means the pipeline is join
    94  	IsJoin bool
    95  
    96  	// IsEnd means the pipeline is end
    97  	IsEnd bool
    98  
    99  	// IsRemote means the pipeline is remote
   100  	IsRemote bool
   101  
   102  	Plan *plan.Plan
   103  	// DataSource stores information about data source.
   104  	DataSource *Source
   105  	// PreScopes contains children of this scope will inherit and execute.
   106  	PreScopes []*Scope
   107  	// NodeInfo contains the information about the remote node.
   108  	NodeInfo engine.Node
   109  	// Instructions contains command list of this scope.
   110  	Instructions vm.Instructions
   111  	// Proc contains the execution context.
   112  	Proc *process.Process
   113  
   114  	Reg *process.WaitRegister
   115  
   116  	RemoteReceivRegInfos []RemoteReceivRegInfo
   117  }
   118  
   119  // scopeContext contextual information to assist in the generation of pipeline.Pipeline.
   120  type scopeContext struct {
   121  	id       int32
   122  	plan     *plan.Plan
   123  	scope    *Scope
   124  	root     *scopeContext
   125  	parent   *scopeContext
   126  	children []*scopeContext
   127  	pipe     *pipeline.Pipeline
   128  	regs     map[*process.WaitRegister]int32
   129  }
   130  
   131  // anaylze information
   132  type anaylze struct {
   133  	// curr is the current index of plan
   134  	curr      int
   135  	isFirst   bool
   136  	qry       *plan.Query
   137  	analInfos []*process.AnalyzeInfo
   138  }
   139  
   140  // Compile contains all the information needed for compilation.
   141  type Compile struct {
   142  	scope *Scope
   143  
   144  	info plan2.ExecInfo
   145  
   146  	u any
   147  	//fill is a result writer runs a callback function.
   148  	//fill will be called when result data is ready.
   149  	fill func(any, *batch.Batch) error
   150  	//affectRows stores the number of rows affected while insert / update / delete
   151  	affectRows uint64
   152  	// cn address
   153  	addr string
   154  	// db current database name.
   155  	db string
   156  	// uid the user who initiated the sql.
   157  	uid string
   158  	// sql sql text.
   159  	sql string
   160  
   161  	anal *anaylze
   162  	// e db engine instance.
   163  	e   engine.Engine
   164  	ctx context.Context
   165  	// proc stores the execution context.
   166  	proc *process.Process
   167  
   168  	cnList engine.Nodes
   169  	// ast
   170  	stmt tree.Statement
   171  
   172  	// when we construct the scope, compileTableScan will new a scope, the magic is
   173  	// remote, but now the tempEngine is just standlone. So for now use this to read
   174  	// table locally. But int the future, this will disappear.
   175  	isTemporaryScan bool
   176  }
   177  type RemoteReceivRegInfo struct {
   178  	Idx      int
   179  	Uuid     uuid.UUID
   180  	FromAddr string
   181  }