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
Changing syntax to use MATERIALIZED VIEW for continuous aggregates #2243
Conversation
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.
Did a quick pass with high-level feedback. Might do a more thorough review later.
cagg = ts_continuous_agg_find_by_view_name(NameStr(view_schema), NameStr(view_name)); | ||
vtyp = ts_continuous_agg_view_type(&cagg->data, NameStr(view_schema), NameStr(view_name)); | ||
|
||
if (vtyp == ContinuousAggPartialView || vtyp == ContinuousAggDirectView) |
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.
The commit message has a typo: it states that ALTER VIEW is allowed with partial and direct views.
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.
Well, it is allowed to use ALTER VIEW
to change some things, such as the schema for the view. Not sure why, but there are tests for 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.
I'll clarify the situation when squashing them.
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.
Rewrote it to mention that it is ALTER VIEW ... SET SCHEMA
that we handle.
67dd652
to
eee6b85
Compare
fe989bd
to
2de3f06
Compare
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.
Approving, but there are a number of nits, issues to fix. Most pressing are several places where the return type and return values do not match.
I also think there's a test case missing for CREATE MATERIALIZED VIEW IF NOT EXISTS
Please also squash a number of the nit commits (7 commits seems a bit excessive for this change).
if (get_relname_relid(stmt->view->relname, nspid)) | ||
nspid = RangeVarGetCreationNamespace(stmt->into->rel); | ||
|
||
if (get_relname_relid(stmt->into->rel->relname, nspid)) |
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.
Shouldn't this honor IF NOT EXISTS
? (Looks like we are always failing here in case of an existing aggregate). Do we have a test for 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.
Added check for it working in a similar way to how it works for normal tables. And added test case.
1707c17
to
f63fbf8
Compare
f63fbf8
to
94aa738
Compare
Codecov Report
@@ Coverage Diff @@
## master #2243 +/- ##
==========================================
+ Coverage 90.11% 90.24% +0.13%
==========================================
Files 212 212
Lines 34347 34341 -6
==========================================
+ Hits 30952 30992 +40
+ Misses 3395 3349 -46
Continue to review full report at Codecov.
|
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.
There are some unexpected diffs in the isolation test output. Other changes look good.
@@ -94,7 +94,8 @@ step Setup2: | |||
END; $$ LANGUAGE plpgsql; | |||
|
|||
step AlterLag1: alter view continuous_view_1 set (timescaledb.refresh_lag = 10); | |||
R1: LOG: materializing continuous aggregate public.continuous_view_1: nothing to invalidate, new range up to 15 | |||
ERROR: cannot alter continuous aggregate using ALTER 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 needs to be fixed. It alters the output for the .out file.
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.
Fixed.
@@ -119,11 +120,12 @@ step Refresh2: REFRESH MATERIALIZED VIEW continuous_view_2; <waiting ...> | |||
step UnlockCompleted: ROLLBACK; | |||
step Refresh2: <... completed> | |||
step UnlockMat1: ROLLBACK; | |||
R1: LOG: materializing continuous aggregate public.continuous_view_1: nothing to invalidate, new range up to 30 | |||
R1: LOG: materializing continuous aggregate public.continuous_view_1: nothing to invalidate, new range up to 45 |
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.
Is this diff also related to the alter view fialing?
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.
Yup. Fixed.
fd39737
to
f80b5ed
Compare
db6946c
to
9c8f941
Compare
We change the syntax for defining continuous aggregates to use `CREATE MATERIALIZED VIEW` rather than `CREATE VIEW`. The command still creates a view, while `CREATE MATERIALIZED VIEW` creates a table. Raise an error if `CREATE VIEW` is used to create a continuous aggregate and redirect to `CREATE MATERIALIZED VIEW`. In a similar vein, `DROP MATERIALIZED VIEW` is used for continuous aggregates and continuous aggregates cannot be dropped with `DROP VIEW`. Continuous aggregates are altered using `ALTER MATERIALIZED VIEW` rather than `ALTER VIEW`, so we ensure that it works for `ALTER MATERIALIZED VIEW` and gives an error if you try to use `ALTER VIEW` to change a continuous aggregate. Note that we allow `ALTER VIEW ... SET SCHEMA` to be used with the partial view as well as with the direct view, so this is handled as a special case. Fixes timescale#2233 Co-authored-by: =?UTF-8?q?Erik=20Nordstr=C3=B6m?= <erik@timescale.com> Co-authored-by: Mats Kindahl <mats@timescale.com>
9c8f941
to
466e236
Compare
We change the syntax for defining continuous aggregates to use
CREATE MATERIALIZED VIEW
rather thanCREATE VIEW
. The command still createsa view, while
CREATE MATERIALIZED VIEW
creates a table. Raise anerror if
CREATE VIEW
is used to create a continuous aggregate andredirect to
CREATE MATERIALIZED VIEW
.In a similar vein,
DROP MATERIALIZED VIEW
is used for continuousaggregates and continuous aggregates cannot be dropped with
DROP VIEW
.Continuous aggregates are altered using
ALTER MATERIALIZED VIEW
rather than
ALTER VIEW
, so we ensure that it works forALTER MATERIALIZED VIEW
and gives an error if you try to useALTER VIEW
tochange a continuous aggregate.
Note that we allow
ALTER VIEW ... SET SCHEMA
to be used with thepartial view as well as with the direct view, so this is handled as a
special case.
Fixes #2233