-
Notifications
You must be signed in to change notification settings - Fork 265
/
operator.go
1964 lines (1836 loc) · 59.8 KB
/
operator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package compile
import (
"context"
"fmt"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/aggexec"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/indexbuild"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/indexjoin"
"github.com/google/uuid"
"github.com/matrixorigin/matrixone/pkg/catalog"
"github.com/matrixorigin/matrixone/pkg/common/moerr"
"github.com/matrixorigin/matrixone/pkg/container/batch"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/matrixorigin/matrixone/pkg/defines"
"github.com/matrixorigin/matrixone/pkg/pb/pipeline"
"github.com/matrixorigin/matrixone/pkg/pb/plan"
"github.com/matrixorigin/matrixone/pkg/pb/timestamp"
"github.com/matrixorigin/matrixone/pkg/sql/colexec"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/anti"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/connector"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/deletion"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/dispatch"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/external"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/fill"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/fuzzyfilter"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/group"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/hashbuild"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/insert"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/intersect"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/intersectall"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/join"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/left"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/limit"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/lockop"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/loopanti"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/loopjoin"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/loopleft"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/loopmark"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/loopsemi"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/loopsingle"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/mark"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/merge"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/mergecte"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/mergegroup"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/mergelimit"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/mergeoffset"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/mergeorder"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/mergerecursive"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/mergetop"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/minus"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/offset"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/onduplicatekey"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/order"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/partition"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/preinsert"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/preinsertsecondaryindex"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/preinsertunique"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/product"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/projection"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/restrict"
"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/sample"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/semi"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/shuffle"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/single"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/source"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/table_function"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/timewin"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/top"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/window"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
plan2 "github.com/matrixorigin/matrixone/pkg/sql/plan"
"github.com/matrixorigin/matrixone/pkg/sql/plan/function"
"github.com/matrixorigin/matrixone/pkg/vm"
"github.com/matrixorigin/matrixone/pkg/vm/engine"
"github.com/matrixorigin/matrixone/pkg/vm/process"
)
var constBat *batch.Batch
func init() {
constBat = batch.NewWithSize(0)
constBat.SetRowCount(1)
}
func dupInstruction(sourceIns *vm.Instruction, regMap map[*process.WaitRegister]*process.WaitRegister, index int) vm.Instruction {
res := vm.Instruction{
Op: sourceIns.Op,
Idx: sourceIns.Idx,
IsFirst: sourceIns.IsFirst,
IsLast: sourceIns.IsLast,
CnAddr: sourceIns.CnAddr,
OperatorID: sourceIns.OperatorID,
MaxParallel: sourceIns.MaxParallel,
ParallelID: sourceIns.ParallelID,
}
switch sourceIns.Op {
case vm.Anti:
t := sourceIns.Arg.(*anti.Argument)
arg := anti.NewArgument()
arg.Cond = t.Cond
arg.Typs = t.Typs
arg.Conditions = t.Conditions
arg.Result = t.Result
arg.HashOnPK = t.HashOnPK
arg.IsShuffle = t.IsShuffle
res.Arg = arg
case vm.Group:
t := sourceIns.Arg.(*group.Argument)
arg := group.NewArgument()
arg.IsShuffle = t.IsShuffle
arg.PreAllocSize = t.PreAllocSize
arg.NeedEval = t.NeedEval
arg.Ibucket = t.Ibucket
arg.Nbucket = t.Nbucket
arg.Exprs = t.Exprs
arg.Types = t.Types
arg.Aggs = t.Aggs
res.Arg = arg
case vm.Sample:
t := sourceIns.Arg.(*sample.Argument)
res.Arg = t.SimpleDup()
case vm.Join:
t := sourceIns.Arg.(*join.Argument)
arg := join.NewArgument()
arg.Result = t.Result
arg.Cond = t.Cond
arg.Typs = t.Typs
arg.Conditions = t.Conditions
arg.RuntimeFilterSpecs = t.RuntimeFilterSpecs
arg.HashOnPK = t.HashOnPK
arg.IsShuffle = t.IsShuffle
res.Arg = arg
case vm.Left:
t := sourceIns.Arg.(*left.Argument)
arg := left.NewArgument()
arg.Cond = t.Cond
arg.Result = t.Result
arg.Typs = t.Typs
arg.Conditions = t.Conditions
arg.RuntimeFilterSpecs = t.RuntimeFilterSpecs
arg.HashOnPK = t.HashOnPK
arg.IsShuffle = t.IsShuffle
res.Arg = arg
case vm.Right:
t := sourceIns.Arg.(*right.Argument)
arg := right.NewArgument()
arg.Cond = t.Cond
arg.Result = t.Result
arg.RightTypes = t.RightTypes
arg.LeftTypes = t.LeftTypes
arg.Conditions = t.Conditions
arg.RuntimeFilterSpecs = t.RuntimeFilterSpecs
arg.HashOnPK = t.HashOnPK
arg.IsShuffle = t.IsShuffle
res.Arg = arg
case vm.RightSemi:
t := sourceIns.Arg.(*rightsemi.Argument)
arg := rightsemi.NewArgument()
arg.Cond = t.Cond
arg.Result = t.Result
arg.RightTypes = t.RightTypes
arg.Conditions = t.Conditions
arg.RuntimeFilterSpecs = t.RuntimeFilterSpecs
arg.HashOnPK = t.HashOnPK
arg.IsShuffle = t.IsShuffle
res.Arg = arg
case vm.RightAnti:
t := sourceIns.Arg.(*rightanti.Argument)
arg := rightanti.NewArgument()
arg.Cond = t.Cond
arg.Result = t.Result
arg.RightTypes = t.RightTypes
arg.Conditions = t.Conditions
arg.RuntimeFilterSpecs = t.RuntimeFilterSpecs
arg.HashOnPK = t.HashOnPK
arg.IsShuffle = t.IsShuffle
res.Arg = arg
case vm.Limit:
t := sourceIns.Arg.(*limit.Argument)
arg := limit.NewArgument()
arg.Limit = t.Limit
res.Arg = arg
case vm.LoopAnti:
t := sourceIns.Arg.(*loopanti.Argument)
arg := loopanti.NewArgument()
arg.Result = t.Result
arg.Cond = t.Cond
arg.Typs = t.Typs
res.Arg = arg
case vm.LoopJoin:
t := sourceIns.Arg.(*loopjoin.Argument)
arg := loopjoin.NewArgument()
arg.Result = t.Result
arg.Cond = t.Cond
arg.Typs = t.Typs
res.Arg = arg
case vm.IndexJoin:
t := sourceIns.Arg.(*indexjoin.Argument)
arg := indexjoin.NewArgument()
arg.Result = t.Result
arg.Typs = t.Typs
arg.RuntimeFilterSpecs = t.RuntimeFilterSpecs
res.Arg = arg
case vm.LoopLeft:
t := sourceIns.Arg.(*loopleft.Argument)
arg := loopleft.NewArgument()
arg.Cond = t.Cond
arg.Typs = t.Typs
arg.Result = t.Result
res.Arg = arg
case vm.LoopSemi:
t := sourceIns.Arg.(*loopsemi.Argument)
arg := loopsemi.NewArgument()
arg.Result = t.Result
arg.Cond = t.Cond
arg.Typs = t.Typs
res.Arg = arg
case vm.LoopSingle:
t := sourceIns.Arg.(*loopsingle.Argument)
arg := loopsingle.NewArgument()
arg.Result = t.Result
arg.Cond = t.Cond
arg.Typs = t.Typs
res.Arg = arg
case vm.LoopMark:
t := sourceIns.Arg.(*loopmark.Argument)
arg := loopmark.NewArgument()
arg.Result = t.Result
arg.Cond = t.Cond
arg.Typs = t.Typs
res.Arg = arg
case vm.Offset:
t := sourceIns.Arg.(*offset.Argument)
arg := offset.NewArgument()
arg.Offset = t.Offset
res.Arg = arg
case vm.Order:
t := sourceIns.Arg.(*order.Argument)
arg := order.NewArgument()
arg.OrderBySpec = t.OrderBySpec
res.Arg = arg
case vm.Product:
t := sourceIns.Arg.(*product.Argument)
arg := product.NewArgument()
arg.Result = t.Result
arg.Typs = t.Typs
arg.IsShuffle = t.IsShuffle
res.Arg = arg
case vm.Projection:
t := sourceIns.Arg.(*projection.Argument)
arg := projection.NewArgument()
arg.Es = t.Es
res.Arg = arg
case vm.Restrict:
t := sourceIns.Arg.(*restrict.Argument)
arg := restrict.NewArgument()
arg.E = t.E
res.Arg = arg
case vm.Semi:
t := sourceIns.Arg.(*semi.Argument)
arg := semi.NewArgument()
arg.Result = t.Result
arg.Cond = t.Cond
arg.Typs = t.Typs
arg.Conditions = t.Conditions
arg.RuntimeFilterSpecs = t.RuntimeFilterSpecs
arg.HashOnPK = t.HashOnPK
arg.IsShuffle = t.IsShuffle
res.Arg = arg
case vm.Single:
t := sourceIns.Arg.(*single.Argument)
arg := single.NewArgument()
arg.Result = t.Result
arg.Cond = t.Cond
arg.Typs = t.Typs
arg.Conditions = t.Conditions
arg.RuntimeFilterSpecs = t.RuntimeFilterSpecs
arg.HashOnPK = t.HashOnPK
res.Arg = arg
case vm.Top:
t := sourceIns.Arg.(*top.Argument)
arg := top.NewArgument()
arg.Limit = t.Limit
arg.TopValueTag = t.TopValueTag
arg.Fs = t.Fs
res.Arg = arg
case vm.Intersect:
t := sourceIns.Arg.(*intersect.Argument)
arg := intersect.NewArgument()
arg.IBucket = t.IBucket
arg.NBucket = t.NBucket
res.Arg = arg
case vm.Minus: // 2
t := sourceIns.Arg.(*minus.Argument)
arg := minus.NewArgument()
arg.IBucket = t.IBucket
arg.NBucket = t.NBucket
res.Arg = arg
case vm.IntersectAll:
t := sourceIns.Arg.(*intersectall.Argument)
arg := intersectall.NewArgument()
arg.IBucket = t.IBucket
arg.NBucket = t.NBucket
res.Arg = arg
case vm.Merge:
t := sourceIns.Arg.(*merge.Argument)
arg := merge.NewArgument()
arg.SinkScan = t.SinkScan
res.Arg = arg
case vm.MergeRecursive:
res.Arg = mergerecursive.NewArgument()
case vm.MergeCTE:
res.Arg = mergecte.NewArgument()
case vm.MergeGroup:
t := sourceIns.Arg.(*mergegroup.Argument)
arg := mergegroup.NewArgument()
arg.NeedEval = t.NeedEval
arg.PartialResults = t.PartialResults
arg.PartialResultTypes = t.PartialResultTypes
res.Arg = arg
case vm.MergeLimit:
t := sourceIns.Arg.(*mergelimit.Argument)
arg := mergelimit.NewArgument()
arg.Limit = t.Limit
res.Arg = arg
case vm.MergeOffset:
t := sourceIns.Arg.(*mergeoffset.Argument)
arg := mergeoffset.NewArgument()
arg.Offset = t.Offset
res.Arg = arg
case vm.MergeTop:
t := sourceIns.Arg.(*mergetop.Argument)
arg := mergetop.NewArgument()
arg.Limit = t.Limit
arg.Fs = t.Fs
res.Arg = arg
case vm.MergeOrder:
t := sourceIns.Arg.(*mergeorder.Argument)
arg := mergeorder.NewArgument()
arg.OrderBySpecs = t.OrderBySpecs
res.Arg = arg
case vm.Mark:
t := sourceIns.Arg.(*mark.Argument)
arg := mark.NewArgument()
arg.Result = t.Result
arg.Conditions = t.Conditions
arg.Typs = t.Typs
arg.Cond = t.Cond
arg.OnList = t.OnList
arg.HashOnPK = t.HashOnPK
res.Arg = arg
case vm.TableFunction:
t := sourceIns.Arg.(*table_function.Argument)
arg := table_function.NewArgument()
arg.FuncName = t.FuncName
arg.Args = t.Args
arg.Rets = t.Rets
arg.Attrs = t.Attrs
arg.Params = t.Params
res.Arg = arg
case vm.HashBuild:
t := sourceIns.Arg.(*hashbuild.Argument)
arg := hashbuild.NewArgument()
arg.NeedHashMap = t.NeedHashMap
arg.NeedExpr = t.NeedExpr
arg.Ibucket = t.Ibucket
arg.Nbucket = t.Nbucket
arg.Typs = t.Typs
arg.Conditions = t.Conditions
arg.HashOnPK = t.HashOnPK
arg.NeedMergedBatch = t.NeedMergedBatch
arg.NeedAllocateSels = t.NeedAllocateSels
res.Arg = arg
case vm.External:
t := sourceIns.Arg.(*external.Argument)
res.Arg = external.NewArgument().WithEs(
&external.ExternalParam{
ExParamConst: external.ExParamConst{
Attrs: t.Es.Attrs,
Cols: t.Es.Cols,
Idx: index,
Name2ColIndex: t.Es.Name2ColIndex,
CreateSql: t.Es.CreateSql,
FileList: t.Es.FileList,
FileSize: t.Es.FileSize,
FileOffsetTotal: t.Es.FileOffsetTotal,
Extern: t.Es.Extern,
},
ExParam: external.ExParam{
Filter: &external.FilterParam{
FilterExpr: t.Es.Filter.FilterExpr,
},
Fileparam: &external.ExFileparam{
End: t.Es.Fileparam.End,
FileCnt: t.Es.Fileparam.FileCnt,
FileFin: t.Es.Fileparam.FileFin,
FileIndex: t.Es.Fileparam.FileIndex,
},
},
},
)
case vm.Source:
t := sourceIns.Arg.(*source.Argument)
arg := source.NewArgument()
arg.TblDef = t.TblDef
arg.Limit = t.Limit
arg.Offset = t.Offset
arg.Configs = t.Configs
res.Arg = arg
case vm.Connector:
ok := false
if regMap != nil {
arg := connector.NewArgument()
sourceReg := sourceIns.Arg.(*connector.Argument).Reg
if arg.Reg, ok = regMap[sourceReg]; !ok {
panic("nonexistent wait register")
}
res.Arg = arg
}
case vm.Shuffle:
sourceArg := sourceIns.Arg.(*shuffle.Argument)
arg := shuffle.NewArgument()
arg.ShuffleType = sourceArg.ShuffleType
arg.ShuffleColIdx = sourceArg.ShuffleColIdx
arg.ShuffleColMax = sourceArg.ShuffleColMax
arg.ShuffleColMin = sourceArg.ShuffleColMin
arg.AliveRegCnt = sourceArg.AliveRegCnt
arg.ShuffleRangeInt64 = sourceArg.ShuffleRangeInt64
arg.ShuffleRangeUint64 = sourceArg.ShuffleRangeUint64
res.Arg = arg
case vm.Dispatch:
ok := false
if regMap != nil {
sourceArg := sourceIns.Arg.(*dispatch.Argument)
arg := dispatch.NewArgument()
arg.IsSink = sourceArg.IsSink
arg.RecSink = sourceArg.RecSink
arg.FuncId = sourceArg.FuncId
arg.LocalRegs = make([]*process.WaitRegister, len(sourceArg.LocalRegs))
arg.RemoteRegs = make([]colexec.ReceiveInfo, len(sourceArg.RemoteRegs))
for j := range arg.LocalRegs {
sourceReg := sourceArg.LocalRegs[j]
if arg.LocalRegs[j], ok = regMap[sourceReg]; !ok {
panic("nonexistent wait register")
}
}
for j := range arg.RemoteRegs {
arg.RemoteRegs[j] = sourceArg.RemoteRegs[j]
}
res.Arg = arg
}
case vm.Insert:
t := sourceIns.Arg.(*insert.Argument)
arg := insert.NewArgument()
arg.InsertCtx = t.InsertCtx
arg.ToWriteS3 = t.ToWriteS3
res.Arg = arg
case vm.PreInsert:
t := sourceIns.Arg.(*preinsert.Argument)
arg := preinsert.NewArgument()
arg.SchemaName = t.SchemaName
arg.TableDef = t.TableDef
arg.Attrs = t.Attrs
arg.IsUpdate = t.IsUpdate
arg.HasAutoCol = t.HasAutoCol
arg.EstimatedRowCount = t.EstimatedRowCount
res.Arg = arg
case vm.Deletion:
t := sourceIns.Arg.(*deletion.Argument)
arg := deletion.NewArgument()
arg.IBucket = t.IBucket
arg.Nbucket = t.Nbucket
arg.DeleteCtx = t.DeleteCtx
arg.RemoteDelete = t.RemoteDelete
arg.SegmentMap = t.SegmentMap
res.Arg = arg
case vm.LockOp:
t := sourceIns.Arg.(*lockop.Argument)
arg := lockop.NewArgument()
*arg = *t
res.Arg = arg
case vm.FuzzyFilter:
t := sourceIns.Arg.(*fuzzyfilter.Argument)
arg := fuzzyfilter.NewArgument()
arg.N = t.N
arg.PkName = t.PkName
arg.PkTyp = t.PkTyp
res.Arg = arg
default:
panic(fmt.Sprintf("unexpected instruction type '%d' to dup", sourceIns.Op))
}
return res
}
func constructRestrict(n *plan.Node, filterExpr *plan2.Expr) *restrict.Argument {
arg := restrict.NewArgument()
arg.E = filterExpr
arg.IsEnd = n.IsEnd
return arg
}
func constructDeletion(n *plan.Node, eg engine.Engine, proc *process.Process) (*deletion.Argument, error) {
oldCtx := n.DeleteCtx
delCtx := &deletion.DeleteCtx{
Ref: oldCtx.Ref,
RowIdIdx: int(oldCtx.RowIdIdx),
CanTruncate: oldCtx.CanTruncate,
AddAffectedRows: oldCtx.AddAffectedRows,
PartitionTableIDs: oldCtx.PartitionTableIds,
PartitionTableNames: oldCtx.PartitionTableNames,
PartitionIndexInBatch: int(oldCtx.PartitionIdx),
PrimaryKeyIdx: int(oldCtx.PrimaryKeyIdx),
}
// get the relation instance of the original table
rel, _, err := getRel(proc.Ctx, proc, eg, oldCtx.Ref, nil)
if err != nil {
return nil, err
}
delCtx.Source = rel
if len(oldCtx.PartitionTableNames) > 0 {
dbSource, err := eg.Database(proc.Ctx, oldCtx.Ref.SchemaName, proc.TxnOperator)
if err != nil {
return nil, err
}
delCtx.PartitionSources = make([]engine.Relation, len(oldCtx.PartitionTableNames))
// get the relation instances for each partition sub table
for i, pTableName := range oldCtx.PartitionTableNames {
pRel, err := dbSource.Relation(proc.Ctx, pTableName, proc)
if err != nil {
return nil, err
}
delCtx.PartitionSources[i] = pRel
}
}
arg := deletion.NewArgument()
arg.DeleteCtx = delCtx
return arg, nil
}
func constructOnduplicateKey(n *plan.Node, eg engine.Engine) *onduplicatekey.Argument {
oldCtx := n.OnDuplicateKey
arg := onduplicatekey.NewArgument()
arg.Engine = eg
arg.OnDuplicateIdx = oldCtx.OnDuplicateIdx
arg.OnDuplicateExpr = oldCtx.OnDuplicateExpr
arg.Attrs = oldCtx.Attrs
arg.InsertColCount = oldCtx.InsertColCount
arg.UniqueCols = oldCtx.UniqueCols
arg.UniqueColCheckExpr = oldCtx.UniqueColCheckExpr
arg.IsIgnore = oldCtx.IsIgnore
return arg
}
func constructFuzzyFilter(c *Compile, n, right *plan.Node) *fuzzyfilter.Argument {
pkName := n.TableDef.Pkey.PkeyColName
var pkTyp plan.Type
if pkName == catalog.CPrimaryKeyColName {
pkTyp = n.TableDef.Pkey.CompPkeyCol.Typ
} else {
cols := n.TableDef.Cols
for _, c := range cols {
if c.Name == pkName {
pkTyp = c.Typ
}
}
}
arg := fuzzyfilter.NewArgument()
arg.PkName = pkName
arg.PkTyp = pkTyp
arg.N = right.Stats.Outcnt
if len(n.RuntimeFilterBuildList) > 0 {
arg.RuntimeFilterSpec = n.RuntimeFilterBuildList[0]
}
return arg
}
func constructPreInsert(ns []*plan.Node, n *plan.Node, eg engine.Engine, proc *process.Process) (*preinsert.Argument, error) {
preCtx := n.PreInsertCtx
schemaName := preCtx.Ref.SchemaName
//var attrs []string
attrs := make([]string, 0)
for _, col := range preCtx.TableDef.Cols {
if col.Hidden && col.Name != catalog.FakePrimaryKeyColName {
continue
}
attrs = append(attrs, col.Name)
}
ctx := proc.Ctx
txnOp := proc.TxnOperator
if n.ScanSnapshot != nil && n.ScanSnapshot.TS != nil {
if !n.ScanSnapshot.TS.Equal(timestamp.Timestamp{LogicalTime: 0, PhysicalTime: 0}) &&
n.ScanSnapshot.TS.Less(proc.TxnOperator.Txn().SnapshotTS) {
txnOp = proc.TxnOperator.CloneSnapshotOp(*n.ScanSnapshot.TS)
if n.ScanSnapshot.Tenant != nil {
ctx = context.WithValue(ctx, defines.TenantIDKey{}, n.ScanSnapshot.Tenant.TenantID)
}
}
}
if preCtx.Ref.SchemaName != "" {
dbSource, err := eg.Database(ctx, preCtx.Ref.SchemaName, txnOp)
if err != nil {
return nil, err
}
if _, err = dbSource.Relation(ctx, preCtx.Ref.ObjName, proc); err != nil {
schemaName = defines.TEMPORARY_DBNAME
}
}
arg := preinsert.NewArgument()
arg.Ctx = proc.Ctx
arg.HasAutoCol = preCtx.HasAutoCol
arg.SchemaName = schemaName
arg.TableDef = preCtx.TableDef
arg.Attrs = attrs
arg.IsUpdate = preCtx.IsUpdate
arg.EstimatedRowCount = int64(ns[n.Children[0]].Stats.Outcnt)
return arg, nil
}
func constructPreInsertUk(n *plan.Node, proc *process.Process) (*preinsertunique.Argument, error) {
preCtx := n.PreInsertUkCtx
arg := preinsertunique.NewArgument()
arg.Ctx = proc.Ctx
arg.PreInsertCtx = preCtx
return arg, nil
}
func constructPreInsertSk(n *plan.Node, proc *process.Process) (*preinsertsecondaryindex.Argument, error) {
arg := preinsertsecondaryindex.NewArgument()
arg.Ctx = proc.Ctx
arg.PreInsertCtx = n.PreInsertSkCtx
return arg, nil
}
func constructLockOp(n *plan.Node, eng engine.Engine) (*lockop.Argument, error) {
arg := lockop.NewArgumentByEngine(eng)
for _, target := range n.LockTargets {
typ := plan2.MakeTypeByPlan2Type(target.PrimaryColTyp)
if target.IsPartitionTable {
arg.AddLockTargetWithPartition(target.GetPartitionTableIds(), target.GetPrimaryColIdxInBat(), typ, target.GetRefreshTsIdxInBat(), target.GetFilterColIdxInBat())
} else {
arg.AddLockTarget(target.GetTableId(), target.GetPrimaryColIdxInBat(), typ, target.GetRefreshTsIdxInBat())
}
}
for _, target := range n.LockTargets {
if target.LockTable {
if target.IsPartitionTable {
for _, pTblId := range target.PartitionTableIds {
arg.LockTable(pTblId, false)
}
} else {
arg.LockTable(target.TableId, false)
}
}
}
return arg, nil
}
func constructInsert(n *plan.Node, eg engine.Engine, proc *process.Process) (*insert.Argument, error) {
oldCtx := n.InsertCtx
ctx := proc.Ctx
var attrs []string
for _, col := range oldCtx.TableDef.Cols {
if col.Name != catalog.Row_ID {
attrs = append(attrs, col.Name)
}
}
originRel, _, err := getRel(ctx, proc, eg, oldCtx.Ref, nil)
if err != nil {
return nil, err
}
newCtx := &insert.InsertCtx{
Ref: oldCtx.Ref,
AddAffectedRows: oldCtx.AddAffectedRows,
Rel: originRel,
Attrs: attrs,
PartitionTableIDs: oldCtx.PartitionTableIds,
PartitionTableNames: oldCtx.PartitionTableNames,
PartitionIndexInBatch: int(oldCtx.PartitionIdx),
TableDef: oldCtx.TableDef,
}
if len(oldCtx.PartitionTableNames) > 0 {
dbSource, err := eg.Database(proc.Ctx, oldCtx.Ref.SchemaName, proc.TxnOperator)
if err != nil {
return nil, err
}
newCtx.PartitionSources = make([]engine.Relation, len(oldCtx.PartitionTableNames))
// get the relation instances for each partition sub table
for i, pTableName := range oldCtx.PartitionTableNames {
pRel, err := dbSource.Relation(proc.Ctx, pTableName, proc)
if err != nil {
return nil, err
}
newCtx.PartitionSources[i] = pRel
}
}
arg := insert.NewArgument()
arg.InsertCtx = newCtx
return arg, nil
}
func constructProjection(n *plan.Node) *projection.Argument {
arg := projection.NewArgument()
arg.Es = n.ProjectList
return arg
}
func constructExternal(n *plan.Node, param *tree.ExternParam, ctx context.Context, fileList []string, FileSize []int64, fileOffset []*pipeline.FileOffset) *external.Argument {
attrs := make([]string, len(n.TableDef.Cols))
for j, col := range n.TableDef.Cols {
attrs[j] = col.Name
}
return external.NewArgument().WithEs(
&external.ExternalParam{
ExParamConst: external.ExParamConst{
Attrs: attrs,
Cols: n.TableDef.Cols,
Extern: param,
Name2ColIndex: n.TableDef.Name2ColIndex,
FileOffsetTotal: fileOffset,
CreateSql: n.TableDef.Createsql,
Ctx: ctx,
FileList: fileList,
FileSize: FileSize,
ClusterTable: n.GetClusterTable(),
},
ExParam: external.ExParam{
Fileparam: new(external.ExFileparam),
Filter: &external.FilterParam{
FilterExpr: colexec.RewriteFilterExprList(n.FilterList),
},
},
},
)
}
func constructStream(n *plan.Node, p [2]int64) *source.Argument {
arg := source.NewArgument()
arg.TblDef = n.TableDef
arg.Offset = p[0]
arg.Limit = p[1]
return arg
}
func constructTableFunction(n *plan.Node) *table_function.Argument {
attrs := make([]string, len(n.TableDef.Cols))
for j, col := range n.TableDef.Cols {
attrs[j] = col.Name
}
arg := table_function.NewArgument()
arg.Attrs = attrs
arg.Rets = n.TableDef.Cols
arg.Args = n.TblFuncExprList
arg.FuncName = n.TableDef.TblFunc.Name
arg.Params = n.TableDef.TblFunc.Param
return arg
}
func constructTop(n *plan.Node, topN int64) *top.Argument {
arg := top.NewArgument()
arg.Fs = n.OrderBy
arg.Limit = topN
if len(n.SendMsgList) > 0 {
arg.TopValueTag = n.SendMsgList[0].MsgTag
}
return arg
}
func constructJoin(n *plan.Node, typs []types.Type, proc *process.Process) *join.Argument {
result := make([]colexec.ResultPos, len(n.ProjectList))
for i, expr := range n.ProjectList {
result[i].Rel, result[i].Pos = constructJoinResult(expr, proc)
}
cond, conds := extraJoinConditions(n.OnList)
arg := join.NewArgument()
arg.Typs = typs
arg.Result = result
arg.Cond = cond
arg.Conditions = constructJoinConditions(conds, proc)
arg.RuntimeFilterSpecs = n.RuntimeFilterBuildList
arg.HashOnPK = n.Stats.HashmapStats != nil && n.Stats.HashmapStats.HashOnPK
arg.IsShuffle = n.Stats.HashmapStats != nil && n.Stats.HashmapStats.Shuffle
return arg
}
func constructSemi(n *plan.Node, typs []types.Type, proc *process.Process) *semi.Argument {
result := make([]int32, len(n.ProjectList))
for i, expr := range n.ProjectList {
rel, pos := constructJoinResult(expr, proc)
if rel != 0 {
panic(moerr.NewNYI(proc.Ctx, "semi result '%s'", expr))
}
result[i] = pos
}
cond, conds := extraJoinConditions(n.OnList)
arg := semi.NewArgument()
arg.Typs = typs
arg.Result = result
arg.Cond = cond
arg.Conditions = constructJoinConditions(conds, proc)
arg.RuntimeFilterSpecs = n.RuntimeFilterBuildList
arg.HashOnPK = n.Stats.HashmapStats != nil && n.Stats.HashmapStats.HashOnPK
arg.IsShuffle = n.Stats.HashmapStats != nil && n.Stats.HashmapStats.Shuffle
return arg
}
func constructLeft(n *plan.Node, typs []types.Type, proc *process.Process) *left.Argument {
result := make([]colexec.ResultPos, len(n.ProjectList))
for i, expr := range n.ProjectList {
result[i].Rel, result[i].Pos = constructJoinResult(expr, proc)
}
cond, conds := extraJoinConditions(n.OnList)
arg := left.NewArgument()
arg.Typs = typs
arg.Result = result
arg.Cond = cond
arg.Conditions = constructJoinConditions(conds, proc)
arg.RuntimeFilterSpecs = n.RuntimeFilterBuildList
arg.HashOnPK = n.Stats.HashmapStats != nil && n.Stats.HashmapStats.HashOnPK
arg.IsShuffle = n.Stats.HashmapStats != nil && n.Stats.HashmapStats.Shuffle
return arg
}
func constructRight(n *plan.Node, left_typs, right_typs []types.Type, Ibucket, Nbucket uint64, proc *process.Process) *right.Argument {
result := make([]colexec.ResultPos, len(n.ProjectList))
for i, expr := range n.ProjectList {
result[i].Rel, result[i].Pos = constructJoinResult(expr, proc)
}
cond, conds := extraJoinConditions(n.OnList)
arg := right.NewArgument()
arg.LeftTypes = left_typs
arg.RightTypes = right_typs
arg.Result = result
arg.Cond = cond
arg.Conditions = constructJoinConditions(conds, proc)
arg.RuntimeFilterSpecs = n.RuntimeFilterBuildList
arg.HashOnPK = n.Stats.HashmapStats != nil && n.Stats.HashmapStats.HashOnPK
arg.IsShuffle = n.Stats.HashmapStats != nil && n.Stats.HashmapStats.Shuffle
return arg
}
func constructRightSemi(n *plan.Node, right_typs []types.Type, Ibucket, Nbucket uint64, proc *process.Process) *rightsemi.Argument {
result := make([]int32, len(n.ProjectList))
for i, expr := range n.ProjectList {
_, result[i] = constructJoinResult(expr, proc)
}
cond, conds := extraJoinConditions(n.OnList)
// 使用NewArgument来初始化
arg := rightsemi.NewArgument()
arg.RightTypes = right_typs
arg.Result = result
arg.Cond = cond
arg.Conditions = constructJoinConditions(conds, proc)
arg.RuntimeFilterSpecs = n.RuntimeFilterBuildList
arg.HashOnPK = n.Stats.HashmapStats != nil && n.Stats.HashmapStats.HashOnPK
arg.IsShuffle = n.Stats.HashmapStats != nil && n.Stats.HashmapStats.Shuffle
return arg
}
func constructRightAnti(n *plan.Node, right_typs []types.Type, Ibucket, Nbucket uint64, proc *process.Process) *rightanti.Argument {
result := make([]int32, len(n.ProjectList))
for i, expr := range n.ProjectList {
_, result[i] = constructJoinResult(expr, proc)
}
cond, conds := extraJoinConditions(n.OnList)
arg := rightanti.NewArgument()
arg.RightTypes = right_typs
arg.Result = result
arg.Cond = cond
arg.Conditions = constructJoinConditions(conds, proc)
arg.RuntimeFilterSpecs = n.RuntimeFilterBuildList
arg.HashOnPK = n.Stats.HashmapStats != nil && n.Stats.HashmapStats.HashOnPK
arg.IsShuffle = n.Stats.HashmapStats != nil && n.Stats.HashmapStats.Shuffle
return arg
}
func constructSingle(n *plan.Node, typs []types.Type, proc *process.Process) *single.Argument {
result := make([]colexec.ResultPos, len(n.ProjectList))
for i, expr := range n.ProjectList {
result[i].Rel, result[i].Pos = constructJoinResult(expr, proc)
}
cond, conds := extraJoinConditions(n.OnList)
arg := single.NewArgument()
arg.Typs = typs
arg.Result = result
arg.Cond = cond
arg.Conditions = constructJoinConditions(conds, proc)
arg.RuntimeFilterSpecs = n.RuntimeFilterBuildList
arg.HashOnPK = n.Stats.HashmapStats != nil && n.Stats.HashmapStats.HashOnPK
return arg
}
func constructProduct(n *plan.Node, typs []types.Type, proc *process.Process) *product.Argument {
result := make([]colexec.ResultPos, len(n.ProjectList))
for i, expr := range n.ProjectList {
result[i].Rel, result[i].Pos = constructJoinResult(expr, proc)
}
arg := product.NewArgument()
arg.Typs = typs
arg.Result = result
return arg
}
func constructAnti(n *plan.Node, typs []types.Type, proc *process.Process) *anti.Argument {
result := make([]int32, len(n.ProjectList))
for i, expr := range n.ProjectList {
rel, pos := constructJoinResult(expr, proc)
if rel != 0 {
panic(moerr.NewNYI(proc.Ctx, "anti result '%s'", expr))
}
result[i] = pos
}
cond, conds := extraJoinConditions(n.OnList)
arg := anti.NewArgument()
arg.Typs = typs
arg.Result = result
arg.Cond = cond
arg.Conditions = constructJoinConditions(conds, proc)
arg.HashOnPK = n.Stats.HashmapStats != nil && n.Stats.HashmapStats.HashOnPK
arg.IsShuffle = n.Stats.HashmapStats != nil && n.Stats.HashmapStats.Shuffle
return arg
}
/*
func constructMark(n *plan.Node, typs []types.Type, proc *process.Process) *mark.Argument {
result := make([]int32, len(n.ProjectList))
for i, expr := range n.ProjectList {
rel, pos := constructJoinResult(expr, proc)
if rel == 0 {
result[i] = pos
} else if rel == -1 {
result[i] = -1
} else {
panic(moerr.NewNYI(proc.Ctx, "loop mark result '%s'", expr))
}
}
cond, conds := extraJoinConditions(n.OnList)
return &mark.Argument{
Typs: typs,
Result: result,
Cond: cond,
Conditions: constructJoinConditions(conds, proc),
OnList: n.OnList,
}
}
*/
func constructOrder(n *plan.Node) *order.Argument {
arg := order.NewArgument()
arg.OrderBySpec = n.OrderBy
return arg
}
func constructFill(n *plan.Node) *fill.Argument {
aggIdx := make([]int32, len(n.AggList))
for i, expr := range n.AggList {
f := expr.Expr.(*plan.Expr_F)
obj := int64(uint64(f.F.Func.Obj) & function.DistinctMask)
aggIdx[i], _ = function.DecodeOverloadID(obj)
}
arg := fill.NewArgument()
arg.ColLen = len(n.AggList)
arg.FillType = n.FillType
arg.FillVal = n.FillVal
arg.AggIds = aggIdx