This is an automated email from the ASF dual-hosted git repository.
chenjinbao1989 pushed a commit to branch cbdb-postgres-merge
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
The following commit(s) were added to refs/heads/cbdb-postgres-merge by this
push:
new 715f3c0d7c4 Fix panic on pg_hint_plan
715f3c0d7c4 is described below
commit 715f3c0d7c47271f4832726e5ddb1fab0b46e18e
Author: Jinbao Chen <[email protected]>
AuthorDate: Wed Jan 14 23:12:43 2026 +0800
Fix panic on pg_hint_plan
The relids of RelOptInfo only contains base relids. But now it contains
baserelids and outer join relids. So we should remove the outer join
ids before use them
---
gpcontrib/pg_hint_plan/pg_hint_plan.c | 18 ++--
src/test/regress/expected/joinhints.out | 120 ++++++++++++-------------
src/test/regress/expected/temp_tablespaces.out | 22 +++--
3 files changed, 85 insertions(+), 75 deletions(-)
diff --git a/gpcontrib/pg_hint_plan/pg_hint_plan.c
b/gpcontrib/pg_hint_plan/pg_hint_plan.c
index 401d31a6405..9fc308b24aa 100644
--- a/gpcontrib/pg_hint_plan/pg_hint_plan.c
+++ b/gpcontrib/pg_hint_plan/pg_hint_plan.c
@@ -4102,18 +4102,20 @@ find_relid_aliasname(PlannerInfo *root, char
*aliasname, List *initial_rels,
* Return join hint which matches given joinrelids.
*/
static JoinMethodHint *
-find_join_hint(Relids joinrelids)
+find_join_hint(PlannerInfo *root, Relids joinrelids)
{
List *join_hint;
ListCell *l;
-
- join_hint =
current_hint_state->join_hint_level[bms_num_members(joinrelids)];
+ Bitmapset *baseRelSet;
+
+ baseRelSet = bms_intersect(joinrelids, root->all_baserels);
+ join_hint =
current_hint_state->join_hint_level[bms_num_members(baseRelSet)];
foreach(l, join_hint)
{
JoinMethodHint *hint = (JoinMethodHint *) lfirst(l);
- if (bms_equal(joinrelids, hint->joinrelids))
+ if (bms_equal(baseRelSet, hint->joinrelids))
return hint;
}
@@ -4164,7 +4166,7 @@ OuterInnerJoinCreate(OuterInnerRels *outer_inner,
LeadingHint *leading_hint,
* If we don't have join method hint, create new one for the
* join combination with all join methods are enabled.
*/
- hint = find_join_hint(join_relids);
+ hint = find_join_hint(root, join_relids);
if (hint == NULL)
{
/*
@@ -4389,7 +4391,7 @@ transform_join_hints(HintState *hstate, PlannerInfo
*root, int nbaserel,
* If we don't have join method hint, create new one
for the
* join combination with all join methods are enabled.
*/
- hint = find_join_hint(joinrelids);
+ hint = find_join_hint(root, joinrelids);
if (hint == NULL)
{
/*
@@ -4735,7 +4737,7 @@ pg_hint_plan_make_join_rel(PlannerInfo *root, RelOptInfo
*rel1, RelOptInfo *rel2
}
joinrelids = bms_union(rel1->relids, rel2->relids);
- hint = find_join_hint(joinrelids);
+ hint = find_join_hint(root, joinrelids);
bms_free(joinrelids);
if (!hint)
@@ -4788,7 +4790,7 @@ pg_hint_plan_add_paths_to_joinrel(PlannerInfo *root,
}
joinrelids = bms_union(outerrel->relids, innerrel->relids);
- join_hint = find_join_hint(joinrelids);
+ join_hint = find_join_hint(root, joinrelids);
bms_free(joinrelids);
if (join_hint && join_hint->inner_nrels != 0)
diff --git a/src/test/regress/expected/joinhints.out
b/src/test/regress/expected/joinhints.out
index 876be468fa7..9063d044117 100644
--- a/src/test/regress/expected/joinhints.out
+++ b/src/test/regress/expected/joinhints.out
@@ -2779,20 +2779,22 @@ Leading((t2 (t1 t3)))
not used hint:
duplication hint:
error hint:
- QUERY PLAN
-----------------------------------------------
+ QUERY PLAN
+----------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
- -> Hash Join
- Hash Cond: (t2.a = t1.a)
- -> Seq Scan on t2
- -> Hash
- -> Hash Left Join
- Hash Cond: (t1.a = t3.a)
- -> Seq Scan on t1
- -> Hash
- -> Seq Scan on t3
- Optimizer: Postgres-based planner
-(11 rows)
+ -> Merge Join
+ Merge Cond: (t2.a = t1.a)
+ -> Index Scan using i2 on t2
+ -> Materialize
+ -> Sort
+ Sort Key: t1.a
+ -> Hash Left Join
+ Hash Cond: (t1.a = t3.a)
+ -> Seq Scan on t1
+ -> Hash
+ -> Seq Scan on t3
+ Optimizer: Postgres query optimizer
+(13 rows)
/*+
Leading((t2 (t1 t3)))
@@ -2829,20 +2831,22 @@ Leading((t2 (t3 t1)))
not used hint:
duplication hint:
error hint:
- QUERY PLAN
-----------------------------------------------
+ QUERY PLAN
+----------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
- -> Hash Join
- Hash Cond: (t2.a = t1.a)
- -> Seq Scan on t2
- -> Hash
- -> Hash Right Join
- Hash Cond: (t3.a = t1.a)
- -> Seq Scan on t3
- -> Hash
- -> Seq Scan on t1
- Optimizer: Postgres-based planner
-(11 rows)
+ -> Merge Join
+ Merge Cond: (t2.a = t1.a)
+ -> Index Scan using i2 on t2
+ -> Materialize
+ -> Sort
+ Sort Key: t1.a
+ -> Hash Right Join
+ Hash Cond: (t3.a = t1.a)
+ -> Seq Scan on t3
+ -> Hash
+ -> Seq Scan on t1
+ Optimizer: Postgres query optimizer
+(13 rows)
/*+
Leading((t2 (t3 t1)))
@@ -3423,23 +3427,21 @@ error hint:
-> Materialize
-> Sort
Sort Key: t2.a
- -> Redistribute Motion 3:3 (slice2; segments: 3)
- Hash Key: t2.a
- -> Merge Right Join
- Merge Cond: (t4.a = t3.a)
- -> Index Scan using i4 on t4
- -> Materialize
- -> Sort
- Sort Key: t3.a
- -> Redistribute Motion 3:3
(slice3; segments: 3)
- Hash Key: t3.a
- -> Hash Left Join
- Hash Cond: (t2.a =
t3.a)
- -> Seq Scan on t2
- -> Hash
- -> Seq Scan on
t3
- Optimizer: Postgres-based planner
-(27 rows)
+ -> Merge Left Join
+ Merge Cond: (t3.a = t4.a)
+ -> Sort
+ Sort Key: t3.a
+ -> Hash Left Join
+ Hash Cond: (t2.a = t3.a)
+ -> Seq Scan on t2
+ -> Hash
+ -> Seq Scan on t3
+ -> Sort
+ Sort Key: t4.a
+ -> Broadcast Motion 3:3 (slice2; segments:
3)
+ -> Seq Scan on t4
+ Optimizer: Postgres query optimizer
+(25 rows)
/*+
Leading((t2 t3))
@@ -3491,23 +3493,21 @@ error hint:
-> Materialize
-> Sort
Sort Key: t2.a
- -> Redistribute Motion 3:3 (slice2; segments: 3)
- Hash Key: t2.a
- -> Merge Right Join
- Merge Cond: (t4.a = t3.a)
- -> Index Scan using i4 on t4
- -> Materialize
- -> Sort
- Sort Key: t3.a
- -> Redistribute Motion 3:3
(slice3; segments: 3)
- Hash Key: t3.a
- -> Hash Right Join
- Hash Cond: (t3.a =
t2.a)
- -> Seq Scan on t3
- -> Hash
- -> Seq Scan on
t2
- Optimizer: Postgres-based planner
-(27 rows)
+ -> Merge Left Join
+ Merge Cond: (t3.a = t4.a)
+ -> Sort
+ Sort Key: t3.a
+ -> Hash Right Join
+ Hash Cond: (t3.a = t2.a)
+ -> Seq Scan on t3
+ -> Hash
+ -> Seq Scan on t2
+ -> Sort
+ Sort Key: t4.a
+ -> Broadcast Motion 3:3 (slice2; segments:
3)
+ -> Seq Scan on t4
+ Optimizer: Postgres query optimizer
+(25 rows)
/*+
Leading((t3 t2))
diff --git a/src/test/regress/expected/temp_tablespaces.out
b/src/test/regress/expected/temp_tablespaces.out
index 8fe01bff02a..8754d831fb4 100644
--- a/src/test/regress/expected/temp_tablespaces.out
+++ b/src/test/regress/expected/temp_tablespaces.out
@@ -1,5 +1,8 @@
-create tablespace some_temp_tablespace location
'@testtablespace@_temp_tablespace';
-create tablespace some_default_tablespace location
'@testtablespace@_default_tablespace';
+\getenv abs_builddir PG_ABS_BUILDDIR
+\set temp_tablespace :abs_builddir '/testtablespace_temp_tablespace'
+\set dddefault_tablepace :abs_builddir '/testtablespace_default_tablespace'
+create tablespace some_temp_tablespace location :'temp_tablespace';
+create tablespace some_default_tablespace location :'dddefault_tablepace';
-- Given I've set up GUCS for how to use tablespaces
set temp_tablespaces to some_temp_tablespace;
set default_tablespace to 'some_default_tablespace';
@@ -43,11 +46,16 @@ reset temp_tablespaces;
-- When the GUC temp_tablespaces is set, one of the temp tablespaces is used
instead of the default tablespace.
-- create several tablespaces and use them as temp tablespaces
-- all QD/QEs in one session should have the same temp tablespace
-create tablespace mytempsp0 location '@testtablespace@_mytempsp0';
-create tablespace mytempsp1 location '@testtablespace@_mytempsp1';
-create tablespace mytempsp2 location '@testtablespace@_mytempsp2';
-create tablespace mytempsp3 location '@testtablespace@_mytempsp3';
-create tablespace mytempsp4 location '@testtablespace@_mytempsp4';
+\set mytempsp0 :abs_builddir '/testtablespace_mytempsp0'
+\set mytempsp1 :abs_builddir '/testtablespace_mytempsp1'
+\set mytempsp2 :abs_builddir '/testtablespace_mytempsp2'
+\set mytempsp3 :abs_builddir '/testtablespace_mytempsp3'
+\set mytempsp4 :abs_builddir '/testtablespace_mytempsp4'
+create tablespace mytempsp0 location :'mytempsp0';
+create tablespace mytempsp1 location :'mytempsp1';
+create tablespace mytempsp2 location :'mytempsp2';
+create tablespace mytempsp3 location :'mytempsp3';
+create tablespace mytempsp4 location :'mytempsp4';
CREATE TABLE tts_foo (i int, j int) distributed by(i);
insert into tts_foo select i, i from generate_series(1,80000)i;
ANALYZE tts_foo;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]