-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: create built-in function to detect violations of unique constraints #73560
Comments
How would this differ from |
Sorry for the slow reply @nvanbenschoten!
Yea, exactly. The idea is that this would be a simple way for customers to detect corruption due to #73024. But I'm also not 100% convinced the built-in is necessary if you see potential issues with it. We also opened #73632 to add unique constraint checks to SCRUB. |
I don't see any problems with it. I was just pointing out that we may already have 90% of the logic we'd want with |
Good point -- I'll look into that as an option -- thanks! |
Just to follow up on this, I decided to go with the builtin function since it can be used to easily validate all unique constraints in the DB at once, which seems more useful at this point. I think we could add support for |
Fixes cockroachdb#73560 Release note (sql change): Added a new builtin function called crdb_internal.validate_unique_constraints, which can be used to validate the unique constraints of all tables in the current database. If any constraint fails validation, the function will return an error with a hint about which data caused the constraint violation. These violations can then be resolved manually by updating or deleting the rows in violation. This will be useful to users who think they may have been affected by cockroachdb#73024.
Fixes cockroachdb#73560 Release note (sql change): Added new builtin functions called crdb_internal.revalidate_unique_constraint, and crdb_internal.revalidate_unique_constraints, which can be used to revalidate existing unique constraints. There are overloads to support validation of a single constraint, all unique constraints in a table, or all unique constraints of all tables in the current database. If any constraint fails validation, the function will return an error with a hint about which data caused the constraint violation. These violations can then be resolved manually by updating or deleting the rows in violation. This will be useful to users who think they may have been affected by cockroachdb#73024.
Fixes cockroachdb#73560 Release note (sql change): Added new builtin functions called crdb_internal.revalidate_unique_constraint, crdb_internal.revalidate_unique_constraints_in_table, and crdb_internal.revalidate_unique_constraints_in_all_tables, which can be used to revalidate existing unique constraints. The different variations support validation of a single constraint, validation of all unique constraints in a table, and validation of all unique constraints in all tables in the current database, respectively. If any constraint fails validation, the functions will return an error with a hint about which data caused the constraint violation. These violations can then be resolved manually by updating or deleting the rows in violation. This will be useful to users who think they may have been affected by cockroachdb#73024.
Fixes cockroachdb#73560 Release note (sql change): Added new builtin functions called crdb_internal.revalidate_unique_constraint, crdb_internal.revalidate_unique_constraints_in_table, and crdb_internal.revalidate_unique_constraints_in_all_tables, which can be used to revalidate existing unique constraints. The different variations support validation of a single constraint, validation of all unique constraints in a table, and validation of all unique constraints in all tables in the current database, respectively. If any constraint fails validation, the functions will return an error with a hint about which data caused the constraint violation. These violations can then be resolved manually by updating or deleting the rows in violation. This will be useful to users who think they may have been affected by cockroachdb#73024.
75548: sql: add builtin functions to revalidate unique constraints r=rytaft a=rytaft Fixes #73560 Release note (sql change): Added new builtin functions called `crdb_internal.revalidate_unique_constraint`, `crdb_internal.revalidate_unique_constraints_in_table`, and `crdb_internal.revalidate_unique_constraints_in_all_tables`, which can be used to revalidate existing unique constraints. The different variations support validation of a single constraint, validation of all unique constraints in a table, and validation of all unique constraints in all tables in the current database, respectively. If any constraint fails validation, the functions will return an error with a hint about which data caused the constraint violation. These violations can then be resolved manually by updating or deleting the rows in violation. This will be useful to users who think they may have been affected by #73024. 75741: colfetcher: fix index join with low workmem limit when using Streamer r=yuzefovich a=yuzefovich Previously, it was possible for an index join to run into "budget exceeded" errors when using the Streamer API because we used the hard-coded value of 4MiB for input batch size without paying attention to possibly lower values of `distsql_workmem` limit. For example, we could have buffered 3MiB worth of spans to be enqueued into the Streamer that only has 1MiB of budget overall. This is now fixed by reducing the input size limit to be a quarter of `distsql_workmem` limit. We don't need to do a similar change to the row-by-row engine because there we hard-code the workmem limit to be at least 8MiB. Fixes: #75703 Release note: None Co-authored-by: Rebecca Taft <[email protected]> Co-authored-by: Yahor Yuzefovich <[email protected]>
Fixes cockroachdb#73560 Release note (sql change): Added new builtin functions called crdb_internal.revalidate_unique_constraint, crdb_internal.revalidate_unique_constraints_in_table, and crdb_internal.revalidate_unique_constraints_in_all_tables, which can be used to revalidate existing unique constraints. The different variations support validation of a single constraint, validation of all unique constraints in a table, and validation of all unique constraints in all tables in the current database, respectively. If any constraint fails validation, the functions will return an error with a hint about which data caused the constraint violation. These violations can then be resolved manually by updating or deleting the rows in violation. This will be useful to users who think they may have been affected by cockroachdb#73024.
Due to the issue described in #73024, on 21.2.0, unique constraints on
REGIONAL BY ROW
tables may not be enforced. It would be helpful to have an easy way to detect violations of unique constraints, such as a built-in SQL function. This function could simply run a SQL query under the covers, similar to the one suggested for detecting violations in the technical advisory for #73024.The text was updated successfully, but these errors were encountered: