clean up codes

This commit is contained in:
Takuma Hoshiai 2024-03-01 17:01:54 +09:00
parent b3603c776d
commit 6b9df6a8d5
2 changed files with 28 additions and 22 deletions

View file

@ -823,7 +823,7 @@ check_ivm_restriction_walker(Node *node, check_ivm_restriction_context *context)
if (IsA(lfirst(lc), Var)) if (IsA(lfirst(lc), Var))
{ {
Var *var = (Var *) lfirst(lc); Var *var = (Var *) lfirst(lc);
/* if system column, return error */ /* if the view has a system column, raise an error */
if (var->varattno < 0) if (var->varattno < 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
@ -831,7 +831,7 @@ check_ivm_restriction_walker(Node *node, check_ivm_restriction_context *context)
} }
} }
/* check if type in the top target list had an equality operator */ /* check that each type in the target list has an equality operator */
if (context->sublevels_up == 0) if (context->sublevels_up == 0)
{ {
foreach(lc, qry->targetList) foreach(lc, qry->targetList)
@ -902,6 +902,7 @@ check_ivm_restriction_walker(Node *node, check_ivm_restriction_context *context)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("VALUES is not supported on incrementally maintainable materialized view"))); errmsg("VALUES is not supported on incrementally maintainable materialized view")));
if (rte->relkind == RELKIND_RELATION && isImmv(rte->relid)) if (rte->relkind == RELKIND_RELATION && isImmv(rte->relid))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
@ -920,9 +921,11 @@ check_ivm_restriction_walker(Node *node, check_ivm_restriction_context *context)
/* /*
* additional restriction checks for exists subquery * additional restriction checks for exists subquery
* *
* If the query has any EXISTS clauses and columns in them refer to * If the query has an EXISTS subquery and columns of a table in
* columns in tables in the output query, those columns must be * the outer query are used in the EXISTS subquery, those columns
* included in the target list. * must be included in the target list. These columns are required
* to identify tuples in the view to be affected by modification
* of tables in the EXISTS subquery.
*/ */
if (context->exists_qual_vars != NIL && context->sublevels_up == 0) if (context->exists_qual_vars != NIL && context->sublevels_up == 0)
{ {
@ -992,6 +995,7 @@ check_ivm_restriction_walker(Node *node, check_ivm_restriction_context *context)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("column name %s is not supported on incrementally maintainable materialized view", tle->resname))); errmsg("column name %s is not supported on incrementally maintainable materialized view", tle->resname)));
if (context->has_agg && !IsA(tle->expr, Aggref) && contain_aggs_of_level((Node *) tle->expr, 0)) if (context->has_agg && !IsA(tle->expr, Aggref) && contain_aggs_of_level((Node *) tle->expr, 0))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
@ -1118,6 +1122,7 @@ check_ivm_restriction_walker(Node *node, check_ivm_restriction_context *context)
errmsg("nested sublink is not supported on incrementally maintainable materialized view"))); errmsg("nested sublink is not supported on incrementally maintainable materialized view")));
subselect = (Query *) sublink->subselect; subselect = (Query *) sublink->subselect;
/* raise ERROR if the sublink has CTE */ /* raise ERROR if the sublink has CTE */
if (subselect->cteList) if (subselect->cteList)
ereport(ERROR, ereport(ERROR,

View file

@ -1606,7 +1606,8 @@ rewrite_exists_subquery_walker(Query *query, Node *node, int *count)
if (fromexpr->quals != NULL) if (fromexpr->quals != NULL)
{ {
query = rewrite_exists_subquery_walker(query, fromexpr->quals, count); query = rewrite_exists_subquery_walker(query, fromexpr->quals, count);
/* drop subquery in WHERE clause */
/* drop WHERE clause when it has only one EXISTS */
if (IsA(fromexpr->quals, SubLink)) if (IsA(fromexpr->quals, SubLink))
fromexpr->quals = NULL; fromexpr->quals = NULL;
} }
@ -1728,7 +1729,7 @@ rewrite_exists_subquery_walker(Query *query, Node *node, int *count)
* SELECT 1, COUNT(*) AS __ivm_exists_count_0__ * SELECT 1, COUNT(*) AS __ivm_exists_count_0__
* FROM t2 * FROM t2
* WHERE t1.key = t2.key * WHERE t1.key = t2.key
* HAVING __ivm_exists_count_0__ > 0) AS ex * HAVING COUNT(*) > 0) AS ex
*/ */
Query * Query *
rewrite_query_for_exists_subquery(Query *query) rewrite_query_for_exists_subquery(Query *query)