github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/causetstore/petri/acyclic/causet/embedded/initialize.go (about)

     1  // Copyright 2020 WHTCORPS INC, Inc.
     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  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package embedded
    15  
    16  import (
    17  	"github.com/whtcorpsinc/milevadb/causet/property"
    18  	"github.com/whtcorpsinc/milevadb/memex"
    19  	"github.com/whtcorpsinc/milevadb/soliton/plancodec"
    20  	"github.com/whtcorpsinc/milevadb/stochastikctx"
    21  	"github.com/whtcorpsinc/milevadb/types"
    22  )
    23  
    24  // Init initializes LogicalAggregation.
    25  func (la LogicalAggregation) Init(ctx stochastikctx.Context, offset int) *LogicalAggregation {
    26  	la.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeAgg, &la, offset)
    27  	return &la
    28  }
    29  
    30  // Init initializes LogicalJoin.
    31  func (p LogicalJoin) Init(ctx stochastikctx.Context, offset int) *LogicalJoin {
    32  	p.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeJoin, &p, offset)
    33  	return &p
    34  }
    35  
    36  // Init initializes DataSource.
    37  func (ds DataSource) Init(ctx stochastikctx.Context, offset int) *DataSource {
    38  	ds.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeDataSource, &ds, offset)
    39  	return &ds
    40  }
    41  
    42  // Init initializes EinsteinDBSingleGather.
    43  func (sg EinsteinDBSingleGather) Init(ctx stochastikctx.Context, offset int) *EinsteinDBSingleGather {
    44  	sg.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeEinsteinDBSingleGather, &sg, offset)
    45  	return &sg
    46  }
    47  
    48  // Init initializes LogicalBlockScan.
    49  func (ts LogicalBlockScan) Init(ctx stochastikctx.Context, offset int) *LogicalBlockScan {
    50  	ts.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeBlockScan, &ts, offset)
    51  	return &ts
    52  }
    53  
    54  // Init initializes LogicalIndexScan.
    55  func (is LogicalIndexScan) Init(ctx stochastikctx.Context, offset int) *LogicalIndexScan {
    56  	is.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeIdxScan, &is, offset)
    57  	return &is
    58  }
    59  
    60  // Init initializes LogicalApply.
    61  func (la LogicalApply) Init(ctx stochastikctx.Context, offset int) *LogicalApply {
    62  	la.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeApply, &la, offset)
    63  	return &la
    64  }
    65  
    66  // Init initializes LogicalSelection.
    67  func (p LogicalSelection) Init(ctx stochastikctx.Context, offset int) *LogicalSelection {
    68  	p.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeSel, &p, offset)
    69  	return &p
    70  }
    71  
    72  // Init initializes PhysicalSelection.
    73  func (p PhysicalSelection) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PhysicalSelection {
    74  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeSel, &p, offset)
    75  	p.childrenReqProps = props
    76  	p.stats = stats
    77  	return &p
    78  }
    79  
    80  // Init initializes LogicalUnionScan.
    81  func (p LogicalUnionScan) Init(ctx stochastikctx.Context, offset int) *LogicalUnionScan {
    82  	p.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeUnionScan, &p, offset)
    83  	return &p
    84  }
    85  
    86  // Init initializes LogicalProjection.
    87  func (p LogicalProjection) Init(ctx stochastikctx.Context, offset int) *LogicalProjection {
    88  	p.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeProj, &p, offset)
    89  	return &p
    90  }
    91  
    92  // Init initializes PhysicalProjection.
    93  func (p PhysicalProjection) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PhysicalProjection {
    94  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeProj, &p, offset)
    95  	p.childrenReqProps = props
    96  	p.stats = stats
    97  	return &p
    98  }
    99  
   100  // Init initializes LogicalUnionAll.
   101  func (p LogicalUnionAll) Init(ctx stochastikctx.Context, offset int) *LogicalUnionAll {
   102  	p.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeUnion, &p, offset)
   103  	return &p
   104  }
   105  
   106  // Init initializes LogicalPartitionUnionAll.
   107  func (p LogicalPartitionUnionAll) Init(ctx stochastikctx.Context, offset int) *LogicalPartitionUnionAll {
   108  	p.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypePartitionUnion, &p, offset)
   109  	return &p
   110  }
   111  
   112  // Init initializes PhysicalUnionAll.
   113  func (p PhysicalUnionAll) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PhysicalUnionAll {
   114  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeUnion, &p, offset)
   115  	p.childrenReqProps = props
   116  	p.stats = stats
   117  	return &p
   118  }
   119  
   120  // Init initializes LogicalSort.
   121  func (ls LogicalSort) Init(ctx stochastikctx.Context, offset int) *LogicalSort {
   122  	ls.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeSort, &ls, offset)
   123  	return &ls
   124  }
   125  
   126  // Init initializes PhysicalSort.
   127  func (p PhysicalSort) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PhysicalSort {
   128  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeSort, &p, offset)
   129  	p.childrenReqProps = props
   130  	p.stats = stats
   131  	return &p
   132  }
   133  
   134  // Init initializes NominalSort.
   135  func (p NominalSort) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *NominalSort {
   136  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeSort, &p, offset)
   137  	p.childrenReqProps = props
   138  	p.stats = stats
   139  	return &p
   140  }
   141  
   142  // Init initializes LogicalTopN.
   143  func (lt LogicalTopN) Init(ctx stochastikctx.Context, offset int) *LogicalTopN {
   144  	lt.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeTopN, &lt, offset)
   145  	return &lt
   146  }
   147  
   148  // Init initializes PhysicalTopN.
   149  func (p PhysicalTopN) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PhysicalTopN {
   150  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeTopN, &p, offset)
   151  	p.childrenReqProps = props
   152  	p.stats = stats
   153  	return &p
   154  }
   155  
   156  // Init initializes LogicalLimit.
   157  func (p LogicalLimit) Init(ctx stochastikctx.Context, offset int) *LogicalLimit {
   158  	p.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeLimit, &p, offset)
   159  	return &p
   160  }
   161  
   162  // Init initializes PhysicalLimit.
   163  func (p PhysicalLimit) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PhysicalLimit {
   164  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeLimit, &p, offset)
   165  	p.childrenReqProps = props
   166  	p.stats = stats
   167  	return &p
   168  }
   169  
   170  // Init initializes LogicalBlockDual.
   171  func (p LogicalBlockDual) Init(ctx stochastikctx.Context, offset int) *LogicalBlockDual {
   172  	p.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeDual, &p, offset)
   173  	return &p
   174  }
   175  
   176  // Init initializes PhysicalBlockDual.
   177  func (p PhysicalBlockDual) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int) *PhysicalBlockDual {
   178  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeDual, &p, offset)
   179  	p.stats = stats
   180  	return &p
   181  }
   182  
   183  // Init initializes LogicalMaxOneRow.
   184  func (p LogicalMaxOneRow) Init(ctx stochastikctx.Context, offset int) *LogicalMaxOneRow {
   185  	p.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeMaxOneRow, &p, offset)
   186  	return &p
   187  }
   188  
   189  // Init initializes PhysicalMaxOneRow.
   190  func (p PhysicalMaxOneRow) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PhysicalMaxOneRow {
   191  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeMaxOneRow, &p, offset)
   192  	p.childrenReqProps = props
   193  	p.stats = stats
   194  	return &p
   195  }
   196  
   197  // Init initializes LogicalWindow.
   198  func (p LogicalWindow) Init(ctx stochastikctx.Context, offset int) *LogicalWindow {
   199  	p.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeWindow, &p, offset)
   200  	return &p
   201  }
   202  
   203  // Init initializes PhysicalWindow.
   204  func (p PhysicalWindow) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PhysicalWindow {
   205  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeWindow, &p, offset)
   206  	p.childrenReqProps = props
   207  	p.stats = stats
   208  	return &p
   209  }
   210  
   211  // Init initializes PhysicalShuffle.
   212  func (p PhysicalShuffle) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PhysicalShuffle {
   213  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeShuffle, &p, offset)
   214  	p.childrenReqProps = props
   215  	p.stats = stats
   216  	return &p
   217  }
   218  
   219  // Init initializes PhysicalShuffleDataSourceStub.
   220  func (p PhysicalShuffleDataSourceStub) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PhysicalShuffleDataSourceStub {
   221  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeShuffleDataSourceStub, &p, offset)
   222  	p.childrenReqProps = props
   223  	p.stats = stats
   224  	return &p
   225  }
   226  
   227  // Init initializes UFIDelate.
   228  func (p UFIDelate) Init(ctx stochastikctx.Context) *UFIDelate {
   229  	p.baseCauset = newBaseCauset(ctx, plancodec.TypeUFIDelate, 0)
   230  	return &p
   231  }
   232  
   233  // Init initializes Delete.
   234  func (p Delete) Init(ctx stochastikctx.Context) *Delete {
   235  	p.baseCauset = newBaseCauset(ctx, plancodec.TypeDelete, 0)
   236  	return &p
   237  }
   238  
   239  // Init initializes Insert.
   240  func (p Insert) Init(ctx stochastikctx.Context) *Insert {
   241  	p.baseCauset = newBaseCauset(ctx, plancodec.TypeInsert, 0)
   242  	return &p
   243  }
   244  
   245  // Init initializes LogicalShow.
   246  func (p LogicalShow) Init(ctx stochastikctx.Context) *LogicalShow {
   247  	p.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeShow, &p, 0)
   248  	return &p
   249  }
   250  
   251  // Init initializes LogicalShowDBSJobs.
   252  func (p LogicalShowDBSJobs) Init(ctx stochastikctx.Context) *LogicalShowDBSJobs {
   253  	p.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeShowDBSJobs, &p, 0)
   254  	return &p
   255  }
   256  
   257  // Init initializes PhysicalShow.
   258  func (p PhysicalShow) Init(ctx stochastikctx.Context) *PhysicalShow {
   259  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeShow, &p, 0)
   260  	// Just use pseudo stats to avoid panic.
   261  	p.stats = &property.StatsInfo{RowCount: 1}
   262  	return &p
   263  }
   264  
   265  // Init initializes PhysicalShowDBSJobs.
   266  func (p PhysicalShowDBSJobs) Init(ctx stochastikctx.Context) *PhysicalShowDBSJobs {
   267  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeShowDBSJobs, &p, 0)
   268  	// Just use pseudo stats to avoid panic.
   269  	p.stats = &property.StatsInfo{RowCount: 1}
   270  	return &p
   271  }
   272  
   273  // Init initializes LogicalLock.
   274  func (p LogicalLock) Init(ctx stochastikctx.Context) *LogicalLock {
   275  	p.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeLock, &p, 0)
   276  	return &p
   277  }
   278  
   279  // Init initializes PhysicalLock.
   280  func (p PhysicalLock) Init(ctx stochastikctx.Context, stats *property.StatsInfo, props ...*property.PhysicalProperty) *PhysicalLock {
   281  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeLock, &p, 0)
   282  	p.childrenReqProps = props
   283  	p.stats = stats
   284  	return &p
   285  }
   286  
   287  // Init initializes PhysicalBlockScan.
   288  func (p PhysicalBlockScan) Init(ctx stochastikctx.Context, offset int) *PhysicalBlockScan {
   289  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeBlockScan, &p, offset)
   290  	return &p
   291  }
   292  
   293  // Init initializes PhysicalIndexScan.
   294  func (p PhysicalIndexScan) Init(ctx stochastikctx.Context, offset int) *PhysicalIndexScan {
   295  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeIdxScan, &p, offset)
   296  	return &p
   297  }
   298  
   299  // Init initializes LogicalMemBlock.
   300  func (p LogicalMemBlock) Init(ctx stochastikctx.Context, offset int) *LogicalMemBlock {
   301  	p.baseLogicalCauset = newBaseLogicalCauset(ctx, plancodec.TypeMemBlockScan, &p, offset)
   302  	return &p
   303  }
   304  
   305  // Init initializes PhysicalMemBlock.
   306  func (p PhysicalMemBlock) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int) *PhysicalMemBlock {
   307  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeMemBlockScan, &p, offset)
   308  	p.stats = stats
   309  	return &p
   310  }
   311  
   312  // Init initializes PhysicalHashJoin.
   313  func (p PhysicalHashJoin) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PhysicalHashJoin {
   314  	tp := plancodec.TypeHashJoin
   315  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, tp, &p, offset)
   316  	p.childrenReqProps = props
   317  	p.stats = stats
   318  	return &p
   319  }
   320  
   321  // Init initializes BatchPointGetCauset.
   322  func (p PhysicalBroadCastJoin) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PhysicalBroadCastJoin {
   323  	tp := plancodec.TypeBroadcastJoin
   324  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, tp, &p, offset)
   325  	p.childrenReqProps = props
   326  	p.stats = stats
   327  	return &p
   328  
   329  }
   330  
   331  // Init initializes PhysicalMergeJoin.
   332  func (p PhysicalMergeJoin) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int) *PhysicalMergeJoin {
   333  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeMergeJoin, &p, offset)
   334  	p.stats = stats
   335  	return &p
   336  }
   337  
   338  // Init initializes basePhysicalAgg.
   339  func (base basePhysicalAgg) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int) *basePhysicalAgg {
   340  	base.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeHashAgg, &base, offset)
   341  	base.stats = stats
   342  	return &base
   343  }
   344  
   345  func (base basePhysicalAgg) initForHash(ctx stochastikctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PhysicalHashAgg {
   346  	p := &PhysicalHashAgg{base}
   347  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeHashAgg, p, offset)
   348  	p.childrenReqProps = props
   349  	p.stats = stats
   350  	return p
   351  }
   352  
   353  func (base basePhysicalAgg) initForStream(ctx stochastikctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PhysicalStreamAgg {
   354  	p := &PhysicalStreamAgg{base}
   355  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeStreamAgg, p, offset)
   356  	p.childrenReqProps = props
   357  	p.stats = stats
   358  	return p
   359  }
   360  
   361  // Init initializes PhysicalApply.
   362  func (p PhysicalApply) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PhysicalApply {
   363  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeApply, &p, offset)
   364  	p.childrenReqProps = props
   365  	p.stats = stats
   366  	return &p
   367  }
   368  
   369  // Init initializes PhysicalUnionScan.
   370  func (p PhysicalUnionScan) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PhysicalUnionScan {
   371  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeUnionScan, &p, offset)
   372  	p.childrenReqProps = props
   373  	p.stats = stats
   374  	return &p
   375  }
   376  
   377  // Init initializes PhysicalIndexLookUpReader.
   378  func (p PhysicalIndexLookUpReader) Init(ctx stochastikctx.Context, offset int) *PhysicalIndexLookUpReader {
   379  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeIndexLookUp, &p, offset)
   380  	p.BlockCausets = flattenPushDownCauset(p.blockCauset)
   381  	p.IndexCausets = flattenPushDownCauset(p.indexCauset)
   382  	p.schemaReplicant = p.blockCauset.Schema()
   383  	return &p
   384  }
   385  
   386  // Init initializes PhysicalIndexMergeReader.
   387  func (p PhysicalIndexMergeReader) Init(ctx stochastikctx.Context, offset int) *PhysicalIndexMergeReader {
   388  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeIndexMerge, &p, offset)
   389  	if p.blockCauset != nil {
   390  		p.stats = p.blockCauset.statsInfo()
   391  	} else {
   392  		var totalRowCount float64
   393  		for _, partCauset := range p.partialCausets {
   394  			totalRowCount += partCauset.StatsCount()
   395  		}
   396  		p.stats = p.partialCausets[0].statsInfo().ScaleByExpectCnt(totalRowCount)
   397  		p.stats.StatsVersion = p.partialCausets[0].statsInfo().StatsVersion
   398  	}
   399  	p.PartialCausets = make([][]PhysicalCauset, 0, len(p.partialCausets))
   400  	for _, partialCauset := range p.partialCausets {
   401  		tempCausets := flattenPushDownCauset(partialCauset)
   402  		p.PartialCausets = append(p.PartialCausets, tempCausets)
   403  	}
   404  	if p.blockCauset != nil {
   405  		p.BlockCausets = flattenPushDownCauset(p.blockCauset)
   406  		p.schemaReplicant = p.blockCauset.Schema()
   407  	} else {
   408  		switch p.PartialCausets[0][0].(type) {
   409  		case *PhysicalBlockScan:
   410  			p.schemaReplicant = p.PartialCausets[0][0].Schema()
   411  		default:
   412  			is := p.PartialCausets[0][0].(*PhysicalIndexScan)
   413  			p.schemaReplicant = is.dataSourceSchema
   414  		}
   415  	}
   416  	return &p
   417  }
   418  
   419  // Init initializes PhysicalBlockReader.
   420  func (p PhysicalBlockReader) Init(ctx stochastikctx.Context, offset int) *PhysicalBlockReader {
   421  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeBlockReader, &p, offset)
   422  	if p.blockCauset != nil {
   423  		p.BlockCausets = flattenPushDownCauset(p.blockCauset)
   424  		p.schemaReplicant = p.blockCauset.Schema()
   425  	}
   426  	return &p
   427  }
   428  
   429  // Init initializes PhysicalIndexReader.
   430  func (p PhysicalIndexReader) Init(ctx stochastikctx.Context, offset int) *PhysicalIndexReader {
   431  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeIndexReader, &p, offset)
   432  	p.SetSchema(nil)
   433  	return &p
   434  }
   435  
   436  // Init initializes PhysicalIndexJoin.
   437  func (p PhysicalIndexJoin) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PhysicalIndexJoin {
   438  	p.basePhysicalCauset = newBasePhysicalCauset(ctx, plancodec.TypeIndexJoin, &p, offset)
   439  	p.childrenReqProps = props
   440  	p.stats = stats
   441  	return &p
   442  }
   443  
   444  // Init initializes PhysicalIndexMergeJoin.
   445  func (p PhysicalIndexMergeJoin) Init(ctx stochastikctx.Context) *PhysicalIndexMergeJoin {
   446  	ctx.GetStochastikVars().CausetID++
   447  	p.tp = plancodec.TypeIndexMergeJoin
   448  	p.id = ctx.GetStochastikVars().CausetID
   449  	p.ctx = ctx
   450  	return &p
   451  }
   452  
   453  // Init initializes PhysicalIndexHashJoin.
   454  func (p PhysicalIndexHashJoin) Init(ctx stochastikctx.Context) *PhysicalIndexHashJoin {
   455  	ctx.GetStochastikVars().CausetID++
   456  	p.tp = plancodec.TypeIndexHashJoin
   457  	p.id = ctx.GetStochastikVars().CausetID
   458  	p.ctx = ctx
   459  	return &p
   460  }
   461  
   462  // Init initializes BatchPointGetCauset.
   463  func (p BatchPointGetCauset) Init(ctx stochastikctx.Context, stats *property.StatsInfo, schemaReplicant *memex.Schema, names []*types.FieldName, offset int) *BatchPointGetCauset {
   464  	p.baseCauset = newBaseCauset(ctx, plancodec.TypeBatchPointGet, offset)
   465  	p.schemaReplicant = schemaReplicant
   466  	p.names = names
   467  	p.stats = stats
   468  	p.DeferredCausets = ExpandVirtualDeferredCauset(p.DeferredCausets, p.schemaReplicant, p.TblInfo.DeferredCausets)
   469  	return &p
   470  }
   471  
   472  // Init initializes PointGetCauset.
   473  func (p PointGetCauset) Init(ctx stochastikctx.Context, stats *property.StatsInfo, offset int, props ...*property.PhysicalProperty) *PointGetCauset {
   474  	p.baseCauset = newBaseCauset(ctx, plancodec.TypePointGet, offset)
   475  	p.stats = stats
   476  	p.DeferredCausets = ExpandVirtualDeferredCauset(p.DeferredCausets, p.schemaReplicant, p.TblInfo.DeferredCausets)
   477  	return &p
   478  }
   479  
   480  func flattenTreeCauset(plan PhysicalCauset, plans []PhysicalCauset) []PhysicalCauset {
   481  	plans = append(plans, plan)
   482  	for _, child := range plan.Children() {
   483  		plans = flattenTreeCauset(child, plans)
   484  	}
   485  	return plans
   486  }
   487  
   488  // flattenPushDownCauset converts a plan tree to a list, whose head is the leaf node like causet scan.
   489  func flattenPushDownCauset(p PhysicalCauset) []PhysicalCauset {
   490  	plans := make([]PhysicalCauset, 0, 5)
   491  	plans = flattenTreeCauset(p, plans)
   492  	for i := 0; i < len(plans)/2; i++ {
   493  		j := len(plans) - i - 1
   494  		plans[i], plans[j] = plans[j], plans[i]
   495  	}
   496  	return plans
   497  }