mirror of https://github.com/citusdata/citus.git
Rename hidden to uninstantiated
parent
8fd06f63f9
commit
c0603a51c5
|
@ -63,13 +63,13 @@ multi_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
|
||||||
/*
|
/*
|
||||||
* We implement INSERT INTO .. SELECT by pushing down the SELECT to
|
* We implement INSERT INTO .. SELECT by pushing down the SELECT to
|
||||||
* each shard. To compute that we use the router planner, by adding
|
* each shard. To compute that we use the router planner, by adding
|
||||||
* a "hidden" constraint that the partition column be equal to a
|
* an "uninstantiated" constraint that the partition column be equal to a
|
||||||
* certain value. standard_planner() distributes that constraint to
|
* certain value. standard_planner() distributes that constraint to
|
||||||
* the baserestrictinfos of the tables that they are connected
|
* the baserestrictinfos of the tables that they are connected
|
||||||
* via equi joins.
|
* via equi joins.
|
||||||
*
|
*
|
||||||
* The router planner then iterates over the target table's shards,
|
* The router planner then iterates over the target table's shards,
|
||||||
* for each we replace the "hidden" restriction, with one that
|
* for each we replace the "uninstantiated" restriction, with one that
|
||||||
* PruneShardList() handles, and then generate a query for that
|
* PruneShardList() handles, and then generate a query for that
|
||||||
* individual shard. If any of the involved tables don't prune down
|
* individual shard. If any of the involved tables don't prune down
|
||||||
* to a single shard, or if the pruned shards aren't colocated,
|
* to a single shard, or if the pruned shards aren't colocated,
|
||||||
|
@ -77,7 +77,7 @@ multi_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
|
||||||
*/
|
*/
|
||||||
if (InsertSelectQuery(parse))
|
if (InsertSelectQuery(parse))
|
||||||
{
|
{
|
||||||
AddHiddenPartitionColumnEqualityQual(parse);
|
AddUninstantiatedPartitionColumnEqualityQual(parse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ static bool MultiRouterPlannableQuery(Query *query, MultiExecutorType taskExecut
|
||||||
RelationRestrictionContext *restrictionContext);
|
RelationRestrictionContext *restrictionContext);
|
||||||
static RelationRestrictionContext * CopyRelationRestrictionContext(
|
static RelationRestrictionContext * CopyRelationRestrictionContext(
|
||||||
RelationRestrictionContext *oldContext);
|
RelationRestrictionContext *oldContext);
|
||||||
static Node * ReplaceHiddenQual(Node *node, void *context);
|
static Node * InstantiatePartitionQual(Node *node, void *context);
|
||||||
static void ErrorIfInsertSelectQueryNotSupported(Query *queryTree,
|
static void ErrorIfInsertSelectQueryNotSupported(Query *queryTree,
|
||||||
RangeTblEntry *insertRte,
|
RangeTblEntry *insertRte,
|
||||||
RangeTblEntry *subqueryRte);
|
RangeTblEntry *subqueryRte);
|
||||||
|
@ -122,7 +122,7 @@ static void ErrorIfInsertPartitionColumnDoesNotMatchSelect(Query *query,
|
||||||
RangeTblEntry *subqueryRte,
|
RangeTblEntry *subqueryRte,
|
||||||
Oid *
|
Oid *
|
||||||
selectPartitionColumnTableId);
|
selectPartitionColumnTableId);
|
||||||
static void AddHiddenEqualityQual(Query *query, Var *targetPartitionColumnVar);
|
static void AddUninstantiatedEqualityQual(Query *query, Var *targetPartitionColumnVar);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -333,8 +333,8 @@ RouterModifyTaskForShardInterval(Query *originalQuery, ShardInterval *shardInter
|
||||||
List *originalBaserestrictInfo = restriction->relOptInfo->baserestrictinfo;
|
List *originalBaserestrictInfo = restriction->relOptInfo->baserestrictinfo;
|
||||||
|
|
||||||
originalBaserestrictInfo =
|
originalBaserestrictInfo =
|
||||||
(List *) ReplaceHiddenQual((Node *) originalBaserestrictInfo,
|
(List *) InstantiatePartitionQual((Node *) originalBaserestrictInfo,
|
||||||
shardInterval);
|
shardInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -547,7 +547,7 @@ ErrorIfMultiTaskRouterSelectQueryUnsupported(Query *query)
|
||||||
"INSERT ... SELECT queries")));
|
"INSERT ... SELECT queries")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* see comment on AddHiddenPartitionColumnEqualityQual() */
|
/* see comment on AddUninstantiatedPartitionColumnEqualityQual() */
|
||||||
if (subquery->setOperations != NULL)
|
if (subquery->setOperations != NULL)
|
||||||
{
|
{
|
||||||
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
|
@ -628,12 +628,12 @@ ErrorIfInsertPartitionColumnDoesNotMatchSelect(Query *query, RangeTblEntry *inse
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* AddHiddenPartitionColumnEqualityQual() can only be used with
|
* AddUninstantiatedPartitionColumnEqualityQual() can only be used with
|
||||||
* INSERT ... SELECT queries.
|
* INSERT ... SELECT queries.
|
||||||
*
|
*
|
||||||
* AddHiddenPartitionColumnEqualityQual adds a hidden equality qual
|
* AddUninstantiatedPartitionColumnEqualityQual adds an equality qual
|
||||||
* to the SELECT query of the given originalQuery. The function currently
|
* to the SELECT query of the given originalQuery. The function currently
|
||||||
* does NOT add hidden quals if
|
* does NOT add the quals if
|
||||||
* (i) CTEs are present on the top level query
|
* (i) CTEs are present on the top level query
|
||||||
* (ii) Set operations are present on the top level query
|
* (ii) Set operations are present on the top level query
|
||||||
* (iii) Target list does not include a bare partition column.
|
* (iii) Target list does not include a bare partition column.
|
||||||
|
@ -641,7 +641,7 @@ ErrorIfInsertPartitionColumnDoesNotMatchSelect(Query *query, RangeTblEntry *inse
|
||||||
* Note that if the input query is not an INSERT .. SELECT the assertion fails.
|
* Note that if the input query is not an INSERT .. SELECT the assertion fails.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
AddHiddenPartitionColumnEqualityQual(Query *originalQuery)
|
AddUninstantiatedPartitionColumnEqualityQual(Query *originalQuery)
|
||||||
{
|
{
|
||||||
Query *subquery = NULL;
|
Query *subquery = NULL;
|
||||||
RangeTblEntry *subqueryEntry = NULL;
|
RangeTblEntry *subqueryEntry = NULL;
|
||||||
|
@ -669,7 +669,7 @@ AddHiddenPartitionColumnEqualityQual(Query *originalQuery)
|
||||||
* [THE ABOVE COMMENT IS TO EASE THE REVIEW, REMOVE LATER ON]
|
* [THE ABOVE COMMENT IS TO EASE THE REVIEW, REMOVE LATER ON]
|
||||||
*
|
*
|
||||||
* (ii) There are potentially multiple jointree quals that we need to add
|
* (ii) There are potentially multiple jointree quals that we need to add
|
||||||
* the hidden qual, and we haven't implemented that logic yet.
|
* the qual, and we haven't implemented that logic yet.
|
||||||
*
|
*
|
||||||
* (iii) We cannot get the source tables OID via target entries resorigtbl field.
|
* (iii) We cannot get the source tables OID via target entries resorigtbl field.
|
||||||
* This makes hard to check the colocation requirement of the source and target
|
* This makes hard to check the colocation requirement of the source and target
|
||||||
|
@ -706,20 +706,20 @@ AddHiddenPartitionColumnEqualityQual(Query *originalQuery)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* finally add the hidden equality qual of target column to subquery */
|
/* finally add the equality qual of target column to subquery */
|
||||||
AddHiddenEqualityQual(subquery, targetPartitionColumnVar);
|
AddUninstantiatedEqualityQual(subquery, targetPartitionColumnVar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* AddHiddenEqualityQual adds a hidden qual in the following form ($1 = partitionColumn)
|
* AddUninstantiatedEqualityQual adds a qual in the following form
|
||||||
* on the input query and partitionColumn.
|
* ($1 = partitionColumn) on the input query and partitionColumn.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
AddHiddenEqualityQual(Query *query, Var *partitionColumn)
|
AddUninstantiatedEqualityQual(Query *query, Var *partitionColumn)
|
||||||
{
|
{
|
||||||
Param *equalityParameter = makeNode(Param);
|
Param *equalityParameter = makeNode(Param);
|
||||||
Node *hiddenEqualityQual = NULL;
|
Node *uninstantiatedEqualityQual = NULL;
|
||||||
Oid partitionColumnCollid = InvalidOid;
|
Oid partitionColumnCollid = InvalidOid;
|
||||||
Oid lessThanOperator = InvalidOid;
|
Oid lessThanOperator = InvalidOid;
|
||||||
Oid equalsOperator = InvalidOid;
|
Oid equalsOperator = InvalidOid;
|
||||||
|
@ -737,28 +737,29 @@ AddHiddenEqualityQual(Query *query, Var *partitionColumn)
|
||||||
partitionColumnCollid = partitionColumn->varcollid;
|
partitionColumnCollid = partitionColumn->varcollid;
|
||||||
|
|
||||||
equalityParameter->paramkind = PARAM_EXTERN;
|
equalityParameter->paramkind = PARAM_EXTERN;
|
||||||
equalityParameter->paramid = HIDDEN_PARAMETER_ID;
|
equalityParameter->paramid = UNINSTANTIATED_PARAMETER_ID;
|
||||||
equalityParameter->paramtype = partitionColumn->vartype;
|
equalityParameter->paramtype = partitionColumn->vartype;
|
||||||
equalityParameter->paramtypmod = partitionColumn->vartypmod;
|
equalityParameter->paramtypmod = partitionColumn->vartypmod;
|
||||||
equalityParameter->paramcollid = partitionColumnCollid;
|
equalityParameter->paramcollid = partitionColumnCollid;
|
||||||
equalityParameter->location = -1;
|
equalityParameter->location = -1;
|
||||||
|
|
||||||
/* create a hidden equality on the on the target partition column */
|
/* create an equality on the on the target partition column */
|
||||||
hiddenEqualityQual = (Node *)
|
uninstantiatedEqualityQual =
|
||||||
make_opclause(equalsOperator, InvalidOid, false,
|
(Node *) make_opclause(equalsOperator, InvalidOid, false,
|
||||||
(Expr *) partitionColumn,
|
(Expr *) partitionColumn,
|
||||||
(Expr *) equalityParameter,
|
(Expr *) equalityParameter,
|
||||||
partitionColumnCollid, partitionColumnCollid);
|
partitionColumnCollid,
|
||||||
|
partitionColumnCollid);
|
||||||
|
|
||||||
/* add restriction on partition column */
|
/* add restriction on partition column */
|
||||||
if (query->jointree->quals == NULL)
|
if (query->jointree->quals == NULL)
|
||||||
{
|
{
|
||||||
query->jointree->quals = hiddenEqualityQual;
|
query->jointree->quals = uninstantiatedEqualityQual;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
query->jointree->quals = make_and_qual(query->jointree->quals,
|
query->jointree->quals = make_and_qual(query->jointree->quals,
|
||||||
hiddenEqualityQual);
|
uninstantiatedEqualityQual);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2457,14 +2458,15 @@ CopyRelationRestrictionContext(RelationRestrictionContext *oldContext)
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ReplaceHiddenQual Replace the "hidden" partition restriction clause with
|
* InstantiatePartitionQual replaces the "uninstantiated" partition
|
||||||
* the current shard's (passed in context) boundary value.
|
* restriction clause with the current shard's (passed in context)
|
||||||
|
* boundary value.
|
||||||
*
|
*
|
||||||
* Once we see ($1 = partition column), we replace it with
|
* Once we see ($1 = partition column), we replace it with
|
||||||
* (partCol >= shardMinValue && partCol <= shardMaxValue)
|
* (partCol >= shardMinValue && partCol <= shardMaxValue).
|
||||||
*/
|
*/
|
||||||
static Node *
|
static Node *
|
||||||
ReplaceHiddenQual(Node *node, void *context)
|
InstantiatePartitionQual(Node *node, void *context)
|
||||||
{
|
{
|
||||||
ShardInterval *shardInterval = (ShardInterval *) context;
|
ShardInterval *shardInterval = (ShardInterval *) context;
|
||||||
Assert(shardInterval->minValueExists);
|
Assert(shardInterval->minValueExists);
|
||||||
|
@ -2478,7 +2480,7 @@ ReplaceHiddenQual(Node *node, void *context)
|
||||||
/*
|
/*
|
||||||
* Look for operator expressions with two arguments.
|
* Look for operator expressions with two arguments.
|
||||||
*
|
*
|
||||||
* Once Found hidden op, replace with appropriate boundaries for the
|
* Once Found the uninstantiate, replace with appropriate boundaries for the
|
||||||
* current shard interval.
|
* current shard interval.
|
||||||
*
|
*
|
||||||
* The boundaries are replaced in the following manner:
|
* The boundaries are replaced in the following manner:
|
||||||
|
@ -2516,7 +2518,7 @@ ReplaceHiddenQual(Node *node, void *context)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* not an interesting param for our purpose, so return */
|
/* not an interesting param for our purpose, so return */
|
||||||
if (!(param && param->paramid == HIDDEN_PARAMETER_ID))
|
if (!(param && param->paramid == UNINSTANTIATED_PARAMETER_ID))
|
||||||
{
|
{
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@ -2560,18 +2562,18 @@ ReplaceHiddenQual(Node *node, void *context)
|
||||||
/* FIXME: probably can remove support for this */
|
/* FIXME: probably can remove support for this */
|
||||||
/* to support CTEs, subqueries, etc */
|
/* to support CTEs, subqueries, etc */
|
||||||
return (Node *) query_tree_mutator((Query *) node,
|
return (Node *) query_tree_mutator((Query *) node,
|
||||||
ReplaceHiddenQual,
|
InstantiatePartitionQual,
|
||||||
context,
|
context,
|
||||||
QTW_EXAMINE_RTES);
|
QTW_EXAMINE_RTES);
|
||||||
}
|
}
|
||||||
else if (IsA(node, RestrictInfo))
|
else if (IsA(node, RestrictInfo))
|
||||||
{
|
{
|
||||||
RestrictInfo *restrictInfo = (RestrictInfo *) node;
|
RestrictInfo *restrictInfo = (RestrictInfo *) node;
|
||||||
restrictInfo->clause = (Expr *) ReplaceHiddenQual(
|
restrictInfo->clause = (Expr *) InstantiatePartitionQual(
|
||||||
(Node *) restrictInfo->clause, context);
|
(Node *) restrictInfo->clause, context);
|
||||||
|
|
||||||
return (Node *) restrictInfo;
|
return (Node *) restrictInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
return expression_tree_mutator(node, ReplaceHiddenQual, context);
|
return expression_tree_mutator(node, InstantiatePartitionQual, context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
|
|
||||||
/* reserved parameted id */
|
/* reserved parameted id */
|
||||||
#define HIDDEN_PARAMETER_ID 0xdeadbeef
|
#define UNINSTANTIATED_PARAMETER_ID 0xdeadbeef
|
||||||
|
|
||||||
/* reserved alias name for UPSERTs */
|
/* reserved alias name for UPSERTs */
|
||||||
#define CITUS_TABLE_ALIAS "citus_table_alias"
|
#define CITUS_TABLE_ALIAS "citus_table_alias"
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
extern MultiPlan * MultiRouterPlanCreate(Query *originalQuery, Query *query,
|
extern MultiPlan * MultiRouterPlanCreate(Query *originalQuery, Query *query,
|
||||||
MultiExecutorType taskExecutorType,
|
MultiExecutorType taskExecutorType,
|
||||||
RelationRestrictionContext *restrictionContext);
|
RelationRestrictionContext *restrictionContext);
|
||||||
extern void AddHiddenPartitionColumnEqualityQual(Query *originalQuery);
|
extern void AddUninstantiatedPartitionColumnEqualityQual(Query *originalQuery);
|
||||||
extern void ErrorIfModifyQueryNotSupported(Query *queryTree);
|
extern void ErrorIfModifyQueryNotSupported(Query *queryTree);
|
||||||
extern Query * ReorderInsertSelectTargetLists(Query *originalQuery,
|
extern Query * ReorderInsertSelectTargetLists(Query *originalQuery,
|
||||||
RangeTblEntry *insertRte,
|
RangeTblEntry *insertRte,
|
||||||
|
|
Loading…
Reference in New Issue