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

Adding page for CBO #24736

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,21 @@ Currently, YugabyteDB doesn't run a background job like PostgreSQL autovacuum to

## Cost estimation

For each potential execution plan, the optimizer calculates costs in terms of I/O, CPU usage, and memory consumption. These costs help the optimizer compare which plan would likely be the most efficient to execute given the current database state and query context. Some of the factors included in the cost estimation are:
For each potential execution plan, the optimizer calculates costs in terms of I/O, CPU usage, and memory consumption. These costs help the optimizer compare which plan would likely be the most efficient to execute given the current database state and query context.

ddhodge marked this conversation as resolved.
Show resolved Hide resolved
{{<tip>}}
These estimates can be seen when using the DEBUG option in the [EXPLAIN](../../../api/ysql/the-sql-language/statements/perf_explain) command as EXPLAIN (ANALYZE, DEBUG).
{{</tip>}}

Some of the factors included in the cost estimation are discussed below.

### Cost of data fetch

To estimate the cost of fetching a tuple from [DocDB](../../docdb/), factors such as the number of SST files that may need to be read, and the estimated number of [seeks](../../docdb/lsm-sst/#seek), [previous](../../docdb/lsm-sst/#previous), and [next](../../docdb/lsm-sst/#next) operations that may be executed in the LSM subsystem, are taken into account.

### Index scan

As the primary key is part of the base table and that each [SST](../../docdb/lsm-sst) of the base table is sorted in the order of the primary key the primary index lookup cheaper compared to secondary index lookup. Depending on the type of query this distinction is considered.
When an index is used, any additional columns needed for the query must be retrieved from the corresponding row in the main table, which can be more costly than scanning only the base table. However, this isn’t an issue if the index is a covering index. To determine the most efficient execution plan, the CBO compares the cost of an index scan with that of a main table scan.
ddhodge marked this conversation as resolved.
Show resolved Hide resolved

### Pushdown to storage layer

Expand Down