Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make table_scan as normal instruction #16956

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
826 changes: 510 additions & 316 deletions pkg/pb/pipeline/pipeline.pb.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions pkg/sql/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2218,6 +2218,13 @@ func (c *Compile) compileTableScanWithNode(n *plan.Node, node engine.Node) (*Sco
s.DataSource = &Source{
node: n,
}

s.appendInstruction(vm.Instruction{
Op: vm.TableScan,
Idx: c.anal.curr,
IsFirst: c.anal.isFirst,
Arg: constructTableScan(),
})
s.Proc = process.NewWithAnalyze(c.proc, c.ctx, 0, c.anal.Nodes())
return s, nil
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/sql/compile/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"

"github.com/matrixorigin/matrixone/pkg/sql/colexec/productl2"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/table_scan"

"github.com/matrixorigin/matrixone/pkg/sql/colexec/shufflebuild"

Expand Down Expand Up @@ -496,6 +497,10 @@ func dupInstruction(sourceIns *vm.Instruction, regMap map[*process.WaitRegister]
arg.PkTyp = t.PkTyp
arg.BuildIdx = t.BuildIdx
res.Arg = arg
case vm.TableScan:
// t := sourceIns.Arg.(*table_scan.Argument)
arg := table_scan.NewArgument()
res.Arg = arg
default:
panic(fmt.Sprintf("unexpected instruction type '%d' to dup", sourceIns.Op))
}
Expand Down Expand Up @@ -1912,6 +1917,10 @@ func constructJoinCondition(expr *plan.Expr, proc *process.Process) (*plan.Expr,
return e.F.Args[0], e.F.Args[1]
}

func constructTableScan() *table_scan.Argument {
return table_scan.NewArgument()
}

func extraJoinConditions(exprs []*plan.Expr) (*plan.Expr, []*plan.Expr) {
exprs = colexec.SplitAndExprs(exprs)
eqConds := make([]*plan.Expr, 0, len(exprs))
Expand Down
7 changes: 6 additions & 1 deletion pkg/sql/compile/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/sql/colexec/right"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/rightanti"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/rightsemi"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/table_scan"
"github.com/matrixorigin/matrixone/pkg/sql/util"
"github.com/matrixorigin/matrixone/pkg/vm/engine"
"github.com/matrixorigin/matrixone/pkg/vm/engine/disttae"
Expand Down Expand Up @@ -786,7 +787,11 @@ func (s *Scope) handleRuntimeFilter(c *Compile) error {
isFilterOnPK := s.DataSource.TableDef.Pkey != nil && col.Name == s.DataSource.TableDef.Pkey.PkeyColName
if !isFilterOnPK {
// put expr in filter instruction
ins := s.Instructions[0]
idx := 0
if _, ok := s.Instructions[0].Arg.(*table_scan.Argument); ok {
idx = 1
}
ins := s.Instructions[idx]
arg, ok := ins.Arg.(*filter.Argument)
if !ok {
panic("missing instruction for runtime filter!")
Expand Down
6 changes: 6 additions & 0 deletions pkg/sql/compile/scopeRemoteRun.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"unsafe"

"github.com/matrixorigin/matrixone/pkg/sql/colexec/productl2"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/table_scan"

"github.com/matrixorigin/matrixone/pkg/common/moerr"
"github.com/matrixorigin/matrixone/pkg/common/morpc"
Expand Down Expand Up @@ -1045,6 +1046,8 @@ func convertToPipelineInstruction(opr *vm.Instruction, ctx *scopeContext, ctxId
Limit: t.Limit,
Offset: t.Offset,
}
case *table_scan.Argument:
in.TableScan = &pipeline.TableScan{}
default:
return -1, nil, moerr.NewInternalErrorNoCtx(fmt.Sprintf("unexpected operator: %v", opr.Op))
}
Expand Down Expand Up @@ -1471,6 +1474,9 @@ func convertToVmInstruction(opr *pipeline.Instruction, ctx *scopeContext, eng en
arg.Limit = t.Limit
arg.Offset = t.Offset
v.Arg = arg
case vm.TableScan:
arg := table_scan.NewArgument()
v.Arg = arg
default:
return v, moerr.NewInternalErrorNoCtx(fmt.Sprintf("unexpected operator: %v", opr.Op))
}
Expand Down
19 changes: 5 additions & 14 deletions pkg/vm/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,12 @@ func (p *Pipeline) Run(r engine.Reader, topValueMsgTag int32, proc *process.Proc
}
}

tableScanOperator := table_scan.Argument{
Reader: r,
TopValueMsgTag: topValueMsgTag,
Attrs: p.attrs,
TableID: p.tableID,
if tableScanOperator, ok := p.instructions[0].Arg.(*table_scan.Argument); ok {
tableScanOperator.Reader = r
tableScanOperator.TopValueMsgTag = topValueMsgTag
tableScanOperator.Attrs = p.attrs
tableScanOperator.TableID = p.tableID
}
p.instructions = append([]vm.Instruction{
{
Op: vm.TableScan,
Idx: -1,
Arg: &tableScanOperator,
IsFirst: true,
IsLast: false,
},
}, p.instructions...)

if err = vm.Prepare(p.instructions, proc); err != nil {
return false, err
Expand Down
5 changes: 5 additions & 0 deletions proto/pipeline.proto
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ message StreamScan {
int64 limit = 3;
}

message TableScan {

}

message SampleFunc {
enum SampleType {
Rows = 0;
Expand Down Expand Up @@ -425,6 +429,7 @@ message Instruction{
int32 max_parallel = 42;
IndexJoin index_join = 43;
ProductL2 product_l2 = 44;
TableScan table_scan = 45;
}

message AnalysisList {
Expand Down
Loading