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
DROP TABLE with CASCADE appears not to account for CHECK constraint with subquery and fails #3955
Comments
Using the debugger took me to (these links are on master, not my version, but they appear to match) h2database/h2/src/main/org/h2/command/ddl/DropTable.java Lines 117 to 137 in 3525a20
prepareDrop does it's checks and whatnot, this seems to be where "is not RESTRICT" seems to be checked. if (!starting) {
Table t = getDependentTable(obj, null);
if (t != null) {
obj.getSchema().add(obj);
throw DbException.get(ErrorCode.CANNOT_DROP_2, obj.getTraceSQL(), t.getTraceSQL());
}
obj.removeChildrenAndResources(session); getDependentTable returns the SCREENING table and so aborts. removeChildrenAndResources I think removes (from browsing the source) the indexes on the MVTable and via the superclass all the resources belonging to the table. |
Just to be clear - are you expecting the SCREENING table to the dropped? Because if so, that is not what CASCADE is designed to do. The intention is that it will drop associated VIEWs, TRIGGERs, and CONSTRAINTs, but not anything else. In which case, the documentation should be clarified. But possibly I am misreading your (very nice) bug report? |
@grandinj I'll take a look on it later, most likely we have other problems in this area. |
grandinj; This would fit what the doc says, and would do what I superficially expect. I haven't used SQL much in production but the purpose of CASCADE appears to me to be to remove things that are preventing the desired deletion operation. To do that it should be sufficient for the constraint, i.e. the thing holding a live reference to the table, to be removed. Afterwards, if something wants to delete the other table later it can. I understand if this wasn't clear from the big SQL blob and unelaborated log I pasted. I.e. no I do not expect SCREENING to be dropped. It shouldn't need to be, it doesn't stop MOVIE from being dropped, only it's constraint stops it. katzyn; |
Such constraints currently don't register themselves in a queried table, but registration can't help by itself because the main problem is bigger. H2 collects dependencies during database object removal in the wrong way, it probably should collect actual dependencies instead of tables with these dependencies. And this collection is performed too late for transient removal. A whole database object deletion logic needs to be adjusted first. |
I'm using a self-compiled version 2.2.214 of H2.
I'm not sure if this is my error or if this is a bug. I have a schema with a check constraint containing a subquery (with H2 being one of the few databases that supports such at thing :) <3 ). When Hibernate tries to drop a table referred to by the constraint, even with CASCADE, it fails.
https://www.h2database.com/html/commands.html#drop_table states the following, which suggests this should work.
I may have time to minimize a repro later but until then, the non-minimized part of my schema dumped with IntelliJ:
The text was updated successfully, but these errors were encountered: