-
-
Notifications
You must be signed in to change notification settings - Fork 525
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
Adding a duplicate constraint with a new name overwrites the existing constraint rather than coexisting #8254
Comments
Thanks for reporting this one and for taking the time to provide such easy repro steps 🙏 We'll dig into this and see what's going on. |
I debugged through this one and I see what's happening now. The way Dolt works with secondary indexes, like these unique constraints create, is that the index is almost always looked up by the columns in the index, not by the index's name. In this case, because the columns are the same for the existing index and the new index, the attempt to create This seems fixable from what I can see so far, although it'll probably take some updates across the code base to untangle things. I'm happy to keep digging into this if it's causing issues for you and your team. At the same time, I also wanted to better understand the need for having two unique indexes over the same set of columns, since the index data would be redundant anyway. I'm wondering if there's something specific you and your team are trying to achieve and if there's a faster way we could help you get there with another approach. Let me know what you think when you get a chance and I'll go ahead and keep poking on this a little more to better understand the scope. |
Thanks for the update! As best as I understand the issue from our side, we don't actually need the two unique indexes long-term, it's a temporary artifact of how Django generates the migration to replace one style of constraint (with a name autogenerated by Django) with a newer style (with an explicitly specified name). It appears to default to adding the new constraint before dropping the old one:
or in other words:
Furthermore, as part of the I'll do a little more digging - maybe we could work around this by manually editing the migration to reverse the order of the two steps above, but the above order works fine as-is with Postgres and MySQL. Thanks again! |
That's really helpful context, thank you for sharing! That's a totally valid use case and one we want to support for compatibility with MySQL and MySQL-based tools like Django. It's also helpful to know that you all need this for a migration – that's helpful because if we can't immediately get merges with duplicated indexes working totally seamlessly, it sounds like that won't affect you. I did a quick audit of the uses of the index lookup APIs yesterday and have some ideas on how to change them to better support multiple indexes over the same set of columns. I'll keep digging in today and see what I can come up with. |
I've got a change in my workspace that allows the duplicate index to be created and I've tested the delete case as well. I spent some time digging around to see if this would cause problems with other features (like merging), and confirmed that we already have logic in place to block trying to merge a duplicate index. I think this change should unblock the Django migration for you. I need to clean up the tests and a little bit and move them into a better position in our test suite, then I'll get a PR opened and get this out for review. |
Safe to say this one can be closed? |
We just released Dolt 1.42.12 with the fix for this issue. Let us know if you all hit any other problems. |
Thank you for the speedy fix! Will verify it locally as soon as the release hits GitHub :-) |
Dolt version: 1.41.3
In Dolt, adding a duplicate constraint to a table with a new name overwrites the existing constraint on that table rather than coexisting with it. I discovered this because it appears to be a different behavior than exhibited by MySQL, and as such causes a Django migration (in our app, resulting from replacing an old-style Django
unique_together
constraint with a new-styleUniqueConstraint
), which works in MySQL, to error out in Dolt, because it tries to remove the original constraint after adding the duplicate constraint, but the original constraint no longer exists.MySQL
Dolt
The text was updated successfully, but these errors were encountered: