-
-
Notifications
You must be signed in to change notification settings - Fork 242
Non-enforced constraints #8076
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
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
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.
It was a quick look, so I can miss something.
Also, I didn't check extract.epp, show.epp and SystemTriggers.epp
@@ -3482,7 +3525,6 @@ bool TriggerDefinition::modify(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch | |||
{ | |||
switch (TRG.RDB$SYSTEM_FLAG) | |||
{ | |||
case fb_sysflag_check_constraint: |
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.
Why ?
constraint.name = clause->name; | ||
constraint.create->enforced = clause->enforced; | ||
*notNull = clause->enforced; |
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 is wrong
break; | ||
} |
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.
Not needed braces, remove please
if (strcmp(RC.RDB$CONSTRAINT_TYPE, PRIMARY_KEY) == 0 || | ||
strcmp(RC.RDB$CONSTRAINT_TYPE, UNIQUE_CNSTRT) == 0) | ||
{ | ||
// Deactivation of primary/unique key requires check for active foreign keys |
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 code works for deactivaiton only ?
} | ||
else if (strcmp(RC.RDB$CONSTRAINT_TYPE, NOT_NULL_CNSTRT) == 0) | ||
{ | ||
AutoRequest requestHandle; |
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.
Should this and below requests be cached ?
@@ -10117,6 +10282,8 @@ void AlterIndexNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, | |||
executeDdlTrigger(tdbb, dsqlScratch, transaction, DTW_BEFORE, DDL_TRIGGER_ALTER_INDEX, | |||
name, NULL); | |||
|
|||
checkIndexReferenced(tdbb, transaction, name.c_str()); |
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 it supposed to run when index is activated ?
|
||
Primary and unique keys cannot be deactivated if they are referenced by any active foreign key. | ||
|
||
The corresponding ALTER INDEX and ALTER TRIGGER statements are allowed as well. |
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.
Not clear at all.
@@ -411,7 +411,7 @@ namespace | |||
const char* users[] = {userName, "PUBLIC"}; | |||
int grantOptions[] = {WITH_GRANT_OPTION, 0}; | |||
|
|||
for (unsigned i = 0; i < FB_NELEM(users); i++) | |||
for (int i = 0; i < FB_NELEM(users); i++) |
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.
Why ?
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.
FB_NELEM
is signed. It fixes a warning.
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.
It is FB_SIZE_T
in master and better to fix if to be at least unsigned
in v5 too, there is no sence to use signed type, imho.
Are you going to change this place in master ?
Anyway, there is a lot of such misuse, why fix just one of them and at the unrelated PR without any need ?
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.
https://groups.google.com/g/firebird-devel/c/D4eu6KGUlRU/m/s-GnU8FxAAAJ
This PR is for master
.
I fix annoying warnings only in files I touch frequently during work to keep the PR small. Fortunately Mark is going to do this job so may be I'll remove this piece from patch.
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 PR is for
master
.
So why you argue ?
I fix annoying warnings only in files I touch frequently during work to keep the PR small
This file makes NO relation with this PR. Don't do it or you will wait for reviews forever as nobody wants to waste a time.
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 PR waited more than a year. Forever is just a little longer so why should I care?..
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.
You never care. Go wait another year.
Implementation of #2358 using standard-compliant clause
ALTER CONSTRAINT [NOT] ENFORCED
.