github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/rowexec/rowfetcher.go (about) 1 // Copyright 2019 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 rowexec 12 13 import ( 14 "context" 15 "time" 16 17 "github.com/cockroachdb/cockroach/pkg/kv" 18 "github.com/cockroachdb/cockroach/pkg/roachpb" 19 "github.com/cockroachdb/cockroach/pkg/sql/execinfra" 20 "github.com/cockroachdb/cockroach/pkg/sql/execinfrapb" 21 "github.com/cockroachdb/cockroach/pkg/sql/row" 22 "github.com/cockroachdb/cockroach/pkg/sql/sqlbase" 23 "github.com/cockroachdb/cockroach/pkg/util" 24 "github.com/cockroachdb/cockroach/pkg/util/hlc" 25 ) 26 27 // rowFetcher is an interface used to abstract a row fetcher so that a stat 28 // collector wrapper can be plugged in. 29 type rowFetcher interface { 30 StartScan( 31 _ context.Context, _ *kv.Txn, _ roachpb.Spans, limitBatches bool, limitHint int64, traceKV bool, 32 ) error 33 StartInconsistentScan( 34 _ context.Context, 35 _ *kv.DB, 36 initialTimestamp hlc.Timestamp, 37 maxTimestampAge time.Duration, 38 spans roachpb.Spans, 39 limitBatches bool, 40 limitHint int64, 41 traceKV bool, 42 ) error 43 44 NextRow(ctx context.Context) ( 45 sqlbase.EncDatumRow, *sqlbase.TableDescriptor, *sqlbase.IndexDescriptor, error) 46 47 // PartialKey is not stat-related but needs to be supported. 48 PartialKey(int) (roachpb.Key, error) 49 Reset() 50 GetBytesRead() int64 51 GetRangesInfo() []roachpb.RangeInfo 52 NextRowWithErrors(context.Context) (sqlbase.EncDatumRow, error) 53 } 54 55 // initRowFetcher initializes the fetcher. 56 func initRowFetcher( 57 flowCtx *execinfra.FlowCtx, 58 fetcher *row.Fetcher, 59 desc *sqlbase.TableDescriptor, 60 indexIdx int, 61 colIdxMap map[sqlbase.ColumnID]int, 62 reverseScan bool, 63 valNeededForCol util.FastIntSet, 64 isCheck bool, 65 alloc *sqlbase.DatumAlloc, 66 scanVisibility execinfrapb.ScanVisibility, 67 lockStr sqlbase.ScanLockingStrength, 68 ) (index *sqlbase.IndexDescriptor, isSecondaryIndex bool, err error) { 69 immutDesc := sqlbase.NewImmutableTableDescriptor(*desc) 70 index, isSecondaryIndex, err = immutDesc.FindIndexByIndexIdx(indexIdx) 71 if err != nil { 72 return nil, false, err 73 } 74 75 cols := immutDesc.Columns 76 if scanVisibility == execinfra.ScanVisibilityPublicAndNotPublic { 77 cols = immutDesc.ReadableColumns 78 } 79 tableArgs := row.FetcherTableArgs{ 80 Desc: immutDesc, 81 Index: index, 82 ColIdxMap: colIdxMap, 83 IsSecondaryIndex: isSecondaryIndex, 84 Cols: cols, 85 ValNeededForCol: valNeededForCol, 86 } 87 if err := fetcher.Init( 88 flowCtx.Codec(), 89 reverseScan, 90 lockStr, 91 true, /* returnRangeInfo */ 92 isCheck, 93 alloc, 94 tableArgs, 95 ); err != nil { 96 return nil, false, err 97 } 98 99 return index, isSecondaryIndex, nil 100 }