Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql,colexec: minor cleanup of scan-related things #57267

Merged
merged 1 commit into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions pkg/sql/colfetcher/colbatch_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ func NewColBatchScan(
var sysColDescs []descpb.ColumnDescriptor
if spec.HasSystemColumns {
sysColDescs = colinfo.AllSystemColumnDescs
}
for i := range sysColDescs {
typs = append(typs, sysColDescs[i].Type)
columnIdxMap.Set(sysColDescs[i].ID, columnIdxMap.Len())
for i := range sysColDescs {
typs = append(typs, sysColDescs[i].Type)
columnIdxMap.Set(sysColDescs[i].ID, columnIdxMap.Len())
}
}

semaCtx := tree.MakeSemaContext()
Expand All @@ -192,9 +192,7 @@ func NewColBatchScan(

fetcher := cFetcherPool.Get().(*cFetcher)
if _, _, err := initCRowFetcher(
flowCtx.Codec(), allocator, fetcher, table, int(spec.IndexIdx), columnIdxMap,
spec.Reverse, neededColumns, spec.Visibility, spec.LockingStrength, spec.LockingWaitPolicy,
sysColDescs,
flowCtx.Codec(), allocator, fetcher, table, columnIdxMap, neededColumns, spec, sysColDescs,
); err != nil {
return nil, err
}
Expand Down Expand Up @@ -224,22 +222,18 @@ func initCRowFetcher(
allocator *colmem.Allocator,
fetcher *cFetcher,
desc *tabledesc.Immutable,
indexIdx int,
colIdxMap catalog.TableColMap,
reverseScan bool,
valNeededForCol util.FastIntSet,
scanVisibility execinfrapb.ScanVisibility,
lockStrength descpb.ScanLockingStrength,
lockWaitPolicy descpb.ScanLockingWaitPolicy,
spec *execinfrapb.TableReaderSpec,
systemColumnDescs []descpb.ColumnDescriptor,
) (index *descpb.IndexDescriptor, isSecondaryIndex bool, err error) {
index, isSecondaryIndex, err = desc.FindIndexByIndexIdx(indexIdx)
index, isSecondaryIndex, err = desc.FindIndexByIndexIdx(int(spec.IndexIdx))
if err != nil {
return nil, false, err
}

cols := desc.Columns
if scanVisibility == execinfra.ScanVisibilityPublicAndNotPublic {
if spec.Visibility == execinfra.ScanVisibilityPublicAndNotPublic {
cols = desc.ReadableColumns
}
// Add on any requested system columns. We slice cols to avoid modifying
Expand All @@ -254,7 +248,7 @@ func initCRowFetcher(
ValNeededForCol: valNeededForCol,
}
if err := fetcher.Init(
codec, allocator, reverseScan, lockStrength, lockWaitPolicy, tableArgs,
codec, allocator, spec.Reverse, spec.LockingStrength, spec.LockingWaitPolicy, tableArgs,
); err != nil {
return nil, false, err
}
Expand Down
20 changes: 11 additions & 9 deletions pkg/sql/distsql_physical_planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ func getIndexIdx(index *descpb.IndexDescriptor, desc *tabledesc.Immutable) (uint
// initTableReaderSpec initializes a TableReaderSpec/PostProcessSpec that
// corresponds to a scanNode, except for the Spans and OutputColumns.
func initTableReaderSpec(
n *scanNode, planCtx *PlanningCtx, indexVarMap []int,
n *scanNode,
) (*execinfrapb.TableReaderSpec, execinfrapb.PostProcessSpec, error) {
s := physicalplan.NewTableReaderSpec()
*s = execinfrapb.TableReaderSpec{
Expand Down Expand Up @@ -1013,8 +1013,9 @@ func tableOrdinal(
}
if visibility == execinfra.ScanVisibilityPublicAndNotPublic {
offset := len(desc.Columns)
for i, col := range desc.MutationColumns() {
if col.ID == colID {
mutationColumns := desc.MutationColumns()
for i := range mutationColumns {
if mutationColumns[i].ID == colID {
return offset + i
}
}
Expand Down Expand Up @@ -1156,7 +1157,6 @@ func (dsp *DistSQLPlanner) CheckNodeHealthAndVersion(

// createTableReaders generates a plan consisting of table reader processors,
// one for each node that has spans that we are reading.
// overridesResultColumns is optional.
func (dsp *DistSQLPlanner) createTableReaders(
planCtx *PlanningCtx, n *scanNode,
) (*PhysicalPlan, error) {
Expand All @@ -1166,7 +1166,7 @@ func (dsp *DistSQLPlanner) createTableReaders(
// scanNodeToTableOrdinalMap is a map from scan node column ordinal to
// table reader column ordinal.
scanNodeToTableOrdinalMap := toTableOrdinals(n.cols, n.desc, n.colCfg.visibility)
spec, post, err := initTableReaderSpec(n, planCtx, scanNodeToTableOrdinalMap)
spec, post, err := initTableReaderSpec(n)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1285,8 +1285,9 @@ func (dsp *DistSQLPlanner) planTableReaders(
typs = append(typs, info.desc.Columns[i].Type)
}
if returnMutations {
for _, col := range info.desc.MutationColumns() {
typs = append(typs, col.Type)
mutationColumns := info.desc.MutationColumns()
for i := range mutationColumns {
typs = append(typs, mutationColumns[i].Type)
}
}
if info.containsSystemColumns {
Expand All @@ -1308,8 +1309,9 @@ func (dsp *DistSQLPlanner) planTableReaders(
colID++
}
if returnMutations {
for _, c := range info.desc.MutationColumns() {
descColumnIDs.Set(colID, int(c.ID))
mutationColumns := info.desc.MutationColumns()
for i := range mutationColumns {
descColumnIDs.Set(colID, int(mutationColumns[i].ID))
colID++
}
}
Expand Down
10 changes: 2 additions & 8 deletions pkg/sql/distsql_plan_scrub_physical.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
package sql

import (
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
"github.com/cockroachdb/cockroach/pkg/sql/execinfrapb"
"github.com/cockroachdb/cockroach/pkg/sql/physicalplan"
"github.com/cockroachdb/cockroach/pkg/sql/rowexec"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
)

// createScrubPhysicalCheck generates a plan for running a physical
Expand All @@ -24,13 +22,9 @@ import (
// TableReaders will only emit errors encountered during scanning
// instead of row data. The plan is finalized.
func (dsp *DistSQLPlanner) createScrubPhysicalCheck(
planCtx *PlanningCtx,
n *scanNode,
desc descpb.TableDescriptor,
indexDesc descpb.IndexDescriptor,
readAsOf hlc.Timestamp,
planCtx *PlanningCtx, n *scanNode,
) (*PhysicalPlan, error) {
spec, _, err := initTableReaderSpec(n, planCtx, nil /* indexVarMap */)
spec, _, err := initTableReaderSpec(n)
if err != nil {
return nil, err
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/sql/distsql_plan_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func (dsp *DistSQLPlanner) createStatsPlan(
if err != nil {
return nil, err
}
var colIdxMap catalog.TableColMap
for i, c := range scan.cols {
colIdxMap.Set(c.ID, i)
}
sb := span.MakeBuilder(planCtx.EvalContext(), planCtx.ExtendedEvalCtx.Codec, desc, scan.index)
scan.spans, err = sb.UnconstrainedSpans()
if err != nil {
Expand Down Expand Up @@ -112,7 +116,7 @@ func (dsp *DistSQLPlanner) createStatsPlan(
StatName: s.name,
}
for i, colID := range s.columns {
colIdx, ok := scan.colIdxMap.Get(colID)
colIdx, ok := colIdxMap.Get(colID)
if !ok {
panic("necessary column not scanned")
}
Expand Down
7 changes: 0 additions & 7 deletions pkg/sql/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"sync"

"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc"
Expand Down Expand Up @@ -64,9 +63,6 @@ type scanNode struct {
// There is a 1-1 correspondence between cols and resultColumns.
resultColumns colinfo.ResultColumns

// Map used to get the index for columns in cols.
colIdxMap catalog.TableColMap

spans []roachpb.Span
reverse bool

Expand Down Expand Up @@ -329,8 +325,5 @@ func (n *scanNode) initDescDefaults(colCfg scanColumnsConfig) error {

// Set up the rest of the scanNode.
n.resultColumns = colinfo.ResultColumnsFromColDescPtrs(n.desc.GetID(), n.cols)
for i, c := range n.cols {
n.colIdxMap.Set(c.ID, i)
}
return nil
}
3 changes: 1 addition & 2 deletions pkg/sql/scrub_physical.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ func (o *physicalCheckOperation) Start(params runParams) error {
// that scrubNode needs to perform, we need to make sure that scrubNode
// is not closed when this physical check operation is being cleaned up.
planCtx.ignoreClose = true
physPlan, err := params.extendedEvalCtx.DistSQLPlanner.createScrubPhysicalCheck(
planCtx, scan, *o.tableDesc.TableDesc(), *o.indexDesc, params.p.ExecCfg().Clock.Now())
physPlan, err := params.extendedEvalCtx.DistSQLPlanner.createScrubPhysicalCheck(planCtx, scan)
if err != nil {
return err
}
Expand Down