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)
| 1395 | // Note that this function may be called by inner workers of index lookup join concurrently. |
| 1396 | // Be careful to avoid data race. |
| 1397 | func (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 |
no test coverage detected