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, opt: avoid full scans in mutation queries #137781

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rytaft
Copy link
Collaborator

@rytaft rytaft commented Dec 19, 2024

opt,sql: support hint to avoid full scan

Informs #79683

Release note (sql change): Added support for a new index hint,
AVOID_FULL_SCAN, which will prevent the optimizer from planning a
full 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};. Note that a
full scan of a partial index may still be preferred by the optimizer,
unless AVOID_FULL_SCAN is used in combination with a specific partial
index via FORCE_INDEX=index_name. This hint is similar to NO_FULL_SCAN,
but will not error if a full scan cannot be avoided.

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, causes
the 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

Copy link

blathers-crl bot commented Dec 19, 2024

Your pull request contains more than 1000 changes. It is strongly encouraged to split big PRs into smaller chunks.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@rytaft rytaft force-pushed the avoid-full-scans branch 3 times, most recently from 1e19a05 to cff59af Compare December 20, 2024 01:46
Informs cockroachdb#79683

Release note (sql change): Added support for a new index hint,
AVOID_FULL_SCAN, which will prevent the optimizer from planning a
full 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};. Note that a
full scan of a partial index may still be preferred by the optimizer,
unless AVOID_FULL_SCAN is used in combination with a specific partial
index via FORCE_INDEX=index_name. This hint is similar to NO_FULL_SCAN,
but will not error if a full scan cannot be avoided.
Fixes cockroachdb#79683

Release note (sql change): Added a new session setting
avoid_full_table_scans_in_mutations, which when set to true, causes
the optimizer to avoid planning full table scans for mutation queries
if any other plan is possible. It now defaults to true.
Removed a comment that references a function parameter that no longer
exists.

Release note: None
Copy link
Collaborator Author

@rytaft rytaft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained


pkg/sql/opt/exec/execbuilder/testdata/update line 404 at r3 (raw file):

└── • render
    │
    └── • limit

Need to investigate why we lost the top k here


pkg/sql/opt/exec/execbuilder/testdata/unique line 5707 at r3 (raw file):

vectorized: true
·
• root

This seems concerning that we're no longer getting the insert fast path here.

@rytaft rytaft marked this pull request as ready for review December 20, 2024 02:47
@rytaft rytaft requested review from a team as code owners December 20, 2024 02:47
@rytaft rytaft requested review from mw5h and mgartner and removed request for a team December 20, 2024 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

opt: the optimizer cost model should consider contention
2 participants