Fix the way we check for local/reference table joins in the executor

pull/3280/head
Hadi Moshayedi 2019-12-10 14:25:47 -08:00
parent 13204487e9
commit e3e174f30f
3 changed files with 23 additions and 4 deletions

View File

@ -580,7 +580,7 @@ IsLocalReferenceTableJoinPlan(PlannedStmt *plan)
{ {
bool hasReferenceTable = false; bool hasReferenceTable = false;
bool hasLocalTable = false; bool hasLocalTable = false;
ListCell *oidCell = NULL; ListCell *rangeTableCell = NULL;
bool hasReferenceTableReplica = false; bool hasReferenceTableReplica = false;
/* /*
@ -617,12 +617,24 @@ IsLocalReferenceTableJoinPlan(PlannedStmt *plan)
return false; return false;
} }
foreach(oidCell, plan->relationOids) /*
* plan->rtable contains the flattened RTE lists of the plan tree, which
* includes rtes in subqueries, CTEs, ...
*
* It doesn't contain optimized away table accesses (due to join optimization),
* which is fine for our purpose.
*/
foreach(rangeTableCell, plan->rtable)
{ {
Oid relationId = lfirst_oid(oidCell); RangeTblEntry *rangeTableEntry = (RangeTblEntry *) lfirst(rangeTableCell);
bool onlySearchPath = false; bool onlySearchPath = false;
if (RelationIsAKnownShard(relationId, onlySearchPath)) if (rangeTableEntry->rtekind != RTE_RELATION)
{
continue;
}
if (RelationIsAKnownShard(rangeTableEntry->relid, onlySearchPath))
{ {
/* /*
* We don't allow joining non-reference distributed tables, so we * We don't allow joining non-reference distributed tables, so we

View File

@ -244,6 +244,9 @@ HINT: Consider using an equality filter on the distributed table's partition co
SELECT local_table.a, numbers.a FROM local_table NATURAL JOIN numbers FOR UPDATE; SELECT local_table.a, numbers.a FROM local_table NATURAL JOIN numbers FOR UPDATE;
ERROR: could not run distributed query with FOR UPDATE/SHARE commands ERROR: could not run distributed query with FOR UPDATE/SHARE commands
HINT: Consider using an equality filter on the distributed table's partition column. HINT: Consider using an equality filter on the distributed table's partition column.
-- verify that we can drop columns from reference tables replicated to the coordinator
-- see https://github.com/citusdata/citus/issues/3279
ALTER TABLE squares DROP COLUMN b;
-- clean-up -- clean-up
SET client_min_messages TO ERROR; SET client_min_messages TO ERROR;
DROP SCHEMA replicate_ref_to_coordinator CASCADE; DROP SCHEMA replicate_ref_to_coordinator CASCADE;

View File

@ -138,6 +138,10 @@ SELECT a FROM t NATURAL JOIN dist;
SELECT local_table.a, numbers.a FROM local_table NATURAL JOIN numbers FOR SHARE; SELECT local_table.a, numbers.a FROM local_table NATURAL JOIN numbers FOR SHARE;
SELECT local_table.a, numbers.a FROM local_table NATURAL JOIN numbers FOR UPDATE; SELECT local_table.a, numbers.a FROM local_table NATURAL JOIN numbers FOR UPDATE;
-- verify that we can drop columns from reference tables replicated to the coordinator
-- see https://github.com/citusdata/citus/issues/3279
ALTER TABLE squares DROP COLUMN b;
-- clean-up -- clean-up
SET client_min_messages TO ERROR; SET client_min_messages TO ERROR;
DROP SCHEMA replicate_ref_to_coordinator CASCADE; DROP SCHEMA replicate_ref_to_coordinator CASCADE;