github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/distsql_plan_scrub_physical.go (about)

     1  // Copyright 2017 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package sql
    12  
    13  import (
    14  	"github.com/cockroachdb/cockroach/pkg/sql/execinfrapb"
    15  	"github.com/cockroachdb/cockroach/pkg/sql/physicalplan"
    16  	"github.com/cockroachdb/cockroach/pkg/sql/rowexec"
    17  	"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
    18  	"github.com/cockroachdb/cockroach/pkg/util/hlc"
    19  )
    20  
    21  // createScrubPhysicalCheck generates a plan for running a physical
    22  // check for an index. The plan consists of TableReaders, with IsCheck
    23  // enabled, that scan an index span. By having IsCheck enabled, the
    24  // TableReaders will only emit errors encountered during scanning
    25  // instead of row data. The plan is finalized.
    26  func (dsp *DistSQLPlanner) createScrubPhysicalCheck(
    27  	planCtx *PlanningCtx,
    28  	n *scanNode,
    29  	desc sqlbase.TableDescriptor,
    30  	indexDesc sqlbase.IndexDescriptor,
    31  	readAsOf hlc.Timestamp,
    32  ) (PhysicalPlan, error) {
    33  	spec, _, err := initTableReaderSpec(n, planCtx, nil /* indexVarMap */)
    34  	if err != nil {
    35  		return PhysicalPlan{}, err
    36  	}
    37  
    38  	spanPartitions, err := dsp.PartitionSpans(planCtx, n.spans)
    39  	if err != nil {
    40  		return PhysicalPlan{}, err
    41  	}
    42  
    43  	var p PhysicalPlan
    44  	stageID := p.NewStageID()
    45  	p.ResultRouters = make([]physicalplan.ProcessorIdx, len(spanPartitions))
    46  	for i, sp := range spanPartitions {
    47  		tr := &execinfrapb.TableReaderSpec{}
    48  		*tr = *spec
    49  		tr.Spans = make([]execinfrapb.TableReaderSpan, len(sp.Spans))
    50  		for j := range sp.Spans {
    51  			tr.Spans[j].Span = sp.Spans[j]
    52  		}
    53  
    54  		proc := physicalplan.Processor{
    55  			Node: sp.Node,
    56  			Spec: execinfrapb.ProcessorSpec{
    57  				Core:    execinfrapb.ProcessorCoreUnion{TableReader: tr},
    58  				Output:  []execinfrapb.OutputRouterSpec{{Type: execinfrapb.OutputRouterSpec_PASS_THROUGH}},
    59  				StageID: stageID,
    60  			},
    61  		}
    62  
    63  		pIdx := p.AddProcessor(proc)
    64  		p.ResultRouters[i] = pIdx
    65  	}
    66  
    67  	// Set the plan's result types to be ScrubTypes.
    68  	p.ResultTypes = rowexec.ScrubTypes
    69  	p.PlanToStreamColMap = identityMapInPlace(make([]int, len(rowexec.ScrubTypes)))
    70  
    71  	dsp.FinalizePlan(planCtx, &p)
    72  	return p, nil
    73  }