Skip to content

Commit 9f3fd47

Browse files
committed
opt: use optimizer_span_limit in split-scan rules
Use the optimizer_span_limit session setting as an additional upper bound in splitScanIntoUnionScansOrSelects. When set, the span limit caps the hard maximum scan count, preventing the split-scan rules (SplitLimitedScanIntoUnionScans, SplitLimitedSelectIntoUnionSelects, SplitGroupByScanIntoUnionScans, etc.) from generating more union branches than the limit allows. Release note: None
1 parent 6f8952d commit 9f3fd47

3 files changed

Lines changed: 866 additions & 0 deletions

File tree

pkg/sql/opt/xform/general_funcs.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ func (c *CustomFuncs) splitScanIntoUnionScansOrSelects(
268268
// If OptSplitScanLimit is below maxScanCount, we will decrease maxScanCount
269269
// to that value because a hard limit should never be lower than a soft limit.
270270
hardMaxScanCount := int(c.e.evalCtx.SessionData().OptSplitScanLimit)
271+
if spanLimit := int(c.e.evalCtx.SessionData().OptimizerSpanLimit); spanLimit > 0 && spanLimit < hardMaxScanCount {
272+
hardMaxScanCount = spanLimit
273+
}
271274
if hardMaxScanCount < maxScanCount {
272275
maxScanCount = hardMaxScanCount
273276
}
@@ -661,6 +664,7 @@ func (c *CustomFuncs) makeNewScanPrivate(
661664
// ScanPrivate has a Constraint, the scan Constraint is returned. Otherwise, an
662665
// effort is made to retrieve a Constraint from the underlying table's check
663666
// constraints. getKnownScanConstraint assumes that the scan is not inverted.
667+
// TODO(michae2): Pass optimizer_span_limit to initIdxConstraintForIndex.
664668
func (c *CustomFuncs) getKnownScanConstraint(
665669
sp *memo.ScanPrivate,
666670
) (_ *constraint.Constraint, found bool) {

0 commit comments

Comments
 (0)