MCPcopy
hub / github.com/pingcap/tidb / buildUnionScanFromReader

Method buildUnionScanFromReader

pkg/executor/builder.go:1397–1537  ·  view source on GitHub ↗

buildUnionScanFromReader builds union scan executor from child executor. Note that this function may be called by inner workers of index lookup join concurrently. Be careful to avoid data race.

(reader exec.Executor, v *plannercore.PhysicalUnionScan)

Source from the content-addressed store, hash-verified

1395// Note that this function may be called by inner workers of index lookup join concurrently.
1396// Be careful to avoid data race.
1397func (b *executorBuilder) buildUnionScanFromReader(reader exec.Executor, v *plannercore.PhysicalUnionScan) exec.Executor {
1398 // If reader is union, it means a partition table and we should transfer as above.
1399 if x, ok := reader.(*unionexec.UnionExec); ok {
1400 for i, child := range x.AllChildren() {
1401 x.SetChildren(i, b.buildUnionScanFromReader(child, v))
1402 if b.err != nil {
1403 return nil
1404 }
1405 }
1406 return x
1407 }
1408 us := &UnionScanExec{BaseExecutor: exec.NewBaseExecutor(b.ctx, v.Schema(), v.ID(), reader)}
1409 // Get the handle column index of the below Plan.
1410 us.handleCols = v.HandleCols
1411 us.mutableRow = chunk.MutRowFromTypes(exec.RetTypes(us))
1412
1413 // If the push-downed condition contains virtual column, we may build a selection upon reader
1414 originReader := reader
1415 if sel, ok := reader.(*SelectionExec); ok {
1416 reader = sel.Children(0)
1417 }
1418
1419 us.collators = make([]collate.Collator, 0, len(us.columns))
1420 for _, tp := range exec.RetTypes(us) {
1421 us.collators = append(us.collators, collate.GetCollator(tp.GetCollate()))
1422 }
1423
1424 startTS, err := b.getSnapshotTS()
1425 sessionVars := b.ctx.GetSessionVars()
1426 if err != nil {
1427 b.err = err
1428 return nil
1429 }
1430
1431 switch x := reader.(type) {
1432 case *MPPGather:
1433 us.desc = false
1434 us.keepOrder = false
1435 us.conditions, us.conditionsWithVirCol = plannercore.SplitSelCondsWithVirtualColumn(v.Conditions)
1436 us.columns = x.columns
1437 us.table = x.table
1438 us.virtualColumnIndex = x.virtualColumnIndex
1439 us.handleCachedTable(b, x, sessionVars, startTS)
1440 case *TableReaderExecutor:
1441 us.desc = x.desc
1442 us.keepOrder = x.keepOrder
1443 colIdxes, err := collectColIdxFromByItems(x.byItems, x.columns)
1444 if err != nil {
1445 b.err = err
1446 return nil
1447 }
1448 us.usedIndex = colIdxes
1449 if len(us.usedIndex) > 0 {
1450 us.needExtraSorting = true
1451 }
1452 us.conditions, us.conditionsWithVirCol = plannercore.SplitSelCondsWithVirtualColumn(v.Conditions)
1453 us.columns = x.columns
1454 us.table = x.table

Callers 2

buildUnionScanExecMethod · 0.95

Calls 15

getSnapshotTSMethod · 0.95
handleCachedTableMethod · 0.95
NewBaseExecutorFunction · 0.92
MutRowFromTypesFunction · 0.92
RetTypesFunction · 0.92
GetCollatorFunction · 0.92
collectColIdxFromByItemsFunction · 0.85
buildVirtualColumnIndexFunction · 0.85
AllChildrenMethod · 0.65
SetChildrenMethod · 0.65
SchemaMethod · 0.65
IDMethod · 0.65

Tested by

no test coverage detected