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
Remove requirement of CASCADE from DROP VIEW #2171
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1079,9 +1079,8 @@ process_grant_and_revoke_role(ProcessUtilityArgs *args) | |
return DDL_DONE; | ||
} | ||
|
||
/* Force the use of CASCADE to drop continuous aggregates */ | ||
static void | ||
block_dropping_continuous_aggregates_without_cascade(ProcessUtilityArgs *args, DropStmt *stmt) | ||
process_drop_continuous_aggregates(ProcessUtilityArgs *args, DropStmt *stmt) | ||
{ | ||
ListCell *lc; | ||
|
||
|
@@ -1108,13 +1107,19 @@ block_dropping_continuous_aggregates_without_cascade(ProcessUtilityArgs *args, D | |
name = get_rel_name(relid); | ||
|
||
cagg = ts_continuous_agg_find_by_view_name(schema, name); | ||
if (cagg == NULL) | ||
continue; | ||
|
||
if (ts_continuous_agg_view_type(&cagg->data, schema, name) == ContinuousAggUserView) | ||
ereport(ERROR, | ||
(errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST), | ||
errmsg("dropping a continuous aggregate requires using CASCADE"))); | ||
if (cagg) | ||
{ | ||
/* Add the materialization table to the arguments so that the | ||
* continuous aggregate and associated materialization table is | ||
* dropped together. | ||
* | ||
* If the table is missing, something is wrong, but we proceed | ||
* with dropping the view anyway since the user cannot get rid of | ||
* the broken view if we generate an error. */ | ||
Hypertable *ht = ts_hypertable_get_by_id(cagg->data.mat_hypertable_id); | ||
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. We are making an assumption here that the only dependent object on the cagg is the materialization hypertable. What happens in the case where we have a view defined on top of the cagg like: 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. Not sure I follow; this code looks up the materialized hypertable and adds it to the list of tables to be dropped. It make no assumptions on other objects and, in particular, does not allow dropping other (dependent) objects without using 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. Thanks for the clarification. See that you also have a test case for it. |
||
if (ht) | ||
process_add_hypertable(args, ht); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -1133,7 +1138,7 @@ process_drop_start(ProcessUtilityArgs *args) | |
process_drop_hypertable_index(args, stmt); | ||
break; | ||
case OBJECT_VIEW: | ||
block_dropping_continuous_aggregates_without_cascade(args, stmt); | ||
process_drop_continuous_aggregates(args, stmt); | ||
break; | ||
case OBJECT_FOREIGN_SERVER: | ||
process_drop_foreign_server_start(stmt); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -658,5 +658,5 @@ SELECT show_chunks('test_drop_chunks_table'); | |
(4 rows) | ||
|
||
--drop the view to allow drop chunks to work | ||
DROP VIEW tdc_view CASCADE; | ||
DROP VIEW tdc_view; | ||
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. I don't think we should keep the cascade notice below if we do not require However, the semantics we want is to treat the DROP as if it was acting on a single abstract object, so it makes no sense to keep the cascade notices about subobjects that are part of the abstract object. 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. As we discussed, the message is something that PostgreSQL generates internally and setting up the dependencies turned out to not be trivial. I will skip this issue for this PR and investigate it separately. Note that PostgreSQL has support for handling internal dependencies and allow objects to be part of an implementation as is the case for continuous aggregates. However, this requires a separate effort. |
||
NOTICE: drop cascades to table _timescaledb_internal._hyper_3_13_chunk |
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 didn't see a test for this case. It suggest adding one.
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.
As we discussed, I'll just remove the warning and update the comment to clarify the situation.