-
Notifications
You must be signed in to change notification settings - Fork 38
Support exists_subquery #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Simple EXISTS clause is supported by this patch. A query is not supported when WHERE clause has OR-condition or JOIN-condition is not contained by targetlist.
@@ -261,7 +263,7 @@ ExecCreateImmv(ParseState *pstate, CreateTableAsStmt *stmt, | |||
CreateIndexOnIMMV(viewQuery, matviewRel, true); | |||
|
|||
/* Create triggers on incremental maintainable materialized view */ | |||
CreateIvmTriggersOnBaseTables(viewQuery, matviewOid, true); | |||
CreateIvmTriggersOnBaseTables(query, matviewOid, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a comment for explaining why we have to use query instad of viewQuery?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. Don't need that I fixed it. revert it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder your reverting code would be wrong. The first commit changed the line 67, but the line 264 was changed in the second commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I made mistake.
This code is not reverted.
I will add a comment for explaining.
createas.c
Outdated
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), | ||
errmsg("unsupported subquery on incrementally maintainable materialized view"), | ||
errhint("Only simple subquery in FROM clause is supported."))); | ||
/* Now, EXISTS clause is supported only */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, "Currently, only EXISTS clause is allowed here" or something like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that's a right.
I will add its comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry I didn't make it clear enough, but I just suggested that "Now, EXISTS clause is ..." at line 1031 should be replaced with "Currently, EXISTS clause is ...", instead of adding the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understood it. i will fix it
I made some review comments. Especially, I think it would be nice if we have more comments in the code because we do somewhat complicated things for handling EXITS. Also, could you please update README? |
And add some comments and documents.
Thank you for your review. |
@@ -261,7 +263,7 @@ ExecCreateImmv(ParseState *pstate, CreateTableAsStmt *stmt, | |||
CreateIndexOnIMMV(viewQuery, matviewRel, true); | |||
|
|||
/* Create triggers on incremental maintainable materialized view */ | |||
CreateIvmTriggersOnBaseTables(viewQuery, matviewOid, true); | |||
CreateIvmTriggersOnBaseTables(query, matviewOid, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder your reverting code would be wrong. The first commit changed the line 67, but the line 264 was changed in the second commit.
createas.c
Outdated
* additional restriction checks for exists subquery | ||
* | ||
* When contain EXISTS clauses, and it has a column refernces | ||
* a table outside, its column must be included by target list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean "If the query has any EXISTS clauses and any columns in them refer to columns in tables in the outer query, those columns must be included in the target list." ?
How about adding comments about "why such check is needed" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I change a comment.
createas.c
Outdated
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), | ||
errmsg("unsupported subquery on incrementally maintainable materialized view"), | ||
errhint("Only simple subquery in FROM clause is supported."))); | ||
/* Now, EXISTS clause is supported only */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry I didn't make it clear enough, but I just suggested that "Now, EXISTS clause is ..." at line 1031 should be replaced with "Currently, EXISTS clause is ...", instead of adding the comment.
createas.c
Outdated
ereport(ERROR, | ||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), | ||
errmsg("this query is not allowed on incrementally maintainable materialized view"), | ||
errhint("subquery in WHERE clause only supports subquery with EXISTS clause"))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think this error message?
ereport(ERROR, | ||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), | ||
errmsg("nested subquery is not supported on incrementally maintainable materialized view"))); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean some nested subqueries are actually supported as above, so the error message does not seem correct, so should improve the message. What do you think about it?
I found that the following view definition caused a segmentation fault.
Could you fix the query check to prevent this? |
Thank you for adding the description that EXISTS subqueries are supported to README! If I understand correctly, I wonder that it would better to add the following information:
|
sublink in targetlist is not supported, so add this restrict and testcase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix your review comments.
createas.c
Outdated
F438 ereport(ERROR, | ||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), | ||
errmsg("this query is not allowed on incrementally maintainable materialized view"), | ||
errhint("subquery in WHERE clause only supports subquery with EXISTS clause"))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error can also occur other than subquery, so error message will be changed.
ereport(ERROR, | ||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), | ||
errmsg("nested subquery is not supported on incrementally maintainable materialized view"))); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error can also occur other than subquery. the nested sublink is actually correct. So error message will be changed.
matview.c
Outdated
TupleDesc tupdesc_old; | ||
TupleDesc tupdesc_new; | ||
bool use_count = false; | ||
char *count_colname = NULL; | ||
|
||
count_colname = pstrdup("__ivm_count__"); | ||
/* check if the modified table is in EXISTS clause. */ | ||
for (i = 0; i< list_length(rte_path); i++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this is fixed
matview.c
Outdated
for (i = 0; i< list_length(rte_path); i++) | ||
{ | ||
int index = lfirst_int(list_nth_cell(rte_path, i)); | ||
rte = (RangeTblEntry *)lfirst(list_nth_cell(querytree->rtable, index - 1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, it was fixed
matview.c
Outdated
/* Add count(*) used for EXISTS clause */ | ||
foreach(tbl_lc, query->rtable) | ||
{ | ||
RangeTblEntry *rte = (RangeTblEntry *)lfirst(tbl_lc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, it was fixed
matview.c
Outdated
* rewrite_query_for_exists_subquery | ||
* | ||
* Rewrite EXISTS sublink in WHERE to LATERAL subquery | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add an example at rewrite_querry_for_exists_subquery().
matview.c
Outdated
|
||
/* get subquery in WHERE clause */ | ||
fromexpr = (FromExpr *)query->jointree; | ||
query = rewrite_exists_subquery_walker(query, fromexpr->quals, count); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, it was fixed.
And I think that same mistakes are everywhere. so I will make a other patch with fixing spaces.
add restriction of EXISTS sublink
fix segmentation fault and add README |
Simple EXISTS clause is supported by this patch. A query is not supported when WHERE clause has OR-condition or JOIN-condition is not contained by targetlist.