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

Cost-based decision between ORDER and SORT plans #8316

Merged
merged 2 commits into from
Nov 14, 2024

Conversation

dyemanov
Copy link
Member

@dyemanov dyemanov commented Nov 12, 2024

Implement cost calculation for the ORDER vs SORT choice when ordering is required for the query. The visible effects are:

  1. ORDER ... INDEX plan is almost never used, being inferior to SORT in most cases -- maybe except some queries with OPTIMIZE FOR FIRST ROWS hint, explicit or implicit (e.g. SELECT FIRST). This is already proven in practice to work better.
  2. SORT plan may be preferred to ORDER for the default OPTIMIZE FOR ALL ROWS scenario if its estimated as being cheaper.
  3. Queries should not imply that ORDER plan will be used always if a suitable index exists. We have a number of QA tests that are affected by this change.

The cost calculation will be adjusted once more statistics will be available to the optimizer (e.g. clustering factor).

const double REDUCE_SELECTIVITY_FACTOR_GREATER = 0.05;
const double REDUCE_SELECTIVITY_FACTOR_STARTING = 0.01;
const double REDUCE_SELECTIVITY_FACTOR_OTHER = 0.01;
constexpr double REDUCE_SELECTIVITY_FACTOR_EQUALITY = 0.001;
Copy link
Member

Choose a reason for hiding this comment

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

Should not better be inline constexpr?

@dyemanov dyemanov added the rdb label Nov 13, 2024
@dyemanov dyemanov merged commit 26e64e9 into master Nov 14, 2024
48 checks passed
@dyemanov dyemanov deleted the work/optimizer-cost-based-ordering branch November 14, 2024 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants