-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
Non-enforced constraints #8076
base: master
Are you sure you want to change the base?
Non-enforced constraints #8076
Conversation
What will happen with |
Why not enforced constaint deactivates corresponding index ? |
Nothing. CREATE TABLE statement does not support creation of inactive constraints. |
Because active unique index won't allow insertion of duplicates by itself.
AFAIK deactivate index + bulk insert + activate index is less costly than bulk insert with active index. |
It is could be changed
It is about constraints in general, not about singe use-case. |
Ok, if it is ever changed, this feature can be changed too.
I know no other use case for this feature. |
It would be much better to do it at once, not leaving big piece of work for someone else, IMHO
It doesn't means they not exists. Such kind of "arguments" never works. |
BTW, it will be good to show here excerpt from standard that describes the feature. |
I do what I can. Sorry, I have no idea how to implement duplicates in unique indices and doubt that it is anyhow useful. From the standard I have access to BNF only:
PS: Oops, header for 11.25 was lost because of parentheses... |
Let's solve problems as they appear. In this case - wait while someone come with different use case. In this PR I only solve my own problem which I know to exist. |
If unique constraint is not enforced one should not wonder duplicates in "unique" index
Do you have BNF that allows to change ENFORCED state ? https://www.ibm.com/docs/en/db2/11.5?topic=constraints-creating-modifying @mrotteveel: could you shed a light on this, please ? |
It is exactly quoted.
And even if I get it wrong, I'll just remove "ANSI standard-compliant" from the doc. This PR is still a valid solution for #2358 even without standard compliance. |
From SQ:2023-2:
And as a reminder, the SQL standard defines "unique constraint" as (4.25.3.2 Unique constraints):
In other words, by syntax rule 3, [NOT] ENFORCED is not allowed for unique constraints (i.e. both PRIMARY KEY and UNIQUE constraints), only for referential and check constraints. Section 4.25.3.1 Introduction to table constraints also says:
|
In other words, for standard conformance, the support for NOT ENFORCED for PRIMARY/UNIQUE KEY should be removed, and support for CHECK constraints should be added, because not enforcing PRIMARY/UNIQUE KEYS is explicitly not allowed by the standard. |
Ah, ok, this really is going to be a non-standard feature. |
@mrotteveel: thanks ! IMHO, we could live with [NOT] ENFORCED PRIMARY/UNIQUE KEY constraints. I'm not insisting, just show my current opinion. And I'm still very concerned about needs of [de]activation of underlying indices in-sync with constraint enforcement. |
If |
PS I could be wrong and there is a less work to do actually :) |
Exactly because I don't know how engine manage constraints and metadata cache, I've chose the simplest solution: to reuse index deactivation code. For my purposes it is enough. If you insist I can remove |
BTW, |
Now this PR is a complete solution for #2358. Shall you review it in current state or I must make it much bigger implementing creation of not enforced constraints? |
So after Create Table stetement should be additional statement fo deactivation. |
No, just creation of a not enforced constraint should be added. The only question is if it will be in this PR or a separate one. |
Now it is complete. |
bfb319e
to
9abe46e
Compare
Partial implementation of #2358 using standard-compliant clause
ALTER CONSTRAINT [NOT] ENFORCED
.