Skip to content

Commit

Permalink
[pg15] fix: activate function yb_cost_index
Browse files Browse the repository at this point in the history
Summary:
The initial merge commit disabled the function yb_cost_index due to compilation
issue(s). The code was refactored in master branch in D33497 and rebased in pg15
branch.

Due to changes in PG commit 1a8d5afb0dfc5d0dcc6eda0656a34cb1f0cf0bdf (titled,
"Refactor the representation of indexable clauses in IndexPaths"), additional
changes were needed in pg15 branch, that are done in this change.

Some changes are made to `yb_select_parallel.out`. Despite this change, this
test and `yb_planner_size_estimates` continue to fail due to plan changes
compared to master. These will be investigated and fixed in a separate diff.

Test Plan:
```
for _ in {1..50}; do grep -E 'TestPgCostModelSeekNextEstimation|TestPgExplainAnalyze|TestPgRegressTAQO'  pg15_tests/passing_tests.tsv; done | pg15_tests/run_tests.sh

pg15_tests/test_D35351.sh
```

Reviewers: aagrawal, fizaa

Reviewed By: aagrawal

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D35351
  • Loading branch information
gauravk-in committed Jul 10, 2024
1 parent e7248c0 commit 2c5c5e0
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 38 deletions.
4 changes: 3 additions & 1 deletion pg15_tests/passing_tests.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ JAVA org.yb.pgsql.TestPgCacheConsistency#testCatalogVersionLogging
JAVA org.yb.pgsql.TestPgConfiguration
JAVA org.yb.pgsql.TestPgConnection
JAVA org.yb.pgsql.TestPgConnection#testConnectionKillsAndRestarts
JAVA org.yb.pgsql.TestPgCostModelSeekNextEstimation#testSeekNextEstimationBitmapScan
JAVA org.yb.pgsql.TestPgCostModelSeekNextEstimation
JAVA org.yb.pgsql.TestPgDepend#testForSuperfluousEntries
JAVA org.yb.pgsql.TestPgDepend#testSequenceDeletionWithCascade
JAVA org.yb.pgsql.TestPgDepend#testTableWithSequenceDeletion
JAVA org.yb.pgsql.TestPgDepend#testViewDeletionWithCascade
JAVA org.yb.pgsql.TestPgExplainAnalyze
JAVA org.yb.pgsql.TestPgExplainAnalyzeColocated
JAVA org.yb.pgsql.TestPgExplainAnalyzeMetrics
JAVA org.yb.pgsql.TestPgExplainAnalyzeScans#testFetchLimitCosting
Expand Down Expand Up @@ -87,6 +88,7 @@ JAVA org.yb.pgsql.TestPgRegressPushdown#testPgRegressPushdown
JAVA org.yb.pgsql.TestPgRegressPushdownKey
JAVA org.yb.pgsql.TestPgRegressReplicaIdentity
JAVA org.yb.pgsql.TestPgRegressReplicationSlot#testPgRegressReplicationSlot
JAVA org.yb.pgsql.TestPgRegressTAQO
JAVA org.yb.pgsql.TestPgRegressTable
JAVA org.yb.pgsql.TestPgRegressTablegroup
JAVA org.yb.pgsql.TestPgRegressTabletSplit
Expand Down
12 changes: 12 additions & 0 deletions pg15_tests/test_D35351.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
source "${BASH_SOURCE[0]%/*}"/common.sh

failing_java_test TestPgRegressParallel
grep_in_java_test \
"Failed tests: [yb_select_parallel]" \
TestPgRegressParallel

