You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
…tched sequentially for primary index scan
Summary:
In the cost model, we try to predict the order in which the disk blocks need
to be fetched. In case of a secondary index scan, we assume that the disk
blocksfor primary table will be fetched in a random order. But for a primary
index scan, we must assume that the disk blocks are fetched in sequential
order.
Before this change, the index scan was being costed higher than a sequential
scan for the following example. With this change, the index scan is cheaper.
```
CREATE TABLE t1 (a INT, PRIMARY KEY (a ASC));
INSERT INTO t1 SELECT s FROM generate_series(1, 10) s;
ANALYZE t1;
SET yb_enable_base_scans_cost_model = ON;
yugabyte=# explain select * from t1 where a < 5;
QUERY PLAN
--------------------------------------------------------------------
Index Scan using t1_pkey on t1 (cost=10.00..31.21 rows=3 width=4)
Index Cond: (a < 5)
(2 rows)
yugabyte=# /*+ SeqScan(t1) */ explain select * from t1 where a < 5;
QUERY PLAN
----------------------------------------------------
Seq Scan on t1 (cost=10.00..31.61 rows=3 width=4)
Storage Filter: (a < 5)
(2 rows)
```
Jira: DB-15582
Test Plan: ./yb_build.sh --java-test 'org.yb.pgsql.TestPgRegressPlanner'
Reviewers: mtakahara, amartsinchyk
Reviewed By: mtakahara
Subscribers: yql
Differential Revision: https://phorge.dev.yugabyte.com/D42188
Jira Link: DB-15582
Description
For small tables, a primary index scan is being assigned higher cost than sequential scan, even though it appears to be slightly faster.
This seems to be caused by the assumption that disk pages will be fetched randomly for primary index scan in the index scan cost model.
Issue Type
kind/bug
Warning: Please confirm that this issue does not contain any sensitive information
The text was updated successfully, but these errors were encountered: