Add GUC for queries with outer joins and pseudoconstant quals (#8163)

Users can turn on this GUC at their own risk.
pull/8166/head
Naisila Puka 2025-08-27 22:31:22 +03:00 committed by GitHub
parent 2e1de77744
commit 544b6c4716
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 121 additions and 1 deletions

View File

@ -97,6 +97,7 @@
#include "distributed/version_compat.h"
bool EnableRecurringOuterJoinPushdown = true;
bool EnableOuterJoinsWithPseudoconstantQualsPrePG17 = false;
/*
* RecursivePlanningContext is used to recursively plan subqueries
@ -509,7 +510,7 @@ ShouldRecursivelyPlanOuterJoins(Query *query, RecursivePlanningContext *context)
bool hasOuterJoin =
context->plannerRestrictionContext->joinRestrictionContext->hasOuterJoin;
#if PG_VERSION_NUM < PG_VERSION_17
if (!hasOuterJoin)
if (!EnableOuterJoinsWithPseudoconstantQualsPrePG17 && !hasOuterJoin)
{
/*
* PG15 commit d1ef5631e620f9a5b6480a32bb70124c857af4f1

View File

@ -1480,6 +1480,23 @@ RegisterCitusConfigVariables(void)
GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE,
NULL, NULL, NULL);
DefineCustomBoolVariable(
"citus.enable_outer_joins_with_pseudoconstant_quals_pre_pg17",
gettext_noop("Enables running distributed queries with outer joins "
"and pseudoconstant quals pre PG17."),
gettext_noop("Set to false by default. If set to true, enables "
"running distributed queries with outer joins and "
"pseudoconstant quals, at user's own risk, because "
"pre PG17, Citus doesn't have access to "
"set_join_pathlist_hook, which doesn't guarantee correct"
"query results. Note that in PG17+, this GUC has no effect"
"and the user can run such queries"),
&EnableOuterJoinsWithPseudoconstantQualsPrePG17,
false,
PGC_USERSET,
GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE,
NULL, NULL, NULL);
DefineCustomBoolVariable(
"citus.enable_recurring_outer_join_pushdown",
gettext_noop("Enables outer join pushdown for recurring relations."),

View File

@ -22,6 +22,7 @@
#include "distributed/relation_restriction_equivalence.h"
extern bool EnableRecurringOuterJoinPushdown;
extern bool EnableOuterJoinsWithPseudoconstantQualsPrePG17;
typedef struct RecursivePlanningContextInternal RecursivePlanningContext;
typedef struct RangeTblEntryIndex

View File

@ -422,6 +422,19 @@ where (exists (select * from t4)) order by 1, 2, 3;
| | 1 | Tue Mar 26 17:36:53 2024
(2 rows)
SET citus.enable_outer_joins_with_pseudoconstant_quals_pre_pg17 TO true;
-- wrong result pre-pg17
select * from
(t0 full outer join t3
on (t0.c3 = t3.c26 ))
where (exists (select * from t4)) order by 1, 2, 3;
vkey | c3 | vkey | c26
---------------------------------------------------------------------
13 | Wed Oct 23 15:34:50 2019 | |
| | 1 | Tue Mar 26 17:36:53 2024
(2 rows)
RESET citus.enable_outer_joins_with_pseudoconstant_quals_pre_pg17;
-- issue https://github.com/citusdata/citus/issues/7696
create table t1 ( vkey int4 );
create table t2 ( vkey int4 );
@ -456,6 +469,16 @@ where not((85) in (select 1 from t2));
5 |
(1 row)
SET citus.enable_outer_joins_with_pseudoconstant_quals_pre_pg17 TO true;
-- wrong result pre-pg17
select * from (t2 full outer join t1 on(t2.vkey = t1.vkey ))
where not((85) in (select 1 from t2));
vkey | vkey
---------------------------------------------------------------------
5 |
(1 row)
RESET citus.enable_outer_joins_with_pseudoconstant_quals_pre_pg17;
-- issue https://github.com/citusdata/citus/issues/7698
create table t5 ( vkey int4, c10 int4 );
create table t6 ( vkey int4 );
@ -489,6 +512,18 @@ where exists (select * from t6);
1
(1 row)
SET citus.enable_outer_joins_with_pseudoconstant_quals_pre_pg17 TO true;
-- wrong result pre-pg17
select t6.vkey
from (t5 right outer join t6
on (t5.c10 = t6.vkey))
where exists (select * from t6);
vkey
---------------------------------------------------------------------
1
(1 row)
RESET citus.enable_outer_joins_with_pseudoconstant_quals_pre_pg17;
-- issue https://github.com/citusdata/citus/issues/7119
-- this test was removed in
-- https://github.com/citusdata/citus/commit/a5ce601c0

View File

@ -374,6 +374,20 @@ where (exists (select * from t4)) order by 1, 2, 3;
ERROR: Distributed queries with outer joins and pseudoconstant quals are not supported in PG15 and PG16.
DETAIL: PG15 and PG16 disallow replacing joins with scans when the query has pseudoconstant quals
HINT: Consider upgrading your PG version to PG17+
SET citus.enable_outer_joins_with_pseudoconstant_quals_pre_pg17 TO true;
-- wrong result pre-pg17
select * from
(t0 full outer join t3
on (t0.c3 = t3.c26 ))
where (exists (select * from t4)) order by 1, 2, 3;
vkey | c3 | vkey | c26
---------------------------------------------------------------------
13 | Wed Oct 23 15:34:50 2019 | |
| | 1 | Tue Mar 26 17:36:53 2024
| | 1 | Tue Mar 26 17:36:53 2024
(3 rows)
RESET citus.enable_outer_joins_with_pseudoconstant_quals_pre_pg17;
-- issue https://github.com/citusdata/citus/issues/7696
create table t1 ( vkey int4 );
create table t2 ( vkey int4 );
@ -406,6 +420,17 @@ where not((85) in (select 1 from t2));
ERROR: Distributed queries with outer joins and pseudoconstant quals are not supported in PG15 and PG16.
DETAIL: PG15 and PG16 disallow replacing joins with scans when the query has pseudoconstant quals
HINT: Consider upgrading your PG version to PG17+
SET citus.enable_outer_joins_with_pseudoconstant_quals_pre_pg17 TO true;
-- wrong result pre-pg17
select * from (t2 full outer join t1 on(t2.vkey = t1.vkey ))
where not((85) in (select 1 from t2));
vkey | vkey
---------------------------------------------------------------------
5 |
5 |
(2 rows)
RESET citus.enable_outer_joins_with_pseudoconstant_quals_pre_pg17;
-- issue https://github.com/citusdata/citus/issues/7698
create table t5 ( vkey int4, c10 int4 );
create table t6 ( vkey int4 );
@ -437,6 +462,19 @@ where exists (select * from t6);
ERROR: Distributed queries with outer joins and pseudoconstant quals are not supported in PG15 and PG16.
DETAIL: PG15 and PG16 disallow replacing joins with scans when the query has pseudoconstant quals
HINT: Consider upgrading your PG version to PG17+
SET citus.enable_outer_joins_with_pseudoconstant_quals_pre_pg17 TO true;
-- wrong result pre-pg17
select t6.vkey
from (t5 right outer join t6
on (t5.c10 = t6.vkey))
where exists (select * from t6);
vkey
---------------------------------------------------------------------
1
1
(2 rows)
RESET citus.enable_outer_joins_with_pseudoconstant_quals_pre_pg17;
-- issue https://github.com/citusdata/citus/issues/7119
-- this test was removed in
-- https://github.com/citusdata/citus/commit/a5ce601c0

View File

@ -220,6 +220,16 @@ select * from
on (t0.c3 = t3.c26 ))
where (exists (select * from t4)) order by 1, 2, 3;
SET citus.enable_outer_joins_with_pseudoconstant_quals_pre_pg17 TO true;
-- wrong result pre-pg17
select * from
(t0 full outer join t3
on (t0.c3 = t3.c26 ))
where (exists (select * from t4)) order by 1, 2, 3;
RESET citus.enable_outer_joins_with_pseudoconstant_quals_pre_pg17;
-- issue https://github.com/citusdata/citus/issues/7696
create table t1 ( vkey int4 );
create table t2 ( vkey int4 );
@ -234,6 +244,14 @@ SELECT create_reference_table('t2');
select * from (t2 full outer join t1 on(t2.vkey = t1.vkey ))
where not((85) in (select 1 from t2));
SET citus.enable_outer_joins_with_pseudoconstant_quals_pre_pg17 TO true;
-- wrong result pre-pg17
select * from (t2 full outer join t1 on(t2.vkey = t1.vkey ))
where not((85) in (select 1 from t2));
RESET citus.enable_outer_joins_with_pseudoconstant_quals_pre_pg17;
-- issue https://github.com/citusdata/citus/issues/7698
create table t5 ( vkey int4, c10 int4 );
create table t6 ( vkey int4 );
@ -252,6 +270,16 @@ from (t5 right outer join t6
on (t5.c10 = t6.vkey))
where exists (select * from t6);
SET citus.enable_outer_joins_with_pseudoconstant_quals_pre_pg17 TO true;
-- wrong result pre-pg17
select t6.vkey
from (t5 right outer join t6
on (t5.c10 = t6.vkey))
where exists (select * from t6);
RESET citus.enable_outer_joins_with_pseudoconstant_quals_pre_pg17;
-- issue https://github.com/citusdata/citus/issues/7119
-- this test was removed in
-- https://github.com/citusdata/citus/commit/a5ce601c0