failing_java_test TestPgRegressPlanner
grep_in_java_test \
"Failed tests: [yb_planner_size_estimates]" \
TestPgRegressPlanner
35 changes: 16 additions & 19 deletions src/postgres/src/backend/optimizer/path/costsize.c
Original file line number Diff line number Diff line change
Expand Up @@ -7578,11 +7578,6 @@ void
yb_cost_index(IndexPath *path, PlannerInfo *root, double loop_count,
bool partial_path)
{
#ifdef YB_TODO
/*
* Gaurav: this function needs changes to work with pg15. Particularly,
* deconstruct_indexquals no longer exists
*/
IndexOptInfo *index = path->indexinfo;
Relation index_rel = RelationIdGetRelation(path->indexinfo->indexoid);
bool is_primary_index = index_rel->rd_index->indisprimary;
Expand All @@ -7600,7 +7595,6 @@ yb_cost_index(IndexPath *path, PlannerInfo *root, double loop_count,
List *index_conditions;
int index_col;
ListCell *lc;
ListCell *lci;
RangeTblEntry *rte;
Oid baserel_oid;
int32 index_tuple_width;
Expand Down Expand Up @@ -7714,32 +7708,36 @@ yb_cost_index(IndexPath *path, PlannerInfo *root, double loop_count,
index_conditions_on_each_column = palloc0(sizeof(List*) * index->nkeycolumns);
index_conditions = NIL;
index_col = 0;
forboth(lc, path->indexquals, lci, path->indexqualcols)

foreach(lc, path->indexclauses)
{
RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
int index_qual_col = lfirst_int(lci);
IndexClause *iclause = lfirst_node(IndexClause, lc);
ListCell *lc2;
int index_qual_col = iclause->indexcol;

while (index_col != index_qual_col)
{
++index_col;
Assert(index_col < index->nkeycolumns);
}

if (path->path.param_info)
foreach (lc2, iclause->indexquals)
{
Relids batched = YB_PATH_REQ_OUTER_BATCHED(&path->path);
RestrictInfo *batched_rinfo = yb_get_batched_restrictinfo(
RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc2);
if (path->path.param_info)
{
Relids batched = YB_PATH_REQ_OUTER_BATCHED(&path->path);
RestrictInfo *batched_rinfo = yb_get_batched_restrictinfo(
rinfo, batched, path->path.parent->relids);
if (batched_rinfo)
if (batched_rinfo)
rinfo = batched_rinfo;
}
index_conditions_on_each_column[index_col] =
lappend(index_conditions_on_each_column[index_col], rinfo);
index_conditions = lappend(index_conditions, rinfo);
}

index_conditions_on_each_column[index_col] =
lappend(index_conditions_on_each_column[index_col], rinfo);
index_conditions = lappend(index_conditions, rinfo);
}


bool yb_exist_conditions_on_all_hash_keys_ =
yb_exist_conditions_on_all_hash_keys(index,
index_conditions_on_each_column);
Expand Down Expand Up @@ -8140,7 +8138,6 @@ yb_cost_index(IndexPath *path, PlannerInfo *root, double loop_count,
path->path.startup_cost = startup_cost;
path->path.total_cost = startup_cost + run_cost;
yb_parallel_cost((Path *) path);
#endif
}

/*
Expand Down
28 changes: 14 additions & 14 deletions src/postgres/src/test/regress/expected/yb_parallel_append.out
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ select * from t, t1 where t.k = t1.k union all select * from t, t2 where t.k = t
-- partitioned table
explain (costs off)
select * from lp;
QUERY PLAN
------------------------------
QUERY PLAN
-----------------------------------
Append
-> Seq Scan on lp_ad
-> Seq Scan on lp_bc
-> Seq Scan on lp_ef
-> Seq Scan on lp_null
-> Seq Scan on lp_default
-> Seq Scan on lp_ad lp_1
-> Seq Scan on lp_bc lp_2
-> Seq Scan on lp_ef lp_3
-> Seq Scan on lp_null lp_4
-> Seq Scan on lp_default lp_5
(6 rows)

select * from lp;
Expand Down Expand Up @@ -192,14 +192,14 @@ select * from t, t1 where t.k = t1.k union all select * from t, t2 where t.k = t
-- partitioned table
explain (costs off)
select * from lp;
QUERY PLAN
------------------------------------
QUERY PLAN
-----------------------------------------
Gather
Workers Planned: 2
-> Parallel Append
-> Seq Scan on lp_ad
-> Seq Scan on lp_bc
-> Seq Scan on lp_ef
-> Seq Scan on lp_null
-> Seq Scan on lp_default
-> Seq Scan on lp_ad lp_1
-> Seq Scan on lp_bc lp_2
-> Seq Scan on lp_ef lp_3
-> Seq Scan on lp_null lp_4
-> Seq Scan on lp_default lp_5
(8 rows)
8 changes: 4 additions & 4 deletions src/postgres/src/test/regress/expected/yb_select_parallel.out
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ explain (costs off)
-------------------------------------------------
Aggregate
-> Append
-> Seq Scan on part_pa_test_p1 pa2
-> Seq Scan on part_pa_test_p2 pa2_1
-> Seq Scan on part_pa_test_p1 pa2_1
-> Seq Scan on part_pa_test_p2 pa2_2
SubPlan 2
-> Result
SubPlan 1
-> Append
-> Seq Scan on part_pa_test_p1 pa1
-> Seq Scan on part_pa_test_p1 pa1_1
Storage Filter: (a = pa2.a)
-> Seq Scan on part_pa_test_p2 pa1_1
-> Seq Scan on part_pa_test_p2 pa1_2
Storage Filter: (a = pa2.a)
(12 rows)

Expand Down

0 comments on commit 2c5c5e0

Please sign in to comment.