mirror of https://github.com/citusdata/citus.git
skip restriction clause if it contains placeholdervar (#6857)
`PlaceHolderVar` is not relevant to be processed inside a restriction clause. Otherwise, `pull_var_clause_default` would throw error. PG would create the restriction to physical `Var` that `PlaceHolderVar` points to anyway, so it is safe to skip this restriction. DESCRIPTION: Fixes a bug related to WHERE clause list which contains placeholder. Fixes https://github.com/citusdata/citus/issues/6758pull/6829/head
parent
2675a68218
commit
08e2820c67
|
@ -155,6 +155,7 @@ static bool AllDistributedRelationsInRestrictionContextColocated(
|
|||
RelationRestrictionContext *
|
||||
restrictionContext);
|
||||
static bool IsNotSafeRestrictionToRecursivelyPlan(Node *node);
|
||||
static bool HasPlaceHolderVar(Node *node);
|
||||
static JoinRestrictionContext * FilterJoinRestrictionContext(
|
||||
JoinRestrictionContext *joinRestrictionContext, Relids
|
||||
queryRteIdentities);
|
||||
|
@ -2149,6 +2150,17 @@ GetRestrictInfoListForRelation(RangeTblEntry *rangeTblEntry,
|
|||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* PlaceHolderVar is not relevant to be processed inside a restriction clause.
|
||||
* Otherwise, pull_var_clause_default would throw error. PG would create
|
||||
* the restriction to physical Var that PlaceHolderVar points anyway, so it is
|
||||
* safe to skip this restriction.
|
||||
*/
|
||||
if (FindNodeMatchingCheckFunction((Node *) restrictionClause, HasPlaceHolderVar))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* We're going to add this restriction expression to a subquery
|
||||
* which consists of only one relation in its jointree. Thus,
|
||||
|
@ -2214,6 +2226,16 @@ IsNotSafeRestrictionToRecursivelyPlan(Node *node)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* HasPlaceHolderVar returns true if given node contains any PlaceHolderVar.
|
||||
*/
|
||||
static bool
|
||||
HasPlaceHolderVar(Node *node)
|
||||
{
|
||||
return IsA(node, PlaceHolderVar);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* FilterRelationRestrictionContext gets a relation restriction context and
|
||||
* set of rte identities. It returns the relation restrictions that that appear
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
CREATE SCHEMA issue_6758;
|
||||
SET search_path to 'issue_6758';
|
||||
CREATE TABLE dist0(id int);
|
||||
SELECT create_distributed_table('dist0','id');
|
||||
create_distributed_table
|
||||
---------------------------------------------------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
CREATE TABLE dist1(id int);
|
||||
SELECT create_distributed_table('dist1','id');
|
||||
create_distributed_table
|
||||
---------------------------------------------------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- added to verify we fixed the issue https://github.com/citusdata/citus/issues/6758
|
||||
-- generated by Citus query generator tool
|
||||
SELECT
|
||||
avg(avgsub.id)
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
table_0.id
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
table_1.id
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
table_2.id
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
table_3.id
|
||||
FROM
|
||||
(
|
||||
VALUES
|
||||
(838)
|
||||
) AS table_3(id) FULL
|
||||
JOIN dist0 AS table_4 USING (id)
|
||||
WHERE
|
||||
table_4.id = 3
|
||||
) AS table_2
|
||||
WHERE
|
||||
table_2.id = 2
|
||||
ORDER BY
|
||||
id
|
||||
LIMIT
|
||||
77
|
||||
) AS table_1
|
||||
LEFT JOIN dist0 AS table_5 USING (id)
|
||||
ORDER BY
|
||||
id
|
||||
LIMIT
|
||||
44
|
||||
) AS table_0 FULL
|
||||
JOIN dist1 AS table_6 USING (id)
|
||||
) AS avgsub;
|
||||
avg
|
||||
---------------------------------------------------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
DROP SCHEMA issue_6758 CASCADE;
|
||||
NOTICE: drop cascades to 2 other objects
|
||||
DETAIL: drop cascades to table dist0
|
||||
drop cascades to table dist1
|
|
@ -95,7 +95,7 @@ test: multi_dropped_column_aliases foreign_key_restriction_enforcement
|
|||
test: binary_protocol
|
||||
test: alter_table_set_access_method
|
||||
test: alter_distributed_table
|
||||
test: issue_5248 issue_5099 issue_5763 issue_6543
|
||||
test: issue_5248 issue_5099 issue_5763 issue_6543 issue_6758
|
||||
test: object_propagation_debug
|
||||
test: undistribute_table
|
||||
test: run_command_on_all_nodes
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
CREATE SCHEMA issue_6758;
|
||||
SET search_path to 'issue_6758';
|
||||
|
||||
CREATE TABLE dist0(id int);
|
||||
SELECT create_distributed_table('dist0','id');
|
||||
|
||||
CREATE TABLE dist1(id int);
|
||||
SELECT create_distributed_table('dist1','id');
|
||||
|
||||
-- added to verify we fixed the issue https://github.com/citusdata/citus/issues/6758
|
||||
-- generated by Citus query generator tool
|
||||
SELECT
|
||||
avg(avgsub.id)
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
table_0.id
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
table_1.id
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
table_2.id
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
table_3.id
|
||||
FROM
|
||||
(
|
||||
VALUES
|
||||
(838)
|
||||
) AS table_3(id) FULL
|
||||
JOIN dist0 AS table_4 USING (id)
|
||||
WHERE
|
||||
table_4.id = 3
|
||||
) AS table_2
|
||||
WHERE
|
||||
table_2.id = 2
|
||||
ORDER BY
|
||||
id
|
||||
LIMIT
|
||||
77
|
||||
) AS table_1
|
||||
LEFT JOIN dist0 AS table_5 USING (id)
|
||||
ORDER BY
|
||||
id
|
||||
LIMIT
|
||||
44
|
||||
) AS table_0 FULL
|
||||
JOIN dist1 AS table_6 USING (id)
|
||||
) AS avgsub;
|
||||
|
||||
DROP SCHEMA issue_6758 CASCADE;
|
Loading…
Reference in New Issue