github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/execinfra/scanbase.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 execinfra
    12  
    13  import (
    14  	"github.com/cockroachdb/cockroach/pkg/sql/execinfrapb"
    15  	"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
    16  )
    17  
    18  // ParallelScanResultThreshold is the number of results up to which, if the
    19  // maximum number of results returned by a scan is known, the table reader
    20  // disables batch limits in the dist sender. This results in the parallelization
    21  // of these scans.
    22  const ParallelScanResultThreshold = 10000
    23  
    24  // ScanShouldLimitBatches returns whether the scan should pace itself.
    25  func ScanShouldLimitBatches(maxResults uint64, limitHint int64, flowCtx *FlowCtx) bool {
    26  	// We don't limit batches if the scan doesn't have a limit, and if the
    27  	// spans scanned will return less than the ParallelScanResultThreshold.
    28  	// This enables distsender parallelism - if we limit batches, distsender
    29  	// does *not* parallelize multi-range scan requests.
    30  	if maxResults != 0 &&
    31  		maxResults < ParallelScanResultThreshold &&
    32  		limitHint == 0 &&
    33  		sqlbase.ParallelScans.Get(&flowCtx.Cfg.Settings.SV) {
    34  		return false
    35  	}
    36  	return true
    37  }
    38  
    39  // Prettier aliases for execinfrapb.ScanVisibility values.
    40  const (
    41  	ScanVisibilityPublic             = execinfrapb.ScanVisibility_PUBLIC
    42  	ScanVisibilityPublicAndNotPublic = execinfrapb.ScanVisibility_PUBLIC_AND_NOT_PUBLIC
    43  )