Skip to content
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

[Idea] Are there any concerns about creating PostgreSQL exclusion constraints (gist)? #191

Closed
cbortz opened this issue Jul 28, 2022 · 4 comments

Comments

@cbortz
Copy link

cbortz commented Jul 28, 2022

Hey y'all. Thanks for this super helpful gem.

Last month rails/rails#40224 was merged, which introduces support for PostgreSQL exclusion constraints using gist. Among other things, there is a new migration method add_exclusion_constraint.

As far as I can tell, it hasn't yet been staged for an official release, but it's in the main branch at this point.

Admittedly, I don't have enough experience to know what might (if anything) make this type of table alteration unsafe, but thought it may be relevant to this project. So, I figured I'd at least get a conversation started.

@ankane ankane mentioned this issue Jul 28, 2022
5 tasks
@ankane
Copy link
Owner

ankane commented Jul 28, 2022

Hey @cbortz, thanks for sharing! From what I can tell, it appears to be unsafe (for existing tables).

CREATE EXTENSION IF NOT EXISTS btree_gist;
CREATE TABLE t1 (value int);
INSERT INTO t1 SELECT i FROM generate_series(1,1000000) i;
ALTER TABLE t1 ADD CONSTRAINT c1 EXCLUDE USING gist (value WITH =); -- slow, table locked

Also, I'm not sure there's a safe way to do it.

ALTER TABLE t1 ADD CONSTRAINT c1 EXCLUDE USING gist (value WITH =) NOT VALID;
ERROR:  EXCLUDE constraints cannot be marked NOT VALID

I've added it to the plan (#177) for when Rails 7.1 rc1 is released.

@cbortz
Copy link
Author

cbortz commented Jul 28, 2022

@ankane Glad it was helpful. Thanks for sharing that example from your experiment! 🙏

@ankane ankane closed this as completed in 4ff6be6 Oct 30, 2022
@ankane
Copy link
Owner

ankane commented Oct 30, 2022

Hey @cbortz, added (a little early) in the commit above. Thanks again for the suggestion!

@cbortz
Copy link
Author

cbortz commented Oct 30, 2022

@ankane As always, thank you for continuing to maintain this library (and all of the others)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants