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
Enable joins for hierarchical continuous aggregates #5344
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ | |
#include <parser/parse_oper.h> | ||
#include <parser/parse_relation.h> | ||
#include <parser/parse_type.h> | ||
#include <parser/parsetree.h> | ||
#include <rewrite/rewriteHandler.h> | ||
#include <rewrite/rewriteManip.h> | ||
#include <utils/acl.h> | ||
|
@@ -1284,31 +1285,42 @@ | |
op = (OpExpr *) join->quals; | ||
rte = list_nth(query->rtable, ((RangeTblRef *) join->larg)->rtindex - 1); | ||
rte_other = list_nth(query->rtable, ((RangeTblRef *) join->rarg)->rtindex - 1); | ||
if (rte->subquery != NULL || rte_other->subquery != NULL) | ||
ereport(ERROR, | ||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), | ||
errmsg("invalid continuous aggregate view"), | ||
errdetail("sub-queries are not supported in FROM clause"))); | ||
RangeTblEntry *jrte = rt_fetch(join->rtindex, query->rtable); | ||
if (jrte->joinaliasvars == NIL) | ||
ereport(ERROR, | ||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), | ||
errmsg("invalid continuous aggregate view"))); | ||
} | ||
} | ||
} | ||
|
||
/* | ||
* Cagg with joins does not support hierarchical caggs in from clause. | ||
* Error out if there is aynthing else than one normal table and one hypertable | ||
* in the from clause, e.g. sub-query, lateral, two hypertables, etc. | ||
*/ | ||
if (rte->relkind == RELKIND_VIEW || rte_other->relkind == RELKIND_VIEW) | ||
if (rte->lateral || rte_other->lateral) | ||
ereport(ERROR, | ||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), | ||
errmsg("joins for hierarchical continuous aggregates are not supported"))); | ||
|
||
/* | ||
* Error out if there is aynthing else than one normal table and one hypertable | ||
* in the from clause, e.g. sub-query. | ||
*/ | ||
if (((rte->relkind != RELKIND_RELATION && rte->relkind != RELKIND_VIEW) || | ||
rte->tablesample || rte->inh == false) || | ||
((rte_other->relkind != RELKIND_RELATION && rte_other->relkind != RELKIND_VIEW) || | ||
rte_other->tablesample || rte_other->inh == false) || | ||
errmsg("invalid continuous aggregate view"), | ||
errdetail("lateral are not supported in FROM clause"))); | ||
if ((rte->relkind == RELKIND_VIEW && ts_is_hypertable(rte_other->relid)) || | ||
(rte_other->relkind == RELKIND_VIEW && ts_is_hypertable(rte->relid))) | ||
ereport(ERROR, | ||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), | ||
errmsg("invalid continuous aggregate view"), | ||
errdetail("views are not supported in FROM clause"))); | ||
if (rte->relkind != RELKIND_VIEW && rte_other->relkind != RELKIND_VIEW && | ||
(ts_is_hypertable(rte->relid) == ts_is_hypertable(rte_other->relid))) | ||
ereport(ERROR, | ||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), | ||
errmsg("invalid continuous aggregate view"), | ||
errdetail("from clause can only have one hypertable and one normal table"))); | ||
errdetail("multiple hypertables or normal tables" | ||
" are not supported in FROM clause"))); | ||
|
||
/* Only inner joins are allowed. */ | ||
if (jointype != JOIN_INNER) | ||
|
@@ -1340,7 +1352,12 @@ | |
* that we know which one is hypertable to carry out the related | ||
* processing in later parts of code. | ||
*/ | ||
normal_table_id = ts_is_hypertable(rte->relid) ? rte_other->relid : rte->relid; | ||
if (rte->relkind == RELKIND_VIEW) | ||
normal_table_id = rte_other->relid; | ||
else if (rte_other->relkind == RELKIND_VIEW) | ||
normal_table_id = rte->relid; | ||
else | ||
normal_table_id = ts_is_hypertable(rte->relid) ? rte_other->relid : rte->relid; | ||
if (normal_table_id == rte->relid) | ||
rte = rte_other; | ||
} | ||
|
@@ -2450,14 +2467,28 @@ | |
* which contains the information of the materialised hypertable | ||
* that is created for this cagg. | ||
*/ | ||
if (list_length(inp->final_userquery->jointree->fromlist) >= CONTINUOUS_AGG_MAX_JOIN_RELATIONS) | ||
if (list_length(inp->final_userquery->jointree->fromlist) >= | ||
CONTINUOUS_AGG_MAX_JOIN_RELATIONS || | ||
!IsA(linitial(inp->final_userquery->jointree->fromlist), RangeTblRef)) | ||
{ | ||
rte = makeNode(RangeTblEntry); | ||
rte->alias = makeAlias(relname, NIL); | ||
rte->inFromCl = true; | ||
rte->inh = true; | ||
rte->rellockmode = 1; | ||
rte->eref = copyObject(rte->alias); | ||
ListCell *l; | ||
foreach (l, inp->final_userquery->jointree->fromlist) | ||
{ | ||
Node *jtnode = (Node *) lfirst(l); | ||
JoinExpr *join = NULL; | ||
if (IsA(jtnode, JoinExpr)) | ||
{ | ||
join = castNode(JoinExpr, jtnode); | ||
RangeTblEntry *jrte = rt_fetch(join->rtindex, inp->final_userquery->rtable); | ||
rte->joinaliasvars = jrte->joinaliasvars; | ||
} | ||
} | ||
Comment on lines
+2481
to
+2491
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this is needed?? Can u add a comment here. I also asked for the same in the other PR https://github.com/timescale/timescaledb/pull/5441/files#r1150565424 |
||
} | ||
else | ||
rte = llast_node(RangeTblEntry, inp->final_userquery->rtable); | ||
|
@@ -3411,12 +3442,17 @@ | |
*/ | ||
if (list_length(q2->rtable) == CONTINUOUS_AGG_MAX_JOIN_RELATIONS) | ||
{ | ||
Oid normal_table_id = InvalidOid; | ||
RangeTblRef *rtref = linitial_node(RangeTblRef, q2->jointree->fromlist); | ||
RangeTblEntry *rte = list_nth(q2->rtable, rtref->rtindex - 1); | ||
RangeTblRef *rtref_other = lsecond_node(RangeTblRef, q2->jointree->fromlist); | ||
RangeTblEntry *rte_other = list_nth(q2->rtable, rtref_other->rtindex - 1); | ||
|
||
Oid normal_table_id = ts_is_hypertable(rte->relid) ? rte_other->relid : rte->relid; | ||
if (rte->relkind == RELKIND_VIEW) | ||
normal_table_id = rte_other->relid; | ||
else if (rte_other->relkind == RELKIND_VIEW) | ||
normal_table_id = rte->relid; | ||
else | ||
normal_table_id = ts_is_hypertable(rte->relid) ? rte_other->relid : rte->relid; | ||
if (normal_table_id == rte->relid) | ||
varno = 2; | ||
else | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 guess your CHANGELOG entry is on the wrong place, it should reside on the Unreleased section at the beginning of the file.