sql, opt: avoid full scans in mutation queries with cost flags #137984
+3,543
−2,536
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
opt: convert
memo.Cost
to a struct withCostFlags
This is a mechanical change that will set up the ability to use
CostFlags
in a future commit.Release note: None
opt,sql: support hint to avoid full scan
Added a hint to avoid full scans (see release note below for details).
To support this change, added a field to
memo.Cost
with a new typememo.CostFlags
, which contains a number of boolean flags and supports"multi-dimensional costing". This allows the optimizer to compare plans
based on the flags set in addition to the single-dimensional float64
cost. For example, plans with the new
FullScanPenalty
cost flag enabledwill always be more expensive than plans without any cost flags, even
if the base float64 cost is lower.
The new
CostFlags
type also includes a flag forHugeCostPenalty
, whichmust be set for plans with
hugeCost
. This ensures that existinghints that use
hugeCost
still work if some other cost flags are set,since
HugeCostPenalty
takes precedence over other cost flags.This new
CostFlags
field is needed to support hints that do not cause anerror if the optimizer cannot find a plan complying with the hint. This
is needed because the previous approach of simply using
hugeCost
toavoid certain plans meant that if such plans were unavoidable, we could
not effectively compare plans with cost greater than
hugeCost
due toloss of floating point precision.
Informs #79683
Release note (sql change): Added support for a new index hint,
AVOID_FULL_SCAN
, which will prevent the optimizer from planning afull scan for the specified table if any other plan is possible. The
hint can be used in the same way as other existing index hints. For
example,
SELECT * FROM table_name@{AVOID_FULL_SCAN};
. This hint issimilar to
NO_FULL_SCAN
, but will not error if a full scan cannot beavoided. Note that normally a full scan of a partial index would not
be considered a "full scan" for the purposes of the
NO_FULL_SCAN
andAVOID_FULL_SCAN
hints, but if the user has explicitly forced thepartial index via
FORCE_INDEX=index_name
, we do consider it a fullscan.
sql,opt: add setting
avoid_full_table_scans_in_mutations
Fixes #79683
Release note (sql change): Added a new session setting
avoid_full_table_scans_in_mutations
, which when set to true, causesthe optimizer to avoid planning full table scans for mutation queries
if any other plan is possible. It now defaults to true.
opt: remove a stale comment above
optbuilder.buildScan
Removed a comment that references a function parameter that no longer
exists.
Release note: None