8000 Support exists_subquery by thoshiai · Pull Request #53 · sraoss/pg_ivm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 7 commits into from
Aug 31, 2023
Merged

Support exists_subquery #53

merged 7 commits into from
Aug 31, 2023

Conversation

thoshiai
Copy link
Collaborator
@thoshiai thoshiai commented Feb 9, 2023

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.

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.
@thoshiai thoshiai requested a review from yugo-n February 9, 2023 01:50
@@ -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);
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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 */
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator
@yugo-n yugo-n Jul 14, 2023

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.

Copy link
Collaborator Author

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

@yugo-n
Copy link
Collaborator
yugo-n commented Mar 20, 2023

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.
@thoshiai thoshiai requested a review from yugo-n June 24, 2023 20:40
@thoshiai
Copy link
Collaborator Author

Thank you for your review.
I fixed and add README messages

@@ -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);
Copy link
Collaborator

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.
Copy link
Collaborator

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" ?

Copy link
Collaborator Author

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 */
Copy link
Collaborator
@yugo-n yugo-n Jul 14, 2023

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")));
Copy link
Collaborator

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")));

Copy link
Collaborator

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?

@yugo-n
Copy link
Collaborator
yugo-n commented Jul 14, 2023

I found that the following view definition caused a segmentation fault.

select create_immv('xx2', 'select exists(select 1 from t) from t2 ');

Could you fix the query check to prevent this?

@yugo-n
Copy link
Collaborator
yugo-n commented Jul 14, 2023

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:

  • EXISTS subquery is supported only in WHERE but not in the target list
    (Maybe, it is mandatory because it already explains Subqueries in targetlist are not supported, but adding the information would be helpful for clarification.)

  • Restriction that if EXISTS contains columns that refer to columns in tables in the outer query, such columns must be included in the target list.

hoshiai and others added 3 commits July 26, 2023 06:57
Copy link
Collaborator Author
@thoshiai thoshiai left a 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")));
Copy link
Collaborator Author

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")));

Copy link
Collaborator Author

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++)
Copy link
Collaborator Author

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));
Copy link
Collaborator Author

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);
Copy link
Collaborator Author

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
*/
Copy link
Collaborator Author

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);
Copy link
Collaborator Author

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
@thoshiai
Copy link
Collaborator Author
thoshiai commented Aug 8, 2023

fix segmentation fault and add README

@yugo-n yugo-n merged commit c355f40 into sraoss:main Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0