Skip to content

Commit

Permalink
[BACKPORT 2024.1][#21892] YSQL: Fix index tuple width estimation in c…
Browse files Browse the repository at this point in the history
…ost model

Summary:
Original commit: fa7c8bb / D33947
The YB base scans cost model calculates the index tuple width to estimate the
cost of fetching the index from the disk to memory. This change fixes a bug in
the index tuple width calculation.
Jira: DB-10792

Test Plan: ./yb_build.sh --java-test 'org.yb.pgsql.TestPgRegressTAQO#testPgRegressTAQO'

Reviewers: tverona, tnayak, telgersma

Reviewed By: telgersma

Subscribers: yql

Tags: #jenkins-ready

Differential Revision: https://phorge.dev.yugabyte.com/D35028
  • Loading branch information
gauravk-in committed May 14, 2024
1 parent 9e346b3 commit 41c53e1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/postgres/src/backend/optimizer/path/costsize.c
Original file line number Diff line number Diff line change
Expand Up @@ -6344,7 +6344,8 @@ yb_get_index_tuple_width(IndexOptInfo *index, Oid baserel_oid,
/* Aggregate the width of the columns in the secondary index */
for (int i = 0; i < index->ncolumns; i++)
{
index_tuple_width += index->rel->attr_widths[index->indexkeys[i]];
index_tuple_width +=
index->rel->attr_widths[index->indexkeys[i] - index->rel->min_attr];
}
index_tuple_width += HIDDEN_COLUMNS_SIZE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1218,26 +1218,26 @@ EXPLAIN (COSTS OFF) SELECT * FROM t_range_100k where v1 > 100000;

-- Query Hash: d93f6e4d8c79ed9ff1777a8346135486
EXPLAIN (COSTS OFF) SELECT v1 FROM t_range_100k where v1 > 0;
QUERY PLAN
------------------------------------------------
Index Only Scan using tr100kv1 on t_range_100k
Index Cond: (v1 > 0)
QUERY PLAN
----------------------------
Seq Scan on t_range_100k
Storage Filter: (v1 > 0)
(2 rows)

-- Query Hash: ad243137d04da666112652bc4daee5bb
EXPLAIN (COSTS OFF) SELECT v1 FROM t_range_100k where v1 > 1;
QUERY PLAN
------------------------------------------------
Index Only Scan using tr100kv1 on t_range_100k
Index Cond: (v1 > 1)
QUERY PLAN
----------------------------
Seq Scan on t_range_100k
Storage Filter: (v1 > 1)
(2 rows)

-- Query Hash: bfeb69f5dd583f251a20785be7fff7f8
EXPLAIN (COSTS OFF) SELECT v1 FROM t_range_100k where v1 > 10;
QUERY PLAN
------------------------------------------------
Index Only Scan using tr100kv1 on t_range_100k
Index Cond: (v1 > 10)
QUERY PLAN
-----------------------------
Seq Scan on t_range_100k
Storage Filter: (v1 > 10)
(2 rows)

-- Query Hash: 6c0176a4d1a4d77205315f39efea625c
Expand Down

0 comments on commit 41c53e1

Please sign in to comment.