-
-
Notifications
You must be signed in to change notification settings - Fork 33k
Fixed #29547 -- Added support for partial indexes. #10140
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
Conversation
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.
Nice stuff, I've been wanting this feature for a while!
docs/releases/2.2.txt
Outdated
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.
Can you move this 2 lines above, right next to the other change about Indexes.
75f68a5
to
6b88dc3
Compare
6b88dc3
to
fd4e3a7
Compare
55b13c4
to
f461550
Compare
@atombrella what do you need / how can I help to get this over the finish line? |
@MarkusH The biggest hurdle now is the unnecessary lookup casts. I posted a question on IRC about it, but perhaps the mailing list is a better place. On PostgreSQL, |
8755635
to
a6816b2
Compare
@felixxm Could you please assist with the Oracle test failures? |
@atombrella Sure, I will check them in this week. |
a6816b2
to
1a15f08
Compare
@atombrella Thanks for this PR 🚀 On Oracle we should be able to emulate (in most cases) partial indexes by function-based indexes. I will check how it works with this PR. |
@atombrella Oracle doesn't index CREATE INDEX "RECENT_ARTICLE_IDX" ON "INDEXES_ARTICLE" (
CASE WHEN "PUB_DATE" > '2015-01-01' THEN 1 END
); |
cf0dcde
to
9a72d67
Compare
Awesome stuff! Is handling of unique indexes planned for this feature? They can be really useful as a conditional alternative for unique constraints. |
@georgebrock there's work being done in this regards in #10337. Not sure about the API yet but I think the idea would be to have |
@felixxm Would you be ok with a Likewise for unique-constraints; this seems to be handled currently in the ongoing |
yeah we really need to gather consensus on the |
tests/indexes/tests.py
Outdated
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.
Do we need the tzinfo
bit for the test? I'm worried relying on get_current_timezone
could make the test flaky.
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.
The reason for the tzinfo
bit was the type casting which makes the function mutable, and PostgreSQL raises an error. USE_TZ
is False
by default; without tzinfo
, the test fails with django.db.utils.ProgrammingError: functions in index predicate must be marked IMMUTABLE
. I believed I touched this problem about timezones in the documentation, but it may need improvement or clarification.
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.
Maybe include a comment here?
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.
Yes 👍 I'll also try to write a sentence or two about DateField
under the postgresql note. I noticed that comparison between dates (and not date+time) won't be converted to a mutable function.
5a1684a
to
9921419
Compare
tests/indexes/models.py
Outdated
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.
I'm not sure why I added null=True
, so it should probably be removed.
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.
what about auto_now=True instead of null=True?
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.
The tests pass without any change to that line, so I'll just revert my addition, and don't plan on changing it again.
After thinking about it a bit more I think there's room for both Maybe e.g. Appointment.objects.bulk_create(objs, conflict_updates=[
ConflictUpdate(
'location_timeslot', # UniqueConstraint(name)
Q(prefered_timeslot=False),
timeslot=Subquery(
Availability.objects.filter(
location=OuterRef('location')
).values('timeslot').order_by('timeslot')[1]
),
],
}) ON CONFLICT UPDATE
SET timeslot = (SELECT timeslot FROM ...) WHERE excluded.prefered_timeslot = false or warn about |
9921419
to
1d1f1ad
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.
Looks good to me overall.
80b0add
to
f913559
Compare
f913559
to
c0b9a2b
Compare
Thanks to Ian Foote, Mariusz Felisiak, Simon Charettes, and Markus Holtermann for comments and feedback.
c0b9a2b
to
a906c98
Compare
opclasses
andIndexError
when alookup
is used.